renderer_opengl.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "generated/gl_3_2_core.h"
  7. #include "common/math_util.h"
  8. #include "core/hw/gpu.h"
  9. #include "video_core/renderer_base.h"
  10. class EmuWindow;
  11. class RendererOpenGL : public RendererBase {
  12. public:
  13. RendererOpenGL();
  14. ~RendererOpenGL() override;
  15. /// Swap buffers (render frame)
  16. void SwapBuffers() override;
  17. /**
  18. * Set the emulator window to use for renderer
  19. * @param window EmuWindow handle to emulator window to use for rendering
  20. */
  21. void SetWindow(EmuWindow* window) override;
  22. /// Initialize the renderer
  23. void Init() override;
  24. /// Shutdown the renderer
  25. void ShutDown() override;
  26. private:
  27. /// Structure used for storing information about the textures for each 3DS screen
  28. struct TextureInfo {
  29. GLuint handle;
  30. GLsizei width;
  31. GLsizei height;
  32. GPU::Regs::PixelFormat format;
  33. GLenum gl_format;
  34. GLenum gl_type;
  35. };
  36. void InitOpenGLObjects();
  37. static void ConfigureFramebufferTexture(TextureInfo& texture,
  38. const GPU::Regs::FramebufferConfig& framebuffer);
  39. void DrawScreens();
  40. void DrawSingleScreenRotated(const TextureInfo& texture, float x, float y, float w, float h);
  41. void UpdateFramerate();
  42. // Loads framebuffer from emulated memory into the active OpenGL texture.
  43. static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer,
  44. const TextureInfo& texture);
  45. // Fills active OpenGL texture with the given RGB color.
  46. static void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b,
  47. const TextureInfo& texture);
  48. /// Computes the viewport rectangle
  49. MathUtil::Rectangle<unsigned> GetViewportExtent();
  50. EmuWindow* render_window; ///< Handle to render window
  51. u32 last_mode; ///< Last render mode
  52. int resolution_width; ///< Current resolution width
  53. int resolution_height; ///< Current resolution height
  54. // OpenGL object IDs
  55. GLuint vertex_array_handle;
  56. GLuint vertex_buffer_handle;
  57. GLuint program_id;
  58. std::array<TextureInfo, 2> textures; ///< Textures for top and bottom screens respectively
  59. // Shader uniform location indices
  60. GLuint uniform_modelview_matrix;
  61. GLuint uniform_color_texture;
  62. // Shader attribute input indices
  63. GLuint attrib_position;
  64. GLuint attrib_tex_coord;
  65. };