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 "GrGLBuffer.h" |
9 #include "GrGLGpu.h" | 10 #include "GrGLGpu.h" |
10 | 11 |
11 struct AttribLayout { | 12 struct AttribLayout { |
12 GrGLint fCount; | 13 GrGLint fCount; |
13 GrGLenum fType; | 14 GrGLenum fType; |
14 GrGLboolean fNormalized; // Only used by floating point types. | 15 GrGLboolean fNormalized; // Only used by floating point types. |
15 }; | 16 }; |
16 | 17 |
17 static const AttribLayout gLayouts[kGrVertexAttribTypeCount] = { | 18 static const AttribLayout gLayouts[kGrVertexAttribTypeCount] = { |
18 {1, GR_GL_FLOAT, false}, // kFloat_GrVertexAttribType | 19 {1, GR_GL_FLOAT, false}, // kFloat_GrVertexAttribType |
(...skipping 12 matching lines...) Expand all Loading... |
31 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 32 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
32 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 33 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
33 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); | 34 GR_STATIC_ASSERT(4 == kUByte_GrVertexAttribType); |
34 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 35 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
35 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType); | 36 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType); |
36 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); | 37 GR_STATIC_ASSERT(7 == kInt_GrVertexAttribType); |
37 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType); | 38 GR_STATIC_ASSERT(8 == kUint_GrVertexAttribType); |
38 | 39 |
39 void GrGLAttribArrayState::set(GrGLGpu* gpu, | 40 void GrGLAttribArrayState::set(GrGLGpu* gpu, |
40 int index, | 41 int index, |
41 GrGLuint vertexBufferID, | 42 const GrGLBuffer* vertexBuffer, |
42 GrVertexAttribType type, | 43 GrVertexAttribType type, |
43 GrGLsizei stride, | 44 GrGLsizei stride, |
44 GrGLvoid* offset) { | 45 GrGLvoid* offset) { |
45 SkASSERT(index >= 0 && index < fAttribArrayStates.count()); | 46 SkASSERT(index >= 0 && index < fAttribArrayStates.count()); |
46 AttribArrayState* array = &fAttribArrayStates[index]; | 47 AttribArrayState* array = &fAttribArrayStates[index]; |
47 if (!array->fEnableIsValid || !array->fEnabled) { | 48 if (!array->fEnableIsValid || !array->fEnabled) { |
48 GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(index)); | 49 GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(index)); |
49 array->fEnableIsValid = true; | 50 array->fEnableIsValid = true; |
50 array->fEnabled = true; | 51 array->fEnabled = true; |
51 } | 52 } |
52 if (!array->fAttribPointerIsValid || | 53 if (array->fVertexBufferUniqueID != vertexBuffer->getUniqueID() || |
53 array->fVertexBufferID != vertexBufferID || | |
54 array->fType != type || | 54 array->fType != type || |
55 array->fStride != stride || | 55 array->fStride != stride || |
56 array->fOffset != offset) { | 56 array->fOffset != offset) { |
57 | 57 gpu->bindBuffer(kVertex_GrBufferType, vertexBuffer); |
58 gpu->bindVertexBuffer(vertexBufferID); | |
59 const AttribLayout& layout = gLayouts[type]; | 58 const AttribLayout& layout = gLayouts[type]; |
60 if (!GrVertexAttribTypeIsIntType(type)) { | 59 if (!GrVertexAttribTypeIsIntType(type)) { |
61 GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index, | 60 GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index, |
62 layout.fCount, | 61 layout.fCount, |
63 layout.fType, | 62 layout.fType, |
64 layout.fNormalize
d, | 63 layout.fNormalize
d, |
65 stride, | 64 stride, |
66 offset)); | 65 offset)); |
67 } else { | 66 } else { |
68 SkASSERT(gpu->caps()->shaderCaps()->integerSupport()); | 67 SkASSERT(gpu->caps()->shaderCaps()->integerSupport()); |
69 SkASSERT(!layout.fNormalized); | 68 SkASSERT(!layout.fNormalized); |
70 GR_GL_CALL(gpu->glInterface(), VertexAttribIPointer(index, | 69 GR_GL_CALL(gpu->glInterface(), VertexAttribIPointer(index, |
71 layout.fCount, | 70 layout.fCount, |
72 layout.fType, | 71 layout.fType, |
73 stride, | 72 stride, |
74 offset)); | 73 offset)); |
75 } | 74 } |
76 array->fAttribPointerIsValid = true; | 75 array->fVertexBufferUniqueID = vertexBuffer->getUniqueID(); |
77 array->fVertexBufferID = vertexBufferID; | |
78 array->fType = type; | 76 array->fType = type; |
79 array->fStride = stride; | 77 array->fStride = stride; |
80 array->fOffset = offset; | 78 array->fOffset = offset; |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 void GrGLAttribArrayState::disableUnusedArrays(const GrGLGpu* gpu, uint64_t used
Mask) { | 82 void GrGLAttribArrayState::disableUnusedArrays(const GrGLGpu* gpu, uint64_t used
Mask) { |
85 int count = fAttribArrayStates.count(); | 83 int count = fAttribArrayStates.count(); |
86 for (int i = 0; i < count; ++i) { | 84 for (int i = 0; i < count; ++i) { |
87 if (!(usedMask & 0x1)) { | 85 if (!(usedMask & 0x1)) { |
88 if (!fAttribArrayStates[i].fEnableIsValid || fAttribArrayStates[i].f
Enabled) { | 86 if (!fAttribArrayStates[i].fEnableIsValid || fAttribArrayStates[i].f
Enabled) { |
89 GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i)); | 87 GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i)); |
90 fAttribArrayStates[i].fEnableIsValid = true; | 88 fAttribArrayStates[i].fEnableIsValid = true; |
91 fAttribArrayStates[i].fEnabled = false; | 89 fAttribArrayStates[i].fEnabled = false; |
92 } | 90 } |
93 } else { | 91 } else { |
94 SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[
i].fEnabled); | 92 SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[
i].fEnabled); |
95 } | 93 } |
96 // if the count is greater than 64 then this will become 0 and we will d
isable arrays 64+. | 94 // if the count is greater than 64 then this will become 0 and we will d
isable arrays 64+. |
97 usedMask >>= 1; | 95 usedMask >>= 1; |
98 } | 96 } |
99 } | 97 } |
100 | 98 |
101 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 99 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
102 | 100 |
103 GrGLVertexArray::GrGLVertexArray(GrGLint id, int attribCount) | 101 GrGLVertexArray::GrGLVertexArray(GrGLint id, int attribCount) |
104 : fID(id) | 102 : fID(id) |
105 , fAttribArrays(attribCount) | 103 , fAttribArrays(attribCount) |
106 , fIndexBufferIDIsValid(false) { | 104 , fIndexBufferUniqueID(SK_InvalidUniqueID) { |
107 } | 105 } |
108 | 106 |
109 GrGLAttribArrayState* GrGLVertexArray::bind(GrGLGpu* gpu) { | 107 GrGLAttribArrayState* GrGLVertexArray::bind(GrGLGpu* gpu) { |
110 if (0 == fID) { | 108 if (0 == fID) { |
111 return nullptr; | 109 return nullptr; |
112 } | 110 } |
113 gpu->bindVertexArray(fID); | 111 gpu->bindVertexArray(fID); |
114 return &fAttribArrays; | 112 return &fAttribArrays; |
115 } | 113 } |
116 | 114 |
117 GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(GrGLGpu* gpu, GrGLuin
t ibufferID) { | 115 GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(GrGLGpu* gpu, const G
rGLBuffer* ibuff) { |
118 GrGLAttribArrayState* state = this->bind(gpu); | 116 GrGLAttribArrayState* state = this->bind(gpu); |
119 if (state) { | 117 if (state && fIndexBufferUniqueID != ibuff->getUniqueID()) { |
120 if (!fIndexBufferIDIsValid || ibufferID != fIndexBufferID) { | 118 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ib
uff->bufferID())); |
121 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER
, ibufferID)); | 119 fIndexBufferUniqueID = ibuff->getUniqueID(); |
122 fIndexBufferIDIsValid = true; | |
123 fIndexBufferID = ibufferID; | |
124 } | |
125 } | 120 } |
126 return state; | 121 return state; |
127 } | 122 } |
128 | 123 |
129 void GrGLVertexArray::notifyIndexBufferDelete(GrGLuint bufferID) { | |
130 if (fIndexBufferIDIsValid && bufferID == fIndexBufferID) { | |
131 fIndexBufferID = 0; | |
132 } | |
133 } | |
134 | |
135 void GrGLVertexArray::invalidateCachedState() { | 124 void GrGLVertexArray::invalidateCachedState() { |
136 fAttribArrays.invalidate(); | 125 fAttribArrays.invalidate(); |
137 fIndexBufferIDIsValid = false; | 126 fIndexBufferUniqueID = SK_InvalidUniqueID; |
138 } | 127 } |
OLD | NEW |