From dbdd461a53cfcdf4f469c3ebf8cdd3a6f35ae33c Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 22 Jan 2013 22:27:03 +0100 Subject: [PATCH] Fix issue with vertex shader IDs. Write the 4th component of packed vectors. The latter makes sure we leave no holes in the CPU writebuffer. --- GPU/GLES/FragmentShaderGenerator.cpp | 12 ++++++++++++ GPU/GLES/VertexDecoder.cpp | 16 +++++++++++----- GPU/GLES/VertexShaderGenerator.cpp | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 51f3541802..94355e14cf 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -34,6 +34,8 @@ #define WRITE p+=sprintf +// #define DEBUG_SHADER + // GL_NV_shader_framebuffer_fetch looks interesting.... // Here we must take all the bits of the gstate that determine what the fragment shader will @@ -72,6 +74,8 @@ void ComputeFragmentShaderID(FragmentShaderID *id) void GenerateFragmentShader(char *buffer) { char *p = buffer; + + #if defined(GLSL_ES_1_0) WRITE(p, "precision mediump float;\n"); #elif !defined(FORCE_OPENGL_2_0) @@ -186,8 +190,16 @@ void GenerateFragmentShader(char *buffer) WRITE(p, " v = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n"); // WRITE(p, " v.x = v_depth;\n"); } + } +#ifdef DEBUG_SHADER + if (doTexture) { + WRITE(p, " v = texture2D(tex, v_texcoord);\n"); + } else { + WRITE(p, " v = vec4(1,0,1,1);\n"); + } +#endif WRITE(p, " gl_FragColor = v;\n"); WRITE(p, "}\n"); } diff --git a/GPU/GLES/VertexDecoder.cpp b/GPU/GLES/VertexDecoder.cpp index f3b7dc0d57..5f64f9650c 100644 --- a/GPU/GLES/VertexDecoder.cpp +++ b/GPU/GLES/VertexDecoder.cpp @@ -50,11 +50,11 @@ void PrintDecodedVertex(VertexReader &vtx) { printf("P: %f %f %f\n", pos[0], pos[1], pos[2]); } -const int tcsize[4] = {0,2,4,8}, tcalign[4] = {0,1,2,4}; -const int colsize[8] = {0,0,0,0,2,2,2,4}, colalign[8] = {0,0,0,0,2,2,2,4}; -const int nrmsize[4] = {0,3,6,12}, nrmalign[4] = {0,1,2,4}; -const int possize[4] = {0,3,6,12}, posalign[4] = {0,1,2,4}; -const int wtsize[4] = {0,1,2,4}, wtalign[4] = {0,1,2,4}; +const u8 tcsize[4] = {0,2,4,8}, tcalign[4] = {0,1,2,4}; +const u8 colsize[8] = {0,0,0,0,2,2,2,4}, colalign[8] = {0,0,0,0,2,2,2,4}; +const u8 nrmsize[4] = {0,3,6,12}, nrmalign[4] = {0,1,2,4}; +const u8 possize[4] = {0,3,6,12}, posalign[4] = {0,1,2,4}; +const u8 wtsize[4] = {0,1,2,4}, wtalign[4] = {0,1,2,4}; inline int align(int n, int align) { return (n + (align - 1)) & ~(align - 1); @@ -283,6 +283,7 @@ void VertexDecoder::Step_NormalS8() const const s8 *sv = (const s8*)(ptr_ + nrmoff); for (int j = 0; j < 3; j++) normal[j] = sv[j] ^ xorval; + normal[3] = 0; } void VertexDecoder::Step_NormalS16() const @@ -294,6 +295,7 @@ void VertexDecoder::Step_NormalS16() const const s16 *sv = (const s16*)(ptr_ + nrmoff); for (int j = 0; j < 3; j++) normal[j] = sv[j] ^ xorval ; + normal[3] = 0; } void VertexDecoder::Step_NormalFloat() const @@ -361,6 +363,7 @@ void VertexDecoder::Step_PosS8() const const s8 *sv = (const s8*)(ptr_ + posoff); for (int j = 0; j < 3; j++) v[j] = sv[j]; + v[3] = 0; } void VertexDecoder::Step_PosS16() const @@ -369,6 +372,7 @@ void VertexDecoder::Step_PosS16() const const s16 *sv = (const s16*)(ptr_ + posoff); for (int j = 0; j < 3; j++) v[j] = sv[j]; + v[3] = 0; } void VertexDecoder::Step_PosFloat() const @@ -386,6 +390,7 @@ void VertexDecoder::Step_PosS8Through() const v[0] = sv[0]; v[1] = sv[1]; v[2] = sv[2]; + v[3] = 0; } void VertexDecoder::Step_PosS16Through() const @@ -395,6 +400,7 @@ void VertexDecoder::Step_PosS16Through() const v[0] = sv[0]; v[1] = sv[1]; v[2] = sv[2]; + v[3] = 0; } void VertexDecoder::Step_PosFloatThrough() const diff --git a/GPU/GLES/VertexShaderGenerator.cpp b/GPU/GLES/VertexShaderGenerator.cpp index 8bbdd0cbe1..ba45d20259 100644 --- a/GPU/GLES/VertexShaderGenerator.cpp +++ b/GPU/GLES/VertexShaderGenerator.cpp @@ -82,7 +82,7 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim) // Okay, d[1] coming up. ============== id->d[1] |= (gstate.lightingEnable & 1) << 19; - if (gstate.lightingEnable & 1) { + if ((gstate.lightingEnable & 1) || gstate.getUVGenMode() == 2) { // Light bits for (int i = 0; i < 4; i++) { id->d[1] |= (gstate.ltype[i] & 3) << (i * 4);