From a315627401b9fbb16edf778076777dac4387955c Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Fri, 11 Aug 2017 00:41:10 +0000 Subject: [PATCH] Added support for loading shaders from files for new engine and tile renderer. Changed help text to reflect new engine being default. --- Src/Graphics/New3D/New3D.cpp | 4 +- Src/Graphics/New3D/New3D.h | 7 ++- Src/Graphics/New3D/R3DScrollFog.cpp | 5 +- Src/Graphics/New3D/R3DScrollFog.h | 5 +- Src/Graphics/New3D/R3DShader.cpp | 5 +- Src/Graphics/New3D/R3DShader.h | 6 +- Src/Graphics/Render2D.cpp | 5 +- Src/Graphics/Render2D.h | 11 +++- Src/OSD/SDL/Main.cpp | 98 ++++++++++++++++------------- 9 files changed, 90 insertions(+), 56 deletions(-) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 87c86d5..9edbf7d 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -12,7 +12,9 @@ namespace New3D { -CNew3D::CNew3D() +CNew3D::CNew3D(const Util::Config::Node &config) + : m_r3dShader(config), + m_r3dScrollFog(config) { m_cullingRAMLo = nullptr; m_cullingRAMHi = nullptr; diff --git a/Src/Graphics/New3D/New3D.h b/Src/Graphics/New3D/New3D.h index df216c4..67e35d4 100644 --- a/Src/Graphics/New3D/New3D.h +++ b/Src/Graphics/New3D/New3D.h @@ -142,12 +142,15 @@ public: bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes); /* - * CRender3D(void): + * CRender3D(config): * ~CRender3D(void): * * Constructor and destructor. + * + * Parameters: + * config Run-time configuration. */ - CNew3D(void); + CNew3D(const Util::Config::Node &config); ~CNew3D(void); private: diff --git a/Src/Graphics/New3D/R3DScrollFog.cpp b/Src/Graphics/New3D/R3DScrollFog.cpp index e693bc8..3df2672 100644 --- a/Src/Graphics/New3D/R3DScrollFog.cpp +++ b/Src/Graphics/New3D/R3DScrollFog.cpp @@ -60,7 +60,8 @@ void main() )glsl"; -R3DScrollFog::R3DScrollFog() +R3DScrollFog::R3DScrollFog(const Util::Config::Node &config) + : m_config(config) { //default coordinates are NDC -1,1 etc @@ -121,7 +122,7 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient void R3DScrollFog::AllocResources() { - bool success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, std::string(), std::string(), vertexShaderFog, fragmentShaderFog); + bool success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, m_config["VertexShaderFog"].ValueAs(), m_config["FragmentShaderFog"].ValueAs(), vertexShaderFog, fragmentShaderFog); m_locMVP = glGetUniformLocation(m_shaderProgram, "mvp"); m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour"); diff --git a/Src/Graphics/New3D/R3DScrollFog.h b/Src/Graphics/New3D/R3DScrollFog.h index c44214d..641e706 100644 --- a/Src/Graphics/New3D/R3DScrollFog.h +++ b/Src/Graphics/New3D/R3DScrollFog.h @@ -1,6 +1,7 @@ #ifndef _R3DSCROLLFOG_H_ #define _R3DSCROLLFOG_H_ +#include "Util/NewConfig.h" #include "VBO.h" namespace New3D { @@ -9,7 +10,7 @@ class R3DScrollFog { public: - R3DScrollFog(); + R3DScrollFog(const Util::Config::Node &config); ~R3DScrollFog(); void DrawScrollFog(float rbga[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse); @@ -19,6 +20,8 @@ private: void AllocResources(); void DeallocResources(); + const Util::Config::Node &m_config; + struct SFVertex { void Set(float x, float y, float z) { diff --git a/Src/Graphics/New3D/R3DShader.cpp b/Src/Graphics/New3D/R3DShader.cpp index 4a016a7..e5c84ea 100644 --- a/Src/Graphics/New3D/R3DShader.cpp +++ b/Src/Graphics/New3D/R3DShader.cpp @@ -221,7 +221,8 @@ void main() } )glsl"; -R3DShader::R3DShader() +R3DShader::R3DShader(const Util::Config::Node &config) + : m_config(config) { m_shaderProgram = 0; m_vertexShader = 0; @@ -275,7 +276,7 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader) fShader = fragmentShaderR3D; } - success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, std::string(), std::string(), vShader, fShader); + success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, m_config["VertexShader"].ValueAs(), m_config["FragmentShader"].ValueAs(), vShader, fShader); m_locTexture1 = glGetUniformLocation(m_shaderProgram, "tex1"); m_locTexture2 = glGetUniformLocation(m_shaderProgram, "tex2"); diff --git a/Src/Graphics/New3D/R3DShader.h b/Src/Graphics/New3D/R3DShader.h index d3175c9..db5dd29 100644 --- a/Src/Graphics/New3D/R3DShader.h +++ b/Src/Graphics/New3D/R3DShader.h @@ -2,6 +2,7 @@ #define _R3DSHADER_H_ #include "Pkgs/glew.h" +#include "Util/NewConfig.h" #include "Model.h" namespace New3D { @@ -9,7 +10,7 @@ namespace New3D { class R3DShader { public: - R3DShader(); + R3DShader(const Util::Config::Node &config); bool LoadShader (const char* vertexShader = nullptr, const char* fragmentShader = nullptr); void SetMeshUniforms (const Mesh* m); @@ -20,6 +21,9 @@ public: private: + // run-time config + const Util::Config::Node &m_config; + // shader IDs GLuint m_shaderProgram; GLuint m_vertexShader; diff --git a/Src/Graphics/Render2D.cpp b/Src/Graphics/Render2D.cpp index 1d66291..94ef65e 100644 --- a/Src/Graphics/Render2D.cpp +++ b/Src/Graphics/Render2D.cpp @@ -638,7 +638,7 @@ void CRender2D::AttachVRAM(const uint8_t *vramPtr) bool CRender2D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes) { // Load shaders - if (OKAY != LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, std::string(), std::string(), s_vertexShaderSource, s_fragmentShaderSource)) + if (OKAY != LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, m_config["VertexShader2D"].ValueAs(), m_config["FragmentShader2D"].ValueAs(), s_vertexShaderSource, s_fragmentShaderSource)) return FAIL; // Get locations of the uniforms @@ -683,7 +683,8 @@ bool CRender2D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned return OKAY; } -CRender2D::CRender2D(void) +CRender2D::CRender2D(const Util::Config::Node &config) + : m_config(config) { DebugLog("Built Render2D\n"); } diff --git a/Src/Graphics/Render2D.h b/Src/Graphics/Render2D.h index 7715211..7fdb9d0 100644 --- a/Src/Graphics/Render2D.h +++ b/Src/Graphics/Render2D.h @@ -29,6 +29,7 @@ #define INCLUDED_RENDER2D_H #include "Pkgs/glew.h" +#include "Util/NewConfig.h" /* @@ -159,12 +160,15 @@ public: bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes); /* - * CRender2D(void): + * CRender2D(config): * ~CRender2D(void): * * Constructor and destructor. + * + * Parameters: + * config Run-time configuration. */ - CRender2D(void); + CRender2D(const Util::Config::Node &config); ~CRender2D(void); private: @@ -173,6 +177,9 @@ private: void DisplaySurface(int surface); void Setup2D(bool isBottom, bool clearAll); + // Run-time configuration + const Util::Config::Node &m_config; + // Data received from tile generator device object const uint32_t *m_vram; const uint32_t *m_palette[2]; // palettes for A/A' and B/B' diff --git a/Src/OSD/SDL/Main.cpp b/Src/OSD/SDL/Main.cpp index ded0905..d93517c 100644 --- a/Src/OSD/SDL/Main.cpp +++ b/Src/OSD/SDL/Main.cpp @@ -828,8 +828,8 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In Model3->AttachOutputs(Outputs); // Initialize the renderers - CRender2D *Render2D = new CRender2D(); - IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs() ? ((IRender3D *) new New3D::CNew3D()) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); + CRender2D *Render2D = new CRender2D(s_runtime_config); + IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) goto QuitError; if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) @@ -970,8 +970,8 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In goto QuitError; // Recreate renderers and attach to the emulator - Render2D = new CRender2D(); - Render3D = s_runtime_config["New3DEngine"].ValueAs() ? ((IRender3D *) new New3D::CNew3D()) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); + Render2D = new CRender2D(s_runtime_config); + Render3D = s_runtime_config["New3DEngine"].ValueAs() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) goto QuitError; if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) @@ -1277,10 +1277,14 @@ static Util::Config::Node DefaultConfig() config.Set("MultiThreaded", true); config.Set("GPUMultiThreaded", true); config.Set("PowerPCFrequency", "50"); - // CLegacy3D + // 2D and 3D graphics engines config.Set("MultiTexture", false); config.Set("VertexShader", ""); config.Set("FragmentShader", ""); + config.Set("VertexShaderFog", ""); + config.Set("FragmentShaderFog", ""); + config.Set("VertexShader2D", ""); + config.Set("FragmentShader2D", ""); // CSoundBoard config.Set("EmulateSound", true); config.Set("Balance", false); @@ -1335,59 +1339,63 @@ static void Help(void) puts("ROM set must be a valid ZIP file containing a single game."); puts(""); puts("General Options:"); - puts(" -?, -h, -help, --help Print this help text"); - puts(" -print-games List supported games and quit"); - printf(" -game-xml-file= ROM set definition file [Default: %s]\n", s_gameXMLFilePath); + puts(" -?, -h, -help, --help Print this help text"); + puts(" -print-games List supported games and quit"); + printf(" -game-xml-file= ROM set definition file [Default: %s]\n", s_gameXMLFilePath); puts(""); puts("Core Options:"); - printf(" -ppc-frequency= PowerPC frequency in MHz [Default: %d]\n", defaultConfig["PowerPCFrequency"].ValueAs()); - puts(" -no-threads Disable multi-threading entirely"); - puts(" -gpu-multi-threaded Run graphics rendering in separate thread [Default]"); - puts(" -no-gpu-thread Run graphics rendering in main thread"); + printf(" -ppc-frequency= PowerPC frequency in MHz [Default: %d]\n", defaultConfig["PowerPCFrequency"].ValueAs()); + puts(" -no-threads Disable multi-threading entirely"); + puts(" -gpu-multi-threaded Run graphics rendering in separate thread [Default]"); + puts(" -no-gpu-thread Run graphics rendering in main thread"); puts(""); puts("Video Options:"); - puts(" -res=, Resolution [Default: 496,384]"); - puts(" -window Windowed mode [Default]"); - puts(" -fullscreen Full screen mode"); - puts(" -wide-screen Expand 3D field of view to screen width"); - puts(" -multi-texture Use 8 texture maps for decoding"); - puts(" -no-multi-texture Decode to a single texture map [Default]"); - puts(" -no-throttle Disable 60 Hz frame rate lock"); - puts(" -vsync Lock to vertical refresh rate [Default]"); - puts(" -no-vsync Do not lock to vertical refresh rate"); - puts(" -show-fps Display frame rate in window title bar"); - puts(" -crosshairs= Crosshairs configuration for gun games:"); - puts(" 0=none [Default], 1=P1 only, 2=P2 only, 3=P1 & P2"); - puts(" -legacy3d Legacy 3D engine [Default]"); - puts(" -new3d New 3D engine by Ian Curtis"); - puts(" -vert-shader= Load vertex shader from file (legacy 3D engine)"); - puts(" -frag-shader= Load fragment shader from file (legacy 3D engine)"); - puts(" -print-gl-info Print OpenGL driver information and quit"); + puts(" -res=, Resolution [Default: 496,384]"); + puts(" -window Windowed mode [Default]"); + puts(" -fullscreen Full screen mode"); + puts(" -wide-screen Expand 3D field of view to screen width"); + puts(" -no-throttle Disable 60 Hz frame rate lock"); + puts(" -vsync Lock to vertical refresh rate [Default]"); + puts(" -no-vsync Do not lock to vertical refresh rate"); + puts(" -show-fps Display frame rate in window title bar"); + puts(" -crosshairs= Crosshairs configuration for gun games:"); + puts(" 0=none [Default], 1=P1 only, 2=P2 only, 3=P1 & P2"); + puts(" -new3d New 3D engine by Ian Curtis [Default]"); + puts(" -legacy3d Legacy 3D engine (faster but less accurate)"); + puts(" -multi-texture Use 8 texture maps for decoding (legacy engine)"); + puts(" -no-multi-texture Decode to single texture (legacy engine) [Default]"); + puts(" -vert-shader= Load Real3D vertex shader for 3D rendering"); + puts(" -frag-shader= Load Real3D fragment shader for 3D rendering"); + puts(" -vert-shader-fog= Load Real3D scroll fog vertex shader (new engine)"); + puts(" -frag-shader-fog= Load Real3D scroll fog fragment shader (new engine)"); + puts(" -vert-shader-2d= Load tile map vertex shader"); + puts(" -frag-shader-2d= Load tile map fragment shader"); + puts(" -print-gl-info Print OpenGL driver information and quit"); puts(""); puts("Audio Options:"); - puts(" -sound-volume= Volume of SCSP-generated sound in %, applies only"); - puts(" when Digital Sound Board is present [Default: 100]"); - puts(" -music-volume= Digital Sound Board volume in % [Default: 100]"); - puts(" -balance= Relative front/rear balance in % [Default: 0]"); - puts(" -flip-stereo Swap left and right audio channels"); - puts(" -no-sound Disable sound board emulation (sound effects)"); - puts(" -no-dsb Disable Digital Sound Board (MPEG music)"); + puts(" -sound-volume= Volume of SCSP-generated sound in %, applies only"); + puts(" when Digital Sound Board is present [Default: 100]"); + puts(" -music-volume= Digital Sound Board volume in % [Default: 100]"); + puts(" -balance= Relative front/rear balance in % [Default: 0]"); + puts(" -flip-stereo Swap left and right audio channels"); + puts(" -no-sound Disable sound board emulation (sound effects)"); + puts(" -no-dsb Disable Digital Sound Board (MPEG music)"); puts(""); puts("Input Options:"); #ifdef SUPERMODEL_WIN32 - puts(" -force-feedback Enable force feedback (DirectInput, XInput)"); + puts(" -force-feedback Enable force feedback (DirectInput, XInput)"); #endif - puts(" -config-inputs Configure keyboards, mice, and game controllers"); + puts(" -config-inputs Configure keyboards, mice, and game controllers"); #ifdef SUPERMODEL_WIN32 - printf(" -input-system= Input system [Default: %s]\n", defaultConfig["InputSystem"].ValueAs().c_str()); - printf(" -outputs= Outputs [Default: %s]\n", defaultConfig["Outputs"].ValueAs().c_str()); + printf(" -input-system= Input system [Default: %s]\n", defaultConfig["InputSystem"].ValueAs().c_str()); + printf(" -outputs= Outputs [Default: %s]\n", defaultConfig["Outputs"].ValueAs().c_str()); #endif - puts(" -print-inputs Prints current input configuration"); + puts(" -print-inputs Prints current input configuration"); puts(""); #ifdef SUPERMODEL_DEBUGGER puts("Debug Options:"); - puts(" -disable-debugger Completely disable debugger functionality"); - puts(" -enter-debugger Enter debugger at start of emulation"); + puts(" -disable-debugger Completely disable debugger functionality"); + puts(" -enter-debugger Enter debugger at start of emulation"); puts(""); #endif // SUPERMODEL_DEBUGGER } @@ -1418,6 +1426,10 @@ static ParsedCommandLine ParseCommandLine(int argc, char **argv) { "-crosshairs", "Crosshairs" }, { "-vert-shader", "VertexShader" }, { "-frag-shader", "FragmentShader" }, + { "-vert-shader-fog", "VertexShaderFog" }, + { "-frag-shader-fog", "FragmentShaderFog" }, + { "-vert-shader-2d", "VertexShader2D" }, + { "-frag-shader-2d", "FragmentShader2D" }, { "-sound-volume", "SoundVolume" }, { "-music-volume", "MusicVolume" }, { "-balance", "Balance" },