fix formatting uglies introduced in glsl-master branch

This commit is contained in:
Shawn Hoffman 2011-12-26 00:15:54 -05:00 committed by Sonicadvance1
parent 4a4833e617
commit 31a8424bcc
15 changed files with 1061 additions and 1051 deletions

View File

@ -573,7 +573,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title, con
// 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);
szr_misc->Add(cb_GLSL);

View File

@ -112,7 +112,7 @@ protected:
void Event_ProgressiveScan(wxCommandEvent &ev)
{
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();
}

View File

@ -511,23 +511,25 @@ static void BuildSwapModeTable()
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
static char result[64];
sprintf(result, " : register(%s%d)", prefix, num);
return result;
}
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 "";
static char result[64];
sprintf(result, "layout(binding = %d) ", num);
return result;
}
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 "";
static char result[64];
sprintf(result, "uniform ");
@ -559,7 +561,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 ;
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
// 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)
@ -573,7 +575,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
else
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");
// Silly differences
WRITE(p, "#define float2 vec2\n");
@ -602,7 +604,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{
// Declare samplers
if(ApiType != API_D3D11)
if (ApiType != API_D3D11)
{
WRITE(p, "uniform sampler2D ");
}
@ -618,7 +620,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
bfirst = false;
}
WRITE(p, ";\n");
if(ApiType == API_D3D11)
if (ApiType == API_D3D11)
{
WRITE(p, "Texture2D ");
bfirst = true;
@ -632,7 +634,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
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, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
@ -648,13 +650,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_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");
if(ApiType != API_GLSL)
if (ApiType != API_GLSL)
{
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",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
@ -702,7 +704,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// 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
WRITE(p, " layout(location = 0) out float4 ocol0;\n");
@ -712,7 +714,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{
WRITE(p, " float4 ocol0;\n");
}
if(DepthTextureEnable)
if (DepthTextureEnable)
WRITE(p, " float depth;\n"); // TODO: Passed to Vertex Shader right?
WRITE(p, " float4 rawpos = gl_FragCoord;\n");
@ -725,13 +727,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numTexgen; ++i)
WRITE(p, " float3 uv%d = gl_TexCoord[%d].xyz;\n", i, i);
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);
}
else
{
// 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)
WRITE(p, " float4 uv%d = gl_TexCoord[%d];\n", i, i);
@ -783,7 +785,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 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)
{
@ -830,7 +832,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
// 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))
{
@ -860,7 +862,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numStages; i++)
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,
// regardless of the used destination register
@ -889,15 +891,15 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "ocol0 = 0;\n");
if(DepthTextureEnable)
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");
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
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n");
if(DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
}
WRITE(p, "discard;\n");
if(ApiType != API_D3D11)
@ -945,9 +947,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// ...and the alpha from ocol0 will be written to the framebuffer.
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");
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n");
@ -1109,10 +1111,10 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (bpmem.tevorders[n/2].getEnable(n&1))
{
if(!bHasIndStage)
if (!bHasIndStage)
{
// calc tevcord
if(bHasTexCoord)
if (bHasTexCoord)
WRITE(p, "tevcoord.xy = uv%d.xy;\n", texcoord);
else
WRITE(p, "tevcoord.xy = float2(0.0f, 0.0f);\n");
@ -1132,7 +1134,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
int kc = bpmem.tevksel[n / 2].getKC(n & 1);
int ka = bpmem.tevksel[n / 2].getKA(n & 1);
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");
}
@ -1231,7 +1233,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (cc.shift > TEVSCALE_1)
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]);
if (cc.a == cc.b)
@ -1281,7 +1283,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (ac.shift > TEVSCALE_1)
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]);
if (ac.a == ac.b)
@ -1297,7 +1299,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
WRITE(p, "%s",tevBiasTable[ac.bias]);
if (ac.shift>0)
if (ac.shift > 0)
WRITE(p, ")");
}
@ -1386,6 +1388,7 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
I_ALPHA"[0].g"
};
// using discard then return works the same in cg and dx9 but not in dx11
WRITE(p, "if(!( ");
@ -1399,9 +1402,9 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
<<<<<<< HEAD
WRITE(p, ")) {\n");
WRITE(p, "ocol0 = float4(0);\n");
WRITE(p, "ocol0 = float4(0.0f);\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = 0;\n");
WRITE(p, "ocol1 = float4(0.0f);\n");
if (DepthTextureEnable)
WRITE(p, "depth = 1.f;\n");
@ -1426,13 +1429,6 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
WRITE(p, "}\n");
=======
WRITE(p, ")){ocol0 = float4(0.0f);%s%s discard;%s}\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "ocol1 = vec4(0.0f);" : "",
DepthTextureEnable ? "depth = 1.f;" : "",
(ApiType != API_D3D11) ? "return;" : "");
return true;
>>>>>>> Few compiler errors that got exposed once I got Dual Source Blending working. Seems it isn't working quite 100% either. Good chance I missed something anyway.
}
static const char *tevFogFuncsTable[] =
@ -1449,7 +1445,8 @@ static const char *tevFogFuncsTable[] =
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)
{
@ -1467,7 +1464,7 @@ static void WriteFog(char *&p)
// x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust
//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, " x_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[2].z * " I_FOG"[2].z) / " I_FOG"[2].z;\n");
@ -1476,17 +1473,15 @@ static void WriteFog(char *&p)
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]);
}
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);
}
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;
}
}
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
static char result[64];
sprintf(result, " : register(%s%d)", prefix, num);
return result;
}
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 "";
static char result[64];
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
// [1] width and height of destination texture in pixels
// 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, "%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");
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, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -131,7 +133,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
else
{
WRITE(p,"void main(\n");
if(ApiType != API_D3D11)
if (ApiType != API_D3D11)
{
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");
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 = 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 / "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
// [1] width and height of destination texture in pixels
// 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, "%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");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
// 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");
}
@ -212,7 +214,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, "Texture2D Tex0 : register(t0);\n");
}
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -249,18 +251,17 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " float xl = floor(x2 / %f);\n", blkW);
WRITE(p, " float xib = x2 - (xl * %f);\n", blkW);
WRITE(p, " float halfxb = floor(xb / 2);\n");
WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW);
WRITE(p, " sampleUv.y = yb + xoff;\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 = 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 / "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.
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";
else
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)
{
if(!IntensityConstantAdded)
if (!IntensityConstantAdded)
{
WRITE(p, " float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n");
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)
{
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
WRITE(p, "gl_FragData[0] = ocol0;\n");
WRITE(p, "}\n");
IntensityConstantAdded = false;
@ -337,22 +338,22 @@ void WriteEncoderEnd(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");
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
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)
{
WriteSwizzler(p, GX_TF_I4,ApiType);
WriteSwizzler(p, GX_TF_I4, ApiType);
WRITE(p, " float3 texSample;\n");
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
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");
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)
{
WriteSwizzler(p, GX_TF_IA8,ApiType);
WriteSwizzler(p, GX_TF_IA8, ApiType);
WRITE(p, " float4 texSample;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " ocol0.b = texSample.a;\n");
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");
WriteColorToIntensity(p, "texSample", "ocol0.a");
@ -429,27 +430,27 @@ void WriteIA8Encoder(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 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n");
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");
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");
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");
WriteColorToIntensity(p, "texSample", "color1.a");
@ -464,11 +465,11 @@ void WriteIA4Encoder(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);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1",ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1", ApiType);
WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n");
WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\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)
{
WriteSwizzler(p, GX_TF_RGB5A3,ApiType);
WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
WRITE(p, " float4 texSample;\n");
WRITE(p, " float color0;\n");
WRITE(p, " float gUpper;\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
WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -522,9 +523,9 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
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");
@ -555,21 +556,21 @@ void WriteRGB5A3Encoder(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 color0;\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, 4, "texSample.r", "color1.b");
WriteToBitDepth(p, 4, "texSample.g", "color0.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, 4, "texSample.r", "color1.r");
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)
{
Write32BitSwizzler(p, GX_TF_RGBA8,ApiType);
Write32BitSwizzler(p, GX_TF_RGBA8, ApiType);
WRITE(p, " float cl1 = xb - (halfxb * 2);\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 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n");
WRITE(p, " color0.g = texSample.r;\n");
WRITE(p, " color1.b = texSample.g;\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.a = texSample.r;\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)
{
WriteSwizzler(p, GX_CTF_R4,ApiType);
WriteSwizzler(p, GX_CTF_R4, ApiType);
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "color0.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.a",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.a", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.a",ApiType);
WriteSampleColor(p, comp, "color1.a", ApiType);
WriteToBitDepth(p, 4, "color0", "color0");
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)
{
WriteSwizzler(p, GX_CTF_R8,ApiType);
WriteSwizzler(p, GX_CTF_R8, ApiType);
WriteSampleColor(p, comp, "ocol0.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.a",ApiType);
WriteSampleColor(p, comp, "ocol0.a", ApiType);
WriteEncoderEnd(p, 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, " float4 color0;\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, " 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, " 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, " 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, " 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)
{
WriteSwizzler(p, GX_CTF_RA8,ApiType);
WriteSwizzler(p, GX_CTF_RA8, ApiType);
WriteSampleColor(p, comp, "ocol0.bg",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.bg", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.ra",ApiType);
WriteSampleColor(p, comp, "ocol0.ra", ApiType);
WriteEncoderEnd(p, 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");
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
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);
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);
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);
WriteEncoderEnd(p, ApiType);
@ -734,14 +735,14 @@ void WriteZ8Encoder(char* p, const char* multiplier,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, " float3 expanded;\n");
// byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\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.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, " 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)
{
WriteSwizzler(p, GX_CTF_Z16L,ApiType);
WriteSwizzler(p, GX_CTF_Z16L, ApiType);
WRITE(p, " float depth;\n");
WRITE(p, " float3 expanded;\n");
// byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\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.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, " 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)
{
Write32BitSwizzler(p, GX_TF_Z24X8,ApiType);
Write32BitSwizzler(p, GX_TF_Z24X8, ApiType);
WRITE(p, " float cl = xb - (halfxb * 2);\n");
@ -815,19 +816,19 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
WRITE(p, " float3 expanded0;\n");
WRITE(p, " float3 expanded1;\n");
WriteSampleColor(p, "b", "depth0",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, "b", "depth1",ApiType);
WriteSampleColor(p, "b", "depth0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth1", ApiType);
for (int i = 0; i < 2; i++)
{
WRITE(p, " depth%i *= 16777215.0f;\n", i);
WRITE(p, " depth%i *= 16777215.0f;\n", i);
WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i);
WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i);
WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i);
WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i);
WRITE(p, " expanded%i.b = depth%i;\n", i, i);
WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i);
WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i);
WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i);
WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i);
WRITE(p, " expanded%i.b = depth%i;\n", i, i);
}
WRITE(p, " if(cl > 0.5f) {\n");
@ -854,7 +855,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
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
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");
}
switch(format)
switch (format)
{
case GX_TF_I4:
WriteI4Encoder(p,ApiType);
WriteI4Encoder(p, ApiType);
break;
case GX_TF_I8:
WriteI8Encoder(p,ApiType);
WriteI8Encoder(p, ApiType);
break;
case GX_TF_IA4:
WriteIA4Encoder(p,ApiType);
WriteIA4Encoder(p, ApiType);
break;
case GX_TF_IA8:
WriteIA8Encoder(p,ApiType);
WriteIA8Encoder(p, ApiType);
break;
case GX_TF_RGB565:
WriteRGB565Encoder(p,ApiType);
WriteRGB565Encoder(p, ApiType);
break;
case GX_TF_RGB5A3:
WriteRGB5A3Encoder(p,ApiType);
WriteRGB5A3Encoder(p, ApiType);
break;
case GX_TF_RGBA8:
WriteRGBA8Encoder(p,ApiType);
WriteRGBA8Encoder(p, ApiType);
break;
case GX_CTF_R4:
WriteC4Encoder(p, "r",ApiType);
WriteC4Encoder(p, "r", ApiType);
break;
case GX_CTF_RA4:
WriteCC4Encoder(p, "ar",ApiType);
WriteCC4Encoder(p, "ar", ApiType);
break;
case GX_CTF_RA8:
WriteCC8Encoder(p, "ar",ApiType);
WriteCC8Encoder(p, "ar", ApiType);
break;
case GX_CTF_A8:
WriteC8Encoder(p, "a",ApiType);
WriteC8Encoder(p, "a", ApiType);
break;
case GX_CTF_R8:
WriteC8Encoder(p, "r",ApiType);
WriteC8Encoder(p, "r", ApiType);
break;
case GX_CTF_G8:
WriteC8Encoder(p, "g",ApiType);
WriteC8Encoder(p, "g", ApiType);
break;
case GX_CTF_B8:
WriteC8Encoder(p, "b",ApiType);
WriteC8Encoder(p, "b", ApiType);
break;
case GX_CTF_RG8:
WriteCC8Encoder(p, "rg",ApiType);
WriteCC8Encoder(p, "rg", ApiType);
break;
case GX_CTF_GB8:
WriteCC8Encoder(p, "gb",ApiType);
WriteCC8Encoder(p, "gb", ApiType);
break;
case GX_TF_Z8:
WriteC8Encoder(p, "b",ApiType);
WriteC8Encoder(p, "b", ApiType);
break;
case GX_TF_Z16:
WriteZ16Encoder(p,ApiType);
WriteZ16Encoder(p, ApiType);
break;
case GX_TF_Z24X8:
WriteZ24Encoder(p,ApiType);
WriteZ24Encoder(p, ApiType);
break;
case GX_CTF_Z4:
WriteC4Encoder(p, "b",ApiType);
WriteC4Encoder(p, "b", ApiType);
break;
case GX_CTF_Z8M:
WriteZ8Encoder(p, "256.0f",ApiType);
WriteZ8Encoder(p, "256.0f", ApiType);
break;
case GX_CTF_Z8L:
WriteZ8Encoder(p, "65536.0f" ,ApiType);
WriteZ8Encoder(p, "65536.0f" , ApiType);
break;
case GX_CTF_Z16L:
WriteZ16LEncoder(p,ApiType);
WriteZ16LEncoder(p, ApiType);
break;
default:
PanicAlert("Unknown texture copy format: 0x%x\n", format);

View File

@ -185,65 +185,64 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
char *p = text;
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
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
WRITE(p, "#version 330 compatibility\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n");
}
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// 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)
{
WRITE(p, "#version 330 compatibility\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n");
}
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// cg to glsl function translation
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
// cg to glsl function translation
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
}
// 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, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType),WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
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_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType),WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
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));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
p = GenerateVSOutputStruct(p, components, ApiType);
if(ApiType == API_GLSL)
if(ApiType == API_GLSL)
{
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)
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
{
WRITE(p, "VS_OUTPUT main(\n");
// inputs
@ -306,9 +304,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
if (components & VB_HAS_POSMTXIDX) {
if (is_d3d)
{
WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
}
else
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"
"float dist, dist2, attn;\n");
if(xfregs.numChan.numColorChans == 0)
if (xfregs.numChan.numColorChans == 0)
{
if (components & VB_HAS_COL0)
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.
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)
WRITE(p, "o.colors_1 = color1;\n");
@ -584,23 +580,23 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
// clipPos/w needs to be done in pixel shader, not here
if (xfregs.numTexGen.numTexGens < 7) {
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d].xyz = o.tex%d;\n", i, i);
WRITE(p, " gl_TexCoord[%d] = o.clipPos;\n", xfregs.numTexGen.numTexGens);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d].xyz = o.tex%d;\n", i, i);
WRITE(p, " gl_TexCoord[%d] = o.clipPos;\n", xfregs.numTexGen.numTexGens);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
} else {
// clip position is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
}
else
{
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d]%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
}
// clip position is in w of first 4 texcoords
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
}
else
{
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d]%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
}
}
WRITE(p, "gl_FrontColor = o.colors_0;\n");
WRITE(p, "gl_FrontSecondaryColor = o.colors_1;\n");
@ -608,7 +604,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "}\n");
}
else
WRITE(p, "return o;\n}\n");
WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");

