gxscene.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef GXSCENE_H
  2. #define GXSCENE_H
  3. #include <map>
  4. #include <d3d.h>
  5. #include "gxlight.h"
  6. class gxCanvas;
  7. class gxMesh;
  8. class gxLight;
  9. class gxGraphics;
  10. class gxTexture;
  11. class gxScene{
  12. public:
  13. gxGraphics *graphics;
  14. IDirect3DDevice7 *dir3dDev;
  15. gxScene( gxGraphics *graphics,gxCanvas *target );
  16. ~gxScene();
  17. void setEnabled( gxLight *light,bool enabled );
  18. /***** GX INTERFACE *****/
  19. public:
  20. enum{
  21. MAX_TEXTURES= 8
  22. };
  23. enum{
  24. FX_FULLBRIGHT= 0x0001,
  25. FX_VERTEXCOLOR= 0x0002,
  26. FX_FLATSHADED= 0x0004,
  27. FX_NOFOG= 0x0008,
  28. FX_DOUBLESIDED= 0x0010,
  29. FX_VERTEXALPHA= 0x0020,
  30. FX_ALPHATEST= 0x2000,
  31. FX_CONDLIGHT= 0x4000,
  32. FX_EMISSIVE= 0x8000
  33. };
  34. enum{
  35. BLEND_REPLACE= 0,
  36. BLEND_ALPHA= 1,
  37. BLEND_MULTIPLY= 2,
  38. BLEND_ADD= 3,
  39. BLEND_DOT3= 4,
  40. BLEND_MULTIPLY2=5,
  41. };
  42. enum{
  43. ZMODE_NORMAL= 0,
  44. ZMODE_DISABLE= 1,
  45. ZMODE_CMPONLY= 2
  46. };
  47. enum{
  48. FOG_NONE= 0,
  49. FOG_LINEAR= 1
  50. };
  51. enum{
  52. TEX_COORDS2= 0x0001
  53. };
  54. struct Matrix{
  55. float elements[4][3];
  56. };
  57. struct RenderState{
  58. float color[3];
  59. float shininess,alpha;
  60. int blend,fx;
  61. struct TexState{
  62. gxCanvas *canvas;
  63. const Matrix *matrix;
  64. int blend,flags;
  65. }tex_states[MAX_TEXTURES];
  66. };
  67. //state
  68. int hwTexUnits();
  69. int gfxDriverCaps3D();
  70. void setWBuffer( bool enable );
  71. void setHWMultiTex( bool enable );
  72. void setDither( bool enable );
  73. void setAntialias( bool enable );
  74. void setWireframe( bool enable );
  75. void setFlippedTris( bool enable );
  76. void setAmbient( const float rgb[3] );
  77. void setAmbient2( const float rgb[3] );
  78. void setFogColor( const float rgb[3] );
  79. void setFogRange( float nr,float fr );
  80. void setFogMode( int mode );
  81. void setZMode( int mode );
  82. void setViewport( int x,int y,int w,int h );
  83. void setOrthoProj( float nr,float fr,float nr_w,float nr_h );
  84. void setPerspProj( float nr,float fr,float nr_w,float nr_h );
  85. void setViewMatrix( const Matrix *matrix );
  86. void setWorldMatrix( const Matrix *matrix );
  87. void setRenderState( const RenderState &state );
  88. //rendering
  89. bool begin( const std::vector<gxLight*> &lights );
  90. void clear( const float rgb[3],float alpha,float z,bool clear_argb,bool clear_z );
  91. void render( gxMesh *mesh,int first_vert,int vert_cnt,int first_tri,int tri_cnt );
  92. void end();
  93. //lighting
  94. gxLight *createLight( int flags );
  95. void freeLight( gxLight *l );
  96. //info
  97. int getTrianglesDrawn()const;
  98. private:
  99. gxCanvas *target;
  100. bool wbuffer,dither,antialias,wireframe,flipped;
  101. unsigned ambient,ambient2,fogcolor;
  102. int caps_level,fogmode,zmode;
  103. float fogrange_nr,fogrange_fr;
  104. D3DVIEWPORT7 viewport;
  105. bool ortho_proj;
  106. float frustum_nr,frustum_fr,frustum_w,frustum_h;
  107. D3DMATRIX projmatrix,viewmatrix,worldmatrix;
  108. D3DMATRIX inv_viewmatrix;
  109. D3DMATERIAL7 material;
  110. float shininess;
  111. int blend,fx;
  112. struct TexState{
  113. gxCanvas *canvas;
  114. int blend,flags;
  115. D3DMATRIX matrix;
  116. bool mat_valid;
  117. };
  118. TexState texstate[MAX_TEXTURES];
  119. int n_texs,tris_drawn;
  120. std::set<gxLight*> _allLights;
  121. std::vector<gxLight*> _curLights;
  122. int d3d_rs[160];
  123. int d3d_tss[8][32];
  124. void setRS( int n,int t );
  125. void setTSS( int n,int s,int t );
  126. void setLights();
  127. void setZMode();
  128. void setAmbient();
  129. void setFogMode();
  130. void setTriCull();
  131. void setTexState( int index,const TexState &state,bool set_blend );
  132. };
  133. #endif