gxmesh.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "std.h"
  2. #include "gxmesh.h"
  3. #include "gxgraphics.h"
  4. #include "gxruntime.h"
  5. extern gxRuntime *gx_runtime;
  6. gxMesh::gxMesh( gxGraphics *g,IDirect3DVertexBuffer7 *vs,WORD *is,int max_vs,int max_ts ):
  7. graphics(g),locked_verts(0),vertex_buff(vs),tri_indices(is),max_verts(max_vs),max_tris(max_ts),mesh_dirty(false){
  8. }
  9. gxMesh::~gxMesh(){
  10. unlock();
  11. vertex_buff->Release();
  12. delete[] tri_indices;
  13. }
  14. bool gxMesh::lock( bool all ){
  15. if( locked_verts ) return true;
  16. //V1.104
  17. //int flags=all ? DDLOCK_DISCARDCONTENTS : 0;
  18. //V1.105
  19. //int flags=all ? DDLOCK_DISCARDCONTENTS : DDLOCK_NOOVERWRITE;
  20. //V1.104/1.105
  21. //if( vertex_buff->Lock( DDLOCK_WRITEONLY|DDLOCK_WAIT|flags,(void**)&locked_verts,0 )>=0 ){
  22. //V1.1.06...
  23. int flags=DDLOCK_WAIT|DDLOCK_WRITEONLY;
  24. //XP or less?
  25. if( graphics->runtime->osinfo.dwMajorVersion<6 ){
  26. flags|=(all ? DDLOCK_DISCARDCONTENTS : DDLOCK_NOOVERWRITE);
  27. }
  28. if( vertex_buff->Lock( flags,(void**)&locked_verts,0 )>=0 ){
  29. mesh_dirty=false;
  30. return true;
  31. }
  32. static dxVertex *err_verts=new dxVertex[32768];
  33. locked_verts=err_verts;
  34. return true;
  35. }
  36. void gxMesh::unlock(){
  37. if( locked_verts ){
  38. vertex_buff->Unlock();
  39. locked_verts=0;
  40. }
  41. }
  42. void gxMesh::backup(){
  43. unlock();
  44. }
  45. void gxMesh::restore(){
  46. mesh_dirty=true;
  47. }
  48. /*
  49. void gxMesh::backup(){
  50. unlock();
  51. if( backup_verts ){
  52. delete[] backup_verts;
  53. backup_verts=0;
  54. }
  55. dxVertex *verts;
  56. if( vertex_buff->Lock( DDLOCK_READONLY|DDLOCK_WAIT,(void**)&verts,0 )>=0 ){
  57. backup_verts=d_new dxVertex[ max_verts ];
  58. memcpy( backup_verts,verts,sizeof(dxVertex)*max_verts );
  59. vertex_buff->Unlock();
  60. }
  61. }
  62. void gxMesh::restore(){
  63. if( !backup_verts ) return;
  64. dxVertex *verts;
  65. if( vertex_buff->Lock( DDLOCK_WRITEONLY|DDLOCK_WAIT,(void**)&verts,0 )>=0 ){
  66. memcpy( verts,backup_verts,sizeof(dxVertex)*max_verts );
  67. vertex_buff->Unlock();
  68. }
  69. delete[] backup_verts;
  70. backup_verts=0;
  71. }
  72. */
  73. void gxMesh::render( int first_vert,int vert_cnt,int first_tri,int tri_cnt ){
  74. unlock();
  75. graphics->dir3dDev->DrawIndexedPrimitiveVB(
  76. D3DPT_TRIANGLELIST,
  77. vertex_buff,first_vert,vert_cnt,
  78. tri_indices+first_tri*3,tri_cnt*3,0 );
  79. }