Fix two inconsistencies in handling fixed-function texture coordinate set generation
Prevent off-by-one bug leaving the texture coordinate set 0 always enabled if
it ever was used. This makes the code consistent with its apparent purpose.
When enabling / disabling texture coordinate sets, call glPathTexGen
only if path rendering is applicable. This makes the functions
consistent with GrGpuGL::resetContext.
R=cdalton@nvidia.com, bsalomon@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/54403003
git-svn-id: http://skia.googlecode.com/svn/trunk/src@12074 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/gl/GrGLProgram.cpp b/gpu/gl/GrGLProgram.cpp
index 7ddd861..f80bc2e 100644
--- a/gpu/gl/GrGLProgram.cpp
+++ b/gpu/gl/GrGLProgram.cpp
@@ -241,8 +241,11 @@
fColorEffects->setData(fGpu, fUniformManager, colorStages);
fCoverageEffects->setData(fGpu, fUniformManager, coverageStages);
+
+ // TexGen state applies to the the fixed function vertex shader. For custom shaders, it's
+ // ignored, so we don't need to change the texgen settings in that case.
if (!fHasVertexShader) {
- fGpu->disableUnusedTexGen(fNumTexCoordSets);
+ fGpu->flushTexGenSettings(fNumTexCoordSets);
}
}
diff --git a/gpu/gl/GrGpuGL.cpp b/gpu/gl/GrGpuGL.cpp
index 92e496c..2e325d4 100644
--- a/gpu/gl/GrGpuGL.cpp
+++ b/gpu/gl/GrGpuGL.cpp
@@ -2104,9 +2104,7 @@
void GrGpuGL::enableTexGen(int unitIdx,
TexGenComponents components,
const GrGLfloat* coefficients) {
-
SkASSERT(this->glCaps().fixedFunctionSupport());
- SkASSERT(this->caps()->pathRenderingSupport());
SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenComponents);
SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx);
@@ -2142,19 +2140,18 @@
GL_CALL(TexGenfv(GR_GL_S + i, GR_GL_OBJECT_PLANE, plane));
}
- GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx,
- GR_GL_OBJECT_LINEAR,
- components,
- coefficients));
+ if (this->caps()->pathRenderingSupport()) {
+ GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx,
+ GR_GL_OBJECT_LINEAR,
+ components,
+ coefficients));
+ }
memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients,
3 * components * sizeof(GrGLfloat));
-
- fHWActiveTexGenSets = SkTMax(fHWActiveTexGenSets, unitIdx);
}
void GrGpuGL::enableTexGen(int unitIdx, TexGenComponents components, const SkMatrix& matrix) {
-
GrGLfloat coefficients[3 * 3];
SkASSERT(this->glCaps().fixedFunctionSupport());
SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenComponents);
@@ -2178,25 +2175,35 @@
enableTexGen(unitIdx, components, coefficients);
}
-void GrGpuGL::disableUnusedTexGen(int numUsedTexCoordSets) {
-
+void GrGpuGL::flushTexGenSettings(int numUsedTexCoordSets) {
SkASSERT(this->glCaps().fixedFunctionSupport());
SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSets);
- for (int i = numUsedTexCoordSets; i < fHWActiveTexGenSets; i++) {
- if (0 == fHWTexGenSettings[i].fNumComponents) {
- continue;
+ // Only write the inactive tex gens, since active tex gens were written
+ // when they were enabled.
+
+ SkDEBUGCODE(
+ for (int i = 0; i < numUsedTexCoordSets; i++) {
+ SkASSERT(0 != fHWTexGenSettings[i].fNumComponents);
}
+ );
+
+ for (int i = numUsedTexCoordSets; i < fHWActiveTexGenSets; i++) {
+ SkASSERT(0 != fHWTexGenSettings[i].fNumComponents);
this->setTextureUnit(i);
for (int j = 0; j < fHWTexGenSettings[i].fNumComponents; j++) {
GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + j));
}
- GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL));
+
+ if (this->caps()->pathRenderingSupport()) {
+ GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL));
+ }
+
fHWTexGenSettings[i].fNumComponents = 0;
}
- fHWActiveTexGenSets = SkTMin(fHWActiveTexGenSets, numUsedTexCoordSets);
+ fHWActiveTexGenSets = numUsedTexCoordSets;
}
void GrGpuGL::flushMiscFixedFunctionState() {
diff --git a/gpu/gl/GrGpuGL.h b/gpu/gl/GrGpuGL.h
index 7c97080..1a3f1a2 100644
--- a/gpu/gl/GrGpuGL.h
+++ b/gpu/gl/GrGpuGL.h
@@ -51,7 +51,7 @@
};
void enableTexGen(int unitIdx, TexGenComponents, const GrGLfloat* coefficients);
void enableTexGen(int unitIdx, TexGenComponents, const SkMatrix& matrix);
- void disableUnusedTexGen(int numUsedTexCoordSets);
+ void flushTexGenSettings(int numUsedTexCoordSets);
bool shouldUseFixedFunctionTexturing() const {
return this->glCaps().fixedFunctionSupport() &&
this->glCaps().pathRenderingSupport();