small code cleanup, and little fixing of errors introduced by mi in my first commit :(

fixed scissor test in direct 3d


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4480 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado 2009-10-30 04:14:43 +00:00
parent 9d57502f1a
commit dd7f6f991f
7 changed files with 46 additions and 48 deletions

View File

@ -310,7 +310,7 @@ static const char *tevAInputTable[] = // CA
"textemp.a", // TEXA,
"rastemp.a", // RASA,
"konsttemp.a", // KONST
"0.0", // ZERO
"0.0f", // ZERO
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
@ -326,7 +326,7 @@ static const char *tevAInputTable2[] = // CA
"textemp", // TEXA,
"rastemp", // RASA,
"konsttemp", // KONST, (hw1 had quarter)
"float4(0.0,0.0,0.0,0.0)", // ZERO
"float4(0.0f,0.0f,0.0f,0.0f)", // ZERO
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
"PADERROR", "PADERROR", "PADERROR", "PADERROR",
@ -342,7 +342,7 @@ static const char *tevRasTable[] =
"ERROR", //4
"alphabump", // use bump alpha
"(alphabump*(255.0f/248.0f))", //normalized
"float4(0.0,0.0,0.0,0.0)", // zero
"float4(0.0f,0.0f,0.0f,0.0f)", // zero
};
static const char *alphaRef[2] =
@ -730,9 +730,9 @@ static void WriteStage(char *&p, int n, u32 texture_mask, bool HLSL)
WRITE(p, " (%s%s",tevCInputTable[cc.d],tevOpTable[cc.op]);
if (cc.a == 15 && cc.b == 15)
WRITE(p, "0");
WRITE(p, "0.0f");
else if (cc.a == 15 && cc.c == 15)
WRITE(p, "0");
WRITE(p, "0.0f");
else if (cc.b == 15 && cc.c == 15)
WRITE(p,"%s",tevCInputTable[cc.a]);
else if (cc.a == 15)
@ -748,7 +748,7 @@ static void WriteStage(char *&p, int n, u32 texture_mask, bool HLSL)
else
{
int cmp = (cc.shift<<1)|cc.op|8; // comparemode stored here
WRITE(p, TEVCMPColorOPTable[cmp],//lockup the function from the op table
WRITE(p, TEVCMPColorOPTable[cmp],//lookup the function from the op table
tevCInputTable[cc.d],
tevCInputTable2[cc.a],
tevCInputTable2[cc.b],
@ -772,9 +772,9 @@ static void WriteStage(char *&p, int n, u32 texture_mask, bool HLSL)
WRITE(p, " (%s%s",tevAInputTable[ac.d],tevOpTable[ac.op]);
if (ac.a == 7 && ac.b == 7)
WRITE(p, "0");
WRITE(p, "0.0f");
else if (ac.a == 7 && ac.c == 7)
WRITE(p, "0");
WRITE(p, "0.0f");
else if (ac.b == 7 && ac.c == 7)
WRITE(p,"%s",tevAInputTable[ac.a]);
else if (ac.a == 7)
@ -843,11 +843,11 @@ void SampleTexture(char *&p, const char *destination, const char *texcoords, con
static const char *tevAlphaFuncsTable[] =
{
"(false)", //ALPHACMP_NEVER 0
"(prev.a <= %s - (1.0f/510.0f))", //ALPHACMP_LESS 1
"(prev.a < %s - (1.0f/510.0f))", //ALPHACMP_LESS 1
"(abs( prev.a - %s ) < (1.0f/255.0f))", //ALPHACMP_EQUAL 2
"(prev.a < %s + (1.0f/510.0f))", //ALPHACMP_LEQUAL 3
"(prev.a >= %s + (1.0f/510.0f))", //ALPHACMP_GREATER 4
"(abs( prev.a - %s ) >= (1.0f/255.0f))", //ALPHACMP_NEQUAL 5
"(prev.a > %s + (1.0f/510.0f))", //ALPHACMP_GREATER 4
"(abs( prev.a - %s ) > (1.0f/255.0f))", //ALPHACMP_NEQUAL 5
"(prev.a > %s - (1.0f/510.0f))", //ALPHACMP_GEQUAL 6
"(true)" //ALPHACMP_ALWAYS 7
};
@ -891,23 +891,24 @@ static bool WriteAlphaTest(char *&p, bool HLSL)
default: PanicAlert("bad logic for alpha test? %08x", op);
}
// Seems we need discard for Cg and clip for d3d. sigh.
if (HLSL)
WRITE(p, "clip( ");
WRITE(p, "clip( (");
else
WRITE(p, "discard(!( ");
int compindex = bpmem.alphaFunc.comp0 % 8;
WRITE(p, tevAlphaFuncsTable[compindex],alphaRef[0]);//lockup the first component from the alpha function table
WRITE(p, tevAlphaFuncsTable[compindex],alphaRef[0]);//lookup the first component from the alpha function table
WRITE(p, tevAlphaFunclogicTable[bpmem.alphaFunc.logic % 4]);//lockup the logic op
WRITE(p, tevAlphaFunclogicTable[bpmem.alphaFunc.logic % 4]);//lookup the logic op
compindex = bpmem.alphaFunc.comp1 % 8;
WRITE(p, tevAlphaFuncsTable[compindex],alphaRef[1]);//lockup the second component from the alpha function table
WRITE(p, tevAlphaFuncsTable[compindex],alphaRef[1]);//lookup the second component from the alpha function table
if (HLSL) {
// clip works differently than discard - discard takes a bool, clip takes a value that kills the pixel on negative
WRITE(p, " ? 1 : -1);\n");
WRITE(p, ") ? 1 : -1);\n");
} else {
WRITE(p, "));\n");
}

View File

@ -168,7 +168,7 @@ const char *GenerateVertexShader(u32 components, bool D3D)
WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
}
else
WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
WRITE(p, " float posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
}
WRITE(p, " float4 rawpos : POSITION) {\n");
WRITE(p, "VS_OUTPUT o;\n");
@ -188,36 +188,36 @@ const char *GenerateVertexShader(u32 components, bool D3D)
}
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
WRITE(p, "float3 _norm0 = float3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
"float3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
WRITE(p, "float3 _norm1 = float3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
WRITE(p, "float3 _norm2 = float3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
else {
WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1.0f);\n");
if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n");
WRITE(p, "float3 _norm0 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
"float3 norm0 = normalize(_norm0);\n");
if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
WRITE(p, "float3 _norm1 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n");
if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
WRITE(p, "float3 _norm2 = float3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n");
}
if (!(components & VB_HAS_NRM0))
WRITE(p, "half3 _norm0 = half3(0,0,0), norm0 = half3(0,0,0);\n");
WRITE(p, "float3 _norm0 = float3(0.0f,0.0f,0.0f), norm0 = float3(0.0f,0.0f,0.0f);\n");
WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n");
WRITE(p, "half4 mat;\n" // = half4(1,1,1,1), lacc = half4(0,0,0,0);\n"
"half3 ldir, h;\n"
"half dist, dist2, attn;\n");
WRITE(p, "float4 mat;\n" // = half4(1,1,1,1), lacc = half4(0,0,0,0);\n"
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
// lights/colors
for (int j = 0; j < xfregs.nNumChans; j++) {
@ -228,12 +228,12 @@ const char *GenerateVertexShader(u32 components, bool D3D)
WRITE(p, "{\n");
WRITE(p, "half4 lacc = half4(1,1,1,1);\n");
WRITE(p, "float4 lacc = float4(1.0f,1.0f,1.0f,1.0f);\n");
if (color.matsource) {// from vertex
if (components & (VB_HAS_COL0 << j))
WRITE(p, "mat = color%d;\n", j);
else
WRITE(p, "mat = half4(1,1,1,1);\n");
WRITE(p, "mat = float4(1.0f,1.0f,1.0f,1.0f);\n");
}
else // from color
WRITE(p, "mat = "I_MATERIALS".C%d;\n", j+2);
@ -243,7 +243,7 @@ const char *GenerateVertexShader(u32 components, bool D3D)
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc = color%d;\n", j);
else
WRITE(p, "lacc = half4(0,0,0,0);\n");
WRITE(p, "lacc = float4(0.0f,0.0f,0.0f,0.0f);\n");
}
else // from color
WRITE(p, "lacc = "I_MATERIALS".C%d;\n", j);
@ -323,7 +323,7 @@ const char *GenerateVertexShader(u32 components, bool D3D)
// zero left over channels
for (int i = xfregs.nNumChans; i < 2; ++i)
WRITE(p, "o.colors[%d] = float4(0,0,0,0);\n", i);
WRITE(p, "o.colors[%d] = float4(0.0f,0.0f,0.0f,0.0f);\n", i);
// transform texcoords
for (int i = 0; i < xfregs.numTexGens; ++i) {
@ -476,11 +476,11 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0f, dot(ldir, "I_LIGHTS".lights[%d].dir.xyz));\n",index);
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, half3(1, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, half3(1,dist,dist2));\n", index, index);
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, float3(1.0f,dist,dist2));\n", index, index);
}
else if (chan.attnfunc == 1) { // specular
WRITE(p, "attn = dot(norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0.0f ? max(0.0f, dot(norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0.0f;\n", index, index);
WRITE(p, "ldir = half3(1,attn,attn*attn);\n");
WRITE(p, "ldir = float3(1,attn,attn*attn);\n");
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, ldir)) / dot("I_LIGHTS".lights[%d].distatt.xyz, ldir);\n", index, index);
}

