Remove unused texture coordinate flags.
Currently we support 5 texture stages, each with 5 possible texture coordinate attributes.
However, we only ever use one explicit texture coordinate. This change removes all but one
(now named just "aTexCoord") of the possible explicit texture coordinates.
Review URL: https://codereview.appspot.com/7308094/
git-svn-id: http://skia.googlecode.com/svn/trunk@7737 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index a5014a6..8620c5c 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -25,19 +25,14 @@
SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false, "Print the source code for all shaders generated.");
+#define TEX_ATTR_NAME "aTexCoord"
#define COL_ATTR_NAME "aColor"
#define COV_ATTR_NAME "aCoverage"
#define EDGE_ATTR_NAME "aEdge"
namespace {
-inline void tex_attr_name(int coordIdx, SkString* s) {
- *s = "aTexCoord";
- s->appendS32(coordIdx);
-}
-
inline const char* declared_color_output_name() { return "fsColorOut"; }
inline const char* dual_source_output_name() { return "dualSourceOut"; }
-
}
void GrGLProgram::BuildDesc(const GrDrawState& drawState,
@@ -731,14 +726,10 @@
}
// add texture coordinates that are used to the list of vertex attr decls
- SkString texCoordAttrs[GrDrawState::kMaxTexCoords];
- for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
- if (GrDrawState::VertexUsesTexCoordIdx(t, layout)) {
- tex_attr_name(t, texCoordAttrs + t);
- builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
- GrGLShaderVar::kAttribute_TypeModifier,
- texCoordAttrs[t].c_str());
- }
+ if (GrDrawState::VertexUsesTexCoords(layout)) {
+ builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
+ GrGLShaderVar::kAttribute_TypeModifier,
+ TEX_ATTR_NAME);
}
///////////////////////////////////////////////////////////////////////////
@@ -757,13 +748,11 @@
const char* inCoords;
// figure out what our input coords are
- int tcIdx = GrDrawState::VertexTexCoordsForStage(s, layout);
- if (tcIdx < 0) {
+ if (!GrDrawState::StageUsesTexCoords(layout, s)) {
inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is enabled.
- GrAssert(texCoordAttrs[tcIdx].size());
- inCoords = texCoordAttrs[tcIdx].c_str();
+ inCoords = TEX_ATTR_NAME;
}
builder.setCurrentStage(s);
@@ -853,15 +842,12 @@
const char* inCoords;
// figure out what our input coords are
- int tcIdx =
- GrDrawState::VertexTexCoordsForStage(s, layout);
- if (tcIdx < 0) {
+ if (!GrDrawState::StageUsesTexCoords(layout, s)) {
inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is
// enabled.
- GrAssert(texCoordAttrs[tcIdx].size());
- inCoords = texCoordAttrs[tcIdx].c_str();
+ inCoords = TEX_ATTR_NAME;
}
// stages don't know how to deal with a scalar input. (Maybe they should. We
@@ -945,7 +931,6 @@
}
if (!this->bindOutputsAttribsAndLinkProgram(builder,
- texCoordAttrs,
isColorDeclared,
dualSourceOutputWritten)) {
return false;
@@ -959,7 +944,6 @@
}
bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
- SkString texCoordAttrNames[],
bool bindColorOut,
bool bindDualSrcOut) {
GL_CALL_RET(fProgramID, CreateProgram());
@@ -984,14 +968,7 @@
GL_CALL(BindAttribLocation(fProgramID,
PositionAttributeIdx(),
builder.positionAttribute().c_str()));
- for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
- if (texCoordAttrNames[t].size()) {
- GL_CALL(BindAttribLocation(fProgramID,
- TexCoordAttributeIdx(t),
- texCoordAttrNames[t].c_str()));
- }
- }
-
+ GL_CALL(BindAttribLocation(fProgramID, TexCoordAttributeIdx(), TEX_ATTR_NAME));
GL_CALL(BindAttribLocation(fProgramID, ColorAttributeIdx(), COL_ATTR_NAME));
GL_CALL(BindAttribLocation(fProgramID, CoverageAttributeIdx(), COV_ATTR_NAME));
GL_CALL(BindAttribLocation(fProgramID, EdgeAttributeIdx(), EDGE_ATTR_NAME));
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index bdf5665..2c3c973 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -85,7 +85,7 @@
static int ColorAttributeIdx() { return 1; }
static int CoverageAttributeIdx() { return 2; }
static int EdgeAttributeIdx() { return 3; }
- static int TexCoordAttributeIdx(int tcIdx) { return 4 + tcIdx; }
+ static int TexCoordAttributeIdx() { return 4; }
/**
* Some GL state that is relevant to programs is not stored per-program. In particular vertex
@@ -227,7 +227,6 @@
// Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program
bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
- SkString texCoordAttrNames[GrDrawState::kMaxTexCoords],
bool bindColorOut,
bool bindDualSrcOut);
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 8ebe7a2..84e3b6d 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -217,26 +217,26 @@
int newColorOffset;
int newCoverageOffset;
- int newTexCoordOffsets[GrDrawState::kMaxTexCoords];
+ int newTexCoordOffset;
int newEdgeOffset;
GrVertexLayout currLayout = this->getDrawState().getVertexLayout();
- GrGLsizei newStride = GrDrawState::VertexSizeAndOffsetsByIdx(currLayout,
- newTexCoordOffsets,
- &newColorOffset,
- &newCoverageOffset,
- &newEdgeOffset);
+ GrGLsizei newStride = GrDrawState::VertexSizeAndOffsets(currLayout,
+ &newTexCoordOffset,
+ &newColorOffset,
+ &newCoverageOffset,
+ &newEdgeOffset);
int oldColorOffset;
int oldCoverageOffset;
- int oldTexCoordOffsets[GrDrawState::kMaxTexCoords];
+ int oldTexCoordOffset;
int oldEdgeOffset;
- GrGLsizei oldStride = GrDrawState::VertexSizeAndOffsetsByIdx(fHWGeometryState.fVertexLayout,
- oldTexCoordOffsets,
- &oldColorOffset,
- &oldCoverageOffset,
- &oldEdgeOffset);
+ GrGLsizei oldStride = GrDrawState::VertexSizeAndOffsets(fHWGeometryState.fVertexLayout,
+ &oldTexCoordOffset,
+ &oldColorOffset,
+ &oldCoverageOffset,
+ &oldEdgeOffset);
int extraVertexOffset;
this->setBuffers(info.isIndexed(), &extraVertexOffset, startIndexOffset);
@@ -254,19 +254,17 @@
fHWGeometryState.fVertexOffset = vertexOffset;
}
- for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) {
- if (newTexCoordOffsets[t] > 0) {
- GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]);
- int idx = GrGLProgram::TexCoordAttributeIdx(t);
- if (oldTexCoordOffsets[t] <= 0) {
- GL_CALL(EnableVertexAttribArray(idx));
- GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
- } else if (allOffsetsChange || newTexCoordOffsets[t] != oldTexCoordOffsets[t]) {
- GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
- }
- } else if (oldTexCoordOffsets[t] > 0) {
- GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
+ if (newTexCoordOffset > 0) {
+ GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffset);
+ int idx = GrGLProgram::TexCoordAttributeIdx();
+ if (oldTexCoordOffset <= 0) {
+ GL_CALL(EnableVertexAttribArray(idx));
+ GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
+ } else if (allOffsetsChange || newTexCoordOffset != oldTexCoordOffset) {
+ GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset));
}
+ } else if (oldTexCoordOffset > 0) {
+ GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx()));
}
if (newColorOffset > 0) {