From abd9dc61378bf36d365ba5bb2bed6933327be6d2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 21 Jul 2013 18:13:55 -0700 Subject: [PATCH] Use the light computation/type GE accessors. --- GPU/GLES/ShaderManager.cpp | 3 +-- GPU/GLES/StateMapping.cpp | 2 +- GPU/GLES/TransformPipeline.cpp | 13 ++++++------- GPU/GLES/VertexShaderGenerator.cpp | 25 +++++++++++-------------- GPU/GPUState.h | 14 ++++++++------ GPU/ge_constants.h | 2 +- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/GPU/GLES/ShaderManager.cpp b/GPU/GLES/ShaderManager.cpp index 1886e53e41..97cf71efea 100644 --- a/GPU/GLES/ShaderManager.cpp +++ b/GPU/GLES/ShaderManager.cpp @@ -415,8 +415,7 @@ void LinkedShader::updateUniforms() { for (int i = 0; i < 4; i++) { if (dirtyUniforms & (DIRTY_LIGHT0 << i)) { - GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3); - if (type == GE_LIGHTTYPE_DIRECTIONAL) { + if (gstate.isDirectionalLight(i)) { // Prenormalize float x = gstate_c.lightpos[i][0]; float y = gstate_c.lightpos[i][1]; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 3ba5528678..3dcaf83fe7 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -117,7 +117,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) { // TODO: All this setup is soon so expensive that we'll need dirty flags, or simply do it in the command writes where we detect dirty by xoring. Silly to do all this work on every drawcall. if (gstate_c.textureChanged) { - if (gstate.textureMapEnable & 1) { + if (gstate.isTextureMapEnabled()) { textureCache_->SetTexture(); } gstate_c.textureChanged = false; diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 2afcb7e154..dd1133af97 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -276,11 +276,10 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[ for (int l = 0; l < 4; l++) { // can we skip this light? - if ((gstate.lightEnable[l] & 1) == 0) + if (!gstate.isLightChanEnabled(l)) continue; - GELightComputation comp = (GELightComputation)(gstate.ltype[l] & 3); - GELightType type = (GELightType)((gstate.ltype[l] >> 8) & 3); + GELightType type = gstate.getLightType(l); Vec3 toLight(0,0,0); Vec3 lightDir(0,0,0); @@ -290,8 +289,8 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[ else toLight = Vec3(gstate_c.lightpos[l]) - pos; - bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE); - bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE; + bool doSpecular = gstate.isUsingSpecularLight(l); + bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(l); float distanceToLight = toLight.Length(); float dot = 0.0f; @@ -348,7 +347,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[ } } - if (gstate.lightEnable[l] & 1) + if (gstate.isLightChanEnabled(l)) { Color4 lightAmbient(gstate_c.lightColor[0][l], 0.0f); lightSum0 += (lightAmbient * *ambient + diff) * lightScale; @@ -922,7 +921,7 @@ int TransformDrawEngine::EstimatePerVertexCost() { } for (int i = 0; i < 4; i++) { - if (gstate.lightEnable[i] & 1) + if (gstate.isLightChanEnabled(i)) cost += 10; } if (gstate.getUVGenMode() != 0) { diff --git a/GPU/GLES/VertexShaderGenerator.cpp b/GPU/GLES/VertexShaderGenerator.cpp index a552023f22..ece49b8418 100644 --- a/GPU/GLES/VertexShaderGenerator.cpp +++ b/GPU/GLES/VertexShaderGenerator.cpp @@ -93,12 +93,12 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) { if (gstate.isLightingEnabled() || gstate.getUVGenMode() == 2) { // Light bits for (int i = 0; i < 4; i++) { - id->d[1] |= (gstate.ltype[i] & 3) << (i * 4); - id->d[1] |= ((gstate.ltype[i] >> 8) & 3) << (i * 4 + 2); + id->d[1] |= gstate.getLightComputation(i) << (i * 4); + id->d[1] |= gstate.getLightType(i) << (i * 4 + 2); } id->d[1] |= (gstate.materialupdate & 7) << 16; for (int i = 0; i < 4; i++) { - id->d[1] |= (gstate.lightEnable[i] & 1) << (20 + i); + id->d[1] |= (gstate.isLightChanEnabled(i) & 1) << (20 + i); } } } @@ -159,7 +159,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { for (int i = 0; i < 4; i++) { if (i == shadeLight0 || i == shadeLight1) doLight[i] = LIGHT_SHADE; - if ((gstate.lightingEnable & 1) && (gstate.lightEnable[i] & 1)) + if (gstate.isLightingEnabled() && gstate.isLightChanEnabled(i)) doLight[i] = LIGHT_FULL; } } @@ -222,7 +222,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { if (doLight[i] == LIGHT_FULL) { // These are needed for the full thing WRITE(p, "uniform mediump vec3 u_lightdir%i;\n", i); - GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3); + GELightType type = gstate.getLightType(i); if (type != GE_LIGHTTYPE_DIRECTIONAL) WRITE(p, "uniform mediump vec3 u_lightatt%i;\n", i); @@ -234,8 +234,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { WRITE(p, "uniform lowp vec3 u_lightambient%i;\n", i); WRITE(p, "uniform lowp vec3 u_lightdiffuse%i;\n", i); - GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3); - if (comp != GE_LIGHTCOMP_ONLYDIFFUSE) + if (gstate.isUsingSpecularLight(i)) WRITE(p, "uniform lowp vec3 u_lightspecular%i;\n", i); } } @@ -399,10 +398,9 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { if (doLight[i] != LIGHT_FULL) continue; diffuseIsZero = false; - GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3); - if (comp != GE_LIGHTCOMP_ONLYDIFFUSE) + if (gstate.isUsingSpecularLight(i)) specularIsZero = false; - GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3); + GELightType type = gstate.getLightType(i); if (type != GE_LIGHTTYPE_DIRECTIONAL) distanceNeeded = true; } @@ -427,8 +425,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { if (doLight[i] != LIGHT_FULL) continue; - GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3); - GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3); + GELightType type = gstate.getLightType(i); if (type == GE_LIGHTTYPE_DIRECTIONAL) { // We prenormalize light positions for directional lights. @@ -439,8 +436,8 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) { WRITE(p, " toLight /= distance;\n"); } - bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE); - bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE; + bool doSpecular = gstate.isUsingSpecularLight(i); + bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(i); if (poweredDiffuse) { WRITE(p, " mediump float dot%i = pow(dot(toLight, worldnormal), u_matspecular.a);\n", i); diff --git a/GPU/GPUState.h b/GPU/GPUState.h index a0aeda0b28..7463d5a95d 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -249,13 +249,15 @@ struct GPUgstate // Lighting bool isLightingEnabled() const { return lightingEnable & 1; } - bool isLightChanEnabled(int chan) const { return lightEnable[chan] & 1;} - bool isUsingPoweredDiffuseLight(int chan) const { return (ltype[chan] & 0x3) == 0x2; } - bool isUsingSpecularLight(int chan) const { return (ltype[chan] & 0x3) == 0x1 || (ltype[chan] & 0x3) == 0x2; } + bool isLightChanEnabled(int chan) const { return lightEnable[chan] & 1; } + GELightComputation getLightComputation(int chan) const { return static_cast(ltype[chan] & 0x3); } + bool isUsingPoweredDiffuseLight(int chan) const { return getLightComputation(chan) == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE; } + bool isUsingSpecularLight(int chan) const { return getLightComputation(chan) != GE_LIGHTCOMP_ONLYDIFFUSE; } bool isUsingSecondaryColor() const { return lmode & 1; } - bool isDirectionalLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 0; } - bool isPointLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 1; } - bool isSpotLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 2; } + GELightType getLightType(int chan) const { return static_cast((ltype[chan] >> 8) & 3); } + bool isDirectionalLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_DIRECTIONAL; } + bool isPointLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_POINT; } + bool isSpotLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_SPOT; } unsigned int getAmbientR() const { return ambientcolor&0xFF; } unsigned int getAmbientG() const { return (ambientcolor>>8)&0xFF; } diff --git a/GPU/ge_constants.h b/GPU/ge_constants.h index 1a32761dfe..c09275053c 100644 --- a/GPU/ge_constants.h +++ b/GPU/ge_constants.h @@ -340,7 +340,7 @@ enum GEComparison enum GELightType { - GE_LIGHTTYPE_DIRECTIONAL=0, + GE_LIGHTTYPE_DIRECTIONAL = 0, GE_LIGHTTYPE_POINT = 1, GE_LIGHTTYPE_SPOT = 2 };