View File

@ -169,6 +169,7 @@ bool Renderer::Init()
D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
D3D::BeginFrame();
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, true);
return true;
}
@ -412,6 +413,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect
Swap(0,FIELD_PROGRESSIVE,0,0); // we used to swap the buffer here, now we will wait
// until the XFB pointer is updated by VI
D3D::SetRenderState(D3DRS_SCISSORTESTENABLE, true);
}
bool Renderer::SetScissorRect()
@ -600,7 +602,6 @@ void UpdateViewport()
// Stretch picture with increased internal resolution
vp.X = (int)(ceil(xfregs.rawViewport[3] - xfregs.rawViewport[0] - (scissorXOff)) * MValueX);
vp.Y = (int)(ceil(xfregs.rawViewport[4] + xfregs.rawViewport[1] - (scissorYOff)) * MValueY);
vp.Width = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX);
vp.Height = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
//new depth equation , don't know if is correct but...

View File

@ -117,7 +117,7 @@ void PixelShaderCache::Init()
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
"PARAM K0 = { 65536.0, 256.0 };\n"
"PARAM K0 = { 65535.0, 255.0 };\n"
"TEX R2, fragment.texcoord[0], texture[0], RECT;\n"
"MUL R0.x, R2.x, K0.x;\n"
"FRC R0.x, R0.x;\n"

