Added support for loading shaders from files for new engine and tile renderer. Changed help text to reflect new engine being default.

This commit is contained in:
Bart Trzynadlowski 2017-08-11 00:41:10 +00:00
parent 7dc1eac614
commit a315627401
9 changed files with 90 additions and 56 deletions

View file

@ -12,7 +12,9 @@
namespace New3D { namespace New3D {
CNew3D::CNew3D() CNew3D::CNew3D(const Util::Config::Node &config)
: m_r3dShader(config),
m_r3dScrollFog(config)
{ {
m_cullingRAMLo = nullptr; m_cullingRAMLo = nullptr;
m_cullingRAMHi = nullptr; m_cullingRAMHi = nullptr;

View file

@ -142,12 +142,15 @@ public:
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes); bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/* /*
* CRender3D(void): * CRender3D(config):
* ~CRender3D(void): * ~CRender3D(void):
* *
* Constructor and destructor. * Constructor and destructor.
*
* Parameters:
* config Run-time configuration.
*/ */
CNew3D(void); CNew3D(const Util::Config::Node &config);
~CNew3D(void); ~CNew3D(void);
private: private:

View file

@ -60,7 +60,8 @@ void main()
)glsl"; )glsl";
R3DScrollFog::R3DScrollFog() R3DScrollFog::R3DScrollFog(const Util::Config::Node &config)
: m_config(config)
{ {
//default coordinates are NDC -1,1 etc //default coordinates are NDC -1,1 etc
@ -121,7 +122,7 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient
void R3DScrollFog::AllocResources() 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<std::string>(), m_config["FragmentShaderFog"].ValueAs<std::string>(), vertexShaderFog, fragmentShaderFog);
m_locMVP = glGetUniformLocation(m_shaderProgram, "mvp"); m_locMVP = glGetUniformLocation(m_shaderProgram, "mvp");
m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour"); m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour");

View file

@ -1,6 +1,7 @@
#ifndef _R3DSCROLLFOG_H_ #ifndef _R3DSCROLLFOG_H_
#define _R3DSCROLLFOG_H_ #define _R3DSCROLLFOG_H_
#include "Util/NewConfig.h"
#include "VBO.h" #include "VBO.h"
namespace New3D { namespace New3D {
@ -9,7 +10,7 @@ class R3DScrollFog
{ {
public: public:
R3DScrollFog(); R3DScrollFog(const Util::Config::Node &config);
~R3DScrollFog(); ~R3DScrollFog();
void DrawScrollFog(float rbga[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse); void DrawScrollFog(float rbga[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse);
@ -19,6 +20,8 @@ private:
void AllocResources(); void AllocResources();
void DeallocResources(); void DeallocResources();
const Util::Config::Node &m_config;
struct SFVertex struct SFVertex
{ {
void Set(float x, float y, float z) { void Set(float x, float y, float z) {

View file

@ -221,7 +221,8 @@ void main()
} }
)glsl"; )glsl";
R3DShader::R3DShader() R3DShader::R3DShader(const Util::Config::Node &config)
: m_config(config)
{ {
m_shaderProgram = 0; m_shaderProgram = 0;
m_vertexShader = 0; m_vertexShader = 0;
@ -275,7 +276,7 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader)
fShader = fragmentShaderR3D; 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<std::string>(), m_config["FragmentShader"].ValueAs<std::string>(), vShader, fShader);
m_locTexture1 = glGetUniformLocation(m_shaderProgram, "tex1"); m_locTexture1 = glGetUniformLocation(m_shaderProgram, "tex1");
m_locTexture2 = glGetUniformLocation(m_shaderProgram, "tex2"); m_locTexture2 = glGetUniformLocation(m_shaderProgram, "tex2");

View file

@ -2,6 +2,7 @@
#define _R3DSHADER_H_ #define _R3DSHADER_H_
#include "Pkgs/glew.h" #include "Pkgs/glew.h"
#include "Util/NewConfig.h"
#include "Model.h" #include "Model.h"
namespace New3D { namespace New3D {
@ -9,7 +10,7 @@ namespace New3D {
class R3DShader class R3DShader
{ {
public: public:
R3DShader(); R3DShader(const Util::Config::Node &config);
bool LoadShader (const char* vertexShader = nullptr, const char* fragmentShader = nullptr); bool LoadShader (const char* vertexShader = nullptr, const char* fragmentShader = nullptr);
void SetMeshUniforms (const Mesh* m); void SetMeshUniforms (const Mesh* m);
@ -20,6 +21,9 @@ public:
private: private:
// run-time config
const Util::Config::Node &m_config;
// shader IDs // shader IDs
GLuint m_shaderProgram; GLuint m_shaderProgram;
GLuint m_vertexShader; GLuint m_vertexShader;

View file

@ -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) bool CRender2D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes)
{ {
// Load shaders // 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<std::string>(), m_config["FragmentShader2D"].ValueAs<std::string>(), s_vertexShaderSource, s_fragmentShaderSource))
return FAIL; return FAIL;
// Get locations of the uniforms // Get locations of the uniforms
@ -683,7 +683,8 @@ bool CRender2D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned
return OKAY; return OKAY;
} }
CRender2D::CRender2D(void) CRender2D::CRender2D(const Util::Config::Node &config)
: m_config(config)
{ {
DebugLog("Built Render2D\n"); DebugLog("Built Render2D\n");
} }

View file

@ -29,6 +29,7 @@
#define INCLUDED_RENDER2D_H #define INCLUDED_RENDER2D_H
#include "Pkgs/glew.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); bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/* /*
* CRender2D(void): * CRender2D(config):
* ~CRender2D(void): * ~CRender2D(void):
* *
* Constructor and destructor. * Constructor and destructor.
*
* Parameters:
* config Run-time configuration.
*/ */
CRender2D(void); CRender2D(const Util::Config::Node &config);
~CRender2D(void); ~CRender2D(void);
private: private:
@ -173,6 +177,9 @@ private:
void DisplaySurface(int surface); void DisplaySurface(int surface);
void Setup2D(bool isBottom, bool clearAll); void Setup2D(bool isBottom, bool clearAll);
// Run-time configuration
const Util::Config::Node &m_config;
// Data received from tile generator device object // Data received from tile generator device object
const uint32_t *m_vram; const uint32_t *m_vram;
const uint32_t *m_palette[2]; // palettes for A/A' and B/B' const uint32_t *m_palette[2]; // palettes for A/A' and B/B'

View file

@ -828,8 +828,8 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
Model3->AttachOutputs(Outputs); Model3->AttachOutputs(Outputs);
// Initialize the renderers // Initialize the renderers
CRender2D *Render2D = new CRender2D(); CRender2D *Render2D = new CRender2D(s_runtime_config);
IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D()) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config));
if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))
goto QuitError; goto QuitError;
if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) 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; goto QuitError;
// Recreate renderers and attach to the emulator // Recreate renderers and attach to the emulator
Render2D = new CRender2D(); Render2D = new CRender2D(s_runtime_config);
Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D()) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config));
if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))
goto QuitError; goto QuitError;
if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) 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("MultiThreaded", true);
config.Set("GPUMultiThreaded", true); config.Set("GPUMultiThreaded", true);
config.Set("PowerPCFrequency", "50"); config.Set("PowerPCFrequency", "50");
// CLegacy3D // 2D and 3D graphics engines
config.Set("MultiTexture", false); config.Set("MultiTexture", false);
config.Set("VertexShader", ""); config.Set("VertexShader", "");
config.Set("FragmentShader", ""); config.Set("FragmentShader", "");
config.Set("VertexShaderFog", "");
config.Set("FragmentShaderFog", "");
config.Set("VertexShader2D", "");
config.Set("FragmentShader2D", "");
// CSoundBoard // CSoundBoard
config.Set("EmulateSound", true); config.Set("EmulateSound", true);
config.Set("Balance", false); 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("ROM set must be a valid ZIP file containing a single game.");
puts(""); puts("");
puts("General Options:"); puts("General Options:");
puts(" -?, -h, -help, --help Print this help text"); puts(" -?, -h, -help, --help Print this help text");
puts(" -print-games List supported games and quit"); puts(" -print-games List supported games and quit");
printf(" -game-xml-file=<file> ROM set definition file [Default: %s]\n", s_gameXMLFilePath); printf(" -game-xml-file=<file> ROM set definition file [Default: %s]\n", s_gameXMLFilePath);
puts(""); puts("");
puts("Core Options:"); puts("Core Options:");
printf(" -ppc-frequency=<freq> PowerPC frequency in MHz [Default: %d]\n", defaultConfig["PowerPCFrequency"].ValueAs<unsigned>()); printf(" -ppc-frequency=<freq> PowerPC frequency in MHz [Default: %d]\n", defaultConfig["PowerPCFrequency"].ValueAs<unsigned>());
puts(" -no-threads Disable multi-threading entirely"); puts(" -no-threads Disable multi-threading entirely");
puts(" -gpu-multi-threaded Run graphics rendering in separate thread [Default]"); puts(" -gpu-multi-threaded Run graphics rendering in separate thread [Default]");
puts(" -no-gpu-thread Run graphics rendering in main thread"); puts(" -no-gpu-thread Run graphics rendering in main thread");
puts(""); puts("");
puts("Video Options:"); puts("Video Options:");
puts(" -res=<x>,<y> Resolution [Default: 496,384]"); puts(" -res=<x>,<y> Resolution [Default: 496,384]");
puts(" -window Windowed mode [Default]"); puts(" -window Windowed mode [Default]");
puts(" -fullscreen Full screen mode"); puts(" -fullscreen Full screen mode");
puts(" -wide-screen Expand 3D field of view to screen width"); puts(" -wide-screen Expand 3D field of view to screen width");
puts(" -multi-texture Use 8 texture maps for decoding"); puts(" -no-throttle Disable 60 Hz frame rate lock");
puts(" -no-multi-texture Decode to a single texture map [Default]"); puts(" -vsync Lock to vertical refresh rate [Default]");
puts(" -no-throttle Disable 60 Hz frame rate lock"); puts(" -no-vsync Do not lock to vertical refresh rate");
puts(" -vsync Lock to vertical refresh rate [Default]"); puts(" -show-fps Display frame rate in window title bar");
puts(" -no-vsync Do not lock to vertical refresh rate"); puts(" -crosshairs=<n> Crosshairs configuration for gun games:");
puts(" -show-fps Display frame rate in window title bar"); puts(" 0=none [Default], 1=P1 only, 2=P2 only, 3=P1 & P2");
puts(" -crosshairs=<n> Crosshairs configuration for gun games:"); puts(" -new3d New 3D engine by Ian Curtis [Default]");
puts(" 0=none [Default], 1=P1 only, 2=P2 only, 3=P1 & P2"); puts(" -legacy3d Legacy 3D engine (faster but less accurate)");
puts(" -legacy3d Legacy 3D engine [Default]"); puts(" -multi-texture Use 8 texture maps for decoding (legacy engine)");
puts(" -new3d New 3D engine by Ian Curtis"); puts(" -no-multi-texture Decode to single texture (legacy engine) [Default]");
puts(" -vert-shader=<file> Load vertex shader from file (legacy 3D engine)"); puts(" -vert-shader=<file> Load Real3D vertex shader for 3D rendering");
puts(" -frag-shader=<file> Load fragment shader from file (legacy 3D engine)"); puts(" -frag-shader=<file> Load Real3D fragment shader for 3D rendering");
puts(" -print-gl-info Print OpenGL driver information and quit"); puts(" -vert-shader-fog=<file> Load Real3D scroll fog vertex shader (new engine)");
puts(" -frag-shader-fog=<file> Load Real3D scroll fog fragment shader (new engine)");
puts(" -vert-shader-2d=<file> Load tile map vertex shader");
puts(" -frag-shader-2d=<file> Load tile map fragment shader");
puts(" -print-gl-info Print OpenGL driver information and quit");
puts(""); puts("");
puts("Audio Options:"); puts("Audio Options:");
puts(" -sound-volume=<vol> Volume of SCSP-generated sound in %, applies only"); puts(" -sound-volume=<vol> Volume of SCSP-generated sound in %, applies only");
puts(" when Digital Sound Board is present [Default: 100]"); puts(" when Digital Sound Board is present [Default: 100]");
puts(" -music-volume=<vol> Digital Sound Board volume in % [Default: 100]"); puts(" -music-volume=<vol> Digital Sound Board volume in % [Default: 100]");
puts(" -balance=<bal> Relative front/rear balance in % [Default: 0]"); puts(" -balance=<bal> Relative front/rear balance in % [Default: 0]");
puts(" -flip-stereo Swap left and right audio channels"); puts(" -flip-stereo Swap left and right audio channels");
puts(" -no-sound Disable sound board emulation (sound effects)"); puts(" -no-sound Disable sound board emulation (sound effects)");
puts(" -no-dsb Disable Digital Sound Board (MPEG music)"); puts(" -no-dsb Disable Digital Sound Board (MPEG music)");
puts(""); puts("");
puts("Input Options:"); puts("Input Options:");
#ifdef SUPERMODEL_WIN32 #ifdef SUPERMODEL_WIN32
puts(" -force-feedback Enable force feedback (DirectInput, XInput)"); puts(" -force-feedback Enable force feedback (DirectInput, XInput)");
#endif #endif
puts(" -config-inputs Configure keyboards, mice, and game controllers"); puts(" -config-inputs Configure keyboards, mice, and game controllers");
#ifdef SUPERMODEL_WIN32 #ifdef SUPERMODEL_WIN32
printf(" -input-system=<s> Input system [Default: %s]\n", defaultConfig["InputSystem"].ValueAs<std::string>().c_str()); printf(" -input-system=<s> Input system [Default: %s]\n", defaultConfig["InputSystem"].ValueAs<std::string>().c_str());
printf(" -outputs=<s> Outputs [Default: %s]\n", defaultConfig["Outputs"].ValueAs<std::string>().c_str()); printf(" -outputs=<s> Outputs [Default: %s]\n", defaultConfig["Outputs"].ValueAs<std::string>().c_str());
#endif #endif
puts(" -print-inputs Prints current input configuration"); puts(" -print-inputs Prints current input configuration");
puts(""); puts("");
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
puts("Debug Options:"); puts("Debug Options:");
puts(" -disable-debugger Completely disable debugger functionality"); puts(" -disable-debugger Completely disable debugger functionality");
puts(" -enter-debugger Enter debugger at start of emulation"); puts(" -enter-debugger Enter debugger at start of emulation");
puts(""); puts("");
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
} }
@ -1418,6 +1426,10 @@ static ParsedCommandLine ParseCommandLine(int argc, char **argv)
{ "-crosshairs", "Crosshairs" }, { "-crosshairs", "Crosshairs" },
{ "-vert-shader", "VertexShader" }, { "-vert-shader", "VertexShader" },
{ "-frag-shader", "FragmentShader" }, { "-frag-shader", "FragmentShader" },
{ "-vert-shader-fog", "VertexShaderFog" },
{ "-frag-shader-fog", "FragmentShaderFog" },
{ "-vert-shader-2d", "VertexShader2D" },
{ "-frag-shader-2d", "FragmentShader2D" },
{ "-sound-volume", "SoundVolume" }, { "-sound-volume", "SoundVolume" },
{ "-music-volume", "MusicVolume" }, { "-music-volume", "MusicVolume" },
{ "-balance", "Balance" }, { "-balance", "Balance" },