/MonoGame.Framework/Graphics/States/GLStateManager.cs

https://github.com/notJUSTguitar/MonoGame
C# | 131 lines | 112 code | 16 blank | 3 comment | 24 complexity | 61aebbbd9968a25d8ad71bbab19d0ae1 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using OpenTK.Graphics.ES20;
  6. using OpenTK.Graphics.ES11;
  7. using GL11 = OpenTK.Graphics.ES11.GL;
  8. using GL20 = OpenTK.Graphics.ES20.GL;
  9. using All11 = OpenTK.Graphics.ES11.All;
  10. using All20 = OpenTK.Graphics.ES20.All;
  11. namespace Microsoft.Xna.Framework.Graphics
  12. {
  13. public static class GLStateManager
  14. {
  15. private static GLStateEnabled _textureCoordArray;
  16. private static GLStateEnabled _textures2D;
  17. private static GLStateEnabled _vertextArray;
  18. private static GLStateEnabled _colorArray;
  19. private static GLStateEnabled _normalArray;
  20. private static GLStateEnabled _depthTest;
  21. private static All11 _blendFuncSource;
  22. private static All11 _blendFuncDest;
  23. private static All11 _cull = All11.Ccw; // default
  24. public static void TextureCoordArray(bool enable)
  25. {
  26. if (enable && (_textureCoordArray != GLStateEnabled.True))
  27. GL11.EnableClientState(All11.TextureCoordArray);
  28. else
  29. GL11.EnableClientState(All11.TextureCoordArray);
  30. }
  31. public static void VertexArray(bool enable)
  32. {
  33. if (enable && (_vertextArray != GLStateEnabled.True))
  34. GL11.EnableClientState(All11.VertexArray);
  35. else
  36. GL11.EnableClientState(All11.VertexArray);
  37. }
  38. public static void ColorArray(bool enable)
  39. {
  40. if (enable && (_colorArray != GLStateEnabled.True))
  41. GL11.EnableClientState(All11.ColorArray);
  42. else
  43. GL11.EnableClientState(All11.ColorArray);
  44. }
  45. public static void NormalArray(bool enable)
  46. {
  47. if (enable && (_normalArray != GLStateEnabled.True))
  48. GL11.EnableClientState(All11.NormalArray);
  49. else
  50. GL11.EnableClientState(All11.NormalArray);
  51. }
  52. public static void Textures2D(bool enable)
  53. {
  54. if (enable && (_textures2D != GLStateEnabled.True))
  55. GL11.Enable(All11.Texture2D);
  56. else
  57. GL11.Disable(All11.Texture2D);
  58. }
  59. public static void DepthTest(bool enable)
  60. {
  61. if (enable && (_depthTest != GLStateEnabled.True))
  62. GL11.Enable(All11.DepthTest);
  63. else
  64. GL11.Disable(All11.DepthTest);
  65. }
  66. public static void Blend(bool enable)
  67. {
  68. GL11.Enable(All11.Blend);
  69. }
  70. public static void Projection(Matrix projection)
  71. {
  72. GL11.MatrixMode(All11.Projection);
  73. GL11.LoadIdentity();
  74. GL11.LoadMatrix(Matrix.ToFloatArray(projection));
  75. //GL11.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
  76. }
  77. public static void View(Matrix view)
  78. {
  79. GL11.MatrixMode(All11.Viewport);
  80. GL11.LoadIdentity();
  81. GL11.LoadMatrix(Matrix.ToFloatArray(view));
  82. //GL11.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
  83. }
  84. public static void World(Matrix world)
  85. {
  86. GL11.MatrixMode(All11.Modelview);
  87. GL11.LoadIdentity();
  88. GL11.LoadMatrix(Matrix.ToFloatArray(world));
  89. //GL11.Ortho(0, _device.DisplayMode.Width, _device.DisplayMode.Height, 0, -1, 1);
  90. }
  91. public static void Cull(All11 cullMode)
  92. {
  93. if (_cull != cullMode)
  94. {
  95. _cull = cullMode;
  96. GL11.Enable(_cull);
  97. }
  98. }
  99. public static void BlendFunc(All11 source, All11 dest)
  100. {
  101. if (source != _blendFuncSource && dest != _blendFuncDest)
  102. {
  103. source = _blendFuncSource;
  104. dest = _blendFuncDest;
  105. GL11.BlendFunc(source, dest);
  106. }
  107. }
  108. }
  109. public enum GLStateEnabled
  110. {
  111. False,
  112. True,
  113. NotSet
  114. }
  115. }