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 |
11 #include "GrTypesPriv.h" | 11 #include "GrTypesPriv.h" |
12 #include "gl/GrGLDefines.h" | 12 #include "gl/GrGLDefines.h" |
13 #include "gl/GrGLTypes.h" | 13 #include "gl/GrGLTypes.h" |
14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
15 | 15 |
| 16 class GrGLBuffer; |
16 class GrGLGpu; | 17 class GrGLGpu; |
17 | 18 |
18 /** | 19 /** |
19 * This sets and tracks the vertex attribute array state. It is used internally
by GrGLVertexArray | 20 * This sets and tracks the vertex attribute array state. It is used internally
by GrGLVertexArray |
20 * (below) but is separate because it is also used to track the state of vertex
array object 0. | 21 * (below) but is separate because it is also used to track the state of vertex
array object 0. |
21 */ | 22 */ |
22 class GrGLAttribArrayState { | 23 class GrGLAttribArrayState { |
23 public: | 24 public: |
24 explicit GrGLAttribArrayState(int arrayCount = 0) { | 25 explicit GrGLAttribArrayState(int arrayCount = 0) { |
25 this->resize(arrayCount); | 26 this->resize(arrayCount); |
26 } | 27 } |
27 | 28 |
28 void resize(int newCount) { | 29 void resize(int newCount) { |
29 fAttribArrayStates.resize_back(newCount); | 30 fAttribArrayStates.resize_back(newCount); |
30 for (int i = 0; i < newCount; ++i) { | 31 for (int i = 0; i < newCount; ++i) { |
31 fAttribArrayStates[i].invalidate(); | 32 fAttribArrayStates[i].invalidate(); |
32 } | 33 } |
33 } | 34 } |
34 | 35 |
35 /** | 36 /** |
36 * This function enables and sets vertex attrib state for the specified attr
ib index. It is | 37 * 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 * assumed that the GrGLAttribArrayState is tracking the state of the curren
tly bound vertex |
38 * array object. | 39 * array object. |
39 */ | 40 */ |
40 void set(GrGLGpu*, | 41 void set(GrGLGpu*, |
41 int attribIndex, | 42 int attribIndex, |
42 GrGLuint vertexBufferID, | 43 const GrGLBuffer* vertexBuffer, |
43 GrVertexAttribType type, | 44 GrVertexAttribType type, |
44 GrGLsizei stride, | 45 GrGLsizei stride, |
45 GrGLvoid* offset); | 46 GrGLvoid* offset); |
46 | 47 |
47 /** | 48 /** |
48 * This function disables vertex attribs not present in the mask. It is assu
med that the | 49 * This function disables vertex attribs not present in the mask. It is assu
med that the |
49 * GrGLAttribArrayState is tracking the state of the currently bound vertex
array object. | 50 * GrGLAttribArrayState is tracking the state of the currently bound vertex
array object. |
50 */ | 51 */ |
51 void disableUnusedArrays(const GrGLGpu*, uint64_t usedAttribArrayMask); | 52 void disableUnusedArrays(const GrGLGpu*, uint64_t usedAttribArrayMask); |
52 | 53 |
53 void invalidate() { | 54 void invalidate() { |
54 int count = fAttribArrayStates.count(); | 55 int count = fAttribArrayStates.count(); |
55 for (int i = 0; i < count; ++i) { | 56 for (int i = 0; i < count; ++i) { |
56 fAttribArrayStates[i].invalidate(); | 57 fAttribArrayStates[i].invalidate(); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 void notifyVertexBufferDelete(GrGLuint id) { | |
61 int count = fAttribArrayStates.count(); | |
62 for (int i = 0; i < count; ++i) { | |
63 if (fAttribArrayStates[i].fAttribPointerIsValid && | |
64 id == fAttribArrayStates[i].fVertexBufferID) { | |
65 fAttribArrayStates[i].invalidate(); | |
66 } | |
67 } | |
68 } | |
69 | |
70 /** | 61 /** |
71 * The number of attrib arrays that this object is configured to track. | 62 * The number of attrib arrays that this object is configured to track. |
72 */ | 63 */ |
73 int count() const { return fAttribArrayStates.count(); } | 64 int count() const { return fAttribArrayStates.count(); } |
74 | 65 |
75 private: | 66 private: |
76 /** | 67 /** |
77 * Tracks the state of glVertexAttribArray for an attribute index. | 68 * Tracks the state of glVertexAttribArray for an attribute index. |
78 */ | 69 */ |
79 struct AttribArrayState { | 70 struct AttribArrayState { |
80 void invalidate() { | 71 void invalidate() { |
81 fEnableIsValid = false; | 72 fEnableIsValid = false; |
82 fAttribPointerIsValid = false; | 73 fVertexBufferUniqueID = SK_InvalidUniqueID; |
83 } | 74 } |
84 | 75 |
85 bool fEnableIsValid; | 76 bool fEnableIsValid; |
86 bool fAttribPointerIsValid; | |
87 bool fEnabled; | 77 bool fEnabled; |
88 GrGLuint fVertexBufferID; | 78 uint32_t fVertexBufferUniqueID; |
89 GrVertexAttribType fType; | 79 GrVertexAttribType fType; |
90 GrGLsizei fStride; | 80 GrGLsizei fStride; |
91 GrGLvoid* fOffset; | 81 GrGLvoid* fOffset; |
92 }; | 82 }; |
93 | 83 |
94 SkSTArray<16, AttribArrayState, true> fAttribArrayStates; | 84 SkSTArray<16, AttribArrayState, true> fAttribArrayStates; |
95 }; | 85 }; |
96 | 86 |
97 /** | 87 /** |
98 * This class represents an OpenGL vertex array object. It manages the lifetime
of the vertex array | 88 * 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. | 89 * and is used to track the state of the vertex array to avoid redundant GL call
s. |
100 */ | 90 */ |
101 class GrGLVertexArray { | 91 class GrGLVertexArray { |
102 public: | 92 public: |
103 GrGLVertexArray(GrGLint id, int attribCount); | 93 GrGLVertexArray(GrGLint id, int attribCount); |
104 | 94 |
105 /** | 95 /** |
106 * Binds this vertex array. If the ID has been deleted or abandoned then nul
lptr is returned. | 96 * Binds this vertex array. If the ID has been deleted or abandoned then nul
lptr is returned. |
107 * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's
attrib bindings is | 97 * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's
attrib bindings is |
108 * returned. | 98 * returned. |
109 */ | 99 */ |
110 GrGLAttribArrayState* bind(GrGLGpu*); | 100 GrGLAttribArrayState* bind(GrGLGpu*); |
111 | 101 |
112 /** | 102 /** |
113 * This is a version of the above function that also binds an index buffer t
o the vertex | 103 * This is a version of the above function that also binds an index buffer t
o the vertex |
114 * array object. | 104 * array object. |
115 */ | 105 */ |
116 GrGLAttribArrayState* bindWithIndexBuffer(GrGLGpu* gpu, GrGLuint indexBuffer
ID); | 106 GrGLAttribArrayState* bindWithIndexBuffer(GrGLGpu* gpu, const GrGLBuffer* in
dexBuffer); |
117 | |
118 void notifyIndexBufferDelete(GrGLuint bufferID); | |
119 | |
120 void notifyVertexBufferDelete(GrGLuint id) { | |
121 fAttribArrays.notifyVertexBufferDelete(id); | |
122 } | |
123 | 107 |
124 GrGLuint arrayID() const { return fID; } | 108 GrGLuint arrayID() const { return fID; } |
125 | 109 |
126 void invalidateCachedState(); | 110 void invalidateCachedState(); |
127 | 111 |
128 private: | 112 private: |
129 GrGLuint fID; | 113 GrGLuint fID; |
130 GrGLAttribArrayState fAttribArrays; | 114 GrGLAttribArrayState fAttribArrays; |
131 GrGLuint fIndexBufferID; | 115 uint32_t fIndexBufferUniqueID; |
132 bool fIndexBufferIDIsValid; | |
133 }; | 116 }; |
134 | 117 |
135 #endif | 118 #endif |
OLD | NEW |