View File

@ -20,7 +20,6 @@
#include "GLUtil.h"
#include <cmath>
#include <assert.h>
#include "Statistics.h"
#include "VideoConfig.h"
@ -51,62 +50,63 @@ bool PixelShaderCache::ShaderEnabled;
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
PIXELSHADERUID PixelShaderCache::last_uid;
void(*pSetPSConstant4f)(unsigned int, float, float, float, float);
void(*pSetPSConstant4fv)(unsigned int, const float*);
void(*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
void (*pSetPSConstant4f)(unsigned int, float, float, float, float);
void (*pSetPSConstant4fv)(unsigned int, const float*);
void (*pSetMultiPSConstant4fv)(unsigned int, unsigned int, const float*);
bool (*pCompilePixelShader)(FRAGMENTSHADER&, const char*);
GLuint PixelShaderCache::GetDepthMatrixProgram()
{
return s_DepthMatrixProgram.glprogid;
return s_DepthMatrixProgram.glprogid;
}
GLuint PixelShaderCache::GetColorMatrixProgram()
{
return s_ColorMatrixProgram.glprogid;
return s_ColorMatrixProgram.glprogid;
}
void PixelShaderCache::Init()
{
ShaderEnabled = true;
CurrentShader = 0;
last_entry = NULL;
GL_REPORT_ERRORD();
ShaderEnabled = true;
CurrentShader = 0;
last_entry = NULL;
GL_REPORT_ERRORD();
s_displayCompileAlert = true;
s_displayCompileAlert = true;
if(g_ActiveConfig.bUseGLSL)
{
if (g_ActiveConfig.bUseGLSL)
{
pSetPSConstant4f = SetGLSLPSConstant4f;
pSetPSConstant4fv = SetGLSLPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv;
pCompilePixelShader = CompileGLSLPixelShader;
}
else
{
}
else
{
pSetPSConstant4f = SetCGPSConstant4f;
pSetPSConstant4fv = SetCGPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv;
pCompilePixelShader = CompileCGPixelShader;
glEnable(GL_FRAGMENT_PROGRAM_ARB);
}
}
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.
s_nMaxPixelInstructions = 4096;
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
if (s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
s_nMaxPixelInstructions = 4096;
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
#if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{
s_nMaxPixelInstructions = 4096;
}
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{
s_nMaxPixelInstructions = 4096;
}
#endif
int maxinst, maxattribs;
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);
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
if(g_ActiveConfig.bUseGLSL)
int maxinst, maxattribs;
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);
INFO_LOG(VIDEO, "pixel max_alu=%d, max_inst=%d, max_attrib=%d", s_nMaxPixelInstructions, maxinst, maxattribs);
if (g_ActiveConfig.bUseGLSL)
{
char pmatrixprog[2048];
sprintf(pmatrixprog, "#version %s\n"
@ -137,14 +137,14 @@ void PixelShaderCache::Init()
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
sprintf(pmatrixprog, "#version %s\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
@ -183,7 +183,7 @@ void PixelShaderCache::Init()
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
@ -194,20 +194,20 @@ void PixelShaderCache::Init()
{
char pmatrixprog[2048];
sprintf(pmatrixprog, "!!ARBfp1.0"
"TEMP R0;\n"
"TEMP R1;\n"
"PARAM K0 = { 0.5, 0.5, 0.5, 0.5};\n"
"TEX R0, fragment.texcoord[0], texture[0], RECT;\n"
"MUL R0, R0, program.env[%d];\n"
"ADD R0, R0, K0;\n"
"FLR R0, R0;\n"
"MUL R0, R0, program.env[%d];\n"
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n",C_COLORS+5,C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
"TEMP R0;\n"
"TEMP R1;\n"
"PARAM K0 = { 0.5, 0.5, 0.5, 0.5};\n"
"TEX R0, fragment.texcoord[0], texture[0], RECT;\n"
"MUL R0, R0, program.env[%d];\n"
"ADD R0, R0, K0;\n"
"FLR R0, R0;\n"
"MUL R0, R0, program.env[%d];\n"
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n",C_COLORS+5,C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
glGenProgramsARB(1, &s_ColorMatrixProgram.glprogid);
SetCurrentShader(s_ColorMatrixProgram.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
@ -219,50 +219,50 @@ void PixelShaderCache::Init()
}
sprintf(pmatrixprog, "!!ARBfp1.0\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
//16777215/16777216*256, 1/255, 256, 0
"PARAM K0 = { 255.99998474121, 0.003921568627451, 256.0, 0.0};\n"
"PARAM K1 = { 15.0, 0.066666666666, 0.0, 0.0};\n"
//sample the depth value
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
//16777215/16777216*256, 1/255, 256, 0
"PARAM K0 = { 255.99998474121, 0.003921568627451, 256.0, 0.0};\n"
"PARAM K1 = { 15.0, 0.066666666666, 0.0, 0.0};\n"
//sample the depth value
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
//scale from [0*16777216..1*16777216] to
//[0*16777215..1*16777215], multiply by 256
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
//scale from [0*16777216..1*16777216] to
//[0*16777215..1*16777215], multiply by 256
"MUL R0, R2.x, K0.x;\n" // *16777215/16777216*256
//It is easy to get bad results due to low precision
//here, for example converting like this:
//MUL R0,R0,{ 65536, 256, 1, 16777216 }
//FRC R0,R0
//gives {?, 128/255, 254/255, ?} for depth value 254/255
//on some gpus
//It is easy to get bad results due to low precision
//here, for example converting like this:
//MUL R0,R0,{ 65536, 256, 1, 16777216 }
//FRC R0,R0
//gives {?, 128/255, 254/255, ?} for depth value 254/255
//on some gpus
"FLR R0.x,R0;\n" //bits 31..24
"FLR R0.x,R0;\n" //bits 31..24
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
"MUL R0.yzw,R0,K0.z;\n" // *256
"FLR R0.y,R0;\n" //bits 23..16
"SUB R0.yzw,R0,R0.x;\n" //subtract bits 31..24 from rest
"MUL R0.yzw,R0,K0.z;\n" // *256
"FLR R0.y,R0;\n" //bits 23..16
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
"MUL R0.zw,R0,K0.z;\n" // *256
"FLR R0.z,R0;\n" //bits 15..8
"SUB R0.zw,R0,R0.y;\n" //subtract bits 23..16 from rest
"MUL R0.zw,R0,K0.z;\n" // *256
"FLR R0.z,R0;\n" //bits 15..8
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
"MOV R0.w,R0.x;\n" //duplicate bit 31..24
"MUL R0,R0,K0.y;\n" // /255
"MUL R0,R0,K0.y;\n" // /255
"MUL R0.w,R0,K1.x;\n" // *15
"FLR R0.w,R0;\n" //bits 31..28
"MUL R0.w,R0,K1.y;\n" // /15
"MUL R0.w,R0,K1.x;\n" // *15
"FLR R0.w,R0;\n" //bits 31..28
"MUL R0.w,R0,K1.y;\n" // /15
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
"DP4 R1.x, R0, program.env[%d];\n"
"DP4 R1.y, R0, program.env[%d];\n"
"DP4 R1.z, R0, program.env[%d];\n"
"DP4 R1.w, R0, program.env[%d];\n"
"ADD result.color, R1, program.env[%d];\n"
"END\n", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
glGenProgramsARB(1, &s_DepthMatrixProgram.glprogid);
SetCurrentShader(s_DepthMatrixProgram.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pmatrixprog), pmatrixprog);
@ -280,71 +280,71 @@ void PixelShaderCache::Shutdown()
{
s_ColorMatrixProgram.Destroy();
s_DepthMatrixProgram.Destroy();
PSCache::iterator iter = PixelShaders.begin();
for (; iter != PixelShaders.end(); iter++)
iter->second.Destroy();
PixelShaders.clear();
PSCache::iterator iter = PixelShaders.begin();
for (; iter != PixelShaders.end(); iter++)
iter->second.Destroy();
PixelShaders.clear();
}
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{
PIXELSHADERUID uid;
GetPixelShaderId(&uid, dstAlphaMode, components);
PIXELSHADERUID uid;
GetPixelShaderId(&uid, dstAlphaMode, components);
// Check if the shader is already set
if (last_entry)
{
if (uid == last_uid)
// Check if the shader is already set
if (last_entry)
{
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
return &last_entry->shader;
if (uid == last_uid)
{
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
return &last_entry->shader;
}
}
}
last_uid = uid;
last_uid = uid;
PSCache::iterator iter = PixelShaders.find(uid);
if (iter != PixelShaders.end())
{
PSCacheEntry &entry = iter->second;
last_entry = &entry;
PSCache::iterator iter = PixelShaders.find(uid);
if (iter != PixelShaders.end())
{
PSCacheEntry &entry = iter->second;
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
return &last_entry->shader;
}
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
return &last_entry->shader;
}
// Make an entry in the table
PSCacheEntry& newentry = PixelShaders[uid];
last_entry = &newentry;
const char *code = GeneratePixelShaderCode(dstAlphaMode, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL, components);
// Make an entry in the table
PSCacheEntry& newentry = PixelShaders[uid];
last_entry = &newentry;
const char *code = GeneratePixelShaderCode(dstAlphaMode, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL, components);
if (g_ActiveConfig.bEnableShaderDebugging && code)
{
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
newentry.shader.strprog = code;
}
if (g_ActiveConfig.bEnableShaderDebugging && code)
{
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
newentry.shader.strprog = code;
}
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, code);
}
SaveData(szTemp, code);
}
#endif
if (!code || !CompilePixelShader(newentry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL;
}
if (!code || !CompilePixelShader(newentry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL;
}
INCSTAT(stats.numPixelShadersCreated);
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
return &last_entry->shader;
INCSTAT(stats.numPixelShadersCreated);
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
return &last_entry->shader;
}
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
@ -352,35 +352,32 @@ bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrpr
return pCompilePixelShader(ps, pstrprogram);
}
//Disable Fragment programs and reset the selected Program
// Disable Fragment programs and reset the selected Program
void PixelShaderCache::DisableShader()
{
if(g_ActiveConfig.bUseGLSL)
assert(true);
if(ShaderEnabled)
{
glDisable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = false;
}
if (ShaderEnabled)
{
glDisable(GL_FRAGMENT_PROGRAM_ARB);
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)
{
if(g_ActiveConfig.bUseGLSL)
assert(true);
if(!ShaderEnabled)
{
glEnable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = true;
}
if(CurrentShader != Shader)
{
if(Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
}
if (!ShaderEnabled)
{
glEnable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = true;
}
if (CurrentShader != Shader)
{
if (Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
}
}
// GLSL Specific
bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{
@ -404,12 +401,12 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
GLchar* infoLog = new GLchar[length];
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
WARN_LOG(VIDEO, "PS Shader info log:\n%s", infoLog);
char szTemp[MAX_PATH];
sprintf(szTemp, "ps_%d.txt", result);
FILE *fp = fopen(szTemp, "wb");
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
fclose(fp);
char szTemp[MAX_PATH];
sprintf(szTemp, "ps_%d.txt", result);
FILE *fp = fopen(szTemp, "wb");
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
fclose(fp);
delete[] infoLog;
}
// Don't try to use this shader
@ -422,40 +419,43 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
ps.bGLSL = true;
return true;
}
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
{
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for (int a = 0; a < NUM_UNIFORMS; ++a)
if (!strcmp(name, UniformNames[a]))
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for (int a = 0; a < NUM_UNIFORMS; ++a)
{
if(tmp.UniformLocations[a] == -1)
return;
else
{
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return;
}
if (!strcmp(name, UniformNames[a]))
{
if (tmp.UniformLocations[a] == -1)
return;
else
{
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return;
}
}
}
}
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float const f[4] = {f1, f2, f3, f4};
float const f[4] = {f1, f2, f3, f4};
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
return;
}
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))
for (unsigned int a = 0; a < 10; ++a)
{
unsigned int offset = const_number - PSVar_Loc[a].reg;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
return;
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;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
return;
}
}
}
}
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
@ -465,15 +465,15 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, 1);
return;
}
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))
for (unsigned int a = 0; a < 10; ++a)
{
unsigned int offset = const_number - PSVar_Loc[a].reg;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
return;
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;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
return;
}
}
}
}
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
@ -483,115 +483,117 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
ProgramShaderCache::SetMultiPSConstant4fv(const_number, f, count);
return;
}
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))
for (unsigned int a = 0; a < 10; ++a)
{
unsigned int offset = const_number - PSVar_Loc[a].reg;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
return;
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;
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
return;
}
}
}
}
// CG Specific
// CG Specific
bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
{
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
}
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before PS!", err);
}
#if defined HAVE_CG && HAVE_CG
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", NULL);
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", NULL);
// handle errors
if (!cgIsProgram(tempprog))
{
cgDestroyProgram(tempprog);
// handle errors
if (!cgIsProgram(tempprog))
{
cgDestroyProgram(tempprog);
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
return false;
}
// handle warnings
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL)
{
const char *penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local");
}
glGenProgramsARB(1, &ps.glprogid);
ps.bGLSL = false;
PixelShaderCache::SetCurrentShader(ps.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
GLint error_pos, native_limit;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
// Error occur
if (error_pos != -1) {
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
char line[256];
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
line[255] = 0;
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
} else if (native_limit != -1) {
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
// TODO
return false;
}
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
// handle warnings
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL)
{
const char *penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local");
}
glGenProgramsARB(1, &ps.glprogid);
ps.bGLSL = false;
PixelShaderCache::SetCurrentShader(ps.glprogid);
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
GLint error_pos, native_limit;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
// Error occur
if (error_pos != -1) {
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
char line[256];
strncpy(line, (const char *)pcompiledprog + error_pos, 255);
line[255] = 0;
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
ERROR_LOG(VIDEO, "Line dump: \n%s", line);
} else if (native_limit != -1) {
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
// TODO
}
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
#endif
return true;
return true;
}
void SetCGPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float f[4] = { f1, f2, f3, f4 };
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
float f[4] = { f1, f2, f3, f4 };
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
}
void SetCGPSConstant4fv(unsigned int const_number, const float *f)
{
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
}
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
}
// Renderer functions
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(bGLSL)
if (bGLSL)
glDeleteShader(glprogid);
else
glDeleteProgramsARB(1, &glprogid);

