OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "GrVertexBatch.h" |
| 9 #include "GrBatchTarget.h" |
| 10 #include "GrResourceProvider.h" |
| 11 |
| 12 GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {} |
| 13 |
| 14 void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimiti
veType primType, |
| 15 size_t vertexStride, const GrIndexBuffer* i
ndexBuffer, |
| 16 int verticesPerInstance, int indicesPerInst
ance, |
| 17 int instancesToDraw) { |
| 18 SkASSERT(batchTarget); |
| 19 if (!indexBuffer) { |
| 20 return NULL; |
| 21 } |
| 22 const GrVertexBuffer* vertexBuffer; |
| 23 int firstVertex; |
| 24 int vertexCount = verticesPerInstance * instancesToDraw; |
| 25 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount, |
| 26 &vertexBuffer, &firstVertex); |
| 27 if (!vertices) { |
| 28 SkDebugf("Vertices could not be allocated for instanced rendering."); |
| 29 return NULL; |
| 30 } |
| 31 SkASSERT(vertexBuffer); |
| 32 size_t ibSize = indexBuffer->gpuMemorySize(); |
| 33 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi
cesPerInstance)); |
| 34 |
| 35 fVertices.initInstanced(primType, vertexBuffer, indexBuffer, |
| 36 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, |
| 37 maxInstancesPerDraw); |
| 38 return vertices; |
| 39 } |
| 40 |
| 41 void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexS
tride, |
| 42 int quadsToDraw) { |
| 43 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( |
| 44 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 45 if (!quadIndexBuffer) { |
| 46 SkDebugf("Could not get quad index buffer."); |
| 47 return NULL; |
| 48 } |
| 49 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex
Stride, |
| 50 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ
uad, quadsToDraw); |
| 51 } |
OLD | NEW |