/opengles/src/RasterizerState.h

http://ftk.googlecode.com/ · C Header · 1245 lines · 956 code · 232 blank · 57 comment · 71 complexity · 496f7b6f1dcd8abb9359d4e8647b54ca MD5 · raw file

  1. #ifndef EGL_RASTERIZER_STATE_H
  2. #define EGL_RASTERIZER_STATE_H 1
  3. // ==========================================================================
  4. //
  5. // RasterizerState Rasterizer State Class for 3D Rendering Library
  6. //
  7. // The rasterizer state maintains all the state information
  8. // that is necessary to determine the details of the
  9. // next primitive to be scan-converted.
  10. //
  11. // --------------------------------------------------------------------------
  12. //
  13. // 10-10-2003 Hans-Martin Will initial version
  14. //
  15. // --------------------------------------------------------------------------
  16. //
  17. // Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  18. //
  19. // Redistribution and use in source and binary forms, with or without
  20. // modification, are permitted provided that the following conditions are
  21. // met:
  22. //
  23. // * Redistributions of source code must retain the above copyright
  24. // notice, this list of conditions and the following disclaimer.
  25. // * Redistributions in binary form must reproduce the above copyright
  26. // notice, this list of conditions and the following disclaimer in the
  27. // documentation and/or other materials provided with the distribution.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  34. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  39. // THE POSSIBILITY OF SUCH DAMAGE.
  40. //
  41. // ==========================================================================
  42. #include "OGLES.h"
  43. #include "fixed.h"
  44. #include "linalg.h"
  45. #include "Color.h"
  46. namespace EGL {
  47. class Rasterizer;
  48. class MultiTexture;
  49. class RasterizerState {
  50. friend class Rasterizer;
  51. friend class CodeGenerator;
  52. public:
  53. enum Limits {
  54. LogMaxTextureSize = 12,
  55. MaxTextureSize = 1 << LogMaxTextureSize
  56. };
  57. enum LogicOp {
  58. LogicOpInvalid = -1,
  59. LogicOpClear,
  60. LogicOpAnd,
  61. LogicOpAndReverse,
  62. LogicOpCopy,
  63. LogicOpAndInverted,
  64. LogicOpNoop,
  65. LogicOpXor,
  66. LogicOpOr,
  67. LogicOpNor,
  68. LogicOpEquiv,
  69. LogicOpInvert,
  70. LogicOpOrReverse,
  71. LogicOpCopyInverted,
  72. LogicOpOrInverted,
  73. LogicOpNand,
  74. LogicOpSet
  75. };
  76. enum ComparisonFunc {
  77. CompFuncInvalid = -1,
  78. CompFuncNever,
  79. CompFuncLess,
  80. CompFuncEqual,
  81. CompFuncLEqual,
  82. CompFuncGreater,
  83. CompFuncNotEqual,
  84. CompFuncGEqual,
  85. CompFuncAlways
  86. };
  87. enum BlendFuncDst {
  88. BlendFuncDstInvalid = -1,
  89. BlendFuncDstZero,
  90. BlendFuncDstOne,
  91. BlendFuncDstSrcColor,
  92. BlendFuncDstOneMinusSrcColor,
  93. BlendFuncDstSrcAlpha,
  94. BlendFuncDstOneMinusSrcAlpha,
  95. BlendFuncDstDstAlpha,
  96. BlendFuncDstOneMinusDstAlpha
  97. };
  98. enum BlendFuncSrc {
  99. BlendFuncSrcInvalid = -1,
  100. BlendFuncSrcZero,
  101. BlendFuncSrcOne,
  102. BlendFuncSrcDstColor,
  103. BlendFuncSrcOneMinusDstColor,
  104. BlendFuncSrcSrcAlpha,
  105. BlendFuncSrcOneMinusSrcAlpha,
  106. BlendFuncSrcDstAlpha,
  107. BlendFuncSrcOneMinusDstAlpha,
  108. BlendFuncSrcSrcAlphaSaturate
  109. };
  110. enum StencilOp {
  111. StencilOpInvalid = -1,
  112. StencilOpZero,
  113. StencilOpKeep,
  114. StencilOpReplace,
  115. StencilOpIncr,
  116. StencilOpDecr,
  117. StencilOpInvert
  118. };
  119. enum ShadingModel {
  120. ShadeModelInvalid = -1,
  121. ShadeModelFlat,
  122. ShadeModelSmooth
  123. };
  124. enum TextureMode {
  125. TextureModeInvalid = -1,
  126. TextureModeDecal,
  127. TextureModeReplace,
  128. TextureModeBlend,
  129. TextureModeAdd,
  130. TextureModeModulate,
  131. TextureModeCombine
  132. };
  133. enum TextureModeCombineFunc {
  134. TextureModeCombineReplace,
  135. TextureModeCombineModulate,
  136. TextureModeCombineAdd,
  137. TextureModeCombineAddSigned,
  138. TextureModeCombineInterpolate,
  139. TextureModeCombineSubtract,
  140. TextureModeCombineDot3RGB,
  141. TextureModeCombineDot3RGBA
  142. };
  143. enum TextureCombineSrc {
  144. TextureCombineSrcTexture,
  145. TextureCombineSrcConstant,
  146. TextureCombineSrcPrimaryColor,
  147. TextureCombineSrcPrevious
  148. };
  149. enum TextureCombineOp {
  150. TextureCombineOpSrcColor,
  151. TextureCombineOpOneMinusSrcColor,
  152. TextureCombineOpSrcAlpha,
  153. TextureCombineOpOneMinusSrcAlpha
  154. };
  155. enum WrappingMode {
  156. WrappingModeInvalid = -1,
  157. WrappingModeClampToEdge,
  158. WrappingModeRepeat
  159. };
  160. enum FilterMode {
  161. FilterModeInvalid = -1,
  162. FilterModeNone,
  163. FilterModeNearest,
  164. FilterModeLinear
  165. };
  166. enum TextureFormat {
  167. TextureFormatInvalid = -1,
  168. TextureFormatAlpha = 0, // 8
  169. TextureFormatLuminance = 1, // 8
  170. TextureFormatLuminanceAlpha = 2, // 8-8
  171. TextureFormatRGB8 = 3, // 8-8-8
  172. TextureFormatRGBA8 = 4, // 8-8-8-8
  173. TextureFormatRGB565 = 5, // 5-6-5
  174. TextureFormatRGBA4444 = 6, // 4-4-4-4
  175. TextureFormatRGBA5551 = 7 // 5-5-5-1
  176. };
  177. public:
  178. RasterizerState();
  179. bool CompareCommon(const RasterizerState& other) const;
  180. bool ComparePoint(const RasterizerState& other) const;
  181. bool CompareLine(const RasterizerState& other) const;
  182. bool ComparePolygon(const RasterizerState& other) const;
  183. typedef bool (RasterizerState::*CompareFunction)(const RasterizerState& other) const;
  184. // ----------------------------------------------------------------------
  185. // Primitive rendering state
  186. // ----------------------------------------------------------------------
  187. void SetTexEnvColor(size_t unit, const Color& color);
  188. Color GetTexEnvColor(size_t unit) const;
  189. void SetTextureMode(size_t unit, TextureMode mode);
  190. TextureMode GetTextureMode(size_t unit) const;
  191. void SetTextureCombineFuncRGB(size_t unit, TextureModeCombineFunc func);
  192. TextureModeCombineFunc GetTextureCombineFuncRGB(size_t unit) const;
  193. void SetTextureCombineFuncAlpha(size_t unit, TextureModeCombineFunc func);
  194. TextureModeCombineFunc GetTextureCombineFuncAlpha(size_t unit) const;
  195. void SetTextureCombineSrcRGB(size_t unit, size_t idx, TextureCombineSrc src);
  196. TextureCombineSrc GetTextureCombineSrcRGB(size_t unit, size_t idx) const;
  197. void SetTextureCombineSrcAlpha(size_t unit, size_t idx, TextureCombineSrc src);
  198. TextureCombineSrc GetTextureCombineSrcAlpha(size_t unit, size_t idx) const;
  199. void SetTextureCombineOpRGB(size_t unit, size_t idx, TextureCombineOp op);
  200. TextureCombineOp GetTextureCombineOpRGB(size_t unit, size_t idx) const;
  201. void SetTextureCombineOpAlpha(size_t unit, size_t idx, TextureCombineOp op);
  202. TextureCombineOp GetTextureCombineOpAlpha(size_t unit, size_t idx) const;
  203. void SetTextureScaleRGB(size_t unit, EGL_Fixed scale);
  204. EGL_Fixed GetTextureScaleRGB(size_t unit) const;
  205. void SetTextureScaleAlpha(size_t unit, EGL_Fixed scale);
  206. EGL_Fixed GetTextureScaleAlpha(size_t unit) const;
  207. void SetMinFilterMode(size_t unit, FilterMode mode);
  208. void SetMagFilterMode(size_t unit, FilterMode mode);
  209. void SetMipmapFilterMode(size_t unit, FilterMode mode);
  210. void SetWrappingModeS(size_t unit, WrappingMode mode);
  211. void SetWrappingModeT(size_t unit, WrappingMode mode);
  212. FilterMode GetMinFilterMode(size_t unit) const { return m_Texture[unit].MinFilterMode; }
  213. FilterMode GetMagFilterMode(size_t unit) const { return m_Texture[unit].MagFilterMode; }
  214. FilterMode GetMipmapFilterMode(size_t unit) const { return m_Texture[unit].MipmapFilterMode; }
  215. WrappingMode GetWrappingModeS(size_t unit) const { return m_Texture[unit].WrappingModeS; }
  216. WrappingMode GetWrappingModeT(size_t unit) const { return m_Texture[unit].WrappingModeT; }
  217. void SetInternalFormat(size_t unit, TextureFormat format);
  218. void SetDepthRange(EGL_Fixed zNear, EGL_Fixed zFar);
  219. void SetFogColor(const Color& color);
  220. Color GetFogColor() const;
  221. void EnableFog(bool enabled);
  222. bool IsEnabledFog() const;
  223. void SetLineWidth(EGL_Fixed width);
  224. void SetLineSmoothEnabled(bool enabled);
  225. bool IsLineSmoothEnabled() const;
  226. void SetLogicOp(LogicOp opcode);
  227. LogicOp GetLogicOp() const;
  228. void SetShadeModel(ShadingModel mode);
  229. ShadingModel GetShadeModel() const;
  230. void EnableTexture(size_t unit, bool enabled);
  231. bool IsEnabledTexture(size_t unit) const;
  232. void SetPointSmoothEnabled(bool enabled);
  233. bool IsPointSmoothEnabled() const;
  234. void SetPointSpriteEnabled(bool enabled);
  235. bool IsPointSpriteEnabled() const;
  236. void SetPointCoordReplaceEnabled(size_t unit, bool enabled);
  237. bool IsPointCoordReplaceEnabled(size_t unit) const;
  238. void EnablePolygonOffsetFill(bool enabled);
  239. bool IsEnabledPolygonOffsetFill() const;
  240. void SetPolygonOffset(EGL_Fixed factor, EGL_Fixed units);
  241. void SetSampleCoverage(EGL_Fixed value, bool invert);
  242. EGL_Fixed GetPolygonOffsetFactor() const;
  243. EGL_Fixed GetPolygonOffsetUnits() const;
  244. EGL_Fixed GetSampleCoverage() const;
  245. bool GetSampleCoverageInvert() const;
  246. // ----------------------------------------------------------------------
  247. // Fragment rendering state
  248. // ----------------------------------------------------------------------
  249. void SetAlphaFunc(ComparisonFunc func, EGL_Fixed ref);
  250. ComparisonFunc GetAlphaFunc() const;
  251. EGL_Fixed GetAlphaRef() const;
  252. void SetBlendFunc(BlendFuncSrc sfactor, BlendFuncDst dfactor);
  253. BlendFuncSrc GetBlendFuncSrc() const;
  254. BlendFuncDst GetBlendFuncDst() const;
  255. void SetColorMask(bool red, bool green, bool blue, bool alpha);
  256. Color GetColorMask() const;
  257. void SetDepthFunc(ComparisonFunc func);
  258. ComparisonFunc GetDepthFunc() const;
  259. void SetDepthMask(bool flag);
  260. bool GetDepthMask() const;
  261. void SetScissor(I32 x, I32 y, U32 width, U32 height);
  262. void EnableAlphaTest(bool enabled);
  263. void EnableDepthTest(bool enabled);
  264. void EnableLogicOp(bool enabled);
  265. void EnableScissorTest(bool enabled);
  266. void EnableBlending(bool enabled);
  267. void EnableStencilTest(bool enabled);
  268. bool IsEnabledAlphaTest() const;
  269. bool IsEnabledDepthTest() const;
  270. bool IsEnabledLogicOp() const;
  271. bool IsEnabledScissorTest() const;
  272. bool IsEnabledBlending() const;
  273. bool IsEnabledStencilTest() const;
  274. void SetStencilFunc(ComparisonFunc func, I32 ref, U32 mask);
  275. ComparisonFunc GetStencilFunc() const;
  276. I32 GetStencilRef() const;
  277. I32 GetStencilComparisonMask() const;
  278. void SetStencilMask(U32 mask);
  279. U32 GetStencilMask() const;
  280. void SetStencilOp(StencilOp fail, StencilOp zfail, StencilOp zpass);
  281. StencilOp GetStencilOpFail() const;
  282. StencilOp GetStencilOpFailZFail() const;
  283. StencilOp GetStencilOpFailZPass() const;
  284. private:
  285. // ----------------------------------------------------------------------
  286. // Primitve specific rendering state
  287. // ----------------------------------------------------------------------
  288. struct PointState {
  289. PointState() {
  290. SmoothEnabled = false;
  291. SpriteEnabled = false;
  292. CoordReplaceEnabled = false;
  293. }
  294. PointState(const PointState& other) {
  295. SmoothEnabled = other.SmoothEnabled;
  296. SpriteEnabled = other.SpriteEnabled;
  297. CoordReplaceEnabled = other.CoordReplaceEnabled;
  298. }
  299. PointState& operator=(const PointState& other) {
  300. SmoothEnabled = other.SmoothEnabled;
  301. SpriteEnabled = other.SpriteEnabled;
  302. CoordReplaceEnabled = other.CoordReplaceEnabled;
  303. return *this;
  304. }
  305. bool operator==(const PointState& other) const {
  306. return SmoothEnabled == other.SmoothEnabled &&
  307. SpriteEnabled == other.SpriteEnabled &&
  308. (!SpriteEnabled ||
  309. CoordReplaceEnabled == other.CoordReplaceEnabled);
  310. }
  311. bool SmoothEnabled;
  312. bool SpriteEnabled;
  313. bool CoordReplaceEnabled;
  314. }
  315. m_Point;
  316. struct LineState {
  317. LineState() {
  318. SmoothEnabled = false;
  319. Width = EGL_ONE;
  320. }
  321. LineState(const LineState& other) {
  322. SmoothEnabled = other.SmoothEnabled;
  323. Width = other.Width;
  324. }
  325. LineState& operator=(const LineState& other) {
  326. SmoothEnabled = other.SmoothEnabled;
  327. Width = other.Width;
  328. return *this;
  329. }
  330. bool operator==(const LineState& other) const {
  331. return SmoothEnabled == other.SmoothEnabled &&
  332. Width == other.Width;
  333. }
  334. bool SmoothEnabled;
  335. EGL_Fixed Width; // current line width
  336. }
  337. m_Line;
  338. struct PolygonState {
  339. PolygonState() {
  340. OffsetFillEnabled = false;
  341. OffsetFactor = 0;
  342. OffsetUnits = 0;
  343. }
  344. PolygonState(const PolygonState& other) {
  345. OffsetFillEnabled = other.OffsetFillEnabled;
  346. OffsetFactor = other.OffsetFactor;
  347. OffsetUnits = other.OffsetUnits;
  348. }
  349. PolygonState& operator=(const PolygonState& other) {
  350. OffsetFillEnabled = other.OffsetFillEnabled;
  351. OffsetFactor = other.OffsetFactor;
  352. OffsetUnits = other.OffsetUnits;
  353. return *this;
  354. }
  355. bool operator==(const PolygonState& other) const {
  356. return OffsetFillEnabled == other.OffsetFillEnabled &&
  357. (!OffsetFillEnabled ||
  358. OffsetFactor == other.OffsetFactor &&
  359. OffsetUnits == other.OffsetUnits);
  360. }
  361. bool OffsetFillEnabled;
  362. EGL_Fixed OffsetFactor;
  363. EGL_Fixed OffsetUnits;
  364. }
  365. m_Polygon;
  366. // ----------------------------------------------------------------------
  367. // General rendering state
  368. // ----------------------------------------------------------------------
  369. struct FogState {
  370. FogState() {
  371. Enabled = false;
  372. Color = EGL::Color(0, 0, 0, 0);
  373. }
  374. FogState(const FogState& other) {
  375. Enabled = other.Enabled;
  376. Color = other.Color;
  377. }
  378. FogState& operator=(const FogState& other) {
  379. Enabled = other.Enabled;
  380. Color = other.Color;
  381. return *this;
  382. }
  383. bool operator==(const FogState& other) const {
  384. return Enabled == other.Enabled &&
  385. (!Enabled || Color == other.Color);
  386. }
  387. bool Enabled;
  388. EGL::Color Color;
  389. }
  390. m_Fog;
  391. struct TextureState {
  392. TextureState() {
  393. Enabled = false;
  394. EnvColor = Color(0, 0, 0, 0);
  395. Mode = TextureModeModulate;
  396. MinFilterMode = FilterModeNearest;
  397. MagFilterMode = FilterModeNearest;
  398. MipmapFilterMode = FilterModeNone;
  399. WrappingModeS = WrappingModeRepeat;
  400. WrappingModeT = WrappingModeRepeat;
  401. InternalFormat = TextureFormatLuminance;
  402. CombineFuncRGB = TextureModeCombineModulate;
  403. CombineFuncAlpha = TextureModeCombineModulate;
  404. CombineSrcRGB[0] = CombineSrcAlpha[0] = TextureCombineSrcTexture;
  405. CombineSrcRGB[1] = CombineSrcAlpha[1] = TextureCombineSrcPrevious;
  406. CombineSrcRGB[2] = CombineSrcAlpha[2] = TextureCombineSrcConstant;
  407. CombineOpRGB[0] = CombineOpRGB[1] = TextureCombineOpSrcColor;
  408. CombineOpRGB[2] = CombineOpAlpha[0] =
  409. CombineOpAlpha[1] = CombineOpAlpha[2] = TextureCombineOpSrcAlpha;
  410. ScaleRGB = ScaleAlpha = EGL_ONE;
  411. }
  412. TextureState(const TextureState& other) {
  413. Enabled = other.Enabled;
  414. EnvColor = other.EnvColor;
  415. Mode = other.Mode;
  416. MinFilterMode = other.MinFilterMode;
  417. MagFilterMode = other.MagFilterMode;
  418. MipmapFilterMode = other.MipmapFilterMode;
  419. WrappingModeS = other.WrappingModeS;
  420. WrappingModeT = other.WrappingModeT;
  421. InternalFormat = other.InternalFormat;
  422. CombineFuncRGB = other.CombineFuncRGB;
  423. CombineFuncAlpha = other.CombineFuncAlpha;
  424. for (int i = 0; i < 3; ++i) {
  425. CombineSrcRGB[i] = other.CombineSrcRGB[i];
  426. CombineSrcAlpha[i] = other.CombineSrcAlpha[i];
  427. CombineOpRGB[i] = other.CombineOpRGB[i];
  428. CombineOpAlpha[i] = other.CombineOpAlpha[i];
  429. }
  430. ScaleRGB = other.ScaleRGB;
  431. ScaleAlpha = other.ScaleAlpha;
  432. }
  433. TextureState& operator=(const TextureState& other) {
  434. Enabled = other.Enabled;
  435. EnvColor = other.EnvColor;
  436. Mode = other.Mode;
  437. MinFilterMode = other.MinFilterMode;
  438. MagFilterMode = other.MagFilterMode;
  439. MipmapFilterMode = other.MipmapFilterMode;
  440. WrappingModeS = other.WrappingModeS;
  441. WrappingModeT = other.WrappingModeT;
  442. InternalFormat = other.InternalFormat;
  443. CombineFuncRGB = other.CombineFuncRGB;
  444. CombineFuncAlpha = other.CombineFuncAlpha;
  445. for (int i = 0; i < 3; ++i) {
  446. CombineSrcRGB[i] = other.CombineSrcRGB[i];
  447. CombineSrcAlpha[i] = other.CombineSrcAlpha[i];
  448. CombineOpRGB[i] = other.CombineOpRGB[i];
  449. CombineOpAlpha[i] = other.CombineOpAlpha[i];
  450. }
  451. ScaleRGB = other.ScaleRGB;
  452. ScaleAlpha = other.ScaleAlpha;
  453. return *this;
  454. }
  455. bool operator==(const TextureState& other) const {
  456. if (!(Enabled == other.Enabled))
  457. return false;
  458. if (!Enabled)
  459. return true;
  460. if (!(EnvColor == other.EnvColor) ||
  461. Mode != other.Mode ||
  462. MinFilterMode != other.MinFilterMode ||
  463. MagFilterMode != other.MagFilterMode ||
  464. MipmapFilterMode != other.MipmapFilterMode ||
  465. WrappingModeS != other.WrappingModeS ||
  466. WrappingModeT != other.WrappingModeT ||
  467. InternalFormat != other.InternalFormat)
  468. return false;
  469. if (Mode == TextureModeCombine) {
  470. if (CombineFuncRGB != other.CombineFuncRGB ||
  471. CombineFuncAlpha != other.CombineFuncAlpha ||
  472. ScaleRGB != other.ScaleRGB ||
  473. ScaleAlpha != other.ScaleAlpha)
  474. return false;
  475. for (int i = 0; i < 3; ++i) {
  476. if (CombineSrcRGB[i] != other.CombineSrcRGB[i] ||
  477. CombineSrcAlpha[i] != other.CombineSrcAlpha[i] ||
  478. CombineOpRGB[i] != other.CombineOpRGB[i] ||
  479. CombineOpAlpha[i] != other.CombineOpAlpha[i])
  480. return false;
  481. }
  482. }
  483. return true;
  484. }
  485. bool Enabled;
  486. Color EnvColor;
  487. TextureMode Mode;
  488. TextureModeCombineFunc CombineFuncRGB, CombineFuncAlpha;
  489. TextureCombineSrc CombineSrcRGB[3], CombineSrcAlpha[3];
  490. TextureCombineOp CombineOpRGB[3], CombineOpAlpha[3];
  491. EGL_Fixed ScaleRGB, ScaleAlpha;
  492. FilterMode MinFilterMode;
  493. FilterMode MagFilterMode;
  494. FilterMode MipmapFilterMode;
  495. WrappingMode WrappingModeS;
  496. WrappingMode WrappingModeT;
  497. TextureFormat InternalFormat;
  498. }
  499. m_Texture[EGL_NUM_TEXTURE_UNITS];
  500. struct ScissorTestState {
  501. ScissorTestState() {
  502. Enabled = false;
  503. X = 0;
  504. Y = 0;
  505. Width = 1024;
  506. Height = 1024;
  507. }
  508. ScissorTestState(const ScissorTestState& other) {
  509. Enabled = other.Enabled;
  510. X = other.X;
  511. Y = other.Y;
  512. Width = other.Width;
  513. Height = other.Height;
  514. }
  515. ScissorTestState& operator=(const ScissorTestState& other) {
  516. Enabled = other.Enabled;
  517. X = other.X;
  518. Y = other.Y;
  519. Width = other.Width;
  520. Height = other.Height;
  521. return *this;
  522. }
  523. bool operator==(const ScissorTestState& other) const {
  524. return Enabled == other.Enabled &&
  525. (!Enabled ||
  526. X == other.X && Y == other.Y &&
  527. Width == other.Width && Height == other.Height);
  528. }
  529. bool Enabled;
  530. I32 X, Y;
  531. U32 Width, Height;
  532. }
  533. m_ScissorTest;
  534. struct MaskState {
  535. MaskState() {
  536. Red = true;
  537. Blue = true;
  538. Green = true;
  539. Alpha = true;
  540. Depth = true;
  541. }
  542. MaskState(const MaskState& other) {
  543. Red = other.Red;
  544. Blue = other.Blue;
  545. Green = other.Green;
  546. Alpha = other.Alpha;
  547. Depth = other.Depth;
  548. }
  549. MaskState& operator=(const MaskState& other) {
  550. Red = other.Red;
  551. Blue = other.Blue;
  552. Green = other.Green;
  553. Alpha = other.Alpha;
  554. Depth = other.Depth;
  555. return *this;
  556. }
  557. bool operator==(const MaskState& other) const {
  558. return Red == other.Red &&
  559. Green == other.Green &&
  560. Blue == other.Blue &&
  561. Alpha == other.Alpha &&
  562. Depth == other.Depth;
  563. }
  564. bool Red; // if true, write red channel
  565. bool Green; // if true, write green channel
  566. bool Blue; // if true, write blue channel
  567. bool Alpha; // if true, write alpha channel
  568. bool Depth; // if true, write depth buffer
  569. }
  570. m_Mask;
  571. struct AlphaState {
  572. AlphaState() {
  573. Enabled = false;
  574. Func = CompFuncAlways;
  575. Reference = 0;
  576. }
  577. AlphaState(const AlphaState& other) {
  578. Enabled = other.Enabled;
  579. Func = other.Func;
  580. Reference = other.Reference;
  581. }
  582. AlphaState& operator=(const AlphaState& other) {
  583. Enabled = other.Enabled;
  584. Func = other.Func;
  585. Reference = other.Reference;
  586. return *this;
  587. }
  588. bool operator==(const AlphaState& other) const {
  589. return Enabled == other.Enabled &&
  590. (!Enabled ||
  591. Func == other.Func &&
  592. Reference == other.Reference);
  593. }
  594. bool Enabled;
  595. ComparisonFunc Func;
  596. EGL_Fixed Reference;
  597. }
  598. m_Alpha;
  599. struct BlendState {
  600. BlendState() {
  601. Enabled = false;
  602. FuncSrc = BlendFuncSrcOne;
  603. FuncDst = BlendFuncDstZero;
  604. }
  605. BlendState(const BlendState& other) {
  606. Enabled = other.Enabled;
  607. FuncSrc = other.FuncSrc;
  608. FuncDst = other.FuncDst;
  609. }
  610. BlendState& operator=(const BlendState& other) {
  611. Enabled = other.Enabled;
  612. FuncSrc = other.FuncSrc;
  613. FuncDst = other.FuncDst;
  614. return *this;
  615. }
  616. bool operator==(const BlendState& other) const {
  617. return Enabled == other.Enabled &&
  618. (!Enabled ||
  619. FuncSrc == other.FuncSrc && FuncDst == other.FuncDst);
  620. }
  621. bool Enabled;
  622. BlendFuncSrc FuncSrc;
  623. BlendFuncDst FuncDst;
  624. }
  625. m_Blend;
  626. struct DepthTestState {
  627. DepthTestState() {
  628. Enabled = false;
  629. Func = CompFuncLess;
  630. }
  631. DepthTestState(const DepthTestState& other) {
  632. Enabled = other.Enabled;
  633. Func = other.Func;
  634. }
  635. DepthTestState& operator=(const DepthTestState& other) {
  636. Enabled = other.Enabled;
  637. Func = other.Func;
  638. return *this;
  639. }
  640. bool operator==(const DepthTestState& other) const {
  641. return Enabled == other.Enabled &&
  642. (!Enabled || Func == other.Func);
  643. }
  644. bool Enabled;
  645. ComparisonFunc Func;
  646. }
  647. m_DepthTest;
  648. struct LogicOpState {
  649. LogicOpState() {
  650. Enabled = false;
  651. Opcode = LogicOpCopy;
  652. }
  653. LogicOpState(const LogicOpState& other) {
  654. Enabled = other.Enabled;
  655. Opcode = other.Opcode;
  656. }
  657. LogicOpState& operator=(const LogicOpState& other) {
  658. Enabled = other.Enabled;
  659. Opcode = other.Opcode;
  660. return *this;
  661. }
  662. bool operator==(const LogicOpState& other) const {
  663. return Enabled == other.Enabled &&
  664. (!Enabled || Opcode == other.Opcode);
  665. }
  666. bool Enabled;
  667. LogicOp Opcode;
  668. }
  669. m_LogicOp;
  670. struct StencilState {
  671. StencilState() {
  672. Enabled = false;
  673. Func = CompFuncAlways;
  674. Reference = 0;
  675. Mask = 0xFFFFFFFFu;
  676. ComparisonMask = 0xFFFFFFFFu;
  677. Fail = StencilOpKeep;
  678. ZFail = StencilOpKeep;
  679. ZPass = StencilOpKeep;
  680. }
  681. StencilState(const StencilState& other) {
  682. Enabled = other.Enabled;
  683. Func = other.Func;
  684. Reference = other.Reference;
  685. ComparisonMask = other.ComparisonMask;
  686. Mask = other.Mask;
  687. Fail = other.Fail;
  688. ZFail = other.ZFail;
  689. ZPass = other.ZPass;
  690. }
  691. StencilState& operator=(const StencilState& other) {
  692. Enabled = other.Enabled;
  693. Func = other.Func;
  694. Reference = other.Reference;
  695. Mask = other.Mask;
  696. ComparisonMask = other.ComparisonMask;
  697. Fail = other.Fail;
  698. ZFail = other.ZFail;
  699. ZPass = other.ZPass;
  700. return *this;
  701. }
  702. bool operator==(const StencilState& other) const {
  703. return Enabled == other.Enabled &&
  704. (!Enabled ||
  705. Func == other.Func &&
  706. Reference == other.Reference &&
  707. Mask == other.Mask &&
  708. ComparisonMask == other.ComparisonMask &&
  709. Fail == other.Fail &&
  710. ZFail == other.ZFail &&
  711. ZPass == other.ZPass);
  712. }
  713. bool Enabled;
  714. ComparisonFunc Func;
  715. I32 Reference;
  716. U32 ComparisonMask;
  717. U32 Mask;
  718. StencilOp Fail, ZFail, ZPass;
  719. }
  720. m_Stencil;
  721. ShadingModel m_ShadingModel;
  722. EGL_Fixed m_SampleCoverage;
  723. bool m_InvertSampleCoverage;
  724. };
  725. // ----------------------------------------------------------------------
  726. // Inline member definitions
  727. // ----------------------------------------------------------------------
  728. inline void RasterizerState :: SetTexEnvColor(size_t unit, const Color& color) {
  729. m_Texture[unit].EnvColor = color;
  730. }
  731. inline Color RasterizerState :: GetTexEnvColor(size_t unit) const {
  732. return m_Texture[unit].EnvColor;
  733. }
  734. inline void RasterizerState :: SetTextureMode(size_t unit, TextureMode mode) {
  735. m_Texture[unit].Mode = mode;
  736. }
  737. inline RasterizerState::TextureMode RasterizerState :: GetTextureMode(size_t unit) const {
  738. return m_Texture[unit].Mode;
  739. }
  740. inline void RasterizerState :: SetMinFilterMode(size_t unit, FilterMode mode) {
  741. m_Texture[unit].MinFilterMode = mode;
  742. }
  743. inline void RasterizerState :: SetMagFilterMode(size_t unit, FilterMode mode) {
  744. m_Texture[unit].MagFilterMode = mode;
  745. }
  746. inline void RasterizerState :: SetMipmapFilterMode(size_t unit, FilterMode mode) {
  747. m_Texture[unit].MipmapFilterMode = mode;
  748. }
  749. inline void RasterizerState :: SetWrappingModeS(size_t unit, WrappingMode mode) {
  750. m_Texture[unit].WrappingModeS = mode;
  751. }
  752. inline void RasterizerState :: SetWrappingModeT(size_t unit, WrappingMode mode) {
  753. m_Texture[unit].WrappingModeT = mode;
  754. }
  755. inline void RasterizerState :: SetInternalFormat(size_t unit, TextureFormat format) {
  756. m_Texture[unit].InternalFormat = format;
  757. }
  758. inline void RasterizerState :: SetFogColor(const Color& color) {
  759. m_Fog.Color = color;
  760. }
  761. inline void RasterizerState :: EnableFog(bool enabled) {
  762. m_Fog.Enabled = enabled;
  763. }
  764. inline void RasterizerState :: SetLineWidth(EGL_Fixed width) {
  765. m_Line.Width = width;
  766. }
  767. inline void RasterizerState :: SetLogicOp(LogicOp opcode) {
  768. m_LogicOp.Opcode = opcode;
  769. }
  770. inline void RasterizerState :: SetShadeModel(ShadingModel mode) {
  771. m_ShadingModel = mode;
  772. }
  773. inline RasterizerState::ShadingModel RasterizerState :: GetShadeModel() const {
  774. return m_ShadingModel;
  775. }
  776. inline void RasterizerState :: EnableTexture(size_t unit, bool enabled) {
  777. m_Texture[unit].Enabled = enabled;
  778. }
  779. inline void RasterizerState :: EnablePolygonOffsetFill(bool enabled) {
  780. m_Polygon.OffsetFillEnabled = enabled;
  781. }
  782. inline bool RasterizerState :: IsEnabledPolygonOffsetFill() const {
  783. return m_Polygon.OffsetFillEnabled;
  784. }
  785. inline void RasterizerState :: SetPolygonOffset(EGL_Fixed factor, EGL_Fixed units) {
  786. m_Polygon.OffsetFactor = factor;
  787. m_Polygon.OffsetUnits = units;
  788. }
  789. inline void RasterizerState :: SetSampleCoverage(EGL_Fixed value, bool invert) {
  790. m_SampleCoverage = value;
  791. m_InvertSampleCoverage = invert;
  792. }
  793. // ----------------------------------------------------------------------
  794. // Fragment rendering state
  795. // ----------------------------------------------------------------------
  796. inline void RasterizerState :: SetAlphaFunc(ComparisonFunc func, EGL_Fixed ref) {
  797. m_Alpha.Func = func;
  798. m_Alpha.Reference = ref;
  799. }
  800. inline void RasterizerState :: SetBlendFunc(BlendFuncSrc sfactor, BlendFuncDst dfactor) {
  801. m_Blend.FuncSrc = sfactor;
  802. m_Blend.FuncDst = dfactor;
  803. }
  804. inline void RasterizerState :: SetColorMask(bool red, bool green, bool blue, bool alpha) {
  805. m_Mask.Alpha = alpha;
  806. m_Mask.Red = red;
  807. m_Mask.Green = green;
  808. m_Mask.Blue = blue;
  809. }
  810. inline Color RasterizerState :: GetColorMask() const {
  811. return Color(m_Mask.Red ? 0xff : 0,
  812. m_Mask.Green ? 0xff : 0,
  813. m_Mask.Blue ? 0xff : 0,
  814. m_Mask.Alpha ? 0xff : 0);
  815. }
  816. inline bool RasterizerState :: GetDepthMask() const {
  817. return m_Mask.Depth;
  818. }
  819. inline U32 RasterizerState :: GetStencilMask() const {
  820. return m_Stencil.Mask;
  821. }
  822. inline void RasterizerState :: SetDepthFunc(ComparisonFunc func) {
  823. m_DepthTest.Func = func;
  824. }
  825. inline void RasterizerState :: SetDepthMask(bool flag) {
  826. m_Mask.Depth = flag;
  827. }
  828. inline void RasterizerState :: SetScissor(I32 x, I32 y, U32 width, U32 height) {
  829. m_ScissorTest.X = x;
  830. m_ScissorTest.Y = y;
  831. m_ScissorTest.Width = width;
  832. m_ScissorTest.Height = height;
  833. }
  834. inline void RasterizerState :: EnableAlphaTest(bool enabled) {
  835. m_Alpha.Enabled = enabled;
  836. }
  837. inline void RasterizerState :: EnableDepthTest(bool enabled) {
  838. m_DepthTest.Enabled = enabled;
  839. }
  840. inline void RasterizerState :: EnableLogicOp(bool enabled) {
  841. m_LogicOp.Enabled = enabled;
  842. }
  843. inline void RasterizerState :: EnableScissorTest(bool enabled) {
  844. m_ScissorTest.Enabled = enabled;
  845. }
  846. inline void RasterizerState :: EnableBlending(bool enabled) {
  847. m_Blend.Enabled = enabled;
  848. }
  849. inline void RasterizerState :: SetStencilFunc(ComparisonFunc func, I32 ref, U32 mask) {
  850. m_Stencil.Func = func;
  851. m_Stencil.Reference = ref;
  852. m_Stencil.ComparisonMask = mask;
  853. }
  854. inline void RasterizerState :: SetStencilMask(U32 mask) {
  855. m_Stencil.Mask = mask;
  856. }
  857. inline void RasterizerState :: SetStencilOp(StencilOp fail, StencilOp zfail, StencilOp zpass) {
  858. m_Stencil.Fail = fail;
  859. m_Stencil.ZFail = zfail;
  860. m_Stencil.ZPass = zpass;
  861. }
  862. inline void RasterizerState :: EnableStencilTest(bool enabled) {
  863. m_Stencil.Enabled = enabled;
  864. }
  865. inline void RasterizerState :: SetLineSmoothEnabled(bool enabled) {
  866. m_Line.SmoothEnabled = enabled;
  867. }
  868. inline void RasterizerState :: SetPointSmoothEnabled(bool enabled) {
  869. m_Point.SmoothEnabled = enabled;
  870. }
  871. inline void RasterizerState :: SetPointSpriteEnabled(bool enabled) {
  872. m_Point.SpriteEnabled = enabled;
  873. }
  874. inline void RasterizerState :: SetPointCoordReplaceEnabled(size_t unit, bool enabled) {
  875. m_Point.CoordReplaceEnabled = enabled;
  876. }
  877. inline bool RasterizerState :: IsPointCoordReplaceEnabled(size_t unit) const {
  878. return m_Point.CoordReplaceEnabled;
  879. }
  880. inline bool RasterizerState :: IsEnabledFog() const {
  881. return m_Fog.Enabled;
  882. }
  883. inline Color RasterizerState :: GetFogColor() const {
  884. return m_Fog.Color;
  885. }
  886. inline EGL_Fixed RasterizerState :: GetPolygonOffsetFactor() const {
  887. return m_Polygon.OffsetFactor;
  888. }
  889. inline EGL_Fixed RasterizerState :: GetPolygonOffsetUnits() const {
  890. return m_Polygon.OffsetUnits;
  891. }
  892. inline EGL_Fixed RasterizerState :: GetSampleCoverage() const {
  893. return m_SampleCoverage;
  894. }
  895. inline bool RasterizerState :: GetSampleCoverageInvert() const {
  896. return m_InvertSampleCoverage;
  897. }
  898. inline bool RasterizerState :: IsPointSmoothEnabled() const {
  899. return m_Point.SmoothEnabled;
  900. }
  901. inline bool RasterizerState :: IsLineSmoothEnabled() const {
  902. return m_Line.SmoothEnabled;
  903. }
  904. inline bool RasterizerState :: IsEnabledAlphaTest() const {
  905. return m_Alpha.Enabled;
  906. }
  907. inline bool RasterizerState :: IsEnabledDepthTest() const {
  908. return m_DepthTest.Enabled;
  909. }
  910. inline bool RasterizerState :: IsEnabledLogicOp() const {
  911. return m_LogicOp.Enabled;
  912. }
  913. inline bool RasterizerState :: IsEnabledScissorTest() const {
  914. return m_ScissorTest.Enabled;
  915. }
  916. inline bool RasterizerState :: IsEnabledBlending() const {
  917. return m_Blend.Enabled;
  918. }
  919. inline bool RasterizerState :: IsEnabledStencilTest() const {
  920. return m_Stencil.Enabled;
  921. }
  922. inline bool RasterizerState :: IsEnabledTexture(size_t unit) const {
  923. return m_Texture[unit].Enabled;
  924. }
  925. inline bool RasterizerState :: IsPointSpriteEnabled() const {
  926. return m_Point.SpriteEnabled;
  927. }
  928. inline RasterizerState::LogicOp RasterizerState :: GetLogicOp() const {
  929. return m_LogicOp.Opcode;
  930. }
  931. inline RasterizerState::ComparisonFunc RasterizerState :: GetAlphaFunc() const {
  932. return m_Alpha.Func;
  933. }
  934. inline EGL_Fixed RasterizerState :: GetAlphaRef() const {
  935. return m_Alpha.Reference;
  936. }
  937. inline RasterizerState::BlendFuncSrc RasterizerState :: GetBlendFuncSrc() const {
  938. return m_Blend.FuncSrc;
  939. }
  940. inline RasterizerState::BlendFuncDst RasterizerState :: GetBlendFuncDst() const {
  941. return m_Blend.FuncDst;
  942. }
  943. inline RasterizerState::ComparisonFunc RasterizerState :: GetDepthFunc() const {
  944. return m_DepthTest.Func;
  945. }
  946. inline RasterizerState::ComparisonFunc RasterizerState :: GetStencilFunc() const {
  947. return m_Stencil.Func;
  948. }
  949. inline I32 RasterizerState :: GetStencilRef() const {
  950. return m_Stencil.Reference;
  951. }
  952. inline I32 RasterizerState :: GetStencilComparisonMask() const {
  953. return m_Stencil.ComparisonMask;
  954. }
  955. inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFail() const {
  956. return m_Stencil.Fail;
  957. }
  958. inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFailZFail() const {
  959. return m_Stencil.ZFail;
  960. }
  961. inline RasterizerState::StencilOp RasterizerState :: GetStencilOpFailZPass() const {
  962. return m_Stencil.ZPass;
  963. }
  964. inline void RasterizerState :: SetTextureCombineFuncRGB(size_t unit, TextureModeCombineFunc func) {
  965. m_Texture[unit].CombineFuncRGB = func;
  966. }
  967. inline RasterizerState::TextureModeCombineFunc RasterizerState :: GetTextureCombineFuncRGB(size_t unit) const {
  968. return m_Texture[unit].CombineFuncRGB;
  969. }
  970. inline void RasterizerState :: SetTextureCombineFuncAlpha(size_t unit, TextureModeCombineFunc func) {
  971. m_Texture[unit].CombineFuncAlpha = func;
  972. }
  973. inline RasterizerState::TextureModeCombineFunc RasterizerState :: GetTextureCombineFuncAlpha(size_t unit) const {
  974. return m_Texture[unit].CombineFuncAlpha;
  975. }
  976. inline void RasterizerState :: SetTextureCombineSrcRGB(size_t unit, size_t idx, TextureCombineSrc src) {
  977. m_Texture[unit].CombineSrcRGB[idx] = src;
  978. }
  979. inline RasterizerState::TextureCombineSrc RasterizerState :: GetTextureCombineSrcRGB(size_t unit, size_t idx) const {
  980. return m_Texture[unit].CombineSrcRGB[idx];
  981. }
  982. inline void RasterizerState :: SetTextureCombineSrcAlpha(size_t unit, size_t idx, TextureCombineSrc src) {
  983. m_Texture[unit].CombineSrcAlpha[idx] = src;
  984. }
  985. inline RasterizerState::TextureCombineSrc RasterizerState :: GetTextureCombineSrcAlpha(size_t unit, size_t idx) const {
  986. return m_Texture[unit].CombineSrcAlpha[idx];
  987. }
  988. inline void RasterizerState :: SetTextureCombineOpRGB(size_t unit, size_t idx, TextureCombineOp op) {
  989. m_Texture[unit].CombineOpRGB[idx] = op;
  990. }
  991. inline RasterizerState::TextureCombineOp RasterizerState :: GetTextureCombineOpRGB(size_t unit, size_t idx) const {
  992. return m_Texture[unit].CombineOpRGB[idx];
  993. }
  994. inline void RasterizerState :: SetTextureCombineOpAlpha(size_t unit, size_t idx, TextureCombineOp op) {
  995. m_Texture[unit].CombineOpAlpha[idx] = op;
  996. }
  997. inline RasterizerState::TextureCombineOp RasterizerState :: GetTextureCombineOpAlpha(size_t unit, size_t idx) const {
  998. return m_Texture[unit].CombineOpAlpha[idx];
  999. }
  1000. inline void RasterizerState :: SetTextureScaleRGB(size_t unit, EGL_Fixed scale) {
  1001. m_Texture[unit].ScaleRGB = scale;
  1002. }
  1003. inline EGL_Fixed RasterizerState :: GetTextureScaleRGB(size_t unit) const {
  1004. return m_Texture[unit].ScaleRGB;
  1005. }
  1006. inline void RasterizerState :: SetTextureScaleAlpha(size_t unit, EGL_Fixed scale) {
  1007. m_Texture[unit].ScaleAlpha = scale;
  1008. }
  1009. inline EGL_Fixed RasterizerState :: GetTextureScaleAlpha(size_t unit) const {
  1010. return m_Texture[unit].ScaleAlpha;
  1011. }
  1012. }
  1013. #endif //ndef EGL_RASTERIZER_STATE_H