Panda3D
 All Classes Functions Variables Enumerations
dxVertexBufferContext9.cxx
1 // Filename: dxVertexBufferContext9.cxx
2 // Created by: drose (18Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "dxVertexBufferContext9.h"
16 #include "geomVertexArrayData.h"
17 #include "geomVertexArrayFormat.h"
18 #include "graphicsStateGuardian.h"
19 #include "pStatTimer.h"
20 #include "internalName.h"
21 #include "config_dxgsg9.h"
22 
23 #define DEBUG_VERTEX_BUFFER false
24 
25 TypeHandle DXVertexBufferContext9::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: DXVertexBufferContext9::Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
35  GeomVertexArrayData *data) :
36  VertexBufferContext(pgo, data),
37  _vbuffer(NULL)
38 {
39  // Now fill in the FVF code.
40  const GeomVertexArrayFormat *array_format = data->get_array_format();
41 
42  // We have to start with the vertex data, and work up from there in
43  // order, since that's the way the FVF is defined.
44  int n = 0;
45  int num_columns = array_format->get_num_columns();
46 
47  _fvf = 0;
48 
49  if (n < num_columns &&
50  array_format->get_column(n)->get_name() == InternalName::get_vertex()) {
51  Geom::Contents contents = array_format->get_column(n)->get_contents();
52  ++n;
53 
54  int num_blend_values = 0;
55 
56  if (n < num_columns &&
57  array_format->get_column(n)->get_name() == InternalName::get_transform_weight()) {
58  // We have hardware vertex animation.
59  num_blend_values = array_format->get_column(n)->get_num_values();
60  ++n;
61  }
62 
63  if (n < num_columns &&
64  array_format->get_column(n)->get_name() == InternalName::get_transform_index()) {
65  // Furthermore, it's indexed vertex animation.
66  _fvf |= D3DFVF_LASTBETA_UBYTE4;
67  ++num_blend_values;
68  ++n;
69  }
70 
71  switch (num_blend_values) {
72  case 0:
73  _fvf |= D3DFVF_XYZ;
74  break;
75 
76  case 1:
77  _fvf |= D3DFVF_XYZB1;
78  break;
79 
80  case 2:
81  _fvf |= D3DFVF_XYZB2;
82  break;
83 
84  case 3:
85  _fvf |= D3DFVF_XYZB3;
86  break;
87 
88  case 4:
89  _fvf |= D3DFVF_XYZB4;
90  break;
91 
92  case 5:
93  _fvf |= D3DFVF_XYZB5;
94  break;
95  }
96  }
97 
98  if (n < num_columns &&
99  array_format->get_column(n)->get_name() == InternalName::get_normal()) {
100  _fvf |= D3DFVF_NORMAL;
101  ++n;
102  }
103  if (n < num_columns &&
104  array_format->get_column(n)->get_name() == InternalName::get_color()) {
105  _fvf |= D3DFVF_DIFFUSE;
106  ++n;
107  }
108 
109  // Now look for all of the texcoord names and enable them in the
110  // same order they appear in the array.
111  int texcoord_index = 0;
112  while (n < num_columns &&
113  array_format->get_column(n)->get_contents() == Geom::C_texcoord) {
114  const GeomVertexColumn *column = array_format->get_column(n);
115  switch (column->get_num_values()) {
116  case 1:
117  _fvf |= D3DFVF_TEXCOORDSIZE1(texcoord_index);
118  ++n;
119  break;
120  case 2:
121  _fvf |= D3DFVF_TEXCOORDSIZE2(texcoord_index);
122  ++n;
123  break;
124  case 3:
125  _fvf |= D3DFVF_TEXCOORDSIZE3(texcoord_index);
126  ++n;
127  break;
128  case 4:
129  _fvf |= D3DFVF_TEXCOORDSIZE4(texcoord_index);
130  ++n;
131  break;
132  }
133  ++texcoord_index;
134  }
135 
136  switch (texcoord_index) {
137  case 0:
138  break;
139  case 1:
140  _fvf |= D3DFVF_TEX1;
141  break;
142  case 2:
143  _fvf |= D3DFVF_TEX2;
144  break;
145  case 3:
146  _fvf |= D3DFVF_TEX3;
147  break;
148  case 4:
149  _fvf |= D3DFVF_TEX4;
150  break;
151  case 5:
152  _fvf |= D3DFVF_TEX5;
153  break;
154  case 6:
155  _fvf |= D3DFVF_TEX6;
156  break;
157  case 7:
158  _fvf |= D3DFVF_TEX7;
159  break;
160  case 8:
161  _fvf |= D3DFVF_TEX8;
162  break;
163  }
164 }
165 
166 ////////////////////////////////////////////////////////////////////
167 // Function: DXVertexBufferContext9::evict_lru
168 // Access: Public, Virtual
169 // Description: Evicts the page from the LRU. Called internally when
170 // the LRU determines that it is full. May also be
171 // called externally when necessary to explicitly evict
172 // the page.
173 //
174 // It is legal for this method to either evict the page
175 // as requested, do nothing (in which case the eviction
176 // will be requested again at the next epoch), or
177 // requeue itself on the tail of the queue (in which
178 // case the eviction will be requested again much
179 // later).
180 ////////////////////////////////////////////////////////////////////
181 void CLP(VertexBufferContext)::
182 evict_lru() {
183  dequeue_lru();
184 
185  if ( _vbuffer != NULL ) {
186  _vbuffer->Release();
187  _vbuffer = NULL;
188  }
189 
190  update_data_size_bytes(0);
191  mark_unloaded();
192 }
193 
A table of objects that are saved within the graphics context for reference by handle later...
This defines how a single column is interleaved within a vertex array stored within a Geom...
int get_num_values() const
Returns the number of numeric values of the column: the number of distinct numeric values that go int...
This is a special class object that holds all the information returned by a particular GSG to indicat...
Encapsulates all the communication with a particular instance of a given rendering backend...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is the data for one array of a GeomVertexData structure.