From c9feb7ea070d7fd162977d49c0d09259abbfdbf1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 2 Nov 2019 00:31:25 +1000 Subject: [PATCH] GPU: Add force true color setting --- src/core/gpu.cpp | 2 +- src/core/gpu.h | 2 +- src/core/gpu_hw.cpp | 16 ++++++++++++++-- src/core/gpu_hw.h | 2 ++ src/core/gpu_hw_opengl.cpp | 8 ++++---- src/core/gpu_hw_opengl.h | 2 +- src/core/settings.h | 1 + src/duckstation/sdl_interface.cpp | 9 ++++++--- 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 046fa714c..6a20f805c 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -26,7 +26,7 @@ bool GPU::Initialize(System* system, DMA* dma, InterruptController* interrupt_co return true; } -void GPU::UpdateResolutionScale() +void GPU::UpdateSettings() { m_resolution_scale = std::clamp(m_system->GetSettings().gpu_resolution_scale, 1, m_max_resolution_scale); } diff --git a/src/core/gpu.h b/src/core/gpu.h index 9b8f8b180..c808b85aa 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -55,7 +55,7 @@ public: // Resolution scaling. u32 GetResolutionScale() const { return m_resolution_scale; } u32 GetMaxResolutionScale() const { return m_max_resolution_scale; } - virtual void UpdateResolutionScale(); + virtual void UpdateSettings(); // Ticks for hblank/vblank. void Execute(TickCount ticks); diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 027791de5..01b0537bb 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1,6 +1,8 @@ #include "gpu_hw.h" #include "YBaseLib/Assert.h" #include "YBaseLib/Log.h" +#include "settings.h" +#include "system.h" #include Log_SetChannel(GPU_HW); @@ -15,6 +17,13 @@ void GPU_HW::Reset() m_batch = {}; } +void GPU_HW::UpdateSettings() +{ + GPU::UpdateSettings(); + + m_true_color = m_system->GetSettings().gpu_true_color; +} + void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices, const u32* command_ptr) { const u32 texpage = @@ -259,6 +268,7 @@ std::string GPU_HW::GenerateFragmentShader(HWBatchRenderMode transparency, Textu DefineMacro(ss, "PALETTE_8_BIT", actual_texture_mode == GPU::TextureMode::Palette8Bit); DefineMacro(ss, "RAW_TEXTURE", raw_texture); DefineMacro(ss, "DITHERING", dithering); + DefineMacro(ss, "TRUE_COLOR", m_true_color); ss << "const int[16] s_dither_values = int[16]( "; for (u32 i = 0; i < 16; i++) @@ -384,7 +394,9 @@ void main() #endif // Clip to 15-bit range - icolor = TruncateTo15Bit(icolor); + #if !TRUE_COLOR + icolor = TruncateTo15Bit(icolor); + #endif // Normalize vec3 color = vec3(icolor) / vec3(255.0, 255.0, 255.0); @@ -585,7 +597,7 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices, const u32 const TransparencyMode transparency_mode = rc.transparency_enable ? m_render_state.transparency_mode : TransparencyMode::Disabled; const HWPrimitive rc_primitive = GetPrimitiveForCommand(rc); - const bool dithering_enable = rc.IsDitheringEnabled() ? m_GPUSTAT.dither_enable : false; + const bool dithering_enable = (!m_true_color && rc.IsDitheringEnabled()) ? m_GPUSTAT.dither_enable : false; if (!IsFlushed()) { const u32 max_added_vertices = num_vertices + 2; diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index 4c9ad2b48..1aafb37ba 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -12,6 +12,7 @@ public: virtual ~GPU_HW(); virtual void Reset() override; + virtual void UpdateSettings() override; protected: enum class HWPrimitive : u8 @@ -107,6 +108,7 @@ protected: std::string GenerateDisplayFragmentShader(bool depth_24bit, bool interlaced); HWRenderBatch m_batch = {}; + bool m_true_color = false; private: static HWPrimitive GetPrimitiveForCommand(RenderCommand rc); diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index bf5b2f16c..8d046aa99 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -65,9 +65,9 @@ void GPU_HW_OpenGL::RestoreGraphicsAPIState() glBindVertexArray(m_vao_id); } -void GPU_HW_OpenGL::UpdateResolutionScale() +void GPU_HW_OpenGL::UpdateSettings() { - GPU_HW::UpdateResolutionScale(); + GPU_HW::UpdateSettings(); CreateFramebuffer(); CompilePrograms(); @@ -322,8 +322,8 @@ bool GPU_HW_OpenGL::CompileProgram(GL::Program& prog, HWBatchRenderMode render_m void GPU_HW_OpenGL::SetDrawState(HWBatchRenderMode render_mode) { - const GL::Program& prog = - m_render_programs[static_cast(render_mode)][static_cast(m_batch.texture_mode)][m_batch.dithering]; + const GL::Program& prog = m_render_programs[static_cast(render_mode)][static_cast(m_batch.texture_mode)] + [BoolToUInt8(m_batch.dithering)]; prog.Bind(); prog.Uniform2i(0, m_drawing_offset.x, m_drawing_offset.y); diff --git a/src/core/gpu_hw_opengl.h b/src/core/gpu_hw_opengl.h index c91c2713a..59ecbb173 100644 --- a/src/core/gpu_hw_opengl.h +++ b/src/core/gpu_hw_opengl.h @@ -18,7 +18,7 @@ public: void ResetGraphicsAPIState() override; void RestoreGraphicsAPIState() override; - void UpdateResolutionScale() override; + void UpdateSettings() override; void DrawRendererStatsWindow() override; diff --git a/src/core/settings.h b/src/core/settings.h index c179fb9a2..879c36949 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -17,6 +17,7 @@ struct Settings u32 gpu_resolution_scale = 1; u32 max_gpu_resolution_scale = 1; bool gpu_vsync = true; + bool gpu_true_color = false; bool display_linear_filtering = true; struct DebugSettings diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index e4927fc10..aaa8fa121 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -862,7 +862,7 @@ void SDLInterface::DrawMainMenuBar() nullptr, current_internal_resolution == scale)) { m_system->GetSettings().gpu_resolution_scale = scale; - m_system->GetGPU()->UpdateResolutionScale(); + m_system->GetGPU()->UpdateSettings(); } } @@ -872,10 +872,13 @@ void SDLInterface::DrawMainMenuBar() if (ImGui::MenuItem("VSync", nullptr, &m_system->GetSettings().gpu_vsync)) UpdateAudioVisualSync(); + if (ImGui::MenuItem("True (24-Bit) Color", nullptr, &m_system->GetSettings().gpu_true_color)) + m_system->GetGPU()->UpdateSettings(); + if (ImGui::MenuItem("Display Linear Filtering", nullptr, &m_system->GetSettings().display_linear_filtering)) { // this has to update the display texture for now.. - m_system->GetGPU()->UpdateResolutionScale(); + m_system->GetGPU()->UpdateSettings(); } ImGui::EndMenu(); @@ -1300,7 +1303,7 @@ void SDLInterface::DoModifyInternalResolution(s32 increment) return; settings.gpu_resolution_scale = new_resolution_scale; - m_system->GetGPU()->UpdateResolutionScale(); + m_system->GetGPU()->UpdateSettings(); AddOSDMessage(TinyString::FromFormat("Resolution scale set to %ux (%ux%u)", settings.gpu_resolution_scale, GPU::VRAM_WIDTH * settings.gpu_resolution_scale,