renderer_opengl.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2014 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. #include "common/common_types.h"
  8. #include "common/math_util.h"
  9. #include "core/hw/gpu.h"
  10. #include "video_core/renderer_base.h"
  11. #include "video_core/renderer_opengl/gl_resource_manager.h"
  12. #include "video_core/renderer_opengl/gl_state.h"
  13. class EmuWindow;
  14. /// Structure used for storing information about the textures for each 3DS screen
  15. struct TextureInfo {
  16. OGLTexture resource;
  17. GLsizei width;
  18. GLsizei height;
  19. GPU::Regs::PixelFormat format;
  20. GLenum gl_format;
  21. GLenum gl_type;
  22. };
  23. /// Structure used for storing information about the display target for each 3DS screen
  24. struct ScreenInfo {
  25. GLuint display_texture;
  26. MathUtil::Rectangle<float> display_texcoords;
  27. TextureInfo texture;
  28. };
  29. class RendererOpenGL : public RendererBase {
  30. public:
  31. RendererOpenGL();
  32. ~RendererOpenGL() override;
  33. /// Swap buffers (render frame)
  34. void SwapBuffers() override;
  35. /**
  36. * Set the emulator window to use for renderer
  37. * @param window EmuWindow handle to emulator window to use for rendering
  38. */
  39. void SetWindow(EmuWindow* window) override;
  40. /// Initialize the renderer
  41. bool Init() override;
  42. /// Shutdown the renderer
  43. void ShutDown() override;
  44. private:
  45. void InitOpenGLObjects();
  46. void ConfigureFramebufferTexture(TextureInfo& texture,
  47. const GPU::Regs::FramebufferConfig& framebuffer);
  48. void DrawScreens();
  49. void DrawSingleScreen(const ScreenInfo& screen_info, float x, float y, float w, float h);
  50. void UpdateFramerate();
  51. // Loads framebuffer from emulated memory into the display information structure
  52. void LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& framebuffer,
  53. ScreenInfo& screen_info);
  54. // Fills active OpenGL texture with the given RGB color.
  55. void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture);
  56. EmuWindow* render_window; ///< Handle to render window
  57. OpenGLState state;
  58. // OpenGL object IDs
  59. OGLVertexArray vertex_array;
  60. OGLBuffer vertex_buffer;
  61. OGLShader shader;
  62. /// Display information for top and bottom screens respectively
  63. std::array<ScreenInfo, 2> screen_infos;
  64. // Shader uniform location indices
  65. GLuint uniform_modelview_matrix;
  66. GLuint uniform_color_texture;
  67. // Shader attribute input indices
  68. GLuint attrib_position;
  69. GLuint attrib_tex_coord;
  70. };