fix formatting uglies introduced in glsl-master branch

This commit is contained in:
Shawn Hoffman 2011-12-26 00:15:54 -05:00
parent f59063c8e7
commit 4bc14c3473
15 changed files with 1069 additions and 1054 deletions

View File

@ -581,7 +581,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con
// GLSL Option // GLSL Option
{ {
if(strstr(choice_backend->GetString(choice_backend->GetSelection()).ToAscii(), "OpenGL") != NULL) if (strstr(choice_backend->GetString(choice_backend->GetSelection()).ToAscii(), "OpenGL") != NULL)
{ {
wxCheckBox* const cb_GLSL = CreateCheckBox(page_advanced, _("Use GLSL Shaders"), wxGetTranslation(GLSL_desc), vconfig.bUseGLSL); wxCheckBox* const cb_GLSL = CreateCheckBox(page_advanced, _("Use GLSL Shaders"), wxGetTranslation(GLSL_desc), vconfig.bUseGLSL);
szr_misc->Add(cb_GLSL); szr_misc->Add(cb_GLSL);

View File

@ -112,7 +112,7 @@ protected:
void Event_ProgressiveScan(wxCommandEvent &ev) void Event_ProgressiveScan(wxCommandEvent &ev)
{ {
SConfig::GetInstance().m_SYSCONF->SetData("IPL.PGS", ev.GetInt()); SConfig::GetInstance().m_SYSCONF->SetData("IPL.PGS", ev.GetInt());
SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive = ev.GetInt(); SConfig::GetInstance().m_LocalCoreStartupParameter.bProgressive = !!ev.GetInt();
ev.Skip(); ev.Skip();
} }

View File

@ -502,23 +502,25 @@ static void BuildSwapModeTable()
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num) const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{ {
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
return ""; // Nothing to do here return ""; // Nothing to do here
static char result[64]; static char result[64];
sprintf(result, " : register(%s%d)", prefix, num); sprintf(result, " : register(%s%d)", prefix, num);
return result; return result;
} }
const char* WriteBinding(API_TYPE ApiType, const u32 num) const char* WriteBinding(API_TYPE ApiType, const u32 num)
{ {
if(ApiType != API_GLSL || !g_ActiveConfig.backend_info.bSupportsGLSLBinding) if (ApiType != API_GLSL || !g_ActiveConfig.backend_info.bSupportsGLSLBinding)
return ""; return "";
static char result[64]; static char result[64];
sprintf(result, "layout(binding = %d) ", num); sprintf(result, "layout(binding = %d) ", num);
return result; return result;
} }
const char *WriteLocation(API_TYPE ApiType) const char *WriteLocation(API_TYPE ApiType)
{ {
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return ""; return "";
static char result[64]; static char result[64];
sprintf(result, "uniform "); sprintf(result, "uniform ");
@ -550,7 +552,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
} }
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ; DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
// A few required defines and ones that will make our lives a lot easier // A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -564,7 +566,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
else else
WRITE(p, "#version 120\n"); WRITE(p, "#version 120\n");
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n"); WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences // Silly differences
WRITE(p, "#define float2 vec2\n"); WRITE(p, "#define float2 vec2\n");
@ -593,7 +595,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{ {
// Declare samplers // Declare samplers
if(ApiType != API_D3D11) if (ApiType != API_D3D11)
{ {
WRITE(p, "uniform sampler2D "); WRITE(p, "uniform sampler2D ");
} }
@ -609,7 +611,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
bfirst = false; bfirst = false;
} }
WRITE(p, ";\n"); WRITE(p, ";\n");
if(ApiType == API_D3D11) if (ApiType == API_D3D11)
{ {
WRITE(p, "Texture2D "); WRITE(p, "Texture2D ");
bfirst = true; bfirst = true;
@ -623,7 +625,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
} }
WRITE(p, "\n"); WRITE(p, "\n");
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform PSBlock {\n"); WRITE(p, "layout(std140) uniform PSBlock {\n");
WRITE(p, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS)); WRITE(p, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
@ -639,13 +641,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "%sfloat4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS)); WRITE(p, "%sfloat4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS));
WRITE(p, "%sfloat4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS)); WRITE(p, "%sfloat4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n"); WRITE(p, "};\n");
if(ApiType != API_GLSL) if (ApiType != API_GLSL)
{ {
WRITE(p, "void main(\n"); WRITE(p, "void main(\n");
if(ApiType != API_D3D11) if (ApiType != API_D3D11)
{ {
WRITE(p, " out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n", WRITE(p, " out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "", dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
@ -693,7 +695,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// Once we switch to GLSL 1.3 we will bind a lot of these. // Once we switch to GLSL 1.3 we will bind a lot of these.
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{ {
// This won't get hit unless we support GL 3.3 // This won't get hit unless we support GL 3.3
WRITE(p, " layout(location = 0) out float4 ocol0;\n"); WRITE(p, " layout(location = 0) out float4 ocol0;\n");
@ -703,7 +705,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{ {
WRITE(p, " float4 ocol0;\n"); WRITE(p, " float4 ocol0;\n");
} }
if(DepthTextureEnable) if (DepthTextureEnable)
WRITE(p, " float depth;\n"); // TODO: Passed to Vertex Shader right? WRITE(p, " float depth;\n"); // TODO: Passed to Vertex Shader right?
WRITE(p, " float4 rawpos = gl_FragCoord;\n"); WRITE(p, " float4 rawpos = gl_FragCoord;\n");
@ -716,13 +718,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numTexgen; ++i) for (int i = 0; i < numTexgen; ++i)
WRITE(p, " float3 uv%d = gl_TexCoord[%d].xyz;\n", i, i); WRITE(p, " float3 uv%d = gl_TexCoord[%d].xyz;\n", i, i);
WRITE(p, " float4 clipPos = gl_TexCoord[%d];\n", numTexgen); WRITE(p, " float4 clipPos = gl_TexCoord[%d];\n", numTexgen);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " float4 Normal = gl_TexCoord[%d];\n", numTexgen + 1); WRITE(p, " float4 Normal = gl_TexCoord[%d];\n", numTexgen + 1);
} }
else else
{ {
// wpos is in w of first 4 texcoords // wpos is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{ {
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
WRITE(p, " float4 uv%d = gl_TexCoord[%d];\n", i, i); WRITE(p, " float4 uv%d = gl_TexCoord[%d];\n", i, i);
@ -767,7 +769,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
" float4 cc2=float4(0.0f,0.0f,0.0f,0.0f), cprev=float4(0.0f,0.0f,0.0f,0.0f);\n" " float4 cc2=float4(0.0f,0.0f,0.0f,0.0f), cprev=float4(0.0f,0.0f,0.0f,0.0f);\n"
" float4 crastemp=float4(0.0f,0.0f,0.0f,0.0f),ckonsttemp=float4(0.0f,0.0f,0.0f,0.0f);\n\n"); " float4 crastemp=float4(0.0f,0.0f,0.0f,0.0f),ckonsttemp=float4(0.0f,0.0f,0.0f,0.0f);\n\n");
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{ {
if (xfregs.numTexGen.numTexGens < 7) if (xfregs.numTexGen.numTexGens < 7)
{ {
@ -814,7 +816,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
} }
// indirect texture map lookup // indirect texture map lookup
for(u32 i = 0; i < bpmem.genMode.numindstages; ++i) for (u32 i = 0; i < bpmem.genMode.numindstages; ++i)
{ {
if (nIndirectStagesUsed & (1<<i)) if (nIndirectStagesUsed & (1<<i))
{ {
@ -834,7 +836,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numStages; i++) for (int i = 0; i < numStages; i++)
WriteStage(p, i, ApiType); //build the equation for this stage WriteStage(p, i, ApiType); //build the equation for this stage
if(numStages) if (numStages)
{ {
// The results of the last texenv stage are put onto the screen, // The results of the last texenv stage are put onto the screen,
// regardless of the used destination register // regardless of the used destination register
@ -850,25 +852,25 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// alpha test will always fail, so restart the shader and just make it an empty function // alpha test will always fail, so restart the shader and just make it an empty function
p = pmainstart; p = pmainstart;
WRITE(p, "ocol0 = vec4(0.0f);\n"); WRITE(p, "ocol0 = vec4(0.0f);\n");
if(DepthTextureEnable) if (DepthTextureEnable)
WRITE(p, "depth = 1.f;\n"); WRITE(p, "depth = 1.f;\n");
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = vec4(0.0f);\n"); WRITE(p, "ocol1 = vec4(0.0f);\n");
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
// Once we switch to GLSL 1.3 and bind variables, we won't need to do this // Once we switch to GLSL 1.3 and bind variables, we won't need to do this
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND) if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n"); WRITE(p, "gl_FragData[0] = ocol0;\n");
if(DepthTextureEnable) if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n"); WRITE(p, "gl_FragDepth = depth;\n");
} }
WRITE(p, "discard;\n"); WRITE(p, "discard;\n");
if(ApiType != API_D3D11) if (ApiType != API_D3D11)
WRITE(p, "return;\n"); WRITE(p, "return;\n");
} }
else else
{ {
if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable) if ((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable)
{ {
// the screen space depth value = far z + (clip z / clip w) * z range // the screen space depth value = far z + (clip z / clip w) * z range
@ -911,9 +913,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n");
} }
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
if(DepthTextureEnable) if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n"); WRITE(p, "gl_FragDepth = depth;\n");
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND) if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n"); WRITE(p, "gl_FragData[0] = ocol0;\n");
@ -1060,7 +1062,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC; TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC;
// blah1 // blah1
if(cc.a == TEVCOLORARG_RASA || cc.a == TEVCOLORARG_RASC if (cc.a == TEVCOLORARG_RASA || cc.a == TEVCOLORARG_RASC
|| cc.b == TEVCOLORARG_RASA || cc.b == TEVCOLORARG_RASC || cc.b == TEVCOLORARG_RASA || cc.b == TEVCOLORARG_RASC
|| cc.c == TEVCOLORARG_RASA || cc.c == TEVCOLORARG_RASC || cc.c == TEVCOLORARG_RASA || cc.c == TEVCOLORARG_RASC
|| cc.d == TEVCOLORARG_RASA || cc.d == TEVCOLORARG_RASC || cc.d == TEVCOLORARG_RASA || cc.d == TEVCOLORARG_RASC
@ -1075,10 +1077,10 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (bpmem.tevorders[n/2].getEnable(n&1)) if (bpmem.tevorders[n/2].getEnable(n&1))
{ {
if(!bHasIndStage) if (!bHasIndStage)
{ {
// calc tevcord // calc tevcord
if(bHasTexCoord) if (bHasTexCoord)
WRITE(p, "tevcoord.xy = uv%d.xy;\n", texcoord); WRITE(p, "tevcoord.xy = uv%d.xy;\n", texcoord);
else else
WRITE(p, "tevcoord.xy = float2(0.0f, 0.0f);\n"); WRITE(p, "tevcoord.xy = float2(0.0f, 0.0f);\n");
@ -1099,7 +1101,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
int kc = bpmem.tevksel[n / 2].getKC(n & 1); int kc = bpmem.tevksel[n / 2].getKC(n & 1);
int ka = bpmem.tevksel[n / 2].getKA(n & 1); int ka = bpmem.tevksel[n / 2].getKA(n & 1);
WRITE(p, "konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]); WRITE(p, "konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]);
if(kc > 7 || ka > 7) if (kc > 7 || ka > 7)
{ {
WRITE(p, "ckonsttemp = frac(konsttemp * (255.0f/256.0f)) * (256.0f/255.0f);\n"); WRITE(p, "ckonsttemp = frac(konsttemp * (255.0f/256.0f)) * (256.0f/255.0f);\n");
} }
@ -1150,7 +1152,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (cc.shift > TEVSCALE_1) if (cc.shift > TEVSCALE_1)
WRITE(p, "%s*(", tevScaleTable[cc.shift]); WRITE(p, "%s*(", tevScaleTable[cc.shift]);
if(!(cc.d == TEVCOLORARG_ZERO && cc.op == TEVOP_ADD)) if (!(cc.d == TEVCOLORARG_ZERO && cc.op == TEVOP_ADD))
WRITE(p, "%s%s", tevCInputTable[cc.d], tevOpTable[cc.op]); WRITE(p, "%s%s", tevCInputTable[cc.d], tevOpTable[cc.op]);
if (cc.a == cc.b) if (cc.a == cc.b)
@ -1197,7 +1199,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (ac.shift > TEVSCALE_1) if (ac.shift > TEVSCALE_1)
WRITE(p, "%s*(", tevScaleTable[ac.shift]); WRITE(p, "%s*(", tevScaleTable[ac.shift]);
if(!(ac.d == TEVALPHAARG_ZERO && ac.op == TEVOP_ADD)) if (!(ac.d == TEVALPHAARG_ZERO && ac.op == TEVOP_ADD))
WRITE(p, "%s.a%s", tevAInputTable[ac.d], tevOpTable[ac.op]); WRITE(p, "%s.a%s", tevAInputTable[ac.d], tevOpTable[ac.op]);
if (ac.a == ac.b) if (ac.a == ac.b)
@ -1213,7 +1215,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
WRITE(p, "%s",tevBiasTable[ac.bias]); WRITE(p, "%s",tevBiasTable[ac.bias]);
if (ac.shift>0) if (ac.shift > 0)
WRITE(p, ")"); WRITE(p, ")");
} }
@ -1303,7 +1305,7 @@ static bool WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
}; };
int Pretest = AlphaPreTest(); int Pretest = AlphaPreTest();
if(Pretest >= 0) if (Pretest >= 0)
{ {
return Pretest != 0; return Pretest != 0;
} }
@ -1339,7 +1341,8 @@ static const char *tevFogFuncsTable[] =
static void WriteFog(char *&p) static void WriteFog(char *&p)
{ {
if(bpmem.fog.c_proj_fsel.fsel == 0)return;//no Fog if (bpmem.fog.c_proj_fsel.fsel == 0)
return; // no Fog
if (bpmem.fog.c_proj_fsel.proj == 0) if (bpmem.fog.c_proj_fsel.proj == 0)
{ {
@ -1357,7 +1360,7 @@ static void WriteFog(char *&p)
// x_adjust = sqrt((x-center)^2 + k^2)/k // x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust // ze *= x_adjust
//this is complitly teorical as the real hard seems to use a table intead of calculate the values. //this is complitly teorical as the real hard seems to use a table intead of calculate the values.
if(bpmem.fogRange.Base.Enabled) if (bpmem.fogRange.Base.Enabled)
{ {
WRITE (p, " float x_adjust = (2.0f * (clipPos.x / "I_FOG"[2].y)) - 1.0f - "I_FOG"[2].x;\n"); WRITE (p, " float x_adjust = (2.0f * (clipPos.x / "I_FOG"[2].y)) - 1.0f - "I_FOG"[2].x;\n");
WRITE (p, " x_adjust = sqrt(x_adjust * x_adjust + "I_FOG"[2].z * "I_FOG"[2].z) / "I_FOG"[2].z;\n"); WRITE (p, " x_adjust = sqrt(x_adjust * x_adjust + "I_FOG"[2].z * "I_FOG"[2].z) / "I_FOG"[2].z;\n");
@ -1366,17 +1369,15 @@ static void WriteFog(char *&p)
WRITE (p, " float fog = saturate(ze - "I_FOG"[1].z);\n"); WRITE (p, " float fog = saturate(ze - "I_FOG"[1].z);\n");
if(bpmem.fog.c_proj_fsel.fsel > 3) if (bpmem.fog.c_proj_fsel.fsel > 3)
{ {
WRITE(p, "%s", tevFogFuncsTable[bpmem.fog.c_proj_fsel.fsel]); WRITE(p, "%s", tevFogFuncsTable[bpmem.fog.c_proj_fsel.fsel]);
} }
else else
{ {
if(bpmem.fog.c_proj_fsel.fsel != 2) if (bpmem.fog.c_proj_fsel.fsel != 2)
WARN_LOG(VIDEO, "Unknown Fog Type! %08x", bpmem.fog.c_proj_fsel.fsel); WARN_LOG(VIDEO, "Unknown Fog Type! %08x", bpmem.fog.c_proj_fsel.fsel);
} }
WRITE(p, " prev.rgb = lerp(prev.rgb,"I_FOG"[0].rgb,fog);\n"); WRITE(p, " prev.rgb = lerp(prev.rgb,"I_FOG"[0].rgb,fog);\n");
} }

View File

@ -66,17 +66,19 @@ u16 GetEncodedSampleCount(u32 format)
default: return 1; default: return 1;
} }
} }
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num) const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{ {
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
return ""; // Once we switch to GLSL 1.3 we can do something here return ""; // Once we switch to GLSL 1.3 we can do something here
static char result[64]; static char result[64];
sprintf(result, " : register(%s%d)", prefix, num); sprintf(result, " : register(%s%d)", prefix, num);
return result; return result;
} }
const char *WriteLocation(API_TYPE ApiType) const char *WriteLocation(API_TYPE ApiType)
{ {
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return ""; return "";
static char result[64]; static char result[64];
sprintf(result, "uniform "); sprintf(result, "uniform ");
@ -90,12 +92,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture // [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels // [1] width and height of destination texture in pixels
// Two were merged for GLSL // Two were merged for GLSL
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : ""); WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS)); WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n"); WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format); float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
@ -122,7 +124,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
} }
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
WRITE(p, " float4 ocol0;\n"); WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n"); WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -131,7 +133,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
else else
{ {
WRITE(p,"void main(\n"); WRITE(p,"void main(\n");
if(ApiType != API_D3D11) if (ApiType != API_D3D11)
{ {
WRITE(p," out float4 ocol0 : COLOR0,\n"); WRITE(p," out float4 ocol0 : COLOR0,\n");
} }
@ -163,12 +165,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n"); WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
if(ApiType == API_OPENGL || ApiType == API_GLSL) if (ApiType == API_OPENGL || ApiType == API_GLSL)
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n"); WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n"); WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
if(ApiType != API_OPENGL && ApiType != API_GLSL) if (ApiType != API_OPENGL && ApiType != API_GLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n"); WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
@ -182,17 +184,17 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture // [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels // [1] width and height of destination texture in pixels
// Two were merged for GLSL // Two were merged for GLSL
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : ""); WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS)); WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n"); WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format); float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format); float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
// 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments // 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
if(ApiType == API_OPENGL) if (ApiType == API_OPENGL)
{ {
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n"); WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
} }
@ -212,7 +214,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, "Texture2D Tex0 : register(t0);\n"); WRITE(p, "Texture2D Tex0 : register(t0);\n");
} }
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
WRITE(p, " float4 ocol0;\n"); WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n"); WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -250,17 +252,16 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " float xib = x2 - (xl * %f);\n", blkW); WRITE(p, " float xib = x2 - (xl * %f);\n", blkW);
WRITE(p, " float halfxb = floor(xb / 2);\n"); WRITE(p, " float halfxb = floor(xb / 2);\n");
WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW); WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW);
WRITE(p, " sampleUv.y = yb + xoff;\n"); WRITE(p, " sampleUv.y = yb + xoff;\n");
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n"); WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
if(ApiType == API_OPENGL || ApiType == API_GLSL) if (ApiType == API_OPENGL || ApiType == API_GLSL)
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n"); WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n"); WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
if(ApiType != API_OPENGL && ApiType != API_GLSL) if (ApiType != API_OPENGL && ApiType != API_GLSL)
{ {
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n"); WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
@ -281,7 +282,7 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
// the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX. // the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX.
const char* texSampleIncrementUnit; const char* texSampleIncrementUnit;
if(ApiType != API_OPENGL || ApiType != API_GLSL) if (ApiType != API_OPENGL || ApiType != API_GLSL)
texSampleIncrementUnit = I_COLORS"[0].x / "I_COLORS"[0].z"; texSampleIncrementUnit = I_COLORS"[0].x / "I_COLORS"[0].z";
else else
texSampleIncrementUnit = I_COLORS"[0].x"; texSampleIncrementUnit = I_COLORS"[0].x";
@ -292,7 +293,7 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
void WriteColorToIntensity(char*& p, const char* src, const char* dest) void WriteColorToIntensity(char*& p, const char* src, const char* dest)
{ {
if(!IntensityConstantAdded) if (!IntensityConstantAdded)
{ {
WRITE(p, " float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n"); WRITE(p, " float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n");
IntensityConstantAdded = true; IntensityConstantAdded = true;
@ -328,7 +329,7 @@ void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
void WriteEncoderEnd(char* p, API_TYPE ApiType) void WriteEncoderEnd(char* p, API_TYPE ApiType)
{ {
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
WRITE(p, "gl_FragData[0] = ocol0;\n"); WRITE(p, "gl_FragData[0] = ocol0;\n");
WRITE(p, "}\n"); WRITE(p, "}\n");
IntensityConstantAdded = false; IntensityConstantAdded = false;
@ -337,22 +338,22 @@ void WriteEncoderEnd(char* p, API_TYPE ApiType)
void WriteI8Encoder(char* p, API_TYPE ApiType) void WriteI8Encoder(char* p, API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_I8,ApiType); WriteSwizzler(p, GX_TF_I8, ApiType);
WRITE(p, " float3 texSample;\n"); WRITE(p, " float3 texSample;\n");
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.b"); WriteColorToIntensity(p, "texSample", "ocol0.b");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.g"); WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.r"); WriteColorToIntensity(p, "texSample", "ocol0.r");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.a"); WriteColorToIntensity(p, "texSample", "ocol0.a");
WRITE(p, " ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity WRITE(p, " ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity
@ -362,40 +363,40 @@ void WriteI8Encoder(char* p, API_TYPE ApiType)
void WriteI4Encoder(char* p, API_TYPE ApiType) void WriteI4Encoder(char* p, API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_I4,ApiType); WriteSwizzler(p, GX_TF_I4, ApiType);
WRITE(p, " float3 texSample;\n"); WRITE(p, " float3 texSample;\n");
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.b"); WriteColorToIntensity(p, "texSample", "color0.b");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.b"); WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.g"); WriteColorToIntensity(p, "texSample", "color0.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.g"); WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.r"); WriteColorToIntensity(p, "texSample", "color0.r");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.r"); WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.a"); WriteColorToIntensity(p, "texSample", "color0.a");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType); WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.a"); WriteColorToIntensity(p, "texSample", "color1.a");
WRITE(p, " color0.rgba += IntensityConst.aaaa;\n"); WRITE(p, " color0.rgba += IntensityConst.aaaa;\n");
@ -410,15 +411,15 @@ void WriteI4Encoder(char* p, API_TYPE ApiType)
void WriteIA8Encoder(char* p,API_TYPE ApiType) void WriteIA8Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_IA8,ApiType); WriteSwizzler(p, GX_TF_IA8, ApiType);
WRITE(p, " float4 texSample;\n"); WRITE(p, " float4 texSample;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " ocol0.b = texSample.a;\n"); WRITE(p, " ocol0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.g"); WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " ocol0.r = texSample.a;\n"); WRITE(p, " ocol0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.a"); WriteColorToIntensity(p, "texSample", "ocol0.a");
@ -429,27 +430,27 @@ void WriteIA8Encoder(char* p,API_TYPE ApiType)
void WriteIA4Encoder(char* p,API_TYPE ApiType) void WriteIA4Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_IA4,ApiType); WriteSwizzler(p, GX_TF_IA4, ApiType);
WRITE(p, " float4 texSample;\n"); WRITE(p, " float4 texSample;\n");
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n"); WRITE(p, " color0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.b"); WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.g = texSample.a;\n"); WRITE(p, " color0.g = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.g"); WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.r = texSample.a;\n"); WRITE(p, " color0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.r"); WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.a = texSample.a;\n"); WRITE(p, " color0.a = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.a"); WriteColorToIntensity(p, "texSample", "color1.a");
@ -464,11 +465,11 @@ void WriteIA4Encoder(char* p,API_TYPE ApiType)
void WriteRGB565Encoder(char* p,API_TYPE ApiType) void WriteRGB565Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_RGB565,ApiType); WriteSwizzler(p, GX_TF_RGB565, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0",ApiType); WriteSampleColor(p, "rgb", "float3 texSample0", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1",ApiType); WriteSampleColor(p, "rgb", "float3 texSample1", ApiType);
WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n"); WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n");
WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\n"); WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\n");
WRITE(p, " float2 texBs = float2(texSample0.b, texSample1.b);\n"); WRITE(p, " float2 texBs = float2(texSample0.b, texSample1.b);\n");
@ -488,14 +489,14 @@ void WriteRGB565Encoder(char* p,API_TYPE ApiType)
void WriteRGB5A3Encoder(char* p,API_TYPE ApiType) void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_RGB5A3,ApiType); WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
WRITE(p, " float4 texSample;\n"); WRITE(p, " float4 texSample;\n");
WRITE(p, " float color0;\n"); WRITE(p, " float color0;\n");
WRITE(p, " float gUpper;\n"); WRITE(p, " float gUpper;\n");
WRITE(p, " float gLower;\n"); WRITE(p, " float gLower;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
// 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits // 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
WRITE(p, "if(texSample.a > 0.878f) {\n"); WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -522,9 +523,9 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
WRITE(p, "}\n"); WRITE(p, "}\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, "if(texSample.a > 0.878f) {\n"); WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -555,21 +556,21 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
void WriteRGBA4443Encoder(char* p,API_TYPE ApiType) void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_RGB5A3,ApiType); WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
WRITE(p, " float4 texSample;\n"); WRITE(p, " float4 texSample;\n");
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.b"); WriteToBitDepth(p, 3, "texSample.a", "color0.b");
WriteToBitDepth(p, 4, "texSample.r", "color1.b"); WriteToBitDepth(p, 4, "texSample.r", "color1.b");
WriteToBitDepth(p, 4, "texSample.g", "color0.g"); WriteToBitDepth(p, 4, "texSample.g", "color0.g");
WriteToBitDepth(p, 4, "texSample.b", "color1.g"); WriteToBitDepth(p, 4, "texSample.b", "color1.g");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.r"); WriteToBitDepth(p, 3, "texSample.a", "color0.r");
WriteToBitDepth(p, 4, "texSample.r", "color1.r"); WriteToBitDepth(p, 4, "texSample.r", "color1.r");
WriteToBitDepth(p, 4, "texSample.g", "color0.a"); WriteToBitDepth(p, 4, "texSample.g", "color0.a");
@ -581,7 +582,7 @@ void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
void WriteRGBA8Encoder(char* p,API_TYPE ApiType) void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
{ {
Write32BitSwizzler(p, GX_TF_RGBA8,ApiType); Write32BitSwizzler(p, GX_TF_RGBA8, ApiType);
WRITE(p, " float cl1 = xb - (halfxb * 2);\n"); WRITE(p, " float cl1 = xb - (halfxb * 2);\n");
WRITE(p, " float cl0 = 1.0f - cl1;\n"); WRITE(p, " float cl0 = 1.0f - cl1;\n");
@ -590,15 +591,15 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n"); WRITE(p, " color0.b = texSample.a;\n");
WRITE(p, " color0.g = texSample.r;\n"); WRITE(p, " color0.g = texSample.r;\n");
WRITE(p, " color1.b = texSample.g;\n"); WRITE(p, " color1.b = texSample.g;\n");
WRITE(p, " color1.g = texSample.b;\n"); WRITE(p, " color1.g = texSample.b;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType); WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.r = texSample.a;\n"); WRITE(p, " color0.r = texSample.a;\n");
WRITE(p, " color0.a = texSample.r;\n"); WRITE(p, " color0.a = texSample.r;\n");
WRITE(p, " color1.r = texSample.g;\n"); WRITE(p, " color1.r = texSample.g;\n");
@ -611,32 +612,32 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType) void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_R4,ApiType); WriteSwizzler(p, GX_CTF_R4, ApiType);
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "color0.b",ApiType); WriteSampleColor(p, comp, "color0.b", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.b",ApiType); WriteSampleColor(p, comp, "color1.b", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.g",ApiType); WriteSampleColor(p, comp, "color0.g", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.g",ApiType); WriteSampleColor(p, comp, "color1.g", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.r",ApiType); WriteSampleColor(p, comp, "color0.r", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.r",ApiType); WriteSampleColor(p, comp, "color1.r", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.a",ApiType); WriteSampleColor(p, comp, "color0.a", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.a",ApiType); WriteSampleColor(p, comp, "color1.a", ApiType);
WriteToBitDepth(p, 4, "color0", "color0"); WriteToBitDepth(p, 4, "color0", "color0");
WriteToBitDepth(p, 4, "color1", "color1"); WriteToBitDepth(p, 4, "color1", "color1");
@ -647,45 +648,45 @@ void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType) void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_R8,ApiType); WriteSwizzler(p, GX_CTF_R8, ApiType);
WriteSampleColor(p, comp, "ocol0.b",ApiType); WriteSampleColor(p, comp, "ocol0.b", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.g",ApiType); WriteSampleColor(p, comp, "ocol0.g", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.r",ApiType); WriteSampleColor(p, comp, "ocol0.r", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.a",ApiType); WriteSampleColor(p, comp, "ocol0.a", ApiType);
WriteEncoderEnd(p, ApiType); WriteEncoderEnd(p, ApiType);
} }
void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType) void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_RA4,ApiType); WriteSwizzler(p, GX_CTF_RA4, ApiType);
WRITE(p, " float2 texSample;\n"); WRITE(p, " float2 texSample;\n");
WRITE(p, " float4 color0;\n"); WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n"); WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "texSample",ApiType); WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.b = texSample.x;\n"); WRITE(p, " color0.b = texSample.x;\n");
WRITE(p, " color1.b = texSample.y;\n"); WRITE(p, " color1.b = texSample.y;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType); WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.g = texSample.x;\n"); WRITE(p, " color0.g = texSample.x;\n");
WRITE(p, " color1.g = texSample.y;\n"); WRITE(p, " color1.g = texSample.y;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType); WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.r = texSample.x;\n"); WRITE(p, " color0.r = texSample.x;\n");
WRITE(p, " color1.r = texSample.y;\n"); WRITE(p, " color1.r = texSample.y;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType); WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.a = texSample.x;\n"); WRITE(p, " color0.a = texSample.x;\n");
WRITE(p, " color1.a = texSample.y;\n"); WRITE(p, " color1.a = texSample.y;\n");
@ -698,35 +699,35 @@ void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType) void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_RA8,ApiType); WriteSwizzler(p, GX_CTF_RA8, ApiType);
WriteSampleColor(p, comp, "ocol0.bg",ApiType); WriteSampleColor(p, comp, "ocol0.bg", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.ra",ApiType); WriteSampleColor(p, comp, "ocol0.ra", ApiType);
WriteEncoderEnd(p, ApiType); WriteEncoderEnd(p, ApiType);
} }
void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType) void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_Z8M,ApiType); WriteSwizzler(p, GX_CTF_Z8M, ApiType);
WRITE(p, " float depth;\n"); WRITE(p, " float depth;\n");
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier); WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier); WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier); WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier); WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);
WriteEncoderEnd(p, ApiType); WriteEncoderEnd(p, ApiType);
@ -734,14 +735,14 @@ void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
void WriteZ16Encoder(char* p,API_TYPE ApiType) void WriteZ16Encoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_TF_Z16,ApiType); WriteSwizzler(p, GX_TF_Z16, ApiType);
WRITE(p, " float depth;\n"); WRITE(p, " float depth;\n");
WRITE(p, " float3 expanded;\n"); WRITE(p, " float3 expanded;\n");
// byte order is reversed // byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n"); WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n"); WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -751,9 +752,9 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.g / 255;\n"); WRITE(p, " ocol0.b = expanded.g / 255;\n");
WRITE(p, " ocol0.g = expanded.r / 255;\n"); WRITE(p, " ocol0.g = expanded.r / 255;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n"); WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n"); WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -768,14 +769,14 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
void WriteZ16LEncoder(char* p,API_TYPE ApiType) void WriteZ16LEncoder(char* p,API_TYPE ApiType)
{ {
WriteSwizzler(p, GX_CTF_Z16L,ApiType); WriteSwizzler(p, GX_CTF_Z16L, ApiType);
WRITE(p, " float depth;\n"); WRITE(p, " float depth;\n");
WRITE(p, " float3 expanded;\n"); WRITE(p, " float3 expanded;\n");
// byte order is reversed // byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n"); WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n"); WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -787,9 +788,9 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.b / 255;\n"); WRITE(p, " ocol0.b = expanded.b / 255;\n");
WRITE(p, " ocol0.g = expanded.g / 255;\n"); WRITE(p, " ocol0.g = expanded.g / 255;\n");
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType); WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n"); WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n"); WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -806,7 +807,7 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
void WriteZ24Encoder(char* p, API_TYPE ApiType) void WriteZ24Encoder(char* p, API_TYPE ApiType)
{ {
Write32BitSwizzler(p, GX_TF_Z24X8,ApiType); Write32BitSwizzler(p, GX_TF_Z24X8, ApiType);
WRITE(p, " float cl = xb - (halfxb * 2);\n"); WRITE(p, " float cl = xb - (halfxb * 2);\n");
@ -815,9 +816,9 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
WRITE(p, " float3 expanded0;\n"); WRITE(p, " float3 expanded0;\n");
WRITE(p, " float3 expanded1;\n"); WRITE(p, " float3 expanded1;\n");
WriteSampleColor(p, "b", "depth0",ApiType); WriteSampleColor(p, "b", "depth0", ApiType);
WriteIncrementSampleX(p,ApiType); WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth1",ApiType); WriteSampleColor(p, "b", "depth1", ApiType);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@ -854,7 +855,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
char *p = text; char *p = text;
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
// A few required defines and ones that will make our lives a lot easier // A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -881,76 +882,76 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n"); WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n");
} }
switch(format) switch (format)
{ {
case GX_TF_I4: case GX_TF_I4:
WriteI4Encoder(p,ApiType); WriteI4Encoder(p, ApiType);
break; break;
case GX_TF_I8: case GX_TF_I8:
WriteI8Encoder(p,ApiType); WriteI8Encoder(p, ApiType);
break; break;
case GX_TF_IA4: case GX_TF_IA4:
WriteIA4Encoder(p,ApiType); WriteIA4Encoder(p, ApiType);
break; break;
case GX_TF_IA8: case GX_TF_IA8:
WriteIA8Encoder(p,ApiType); WriteIA8Encoder(p, ApiType);
break; break;
case GX_TF_RGB565: case GX_TF_RGB565:
WriteRGB565Encoder(p,ApiType); WriteRGB565Encoder(p, ApiType);
break; break;
case GX_TF_RGB5A3: case GX_TF_RGB5A3:
WriteRGB5A3Encoder(p,ApiType); WriteRGB5A3Encoder(p, ApiType);
break; break;
case GX_TF_RGBA8: case GX_TF_RGBA8:
WriteRGBA8Encoder(p,ApiType); WriteRGBA8Encoder(p, ApiType);
break; break;
case GX_CTF_R4: case GX_CTF_R4:
WriteC4Encoder(p, "r",ApiType); WriteC4Encoder(p, "r", ApiType);
break; break;
case GX_CTF_RA4: case GX_CTF_RA4:
WriteCC4Encoder(p, "ar",ApiType); WriteCC4Encoder(p, "ar", ApiType);
break; break;
case GX_CTF_RA8: case GX_CTF_RA8:
WriteCC8Encoder(p, "ar",ApiType); WriteCC8Encoder(p, "ar", ApiType);
break; break;
case GX_CTF_A8: case GX_CTF_A8:
WriteC8Encoder(p, "a",ApiType); WriteC8Encoder(p, "a", ApiType);
break; break;
case GX_CTF_R8: case GX_CTF_R8:
WriteC8Encoder(p, "r",ApiType); WriteC8Encoder(p, "r", ApiType);
break; break;
case GX_CTF_G8: case GX_CTF_G8:
WriteC8Encoder(p, "g",ApiType); WriteC8Encoder(p, "g", ApiType);
break; break;
case GX_CTF_B8: case GX_CTF_B8:
WriteC8Encoder(p, "b",ApiType); WriteC8Encoder(p, "b", ApiType);
break; break;
case GX_CTF_RG8: case GX_CTF_RG8:
WriteCC8Encoder(p, "rg",ApiType); WriteCC8Encoder(p, "rg", ApiType);
break; break;
case GX_CTF_GB8: case GX_CTF_GB8:
WriteCC8Encoder(p, "gb",ApiType); WriteCC8Encoder(p, "gb", ApiType);
break; break;
case GX_TF_Z8: case GX_TF_Z8:
WriteC8Encoder(p, "b",ApiType); WriteC8Encoder(p, "b", ApiType);
break; break;
case GX_TF_Z16: case GX_TF_Z16:
WriteZ16Encoder(p,ApiType); WriteZ16Encoder(p, ApiType);
break; break;
case GX_TF_Z24X8: case GX_TF_Z24X8:
WriteZ24Encoder(p,ApiType); WriteZ24Encoder(p, ApiType);
break; break;
case GX_CTF_Z4: case GX_CTF_Z4:
WriteC4Encoder(p, "b",ApiType); WriteC4Encoder(p, "b", ApiType);
break; break;
case GX_CTF_Z8M: case GX_CTF_Z8M:
WriteZ8Encoder(p, "256.0f",ApiType); WriteZ8Encoder(p, "256.0f", ApiType);
break; break;
case GX_CTF_Z8L: case GX_CTF_Z8L:
WriteZ8Encoder(p, "65536.0f" ,ApiType); WriteZ8Encoder(p, "65536.0f" , ApiType);
break; break;
case GX_CTF_Z16L: case GX_CTF_Z16L:
WriteZ16LEncoder(p,ApiType); WriteZ16LEncoder(p, ApiType);
break; break;
default: default:
PanicAlert("Unknown texture copy format: 0x%x\n", format); PanicAlert("Unknown texture copy format: 0x%x\n", format);

View File

@ -185,7 +185,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
char *p = text; char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components); WRITE(p, "//Vertex Shader: comp:%x, \n", components);
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
// A few required defines and ones that will make our lives a lot easier // A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -204,7 +204,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "#define ATTRIN attribute\n"); WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n"); WRITE(p, "#define ATTROUT attribute\n");
} }
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n"); WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences // Silly differences
WRITE(p, "#define float2 vec2\n"); WRITE(p, "#define float2 vec2\n");
@ -218,7 +218,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
} }
// uniforms // uniforms
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform VSBlock {\n"); WRITE(p, "layout(std140) uniform VSBlock {\n");
WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX)); WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
@ -231,11 +231,10 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES)); WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS)); WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n"); WRITE(p, "};\n");
p = GenerateVSOutputStruct(p, components, ApiType); p = GenerateVSOutputStruct(p, components, ApiType);
if(ApiType == API_GLSL) if(ApiType == API_GLSL)
@ -243,7 +242,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (components & VB_HAS_NRM0) if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n"); WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{ {
if (components & VB_HAS_POSMTXIDX) if (components & VB_HAS_POSMTXIDX)
WRITE(p, "layout(location = %d) ATTRIN float fposmtx;\n", SHADER_POSMTX_ATTRIB); WRITE(p, "layout(location = %d) ATTRIN float fposmtx;\n", SHADER_POSMTX_ATTRIB);
@ -277,7 +276,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
} }
else else
{ {
WRITE(p, "VS_OUTPUT main(\n"); WRITE(p, "VS_OUTPUT main(\n");
// inputs // inputs
@ -306,9 +304,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
} }
if (components & VB_HAS_POSMTXIDX) { if (components & VB_HAS_POSMTXIDX) {
if (is_d3d) if (is_d3d)
{
WRITE(p, " float4 blend_indices : BLENDINDICES,\n"); WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
}
else else
WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB); WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
} }
@ -369,7 +365,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
"float3 ldir, h;\n" "float3 ldir, h;\n"
"float dist, dist2, attn;\n"); "float dist, dist2, attn;\n");
if(xfregs.numChan.numColorChans == 0) if (xfregs.numChan.numColorChans == 0)
{ {
if (components & VB_HAS_COL0) if (components & VB_HAS_COL0)
WRITE(p, "o.colors_0 = color0;\n"); WRITE(p, "o.colors_0 = color0;\n");
@ -380,7 +376,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
// TODO: This probably isn't necessary if pixel lighting is enabled. // TODO: This probably isn't necessary if pixel lighting is enabled.
p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_"); p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
if(xfregs.numChan.numColorChans < 2) if (xfregs.numChan.numColorChans < 2)
{ {
if (components & VB_HAS_COL1) if (components & VB_HAS_COL1)
WRITE(p, "o.colors_1 = color1;\n"); WRITE(p, "o.colors_1 = color1;\n");
@ -570,7 +566,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
//seems to get rather complicated //seems to get rather complicated
} }
if(ApiType == API_GLSL) if (ApiType == API_GLSL)
{ {
// Bit ugly here // Bit ugly here
// Will look better when we bind uniforms in GLSL 1.3 // Will look better when we bind uniforms in GLSL 1.3
@ -584,7 +580,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1); WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
} else { } else {
// clip position is in w of first 4 texcoords // clip position is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{ {
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i); WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
@ -603,7 +599,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
else else
WRITE(p, "return o;\n}\n"); WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C) if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!"); PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
setlocale(LC_NUMERIC, ""); // restore locale setlocale(LC_NUMERIC, ""); // restore locale

View File

@ -20,7 +20,6 @@
#include "GLUtil.h" #include "GLUtil.h"
#include <cmath> #include <cmath>
#include <assert.h>
#include "Statistics.h" #include "Statistics.h"
#include "VideoConfig.h" #include "VideoConfig.h"
@ -51,9 +50,9 @@ bool PixelShaderCache::ShaderEnabled;
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL; PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
PIXELSHADERUID PixelShaderCache::last_uid; PIXELSHADERUID PixelShaderCache::last_uid;
void(*pSetPSConstant4f)(unsigned int, float, float, float, float); void (*pSetPSConstant4f)(unsigned int, float, float, float, float);
void(*pSetPSConstant4fv)(unsigned int, const float*); void (*pSetPSConstant4fv)(unsigned int, const float*);
void(*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*); void (*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
bool (*pCompilePixelShader)(FRAGMENTSHADER&, const char*); bool (*pCompilePixelShader)(FRAGMENTSHADER&, const char*);
GLuint PixelShaderCache::GetDepthMatrixProgram() GLuint PixelShaderCache::GetDepthMatrixProgram()
@ -65,6 +64,7 @@ GLuint PixelShaderCache::GetColorMatrixProgram()
{ {
return s_ColorMatrixProgram.glprogid; return s_ColorMatrixProgram.glprogid;
} }
void PixelShaderCache::Init() void PixelShaderCache::Init()
{ {
ShaderEnabled = true; ShaderEnabled = true;
@ -74,7 +74,7 @@ void PixelShaderCache::Init()
s_displayCompileAlert = true; s_displayCompileAlert = true;
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
pSetPSConstant4f = SetGLSLPSConstant4f; pSetPSConstant4f = SetGLSLPSConstant4f;
pSetPSConstant4fv = SetGLSLPSConstant4fv; pSetPSConstant4fv = SetGLSLPSConstant4fv;
@ -92,7 +92,7 @@ void PixelShaderCache::Init()
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions); glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason. if (s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
s_nMaxPixelInstructions = 4096; s_nMaxPixelInstructions = 4096;
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096; if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
#if CG_VERSION_NUM == 2100 #if CG_VERSION_NUM == 2100
@ -106,7 +106,7 @@ void PixelShaderCache::Init()
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&maxinst); glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&maxinst);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, (GLint *)&maxattribs); glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, (GLint *)&maxattribs);
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs); INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
char pmatrixprog[2048]; char pmatrixprog[2048];
sprintf(pmatrixprog, "#version %s\n" sprintf(pmatrixprog, "#version %s\n"
@ -352,35 +352,32 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr
return pCompilePixelShader(ps, pstrprogram); return pCompilePixelShader(ps, pstrprogram);
} }
//Disable Fragment programs and reset the selected Program // Disable Fragment programs and reset the selected Program
void PixelShaderCache::DisableShader() void PixelShaderCache::DisableShader()
{ {
if(g_ActiveConfig.bUseGLSL) if (ShaderEnabled)
assert(true);
if(ShaderEnabled)
{ {
glDisable(GL_FRAGMENT_PROGRAM_ARB); glDisable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = false; ShaderEnabled = false;
} }
} }
//bind a program if is diferent from the binded oone // bind a program if is different from the binded oone
void PixelShaderCache::SetCurrentShader(GLuint Shader) void PixelShaderCache::SetCurrentShader(GLuint Shader)
{ {
if(g_ActiveConfig.bUseGLSL) if (!ShaderEnabled)
assert(true);
if(!ShaderEnabled)
{ {
glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = true; ShaderEnabled = true;
} }
if(CurrentShader != Shader) if (CurrentShader != Shader)
{ {
if(Shader != 0) if (Shader != 0)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
} }
} }
// GLSL Specific // GLSL Specific
bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{ {
@ -422,13 +419,15 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
ps.bGLSL = true; ps.bGLSL = true;
return true; return true;
} }
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
{ {
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for (int a = 0; a < NUM_UNIFORMS; ++a) for (int a = 0; a < NUM_UNIFORMS; ++a)
{
if (!strcmp(name, UniformNames[a])) if (!strcmp(name, UniformNames[a]))
{ {
if(tmp.UniformLocations[a] == -1) if (tmp.UniformLocations[a] == -1)
return; return;
else else
{ {
@ -436,6 +435,7 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
return; return;
} }
} }
}
} }
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
@ -449,7 +449,7 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
} }
for (unsigned int a = 0; a < 10; ++a) for (unsigned int a = 0; a < 10; ++a)
{ {
if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
{ {
unsigned int offset = const_number - PSVar_Loc[a].reg; unsigned int offset = const_number - PSVar_Loc[a].reg;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
@ -467,7 +467,7 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
} }
for (unsigned int a = 0; a < 10; ++a) for (unsigned int a = 0; a < 10; ++a)
{ {
if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
{ {
unsigned int offset = const_number - PSVar_Loc[a].reg; unsigned int offset = const_number - PSVar_Loc[a].reg;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
@ -493,8 +493,8 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
} }
} }
} }
// CG Specific
// CG Specific
bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{ {
GLenum err = GL_REPORT_ERROR(); GLenum err = GL_REPORT_ERROR();
@ -576,6 +576,7 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
return true; return true;
} }
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
float f[4] = { f1, f2, f3, f4 }; float f[4] = { f1, f2, f3, f4 };
@ -592,6 +593,7 @@ void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, cons
for (unsigned int i = 0; i < count; i++,f+=4) for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f); glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
} }
// Renderer functions // Renderer functions
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {

View File

@ -34,7 +34,7 @@ struct FRAGMENTSHADER
{ {
if (glprogid) if (glprogid)
{ {
if(bGLSL) if (bGLSL)
glDeleteShader(glprogid); glDeleteShader(glprogid);
else else
glDeleteProgramsARB(1, &glprogid); glDeleteProgramsARB(1, &glprogid);

View File

@ -18,19 +18,20 @@
#include "ProgramShaderCache.h" #include "ProgramShaderCache.h"
#include "MathUtil.h" #include "MathUtil.h"
#include <assert.h>
namespace OGL namespace OGL
{ {
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
GLuint ProgramShaderCache::s_ps_vs_ubo;
GLintptr ProgramShaderCache::s_vs_data_offset;
LinearDiskCache<PROGRAMUID, u8> g_program_disk_cache; GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
GLenum ProgramFormat; ProgramShaderCache::PCache ProgramShaderCache::pshaders;
GLuint ProgramShaderCache::s_ps_vs_ubo;
GLintptr ProgramShaderCache::s_vs_data_offset;
std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram; LinearDiskCache<PROGRAMUID, u8> g_program_disk_cache;
const char *UniformNames[NUM_UNIFORMS] = { GLenum ProgramFormat;
std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram;
const char *UniformNames[NUM_UNIFORMS] =
{
// SAMPLERS // SAMPLERS
"samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7", "samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7",
// PIXEL SHADER UNIFORMS // PIXEL SHADER UNIFORMS
@ -54,60 +55,63 @@ namespace OGL
I_NORMALMATRICES , I_NORMALMATRICES ,
I_POSTTRANSFORMMATRICES, I_POSTTRANSFORMMATRICES,
I_DEPTHPARAMS, I_DEPTHPARAMS,
}; };
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid) void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid)
{ {
// Dunno why this is needed when I have the binding // Dunno why this is needed when I have the binding
// points statically set in the shader source // points statically set in the shader source
// We should only need these two functions when we don't support binding but do support UBO // We should only need these two functions when we don't support binding but do support UBO
// Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64 // Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
glUniformBlockBinding( entry.program.glprogid, 0, 1 ); glUniformBlockBinding(entry.program.glprogid, 0, 1);
if(uid.uid.vsid != 0) // Some things have no vertex shader // Some things have no vertex shader
glUniformBlockBinding( entry.program.glprogid, 1, 2 ); if (uid.uid.vsid != 0)
glUniformBlockBinding(entry.program.glprogid, 1, 2);
} }
// We cache our uniform locations for now // We cache our uniform locations for now
// Once we move up to a newer version of GLSL, ~1.30 // Once we move up to a newer version of GLSL, ~1.30
// We can remove this // We can remove this
//For some reason this fails on my hardware // (Sonicadvance): For some reason this fails on my hardware
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations); //glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
//Got to do it this crappy way. // Got to do it this crappy way.
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for(int a = 8; a < NUM_UNIFORMS; ++a) for (int a = 8; a < NUM_UNIFORMS; ++a)
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]); entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding) if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
for(int a = 0; a < 8; ++a) {
for (int a = 0; a < 8; ++a)
{ {
// Still need to get sampler locations since we aren't binding them statically in the shaders // Still need to get sampler locations since we aren't binding them statically in the shaders
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]); entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
if(entry.program.UniformLocations[a] != -1) if (entry.program.UniformLocations[a] != -1)
glUniform1i(entry.program.UniformLocations[a], a); glUniform1i(entry.program.UniformLocations[a], a);
} }
}
// Need to get some attribute locations // Need to get some attribute locations
if(uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) // We have no vertex Shader if (uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{ {
// We have no vertex Shader
glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1"); glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2"); glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx"); glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
} }
} }
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS) {
{
PROGRAMUID uid; PROGRAMUID uid;
CurrentFShader = PS; CurrentFShader = PS;
CurrentVShader = VS; CurrentVShader = VS;
GetProgramShaderId(&uid, CurrentVShader, CurrentFShader); GetProgramShaderId(&uid, CurrentVShader, CurrentFShader);
if(uid.uid.id == 0) if (uid.uid.id == 0)
{ {
CurrentProgram = 0; CurrentProgram = 0;
glUseProgram(0); glUseProgram(0);
@ -126,6 +130,7 @@ namespace OGL
CurrentProgram = entry.program.glprogid; CurrentProgram = entry.program.glprogid;
return; return;
} }
PCacheEntry entry; PCacheEntry entry;
entry.program.vsid = CurrentVShader; entry.program.vsid = CurrentVShader;
entry.program.psid = CurrentFShader; entry.program.psid = CurrentFShader;
@ -134,14 +139,15 @@ namespace OGL
// Right, the program is created now // Right, the program is created now
// Let's attach everything // Let's attach everything
if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out if (entry.program.vsid != 0) // attaching zero vertex shader makes it freak out
glAttachShader(entry.program.glprogid, entry.program.vsid); glAttachShader(entry.program.glprogid, entry.program.vsid);
glAttachShader(entry.program.glprogid, entry.program.psid); glAttachShader(entry.program.glprogid, entry.program.psid);
#ifdef GLEW_VERSION_4_0
#ifdef GLEW_VERSION_4_0
if (g_ActiveConfig.backend_info.bSupportsGLSLCache) if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE); glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
#endif #endif
glLinkProgram(entry.program.glprogid); glLinkProgram(entry.program.glprogid);
@ -152,28 +158,32 @@ namespace OGL
pshaders[ShaderPair] = entry; pshaders[ShaderPair] = entry;
CurrentShaderProgram = ShaderPair; CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid; CurrentProgram = entry.program.glprogid;
} }
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count) void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{ {
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4, glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4,
count * sizeof(float) * 4, f); count * sizeof(float) * 4, f);
} }
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count) void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{ {
glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4, glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4,
count * sizeof(float) * 4, f); count * sizeof(float) * 4, f);
} }
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } GLuint ProgramShaderCache::GetCurrentProgram(void)
{
return CurrentProgram;
}
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void) PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
{ {
return pshaders[CurrentShaderProgram].program; return pshaders[CurrentShaderProgram].program;
} }
void ProgramShaderCache::Init(void)
{ void ProgramShaderCache::Init(void)
{
// We have to get the UBO alignment here because // We have to get the UBO alignment here because
// if we generate a buffer that isn't aligned // if we generate a buffer that isn't aligned
// then the UBO will fail. // then the UBO will fail.
@ -199,7 +209,8 @@ namespace OGL
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_ps_vs_ubo, 0, ps_data_size); glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_ps_vs_ubo, 0, ps_data_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_ps_vs_ubo, s_vs_data_offset, vs_data_size); glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_ps_vs_ubo, s_vs_data_offset, vs_data_size);
} }
#ifdef GLEW_VERSION_4_0
#ifdef GLEW_VERSION_4_0
// Read our shader cache, only if supported // Read our shader cache, only if supported
if (g_ActiveConfig.backend_info.bSupportsGLSLCache) if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{ {
@ -214,14 +225,15 @@ namespace OGL
GLint *Formats = new GLint[Supported]; GLint *Formats = new GLint[Supported];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats); glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
ProgramFormat = (GLenum)Formats[0]; // We don't really care about format // We don't really care about format
ProgramFormat = (GLenum)Formats[0];
delete[] Formats; delete[] Formats;
} }
#endif #endif
} }
void ProgramShaderCache::Shutdown(void) void ProgramShaderCache::Shutdown(void)
{ {
if (g_ActiveConfig.backend_info.bSupportsGLSLCache) if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{ {
PCache::iterator iter = pshaders.begin(); PCache::iterator iter = pshaders.begin();
@ -243,9 +255,10 @@ namespace OGL
glDeleteBuffers(1, &s_ps_vs_ubo); glDeleteBuffers(1, &s_ps_vs_ubo);
s_ps_vs_ubo = 0; s_ps_vs_ubo = 0;
} }
}
} }
} // namespace OGL
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p) void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p)
{ {
uid->uid.vsid = _v; uid->uid.vsid = _v;

View File

@ -15,8 +15,7 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#ifndef _ProgramShaderCache_H_ #pragma once
#define _ProgramShaderCache_H_
#include "GLUtil.h" #include "GLUtil.h"
@ -28,18 +27,18 @@
#include "LinearDiskCache.h" #include "LinearDiskCache.h"
#include "ConfigManager.h" #include "ConfigManager.h"
union PID union PID
{
struct
{ {
struct {
GLuint vsid, psid; GLuint vsid, psid;
}; };
u64 id; u64 id;
}; };
class PROGRAMUID class PROGRAMUID
{ {
public: public:
PID uid; PID uid;
PROGRAMUID() PROGRAMUID()
@ -51,57 +50,63 @@ public:
{ {
uid.id = r.uid.id; uid.id = r.uid.id;
} }
PROGRAMUID(GLuint _v, GLuint _p) PROGRAMUID(GLuint _v, GLuint _p)
{ {
uid.vsid = _v; uid.vsid = _v;
uid.psid = _p; uid.psid = _p;
} }
int GetNumValues() const u64 GetNumValues() const
{ {
return uid.id; return uid.id;
} }
}; };
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p); void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p);
namespace OGL namespace OGL
{ {
#define NUM_UNIFORMS 27
const int NUM_UNIFORMS = 27;
extern const char *UniformNames[NUM_UNIFORMS]; extern const char *UniformNames[NUM_UNIFORMS];
extern GLenum ProgramFormat; extern GLenum ProgramFormat;
struct PROGRAMSHADER struct PROGRAMSHADER
{ {
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0){} PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0) {}
GLuint glprogid; // opengl program id // opengl program id
GLuint glprogid;
GLuint vsid, psid; GLuint vsid, psid;
PROGRAMUID uid; PROGRAMUID uid;
GLint UniformLocations[NUM_UNIFORMS]; GLint UniformLocations[NUM_UNIFORMS];
GLint binaryLength; GLint binaryLength;
// TODO at first glance looks bad - malloc/no free/pointer not saved in instance...
u8 *Data() u8 *Data()
{ {
#ifdef GLEW_VERSION_4_0 #ifdef GLEW_VERSION_4_0
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength); glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
u8* binary = (u8*)malloc(binaryLength); u8* binary = (u8*)malloc(binaryLength);
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary); glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
return binary; return binary;
#else #else
return NULL; return NULL;
#endif #endif
} }
GLint Size() GLint Size()
{ {
#ifdef GLEW_VERSION_4_0 #ifdef GLEW_VERSION_4_0
if(!binaryLength) if (!binaryLength)
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength); glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
return binaryLength; return binaryLength;
#else #else
return 0; return 0;
#endif #endif
} }
}; };
class ProgramShaderCache class ProgramShaderCache
{ {
struct PCacheEntry struct PCacheEntry
@ -109,14 +114,18 @@ class ProgramShaderCache
PROGRAMSHADER program; PROGRAMSHADER program;
int frameCount; int frameCount;
PCacheEntry() : frameCount(0) {} PCacheEntry() : frameCount(0) {}
void Destroy() {
void Destroy()
{
glDeleteProgram(program.glprogid); glDeleteProgram(program.glprogid);
program.glprogid = 0; program.glprogid = 0;
} }
u8* Data() u8* Data()
{ {
return program.Data(); return program.Data();
} }
GLint Size() GLint Size()
{ {
return program.Size(); return program.Size();
@ -128,7 +137,7 @@ class ProgramShaderCache
public: public:
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size) void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
{ {
#ifdef GLEW_VERSION_4_0 #ifdef GLEW_VERSION_4_0
PCacheEntry entry; PCacheEntry entry;
// The two shaders might not even exist anymore // The two shaders might not even exist anymore
@ -149,7 +158,7 @@ class ProgramShaderCache
glUseProgram(entry.program.glprogid); glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, key); SetProgramVariables(entry, key);
} }
#endif #endif
} }
}; };
@ -173,9 +182,6 @@ public:
static void Init(void); static void Init(void);
static void Shutdown(void); static void Shutdown(void);
}; };
} // namespace OGL } // namespace OGL
#endif

