diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 954daba5f..53d8d1967 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -42,6 +42,8 @@ add_library(core gte.h gte.inl gte_types.h + host_display.cpp + host_display.h host_interface.cpp host_interface.h interrupt_controller.cpp diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index e083a791c..8f077ff9b 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -70,6 +70,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 0481e643c..651b6c191 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -38,6 +38,7 @@ + diff --git a/src/core/host_display.cpp b/src/core/host_display.cpp new file mode 100644 index 000000000..bbfc2edd0 --- /dev/null +++ b/src/core/host_display.cpp @@ -0,0 +1,27 @@ +#include "host_display.h" + +HostDisplayTexture::~HostDisplayTexture() = default; + +HostDisplay::~HostDisplay() = default; + +std::tuple HostDisplay::CalculateDrawRect(int window_width, int window_height, float display_ratio) +{ + const float window_ratio = float(window_width) / float(window_height); + int left, top, width, height; + if (window_ratio >= display_ratio) + { + width = static_cast(float(window_height) * display_ratio); + height = static_cast(window_height); + left = (window_width - width) / 2; + top = 0; + } + else + { + width = static_cast(window_width); + height = static_cast(float(window_width) / display_ratio); + left = 0; + top = (window_height - height) / 2; + } + + return std::tie(left, top, width, height); +} diff --git a/src/core/host_display.h b/src/core/host_display.h index 38ab7262f..50bb1f366 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -7,7 +7,7 @@ class HostDisplayTexture { public: - virtual ~HostDisplayTexture() {} + virtual ~HostDisplayTexture(); virtual void* GetHandle() const = 0; virtual u32 GetWidth() const = 0; @@ -26,7 +26,7 @@ public: OpenGLES }; - virtual ~HostDisplay() {} + virtual ~HostDisplay(); virtual RenderAPI GetRenderAPI() const = 0; virtual void* GetRenderDevice() const = 0; @@ -42,11 +42,6 @@ public: virtual void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) = 0; - virtual void SetDisplayTexture(void* texture_handle, s32 offset_x, s32 offset_y, s32 width, s32 height, - u32 texture_width, u32 texture_height, float aspect_ratio) = 0; - virtual void SetDisplayLinearFiltering(bool enabled) = 0; - virtual void SetDisplayTopMargin(int height) = 0; - virtual void Render() = 0; virtual void SetVSync(bool enabled) = 0; @@ -54,26 +49,39 @@ public: virtual std::tuple GetWindowSize() const = 0; virtual void WindowResized() = 0; - // Helper function for computing the draw rectangle in a larger window. - static std::tuple CalculateDrawRect(int window_width, int window_height, float display_ratio) - { - const float window_ratio = float(window_width) / float(window_height); - int left, top, width, height; - if (window_ratio >= display_ratio) - { - width = static_cast(float(window_height) * display_ratio); - height = static_cast(window_height); - left = (window_width - width) / 2; - top = 0; - } - else - { - width = static_cast(window_width); - height = static_cast(float(window_width) / display_ratio); - left = 0; - top = (window_height - height) / 2; - } + const s32 GetDisplayTopMargin() const { return m_display_top_margin; } - return std::tie(left, top, width, height); + void SetDisplayTexture(void* texture_handle, s32 offset_x, s32 offset_y, s32 width, s32 height, u32 texture_width, + u32 texture_height, float aspect_ratio) + { + m_display_texture_handle = texture_handle; + m_display_offset_x = offset_x; + m_display_offset_y = offset_y; + m_display_width = width; + m_display_height = height; + m_display_texture_width = texture_width; + m_display_texture_height = texture_height; + m_display_aspect_ratio = aspect_ratio; + m_display_texture_changed = true; } + + void SetDisplayLinearFiltering(bool enabled) { m_display_linear_filtering = enabled; } + void SetDisplayTopMargin(s32 height) { m_display_top_margin = height; } + + // Helper function for computing the draw rectangle in a larger window. + static std::tuple CalculateDrawRect(int window_width, int window_height, float display_ratio); + +protected: + void* m_display_texture_handle = nullptr; + s32 m_display_offset_x = 0; + s32 m_display_offset_y = 0; + s32 m_display_width = 0; + s32 m_display_height = 0; + u32 m_display_texture_width = 0; + u32 m_display_texture_height = 0; + s32 m_display_top_margin = 0; + float m_display_aspect_ratio = 1.0f; + + bool m_display_texture_changed = false; + bool m_display_linear_filtering = false; }; diff --git a/src/duckstation-qt/d3d11displaywindow.cpp b/src/duckstation-qt/d3d11displaywindow.cpp index 706a83b9d..12ec266c9 100644 --- a/src/duckstation-qt/d3d11displaywindow.cpp +++ b/src/duckstation-qt/d3d11displaywindow.cpp @@ -138,30 +138,6 @@ void D3D11DisplayWindow::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y } } -void D3D11DisplayWindow::SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, - u32 texture_width, u32 texture_height, float aspect_ratio) -{ - m_display_srv = static_cast(texture); - m_display_offset_x = offset_x; - m_display_offset_y = offset_y; - m_display_width = width; - m_display_height = height; - m_display_texture_width = texture_width; - m_display_texture_height = texture_height; - m_display_aspect_ratio = aspect_ratio; - m_display_texture_changed = true; -} - -void D3D11DisplayWindow::SetDisplayLinearFiltering(bool enabled) -{ - m_display_linear_filtering = enabled; -} - -void D3D11DisplayWindow::SetDisplayTopMargin(int height) -{ - m_display_top_margin = height; -} - void D3D11DisplayWindow::SetVSync(bool enabled) { m_vsync = enabled; @@ -452,7 +428,7 @@ void D3D11DisplayWindow::Render() void D3D11DisplayWindow::renderDisplay() { - if (!m_display_srv) + if (!m_display_texture_handle) return; // - 20 for main menu padding @@ -463,7 +439,7 @@ void D3D11DisplayWindow::renderDisplay() m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_context->VSSetShader(m_display_vertex_shader.Get(), nullptr, 0); m_context->PSSetShader(m_display_pixel_shader.Get(), nullptr, 0); - m_context->PSSetShaderResources(0, 1, &m_display_srv); + m_context->PSSetShaderResources(0, 1, reinterpret_cast(&m_display_texture_handle)); m_context->PSSetSamplers( 0, 1, m_display_linear_filtering ? m_linear_sampler.GetAddressOf() : m_point_sampler.GetAddressOf()); diff --git a/src/duckstation-qt/d3d11displaywindow.h b/src/duckstation-qt/d3d11displaywindow.h index 0342ac89c..c3a529cca 100644 --- a/src/duckstation-qt/d3d11displaywindow.h +++ b/src/duckstation-qt/d3d11displaywindow.h @@ -37,11 +37,6 @@ public: void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) override; - void SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, u32 texture_width, - u32 texture_height, float aspect_ratio) override; - void SetDisplayLinearFiltering(bool enabled) override; - void SetDisplayTopMargin(int height) override; - void SetVSync(bool enabled) override; std::tuple GetWindowSize() const override; @@ -79,18 +74,6 @@ private: D3D11::Texture m_display_pixels_texture; D3D11::StreamBuffer m_display_uniform_buffer; - ID3D11ShaderResourceView* m_display_srv = nullptr; - s32 m_display_offset_x = 0; - s32 m_display_offset_y = 0; - s32 m_display_width = 0; - s32 m_display_height = 0; - u32 m_display_texture_width = 0; - u32 m_display_texture_height = 0; - int m_display_top_margin = 0; - float m_display_aspect_ratio = 1.0f; - - bool m_display_texture_changed = false; - bool m_display_linear_filtering = false; bool m_allow_tearing_supported = false; bool m_vsync = false; }; diff --git a/src/duckstation-qt/opengldisplaywindow.cpp b/src/duckstation-qt/opengldisplaywindow.cpp index f5f690045..5bfdae870 100644 --- a/src/duckstation-qt/opengldisplaywindow.cpp +++ b/src/duckstation-qt/opengldisplaywindow.cpp @@ -155,30 +155,6 @@ void OpenGLDisplayWindow::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 glBindTexture(GL_TEXTURE_2D, old_texture_binding); } -void OpenGLDisplayWindow::SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, - u32 texture_width, u32 texture_height, float aspect_ratio) -{ - m_display_texture_id = static_cast(reinterpret_cast(texture)); - m_display_offset_x = offset_x; - m_display_offset_y = offset_y; - m_display_width = width; - m_display_height = height; - m_display_texture_width = texture_width; - m_display_texture_height = texture_height; - m_display_aspect_ratio = aspect_ratio; - m_display_texture_changed = true; -} - -void OpenGLDisplayWindow::SetDisplayLinearFiltering(bool enabled) -{ - m_display_linear_filtering = enabled; -} - -void OpenGLDisplayWindow::SetDisplayTopMargin(int height) -{ - m_display_top_margin = height; -} - void OpenGLDisplayWindow::SetVSync(bool enabled) { // Window framebuffer has to be bound to call SetSwapInterval. @@ -473,7 +449,7 @@ void OpenGLDisplayWindow::Render() void OpenGLDisplayWindow::renderDisplay() { - if (!m_display_texture_id) + if (!m_display_texture_handle) return; // - 20 for main menu padding @@ -491,7 +467,7 @@ void OpenGLDisplayWindow::renderDisplay() static_cast(m_display_offset_y) / static_cast(m_display_texture_height), static_cast(m_display_width) / static_cast(m_display_texture_width), static_cast(m_display_height) / static_cast(m_display_texture_height)); - glBindTexture(GL_TEXTURE_2D, m_display_texture_id); + glBindTexture(GL_TEXTURE_2D, static_cast(reinterpret_cast(m_display_texture_handle))); glBindSampler(0, m_display_linear_filtering ? m_display_linear_sampler : m_display_nearest_sampler); glBindVertexArray(m_display_vao); glDrawArrays(GL_TRIANGLES, 0, 3); diff --git a/src/duckstation-qt/opengldisplaywindow.h b/src/duckstation-qt/opengldisplaywindow.h index e50748588..3bd8f8ec8 100644 --- a/src/duckstation-qt/opengldisplaywindow.h +++ b/src/duckstation-qt/opengldisplaywindow.h @@ -36,11 +36,6 @@ public: void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) override; - void SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, u32 texture_width, - u32 texture_height, float aspect_ratio) override; - void SetDisplayLinearFiltering(bool enabled) override; - void SetDisplayTopMargin(int height) override; - void SetVSync(bool enabled) override; std::tuple GetWindowSize() const override; @@ -63,19 +58,8 @@ private: GL::Program m_display_program; GLuint m_display_vao = 0; - GLuint m_display_texture_id = 0; - s32 m_display_offset_x = 0; - s32 m_display_offset_y = 0; - s32 m_display_width = 0; - s32 m_display_height = 0; - u32 m_display_texture_width = 0; - u32 m_display_texture_height = 0; - int m_display_top_margin = 0; - float m_display_aspect_ratio = 1.0f; GLuint m_display_nearest_sampler = 0; GLuint m_display_linear_sampler = 0; bool m_is_gles = false; - bool m_display_texture_changed = false; - bool m_display_linear_filtering = false; }; diff --git a/src/duckstation-qt/qtdisplaywindow.h b/src/duckstation-qt/qtdisplaywindow.h index ef83eb5f1..abbd6c19c 100644 --- a/src/duckstation-qt/qtdisplaywindow.h +++ b/src/duckstation-qt/qtdisplaywindow.h @@ -22,8 +22,6 @@ public: virtual bool initializeDeviceContext(bool debug_device); virtual void destroyDeviceContext(); - virtual void SetDisplayLinearFiltering(bool enabled) = 0; - virtual void SetDisplayTopMargin(int height) = 0; virtual void Render() = 0; // this comes back on the emu thread diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 3341c01b2..ab2471ca9 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -143,7 +143,7 @@ void QtHostInterface::applySettings() } if (m_settings.display_linear_filtering != old_display_linear_filtering) - m_display_window->SetDisplayLinearFiltering(m_settings.display_linear_filtering); + m_display_window->getHostDisplayInterface()->SetDisplayLinearFiltering(m_settings.display_linear_filtering); } void QtHostInterface::checkSettings() diff --git a/src/duckstation/d3d11_host_display.cpp b/src/duckstation/d3d11_host_display.cpp index df72a0918..de2c60dda 100644 --- a/src/duckstation/d3d11_host_display.cpp +++ b/src/duckstation/d3d11_host_display.cpp @@ -142,30 +142,6 @@ void D3D11HostDisplay::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, } } -void D3D11HostDisplay::SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, - u32 texture_width, u32 texture_height, float aspect_ratio) -{ - m_display_srv = static_cast(texture); - m_display_offset_x = offset_x; - m_display_offset_y = offset_y; - m_display_width = width; - m_display_height = height; - m_display_texture_width = texture_width; - m_display_texture_height = texture_height; - m_display_aspect_ratio = aspect_ratio; - m_display_texture_changed = true; -} - -void D3D11HostDisplay::SetDisplayLinearFiltering(bool enabled) -{ - m_display_linear_filtering = enabled; -} - -void D3D11HostDisplay::SetDisplayTopMargin(int height) -{ - m_display_top_margin = height; -} - void D3D11HostDisplay::SetVSync(bool enabled) { m_vsync = enabled; @@ -418,7 +394,7 @@ void D3D11HostDisplay::Render() void D3D11HostDisplay::RenderDisplay() { - if (!m_display_srv) + if (!m_display_texture_handle) return; // - 20 for main menu padding @@ -429,7 +405,7 @@ void D3D11HostDisplay::RenderDisplay() m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_context->VSSetShader(m_display_vertex_shader.Get(), nullptr, 0); m_context->PSSetShader(m_display_pixel_shader.Get(), nullptr, 0); - m_context->PSSetShaderResources(0, 1, &m_display_srv); + m_context->PSSetShaderResources(0, 1, reinterpret_cast(&m_display_texture_handle)); m_context->PSSetSamplers( 0, 1, m_display_linear_filtering ? m_linear_sampler.GetAddressOf() : m_point_sampler.GetAddressOf()); diff --git a/src/duckstation/d3d11_host_display.h b/src/duckstation/d3d11_host_display.h index c56177bdb..fffd5d108 100644 --- a/src/duckstation/d3d11_host_display.h +++ b/src/duckstation/d3d11_host_display.h @@ -31,11 +31,6 @@ public: void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) override; - void SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, u32 texture_width, - u32 texture_height, float aspect_ratio) override; - void SetDisplayLinearFiltering(bool enabled) override; - void SetDisplayTopMargin(int height) override; - void SetVSync(bool enabled) override; std::tuple GetWindowSize() const override; @@ -73,18 +68,6 @@ private: D3D11::Texture m_display_pixels_texture; D3D11::StreamBuffer m_display_uniform_buffer; - ID3D11ShaderResourceView* m_display_srv = nullptr; - s32 m_display_offset_x = 0; - s32 m_display_offset_y = 0; - s32 m_display_width = 0; - s32 m_display_height = 0; - u32 m_display_texture_width = 0; - u32 m_display_texture_height = 0; - int m_display_top_margin = 0; - float m_display_aspect_ratio = 1.0f; - - bool m_display_texture_changed = false; - bool m_display_linear_filtering = false; bool m_allow_tearing_supported = false; bool m_vsync = false; }; diff --git a/src/duckstation/opengl_host_display.cpp b/src/duckstation/opengl_host_display.cpp index ff33e571a..886e42f8b 100644 --- a/src/duckstation/opengl_host_display.cpp +++ b/src/duckstation/opengl_host_display.cpp @@ -121,30 +121,6 @@ void OpenGLHostDisplay::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, glBindTexture(GL_TEXTURE_2D, old_texture_binding); } -void OpenGLHostDisplay::SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, - u32 texture_width, u32 texture_height, float aspect_ratio) -{ - m_display_texture_id = static_cast(reinterpret_cast(texture)); - m_display_offset_x = offset_x; - m_display_offset_y = offset_y; - m_display_width = width; - m_display_height = height; - m_display_texture_width = texture_width; - m_display_texture_height = texture_height; - m_display_aspect_ratio = aspect_ratio; - m_display_texture_changed = true; -} - -void OpenGLHostDisplay::SetDisplayLinearFiltering(bool enabled) -{ - m_display_linear_filtering = enabled; -} - -void OpenGLHostDisplay::SetDisplayTopMargin(int height) -{ - m_display_top_margin = height; -} - void OpenGLHostDisplay::SetVSync(bool enabled) { // Window framebuffer has to be bound to call SetSwapInterval. @@ -376,7 +352,7 @@ void OpenGLHostDisplay::Render() void OpenGLHostDisplay::RenderDisplay() { - if (!m_display_texture_id) + if (!m_display_texture_handle) return; // - 20 for main menu padding @@ -394,7 +370,7 @@ void OpenGLHostDisplay::RenderDisplay() static_cast(m_display_offset_y) / static_cast(m_display_texture_height), static_cast(m_display_width) / static_cast(m_display_texture_width), static_cast(m_display_height) / static_cast(m_display_texture_height)); - glBindTexture(GL_TEXTURE_2D, m_display_texture_id); + glBindTexture(GL_TEXTURE_2D, static_cast(reinterpret_cast(m_display_texture_handle))); glBindSampler(0, m_display_linear_filtering ? m_display_linear_sampler : m_display_nearest_sampler); glBindVertexArray(m_display_vao); glDrawArrays(GL_TRIANGLES, 0, 3); diff --git a/src/duckstation/opengl_host_display.h b/src/duckstation/opengl_host_display.h index 77538db7d..4a05c0532 100644 --- a/src/duckstation/opengl_host_display.h +++ b/src/duckstation/opengl_host_display.h @@ -26,11 +26,6 @@ public: void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) override; - void SetDisplayTexture(void* texture, s32 offset_x, s32 offset_y, s32 width, s32 height, u32 texture_width, - u32 texture_height, float aspect_ratio) override; - void SetDisplayLinearFiltering(bool enabled) override; - void SetDisplayTopMargin(int height) override; - void SetVSync(bool enabled) override; std::tuple GetWindowSize() const override; @@ -54,19 +49,8 @@ private: GL::Program m_display_program; GLuint m_display_vao = 0; - GLuint m_display_texture_id = 0; - s32 m_display_offset_x = 0; - s32 m_display_offset_y = 0; - s32 m_display_width = 0; - s32 m_display_height = 0; - u32 m_display_texture_width = 0; - u32 m_display_texture_height = 0; - int m_display_top_margin = 0; - float m_display_aspect_ratio = 1.0f; GLuint m_display_nearest_sampler = 0; GLuint m_display_linear_sampler = 0; bool m_is_gles = false; - bool m_display_texture_changed = false; - bool m_display_linear_filtering = false; };