View File

@ -18,234 +18,247 @@
#include "ProgramShaderCache.h"
#include "MathUtil.h"
#include <assert.h>
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;
GLenum ProgramFormat;
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;
std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram;
const char *UniformNames[NUM_UNIFORMS] = {
// SAMPLERS
"samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7",
// PIXEL SHADER UNIFORMS
I_COLORS,
I_KCOLORS,
I_ALPHA,
I_TEXDIMS,
I_ZBIAS ,
I_INDTEXSCALE ,
I_INDTEXMTX,
I_FOG,
I_PLIGHTS,
I_PMATERIALS,
// VERTEX SHADER UNIFORMS
I_POSNORMALMATRIX,
I_PROJECTION ,
I_MATERIALS,
I_LIGHTS,
I_TEXMATRICES,
I_TRANSFORMMATRICES ,
I_NORMALMATRICES ,
I_POSTTRANSFORMMATRICES,
I_DEPTHPARAMS,
};
LinearDiskCache<PROGRAMUID, u8> g_program_disk_cache;
GLenum ProgramFormat;
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid)
std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram;
const char *UniformNames[NUM_UNIFORMS] =
{
// SAMPLERS
"samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7",
// PIXEL SHADER UNIFORMS
I_COLORS,
I_KCOLORS,
I_ALPHA,
I_TEXDIMS,
I_ZBIAS ,
I_INDTEXSCALE ,
I_INDTEXMTX,
I_FOG,
I_PLIGHTS,
I_PMATERIALS,
// VERTEX SHADER UNIFORMS
I_POSNORMALMATRIX,
I_PROJECTION ,
I_MATERIALS,
I_LIGHTS,
I_TEXMATRICES,
I_TRANSFORMMATRICES ,
I_NORMALMATRICES ,
I_POSTTRANSFORMMATRICES,
I_DEPTHPARAMS,
};
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid)
{
// Dunno why this is needed when I have the binding
// points statically set in the shader source
// 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
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
// Dunno why this is needed when I have the binding
// points statically set in the shader source
// 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
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
glUniformBlockBinding( entry.program.glprogid, 0, 1 );
if(uid.uid.vsid != 0) // Some things have no vertex shader
glUniformBlockBinding( entry.program.glprogid, 1, 2 );
}
// We cache our uniform locations for now
// Once we move up to a newer version of GLSL, ~1.30
// We can remove this
//For some reason this fails on my hardware
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
//Got to do it this crappy way.
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for(int a = 8; a < NUM_UNIFORMS; ++a)
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
for(int a = 0; a < 8; ++a)
{
// 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]);
if(entry.program.UniformLocations[a] != -1)
glUniform1i(entry.program.UniformLocations[a], a);
}
glUniformBlockBinding(entry.program.glprogid, 0, 1);
// Some things have no vertex shader
if (uid.uid.vsid != 0)
glUniformBlockBinding(entry.program.glprogid, 1, 2);
}
// Need to get some attribute locations
if(uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind) // We have no vertex Shader
// We cache our uniform locations for now
// Once we move up to a newer version of GLSL, ~1.30
// We can remove this
// (Sonicadvance): For some reason this fails on my hardware
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
// Got to do it this crappy way.
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for (int a = 8; a < NUM_UNIFORMS; ++a)
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
for (int a = 0; a < 8; ++a)
{
glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
// 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]);
if (entry.program.UniformLocations[a] != -1)
glUniform1i(entry.program.UniformLocations[a], a);
}
}
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
// Need to get some attribute locations
if (uid.uid.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{
PROGRAMUID uid;
CurrentFShader = PS;
CurrentVShader = VS;
GetProgramShaderId(&uid, CurrentVShader, CurrentFShader);
if(uid.uid.id == 0)
{
CurrentProgram = 0;
glUseProgram(0);
return;
}
// Fragment shaders can survive without Vertex Shaders
// We have a valid fragment shader, let's create our program
std::pair<u32, u32> ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid);
PCache::iterator iter = pshaders.find(ShaderPair);
if (iter != pshaders.end())
{
PCacheEntry &entry = iter->second;
glUseProgram(entry.program.glprogid);
CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid;
return;
}
PCacheEntry entry;
entry.program.vsid = CurrentVShader;
entry.program.psid = CurrentFShader;
entry.program.uid = uid;
entry.program.glprogid = glCreateProgram();
// Right, the program is created now
// Let's attach everything
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.psid);
#ifdef GLEW_VERSION_4_0
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
#endif
glLinkProgram(entry.program.glprogid);
glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, uid);
pshaders[ShaderPair] = entry;
CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid;
}
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4,
count * sizeof(float) * 4, f);
}
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{
glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4,
count * sizeof(float) * 4, f);
}
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
{
return pshaders[CurrentShaderProgram].program;
}
void ProgramShaderCache::Init(void)
{
// We have to get the UBO alignment here because
// if we generate a buffer that isn't aligned
// then the UBO will fail.
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
GLint Align;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);
GLintptr const ps_data_size = ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align);
GLintptr const vs_data_size = ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align);
s_vs_data_offset = ps_data_size;
// We multiply by *4*4 because we need to get down to basic machine units.
// So multiply by four to get how many floats we have from vec4s
// Then once more to get bytes
glGenBuffers(1, &s_ps_vs_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_vs_ubo);
glBufferData(GL_UNIFORM_BUFFER, ps_data_size + vs_data_size, NULL, GL_DYNAMIC_DRAW);
// Now bind the buffer to the index point
// We know PS is 0 since we have it statically set in the shader
// Repeat for VS shader
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);
}
#ifdef GLEW_VERSION_4_0
// Read our shader cache, only if supported
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{
char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
ProgramShaderCacheInserter inserter;
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
GLint Supported;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
GLint *Formats = new GLint[Supported];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
ProgramFormat = (GLenum)Formats[0]; // We don't really care about format
delete[] Formats;
}
#endif
}
void ProgramShaderCache::Shutdown(void)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{
PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); ++iter)
g_program_disk_cache.Append(iter->second.program.uid, iter->second.program.Data(), iter->second.program.Size());
g_program_disk_cache.Sync();
g_program_disk_cache.Close();
}
PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); ++iter)
iter->second.Destroy();
pshaders.clear();
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glDeleteBuffers(1, &s_ps_vs_ubo);
s_ps_vs_ubo = 0;
}
// We have no vertex Shader
glBindAttribLocation(entry.program.glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(entry.program.glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
glBindAttribLocation(entry.program.glprogid, SHADER_POSMTX_ATTRIB, "fposmtx");
}
}
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
{
PROGRAMUID uid;
CurrentFShader = PS;
CurrentVShader = VS;
GetProgramShaderId(&uid, CurrentVShader, CurrentFShader);
if (uid.uid.id == 0)
{
CurrentProgram = 0;
glUseProgram(0);
return;
}
// Fragment shaders can survive without Vertex Shaders
// We have a valid fragment shader, let's create our program
std::pair<u32, u32> ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid);
PCache::iterator iter = pshaders.find(ShaderPair);
if (iter != pshaders.end())
{
PCacheEntry &entry = iter->second;
glUseProgram(entry.program.glprogid);
CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid;
return;
}
PCacheEntry entry;
entry.program.vsid = CurrentVShader;
entry.program.psid = CurrentFShader;
entry.program.uid = uid;
entry.program.glprogid = glCreateProgram();
// Right, the program is created now
// Let's attach everything
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.psid);
#ifdef GLEW_VERSION_4_0
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
glProgramParameteri(entry.program.glprogid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
#endif
glLinkProgram(entry.program.glprogid);
glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, uid);
pshaders[ShaderPair] = entry;
CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid;
}
void ProgramShaderCache::SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{
glBufferSubData(GL_UNIFORM_BUFFER, offset * sizeof(float) * 4,
count * sizeof(float) * 4, f);
}
void ProgramShaderCache::SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count)
{
glBufferSubData(GL_UNIFORM_BUFFER, s_vs_data_offset + offset * sizeof(float) * 4,
count * sizeof(float) * 4, f);
}
GLuint ProgramShaderCache::GetCurrentProgram(void)
{
return CurrentProgram;
}
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
{
return pshaders[CurrentShaderProgram].program;
}
void ProgramShaderCache::Init(void)
{
// We have to get the UBO alignment here because
// if we generate a buffer that isn't aligned
// then the UBO will fail.
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
GLint Align;
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &Align);
GLintptr const ps_data_size = ROUND_UP(C_PENVCONST_END * sizeof(float) * 4, Align);
GLintptr const vs_data_size = ROUND_UP(C_VENVCONST_END * sizeof(float) * 4, Align);
s_vs_data_offset = ps_data_size;
// We multiply by *4*4 because we need to get down to basic machine units.
// So multiply by four to get how many floats we have from vec4s
// Then once more to get bytes
glGenBuffers(1, &s_ps_vs_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, s_ps_vs_ubo);
glBufferData(GL_UNIFORM_BUFFER, ps_data_size + vs_data_size, NULL, GL_DYNAMIC_DRAW);
// Now bind the buffer to the index point
// We know PS is 0 since we have it statically set in the shader
// Repeat for VS shader
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);
}
#ifdef GLEW_VERSION_4_0
// Read our shader cache, only if supported
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{
char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
ProgramShaderCacheInserter inserter;
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
GLint Supported;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
GLint *Formats = new GLint[Supported];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
// We don't really care about format
ProgramFormat = (GLenum)Formats[0];
delete[] Formats;
}
#endif
}
void ProgramShaderCache::Shutdown(void)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{
PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); ++iter)
g_program_disk_cache.Append(iter->second.program.uid, iter->second.program.Data(), iter->second.program.Size());
g_program_disk_cache.Sync();
g_program_disk_cache.Close();
}
PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); ++iter)
iter->second.Destroy();
pshaders.clear();
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
glBindBuffer(GL_UNIFORM_BUFFER, 0);
glDeleteBuffers(1, &s_ps_vs_ubo);
s_ps_vs_ubo = 0;
}
}
} // namespace OGL
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p)
{
uid->uid.vsid = _v;

View File

@ -15,8 +15,7 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _ProgramShaderCache_H_
#define _ProgramShaderCache_H_
#pragma once
#include "GLUtil.h"
@ -28,18 +27,18 @@
#include "LinearDiskCache.h"
#include "ConfigManager.h"
union PID
union PID
{
struct
{
struct {
GLuint vsid, psid;
};
u64 id;
};
u64 id;
};
class PROGRAMUID
{
public:
PID uid;
PROGRAMUID()
@ -51,57 +50,63 @@ public:
{
uid.id = r.uid.id;
}
PROGRAMUID(GLuint _v, GLuint _p)
{
uid.vsid = _v;
uid.psid = _p;
}
int GetNumValues() const
u64 GetNumValues() const
{
return uid.id;
}
};
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p);
namespace OGL
{
#define NUM_UNIFORMS 27
const int NUM_UNIFORMS = 27;
extern const char *UniformNames[NUM_UNIFORMS];
extern GLenum ProgramFormat;
struct PROGRAMSHADER
{
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0){}
GLuint glprogid; // opengl program id
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0) {}
// opengl program id
GLuint glprogid;
GLuint vsid, psid;
PROGRAMUID uid;
GLint UniformLocations[NUM_UNIFORMS];
GLint binaryLength;
// TODO at first glance looks bad - malloc/no free/pointer not saved in instance...
u8 *Data()
{
#ifdef GLEW_VERSION_4_0
#ifdef GLEW_VERSION_4_0
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
u8* binary = (u8*)malloc(binaryLength);
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
return binary;
#else
return NULL;
#endif
u8* binary = (u8*)malloc(binaryLength);
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
return binary;
#else
return NULL;
#endif
}
GLint Size()
{
#ifdef GLEW_VERSION_4_0
if(!binaryLength)
#ifdef GLEW_VERSION_4_0
if (!binaryLength)
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
return binaryLength;
#else
#else
return 0;
#endif
#endif
}
};
class ProgramShaderCache
{
struct PCacheEntry
@ -109,50 +114,54 @@ class ProgramShaderCache
PROGRAMSHADER program;
int frameCount;
PCacheEntry() : frameCount(0) {}
void Destroy() {
void Destroy()
{
glDeleteProgram(program.glprogid);
program.glprogid = 0;
}
u8* Data()
{
return program.Data();
}
GLint Size()
{
return program.Size();
}
};
class ProgramShaderCacheInserter : public LinearDiskCacheReader<PROGRAMUID, u8>
{
public:
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
public:
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
{
#ifdef GLEW_VERSION_4_0
PCacheEntry entry;
// The two shaders might not even exist anymore
// But it is fine, no need to worry about that
entry.program.vsid = key.uid.vsid;
entry.program.psid = key.uid.psid;
entry.program.glprogid = glCreateProgram();
glProgramBinary(entry.program.glprogid, ProgramFormat, value, value_size);
GLint success;
glGetProgramiv(entry.program.glprogid, GL_LINK_STATUS, &success);
if (success)
{
#ifdef GLEW_VERSION_4_0
PCacheEntry entry;
// The two shaders might not even exist anymore
// But it is fine, no need to worry about that
entry.program.vsid = key.uid.vsid;
entry.program.psid = key.uid.psid;
entry.program.glprogid = glCreateProgram();
glProgramBinary(entry.program.glprogid, ProgramFormat, value, value_size);
GLint success;
glGetProgramiv(entry.program.glprogid, GL_LINK_STATUS, &success);
if (success)
{
pshaders[std::make_pair(key.uid.psid, key.uid.vsid)] = entry;
glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, key);
}
#endif
pshaders[std::make_pair(key.uid.psid, key.uid.vsid)] = entry;
glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, key);
}
#endif
}
};
typedef std::map<std::pair<u32, u32>, PCacheEntry> PCache;
static PCache pshaders;
@ -162,7 +171,7 @@ class ProgramShaderCache
static GLuint s_ps_vs_ubo;
static GLintptr s_vs_data_offset;
static void SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid);
public:
static PROGRAMSHADER GetShaderProgram(void);
static void SetBothShaders(GLuint PS, GLuint VS);
@ -170,12 +179,9 @@ public:
static void SetMultiPSConstant4fv(unsigned int offset, const float *f, unsigned int count);
static void SetMultiVSConstant4fv(unsigned int offset, const float *f, unsigned int count);
static void Init(void);
static void Shutdown(void);
};
} // namespace OGL
#endif