View File

@ -1439,7 +1439,7 @@ void Renderer::ResetAPIState()
{ {
// Gets us to a reasonably sane state where it's possible to do things like // Gets us to a reasonably sane state where it's possible to do things like
// image copies with textured quads, etc. // image copies with textured quads, etc.
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(0, 0); ProgramShaderCache::SetBothShaders(0, 0);
else else
{ {
@ -1471,7 +1471,7 @@ void Renderer::RestoreAPIState()
if (g_ActiveConfig.bWireFrame) if (g_ActiveConfig.bWireFrame)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(0, 0); ProgramShaderCache::SetBothShaders(0, 0);
else else
{ {

View File

@ -297,7 +297,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glViewport(0, 0, virtualW, virtualH); glViewport(0, 0, virtualW, virtualH);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0); ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
else else
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram()); PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());

View File

@ -61,9 +61,9 @@ static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
void CreateRgbToYuyvProgram() void CreateRgbToYuyvProgram()
{ {
// Output is BGRA because that is slightly faster than RGBA. // Output is BGRA because that is slightly faster than RGBA.
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding) if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{ {
const char *FProgram = const char *FProgram =
"#version 330 compatibility\n" "#version 330 compatibility\n"
@ -132,9 +132,9 @@ void CreateRgbToYuyvProgram()
void CreateYuyvToRgbProgram() void CreateYuyvToRgbProgram()
{ {
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding) if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{ {
const char *FProgram = const char *FProgram =
"#version 330 compatibility\n" "#version 330 compatibility\n"
@ -410,7 +410,7 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format); int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format);
g_renderer->ResetAPIState(); g_renderer->ResetAPIState();
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0); ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
else else
PixelShaderCache::SetCurrentShader(texconv_shader.glprogid); PixelShaderCache::SetCurrentShader(texconv_shader.glprogid);
@ -470,7 +470,7 @@ u64 EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
s32 expandedWidth = (width + blkW) & (~blkW); s32 expandedWidth = (width + blkW) & (~blkW);
s32 expandedHeight = (height + blkH) & (~blkH); s32 expandedHeight = (height + blkH) & (~blkH);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0); ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
else else
PixelShaderCache::SetCurrentShader(texconv_shader.glprogid); PixelShaderCache::SetCurrentShader(texconv_shader.glprogid);
@ -516,7 +516,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
{ {
g_renderer->ResetAPIState(); g_renderer->ResetAPIState();
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0); ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0);
else else
PixelShaderCache::SetCurrentShader(s_rgbToYuyvProgram.glprogid); PixelShaderCache::SetCurrentShader(s_rgbToYuyvProgram.glprogid);
@ -563,7 +563,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture);
// TODO: make this less slow. (How?) // TODO: make this less slow. (How?)
if((GLsizei)s_srcTextureWidth == (GLsizei)srcFmtWidth && (GLsizei)s_srcTextureHeight == (GLsizei)srcHeight) if ((GLsizei)s_srcTextureWidth == (GLsizei)srcFmtWidth && (GLsizei)s_srcTextureHeight == (GLsizei)srcHeight)
{ {
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,0,0,s_srcTextureWidth, s_srcTextureHeight, glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,0,0,s_srcTextureWidth, s_srcTextureHeight,
GL_BGRA, GL_UNSIGNED_BYTE, srcAddr); GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
@ -577,7 +577,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
} }
glViewport(0, 0, srcWidth, srcHeight); glViewport(0, 0, srcWidth, srcHeight);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0); ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
else else
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid); PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);