View File

@ -1344,9 +1344,8 @@ void UpdateViewport()
int GLy = (int)ceil(Renderer::GetTargetHeight() - ((int)(xfregs.rawViewport[4] - xfregs.rawViewport[1] - scissorYOff)) * MValueY);
int GLWidth = (int)ceil(abs((int)(2 * xfregs.rawViewport[0])) * MValueX);
int GLHeight = (int)ceil(abs((int)(2 * xfregs.rawViewport[1])) * MValueY);
//new dept equation , don't know if is correct but...
double GLNear = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
double GLFar = xfregs.rawViewport[5] / 16777216.0f;
double GLFar = xfregs.rawViewport[5] / 16777216.0f;
// Update the view port
glViewport(GLx, GLy, GLWidth, GLHeight);

View File

@ -216,16 +216,13 @@ void EncodeToRamUsingShader(FRAGMENTSHADER& shader, GLuint srcTexture, const Tar
// .. and then readback the results.
// TODO: make this less slow.
glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, destAddr);
glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr);
GL_REPORT_ERRORD();
g_framebufferManager.SetFramebuffer(0);
Renderer::RestoreAPIState();
VertexShaderManager::SetViewportChanged();
VertexShaderManager::SetViewportChanged();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
TextureMngr::DisableStage(0);
Renderer::RestoreAPIState();
GL_REPORT_ERRORD();
}

View File

@ -513,7 +513,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
{
glGenTextures(1, (GLuint *)&entry.texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GL_REPORT_ERRORD();
}
else
@ -531,7 +531,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
glDeleteTextures(1,(GLuint *)&entry.texture);
glGenTextures(1, (GLuint *)&entry.texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, entry.texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
GL_REPORT_ERRORD();
}
}
@ -700,8 +700,8 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
glBegin(GL_QUADS);
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.bottom); glVertex2f(-1, 1);
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.top ); glVertex2f(-1, -1);
glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.top ); glVertex2f( 1, -1);
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.top ); glVertex2f(-1, -1);
glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.top ); glVertex2f( 1, -1);
glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.bottom); glVertex2f( 1, 1);
glEnd();