diff options
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/renderer_base.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/renderer_base.h | 15 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 26 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 15 | ||||
| -rw-r--r-- | src/video_core/video_core.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/video_core.h | 3 |
8 files changed, 41 insertions, 51 deletions
diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp index 30075b23c..dbe3edf09 100644 --- a/src/video_core/renderer_base.cpp +++ b/src/video_core/renderer_base.cpp | |||
| @@ -2,14 +2,22 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | #include <memory> | 5 | #include <memory> |
| 6 | #include "core/frontend/emu_window.h" | ||
| 7 | #include "video_core/renderer_base.h" | 7 | #include "video_core/renderer_base.h" |
| 8 | #include "video_core/renderer_opengl/gl_rasterizer.h" | 8 | #include "video_core/renderer_opengl/gl_rasterizer.h" |
| 9 | #include "video_core/video_core.h" | 9 | |
| 10 | RendererBase::RendererBase(EmuWindow& window) : render_window{window} {} | ||
| 11 | RendererBase::~RendererBase() = default; | ||
| 12 | |||
| 13 | void RendererBase::UpdateCurrentFramebufferLayout() { | ||
| 14 | const Layout::FramebufferLayout& layout = render_window.GetFramebufferLayout(); | ||
| 15 | |||
| 16 | render_window.UpdateCurrentFramebufferLayout(layout.width, layout.height); | ||
| 17 | } | ||
| 10 | 18 | ||
| 11 | void RendererBase::RefreshRasterizerSetting() { | 19 | void RendererBase::RefreshRasterizerSetting() { |
| 12 | if (rasterizer == nullptr) { | 20 | if (rasterizer == nullptr) { |
| 13 | rasterizer = std::make_unique<RasterizerOpenGL>(); | 21 | rasterizer = std::make_unique<RasterizerOpenGL>(render_window); |
| 14 | } | 22 | } |
| 15 | } | 23 | } |
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index 89a960eaf..1cb161b7f 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h | |||
| @@ -18,23 +18,21 @@ public: | |||
| 18 | /// Used to reference a framebuffer | 18 | /// Used to reference a framebuffer |
| 19 | enum kFramebuffer { kFramebuffer_VirtualXFB = 0, kFramebuffer_EFB, kFramebuffer_Texture }; | 19 | enum kFramebuffer { kFramebuffer_VirtualXFB = 0, kFramebuffer_EFB, kFramebuffer_Texture }; |
| 20 | 20 | ||
| 21 | virtual ~RendererBase() {} | 21 | explicit RendererBase(EmuWindow& window); |
| 22 | virtual ~RendererBase(); | ||
| 22 | 23 | ||
| 23 | /// Swap buffers (render frame) | 24 | /// Swap buffers (render frame) |
| 24 | virtual void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) = 0; | 25 | virtual void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) = 0; |
| 25 | 26 | ||
| 26 | /** | ||
| 27 | * Set the emulator window to use for renderer | ||
| 28 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 29 | */ | ||
| 30 | virtual void SetWindow(EmuWindow* window) = 0; | ||
| 31 | |||
| 32 | /// Initialize the renderer | 27 | /// Initialize the renderer |
| 33 | virtual bool Init() = 0; | 28 | virtual bool Init() = 0; |
| 34 | 29 | ||
| 35 | /// Shutdown the renderer | 30 | /// Shutdown the renderer |
| 36 | virtual void ShutDown() = 0; | 31 | virtual void ShutDown() = 0; |
| 37 | 32 | ||
| 33 | /// Updates the framebuffer layout of the contained render window handle. | ||
| 34 | void UpdateCurrentFramebufferLayout(); | ||
| 35 | |||
| 38 | // Getter/setter functions: | 36 | // Getter/setter functions: |
| 39 | // ------------------------ | 37 | // ------------------------ |
| 40 | 38 | ||
| @@ -53,9 +51,8 @@ public: | |||
| 53 | void RefreshRasterizerSetting(); | 51 | void RefreshRasterizerSetting(); |
| 54 | 52 | ||
| 55 | protected: | 53 | protected: |
| 54 | EmuWindow& render_window; ///< Reference to the render window handle. | ||
| 56 | std::unique_ptr<VideoCore::RasterizerInterface> rasterizer; | 55 | std::unique_ptr<VideoCore::RasterizerInterface> rasterizer; |
| 57 | f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer | 56 | f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer |
| 58 | int m_current_frame = 0; ///< Current frame, should be set by the renderer | 57 | int m_current_frame = 0; ///< Current frame, should be set by the renderer |
| 59 | |||
| 60 | private: | ||
| 61 | }; | 58 | }; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index a1c47bae9..6555db5bb 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| 15 | #include "common/math_util.h" | 15 | #include "common/math_util.h" |
| 16 | #include "common/microprofile.h" | 16 | #include "common/microprofile.h" |
| 17 | #include "common/scope_exit.h" | ||
| 18 | #include "core/core.h" | 17 | #include "core/core.h" |
| 19 | #include "core/frontend/emu_window.h" | 18 | #include "core/frontend/emu_window.h" |
| 20 | #include "core/hle/kernel/process.h" | 19 | #include "core/hle/kernel/process.h" |
| @@ -37,7 +36,7 @@ MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192)); | |||
| 37 | MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255)); | 36 | MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255)); |
| 38 | MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); | 37 | MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); |
| 39 | 38 | ||
| 40 | RasterizerOpenGL::RasterizerOpenGL() { | 39 | RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window) : emu_window{window} { |
| 41 | // Create sampler objects | 40 | // Create sampler objects |
| 42 | for (size_t i = 0; i < texture_samplers.size(); ++i) { | 41 | for (size_t i = 0; i < texture_samplers.size(); ++i) { |
| 43 | texture_samplers[i].Create(); | 42 | texture_samplers[i].Create(); |
| @@ -395,7 +394,7 @@ void RasterizerOpenGL::Clear() { | |||
| 395 | if (clear_mask == 0) | 394 | if (clear_mask == 0) |
| 396 | return; | 395 | return; |
| 397 | 396 | ||
| 398 | ScopeAcquireGLContext acquire_context; | 397 | ScopeAcquireGLContext acquire_context{emu_window}; |
| 399 | 398 | ||
| 400 | auto [dirty_color_surface, dirty_depth_surface] = | 399 | auto [dirty_color_surface, dirty_depth_surface] = |
| 401 | ConfigureFramebuffers(use_color_fb, use_depth_fb); | 400 | ConfigureFramebuffers(use_color_fb, use_depth_fb); |
| @@ -425,7 +424,7 @@ void RasterizerOpenGL::DrawArrays() { | |||
| 425 | MICROPROFILE_SCOPE(OpenGL_Drawing); | 424 | MICROPROFILE_SCOPE(OpenGL_Drawing); |
| 426 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; | 425 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; |
| 427 | 426 | ||
| 428 | ScopeAcquireGLContext acquire_context; | 427 | ScopeAcquireGLContext acquire_context{emu_window}; |
| 429 | 428 | ||
| 430 | auto [dirty_color_surface, dirty_depth_surface] = | 429 | auto [dirty_color_surface, dirty_depth_surface] = |
| 431 | ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0); | 430 | ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index e150be58f..6d6d85cc1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -21,11 +21,12 @@ | |||
| 21 | #include "video_core/renderer_opengl/gl_state.h" | 21 | #include "video_core/renderer_opengl/gl_state.h" |
| 22 | #include "video_core/renderer_opengl/gl_stream_buffer.h" | 22 | #include "video_core/renderer_opengl/gl_stream_buffer.h" |
| 23 | 23 | ||
| 24 | class EmuWindow; | ||
| 24 | struct ScreenInfo; | 25 | struct ScreenInfo; |
| 25 | 26 | ||
| 26 | class RasterizerOpenGL : public VideoCore::RasterizerInterface { | 27 | class RasterizerOpenGL : public VideoCore::RasterizerInterface { |
| 27 | public: | 28 | public: |
| 28 | RasterizerOpenGL(); | 29 | explicit RasterizerOpenGL(EmuWindow& renderer); |
| 29 | ~RasterizerOpenGL() override; | 30 | ~RasterizerOpenGL() override; |
| 30 | 31 | ||
| 31 | void DrawArrays() override; | 32 | void DrawArrays() override; |
| @@ -144,6 +145,8 @@ private: | |||
| 144 | 145 | ||
| 145 | RasterizerCacheOpenGL res_cache; | 146 | RasterizerCacheOpenGL res_cache; |
| 146 | 147 | ||
| 148 | EmuWindow& emu_window; | ||
| 149 | |||
| 147 | std::unique_ptr<GLShader::ProgramManager> shader_program_manager; | 150 | std::unique_ptr<GLShader::ProgramManager> shader_program_manager; |
| 148 | OGLVertexArray sw_vao; | 151 | OGLVertexArray sw_vao; |
| 149 | OGLVertexArray hw_vao; | 152 | OGLVertexArray hw_vao; |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 7810b9147..74383c7cf 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -92,23 +92,23 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons | |||
| 92 | return matrix; | 92 | return matrix; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | ScopeAcquireGLContext::ScopeAcquireGLContext() { | 95 | ScopeAcquireGLContext::ScopeAcquireGLContext(EmuWindow& emu_window_) : emu_window{emu_window_} { |
| 96 | if (Settings::values.use_multi_core) { | 96 | if (Settings::values.use_multi_core) { |
| 97 | VideoCore::g_emu_window->MakeCurrent(); | 97 | emu_window.MakeCurrent(); |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| 100 | ScopeAcquireGLContext::~ScopeAcquireGLContext() { | 100 | ScopeAcquireGLContext::~ScopeAcquireGLContext() { |
| 101 | if (Settings::values.use_multi_core) { | 101 | if (Settings::values.use_multi_core) { |
| 102 | VideoCore::g_emu_window->DoneCurrent(); | 102 | emu_window.DoneCurrent(); |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | RendererOpenGL::RendererOpenGL() = default; | 106 | RendererOpenGL::RendererOpenGL(EmuWindow& window) : RendererBase{window} {} |
| 107 | RendererOpenGL::~RendererOpenGL() = default; | 107 | RendererOpenGL::~RendererOpenGL() = default; |
| 108 | 108 | ||
| 109 | /// Swap buffers (render frame) | 109 | /// Swap buffers (render frame) |
| 110 | void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { | 110 | void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { |
| 111 | ScopeAcquireGLContext acquire_context; | 111 | ScopeAcquireGLContext acquire_context{render_window}; |
| 112 | 112 | ||
| 113 | Core::System::GetInstance().perf_stats.EndSystemFrame(); | 113 | Core::System::GetInstance().perf_stats.EndSystemFrame(); |
| 114 | 114 | ||
| @@ -130,10 +130,10 @@ void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig& | |||
| 130 | // Load the framebuffer from memory, draw it to the screen, and swap buffers | 130 | // Load the framebuffer from memory, draw it to the screen, and swap buffers |
| 131 | LoadFBToScreenInfo(*framebuffer, screen_info); | 131 | LoadFBToScreenInfo(*framebuffer, screen_info); |
| 132 | DrawScreen(); | 132 | DrawScreen(); |
| 133 | render_window->SwapBuffers(); | 133 | render_window.SwapBuffers(); |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | render_window->PollEvents(); | 136 | render_window.PollEvents(); |
| 137 | 137 | ||
| 138 | Core::System::GetInstance().frame_limiter.DoFrameLimiting(CoreTiming::GetGlobalTimeUs()); | 138 | Core::System::GetInstance().frame_limiter.DoFrameLimiting(CoreTiming::GetGlobalTimeUs()); |
| 139 | Core::System::GetInstance().perf_stats.BeginSystemFrame(); | 139 | Core::System::GetInstance().perf_stats.BeginSystemFrame(); |
| @@ -356,7 +356,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x, | |||
| 356 | * Draws the emulated screens to the emulator window. | 356 | * Draws the emulated screens to the emulator window. |
| 357 | */ | 357 | */ |
| 358 | void RendererOpenGL::DrawScreen() { | 358 | void RendererOpenGL::DrawScreen() { |
| 359 | const auto& layout = render_window->GetFramebufferLayout(); | 359 | const auto& layout = render_window.GetFramebufferLayout(); |
| 360 | const auto& screen = layout.screen; | 360 | const auto& screen = layout.screen; |
| 361 | 361 | ||
| 362 | glViewport(0, 0, layout.width, layout.height); | 362 | glViewport(0, 0, layout.width, layout.height); |
| @@ -380,14 +380,6 @@ void RendererOpenGL::DrawScreen() { | |||
| 380 | /// Updates the framerate | 380 | /// Updates the framerate |
| 381 | void RendererOpenGL::UpdateFramerate() {} | 381 | void RendererOpenGL::UpdateFramerate() {} |
| 382 | 382 | ||
| 383 | /** | ||
| 384 | * Set the emulator window to use for renderer | ||
| 385 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 386 | */ | ||
| 387 | void RendererOpenGL::SetWindow(EmuWindow* window) { | ||
| 388 | render_window = window; | ||
| 389 | } | ||
| 390 | |||
| 391 | static const char* GetSource(GLenum source) { | 383 | static const char* GetSource(GLenum source) { |
| 392 | #define RET(s) \ | 384 | #define RET(s) \ |
| 393 | case GL_DEBUG_SOURCE_##s: \ | 385 | case GL_DEBUG_SOURCE_##s: \ |
| @@ -445,7 +437,7 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum | |||
| 445 | 437 | ||
| 446 | /// Initialize the renderer | 438 | /// Initialize the renderer |
| 447 | bool RendererOpenGL::Init() { | 439 | bool RendererOpenGL::Init() { |
| 448 | ScopeAcquireGLContext acquire_context; | 440 | ScopeAcquireGLContext acquire_context{render_window}; |
| 449 | 441 | ||
| 450 | if (GLAD_GL_KHR_debug) { | 442 | if (GLAD_GL_KHR_debug) { |
| 451 | glEnable(GL_DEBUG_OUTPUT); | 443 | glEnable(GL_DEBUG_OUTPUT); |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 59d92a3dc..ab7de41c8 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h | |||
| @@ -34,24 +34,21 @@ struct ScreenInfo { | |||
| 34 | /// Helper class to acquire/release OpenGL context within a given scope | 34 | /// Helper class to acquire/release OpenGL context within a given scope |
| 35 | class ScopeAcquireGLContext : NonCopyable { | 35 | class ScopeAcquireGLContext : NonCopyable { |
| 36 | public: | 36 | public: |
| 37 | ScopeAcquireGLContext(); | 37 | explicit ScopeAcquireGLContext(EmuWindow& window); |
| 38 | ~ScopeAcquireGLContext(); | 38 | ~ScopeAcquireGLContext(); |
| 39 | |||
| 40 | private: | ||
| 41 | EmuWindow& emu_window; | ||
| 39 | }; | 42 | }; |
| 40 | 43 | ||
| 41 | class RendererOpenGL : public RendererBase { | 44 | class RendererOpenGL : public RendererBase { |
| 42 | public: | 45 | public: |
| 43 | RendererOpenGL(); | 46 | explicit RendererOpenGL(EmuWindow& window); |
| 44 | ~RendererOpenGL() override; | 47 | ~RendererOpenGL() override; |
| 45 | 48 | ||
| 46 | /// Swap buffers (render frame) | 49 | /// Swap buffers (render frame) |
| 47 | void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) override; | 50 | void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) override; |
| 48 | 51 | ||
| 49 | /** | ||
| 50 | * Set the emulator window to use for renderer | ||
| 51 | * @param window EmuWindow handle to emulator window to use for rendering | ||
| 52 | */ | ||
| 53 | void SetWindow(EmuWindow* window) override; | ||
| 54 | |||
| 55 | /// Initialize the renderer | 52 | /// Initialize the renderer |
| 56 | bool Init() override; | 53 | bool Init() override; |
| 57 | 54 | ||
| @@ -72,8 +69,6 @@ private: | |||
| 72 | void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, | 69 | void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, |
| 73 | const TextureInfo& texture); | 70 | const TextureInfo& texture); |
| 74 | 71 | ||
| 75 | EmuWindow* render_window; ///< Handle to render window | ||
| 76 | |||
| 77 | OpenGLState state; | 72 | OpenGLState state; |
| 78 | 73 | ||
| 79 | // OpenGL object IDs | 74 | // OpenGL object IDs |
diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 289140f31..06b13e681 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp | |||
| @@ -13,16 +13,13 @@ | |||
| 13 | 13 | ||
| 14 | namespace VideoCore { | 14 | namespace VideoCore { |
| 15 | 15 | ||
| 16 | EmuWindow* g_emu_window = nullptr; ///< Frontend emulator window | ||
| 17 | std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin | 16 | std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin |
| 18 | 17 | ||
| 19 | std::atomic<bool> g_toggle_framelimit_enabled; | 18 | std::atomic<bool> g_toggle_framelimit_enabled; |
| 20 | 19 | ||
| 21 | /// Initialize the video core | 20 | /// Initialize the video core |
| 22 | bool Init(EmuWindow* emu_window) { | 21 | bool Init(EmuWindow& emu_window) { |
| 23 | g_emu_window = emu_window; | 22 | g_renderer = std::make_unique<RendererOpenGL>(emu_window); |
| 24 | g_renderer = std::make_unique<RendererOpenGL>(); | ||
| 25 | g_renderer->SetWindow(g_emu_window); | ||
| 26 | if (g_renderer->Init()) { | 23 | if (g_renderer->Init()) { |
| 27 | LOG_DEBUG(Render, "initialized OK"); | 24 | LOG_DEBUG(Render, "initialized OK"); |
| 28 | } else { | 25 | } else { |
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index 37da62436..8707e9881 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h | |||
| @@ -18,7 +18,6 @@ namespace VideoCore { | |||
| 18 | enum class Renderer { Software, OpenGL }; | 18 | enum class Renderer { Software, OpenGL }; |
| 19 | 19 | ||
| 20 | extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin | 20 | extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin |
| 21 | extern EmuWindow* g_emu_window; ///< Emu window | ||
| 22 | 21 | ||
| 23 | // TODO: Wrap these in a user settings struct along with any other graphics settings (often set from | 22 | // TODO: Wrap these in a user settings struct along with any other graphics settings (often set from |
| 24 | // qt ui) | 23 | // qt ui) |
| @@ -28,7 +27,7 @@ extern std::atomic<bool> g_toggle_framelimit_enabled; | |||
| 28 | void Start(); | 27 | void Start(); |
| 29 | 28 | ||
| 30 | /// Initialize the video core | 29 | /// Initialize the video core |
| 31 | bool Init(EmuWindow* emu_window); | 30 | bool Init(EmuWindow& emu_window); |
| 32 | 31 | ||
| 33 | /// Shutdown the video core | 32 | /// Shutdown the video core |
| 34 | void Shutdown(); | 33 | void Shutdown(); |