| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLVertexArray_DEFINED | 8 #ifndef GrGLVertexArray_DEFINED |
| 9 #define GrGLVertexArray_DEFINED | 9 #define GrGLVertexArray_DEFINED |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * This sets and tracks the vertex attribute array state. It is used internally
by GrGLVertexArray | 47 * This sets and tracks the vertex attribute array state. It is used internally
by GrGLVertexArray |
| 48 * (below) but is separate because it is also used to track the state of vertex
array object 0. | 48 * (below) but is separate because it is also used to track the state of vertex
array object 0. |
| 49 */ | 49 */ |
| 50 class GrGLAttribArrayState { | 50 class GrGLAttribArrayState { |
| 51 public: | 51 public: |
| 52 explicit GrGLAttribArrayState(int arrayCount = 0) { | 52 explicit GrGLAttribArrayState(int arrayCount = 0) { |
| 53 this->resize(arrayCount); | 53 this->resize(arrayCount); |
| 54 // glVertexPointer doesn't have a normalization param. | |
| 55 fFixedFunctionVertexArray.fNormalized = false; | |
| 56 fUnusedFixedFunctionArraysDisabled = false; | |
| 57 } | 54 } |
| 58 | 55 |
| 59 void resize(int newCount) { | 56 void resize(int newCount) { |
| 60 fAttribArrayStates.resize_back(newCount); | 57 fAttribArrayStates.resize_back(newCount); |
| 61 for (int i = 0; i < newCount; ++i) { | 58 for (int i = 0; i < newCount; ++i) { |
| 62 fAttribArrayStates[i].invalidate(); | 59 fAttribArrayStates[i].invalidate(); |
| 63 } | 60 } |
| 64 } | 61 } |
| 65 | 62 |
| 66 /** | 63 /** |
| 67 * This function enables and sets vertex attrib state for the specified attr
ib index. It is | 64 * This function enables and sets vertex attrib state for the specified attr
ib index. It is |
| 68 * assumed that the GrGLAttribArrayState is tracking the state of the curren
tly bound vertex | 65 * assumed that the GrGLAttribArrayState is tracking the state of the curren
tly bound vertex |
| 69 * array object. | 66 * array object. |
| 70 */ | 67 */ |
| 71 void set(const GrGpuGL*, | 68 void set(const GrGpuGL*, |
| 72 int index, | 69 int index, |
| 73 GrGLVertexBuffer*, | 70 GrGLVertexBuffer*, |
| 74 GrGLint size, | 71 GrGLint size, |
| 75 GrGLenum type, | 72 GrGLenum type, |
| 76 GrGLboolean normalized, | 73 GrGLboolean normalized, |
| 77 GrGLsizei stride, | 74 GrGLsizei stride, |
| 78 GrGLvoid* offset); | 75 GrGLvoid* offset); |
| 79 | 76 |
| 80 void setFixedFunctionVertexArray(const GrGpuGL*, | |
| 81 GrGLVertexBuffer*, | |
| 82 GrGLint size, | |
| 83 GrGLenum type, | |
| 84 GrGLsizei stride, | |
| 85 GrGLvoid* offset); | |
| 86 | |
| 87 /** | 77 /** |
| 88 * This function disables vertex attribs not present in the mask. It is assu
med that the | 78 * This function disables vertex attribs not present in the mask. It is assu
med that the |
| 89 * GrGLAttribArrayState is tracking the state of the currently bound vertex
array object. | 79 * GrGLAttribArrayState is tracking the state of the currently bound vertex
array object. |
| 90 */ | 80 */ |
| 91 void disableUnusedArrays(const GrGpuGL*, uint64_t usedAttribArrayMask, bool
usingFFVertexArray); | 81 void disableUnusedArrays(const GrGpuGL*, uint64_t usedAttribArrayMask); |
| 92 | 82 |
| 93 void invalidate() { | 83 void invalidate() { |
| 94 int count = fAttribArrayStates.count(); | 84 int count = fAttribArrayStates.count(); |
| 95 for (int i = 0; i < count; ++i) { | 85 for (int i = 0; i < count; ++i) { |
| 96 fAttribArrayStates[i].invalidate(); | 86 fAttribArrayStates[i].invalidate(); |
| 97 } | 87 } |
| 98 fFixedFunctionVertexArray.invalidate(); | |
| 99 fUnusedFixedFunctionArraysDisabled = false; | |
| 100 } | 88 } |
| 101 | 89 |
| 102 void notifyVertexBufferDelete(GrGLuint id) { | 90 void notifyVertexBufferDelete(GrGLuint id) { |
| 103 int count = fAttribArrayStates.count(); | 91 int count = fAttribArrayStates.count(); |
| 104 for (int i = 0; i < count; ++i) { | 92 for (int i = 0; i < count; ++i) { |
| 105 if (fAttribArrayStates[i].fAttribPointerIsValid && | 93 if (fAttribArrayStates[i].fAttribPointerIsValid && |
| 106 id == fAttribArrayStates[i].fVertexBufferID) { | 94 id == fAttribArrayStates[i].fVertexBufferID) { |
| 107 fAttribArrayStates[i].invalidate(); | 95 fAttribArrayStates[i].invalidate(); |
| 108 } | 96 } |
| 109 } | 97 } |
| 110 if (fFixedFunctionVertexArray.fAttribPointerIsValid && | |
| 111 id == fFixedFunctionVertexArray.fVertexBufferID) { | |
| 112 fFixedFunctionVertexArray.invalidate(); | |
| 113 } | |
| 114 } | 98 } |
| 115 | 99 |
| 116 /** | 100 /** |
| 117 * The number of attrib arrays that this object is configured to track. | 101 * The number of attrib arrays that this object is configured to track. |
| 118 */ | 102 */ |
| 119 int count() const { return fAttribArrayStates.count(); } | 103 int count() const { return fAttribArrayStates.count(); } |
| 120 | 104 |
| 121 private: | 105 private: |
| 122 /** | 106 /** |
| 123 * Tracks the state of glVertexAttribArray for an attribute index. | 107 * Tracks the state of glVertexAttribArray for an attribute index. |
| 124 */ | 108 */ |
| 125 struct AttribArrayState { | 109 struct AttribArrayState { |
| 126 void invalidate() { | 110 void invalidate() { |
| 127 fEnableIsValid = false; | 111 fEnableIsValid = false; |
| 128 fAttribPointerIsValid = false; | 112 fAttribPointerIsValid = false; |
| 129 } | 113 } |
| 130 | 114 |
| 131 bool fEnableIsValid; | 115 bool fEnableIsValid; |
| 132 bool fAttribPointerIsValid; | 116 bool fAttribPointerIsValid; |
| 133 bool fEnabled; | 117 bool fEnabled; |
| 134 GrGLuint fVertexBufferID; | 118 GrGLuint fVertexBufferID; |
| 135 GrGLint fSize; | 119 GrGLint fSize; |
| 136 GrGLenum fType; | 120 GrGLenum fType; |
| 137 GrGLboolean fNormalized; | 121 GrGLboolean fNormalized; |
| 138 GrGLsizei fStride; | 122 GrGLsizei fStride; |
| 139 GrGLvoid* fOffset; | 123 GrGLvoid* fOffset; |
| 140 }; | 124 }; |
| 141 | 125 |
| 142 SkSTArray<16, AttribArrayState, true> fAttribArrayStates; | 126 SkSTArray<16, AttribArrayState, true> fAttribArrayStates; |
| 143 | |
| 144 // Tracks the array specified by glVertexPointer. | |
| 145 AttribArrayState fFixedFunctionVertexArray; | |
| 146 | |
| 147 // Tracks whether we've disabled the other fixed function arrays that we don
't | |
| 148 // use (e.g. glNormalPointer). | |
| 149 bool fUnusedFixedFunctionArraysDisabled; | |
| 150 }; | 127 }; |
| 151 | 128 |
| 152 /** | 129 /** |
| 153 * This class represents an OpenGL vertex array object. It manages the lifetime
of the vertex array | 130 * This class represents an OpenGL vertex array object. It manages the lifetime
of the vertex array |
| 154 * and is used to track the state of the vertex array to avoid redundant GL call
s. | 131 * and is used to track the state of the vertex array to avoid redundant GL call
s. |
| 155 */ | 132 */ |
| 156 class GrGLVertexArray : public GrResource { | 133 class GrGLVertexArray : public GrResource { |
| 157 public: | 134 public: |
| 158 GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount); | 135 GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount); |
| 159 | 136 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 190 private: | 167 private: |
| 191 GrGLuint fID; | 168 GrGLuint fID; |
| 192 GrGLAttribArrayState fAttribArrays; | 169 GrGLAttribArrayState fAttribArrays; |
| 193 GrGLuint fIndexBufferID; | 170 GrGLuint fIndexBufferID; |
| 194 bool fIndexBufferIDIsValid; | 171 bool fIndexBufferIDIsValid; |
| 195 | 172 |
| 196 typedef GrResource INHERITED; | 173 typedef GrResource INHERITED; |
| 197 }; | 174 }; |
| 198 | 175 |
| 199 #endif | 176 #endif |
| OLD | NEW |