diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index 80bd3d75e8..aba142aefe 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -129,6 +129,13 @@ #endif // WIN32 +typedef enum +{ + API_OPENGL, + API_D3D9, + API_D3D11 +} API_TYPE; + // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 87aa9480b3..ae2758c84f 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -146,10 +146,10 @@ void GetPixelShaderId(PIXELSHADERUID *uid, u32 texturemask, u32 dstAlphaEnable) // output is given by .outreg // tevtemp is set according to swapmodetables and -static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL); -static void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask, u32 HLSL); +static void WriteStage(char *&p, int n, u32 texture_mask, API_TYPE ApiType); +static void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask, API_TYPE ApiType); // static void WriteAlphaCompare(char *&p, int num, int comp); -static bool WriteAlphaTest(char *&p, u32 HLSL); +static bool WriteAlphaTest(char *&p, API_TYPE ApiType); static void WriteFog(char *&p); const float epsilon8bit = 1.0f / 255.0f; @@ -357,7 +357,7 @@ static void BuildSwapModeTable() } } -const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, u32 HLSL) +const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_TYPE ApiType) { setlocale(LC_NUMERIC, "C"); // Reset locale for compilation text[sizeof(text) - 1] = 0x7C; // canary @@ -385,7 +385,7 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, u32 H // Declare samplers if (texture_mask) { - if (HLSL) + if (ApiType != API_OPENGL) WRITE(p, "uniform sampler "); else WRITE(p, "uniform samplerRECT "); @@ -488,13 +488,13 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, u32 H char buffer[32]; sprintf(buffer, "float3 indtex%d", i); - SampleTexture(p, buffer, "tempcoord", "abg", bpmem.tevindref.getTexMap(i), texture_mask,HLSL); + SampleTexture(p, buffer, "tempcoord", "abg", bpmem.tevindref.getTexMap(i), texture_mask,ApiType); } } for (int i = 0; i < numStages; i++) - WriteStage(p, i, texture_mask,HLSL); //build the equation for this stage + WriteStage(p, i, texture_mask,ApiType); //build the equation for this stage if(numStages) { // The results of the last texenv stage are put onto the screen, @@ -506,13 +506,15 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, u32 H // emulation of unisgned 8 overflow when casting WRITE(p, "prev = frac(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n"); - if (!WriteAlphaTest(p, HLSL)) + if (!WriteAlphaTest(p, ApiType)) { // alpha test will always fail, so restart the shader and just make it an empty function p = pmainstart; WRITE(p, "ocol0 = 0;\n"); WRITE(p, "depth = 1.f;\n"); - WRITE(p, "discard;return;\n"); + WRITE(p, "discard;\n"); + if(ApiType != API_D3D11) + WRITE(p, "return;\n"); } else { @@ -602,7 +604,7 @@ static const char *TEVCMPAlphaOPTable[16] = }; -static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL) +static void WriteStage(char *&p, int n, u32 texture_mask, API_TYPE ApiType) { char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap]; char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; @@ -698,7 +700,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL) WRITE(p, "tevcoord.xy = float2(0.0f,0.0f);\n"); } - SampleTexture(p, "textemp", "tevcoord", texswap, texmap, texture_mask, HLSL); + SampleTexture(p, "textemp", "tevcoord", texswap, texmap, texture_mask, ApiType); } else WRITE(p, "textemp=float4(1.0f,1.0f,1.0f,1.0f);\n"); @@ -851,7 +853,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask, u32 HLSL) WRITE(p, ";\n\n"); } -void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask, u32 HLSL) +void SampleTexture(char *&p, const char *destination, const char *texcoords, const char *texswap, int texmap, u32 texture_mask, API_TYPE ApiType) { if (texture_mask & (1<