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 #ifndef GrVertexBatch_DEFINED |
| 9 #define GrVertexBatch_DEFINED |
| 10 |
| 11 #include "GrDrawBatch.h" |
| 12 #include "GrBatchTarget.h" |
| 13 |
| 14 /** |
| 15 * Base class for vertex-based GrBatches. |
| 16 */ |
| 17 class GrVertexBatch : public GrDrawBatch { |
| 18 public: |
| 19 GrVertexBatch(); |
| 20 |
| 21 virtual void generateGeometry(GrBatchTarget*) = 0; |
| 22 |
| 23 // TODO this goes away when batches are everywhere |
| 24 void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; } |
| 25 int numberOfDraws() const { return fNumberOfDraws; } |
| 26 |
| 27 protected: |
| 28 /** Helper for rendering instances using an instanced index index buffer. Th
is class creates the |
| 29 space for the vertices and flushes the draws to the batch target. */ |
| 30 class InstancedHelper { |
| 31 public: |
| 32 InstancedHelper() {} |
| 33 /** Returns the allocated storage for the vertices. The caller should po
pulate the before |
| 34 vertices before calling issueDraws(). */ |
| 35 void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStr
ide, |
| 36 const GrIndexBuffer*, int verticesPerInstance, int indicesPer
Instance, |
| 37 int instancesToDraw); |
| 38 |
| 39 /** Call after init() to issue draws to the batch target.*/ |
| 40 void issueDraw(GrBatchTarget* batchTarget) { |
| 41 SkASSERT(fVertices.instanceCount()); |
| 42 batchTarget->draw(fVertices); |
| 43 } |
| 44 private: |
| 45 GrVertices fVertices; |
| 46 }; |
| 47 |
| 48 static const int kVerticesPerQuad = 4; |
| 49 static const int kIndicesPerQuad = 6; |
| 50 |
| 51 /** A specialization of InstanceHelper for quad rendering. */ |
| 52 class QuadHelper : private InstancedHelper { |
| 53 public: |
| 54 QuadHelper() : INHERITED() {} |
| 55 /** Finds the cached quad index buffer and reserves vertex space. Return
s NULL on failure |
| 56 and on sucess a pointer to the vertex data that the caller should po
pulate before |
| 57 calling issueDraws(). */ |
| 58 void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToD
raw); |
| 59 |
| 60 using InstancedHelper::issueDraw; |
| 61 |
| 62 private: |
| 63 typedef InstancedHelper INHERITED; |
| 64 }; |
| 65 |
| 66 private: |
| 67 int fNumberOfDraws; |
| 68 typedef GrDrawBatch INHERITED; |
| 69 }; |
| 70 |
| 71 #endif |
OLD | NEW |