From eaaf1ad7799a7450a66f9faf34886bf79a899de6 Mon Sep 17 00:00:00 2001 From: OV2 Date: Sat, 11 Mar 2023 21:49:10 +0100 Subject: [PATCH] win32: make shader params part of IS9xDisplayOutput, add override specifier --- win32/CDirect3D.h | 16 ++++++++-------- win32/CDirectDraw.h | 16 ++++++++-------- win32/COpenGL.cpp | 7 +++++-- win32/COpenGL.h | 20 ++++++++++---------- win32/CShaderParamDlg.cpp | 8 ++++---- win32/CShaderParamDlg.h | 8 ++++---- win32/CVulkan.cpp | 5 +++-- win32/CVulkan.h | 20 ++++++++++---------- win32/IS9xDisplayOutput.h | 3 +++ win32/win32_display.cpp | 15 +++------------ win32/win32_display.h | 3 +-- win32/wsnes9x.h | 11 +++++++++++ 12 files changed, 70 insertions(+), 62 deletions(-) diff --git a/win32/CDirect3D.h b/win32/CDirect3D.h index c8f65c31..902943b6 100644 --- a/win32/CDirect3D.h +++ b/win32/CDirect3D.h @@ -81,14 +81,14 @@ private: public: CDirect3D(); ~CDirect3D(); - bool Initialize(HWND hWnd); - void DeInitialize(); - void Render(SSurface Src); - bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight); - bool ApplyDisplayChanges(void); - bool SetFullscreen(bool fullscreen); - void SetSnes9xColorFormat(); - void EnumModes(std::vector *modeVector); + bool Initialize(HWND hWnd) override; + void DeInitialize() override; + void Render(SSurface Src) override; + bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) override; + bool ApplyDisplayChanges(void) override; + bool SetFullscreen(bool fullscreen) override; + void SetSnes9xColorFormat() override; + void EnumModes(std::vector *modeVector) override; }; #endif diff --git a/win32/CDirectDraw.h b/win32/CDirectDraw.h index ffe7070c..4f40aec4 100644 --- a/win32/CDirectDraw.h +++ b/win32/CDirectDraw.h @@ -48,16 +48,16 @@ public: char pDepth, int pRefreshRate, bool pWindowed, bool pDoubleBuffered); void GetPixelFormat (); - void DeInitialize(); - bool Initialize (HWND hWnd); + void DeInitialize() override; + bool Initialize (HWND hWnd) override; - void Render(SSurface Src); - bool ApplyDisplayChanges(void); - bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight); - bool SetFullscreen(bool fullscreen); - void SetSnes9xColorFormat(); + void Render(SSurface Src) override; + bool ApplyDisplayChanges(void) override; + bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) override; + bool SetFullscreen(bool fullscreen) override; + void SetSnes9xColorFormat() override; - void EnumModes(std::vector *modeVector); + void EnumModes(std::vector *modeVector) override; CDirectDraw(); virtual ~CDirectDraw(); diff --git a/win32/COpenGL.cpp b/win32/COpenGL.cpp index 4eb1a3ca..b5dd7740 100644 --- a/win32/COpenGL.cpp +++ b/win32/COpenGL.cpp @@ -397,10 +397,13 @@ void COpenGL::SetSwapInterval(int frames) wglSwapIntervalEXT(frames); } -std::vector* COpenGL::GetShaderParameters(void) +std::vector* COpenGL::GetShaderParameters(void) { if (shader_type == OGL_SHADER_GLSL && initDone) - return &glslShader->param; + { + // GLSLParam currently equal ShaderParam, so no conversion is neccessary + return (std::vector*)&glslShader->param; + } return nullptr; } diff --git a/win32/COpenGL.h b/win32/COpenGL.h index 5c510fea..aa4e5ac1 100644 --- a/win32/COpenGL.h +++ b/win32/COpenGL.h @@ -76,17 +76,17 @@ private: public: COpenGL(); ~COpenGL(); - bool Initialize(HWND hWnd); - void DeInitialize(); - void Render(SSurface Src); - bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight); - bool ApplyDisplayChanges(void); - bool SetFullscreen(bool fullscreen); - void SetSnes9xColorFormat(void); - void EnumModes(std::vector *modeVector); + bool Initialize(HWND hWnd) override; + void DeInitialize() override; + void Render(SSurface Src) override; + bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) override; + bool ApplyDisplayChanges(void) override; + bool SetFullscreen(bool fullscreen) override; + void SetSnes9xColorFormat(void) override; + void EnumModes(std::vector *modeVector) override; void SetSwapInterval(int frames); - std::vector *GetShaderParameters(void); - std::function GetShaderParametersSaveFunction(); + std::vector *GetShaderParameters(void) override; + std::function GetShaderParametersSaveFunction() override; }; diff --git a/win32/CShaderParamDlg.cpp b/win32/CShaderParamDlg.cpp index 7ac8a3a0..4f00bb15 100644 --- a/win32/CShaderParamDlg.cpp +++ b/win32/CShaderParamDlg.cpp @@ -143,7 +143,7 @@ void CShaderParamDlg::trackbar_changed(HWND trackbar) SetWindowText(p.entry, val); } -CShaderParamDlg::CShaderParamDlg(std::vector& parameters_, std::function save_function_) +CShaderParamDlg::CShaderParamDlg(std::vector& parameters_, std::function save_function_) : parameters(parameters_), save_function(save_function_) { @@ -288,7 +288,7 @@ void CShaderParamDlg::createContent(HWND hDlg) parameter_widgets.clear(); for(int i = 0; i < parameters.size(); i++) { ParameterWidgetSet widgets{}; - GLSLParam &p = parameters[i]; + ShaderParam &p = parameters[i]; TCHAR desc[270]; _stprintf(desc, TEXT("%s [%g-%g]"), (TCHAR*)_tFromChar(p.name.c_str()), p.min, p.max); HWND item = CreateWindow(TEXT("STATIC"), desc, SS_LEFTNOWORDWRAP | WS_VISIBLE | WS_CHILD, MARGIN, (INT)(top + avgCharHeight * 0.3), desc_width, avgCharHeight, parent, (HMENU)(UINT_PTR)(IDC_PARAMS_START_STATIC + i), GUI.hInstance, NULL); @@ -351,7 +351,7 @@ void CShaderParamDlg::handle_up_down(HWND hStatic, int id, int change) { int param_id = id - IDC_PARAMS_START_UPDOWN; HWND hEdit = GetDlgItem(hStatic, IDC_PARAMS_START_EDIT + param_id); - GLSLParam &p = parameters[param_id]; + ShaderParam &p = parameters[param_id]; TCHAR val[100]; GetWindowText(hEdit, val, 100); p.val = _ttof(val); @@ -371,7 +371,7 @@ void CShaderParamDlg::get_changed_parameters(HWND hDlg) { HWND parent = GetDlgItem(hDlg, IDC_STATIC_CONTAINER); for(int i = 0; i < parameters.size(); i++) { - GLSLParam &p = parameters[i]; + ShaderParam &p = parameters[i]; TCHAR val[100]; HWND hEdit = GetDlgItem(parent, IDC_PARAMS_START_EDIT + i); GetWindowText(hEdit, val, 100); diff --git a/win32/CShaderParamDlg.h b/win32/CShaderParamDlg.h index 8bdfbfae..59f9f725 100644 --- a/win32/CShaderParamDlg.h +++ b/win32/CShaderParamDlg.h @@ -6,7 +6,7 @@ #pragma once #include "windows.h" -#include "../shaders/glsl.h" +#include "wsnes9x.h" #include typedef void(*APPLYCALLBACK) (); @@ -29,8 +29,8 @@ private: unsigned int avgCharHeight; unsigned int maxDescriptionWidth; int scrollpos; - std::vector& parameters; - std::vector saved_parameters; + std::vector& parameters; + std::vector saved_parameters; std::function save_function; struct ParameterWidgetSet @@ -45,7 +45,7 @@ private: WNDPROC oldStaticProc; public: - CShaderParamDlg(std::vector ¶meters, std::function save_function); + CShaderParamDlg(std::vector ¶meters, std::function save_function); virtual ~CShaderParamDlg(); bool show(); diff --git a/win32/CVulkan.cpp b/win32/CVulkan.cpp index 7b4097e2..8a3badb3 100644 --- a/win32/CVulkan.cpp +++ b/win32/CVulkan.cpp @@ -205,11 +205,12 @@ void CVulkan::EnumModes(std::vector* modeVector) } } -std::vector *CVulkan::GetShaderParameters() +std::vector *CVulkan::GetShaderParameters() { if (shaderchain) { - return &shaderchain->preset->parameters; + // SlangShader::Parameter currently equal ShaderParam, so no conversion is neccessary + return (std::vector*)&shaderchain->preset->parameters; } else return nullptr; diff --git a/win32/CVulkan.h b/win32/CVulkan.h index 0cd50159..d5875bb7 100644 --- a/win32/CVulkan.h +++ b/win32/CVulkan.h @@ -20,15 +20,15 @@ class CVulkan : public IS9xDisplayOutput int current_height; public: - bool Initialize(HWND hWnd); - void DeInitialize(); - void Render(SSurface Src); - bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight); - bool ApplyDisplayChanges(void); - bool SetFullscreen(bool fullscreen); - void SetSnes9xColorFormat(); - void EnumModes(std::vector* modeVector); - std::vector *GetShaderParameters(void); - std::function GetShaderParametersSaveFunction(); + bool Initialize(HWND hWnd) override; + void DeInitialize() override; + void Render(SSurface Src) override; + bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) override; + bool ApplyDisplayChanges(void) override; + bool SetFullscreen(bool fullscreen) override; + void SetSnes9xColorFormat() override; + void EnumModes(std::vector* modeVector) override; + std::vector *GetShaderParameters(void) override; + std::function GetShaderParametersSaveFunction() override; }; diff --git a/win32/IS9xDisplayOutput.h b/win32/IS9xDisplayOutput.h index c4c000b3..dc9c0e72 100644 --- a/win32/IS9xDisplayOutput.h +++ b/win32/IS9xDisplayOutput.h @@ -10,6 +10,7 @@ #include "render.h" #include "wsnes9x.h" #include +#include /* IS9xDisplayOutput Interface for display driver. @@ -27,6 +28,8 @@ public: virtual bool SetFullscreen(bool fullscreen)=0; virtual void SetSnes9xColorFormat()=0; virtual void EnumModes(std::vector *modeVector)=0; + virtual std::vector* GetShaderParameters(void) { return nullptr; } + virtual std::function GetShaderParametersSaveFunction() { return std::function(); } }; diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index 673bc6f5..4c7bafc3 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -711,23 +711,14 @@ void WinThrottleFramerate() PCStart += PCFrameTime; } -std::vector *WinGetShaderParameters() +std::vector *WinGetShaderParameters() { - if (GUI.outputMethod == OPENGL) - return OpenGL.GetShaderParameters(); - if (GUI.outputMethod == VULKAN) - return (std::vector *)VulkanDriver.GetShaderParameters(); - return nullptr; + return S9xDisplayOutput->GetShaderParameters(); } std::function WinGetShaderSaveFunction() { - if (GUI.outputMethod == OPENGL) - return OpenGL.GetShaderParametersSaveFunction(); - else if (GUI.outputMethod == VULKAN) - return VulkanDriver.GetShaderParametersSaveFunction(); - else - return std::function(); + return S9xDisplayOutput->GetShaderParametersSaveFunction(); } /* Depth conversion functions begin */ diff --git a/win32/win32_display.h b/win32/win32_display.h index aaf2c8b0..84fcd9fc 100644 --- a/win32/win32_display.h +++ b/win32/win32_display.h @@ -10,7 +10,6 @@ #include "wsnes9x.h" #include "port.h" #include "render.h" -#include "../shaders/glsl.h" #include #include @@ -43,7 +42,7 @@ void ReduceToPath(TCHAR *filename); double WinGetRefreshRate(); int WinGetAutomaticInputRate(); void WinThrottleFramerate(); -std::vector *WinGetShaderParameters(); +std::vector *WinGetShaderParameters(); std::function WinGetShaderSaveFunction(); #endif diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index 687a997e..aac51221 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -121,6 +121,17 @@ struct dMode long rate; }; +struct ShaderParam +{ + std::string name; + std::string id; + float min; + float max; + float val; + float step; + int significant_digits; +}; + struct sCustomRomDlgSettings { int columnFilename; int columnDescription;