Ensure all vertex attributes (except zero that we always use) are disabled after a resetContext.

Review URL: http://codereview.appspot.com/5309043/


git-svn-id: http://skia.googlecode.com/svn/trunk@2494 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-10-19 13:25:46 +00:00
parent 7a17e3a34f
commit b5b5eaff47
3 changed files with 27 additions and 9 deletions

View File

@ -61,7 +61,7 @@ public:
void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
/**
* Attribute indices
* Attribute indices. These should not overlap. Matrices consume 3 slots.
*/
static int PositionAttributeIdx() { return 0; }
static int TexCoordAttributeIdx(int tcIdx) { return 1 + tcIdx; }
@ -72,10 +72,10 @@ public:
static int EdgeAttributeIdx() { return 3 + GrDrawTarget::kMaxTexCoords; }
static int ViewMatrixAttributeIdx() {
return 2 + GrDrawTarget::kMaxTexCoords;
return 4 + GrDrawTarget::kMaxTexCoords;
}
static int TextureMatrixAttributeIdx(int stage) {
return 5 + GrDrawTarget::kMaxTexCoords + 3 * stage;
return 7 + GrDrawTarget::kMaxTexCoords + 3 * stage;
}
private:

View File

@ -325,6 +325,8 @@ GrGpuGLShaders::GrGpuGLShaders(const GrGLInterface* gl)
this->hasExtension("GL_OES_standard_derivatives");
}
GR_GL_GetIntegerv(gl, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttribs);
fProgramData = NULL;
fProgramCache = new ProgramCache(gl, glslVersion);
@ -361,14 +363,27 @@ void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) {
void GrGpuGLShaders::resetContext() {
INHERITED::resetContext();
fHWGeometryState.fVertexLayout = 0;
fHWGeometryState.fVertexOffset = ~0;
GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx()));
for (int t = 0; t < kMaxTexCoords; ++t) {
GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
// Third party GL code may have left vertex attributes enabled. Some GL
// implementations (osmesa) may read vetex attributes that are not required
// by the current shader. Therefore, we have to ensure that only the
// attributes we require for the current draw are enabled or we may cause an
// invalid read.
// Disable all vertex layout bits so that next flush will assume all
// optional vertex attributes are disabled.
fHWGeometryState.fVertexLayout = 0;
// We always use the this attribute and assume it is always enabled.
int posAttrIdx = GrGLProgram::PositionAttributeIdx();
GL_CALL(EnableVertexAttribArray(posAttrIdx));
// Disable all other vertex attributes.
for (int va = 0; va < fMaxVertexAttribs; ++va) {
if (va != posAttrIdx) {
GL_CALL(DisableVertexAttribArray(va));
}
}
GL_CALL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx()));
fHWProgramID = 0;
}

View File

@ -85,6 +85,9 @@ private:
CachedData* fProgramData;
GrGLuint fHWProgramID;
GrGLProgram fCurrentProgram;
// If we get rid of fixed function subclass this should move
// to the GLCaps struct in parent class
GrGLint fMaxVertexAttribs;
typedef GrGpuGL INHERITED;
};