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