renderer_opengl.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 the Switch screen
  14. struct TextureInfo {
  15. OGLTexture resource;
  16. GLsizei width;
  17. GLsizei height;
  18. GLenum gl_format;
  19. GLenum gl_type;
  20. Tegra::FramebufferConfig::PixelFormat pixel_format;
  21. };
  22. /// Structure used for storing information about the display target for the Switch 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 Tegra::FramebufferConfig&> framebuffer) 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,
  46. const Tegra::FramebufferConfig& framebuffer);
  47. void DrawScreen();
  48. void DrawScreenTriangles(const ScreenInfo& screen_info, float x, float y, float w, float h);
  49. void UpdateFramerate();
  50. // Loads framebuffer from emulated memory into the display information structure
  51. void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer, ScreenInfo& screen_info);
  52. // Fills active OpenGL texture with the given RGBA color.
  53. void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
  54. const TextureInfo& texture);
  55. EmuWindow* render_window; ///< Handle to render window
  56. OpenGLState state;
  57. // OpenGL object IDs
  58. OGLVertexArray vertex_array;
  59. OGLBuffer vertex_buffer;
  60. OGLProgram shader;
  61. /// Display information for Switch screen
  62. ScreenInfo screen_info;
  63. /// OpenGL framebuffer data
  64. std::vector<u8> gl_framebuffer_data;
  65. // Shader uniform location indices
  66. GLuint uniform_modelview_matrix;
  67. GLuint uniform_color_texture;
  68. // Shader attribute input indices
  69. GLuint attrib_position;
  70. GLuint attrib_tex_coord;
  71. /// Used for transforming the framebuffer orientation
  72. Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
  73. };