gl_state.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <type_traits>
  7. #include <glad/glad.h>
  8. #include "video_core/engines/maxwell_3d.h"
  9. namespace OpenGL {
  10. class OpenGLState {
  11. public:
  12. static constexpr std::size_t NumSamplers = 32 * 5;
  13. static constexpr std::size_t NumImages = 8 * 5;
  14. std::array<GLuint, NumSamplers> textures = {};
  15. std::array<GLuint, NumSamplers> samplers = {};
  16. std::array<GLuint, NumImages> images = {};
  17. struct {
  18. GLuint read_framebuffer = 0; // GL_READ_FRAMEBUFFER_BINDING
  19. GLuint draw_framebuffer = 0; // GL_DRAW_FRAMEBUFFER_BINDING
  20. GLuint shader_program = 0; // GL_CURRENT_PROGRAM
  21. GLuint program_pipeline = 0; // GL_PROGRAM_PIPELINE_BINDING
  22. } draw;
  23. GLuint renderbuffer{}; // GL_RENDERBUFFER_BINDING
  24. OpenGLState();
  25. /// Get the currently active OpenGL state
  26. static OpenGLState GetCurState() {
  27. return cur_state;
  28. }
  29. /// Apply this state as the current OpenGL state
  30. void Apply();
  31. void ApplyFramebufferState();
  32. void ApplyShaderProgram();
  33. void ApplyProgramPipeline();
  34. void ApplyTextures();
  35. void ApplySamplers();
  36. void ApplyImages();
  37. void ApplyRenderBuffer();
  38. /// Resets any references to the given resource
  39. OpenGLState& UnbindTexture(GLuint handle);
  40. OpenGLState& ResetSampler(GLuint handle);
  41. OpenGLState& ResetProgram(GLuint handle);
  42. OpenGLState& ResetPipeline(GLuint handle);
  43. OpenGLState& ResetFramebuffer(GLuint handle);
  44. OpenGLState& ResetRenderbuffer(GLuint handle);
  45. private:
  46. static OpenGLState cur_state;
  47. };
  48. static_assert(std::is_trivially_copyable_v<OpenGLState>);
  49. } // namespace OpenGL