Panda3D
 All Classes Functions Variables Enumerations
dxVertexBufferContext9.cxx
00001 // Filename: dxVertexBufferContext9.cxx
00002 // Created by:  drose (18Mar05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
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 //     Function: DXVertexBufferContext9::Constructor
00029 //       Access: Public
00030 //  Description:
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   // Now fill in the FVF code.
00040   const GeomVertexArrayFormat *array_format = data->get_array_format();
00041 
00042   // We have to start with the vertex data, and work up from there in
00043   // order, since that's the way the FVF is defined.
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       // We have hardware vertex animation.
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       // Furthermore, it's indexed vertex animation.
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   // Now look for all of the texcoord names and enable them in the
00110   // same order they appear in the array.
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 //     Function: DXVertexBufferContext9::evict_lru
00168 //       Access: Public, Virtual
00169 //  Description: Evicts the page from the LRU.  Called internally when
00170 //               the LRU determines that it is full.  May also be
00171 //               called externally when necessary to explicitly evict
00172 //               the page.
00173 //
00174 //               It is legal for this method to either evict the page
00175 //               as requested, do nothing (in which case the eviction
00176 //               will be requested again at the next epoch), or
00177 //               requeue itself on the tail of the queue (in which
00178 //               case the eviction will be requested again much
00179 //               later).
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 
 All Classes Functions Variables Enumerations