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