gxmesh.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef GXMESH_H
  2. #define GXMESH_H
  3. #include <d3d.h>
  4. class gxGraphics;
  5. class gxMesh{
  6. public:
  7. gxMesh( gxGraphics *graphics,IDirect3DVertexBuffer7 *verts,WORD *indicies,int max_verts,int max_tris );
  8. ~gxMesh();
  9. int maxVerts()const{ return max_verts; }
  10. int maxTris()const{ return max_tris; }
  11. bool dirty()const{ return mesh_dirty; }
  12. void render( int first_vert,int vert_cnt,int first_tri,int tri_cnt );
  13. void backup();
  14. void restore();
  15. private:
  16. struct dxVertex{
  17. float coords[3];
  18. float normal[3];
  19. unsigned argb;
  20. float tex_coords[4];
  21. };
  22. gxGraphics *graphics;
  23. IDirect3DVertexBuffer7 *vertex_buff;
  24. WORD *tri_indices;
  25. int max_verts,max_tris;
  26. bool mesh_dirty;
  27. dxVertex *locked_verts;
  28. /***** GX INTERFACE *****/
  29. public:
  30. bool lock( bool all );
  31. void unlock();
  32. //VERY NAUGHTY!!!!!
  33. void setVertex( int n,const void *v ){
  34. memcpy( locked_verts+n,v,sizeof(dxVertex) );
  35. }
  36. void setVertex( int n,const float coords[3],const float normal[3],const float tex_coords[2][2] ){
  37. dxVertex *t=locked_verts+n;
  38. memcpy( t->coords,coords,12 );
  39. memcpy( t->normal,normal,12 );
  40. t->argb=0xffffffff;
  41. memcpy( t->tex_coords,tex_coords,16 );
  42. }
  43. void setVertex( int n,const float coords[3],const float normal[3],unsigned argb,const float tex_coords[2][2] ){
  44. dxVertex *t=locked_verts+n;
  45. memcpy( t->coords,coords,12 );
  46. memcpy( t->normal,normal,12 );
  47. t->argb=argb;
  48. memcpy( t->tex_coords,tex_coords,16 );
  49. }
  50. void setTriangle( int n,int v0,int v1,int v2 ){
  51. tri_indices[n*3]=v0;
  52. tri_indices[n*3+1]=v1;
  53. tri_indices[n*3+2]=v2;
  54. }
  55. };
  56. #endif