OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GLInstancedRendering.h" | 8 #include "GLInstancedRendering.h" |
9 | 9 |
10 #include "GrResourceProvider.h" | 10 #include "GrResourceProvider.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Lazily create a vertex array object. | 90 // Lazily create a vertex array object. |
91 if (!fVertexArrayID) { | 91 if (!fVertexArrayID) { |
92 GL_CALL(GenVertexArrays(1, &fVertexArrayID)); | 92 GL_CALL(GenVertexArrays(1, &fVertexArrayID)); |
93 if (!fVertexArrayID) { | 93 if (!fVertexArrayID) { |
94 return; | 94 return; |
95 } | 95 } |
96 this->glGpu()->bindVertexArray(fVertexArrayID); | 96 this->glGpu()->bindVertexArray(fVertexArrayID); |
97 | 97 |
98 // Attach our index buffer to the vertex array. | 98 // Attach our index buffer to the vertex array. |
| 99 SkASSERT(!this->indexBuffer()->isCPUBacked()); |
99 GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, | 100 GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, |
100 static_cast<const GrGLBuffer*>(this->indexBuffer())->
bufferID())); | 101 static_cast<const GrGLBuffer*>(this->indexBuffer())->
bufferID())); |
101 | 102 |
102 // Set up the non-instanced attribs. | 103 // Set up the non-instanced attribs. |
103 this->glGpu()->bindBuffer(kVertex_GrBufferType, | 104 this->glGpu()->bindBuffer(kVertex_GrBufferType, this->vertexBuffer()); |
104 static_cast<const GrGLBuffer*>(this->vertexBuf
fer())); | |
105 GL_CALL(EnableVertexAttribArray((int)Attrib::kShapeCoords)); | 105 GL_CALL(EnableVertexAttribArray((int)Attrib::kShapeCoords)); |
106 GL_CALL(VertexAttribPointer((int)Attrib::kShapeCoords, 2, GR_GL_FLOAT, G
R_GL_FALSE, | 106 GL_CALL(VertexAttribPointer((int)Attrib::kShapeCoords, 2, GR_GL_FLOAT, G
R_GL_FALSE, |
107 sizeof(ShapeVertex), (void*) offsetof(ShapeV
ertex, fX))); | 107 sizeof(ShapeVertex), (void*) offsetof(ShapeV
ertex, fX))); |
108 GL_CALL(EnableVertexAttribArray((int)Attrib::kVertexAttrs)); | 108 GL_CALL(EnableVertexAttribArray((int)Attrib::kVertexAttrs)); |
109 GL_CALL(VertexAttribIPointer((int)Attrib::kVertexAttrs, 1, GR_GL_INT, si
zeof(ShapeVertex), | 109 GL_CALL(VertexAttribIPointer((int)Attrib::kVertexAttrs, 1, GR_GL_INT, si
zeof(ShapeVertex), |
110 (void*) offsetof(ShapeVertex, fAttrs))); | 110 (void*) offsetof(ShapeVertex, fAttrs))); |
111 | 111 |
112 SkASSERT(SK_InvalidUniqueID == fInstanceAttribsBufferUniqueId); | 112 SkASSERT(SK_InvalidUniqueID == fInstanceAttribsBufferUniqueId); |
113 } | 113 } |
114 | 114 |
115 // Create and map instance and draw-indirect buffers. | 115 // Create and map instance and draw-indirect buffers. |
116 SkASSERT(!fInstanceBuffer); | 116 SkASSERT(!fInstanceBuffer); |
117 fInstanceBuffer.reset(static_cast<GrGLBuffer*>( | 117 fInstanceBuffer.reset( |
118 rp->createBuffer(sizeof(Instance) * numGLInstances, kVertex_GrBufferType
, | 118 rp->createBuffer(sizeof(Instance) * numGLInstances, kVertex_GrBufferType
, |
119 kDynamic_GrAccessPattern, GrResourceProvider::kNoPendin
gIO_Flag))); | 119 kDynamic_GrAccessPattern, |
| 120 GrResourceProvider::kNoPendingIO_Flag | |
| 121 GrResourceProvider::kRequireGpuMemory_Flag)); |
120 if (!fInstanceBuffer) { | 122 if (!fInstanceBuffer) { |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 SkASSERT(!fDrawIndirectBuffer); | 126 SkASSERT(!fDrawIndirectBuffer); |
125 fDrawIndirectBuffer.reset(static_cast<GrGLBuffer*>( | 127 fDrawIndirectBuffer.reset( |
126 rp->createBuffer(sizeof(GrGLDrawElementsIndirectCommand) * numGLDrawCmds
, | 128 rp->createBuffer(sizeof(GrGLDrawElementsIndirectCommand) * numGLDrawCmds
, |
127 kDrawIndirect_GrBufferType, kDynamic_GrAccessPattern, | 129 kDrawIndirect_GrBufferType, kDynamic_GrAccessPattern, |
128 GrResourceProvider::kNoPendingIO_Flag))); | 130 GrResourceProvider::kNoPendingIO_Flag | |
| 131 GrResourceProvider::kRequireGpuMemory_Flag)); |
129 if (!fDrawIndirectBuffer) { | 132 if (!fDrawIndirectBuffer) { |
130 return; | 133 return; |
131 } | 134 } |
132 | 135 |
133 Instance* glMappedInstances = static_cast<Instance*>(fInstanceBuffer->map())
; | 136 Instance* glMappedInstances = static_cast<Instance*>(fInstanceBuffer->map())
; |
134 int glInstancesIdx = 0; | 137 int glInstancesIdx = 0; |
135 | 138 |
136 auto* glMappedCmds = static_cast<GrGLDrawElementsIndirectCommand*>(fDrawIndi
rectBuffer->map()); | 139 auto* glMappedCmds = static_cast<GrGLDrawElementsIndirectCommand*>(fDrawIndi
rectBuffer->map()); |
137 int glDrawCmdsIdx = 0; | 140 int glDrawCmdsIdx = 0; |
138 | 141 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 GL_CALL(DeleteVertexArrays(1, &fVertexArrayID)); | 295 GL_CALL(DeleteVertexArrays(1, &fVertexArrayID)); |
293 this->glGpu()->notifyVertexArrayDelete(fVertexArrayID); | 296 this->glGpu()->notifyVertexArrayDelete(fVertexArrayID); |
294 } | 297 } |
295 fVertexArrayID = 0; | 298 fVertexArrayID = 0; |
296 fInstanceBuffer.reset(); | 299 fInstanceBuffer.reset(); |
297 fDrawIndirectBuffer.reset(); | 300 fDrawIndirectBuffer.reset(); |
298 fInstanceAttribsBufferUniqueId = SK_InvalidUniqueID; | 301 fInstanceAttribsBufferUniqueId = SK_InvalidUniqueID; |
299 } | 302 } |
300 | 303 |
301 } | 304 } |
OLD | NEW |