View File

@ -203,7 +203,7 @@ void VertexManager::vFlush()
} }
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components); VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid); ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
else else
{ {
@ -226,10 +226,10 @@ void VertexManager::vFlush()
if (useDstAlpha && !dualSourcePossible) if (useDstAlpha && !dualSourcePossible)
{ {
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components); ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
ProgramShaderCache::SetBothShaders(ps->glprogid, 0); ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
if (g_nativeVertexFmt) if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers(); g_nativeVertexFmt->SetupVertexPointers();

View File

@ -16,7 +16,6 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <math.h> #include <math.h>
#include <assert.h>
#include "Globals.h" #include "Globals.h"
#include "VideoConfig.h" #include "VideoConfig.h"
@ -59,7 +58,7 @@ void VertexShaderCache::Init()
CurrentShader = 0; CurrentShader = 0;
last_entry = NULL; last_entry = NULL;
if(g_ActiveConfig.bUseGLSL) if (g_ActiveConfig.bUseGLSL)
{ {
pSetVSConstant4f = SetGLSLVSConstant4f; pSetVSConstant4f = SetGLSLVSConstant4f;
pSetVSConstant4fv = SetGLSLVSConstant4fv; pSetVSConstant4fv = SetGLSLVSConstant4fv;
@ -94,7 +93,6 @@ void VertexShaderCache::Shutdown()
vshaders.clear(); vshaders.clear();
} }
VERTEXSHADER* VertexShaderCache::SetShader(u32 components) VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
{ {
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
@ -156,8 +154,6 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
void VertexShaderCache::DisableShader() void VertexShaderCache::DisableShader()
{ {
if(g_ActiveConfig.bUseGLSL)
assert(true);
if (ShaderEnabled) if (ShaderEnabled)
{ {
glDisable(GL_VERTEX_PROGRAM_ARB); glDisable(GL_VERTEX_PROGRAM_ARB);
@ -165,11 +161,8 @@ void VertexShaderCache::DisableShader()
} }
} }
void VertexShaderCache::SetCurrentShader(GLuint Shader) void VertexShaderCache::SetCurrentShader(GLuint Shader)
{ {
if(g_ActiveConfig.bUseGLSL)
assert(true);
if (!ShaderEnabled) if (!ShaderEnabled)
{ {
glEnable(GL_VERTEX_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB);
@ -177,11 +170,12 @@ void VertexShaderCache::SetCurrentShader(GLuint Shader)
} }
if (CurrentShader != Shader) if (CurrentShader != Shader)
{ {
if(Shader != 0) if (Shader != 0)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
} }
} }
// GLSL Specific // GLSL Specific
bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram) bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{ {
@ -223,13 +217,15 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
vs.bGLSL = true; vs.bGLSL = true;
return true; return true;
} }
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
{ {
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for(int a = 0; a < NUM_UNIFORMS; ++a) for (int a = 0; a < NUM_UNIFORMS; ++a)
if(!strcmp(name, UniformNames[a]))
{ {
if(tmp.UniformLocations[a] == -1) if (!strcmp(name, UniformNames[a]))
{
if (tmp.UniformLocations[a] == -1)
return; return;
else else
{ {
@ -237,7 +233,9 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
return; return;
} }
} }
}
} }
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
float const buf[4] = {f1, f2, f3, f4}; float const buf[4] = {f1, f2, f3, f4};
@ -247,9 +245,9 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1); ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for (unsigned int a = 0; a < 9; ++a)
{ {
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
@ -265,9 +263,9 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1); ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for (unsigned int a = 0; a < 9; ++a)
{ {
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
@ -283,9 +281,9 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count); ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for (unsigned int a = 0; a < 9; ++a)
{ {
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
@ -309,9 +307,9 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count); ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count);
return; return;
} }
for( unsigned int a = 0; a < 9; ++a) for (unsigned int a = 0; a < 9; ++a)
{ {
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) if (const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
@ -397,7 +395,7 @@ void SetCGVSConstant4fv(unsigned int const_number, const float *f)
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{ {
if(GLEW_EXT_gpu_program_parameters) if (GLEW_EXT_gpu_program_parameters)
{ {
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f); glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
} }
@ -410,7 +408,7 @@ void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, cons
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{ {
if(GLEW_EXT_gpu_program_parameters) if (GLEW_EXT_gpu_program_parameters)
{ {
float buf[4 * C_VENVCONST_END]; float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
@ -457,5 +455,4 @@ void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int cou
pSetMultiVSConstant3fv(const_number, count, f); pSetMultiVSConstant3fv(const_number, count, f);
} }
} // namespace OGL } // namespace OGL

View File

@ -32,7 +32,7 @@ struct VERTEXSHADER
VERTEXSHADER() : glprogid(0), bGLSL(0) {} VERTEXSHADER() : glprogid(0), bGLSL(0) {}
void Destroy() void Destroy()
{ {
if(bGLSL) if (bGLSL)
glDeleteShader(glprogid); glDeleteShader(glprogid);
else else
glDeleteProgramsARB(1, &glprogid); glDeleteProgramsARB(1, &glprogid);