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 #include "GrGLVertexArray.h" | 8 #include "GrGLVertexArray.h" |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 | 10 |
11 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | |
12 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X); | |
13 | 11 |
14 void GrGLAttribArrayState::set(const GrGLGpu* gpu, | 12 void GrGLAttribArrayState::set(const GrGLGpu* gpu, |
15 int index, | 13 int index, |
16 GrGLVertexBuffer* buffer, | 14 GrGLVertexBuffer* buffer, |
17 GrGLint size, | 15 GrGLint size, |
18 GrGLenum type, | 16 GrGLenum type, |
19 GrGLboolean normalized, | 17 GrGLboolean normalized, |
20 GrGLsizei stride, | 18 GrGLsizei stride, |
21 GrGLvoid* offset) { | 19 GrGLvoid* offset) { |
22 SkASSERT(index >= 0 && index < fAttribArrayStates.count()); | 20 SkASSERT(index >= 0 && index < fAttribArrayStates.count()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } else { | 59 } else { |
62 SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[
i].fEnabled); | 60 SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[
i].fEnabled); |
63 } | 61 } |
64 // if the count is greater than 64 then this will become 0 and we will d
isable arrays 64+. | 62 // if the count is greater than 64 then this will become 0 and we will d
isable arrays 64+. |
65 usedMask >>= 1; | 63 usedMask >>= 1; |
66 } | 64 } |
67 } | 65 } |
68 | 66 |
69 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 67 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
70 | 68 |
71 GrGLVertexArray::GrGLVertexArray(GrGLGpu* gpu, GrGLint id, int attribCount) | 69 GrGLVertexArray::GrGLVertexArray(GrGLint id, int attribCount) |
72 : INHERITED(gpu, kCached_LifeCycle) | 70 : fID(id) |
73 , fID(id) | |
74 , fAttribArrays(attribCount) | 71 , fAttribArrays(attribCount) |
75 , fIndexBufferIDIsValid(false) { | 72 , fIndexBufferIDIsValid(false) { |
76 this->registerWithCache(); | |
77 } | 73 } |
78 | 74 |
79 void GrGLVertexArray::onAbandon() { | 75 GrGLAttribArrayState* GrGLVertexArray::bind(GrGLGpu* gpu) { |
80 fID = 0; | |
81 INHERITED::onAbandon(); | |
82 } | |
83 | |
84 void GrGLVertexArray::onRelease() { | |
85 if (0 != fID) { | |
86 GL_CALL(DeleteVertexArrays(1, &fID)); | |
87 GPUGL->notifyVertexArrayDelete(fID); | |
88 fID = 0; | |
89 } | |
90 INHERITED::onRelease(); | |
91 } | |
92 | |
93 GrGLAttribArrayState* GrGLVertexArray::bind() { | |
94 if (0 == fID) { | 76 if (0 == fID) { |
95 return NULL; | 77 return NULL; |
96 } | 78 } |
97 GPUGL->bindVertexArray(fID); | 79 gpu->bindVertexArray(fID); |
98 return &fAttribArrays; | 80 return &fAttribArrays; |
99 } | 81 } |
100 | 82 |
101 GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(const GrGLIndexBuffer
* buffer) { | 83 GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(GrGLGpu* gpu, |
102 GrGLAttribArrayState* state = this->bind(); | 84 const GrGLIndexBuffer
* buffer) { |
| 85 GrGLAttribArrayState* state = this->bind(gpu); |
103 if (state && buffer) { | 86 if (state && buffer) { |
104 GrGLuint bufferID = buffer->bufferID(); | 87 GrGLuint bufferID = buffer->bufferID(); |
105 if (!fIndexBufferIDIsValid || bufferID != fIndexBufferID) { | 88 if (!fIndexBufferIDIsValid || bufferID != fIndexBufferID) { |
106 GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, bufferID)); | 89 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER
, bufferID)); |
107 fIndexBufferIDIsValid = true; | 90 fIndexBufferIDIsValid = true; |
108 fIndexBufferID = bufferID; | 91 fIndexBufferID = bufferID; |
109 } | 92 } |
110 } | 93 } |
111 return state; | 94 return state; |
112 } | 95 } |
113 | 96 |
114 void GrGLVertexArray::notifyIndexBufferDelete(GrGLuint bufferID) { | 97 void GrGLVertexArray::notifyIndexBufferDelete(GrGLuint bufferID) { |
115 if (fIndexBufferIDIsValid && bufferID == fIndexBufferID) { | 98 if (fIndexBufferIDIsValid && bufferID == fIndexBufferID) { |
116 fIndexBufferID = 0; | 99 fIndexBufferID = 0; |
117 } | 100 } |
118 } | 101 } |
119 | 102 |
120 void GrGLVertexArray::invalidateCachedState() { | 103 void GrGLVertexArray::invalidateCachedState() { |
121 fAttribArrays.invalidate(); | 104 fAttribArrays.invalidate(); |
122 fIndexBufferIDIsValid = false; | 105 fIndexBufferIDIsValid = false; |
123 } | 106 } |
OLD | NEW |