renderer_opengl.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <GL/glew.h>
  6. #include "common/common.h"
  7. #include "common/emu_window.h"
  8. #include "video_core/renderer_base.h"
  9. #include <array>
  10. class RendererOpenGL : virtual public RendererBase {
  11. public:
  12. RendererOpenGL();
  13. ~RendererOpenGL();
  14. /// Swap buffers (render frame)
  15. void SwapBuffers();
  16. /**
  17. * Renders external framebuffer (XFB)
  18. * @param src_rect Source rectangle in XFB to copy
  19. * @param dst_rect Destination rectangle in output framebuffer to copy to
  20. */
  21. void RenderXFB(const common::Rect& src_rect, const common::Rect& dst_rect);
  22. /**
  23. * Set the emulator window to use for renderer
  24. * @param window EmuWindow handle to emulator window to use for rendering
  25. */
  26. void SetWindow(EmuWindow* window);
  27. /// Initialize the renderer
  28. void Init();
  29. /// Shutdown the renderer
  30. void ShutDown();
  31. private:
  32. /// Initialize the FBO
  33. void InitFramebuffer();
  34. // Blit the FBO to the OpenGL default framebuffer
  35. void RenderFramebuffer();
  36. /// Updates the framerate
  37. void UpdateFramerate();
  38. /// Structure used for storing information for rendering each 3DS screen
  39. struct ScreenInfo {
  40. // Properties
  41. int width;
  42. int height;
  43. int stride; ///< Number of bytes between the coordinates (0,0) and (1,0)
  44. // OpenGL object IDs
  45. GLuint texture_id;
  46. GLuint vertex_buffer_id;
  47. // Temporary
  48. u8* flipped_xfb_data;
  49. };
  50. /**
  51. * Helper function to flip framebuffer from left-to-right to top-to-bottom
  52. * @param raw_data Pointer to input raw framebuffer in V/RAM
  53. * @param screen_info ScreenInfo structure with screen size and output buffer pointer
  54. * @todo Early on hack... I'd like to find a more efficient way of doing this /bunnei
  55. */
  56. void FlipFramebuffer(const u8* raw_data, ScreenInfo& screen_info);
  57. EmuWindow* render_window; ///< Handle to render window
  58. u32 last_mode; ///< Last render mode
  59. int resolution_width; ///< Current resolution width
  60. int resolution_height; ///< Current resolution height
  61. // OpenGL global object IDs
  62. GLuint vertex_array_id;
  63. GLuint program_id;
  64. GLuint sampler_id;
  65. struct : std::array<ScreenInfo, 2> {
  66. ScreenInfo& Top() { return (*this)[0]; }
  67. ScreenInfo& Bottom() { return (*this)[1]; }
  68. } screen_info;
  69. // "Flipped" framebuffers translate scanlines from native 3DS left-to-right to top-to-bottom
  70. // as OpenGL expects them in a texture. There probably is a more efficient way of doing this:
  71. u8 xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopHeight * 4];
  72. u8 xfb_bottom_flipped[VideoCore::kScreenBottomWidth * VideoCore::kScreenBottomHeight * 4];
  73. };