diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.h b/Source/Core/VideoCommon/Src/LightingShaderGen.h index 09b0cdc28f..5945bc09ca 100644 --- a/Source/Core/VideoCommon/Src/LightingShaderGen.h +++ b/Source/Core/VideoCommon/Src/LightingShaderGen.h @@ -18,15 +18,17 @@ #ifndef _LIGHTINGSHADERGEN_H_ #define _LIGHTINGSHADERGEN_H_ +#include + #include "ShaderGenCommon.h" #include "NativeVertexFormat.h" #include "XFMemory.h" // T.uid_data needs to have a struct named lighting_uid -template +template void GenerateLightShader(T& object, int index, int litchan_index, const char* lightsName, int coloralpha) { -#define SetUidField(name, value) if (type == GO_ShaderUid) { object.GetUidData().name = value; }; +#define SetUidField(name, value) if (typeid(T) == typeid(UidType)) { object.GetUidData().name = value; }; const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index]; const char* swizzle = "xyzw"; if (coloralpha == 1 ) swizzle = "xyz"; @@ -92,7 +94,7 @@ void GenerateLightShader(T& object, int index, int litchan_index, const char* li // materials name is I_MATERIALS in vs and I_PMATERIALS in ps // inColorName is color in vs and colors_ in ps // dest is o.colors_ in vs and colors_ in ps -template +template void GenerateLightingShader(T& object, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest) { for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++) @@ -186,7 +188,7 @@ void GenerateLightingShader(T& object, int components, const char* materialsName { if (mask & (1<(object, i, j, lightsName, 3); + GenerateLightShader(object, i, j, lightsName, 3); } } } @@ -196,9 +198,9 @@ void GenerateLightingShader(T& object, int components, const char* materialsName for (int i = 0; i < 8; ++i) { if (!(mask&(1<(object, i, j, lightsName, 1); + GenerateLightShader(object, i, j, lightsName, 1); if (!(mask&(1<(object, i, j+2, lightsName, 2); + GenerateLightShader(object, i, j+2, lightsName, 2); } } else if (color.enablelighting || alpha.enablelighting) @@ -212,7 +214,7 @@ void GenerateLightingShader(T& object, int components, const char* materialsName for (int i = 0; i < 8; ++i) { if (workingchannel.GetFullLightMask() & (1<(object, i, lit_index, lightsName, coloralpha); + GenerateLightShader(object, i, lit_index, lightsName, coloralpha); } } object.Write("%s%d = mat * saturate(lacc);\n", dest, j); diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 44023e2000..f22ef94c6d 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "LightingShaderGen.h" #include "PixelShaderGen.h" @@ -37,10 +38,10 @@ // output is given by .outreg // tevtemp is set according to swapmodetables and -template static void WriteStage(char *&p, int n, API_TYPE ApiType); -template static void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType); -template static void WriteAlphaTest(T& out, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth); -template static void WriteFog(T& out); +template static void WriteStage(char *&p, int n, API_TYPE ApiType); +template static void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType); +template static void WriteAlphaTest(T& out, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth); +template static void WriteFog(T& out); static const char *tevKSelTableC[] = // KCSEL { @@ -266,13 +267,13 @@ const char *WriteLocation(API_TYPE ApiType) return result; } -template +template void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) { // TODO: Can be optimized if using alpha pass -#define SetUidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name = value; }; -#define OR_UidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name |= value; }; - if (type == GO_ShaderCode) +#define SetUidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name = value; }; +#define OR_UidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name |= value; }; + if (typeid(T) == typeid(PixelShaderCode)) { setlocale(LC_NUMERIC, "C"); // Reset locale for compilation out.SetBuffer(text); @@ -558,7 +559,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u char buffer[32]; sprintf(buffer, "float3 indtex%d", i); - SampleTexture(out, buffer, "tempcoord", "abg", texmap, ApiType); + SampleTexture(out, buffer, "tempcoord", "abg", texmap, ApiType); } } @@ -575,7 +576,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u // Uid fields for BuildSwapModeTable are set in WriteStage BuildSwapModeTable(); for (unsigned int i = 0; i < numStages; i++) - WriteStage(out, i, ApiType); // build the equation for this stage + WriteStage(out, i, ApiType); // build the equation for this stage if (numStages) { @@ -604,7 +605,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u AlphaTest::TEST_RESULT Pretest = bpmem.alpha_test.TestResult(); SetUidField(Pretest, Pretest); if (Pretest == AlphaTest::UNDETERMINED) - WriteAlphaTest(out, ApiType, dstAlphaMode, per_pixel_depth); + WriteAlphaTest(out, ApiType, dstAlphaMode, per_pixel_depth); // the screen space depth value = far z + (clip z / clip w) * z range @@ -648,7 +649,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u } else { - WriteFog(out); + WriteFog(out); out.Write("\tocol0 = prev;\n"); } @@ -716,7 +717,7 @@ static const char *TEVCMPAlphaOPTable[16] = }; -template +template static void WriteStage(T& out, int n, API_TYPE ApiType) { int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1); @@ -865,7 +866,7 @@ static void WriteStage(T& out, int n, API_TYPE ApiType) char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; int texmap = bpmem.tevorders[n/2].getTexMap(n&1); - SampleTexture(out, "textemp", "tevcoord", texswap, texmap, ApiType); + SampleTexture(out, "textemp", "tevcoord", texswap, texmap, ApiType); } else out.Write("textemp = float4(1.0f, 1.0f, 1.0f, 1.0f);\n"); @@ -1090,7 +1091,7 @@ static void WriteStage(T& out, int n, API_TYPE ApiType) out.Write("// TEV done\n"); } -template +template void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType) { out.SetConstantsUsed(C_TEXDIMS+texmap,C_TEXDIMS+texmap); @@ -1120,7 +1121,7 @@ static const char *tevAlphaFunclogicTable[] = " == " // xnor }; -template +template static void WriteAlphaTest(T& out, API_TYPE ApiType, DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth) { static const char *alphaRef[2] = @@ -1188,7 +1189,7 @@ static const char *tevFogFuncsTable[] = "\tfog = 1.0f - fog;\n fog = pow(2.0f, -8.0f * fog * fog);\n" //backward exp2 }; -template +template static void WriteFog(T& out) { SetUidField(fog.fsel, bpmem.fog.c_proj_fsel.fsel); @@ -1240,16 +1241,16 @@ static void WriteFog(T& out) void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) { - GeneratePixelShader(object, dstAlphaMode, ApiType, components); + GeneratePixelShader(object, dstAlphaMode, ApiType, components); } void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) { - GeneratePixelShader(object, dstAlphaMode, ApiType, components); + GeneratePixelShader(object, dstAlphaMode, ApiType, components); } void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) { - GeneratePixelShader(object, dstAlphaMode, ApiType, components); + GeneratePixelShader(object, dstAlphaMode, ApiType, components); } diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h index d02462360d..8606a4e5b9 100644 --- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h @@ -123,11 +123,4 @@ private: std::vector constant_usage; // TODO: Is vector appropriate here? }; -enum GenOutput -{ - GO_ShaderCode, - GO_ShaderUid, - GO_ShaderConstantProfile, -}; - #endif // _SHADERGENCOMMON_H diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 2ea5ef5d7f..3e2daf55d3 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "NativeVertexFormat.h" @@ -80,13 +81,13 @@ void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type) extern const char *WriteRegister(API_TYPE api_type, const char *prefix, const u32 num); extern const char *WriteLocation(API_TYPE api_type); -template +template void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) { #undef SetUidField -#define SetUidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name = value; }; +#define SetUidField(name, value) if (typeid(T) == typeid(VertexShaderUid)) {out.GetUidData().name = value; }; - if (type == GO_ShaderCode) + if (typeid(T) == typeid(VertexShaderCode)) { out.SetBuffer(text); setlocale(LC_NUMERIC, "C"); // Reset locale for compilation @@ -275,7 +276,7 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) } // TODO: This probably isn't necessary if pixel lighting is enabled. - GenerateLightingShader(out, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_"); + GenerateLightingShader(out, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_"); if (xfregs.numChan.numColorChans < 2) { @@ -522,16 +523,16 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) /// if (text[sizeof(text) - 1] != 0x7C) /// PanicAlert("VertexShader generator - buffer too small, canary has been eaten!"); - if (type == GO_ShaderCode) + if (typeid(T) == typeid(VertexShaderCode)) setlocale(LC_NUMERIC, ""); // restore locale } void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type) { - GenerateVertexShader(object, components, api_type); + GenerateVertexShader(object, components, api_type); } void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type) { - GenerateVertexShader(object, components, api_type); + GenerateVertexShader(object, components, api_type); }