OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef GrVertexBatch_DEFINED | 8 #ifndef GrVertexBatch_DEFINED |
9 #define GrVertexBatch_DEFINED | 9 #define GrVertexBatch_DEFINED |
10 | 10 |
11 #include "GrDrawBatch.h" | 11 #include "GrDrawBatch.h" |
12 #include "GrGeometryProcessor.h" | |
12 #include "GrMesh.h" | 13 #include "GrMesh.h" |
13 #include "GrPrimitiveProcessor.h" | |
14 #include "GrPendingProgramElement.h" | 14 #include "GrPendingProgramElement.h" |
15 | 15 |
16 #include "SkTLList.h" | 16 #include "SkTLList.h" |
17 | 17 |
18 class GrBatchFlushState; | 18 class GrBatchFlushState; |
19 | 19 |
20 /** | 20 /** |
21 * Base class for vertex-based GrBatches. | 21 * Base class for vertex-based GrBatches. |
22 */ | 22 */ |
23 class GrVertexBatch : public GrDrawBatch { | 23 class GrVertexBatch : public GrDrawBatch { |
24 public: | 24 public: |
25 class Target; | 25 class Target; |
26 | 26 |
27 GrVertexBatch(uint32_t classID); | 27 GrVertexBatch(uint32_t classID); |
28 | 28 |
29 protected: | 29 protected: |
30 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the | 30 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the |
31 space for the vertices and flushes the draws to the batch target. */ | 31 space for the vertices and flushes the draws to the batch target. */ |
32 class InstancedHelper { | 32 class InstancedHelper { |
33 public: | 33 public: |
34 InstancedHelper() {} | 34 InstancedHelper() {} |
35 /** Returns the allocated storage for the vertices. The caller should po pulate the before | 35 /** Returns the allocated storage for the vertices. The caller should po pulate the before |
36 vertices before calling issueDraws(). */ | 36 vertices before calling issueDraws(). */ |
egdaniel
2016/03/30 15:52:33
What is issueDraws here?
Also I think there is an
bsalomon
2016/03/30 16:59:11
Done.
| |
37 void* init(Target*, GrPrimitiveType, size_t vertexStride, | 37 void* init(Target*, GrPrimitiveType, size_t vertexStride, |
38 const GrBuffer*, int verticesPerInstance, int indicesPerInsta nce, | 38 const GrBuffer*, int verticesPerInstance, int indicesPerInsta nce, |
39 int instancesToDraw); | 39 int instancesToDraw); |
40 | 40 |
41 /** Call after init() to issue draws to the batch target.*/ | 41 /** Call after init() to issue draws to the batch target.*/ |
42 void recordDraw(Target* target); | 42 void recordDraw(Target*, const GrGeometryProcessor*); |
43 private: | 43 private: |
44 GrMesh fMesh; | 44 GrMesh fMesh; |
45 }; | 45 }; |
46 | 46 |
47 static const int kVerticesPerQuad = 4; | 47 static const int kVerticesPerQuad = 4; |
48 static const int kIndicesPerQuad = 6; | 48 static const int kIndicesPerQuad = 6; |
49 | 49 |
50 /** A specialization of InstanceHelper for quad rendering. */ | 50 /** A specialization of InstanceHelper for quad rendering. */ |
51 class QuadHelper : private InstancedHelper { | 51 class QuadHelper : private InstancedHelper { |
52 public: | 52 public: |
53 QuadHelper() : INHERITED() {} | 53 QuadHelper() : INHERITED() {} |
54 /** Finds the cached quad index buffer and reserves vertex space. Return s nullptr on failure | 54 /** Finds the cached quad index buffer and reserves vertex space. Return s nullptr on failure |
55 and on sucess a pointer to the vertex data that the caller should po pulate before | 55 and on sucess a pointer to the vertex data that the caller should po pulate before |
56 calling issueDraws(). */ | 56 calling issueDraws(). */ |
57 void* init(Target* batchTarget, size_t vertexStride, int quadsToDraw); | 57 void* init(Target*, size_t vertexStride, int quadsToDraw); |
58 | 58 |
59 using InstancedHelper::recordDraw; | 59 using InstancedHelper::recordDraw; |
60 private: | 60 private: |
61 typedef InstancedHelper INHERITED; | 61 typedef InstancedHelper INHERITED; |
62 }; | 62 }; |
63 | 63 |
64 private: | 64 private: |
65 void onPrepare(GrBatchFlushState* state) final; | 65 void onPrepare(GrBatchFlushState* state) final; |
66 void onDraw(GrBatchFlushState* state) final; | 66 void onDraw(GrBatchFlushState* state) final; |
67 | 67 |
68 virtual void onPrepareDraws(Target*) const = 0; | 68 virtual void onPrepareDraws(Target*) const = 0; |
69 | 69 |
70 // A set of contiguous draws with no inline uploads between them that all us e the same | 70 // A set of contiguous draws that share a draw token and primitive processor . The draws all use |
71 // primitive processor. All the draws in a DrawArray share a primitive proce ssor and use the | 71 // the batch's pipeline. The meshes for the draw are stored in the fMeshes a rray and each |
robertphillips
2016/03/30 14:29:47
overlength
bsalomon
2016/03/30 16:59:11
Done.
| |
72 // the batch's GrPipeline. | 72 // Queued draw uses fMeshCnt meshes from the fMeshes array. The reason for c oallescing meshes that |
robertphillips
2016/03/30 14:29:47
extra '.' ?
egdaniel
2016/03/30 15:52:33
if you're capitalizing Queued make it QueuedDraw
bsalomon
2016/03/30 16:59:11
Done.
bsalomon
2016/03/30 16:59:11
Done.
| |
73 struct DrawArray { | 73 // share a primitive processor into a QueueDraw. is that it allows the Gpu o bject to setup the |
74 SkSTArray<1, GrMesh, true> fDraws; | 74 // shared state once and then issue draws for each mesh. |
75 GrPendingProgramElement<const GrPrimitiveProcessor> fPrimitiveProcessor; | 75 struct QueuedDraw { |
76 int fMeshCnt = 0; | |
77 GrPendingProgramElement<const GrGeometryProcessor> fGeometryProcessor; | |
76 }; | 78 }; |
77 | 79 |
78 // Array of DrawArray. There may be inline uploads between each DrawArray an d each DrawArray | 80 // All draws in all the vertex batches have implicit tokens based on the ord er they are |
79 // may use a different primitive processor. | 81 // enqueued globally across all batches. This is the offset of the first ent ry in fQueuedDraws. |
80 typedef SkTLList<DrawArray, 4> DrawArrayList; | 82 // fQueuedDraws[i]'s token is fBaseDrawToken + i. |
81 DrawArrayList fDrawArrays; | 83 GrBatchDrawToken fBaseDrawToken; |
84 | |
85 SkSTArray<4, GrMesh> fMeshes; | |
86 SkSTArray<4, QueuedDraw, true> fQueuedDraws; | |
82 | 87 |
83 typedef GrDrawBatch INHERITED; | 88 typedef GrDrawBatch INHERITED; |
84 }; | 89 }; |
85 | 90 |
86 #endif | 91 #endif |
OLD | NEW |