Display State.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /******************************************************************************/
  2. enum ALPHA_MODE : Byte // Alpha Blending Modes
  3. {
  4. ALPHA_NONE , // Color:set , Alpha:set
  5. ALPHA_BLEND , // Color:blend , Alpha:increase
  6. ALPHA_BLEND_DEC, // Color:blend , Alpha:decrease
  7. ALPHA_ADD , // Color:add , Alpha:add
  8. ALPHA_MUL , // Color:multiply, Alpha:multiply
  9. ALPHA_MERGE , // Color:blend alpha premultiplied, Alpha:increase
  10. ALPHA_ADDBLEND_KEEP, // Color:add blended , Alpha:keep
  11. ALPHA_ADD_KEEP , // Color:add , Alpha:keep
  12. ALPHA_BLEND_FACTOR , // Color:blend , Alpha:blend with factor
  13. ALPHA_ADD_FACTOR , // Color:add , Alpha:add with factor
  14. #if EE_PRIVATE
  15. ALPHA_SETBLEND_SET , // Color:set blended, Alpha:set
  16. ALPHA_FACTOR , // Color:factor , Alpha:factor
  17. ALPHA_NONE_ADD , // Color:set , Alpha:add
  18. ALPHA_INVERT , // invert destination
  19. ALPHA_FONT , // Color:clear type, Alpha:increase
  20. ALPHA_FONT_DEC , // Color:clear type, Alpha:decrease
  21. //ALPHA_NONE_WRITE_A , // no blending, write only to A
  22. //ALPHA_NONE_WRITE_RGB, // no blending, write only to RGB
  23. //ALPHA_NONE_COVERAGE , // no blending with Alpha To Coverage
  24. //ALPHA_ADD_COVERAGE , // Color:add with Alpha To Coverage
  25. ALPHA_NUM , // number of alpha blending modes
  26. #endif
  27. };
  28. /******************************************************************************/
  29. #if EE_PRIVATE
  30. enum BIAS_MODE : Byte
  31. {
  32. BIAS_ZERO ,
  33. BIAS_SHADOW ,
  34. BIAS_OVERLAY,
  35. BIAS_NUM ,
  36. };
  37. enum STENCIL_MODE : Byte
  38. {
  39. STENCIL_NONE ,
  40. STENCIL_ALWAYS_SET ,
  41. STENCIL_MSAA_SET ,
  42. STENCIL_MSAA_TEST ,
  43. STENCIL_EDGE_SOFT_SET ,
  44. STENCIL_EDGE_SOFT_TEST,
  45. STENCIL_TERRAIN_TEST ,
  46. STENCIL_WATER_SET ,
  47. STENCIL_WATER_TEST ,
  48. STENCIL_OUTLINE_SET ,
  49. STENCIL_OUTLINE_TEST ,
  50. STENCIL_NUM ,
  51. };
  52. enum STENCIL_REF : Byte
  53. {
  54. STENCIL_REF_ZERO = 0,
  55. STENCIL_REF_MSAA =0x01, // Multi-Sampled Pixel
  56. STENCIL_REF_EDGE_SOFT=0x02, // Edge Soften
  57. STENCIL_REF_TERRAIN =0x04, // Terrain (to apply decals)
  58. STENCIL_REF_WATER =0x08, // Water
  59. STENCIL_REF_OUTLINE =0x10, // Outline
  60. };
  61. #endif
  62. struct DisplayState // Display States Control, this class methods can be called by the use of 'D' display object
  63. {
  64. ALPHA_MODE alpha ( )C {return _alpha;} // get alpha blending mode
  65. static ALPHA_MODE alpha (ALPHA_MODE alpha ); // set alpha blending mode and return previous mode
  66. static void clip (C Rect *rect=null); // set rectangle clipping, null for none
  67. static void clip (C Rect &rect ) {clip(&rect);} // set rectangle clipping
  68. static void depthLock (Bool on ); // set depth buffer usage and lock it
  69. static void depthUnlock( ); // unlock depth buffer usage
  70. static Bool depthWrite (Bool on ); // set depth buffer writing and return previous state
  71. static Bool lineSmooth (Bool on ); // set line smoothing (anti-aliasing) and return previous state, enabling this option can significantly reduce performance of drawing lines, default=false
  72. #if EE_PRIVATE
  73. #define COL_WRITE_R GPU_API(D3DCOLORWRITEENABLE_RED , D3D11_COLOR_WRITE_ENABLE_RED , 0x1)
  74. #define COL_WRITE_G GPU_API(D3DCOLORWRITEENABLE_GREEN, D3D11_COLOR_WRITE_ENABLE_GREEN, 0x2)
  75. #define COL_WRITE_B GPU_API(D3DCOLORWRITEENABLE_BLUE , D3D11_COLOR_WRITE_ENABLE_BLUE , 0x4)
  76. #define COL_WRITE_A GPU_API(D3DCOLORWRITEENABLE_ALPHA, D3D11_COLOR_WRITE_ENABLE_ALPHA, 0x8)
  77. #define FUNC_NEVER GPU_API(D3DCMP_NEVER , D3D11_COMPARISON_NEVER , GL_NEVER )
  78. #define FUNC_ALWAYS GPU_API(D3DCMP_ALWAYS , D3D11_COMPARISON_ALWAYS , GL_ALWAYS )
  79. #if REVERSE_DEPTH
  80. #define FUNC_LESS GPU_API(D3DCMP_GREATER , D3D11_COMPARISON_GREATER , GL_GREATER)
  81. #define FUNC_LESS_EQUAL GPU_API(D3DCMP_GREATEREQUAL, D3D11_COMPARISON_GREATER_EQUAL, GL_GEQUAL )
  82. #define FUNC_GREATER GPU_API(D3DCMP_LESS , D3D11_COMPARISON_LESS , GL_LESS )
  83. #else
  84. #define FUNC_LESS GPU_API(D3DCMP_LESS , D3D11_COMPARISON_LESS , GL_LESS )
  85. #define FUNC_LESS_EQUAL GPU_API(D3DCMP_LESSEQUAL , D3D11_COMPARISON_LESS_EQUAL , GL_LEQUAL )
  86. #define FUNC_GREATER GPU_API(D3DCMP_GREATER , D3D11_COMPARISON_GREATER , GL_GREATER)
  87. #endif
  88. #define COL_WRITE_RGB (COL_WRITE_R|COL_WRITE_G|COL_WRITE_B )
  89. #define COL_WRITE_RGBA (COL_WRITE_R|COL_WRITE_G|COL_WRITE_B|COL_WRITE_A)
  90. #define MAX_DX9_TEXTURES 261 // D3DVERTEXTEXTURESAMPLER3+1
  91. #define MAX_DX9_SHADER_CONSTANT (4096+32) // memory size (not number of constants), should be 4096 (256 Vec4's), however for unknown reason some shaders use more
  92. #define MAX_TEXTURES 20 // keep this low because of 'texClear'
  93. #define MAX_SHADER_BUFFERS 16
  94. void setDeviceSettings();
  95. void clearShader ();
  96. void del ();
  97. void create ();
  98. static void depth (Bool on );
  99. static void depthAllow (Bool on );
  100. static void depthFunc (UInt func );
  101. static void wire (Bool on );
  102. static void cull (Bool on );
  103. static void cullGL ( );
  104. static void alphaFactor (C Color &factor);
  105. static void clipForce (C RectI &rect );
  106. static void clipAllow (C RectI &rect );
  107. static void clipAllow (Bool on );
  108. static void clipPlane (Bool on );
  109. static void clipPlane (C PlaneM &plane );
  110. static void colWrite (Byte color_mask, Byte index=0);
  111. static void colWriteAllow(Byte color_mask);
  112. static void sampleMask (UInt mask );
  113. static void viewportForce(C RectI &rect );
  114. static void viewport (C RectI &rect, Bool allow_proj_matrix_update=true);
  115. static void vf (GPU_API(IDirect3DVertexDeclaration9, ID3D11InputLayout, VtxFormatGL) *vf);
  116. static void texVS (Int index, GPU_API(IDirect3DBaseTexture9*, ID3D11ShaderResourceView*, UInt) tex);
  117. static void texHS (Int index, GPU_API(IDirect3DBaseTexture9*, ID3D11ShaderResourceView*, UInt) tex);
  118. static void texDS (Int index, GPU_API(IDirect3DBaseTexture9*, ID3D11ShaderResourceView*, UInt) tex);
  119. static void texPS (Int index, GPU_API(IDirect3DBaseTexture9*, ID3D11ShaderResourceView*, UInt) tex);
  120. static void texClear ( GPU_API(IDirect3DBaseTexture9*, ID3D11ShaderResourceView*, UInt) tex);
  121. static void texBind (UInt mode, UInt tex); // needs to be called on OpenGL instead of calling 'glBindTexture'
  122. static void bias (BIAS_MODE bias);
  123. static void stencil (STENCIL_MODE mode);
  124. static void stencilRef (Byte ref );
  125. static void stencil (STENCIL_MODE mode, Byte ref);
  126. static void depth2DOn (Bool background=false); // this enables processing pixels only in foreground or background (depending on depth buffer value)
  127. static void depth2DOff ( ); // disables processing pixels only in foreground or background
  128. static void sampler2D ();
  129. static void sampler3D ();
  130. static void samplerShadow();
  131. static void set2D ();
  132. static void set3D ();
  133. static void fbo (UInt fbo);
  134. #if IOS
  135. Bool mainFBO ()C; // on iOS there's only one custom FBO used, so we have to check active targets manually
  136. #else
  137. Bool mainFBO ()C {return _fbo==0;}
  138. #endif
  139. #endif
  140. #if !EE_PRIVATE
  141. private:
  142. #endif
  143. ALPHA_MODE _alpha;
  144. Bool _depth_lock, _depth, _depth_write, _cull, _line_smooth, _wire, _clip, _clip_allow, _clip_real, _clip_plane_allow, _sampler2D;
  145. Byte _col_write[4], _stencil, _stencil_ref, _bias;
  146. UInt _depth_func, _sampler_filter[3], _sampler_address, _sample_mask, _fbo;
  147. RectI _viewport, _clip_recti;
  148. Rect _clip_rect;
  149. Color _alpha_factor;
  150. Vec4 _alpha_factor_v4, _clip_plane;
  151. #if EE_PRIVATE
  152. GPU_API(IDirect3DVertexDeclaration9, ID3D11InputLayout, VtxFormatGL) *_vf;
  153. #else
  154. Ptr _vf;
  155. #endif
  156. protected:
  157. DisplayState();
  158. };
  159. /******************************************************************************/