View File

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

View File

@ -211,7 +211,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
if (pcfmt != PC_TEX_FMT_DXT1)
{
if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
if (bHaveMipMaps && autogen_mips)
{
@ -225,7 +225,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
}
if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
}
else
{
@ -300,7 +300,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glViewport(0, 0, virtual_width, virtual_height);
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
else
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
@ -396,8 +396,8 @@ TextureCache::~TextureCache()
{
if (s_TempFramebuffer)
{
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
s_TempFramebuffer = 0;
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
s_TempFramebuffer = 0;
}
}

View File

@ -61,9 +61,9 @@ static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
void CreateRgbToYuyvProgram()
{
// 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 =
"#version 330 compatibility\n"
@ -132,9 +132,9 @@ void CreateRgbToYuyvProgram()
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 =
"#version 330 compatibility\n"
@ -390,7 +390,7 @@ int EncodeToRamFromTexture(u32 address,GLuint source_texture, bool bFromZBuffer,
s32 expandedWidth = (width + blkW) & (~blkW);
s32 expandedHeight = (height + blkH) & (~blkH);
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(texconv_shader.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(texconv_shader.glprogid);
@ -425,7 +425,7 @@ void EncodeToRamYUYV(GLuint srcTexture, const TargetRectangle& sourceRc, u8* des
{
g_renderer->ResetAPIState();
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_rgbToYuyvProgram.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(s_rgbToYuyvProgram.glprogid);
@ -472,7 +472,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture);
// 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,
GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
@ -486,7 +486,7 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
}
glViewport(0, 0, srcWidth, srcHeight);
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
else
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);

View File

@ -195,7 +195,7 @@ void VertexManager::vFlush()
}
VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
else
{
@ -218,10 +218,10 @@ void VertexManager::vFlush()
if (useDstAlpha && !dualSourcePossible)
{
ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components);
if(g_ActiveConfig.bUseGLSL)
if (g_ActiveConfig.bUseGLSL)
{
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
if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();

View File

@ -16,7 +16,6 @@
// http://code.google.com/p/dolphin-emu/
#include <math.h>
#include <assert.h>
#include "Globals.h"
#include "VideoConfig.h"
@ -55,98 +54,97 @@ bool (*pCompileVertexShader)(VERTEXSHADER&, const char*);
void VertexShaderCache::Init()
{
ShaderEnabled = true;
CurrentShader = 0;
last_entry = NULL;
ShaderEnabled = true;
CurrentShader = 0;
last_entry = NULL;
if(g_ActiveConfig.bUseGLSL)
{
pSetVSConstant4f = SetGLSLVSConstant4f;
pSetVSConstant4fv = SetGLSLVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
pCompileVertexShader = CompileGLSLVertexShader;
}
else
{
pSetVSConstant4f = SetCGVSConstant4f;
pSetVSConstant4fv = SetCGVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
pCompileVertexShader = CompileCGVertexShader;
glEnable(GL_VERTEX_PROGRAM_ARB);
}
if (g_ActiveConfig.bUseGLSL)
{
pSetVSConstant4f = SetGLSLVSConstant4f;
pSetVSConstant4fv = SetGLSLVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
pCompileVertexShader = CompileGLSLVertexShader;
}
else
{
pSetVSConstant4f = SetCGVSConstant4f;
pSetVSConstant4fv = SetCGVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
pCompileVertexShader = CompileCGVertexShader;
glEnable(GL_VERTEX_PROGRAM_ARB);
}
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
#if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{
s_nMaxVertexInstructions = 4096;
}
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{
s_nMaxVertexInstructions = 4096;
}
#endif
}
void VertexShaderCache::Shutdown()
{
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
iter->second.Destroy();
vshaders.clear();
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
iter->second.Destroy();
vshaders.clear();
}
VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
{
VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components);
if (last_entry)
{
if (uid == last_uid)
VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components);
if (last_entry)
{
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
return &last_entry->shader;
if (uid == last_uid)
{
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
return &last_entry->shader;
}
}
}
last_uid = uid;
last_uid = uid;
VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end())
{
VSCacheEntry &entry = iter->second;
VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end())
{
VSCacheEntry &entry = iter->second;
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
return &last_entry->shader;
}
// Make an entry in the table
VSCacheEntry& entry = vshaders[uid];
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
return &last_entry->shader;
}
// Make an entry in the table
VSCacheEntry& entry = vshaders[uid];
last_entry = &entry;
const char *code = GenerateVertexShaderCode(components, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
GetSafeVertexShaderId(&entry.safe_uid, components);
const char *code = GenerateVertexShaderCode(components, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL);
GetSafeVertexShaderId(&entry.safe_uid, components);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, code);
}
SaveData(szTemp, code);
}
#endif
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL;
}
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL;
}
INCSTAT(stats.numVertexShadersCreated);
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
return &last_entry->shader;
INCSTAT(stats.numVertexShadersCreated);
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
return &last_entry->shader;
}
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
@ -156,32 +154,28 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
void VertexShaderCache::DisableShader()
{
if(g_ActiveConfig.bUseGLSL)
assert(true);
if (ShaderEnabled)
{
glDisable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = false;
}
if (ShaderEnabled)
{
glDisable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = false;
}
}
void VertexShaderCache::SetCurrentShader(GLuint Shader)
{
if(g_ActiveConfig.bUseGLSL)
assert(true);
if (!ShaderEnabled)
{
glEnable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled= true;
}
if (CurrentShader != Shader)
{
if(Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
}
if (!ShaderEnabled)
{
glEnable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled= true;
}
if (CurrentShader != Shader)
{
if (Shader != 0)
CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
}
}
// GLSL Specific
bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
@ -205,12 +199,12 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
GLchar* infoLog = new GLchar[length];
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog);
char szTemp[MAX_PATH];
sprintf(szTemp, "vs_%d.txt", result);
FILE *fp = fopen(szTemp, "wb");
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
fclose(fp);
char szTemp[MAX_PATH];
sprintf(szTemp, "vs_%d.txt", result);
FILE *fp = fopen(szTemp, "wb");
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
fclose(fp);
delete[] infoLog;
}
// Don't try to use this shader
@ -223,39 +217,43 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
vs.bGLSL = true;
return true;
}
void SetVSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
{
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for(int a = 0; a < NUM_UNIFORMS; ++a)
if(!strcmp(name, UniformNames[a]))
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
for (int a = 0; a < NUM_UNIFORMS; ++a)
{
if(tmp.UniformLocations[a] == -1)
return;
else
{
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return;
}
if (!strcmp(name, UniformNames[a]))
{
if (tmp.UniformLocations[a] == -1)
return;
else
{
glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return;
}
}
}
}
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};
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, 1);
return;
}
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))
for (unsigned int a = 0; a < 9; ++a)
{
unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
return;
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;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
return;
}
}
}
}
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
@ -265,15 +263,15 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, 1);
return;
}
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))
for (unsigned int a = 0; a < 9; ++a)
{
unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
return;
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;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
return;
}
}
}
}
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
@ -283,157 +281,157 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
ProgramShaderCache::SetMultiVSConstant4fv(const_number, f, count);
return;
}
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))
for (unsigned int a = 0; a < 9; ++a)
{
unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
return;
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;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
return;
}
}
}
}
void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
{
buf[4*i ] = *f++;
buf[4*i+1] = *f++;
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
}
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
{
buf[4*i ] = *f++;
buf[4*i+1] = *f++;
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
}
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetMultiVSConstant4fv(const_number, buf, count);
return;
}
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))
for (unsigned int a = 0; a < 9; ++a)
{
unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
return;
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;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
return;
}
}
}
}
// CG Specific
bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
{
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
}
// Reset GL error before compiling shaders. Yeah, we need to investigate the causes of these.
GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR)
{
ERROR_LOG(VIDEO, "glError %08x before VS!", err);
}
#if defined HAVE_CG && HAVE_CG
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
if (!cgIsProgram(tempprog)) {
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
if (!cgIsProgram(tempprog)) {
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
std::ofstream file(szTemp);
file << pstrprogram;
file.close();
PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp,
g_cgfProf,
cgGetLastListing(g_cgcontext));
cgDestroyProgram(tempprog);
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, "%s", pstrprogram);
return false;
}
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char* penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local");
}
glGenProgramsARB(1, &vs.glprogid);
vs.bGLSL = false;
VertexShaderCache::SetCurrentShader(vs.glprogid);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, "%s", pstrprogram);
return false;
}
if (cgGetError() != CG_NO_ERROR)
{
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram);
}
// This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char* penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local");
}
glGenProgramsARB(1, &vs.glprogid);
vs.bGLSL = false;
VertexShaderCache::SetCurrentShader(vs.glprogid);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog);
}
cgDestroyProgram(tempprog);
#endif
if (g_ActiveConfig.bEnableShaderDebugging)
vs.strprog = pstrprogram;
if (g_ActiveConfig.bEnableShaderDebugging)
vs.strprog = pstrprogram;
return true;
return true;
}
void SetCGVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
}
void SetCGVSConstant4fv(unsigned int const_number, const float *f)
{
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
}
void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
if(GLEW_EXT_gpu_program_parameters)
{
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
}
else
{
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
}
if (GLEW_EXT_gpu_program_parameters)
{
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
}
else
{
for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
}
}
void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{
if(GLEW_EXT_gpu_program_parameters)
{
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
if (GLEW_EXT_gpu_program_parameters)
{
buf[4*i ] = *f++;
buf[4*i+1] = *f++;
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++)
{
buf[4*i ] = *f++;
buf[4*i+1] = *f++;
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
}
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
}
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
}
else
{
for (unsigned int i = 0; i < count; i++)
else
{
float buf[4];
buf[0] = *f++;
buf[1] = *f++;
buf[2] = *f++;
buf[3] = 0.f;
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
for (unsigned int i = 0; i < count; i++)
{
float buf[4];
buf[0] = *f++;
buf[1] = *f++;
buf[2] = *f++;
buf[3] = 0.f;
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
}
}
}
}
// Renderer Functions
@ -457,5 +455,4 @@ void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int cou
pSetMultiVSConstant3fv(const_number, count, f);
}
} // namespace OGL

View File

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