renderer_opengl.h 3.0 KB

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