renderer_opengl.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. namespace Core {
  13. class System;
  14. }
  15. namespace Core::Frontend {
  16. class EmuWindow;
  17. }
  18. namespace Layout {
  19. struct FramebufferLayout;
  20. }
  21. namespace OpenGL {
  22. /// Structure used for storing information about the textures for the Switch screen
  23. struct TextureInfo {
  24. OGLTexture resource;
  25. GLsizei width;
  26. GLsizei height;
  27. GLenum gl_format;
  28. GLenum gl_type;
  29. Tegra::FramebufferConfig::PixelFormat pixel_format;
  30. };
  31. /// Structure used for storing information about the display target for the Switch screen
  32. struct ScreenInfo {
  33. GLuint display_texture;
  34. const Common::Rectangle<float> display_texcoords{0.0f, 0.0f, 1.0f, 1.0f};
  35. TextureInfo texture;
  36. };
  37. class RendererOpenGL : public VideoCore::RendererBase {
  38. public:
  39. explicit RendererOpenGL(Core::Frontend::EmuWindow& window, Core::System& system);
  40. ~RendererOpenGL() override;
  41. /// Swap buffers (render frame)
  42. void SwapBuffers(
  43. std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override;
  44. /// Initialize the renderer
  45. bool Init() override;
  46. /// Shutdown the renderer
  47. void ShutDown() override;
  48. private:
  49. void InitOpenGLObjects();
  50. void AddTelemetryFields();
  51. void CreateRasterizer();
  52. void ConfigureFramebufferTexture(TextureInfo& texture,
  53. const Tegra::FramebufferConfig& framebuffer);
  54. void DrawScreen(const Layout::FramebufferLayout& layout);
  55. void DrawScreenTriangles(const ScreenInfo& screen_info, float x, float y, float w, float h);
  56. void UpdateFramerate();
  57. void CaptureScreenshot();
  58. // Loads framebuffer from emulated memory into the display information structure
  59. void LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer);
  60. // Fills active OpenGL texture with the given RGBA color.
  61. void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
  62. const TextureInfo& texture);
  63. Core::System& system;
  64. OpenGLState state;
  65. // OpenGL object IDs
  66. OGLVertexArray vertex_array;
  67. OGLBuffer vertex_buffer;
  68. OGLProgram shader;
  69. OGLFramebuffer screenshot_framebuffer;
  70. /// Display information for Switch screen
  71. ScreenInfo screen_info;
  72. /// OpenGL framebuffer data
  73. std::vector<u8> gl_framebuffer_data;
  74. // Shader uniform location indices
  75. GLuint uniform_modelview_matrix;
  76. GLuint uniform_color_texture;
  77. // Shader attribute input indices
  78. GLuint attrib_position;
  79. GLuint attrib_tex_coord;
  80. /// Used for transforming the framebuffer orientation
  81. Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags;
  82. Common::Rectangle<int> framebuffer_crop_rect;
  83. };
  84. } // namespace OpenGL