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