attribState = fHWVertexArrayState.bindInternalVertexArray(this);
}
- SkASSERT(vertexBuffer);
- SkASSERT(!vertexBuffer->isMapped());
-
int vaCount = primProc.numAttribs();
+ attribState->enableVertexArrays(this, vaCount);
+
if (vaCount > 0) {
+ SkASSERT(vertexBuffer);
+ SkASSERT(!vertexBuffer->isMapped());
GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride());
-
- size_t vertexOffsetInBytes = stride * baseVertex;
-
- vertexOffsetInBytes += vertexBuffer->baseOffset();
-
- uint32_t usedAttribArraysMask = 0;
- size_t offset = 0;
+ size_t vertexBufferOffsetInBytes = stride * baseVertex + vertexBuffer->baseOffset();
+ size_t attribOffset = 0;
for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) {
const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(attribIndex);
- usedAttribArraysMask |= (1 << attribIndex);
- GrVertexAttribType attribType = attrib.fType;
- attribState->set(this,
- attribIndex,
- vertexBuffer,
- attribType,
- stride,
- reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + offset));
- offset += attrib.fOffset;
+ attribState->set(this, attribIndex, vertexBuffer, attrib.fType, stride,
+ vertexBufferOffsetInBytes + attribOffset);
+ attribOffset += attrib.fOffset;
}
- attribState->disableUnusedArrays(this, usedAttribArraysMask);
}
}
fHWVertexArrayState.setVertexArrayID(this, 0);
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
+ attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fWireRectArrayBuffer.get(), kVec2f_GrVertexAttribType,
2 * sizeof(GrGLfloat), 0);
- attribs->disableUnusedArrays(this, 0x1);
GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges));
GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels));
fHWVertexArrayState.setVertexArrayID(this, 0);
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
+ attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fCopyProgramArrayBuffer.get(), kVec2f_GrVertexAttribType,
2 * sizeof(GrGLfloat), 0);
- attribs->disableUnusedArrays(this, 0x1);
// dst rect edges in NDC (-1 to 1)
int dw = dst->width();
fHWVertexArrayState.setVertexArrayID(this, 0);
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
+ attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fMipmapProgramArrayBuffer.get(), kVec2f_GrVertexAttribType,
2 * sizeof(GrGLfloat), 0);
- attribs->disableUnusedArrays(this, 0x1);
// Set "simple" state once:
GrXferProcessor::BlendInfo blendInfo;
const GrBuffer* vertexBuffer,
GrVertexAttribType type,
GrGLsizei stride,
- GrGLvoid* offset) {
+ size_t offsetInBytes) {
SkASSERT(index >= 0 && index < fAttribArrayStates.count());
AttribArrayState* array = &fAttribArrayStates[index];
- if (!array->fEnableIsValid || !array->fEnabled) {
- GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(index));
- array->fEnableIsValid = true;
- array->fEnabled = true;
- }
if (array->fVertexBufferUniqueID != vertexBuffer->uniqueID() ||
array->fType != type ||
array->fStride != stride ||
- array->fOffset != offset) {
+ array->fOffset != offsetInBytes) {
gpu->bindBuffer(kVertex_GrBufferType, vertexBuffer);
const AttribLayout& layout = attrib_layout(type);
+ const GrGLvoid* offsetAsPtr = reinterpret_cast<const GrGLvoid*>(offsetInBytes);
if (!GrVertexAttribTypeIsIntType(type)) {
GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
layout.fCount,
layout.fType,
layout.fNormalized,
stride,
- offset));
+ offsetAsPtr));
} else {
SkASSERT(gpu->caps()->shaderCaps()->integerSupport());
SkASSERT(!layout.fNormalized);
layout.fCount,
layout.fType,
stride,
- offset));
+ offsetAsPtr));
}
array->fVertexBufferUniqueID = vertexBuffer->uniqueID();
array->fType = type;
array->fStride = stride;
- array->fOffset = offset;
+ array->fOffset = offsetInBytes;
}
}
-void GrGLAttribArrayState::disableUnusedArrays(const GrGLGpu* gpu, uint64_t usedMask) {
- int count = fAttribArrayStates.count();
- for (int i = 0; i < count; ++i) {
- if (!(usedMask & 0x1)) {
- if (!fAttribArrayStates[i].fEnableIsValid || fAttribArrayStates[i].fEnabled) {
- GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i));
- fAttribArrayStates[i].fEnableIsValid = true;
- fAttribArrayStates[i].fEnabled = false;
- }
- } else {
- SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[i].fEnabled);
- }
- // if the count is greater than 64 then this will become 0 and we will disable arrays 64+.
- usedMask >>= 1;
+void GrGLAttribArrayState::enableVertexArrays(const GrGLGpu* gpu, int enabledCount) {
+ SkASSERT(enabledCount <= fAttribArrayStates.count());
+
+ int firstIdxToEnable = fEnabledCountIsValid ? fNumEnabledArrays : 0;
+ for (int i = firstIdxToEnable; i < enabledCount; ++i) {
+ GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(i));
}
+
+ int endIdxToDisable = fEnabledCountIsValid ? fNumEnabledArrays : fAttribArrayStates.count();
+ for (int i = enabledCount; i < endIdxToDisable; ++i) {
+ GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i));
+ }
+
+ fNumEnabledArrays = enabledCount;
+ fEnabledCountIsValid = true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
const GrBuffer* vertexBuffer,
GrVertexAttribType type,
GrGLsizei stride,
- GrGLvoid* offset);
+ size_t offsetInBytes);
/**
- * This function disables vertex attribs not present in the mask. It is assumed that the
- * GrGLAttribArrayState is tracking the state of the currently bound vertex array object.
+ * This function enables the first 'enabledCount' vertex arrays and disables the rest.
*/
- void disableUnusedArrays(const GrGLGpu*, uint64_t usedAttribArrayMask);
+ void enableVertexArrays(const GrGLGpu*, int enabledCount);
void invalidate() {
int count = fAttribArrayStates.count();
for (int i = 0; i < count; ++i) {
fAttribArrayStates[i].invalidate();
}
+ fEnabledCountIsValid = false;
}
/**
* Tracks the state of glVertexAttribArray for an attribute index.
*/
struct AttribArrayState {
- void invalidate() {
- fEnableIsValid = false;
- fVertexBufferUniqueID.makeInvalid();
- }
+ void invalidate() { fVertexBufferUniqueID.makeInvalid(); }
- bool fEnableIsValid;
- bool fEnabled;
- GrGpuResource::UniqueID fVertexBufferUniqueID;
- GrVertexAttribType fType;
- GrGLsizei fStride;
- GrGLvoid* fOffset;
+ GrGpuResource::UniqueID fVertexBufferUniqueID;
+ GrVertexAttribType fType;
+ GrGLsizei fStride;
+ size_t fOffset;
};
- SkSTArray<16, AttribArrayState, true> fAttribArrayStates;
+ SkSTArray<16, AttribArrayState, true> fAttribArrayStates;
+ int fNumEnabledArrays;
+ bool fEnabledCountIsValid;
};
/**