Fix more cases where shader compilation can fail if there are no tex gens.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2556 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
donkopunchstania 2009-03-05 05:10:25 +00:00
parent 0b6bf51c9a
commit cb121dab66

View File

@ -476,21 +476,32 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
// note that we have to scale by the regular texture map's coordinates since this is a texRECT call // note that we have to scale by the regular texture map's coordinates since this is a texRECT call
// (and we have to match with the game's texscale calls) // (and we have to match with the game's texscale calls)
int texcoord = bpmem.tevindref.getTexCoord(i); int texcoord = bpmem.tevindref.getTexCoord(i);
if (texture_mask & (1<<bpmem.tevindref.getTexMap(i))) {
// TODO: I removed a superfluous argument, please check that the resulting expression is correct. (mthuurne 2008-08-27)
WRITE(p, "float2 induv%d=uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", i, texcoord, i/2, (i&1)?"zw":"xy"); //, bpmem.tevindref.getTexMap(i)
char str[16]; if (texcoord < numTexgen) {
sprintf(str, "induv%d", i); if (texture_mask & (1<<bpmem.tevindref.getTexMap(i))) {
WrapNonPow2Tex(p, str, bpmem.tevindref.getTexMap(i), texture_mask); // TODO: I removed a superfluous argument, please check that the resulting expression is correct. (mthuurne 2008-08-27)
WRITE(p, "float3 indtex%d=texRECT(samp%d,induv%d.xy).abg;\n", i, bpmem.tevindref.getTexMap(i), i); WRITE(p, "float2 induv%d=uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", i, texcoord, i/2, (i&1)?"zw":"xy"); //, bpmem.tevindref.getTexMap(i)
char str[16];
sprintf(str, "induv%d", i);
WrapNonPow2Tex(p, str, bpmem.tevindref.getTexMap(i), texture_mask);
WRITE(p, "float3 indtex%d=texRECT(samp%d,induv%d.xy).abg;\n", i, bpmem.tevindref.getTexMap(i), i);
}
else {
WRITE(p, "float3 indtex%d=tex2D(samp%d,uv%d.xy*"I_INDTEXSCALE"[%d].%s).abg;\n", i, bpmem.tevindref.getTexMap(i), texcoord, i/2, (i&1)?"zw":"xy");
}
} }
else { else {
WRITE(p, "float3 indtex%d=tex2D(samp%d,uv%d.xy*"I_INDTEXSCALE"[%d].%s).abg;\n", i, bpmem.tevindref.getTexMap(i), texcoord, i/2, (i&1)?"zw":"xy"); WRITE(p, "float3 indtex%d=tex2D(samp%d,float2(0.0f,0.0f));\n", i, bpmem.tevindref.getTexMap(i));
} }
} }
} }
// HACK to handle cases where the tex gen is not enabled
if (numTexgen == 0) {
WRITE(p, "float3 uv0 = float3(0.0f,0.0f,0.0f);\n");
}
for (int i = 0; i < numStages; i++) for (int i = 0; i < numStages; i++)
WriteStage(p, i, texture_mask); //build the equation for this stage WriteStage(p, i, texture_mask); //build the equation for this stage
@ -570,8 +581,14 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1); int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1);
int texfun = xfregs.texcoords[texcoord].texmtxinfo.projection; int texfun = xfregs.texcoords[texcoord].texmtxinfo.projection;
bool bHasTexCoord = texcoord < bpmem.genMode.numtexgens;
bool bHasIndStage = bpmem.tevind[n].IsActive() && bpmem.tevind[n].bt < bpmem.genMode.numindstages; bool bHasIndStage = bpmem.tevind[n].IsActive() && bpmem.tevind[n].bt < bpmem.genMode.numindstages;
// HACK to handle cases where the tex gen is not enabled
if (!bHasTexCoord) {
texcoord = 0;
}
if (bHasIndStage) { if (bHasIndStage) {
// perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords // perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords
bHasIndStage = true; bHasIndStage = true;
@ -610,11 +627,11 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
WRITE(p, "float2 indtevtrans%d = float2(dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d), dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d));\n", WRITE(p, "float2 indtevtrans%d = float2(dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d), dot("I_INDTEXMTX"[%d].xyz, indtevcrd%d));\n",
n, mtxidx, n, mtxidx+1, n); n, mtxidx, n, mtxidx+1, n);
} }
else if (bpmem.tevind[n].mid <= 5) { // s matrix else if (bpmem.tevind[n].mid <= 5 && bHasTexCoord) { // s matrix
int mtxidx = 2*(bpmem.tevind[n].mid-5); int mtxidx = 2*(bpmem.tevind[n].mid-5);
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n); WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n);
} }
else if (bpmem.tevind[n].mid <= 9) { // t matrix else if (bpmem.tevind[n].mid <= 9 && bHasTexCoord) { // t matrix
int mtxidx = 2*(bpmem.tevind[n].mid-9); int mtxidx = 2*(bpmem.tevind[n].mid-9);
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n); WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n);
} }
@ -714,7 +731,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask)
if(!bHasIndStage) { if(!bHasIndStage) {
// calc tevcord // calc tevcord
//tevcoord.xy = texdim[1].xy * uv1.xy / uv1.z; //tevcoord.xy = texdim[1].xy * uv1.xy / uv1.z;
if(bpmem.genMode.numtexgens) { if(bHasTexCoord) {
if (texture_mask & (1<<texmap)) { if (texture_mask & (1<<texmap)) {
// nonpow2 // nonpow2
if (texfun == XF_TEXPROJ_STQ ) if (texfun == XF_TEXPROJ_STQ )