gl_state.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <glad/glad.h>
  7. namespace TextureUnits {
  8. struct TextureUnit {
  9. GLint id;
  10. constexpr GLenum Enum() const {
  11. return static_cast<GLenum>(GL_TEXTURE0 + id);
  12. }
  13. };
  14. constexpr TextureUnit MaxwellTexture(int unit) {
  15. return TextureUnit{unit};
  16. }
  17. constexpr TextureUnit LightingLUT{3};
  18. constexpr TextureUnit FogLUT{4};
  19. constexpr TextureUnit ProcTexNoiseLUT{5};
  20. constexpr TextureUnit ProcTexColorMap{6};
  21. constexpr TextureUnit ProcTexAlphaMap{7};
  22. constexpr TextureUnit ProcTexLUT{8};
  23. constexpr TextureUnit ProcTexDiffLUT{9};
  24. } // namespace TextureUnits
  25. class OpenGLState {
  26. public:
  27. struct {
  28. bool enabled; // GL_CULL_FACE
  29. GLenum mode; // GL_CULL_FACE_MODE
  30. GLenum front_face; // GL_FRONT_FACE
  31. } cull;
  32. struct {
  33. bool test_enabled; // GL_DEPTH_TEST
  34. GLenum test_func; // GL_DEPTH_FUNC
  35. GLboolean write_mask; // GL_DEPTH_WRITEMASK
  36. } depth;
  37. struct {
  38. GLboolean red_enabled;
  39. GLboolean green_enabled;
  40. GLboolean blue_enabled;
  41. GLboolean alpha_enabled;
  42. } color_mask; // GL_COLOR_WRITEMASK
  43. struct {
  44. bool test_enabled; // GL_STENCIL_TEST
  45. GLenum test_func; // GL_STENCIL_FUNC
  46. GLint test_ref; // GL_STENCIL_REF
  47. GLuint test_mask; // GL_STENCIL_VALUE_MASK
  48. GLuint write_mask; // GL_STENCIL_WRITEMASK
  49. GLenum action_stencil_fail; // GL_STENCIL_FAIL
  50. GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
  51. GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
  52. } stencil;
  53. struct {
  54. bool enabled; // GL_BLEND
  55. GLenum rgb_equation; // GL_BLEND_EQUATION_RGB
  56. GLenum a_equation; // GL_BLEND_EQUATION_ALPHA
  57. GLenum src_rgb_func; // GL_BLEND_SRC_RGB
  58. GLenum dst_rgb_func; // GL_BLEND_DST_RGB
  59. GLenum src_a_func; // GL_BLEND_SRC_ALPHA
  60. GLenum dst_a_func; // GL_BLEND_DST_ALPHA
  61. struct {
  62. GLclampf red;
  63. GLclampf green;
  64. GLclampf blue;
  65. GLclampf alpha;
  66. } color; // GL_BLEND_COLOR
  67. } blend;
  68. GLenum logic_op; // GL_LOGIC_OP_MODE
  69. // 3 texture units - one for each that is used in PICA fragment shader emulation
  70. struct {
  71. GLuint texture_2d; // GL_TEXTURE_BINDING_2D
  72. GLuint sampler; // GL_SAMPLER_BINDING
  73. } texture_units[32];
  74. struct {
  75. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  76. } lighting_lut;
  77. struct {
  78. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  79. } fog_lut;
  80. struct {
  81. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  82. } proctex_noise_lut;
  83. struct {
  84. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  85. } proctex_color_map;
  86. struct {
  87. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  88. } proctex_alpha_map;
  89. struct {
  90. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  91. } proctex_lut;
  92. struct {
  93. GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
  94. } proctex_diff_lut;
  95. struct {
  96. GLuint read_framebuffer; // GL_READ_FRAMEBUFFER_BINDING
  97. GLuint draw_framebuffer; // GL_DRAW_FRAMEBUFFER_BINDING
  98. GLuint vertex_array; // GL_VERTEX_ARRAY_BINDING
  99. GLuint vertex_buffer; // GL_ARRAY_BUFFER_BINDING
  100. GLuint uniform_buffer; // GL_UNIFORM_BUFFER_BINDING
  101. GLuint shader_program; // GL_CURRENT_PROGRAM
  102. GLuint program_pipeline; // GL_PROGRAM_PIPELINE_BINDING
  103. } draw;
  104. struct {
  105. bool enabled; // GL_SCISSOR_TEST
  106. GLint x;
  107. GLint y;
  108. GLsizei width;
  109. GLsizei height;
  110. } scissor;
  111. struct {
  112. GLint x;
  113. GLint y;
  114. GLsizei width;
  115. GLsizei height;
  116. } viewport;
  117. std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE
  118. OpenGLState();
  119. /// Get the currently active OpenGL state
  120. static OpenGLState GetCurState() {
  121. return cur_state;
  122. }
  123. /// Apply this state as the current OpenGL state
  124. void Apply() const;
  125. /// Resets any references to the given resource
  126. OpenGLState& ResetTexture(GLuint handle);
  127. OpenGLState& ResetSampler(GLuint handle);
  128. OpenGLState& ResetProgram(GLuint handle);
  129. OpenGLState& ResetPipeline(GLuint handle);
  130. OpenGLState& ResetBuffer(GLuint handle);
  131. OpenGLState& ResetVertexArray(GLuint handle);
  132. OpenGLState& ResetFramebuffer(GLuint handle);
  133. private:
  134. static OpenGLState cur_state;
  135. };