Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrGLVertexArray_DEFINED | |
| 9 #define GrGLVertexArray_DEFINED | |
| 10 | |
| 11 #include "GrResource.h" | |
| 12 #include "gl/GrGLFunctions.h" | |
| 13 | |
| 14 #include "SkTArray.h" | |
| 15 | |
| 16 class GrGLVertexBuffer; | |
| 17 class GrGLIndexBuffer; | |
| 18 class GrGpuGL; | |
| 19 | |
| 20 /** | |
| 21 * This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray | |
| 22 * (below) but is separate because it is also used to track the state of vertex array object 0. | |
| 23 */ | |
| 24 class GrGLAttribArrayState { | |
| 25 public: | |
| 26 explicit GrGLAttribArrayState(int arrayCount = 0) { this->resize(arrayCount) ; } | |
| 27 | |
| 28 void resize(int newCount) { | |
| 29 fAttribArrays.resize_back(newCount); | |
| 30 for (int i = 0; i < newCount; ++i) { | |
| 31 fAttribArrays[i].invalidate(); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * This function enables and sets vertex attrib state for the specified attr ib index. It is | |
| 37 * assumed that the GrGLAttribArrayState is tracking the state of the curren tly bound vertex | |
| 38 * array object. | |
| 39 */ | |
| 40 void set(const GrGpuGL*, | |
| 41 int index, | |
| 42 GrGLVertexBuffer*, | |
| 43 GrGLint size, | |
| 44 GrGLenum type, | |
| 45 GrGLboolean normalized, | |
| 46 GrGLsizei stride, | |
| 47 GrGLvoid* offset); | |
| 48 | |
| 49 /** | |
| 50 * This function disables vertex attribs not present in the mask. It is assu med that the | |
| 51 * GrGLAttribArrayState is tracking the state of the currently bound vertex array object. | |
| 52 */ | |
| 53 void disableUnusedAttribArrays(const GrGpuGL*, uint64_t usedAttribArrayMask) ; | |
| 54 | |
| 55 void invalidate() { | |
| 56 int count = fAttribArrays.count(); | |
| 57 for (int i = 0; i < count; ++i) { | |
| 58 fAttribArrays[i].invalidate(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void notifyVertexBufferDelete(GrGLuint id) { | |
| 63 int count = fAttribArrays.count(); | |
| 64 for (int i = 0; i < count; ++i) { | |
| 65 if (id == fAttribArrays[i].fVertexBufferID) { | |
| 66 fAttribArrays[i].invalidate(); | |
| 67 } | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * The number of attrib arrays that this object is configured to track. | |
| 73 */ | |
| 74 int count() const { return fAttribArrays.count(); } | |
| 75 | |
| 76 private: | |
| 77 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.
| |
| 78 void invalidate() { | |
| 79 fEnableIsValid = false; | |
| 80 fAttribPointerIsValid = false; | |
| 81 } | |
| 82 | |
| 83 bool fEnableIsValid; | |
| 84 bool fAttribPointerIsValid; | |
| 85 bool fEnabled; | |
| 86 GrGLuint fVertexBufferID; | |
| 87 GrGLint fSize; | |
| 88 GrGLenum fType; | |
| 89 GrGLboolean fNormalized; | |
| 90 GrGLsizei fStride; | |
| 91 GrGLvoid* fOffset; | |
| 92 }; | |
| 93 | |
| 94 SkSTArray<16, AttribArray, true> fAttribArrays; | |
| 95 }; | |
| 96 | |
| 97 /** | |
| 98 * This class represents an OpenGL vertex array object. It manages the lifetime of the vertex array | |
| 99 * and is used to track the state of the vertex array to avoid redundant GL call s. | |
| 100 */ | |
| 101 class GrGLVertexArray : public GrResource { | |
| 102 public: | |
| 103 GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount); | |
| 104 | |
| 105 /** | |
| 106 * Binds this vertex array. If the ID has been deleted or abandoned then NUL L is returned. | |
| 107 * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's attrib bindings is | |
| 108 * returned. | |
| 109 */ | |
| 110 GrGLAttribArrayState* bind(); | |
| 111 | |
| 112 /** | |
| 113 * This is a version of the above function that also binds an index buffer t o the vertex | |
| 114 * array object. | |
| 115 */ | |
| 116 GrGLAttribArrayState* bindWithIndexBuffer(const GrGLIndexBuffer* indexBuffer ); | |
| 117 | |
| 118 void notifyIndexBufferDelete(GrGLuint bufferID); | |
| 119 | |
| 120 void notifyVertexBufferDelete(GrGLuint id) { | |
| 121 fAttribArrays.notifyVertexBufferDelete(id); | |
| 122 } | |
| 123 | |
| 124 GrGLuint arrayID() const { return fID; } | |
| 125 | |
| 126 void invalidateCachedState(); | |
| 127 | |
| 128 virtual size_t sizeInBytes() const SK_OVERRIDE { return 0; } | |
| 129 | |
| 130 protected: | |
| 131 virtual void onAbandon() SK_OVERRIDE; | |
| 132 | |
| 133 virtual void onRelease() SK_OVERRIDE; | |
| 134 | |
| 135 private: | |
| 136 GrGLuint fID; | |
| 137 GrGLAttribArrayState fAttribArrays; | |
| 138 GrGLuint fIndexBufferID; | |
| 139 bool fIndexBufferIDIsValid; | |
| 140 | |
| 141 typedef GrResource INHERITED; | |
| 142 }; | |
| 143 | |
| 144 #endif | |
| OLD | NEW |