diff --git a/src/Cafe/HW/Latte/Core/Latte.h b/src/Cafe/HW/Latte/Core/Latte.h index 2636467b55..3495d1b9e5 100644 --- a/src/Cafe/HW/Latte/Core/Latte.h +++ b/src/Cafe/HW/Latte/Core/Latte.h @@ -54,6 +54,8 @@ struct LatteGPUState_t // temporary (replace with proper solution later) bool tvBufferUsesSRGB; bool drcBufferUsesSRGB; + float tvGamma = 0.0f; + float drcGamma = 0.0f; // draw state bool activeShaderHasError; // if try, at least one currently bound shader stage has an error and cannot be used for drawing bool repeatTextureInitialization; // if set during rendertarget or texture initialization, repeat the process (textures likely have been invalidated) diff --git a/src/Cafe/HW/Latte/Core/LatteTextureLoader.cpp b/src/Cafe/HW/Latte/Core/LatteTextureLoader.cpp index c06a3bf189..e6bfbb856c 100644 --- a/src/Cafe/HW/Latte/Core/LatteTextureLoader.cpp +++ b/src/Cafe/HW/Latte/Core/LatteTextureLoader.cpp @@ -120,16 +120,6 @@ uint8* LatteTextureLoader_getInputLinearOptimized(LatteTextureLoaderCtx* texture #define LatteTextureLoader_getInputLinearOptimized_(__textureLoader,__x,__y,__stepX,__stepY,__bpp,__sliceIndex,__numSlices,__sample,__pitch,__height) (textureLoader->inputData+((__x/__stepX) + __pitch * (__y/__stepY) + (__sliceIndex + __numSlices * __sample) * __height * __pitch)*(__bpp/8)) -float SRGB_to_RGB(float cs) -{ - float cl; - if (cs <= 0.04045f) - cl = cs / 12.92f; - else - cl = powf(((cs + 0.055f) / 1.055f), 2.4f); - return cl; -} - void decodeBC1Block(uint8* inputData, float* output4x4RGBA) { // read colors diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 63c344ca41..76f6769288 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -603,7 +603,7 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu shader_unbind(RendererShader::ShaderType::kGeometry); shader_bind(shader->GetVertexShader()); shader_bind(shader->GetFragmentShader()); - shader->SetUniformParameters(*texView, {imageWidth, imageHeight}); + shader->SetUniformParameters(*texView, {imageWidth, imageHeight}, padView); // set viewport glViewportIndexedf(0, imageX, imageY, imageWidth, imageHeight); @@ -620,14 +620,12 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, useLinearTexFilter ? GL_LINEAR : GL_NEAREST); texViewGL->samplerState.filterMag = 0xFFFFFFFF; - if ((!padView && !LatteGPUState.tvBufferUsesSRGB) || (padView && !LatteGPUState.drcBufferUsesSRGB)) - glDisable(GL_FRAMEBUFFER_SRGB); + glDisable(GL_FRAMEBUFFER_SRGB); uint16 indexData[6] = { 0,1,2,3,4,5 }; glDrawRangeElements(GL_TRIANGLES, 0, 5, 6, GL_UNSIGNED_SHORT, indexData); - if ((!padView && !LatteGPUState.tvBufferUsesSRGB) || (padView && !LatteGPUState.drcBufferUsesSRGB)) - glEnable(GL_FRAMEBUFFER_SRGB); + glEnable(GL_FRAMEBUFFER_SRGB); // unbind texture texture_bindAndActivate(nullptr, 0); diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp index cae5314029..4d7fe2b9ac 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.cpp @@ -227,6 +227,16 @@ sint32 RendererShaderGL::GetUniformLocation(const char* name) return glGetUniformLocation(m_program, name); } +void RendererShaderGL::SetUniform1i(sint32 location, sint32 value) +{ + glProgramUniform1i(m_program, location, value); +} + +void RendererShaderGL::SetUniform1f(sint32 location, float value) +{ + glProgramUniform1f(m_program, location, value); +} + void RendererShaderGL::SetUniform2fv(sint32 location, void* data, sint32 count) { glProgramUniform2fv(m_program, location, count, (const GLfloat*)data); diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h index 60c51cc13d..db69c14f8e 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/RendererShaderGL.h @@ -18,6 +18,9 @@ class RendererShaderGL : public RendererShader GLuint GetShaderObject() const { cemu_assert_debug(m_isCompiled); return m_shader_object; } sint32 GetUniformLocation(const char* name) override; + + void SetUniform1i(sint32 location, sint32 value) override; + void SetUniform1f(sint32 location, float value) override; void SetUniform2fv(sint32 location, void* data, sint32 count) override; void SetUniform4iv(sint32 location, void* data, sint32 count) override; diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index afe53a16cb..c4274164e6 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -1,9 +1,10 @@ #include "Cafe/HW/Latte/Renderer/RendererOuputShader.h" #include "Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h" +#include "config/ActiveSettings.h" const std::string RendererOutputShader::s_copy_shader_source = R"( -void main() +void outputShader() { colorOut0 = vec4(texture(textureSrc, passUV).rgb,1.0); } @@ -49,7 +50,7 @@ vec4 bcFilter(vec2 uv, vec4 texelSize) mix(sample1, sample0, sx), sy); } -void main(){ +void outputShader(){ vec4 texelSize = vec4( 1.0 / textureSrcResolution.xy, textureSrcResolution.xy); colorOut0 = vec4(bcFilter(passUV, texelSize).rgb,1.0); } @@ -108,7 +109,7 @@ vec3 BicubicHermiteTexture(vec2 uv, vec4 texelSize) return CubicHermite(CP0X, CP1X, CP2X, CP3X, frac.y); } -void main(){ +void outputShader(){ vec4 texelSize = vec4( 1.0 / textureSrcResolution.xy, textureSrcResolution.xy); colorOut0 = vec4(BicubicHermiteTexture(passUV, texelSize), 1.0); } @@ -135,14 +136,20 @@ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, con m_uniformLocations[0].m_loc_textureSrcResolution = m_vertex_shader->GetUniformLocation("textureSrcResolution"); m_uniformLocations[0].m_loc_nativeResolution = m_vertex_shader->GetUniformLocation("nativeResolution"); m_uniformLocations[0].m_loc_outputResolution = m_vertex_shader->GetUniformLocation("outputResolution"); + m_uniformLocations[0].m_loc_applySRGBEncoding = m_vertex_shader->GetUniformLocation("applySRGBEncoding"); + m_uniformLocations[0].m_loc_targetGamma = m_fragment_shader->GetUniformLocation("targetGamma"); + m_uniformLocations[0].m_loc_displayGamma = m_fragment_shader->GetUniformLocation("displayGamma"); m_uniformLocations[1].m_loc_textureSrcResolution = m_fragment_shader->GetUniformLocation("textureSrcResolution"); m_uniformLocations[1].m_loc_nativeResolution = m_fragment_shader->GetUniformLocation("nativeResolution"); m_uniformLocations[1].m_loc_outputResolution = m_fragment_shader->GetUniformLocation("outputResolution"); + m_uniformLocations[1].m_loc_applySRGBEncoding = m_fragment_shader->GetUniformLocation("applySRGBEncoding"); + m_uniformLocations[1].m_loc_targetGamma = m_fragment_shader->GetUniformLocation("targetGamma"); + m_uniformLocations[1].m_loc_displayGamma = m_fragment_shader->GetUniformLocation("displayGamma"); } } -void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res) const +void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res, const bool padView) const { sint32 effectiveWidth, effectiveHeight; texture_view.baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); @@ -168,6 +175,22 @@ void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_ res[1] = (float)output_res.y; shader->SetUniform2fv(locations.m_loc_outputResolution, res, 1); } + + if (locations.m_loc_applySRGBEncoding != -1) + { + shader->SetUniform1i(locations.m_loc_applySRGBEncoding, padView ? LatteGPUState.drcBufferUsesSRGB : LatteGPUState.tvBufferUsesSRGB); + } + + if (locations.m_loc_targetGamma != -1) + { + shader->SetUniform1f(locations.m_loc_targetGamma, padView ? ActiveSettings::GetDRCGamma() : ActiveSettings::GetTVGamma()); + } + + if (locations.m_loc_displayGamma != -1) + { + shader->SetUniform1f(locations.m_loc_displayGamma, GetConfig().userDisplayGamma); + } + }; setUniforms(m_vertex_shader.get(), m_uniformLocations[0]); setUniforms(m_fragment_shader.get(), m_uniformLocations[1]); @@ -290,16 +313,52 @@ layout(push_constant) uniform pc { vec2 textureSrcResolution; vec2 nativeResolution; vec2 outputResolution; + bool applySRGBEncoding; // true = app requested sRGB encoding + float targetGamma; + float displayGamma; }; #else uniform vec2 textureSrcResolution; uniform vec2 nativeResolution; uniform vec2 outputResolution; +uniform bool applySRGBEncoding; +uniform float targetGamma; +uniform float displayGamma; #endif layout(location = 0) smooth in vec2 passUV; layout(binding = 0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; + +float sRGBEncode(float linear) +{ + if(linear <= 0.0031308) + return 12.92f * linear; + else + return 1.055f * pow(linear, 1.0f / 2.4f) - 0.055f; + +} + +vec3 sRGBEncode(vec3 linear) +{ + return vec3(sRGBEncode(linear.r), sRGBEncode(linear.g), sRGBEncode(linear.b)); +} + +// fwd. declaration +void outputShader(); +void main() +{ + outputShader(); // sets colorOut0 + if(applySRGBEncoding) + colorOut0 = vec4(sRGBEncode(colorOut0.rgb), 1.0f); + + if (displayGamma > 0.0f) + colorOut0 = pow(colorOut0, vec4(targetGamma / displayGamma) ); + else + colorOut0 = vec4( sRGBEncode( pow(colorOut0.rgb, vec3(targetGamma)) ), 1.0f); + +} + )" + shaderSrc; } void RendererOutputShader::InitializeStatic() diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h index b12edf8b4a..44373791b0 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h @@ -17,7 +17,7 @@ class RendererOutputShader RendererOutputShader(const std::string& vertex_source, const std::string& fragment_source); virtual ~RendererOutputShader() = default; - void SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res) const; + void SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res, const bool padView) const; RendererShader* GetVertexShader() const { @@ -55,6 +55,9 @@ class RendererOutputShader sint32 m_loc_textureSrcResolution = -1; sint32 m_loc_nativeResolution = -1; sint32 m_loc_outputResolution = -1; + sint32 m_loc_applySRGBEncoding = -1; + sint32 m_loc_targetGamma = -1; + sint32 m_loc_displayGamma = -1; } m_uniformLocations[2]{}; private: diff --git a/src/Cafe/HW/Latte/Renderer/RendererShader.h b/src/Cafe/HW/Latte/Renderer/RendererShader.h index e3f254c600..b3d6d62b16 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererShader.h @@ -20,6 +20,8 @@ class RendererShader virtual sint32 GetUniformLocation(const char* name) = 0; + virtual void SetUniform1i(sint32 location, sint32 value) = 0; + virtual void SetUniform1f(sint32 location, float value) = 0; virtual void SetUniform2fv(sint32 location, void* data, sint32 count) = 0; virtual void SetUniform4iv(sint32 location, void* data, sint32 count) = 0; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp index 665a5da3bb..403db5bf41 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp @@ -232,6 +232,16 @@ sint32 RendererShaderVk::GetUniformLocation(const char* name) return 0; } +void RendererShaderVk::SetUniform1i(sint32 location, sint32 value) +{ + cemu_assert_suspicious(); +} + +void RendererShaderVk::SetUniform1f(sint32 location, float value) +{ + cemu_assert_suspicious(); +} + void RendererShaderVk::SetUniform2fv(sint32 location, void* data, sint32 count) { cemu_assert_suspicious(); diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h index f9c3ede140..7b9fc34b86 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.h @@ -32,6 +32,8 @@ class RendererShaderVk : public RendererShader static void Shutdown(); sint32 GetUniformLocation(const char* name) override; + void SetUniform1i(sint32 location, sint32 value) override; + void SetUniform1f(sint32 location, float value) override; void SetUniform2fv(sint32 location, void* data, sint32 count) override; void SetUniform4iv(sint32 location, void* data, sint32 count) override; VkShaderModule& GetShaderModule() { return m_shader_module; } diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp index 79bdffd1bf..b27aae0e2e 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp @@ -319,18 +319,8 @@ VkSurfaceFormatKHR SwapchainInfoVk::ChooseSurfaceFormat(const std::vectorbaseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); - pushData[0] = {(float)effectiveWidth, (float)effectiveHeight}; + pushData.vecs[0] = {(float)effectiveWidth, (float)effectiveHeight}; // nativeResolution - pushData[1] = { + pushData.vecs[1] = { (float)texViewVk->baseTexture->width, (float)texViewVk->baseTexture->height, }; // outputResolution - pushData[2] = {(float)imageWidth,(float)imageHeight}; + pushData.vecs[2] = {(float)imageWidth,(float)imageHeight}; + + pushData.applySRGBEncoding = padView ? LatteGPUState.drcBufferUsesSRGB : LatteGPUState.tvBufferUsesSRGB; + pushData.targetGamma = padView ? ActiveSettings::GetDRCGamma() : ActiveSettings::GetTVGamma(); + pushData.displayGamma = GetConfig().userDisplayGamma; - vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(float) * 2 * 3, &pushData); + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(pushData), &pushData); vkCmdDraw(m_state.currentCommandBuffer, 6, 1, 0, 0); diff --git a/src/Cafe/OS/libs/gx2/GX2_Misc.cpp b/src/Cafe/OS/libs/gx2/GX2_Misc.cpp index e7830cd8e7..564b787ed8 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Misc.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Misc.cpp @@ -206,8 +206,12 @@ namespace GX2 void GX2SetTVGamma(float gamma) { - if (abs(gamma - 1.0f) > 0.01f) - cemuLog_logDebug(LogType::Force, "TV gamma set to {} which is not supported", gamma); + LatteGPUState.tvGamma = (1.0f - gamma); + } + + void GX2SetDRCGamma(float gamma) + { + LatteGPUState.drcGamma = (1.0f - gamma); } bool GX2GetLastFrame(uint32 deviceId, GX2Texture* textureOut) @@ -307,6 +311,7 @@ namespace GX2 cafeExportRegister("gx2", GX2SetTVBuffer, LogType::GX2); cafeExportRegister("gx2", GX2SetTVGamma, LogType::GX2); + cafeExportRegister("gx2", GX2SetDRCGamma, LogType::GX2); cafeExportRegister("gx2", GX2GetLastFrame, LogType::GX2); cafeExportRegister("gx2", GX2GetLastFrameGammaA, LogType::GX2); diff --git a/src/Common/GLInclude/glFunctions.h b/src/Common/GLInclude/glFunctions.h index 412816af5e..9c93637b0b 100644 --- a/src/Common/GLInclude/glFunctions.h +++ b/src/Common/GLInclude/glFunctions.h @@ -116,6 +116,7 @@ GLFUNC(PFNGLPROGRAMUNIFORM1IPROC, glProgramUniform1i) GLFUNC(PFNGLPROGRAMUNIFORM2IPROC, glProgramUniform2i) GLFUNC(PFNGLPROGRAMUNIFORM1IVPROC, glProgramUniform1iv) GLFUNC(PFNGLPROGRAMUNIFORM4IVPROC, glProgramUniform4iv) +GLFUNC(PFNGLPROGRAMUNIFORM1IPROC, glProgramUniform1f) GLFUNC(PFNGLPROGRAMUNIFORM1FVPROC, glProgramUniform1fv) GLFUNC(PFNGLPROGRAMUNIFORM2FVPROC, glProgramUniform2fv) diff --git a/src/config/ActiveSettings.cpp b/src/config/ActiveSettings.cpp index 58a83a154b..3ecd885513 100644 --- a/src/config/ActiveSettings.cpp +++ b/src/config/ActiveSettings.cpp @@ -6,6 +6,7 @@ #include "config/ActiveSettings.h" #include "config/LaunchSettings.h" #include "util/helpers/helpers.h" +#include "Cafe/HW/Latte/Core/Latte.h" void ActiveSettings::SetPaths(bool isPortableMode, const fs::path& executablePath, @@ -112,6 +113,18 @@ GraphicAPI ActiveSettings::GetGraphicsAPI() return api; } +float ActiveSettings::GetTVGamma() +{ + const auto& config = GetConfig(); + return config.overrideGammaValue.GetValue() + LatteGPUState.tvGamma * !config.overrideAppGammaPreference.GetValue(); +} + +float ActiveSettings::GetDRCGamma() +{ + const auto& config = GetConfig(); + return config.overrideGammaValue.GetValue() + LatteGPUState.drcGamma * !config.overrideAppGammaPreference.GetValue(); +} + bool ActiveSettings::AudioOutputOnlyAux() { return s_audio_aux_only; diff --git a/src/config/ActiveSettings.h b/src/config/ActiveSettings.h index c01170e265..20838f4a6b 100644 --- a/src/config/ActiveSettings.h +++ b/src/config/ActiveSettings.h @@ -96,6 +96,11 @@ class ActiveSettings [[nodiscard]] static bool WaitForGX2DrawDoneEnabled(); [[nodiscard]] static GraphicAPI GetGraphicsAPI(); + // gamma + [[nodiscard]] static float GetTVGamma(); + [[nodiscard]] static float GetDRCGamma(); + [[nodiscard]] static float GetPCDisplayGamma(); + // audio [[nodiscard]] static bool AudioOutputOnlyAux(); static void EnableAudioOnlyAux(bool state); diff --git a/src/config/CemuConfig.cpp b/src/config/CemuConfig.cpp index 620f005e8c..d01f554dda 100644 --- a/src/config/CemuConfig.cpp +++ b/src/config/CemuConfig.cpp @@ -129,6 +129,13 @@ XMLConfigParser CemuConfig::Load(XMLConfigParser& parser) graphic_api = graphic.get("api", kOpenGL); graphic.get("device", graphic_device_uuid); vsync = graphic.get("VSync", 0); + overrideAppGammaPreference = graphic.get("OverrideAppGammaPreference", false); + overrideGammaValue = graphic.get("OverrideGammaValue", 2.2f); + if(overrideGammaValue < 0) + overrideGammaValue = 2.2f; + userDisplayGamma = graphic.get("UserDisplayGamma", 2.2f); + if(userDisplayGamma < 0) + userDisplayGamma = 2.2f; gx2drawdone_sync = graphic.get("GX2DrawdoneSync", true); upscale_filter = graphic.get("UpscaleFilter", kBicubicHermiteFilter); downscale_filter = graphic.get("DownscaleFilter", kLinearFilter); @@ -346,6 +353,9 @@ XMLConfigParser CemuConfig::Save(XMLConfigParser& parser) graphic.set("api", graphic_api); graphic.set("device", graphic_device_uuid); graphic.set("VSync", vsync); + graphic.set("OverrideAppGammaPreference", overrideAppGammaPreference); + graphic.set("OverrideGammaValue", overrideGammaValue); + graphic.set("UserDisplayGamma", userDisplayGamma); graphic.set("GX2DrawdoneSync", gx2drawdone_sync); //graphic.set("PrecompiledShaders", precompiled_shaders.GetValue()); graphic.set("UpscaleFilter", upscale_filter); diff --git a/src/config/CemuConfig.h b/src/config/CemuConfig.h index ff892fb801..904b81cb9d 100644 --- a/src/config/CemuConfig.h +++ b/src/config/CemuConfig.h @@ -389,6 +389,11 @@ struct CemuConfig ConfigValue render_upside_down{ false }; ConfigValue async_compile{ true }; + // Gamma + ConfigValue overrideAppGammaPreference{ false }; + ConfigValue overrideGammaValue{ 2.2f }; + ConfigValue userDisplayGamma { 2.2f }; // 0 = sRGB, >0 gamma + ConfigValue vk_accurate_barriers{ true }; struct diff --git a/src/gui/wxgui/GeneralSettings2.cpp b/src/gui/wxgui/GeneralSettings2.cpp index f937549d41..ce06ffa638 100644 --- a/src/gui/wxgui/GeneralSettings2.cpp +++ b/src/gui/wxgui/GeneralSettings2.cpp @@ -361,6 +361,28 @@ wxPanel* GeneralSettings2::AddGraphicsPage(wxNotebook* notebook) m_vsync->SetToolTip(_("Controls the vsync state")); row->Add(m_vsync, 0, wxALL, 5); + row->Add(new wxStaticText(box, wxID_ANY, _("Override gamma")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + m_overrideGamma = new wxCheckBox(box, wxID_ANY, "", wxDefaultPosition, {230, -1}); + m_overrideGamma->SetToolTip(_("Ignore app gamma preference")); + row->Add(m_overrideGamma, 0, wxALL, 5); + + row->Add(new wxStaticText(box, wxID_ANY, _("Gamma")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + m_overrideGammaValue = new wxSpinCtrlDouble(box, wxID_ANY, "2.2f", wxDefaultPosition, {230, -1}, wxSP_ARROW_KEYS, 0.1f, 4.0f, 2.2f, 0.1f); + row->Add(m_overrideGammaValue, 0, wxALL, 5); + + + row->Add(new wxStaticText(box, wxID_ANY, _("Display Gamma")), 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + + wxBoxSizer* test = new wxBoxSizer(wxHORIZONTAL); + row->Add(test); + m_userDisplayGamma = new wxSpinCtrlDouble(box, wxID_ANY, "2.2f", wxDefaultPosition, {230, -1}, wxSP_ARROW_KEYS, 0.1f, 4.0f, 2.2f, 0.1f); + m_userDisplayisSRGB = new wxCheckBox(box, wxID_ANY, "sRGB", wxDefaultPosition, wxDefaultSize); + m_userDisplayisSRGB->SetToolTip(_("Select this if your screen is standard compliant sRGB.\nMore accurate but may result in banding and/or crushed shadows.")); + m_userDisplayisSRGB->Bind(wxEVT_CHECKBOX, &GeneralSettings2::OnUserDisplaySRGBSelected, this); + + test->Add(m_userDisplayGamma, 0, wxALL, 5); + test->Add(m_userDisplayisSRGB, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + box_sizer->Add(row, 0, wxEXPAND, 5); auto* graphic_misc_row = new wxFlexGridSizer(0, 2, 0, 0); @@ -1104,6 +1126,9 @@ void GeneralSettings2::StoreConfig() config.vsync = m_vsync->GetSelection(); + config.overrideAppGammaPreference = m_overrideGamma->IsChecked(); + config.overrideGammaValue = m_overrideGammaValue->GetValue(); + config.userDisplayGamma = m_userDisplayGamma->GetValue() * !m_userDisplayisSRGB->GetValue(); config.gx2drawdone_sync = m_gx2drawdone_sync->IsChecked(); config.async_compile = m_async_compile->IsChecked(); @@ -1685,6 +1710,15 @@ void GeneralSettings2::ApplyConfig() // graphics m_graphic_api->SetSelection(config.graphic_api); m_vsync->SetSelection(config.vsync); + m_overrideGamma->SetValue(config.overrideAppGammaPreference); + m_overrideGammaValue->SetValue(config.overrideGammaValue); + m_userDisplayisSRGB->SetValue(config.userDisplayGamma == 0.0f); + m_userDisplayGamma->SetValue(config.userDisplayGamma); + if(m_userDisplayisSRGB->GetValue()) + { + m_userDisplayGamma->Disable(); + m_userDisplayGamma->SetValue(2.2f); + } m_async_compile->SetValue(config.async_compile); m_gx2drawdone_sync->SetValue(config.gx2drawdone_sync); m_upscale_filter->SetSelection(config.upscale_filter); @@ -2040,6 +2074,15 @@ void GeneralSettings2::OnGraphicAPISelected(wxCommandEvent& event) HandleGraphicsApiSelection(); } +void GeneralSettings2::OnUserDisplaySRGBSelected(wxCommandEvent& event) +{ + m_userDisplayGamma->SetValue(2.2f); + if(event.GetInt()) + m_userDisplayGamma->Disable(); + else + m_userDisplayGamma->Enable(); +} + void GeneralSettings2::OnAddPathClicked(wxCommandEvent& event) { wxDirDialog path_dialog(this, _("Select a directory containing games."), wxEmptyString, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); diff --git a/src/gui/wxgui/GeneralSettings2.h b/src/gui/wxgui/GeneralSettings2.h index fb0cfe872d..fd0a0dc5db 100644 --- a/src/gui/wxgui/GeneralSettings2.h +++ b/src/gui/wxgui/GeneralSettings2.h @@ -56,6 +56,11 @@ class GeneralSettings2 : public wxDialog // Graphics wxChoice* m_graphic_api, * m_graphic_device; wxChoice* m_vsync; + wxCheckBox* m_overrideGamma; + wxSpinCtrlDouble* m_overrideGammaValue; + wxSpinCtrlDouble* m_userDisplayGamma; + wxCheckBox* m_userDisplayisSRGB; + wxCheckBox *m_async_compile, *m_gx2drawdone_sync; wxRadioBox* m_upscale_filter, *m_downscale_filter, *m_fullscreen_scaling; wxChoice* m_overlay_position, *m_notification_position, *m_overlay_scale, *m_notification_scale; @@ -95,6 +100,7 @@ class GeneralSettings2 : public wxDialog void OnAudioDeviceSelected(wxCommandEvent& event); void OnAudioChannelsSelected(wxCommandEvent& event); void OnGraphicAPISelected(wxCommandEvent& event); + void OnUserDisplaySRGBSelected(wxCommandEvent& event); void OnAddPathClicked(wxCommandEvent& event); void OnRemovePathClicked(wxCommandEvent& event); void OnActiveAccountChanged(wxCommandEvent& event); @@ -115,6 +121,7 @@ class GeneralSettings2 : public wxDialog void UpdateAccountInformation(); void UpdateOnlineAccounts(); void HandleGraphicsApiSelection(); + void HandleGammaSettings(); void ApplyConfig(); };