Chromium Code Reviews| Index: src/gpu/gl/GrGLVertexArray.h |
| =================================================================== |
| --- src/gpu/gl/GrGLVertexArray.h (revision 0) |
| +++ src/gpu/gl/GrGLVertexArray.h (revision 0) |
| @@ -0,0 +1,144 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef GrGLVertexArray_DEFINED |
| +#define GrGLVertexArray_DEFINED |
| + |
| +#include "GrResource.h" |
| +#include "gl/GrGLFunctions.h" |
| + |
| +#include "SkTArray.h" |
| + |
| +class GrGLVertexBuffer; |
| +class GrGLIndexBuffer; |
| +class GrGpuGL; |
| + |
| +/** |
| + * This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray |
| + * (below) but is separate because it is also used to track the state of vertex array object 0. |
| + */ |
| +class GrGLAttribArrayState { |
| +public: |
| + explicit GrGLAttribArrayState(int arrayCount = 0) { this->resize(arrayCount); } |
| + |
| + void resize(int newCount) { |
| + fAttribArrays.resize_back(newCount); |
| + for (int i = 0; i < newCount; ++i) { |
| + fAttribArrays[i].invalidate(); |
| + } |
| + } |
| + |
| + /** |
| + * This function enables and sets vertex attrib state for the specified attrib index. It is |
| + * assumed that the GrGLAttribArrayState is tracking the state of the currently bound vertex |
| + * array object. |
| + */ |
| + void set(const GrGpuGL*, |
| + int index, |
| + GrGLVertexBuffer*, |
| + GrGLint size, |
| + GrGLenum type, |
| + GrGLboolean normalized, |
| + GrGLsizei stride, |
| + GrGLvoid* offset); |
| + |
| + /** |
| + * 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. |
| + */ |
| + void disableUnusedAttribArrays(const GrGpuGL*, uint64_t usedAttribArrayMask); |
| + |
| + void invalidate() { |
| + int count = fAttribArrays.count(); |
| + for (int i = 0; i < count; ++i) { |
| + fAttribArrays[i].invalidate(); |
| + } |
| + } |
| + |
| + void notifyVertexBufferDelete(GrGLuint id) { |
| + int count = fAttribArrays.count(); |
| + for (int i = 0; i < count; ++i) { |
| + if (id == fAttribArrays[i].fVertexBufferID) { |
| + fAttribArrays[i].invalidate(); |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * The number of attrib arrays that this object is configured to track. |
| + */ |
| + int count() const { return fAttribArrays.count(); } |
| + |
| +private: |
| + struct AttribArray { |
|
jvanverth1
2013/03/06 17:50:12
I think this struct name is confusing -- isn't it
bsalomon
2013/03/06 18:31:07
Hmm... I get what you mean. It isn't a C array but
robertphillips
2013/03/06 21:00:16
I think that is clearer (AttribArrayState that is)
bsalomon
2013/03/06 21:32:53
Done.
|
| + void invalidate() { |
| + fEnableIsValid = false; |
| + fAttribPointerIsValid = false; |
| + } |
| + |
| + bool fEnableIsValid; |
| + bool fAttribPointerIsValid; |
| + bool fEnabled; |
| + GrGLuint fVertexBufferID; |
| + GrGLint fSize; |
| + GrGLenum fType; |
| + GrGLboolean fNormalized; |
| + GrGLsizei fStride; |
| + GrGLvoid* fOffset; |
| + }; |
| + |
| + SkSTArray<16, AttribArray, true> fAttribArrays; |
| +}; |
| + |
| +/** |
| + * This class represents an OpenGL vertex array object. It manages the lifetime of the vertex array |
| + * and is used to track the state of the vertex array to avoid redundant GL calls. |
| + */ |
| +class GrGLVertexArray : public GrResource { |
| +public: |
| + GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount); |
| + |
| + /** |
| + * Binds this vertex array. If the ID has been deleted or abandoned then NULL is returned. |
| + * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's attrib bindings is |
| + * returned. |
| + */ |
| + GrGLAttribArrayState* bind(); |
| + |
| + /** |
| + * This is a version of the above function that also binds an index buffer to the vertex |
| + * array object. |
| + */ |
| + GrGLAttribArrayState* bindWithIndexBuffer(const GrGLIndexBuffer* indexBuffer); |
| + |
| + void notifyIndexBufferDelete(GrGLuint bufferID); |
| + |
| + void notifyVertexBufferDelete(GrGLuint id) { |
| + fAttribArrays.notifyVertexBufferDelete(id); |
| + } |
| + |
| + GrGLuint arrayID() const { return fID; } |
| + |
| + void invalidateCachedState(); |
| + |
| + virtual size_t sizeInBytes() const SK_OVERRIDE { return 0; } |
| + |
| +protected: |
| + virtual void onAbandon() SK_OVERRIDE; |
| + |
| + virtual void onRelease() SK_OVERRIDE; |
| + |
| +private: |
| + GrGLuint fID; |
| + GrGLAttribArrayState fAttribArrays; |
| + GrGLuint fIndexBufferID; |
| + bool fIndexBufferIDIsValid; |
| + |
| + typedef GrResource INHERITED; |
| +}; |
| + |
| +#endif |