renderer_opengl.h 2.7 KB

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