Chromium Code Reviews| Index: src/gpu/gl/GrGLVertexArray.cpp |
| =================================================================== |
| --- src/gpu/gl/GrGLVertexArray.cpp (revision 0) |
| +++ src/gpu/gl/GrGLVertexArray.cpp (revision 0) |
| @@ -0,0 +1,123 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "GrGLVertexArray.h" |
| +#include "GrGpuGL.h" |
| + |
| +#define GPUGL static_cast<GrGpuGL*>(this->getGpu()) |
| +#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X); |
| + |
| +void GrGLAttribArrayState::set(const GrGpuGL* gpu, |
| + int index, |
| + GrGLVertexBuffer* buffer, |
| + GrGLint size, |
| + GrGLenum type, |
| + GrGLboolean normalized, |
| + GrGLsizei stride, |
| + GrGLvoid* offset) { |
| + GrAssert(index >= 0 && index < fAttribArrays.count()); |
| + AttribArray* array = &fAttribArrays[index]; |
| + if (!array->fEnableIsValid || !array->fEnabled) { |
| + GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(index)); |
| + array->fEnableIsValid = true; |
| + array->fEnabled = true; |
| + } |
| + if (!array->fAttribPointerIsValid || |
| + array->fVertexBufferID != buffer->bufferID() || |
| + array->fSize != size || |
| + array->fNormalized != normalized || |
| + array->fStride != stride || |
| + array->fOffset != offset) { |
| + |
| + buffer->bind(); |
| + GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index, |
| + size, |
| + type, |
| + normalized, |
| + stride, |
| + offset)); |
| + array->fAttribPointerIsValid = true; |
| + array->fVertexBufferID = buffer->bufferID(); |
| + array->fSize = size; |
| + array->fNormalized = normalized; |
| + array->fStride = stride; |
| + array->fOffset = offset; |
| + } |
| +} |
| + |
| +void GrGLAttribArrayState::disableUnusedAttribArrays(const GrGpuGL* gpu, uint64_t usedMask) { |
| + int count = fAttribArrays.count(); |
| + for (int i = 0; i < count; ++i) { |
| + if (!(usedMask & 0x1)) { |
| + if (!fAttribArrays[i].fEnableIsValid || fAttribArrays[i].fEnabled) { |
| + GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i)); |
|
robertphillips
2013/03/06 21:00:16
is this supposed to be true?
bsalomon
2013/03/06 21:32:53
Yeah, the bool fEnabledIsValid indicates whether f
|
| + fAttribArrays[i].fEnableIsValid = true; |
| + fAttribArrays[i].fEnabled = false; |
| + } |
| + } |
| + // if the count is greater than 64 then this will become 0 and we will disable arrays 64+. |
| + usedMask >>= 1; |
| + } |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| + |
| +GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount) |
| + : GrResource(gpu, false) |
| + , fID(id) |
| + , fAttribArrays(attribCount) |
| + , fIndexBufferIDIsValid(false) { |
| +} |
| + |
| +void GrGLVertexArray::onAbandon() { |
| + fID = 0; |
| + INHERITED::onAbandon(); |
| +} |
| + |
| +void GrGLVertexArray::onRelease() { |
| + if (0 != fID) { |
| + GL_CALL(DeleteVertexArrays(1, &fID)); |
| + GPUGL->notifyVertexArrayDelete(fID); |
| + fID = 0; |
| + } |
| + INHERITED::onRelease(); |
| +} |
| + |
| +GrGLAttribArrayState* GrGLVertexArray::bind() { |
| + if (0 == fID) { |
| + return NULL; |
| + } |
| + GPUGL->bindVertexArray(fID); |
| + return &fAttribArrays; |
| +} |
| + |
| +GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(const GrGLIndexBuffer* buffer) { |
| + GrGLAttribArrayState* state = this->bind(); |
| + if (NULL != state && NULL != buffer) { |
| + GrGLuint bufferID = buffer->bufferID(); |
| + if (!fIndexBufferIDIsValid || bufferID != fIndexBufferID) { |
| + GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, bufferID)); |
| + fIndexBufferIDIsValid = true; |
| + fIndexBufferID = bufferID; |
| + } |
| + } |
| + return state; |
| +} |
| + |
| +void GrGLVertexArray::notifyIndexBufferDelete(GrGLuint bufferID) { |
| + if (fIndexBufferIDIsValid && bufferID == fIndexBufferID) { |
|
robertphillips
2013/03/06 21:00:16
reset fIndexBufferIDIsValid too?
bsalomon
2013/03/06 21:32:53
We already checked that it's true on the previous
|
| + fIndexBufferID = 0; |
| + } |
| + } |
| + |
| +void GrGLVertexArray::invalidateCachedState() { |
| + int count = fAttribArrays.count(); |
| + for (int i = 0; i < count; ++i) { |
| + fAttribArrays.invalidate(); |
| + } |
| + fIndexBufferIDIsValid = false; |
| +} |