00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dxVertexBufferContext9.h"
00016 #include "geomVertexArrayData.h"
00017 #include "geomVertexArrayFormat.h"
00018 #include "graphicsStateGuardian.h"
00019 #include "pStatTimer.h"
00020 #include "internalName.h"
00021 #include "config_dxgsg9.h"
00022
00023 #define DEBUG_VERTEX_BUFFER false
00024
00025 TypeHandle DXVertexBufferContext9::_type_handle;
00026
00027
00028
00029
00030
00031
00032 CLP(VertexBufferContext)::
00033 CLP(VertexBufferContext)(CLP(GraphicsStateGuardian) *dxgsg,
00034 PreparedGraphicsObjects *pgo,
00035 GeomVertexArrayData *data) :
00036 VertexBufferContext(pgo, data),
00037 _vbuffer(NULL)
00038 {
00039
00040 const GeomVertexArrayFormat *array_format = data->get_array_format();
00041
00042
00043
00044 int n = 0;
00045 int num_columns = array_format->get_num_columns();
00046
00047 _fvf = 0;
00048
00049 if (n < num_columns &&
00050 array_format->get_column(n)->get_name() == InternalName::get_vertex()) {
00051 Geom::Contents contents = array_format->get_column(n)->get_contents();
00052 ++n;
00053
00054 int num_blend_values = 0;
00055
00056 if (n < num_columns &&
00057 array_format->get_column(n)->get_name() == InternalName::get_transform_weight()) {
00058
00059 num_blend_values = array_format->get_column(n)->get_num_values();
00060 ++n;
00061 }
00062
00063 if (n < num_columns &&
00064 array_format->get_column(n)->get_name() == InternalName::get_transform_index()) {
00065
00066 _fvf |= D3DFVF_LASTBETA_UBYTE4;
00067 ++num_blend_values;
00068 ++n;
00069 }
00070
00071 switch (num_blend_values) {
00072 case 0:
00073 _fvf |= D3DFVF_XYZ;
00074 break;
00075
00076 case 1:
00077 _fvf |= D3DFVF_XYZB1;
00078 break;
00079
00080 case 2:
00081 _fvf |= D3DFVF_XYZB2;
00082 break;
00083
00084 case 3:
00085 _fvf |= D3DFVF_XYZB3;
00086 break;
00087
00088 case 4:
00089 _fvf |= D3DFVF_XYZB4;
00090 break;
00091
00092 case 5:
00093 _fvf |= D3DFVF_XYZB5;
00094 break;
00095 }
00096 }
00097
00098 if (n < num_columns &&
00099 array_format->get_column(n)->get_name() == InternalName::get_normal()) {
00100 _fvf |= D3DFVF_NORMAL;
00101 ++n;
00102 }
00103 if (n < num_columns &&
00104 array_format->get_column(n)->get_name() == InternalName::get_color()) {
00105 _fvf |= D3DFVF_DIFFUSE;
00106 ++n;
00107 }
00108
00109
00110
00111 int texcoord_index = 0;
00112 while (n < num_columns &&
00113 array_format->get_column(n)->get_contents() == Geom::C_texcoord) {
00114 const GeomVertexColumn *column = array_format->get_column(n);
00115 switch (column->get_num_values()) {
00116 case 1:
00117 _fvf |= D3DFVF_TEXCOORDSIZE1(texcoord_index);
00118 ++n;
00119 break;
00120 case 2:
00121 _fvf |= D3DFVF_TEXCOORDSIZE2(texcoord_index);
00122 ++n;
00123 break;
00124 case 3:
00125 _fvf |= D3DFVF_TEXCOORDSIZE3(texcoord_index);
00126 ++n;
00127 break;
00128 case 4:
00129 _fvf |= D3DFVF_TEXCOORDSIZE4(texcoord_index);
00130 ++n;
00131 break;
00132 }
00133 ++texcoord_index;
00134 }
00135
00136 switch (texcoord_index) {
00137 case 0:
00138 break;
00139 case 1:
00140 _fvf |= D3DFVF_TEX1;
00141 break;
00142 case 2:
00143 _fvf |= D3DFVF_TEX2;
00144 break;
00145 case 3:
00146 _fvf |= D3DFVF_TEX3;
00147 break;
00148 case 4:
00149 _fvf |= D3DFVF_TEX4;
00150 break;
00151 case 5:
00152 _fvf |= D3DFVF_TEX5;
00153 break;
00154 case 6:
00155 _fvf |= D3DFVF_TEX6;
00156 break;
00157 case 7:
00158 _fvf |= D3DFVF_TEX7;
00159 break;
00160 case 8:
00161 _fvf |= D3DFVF_TEX8;
00162 break;
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 void CLP(VertexBufferContext)::
00182 evict_lru() {
00183 dequeue_lru();
00184
00185 if ( _vbuffer != NULL ) {
00186 _vbuffer->Release();
00187 _vbuffer = NULL;
00188 }
00189
00190 update_data_size_bytes(0);
00191 mark_unloaded();
00192 }
00193