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 GrVertices_DEFINED | 8 #ifndef GrVertices_DEFINED |
9 #define GrVertices_DEFINED | 9 #define GrVertices_DEFINED |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 GrVertices() {} | 45 GrVertices() {} |
46 GrVertices(const GrVertices& di) { (*this) = di; } | 46 GrVertices(const GrVertices& di) { (*this) = di; } |
47 GrVertices& operator =(const GrVertices& di); | 47 GrVertices& operator =(const GrVertices& di); |
48 | 48 |
49 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer, int
startVertex, | 49 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer, int
startVertex, |
50 int vertexCount) { | 50 int vertexCount) { |
51 SkASSERT(vertexBuffer); | 51 SkASSERT(vertexBuffer); |
52 SkASSERT(vertexCount); | 52 SkASSERT(vertexCount); |
53 SkASSERT(startVertex >= 0); | 53 SkASSERT(startVertex >= 0); |
54 fPrimitiveType = primType; | 54 fPrimitiveType = primType; |
55 fVertexBuffer.reset(vertexBuffer); | 55 fVertexBuffer.reset(vertexBuffer, nullptr); |
56 fIndexBuffer.reset(nullptr); | 56 fIndexBuffer.reset(nullptr, nullptr); |
57 fStartVertex = startVertex; | 57 fStartVertex = startVertex; |
58 fStartIndex = 0; | 58 fStartIndex = 0; |
59 fVertexCount = vertexCount; | 59 fVertexCount = vertexCount; |
60 fIndexCount = 0; | 60 fIndexCount = 0; |
61 fInstanceCount = 0; | 61 fInstanceCount = 0; |
62 fVerticesPerInstance = 0; | 62 fVerticesPerInstance = 0; |
63 fIndicesPerInstance = 0; | 63 fIndicesPerInstance = 0; |
64 fMaxInstancesPerDraw = 0; | 64 fMaxInstancesPerDraw = 0; |
65 } | 65 } |
66 | 66 |
67 void initIndexed(GrPrimitiveType primType, | 67 void initIndexed(GrPrimitiveType primType, |
68 const GrVertexBuffer* vertexBuffer, | 68 const GrVertexBuffer* vertexBuffer, |
69 const GrIndexBuffer* indexBuffer, | 69 const GrIndexBuffer* indexBuffer, |
70 int startVertex, | 70 int startVertex, |
71 int startIndex, | 71 int startIndex, |
72 int vertexCount, | 72 int vertexCount, |
73 int indexCount) { | 73 int indexCount) { |
74 SkASSERT(indexBuffer); | 74 SkASSERT(indexBuffer); |
75 SkASSERT(vertexBuffer); | 75 SkASSERT(vertexBuffer); |
76 SkASSERT(indexCount); | 76 SkASSERT(indexCount); |
77 SkASSERT(vertexCount); | 77 SkASSERT(vertexCount); |
78 SkASSERT(startIndex >= 0); | 78 SkASSERT(startIndex >= 0); |
79 SkASSERT(startVertex >= 0); | 79 SkASSERT(startVertex >= 0); |
80 fPrimitiveType = primType; | 80 fPrimitiveType = primType; |
81 fVertexBuffer.reset(vertexBuffer); | 81 fVertexBuffer.reset(vertexBuffer, NULL); |
82 fIndexBuffer.reset(indexBuffer); | 82 fIndexBuffer.reset(indexBuffer, NULL); |
83 fStartVertex = startVertex; | 83 fStartVertex = startVertex; |
84 fStartIndex = startIndex; | 84 fStartIndex = startIndex; |
85 fVertexCount = vertexCount; | 85 fVertexCount = vertexCount; |
86 fIndexCount = indexCount; | 86 fIndexCount = indexCount; |
87 fInstanceCount = 0; | 87 fInstanceCount = 0; |
88 fVerticesPerInstance = 0; | 88 fVerticesPerInstance = 0; |
89 fIndicesPerInstance = 0; | 89 fIndicesPerInstance = 0; |
90 fMaxInstancesPerDraw = 0; | 90 fMaxInstancesPerDraw = 0; |
91 } | 91 } |
92 | 92 |
93 | 93 |
94 /** Variation of the above that may be used when the total number of instanc
es may exceed | 94 /** Variation of the above that may be used when the total number of instanc
es may exceed |
95 the number of instances supported by the index buffer. To be used with | 95 the number of instances supported by the index buffer. To be used with |
96 nextInstances() to draw in max-sized batches.*/ | 96 nextInstances() to draw in max-sized batches.*/ |
97 void initInstanced(GrPrimitiveType primType, | 97 void initInstanced(GrPrimitiveType primType, |
98 const GrVertexBuffer* vertexBuffer, | 98 const GrVertexBuffer* vertexBuffer, |
99 const GrIndexBuffer* indexBuffer, | 99 const GrIndexBuffer* indexBuffer, |
100 int startVertex, | 100 int startVertex, |
101 int verticesPerInstance, | 101 int verticesPerInstance, |
102 int indicesPerInstance, | 102 int indicesPerInstance, |
103 int instanceCount, | 103 int instanceCount, |
104 int maxInstancesPerDraw) { | 104 int maxInstancesPerDraw) { |
105 SkASSERT(vertexBuffer); | 105 SkASSERT(vertexBuffer); |
106 SkASSERT(indexBuffer); | 106 SkASSERT(indexBuffer); |
107 SkASSERT(instanceCount); | 107 SkASSERT(instanceCount); |
108 SkASSERT(verticesPerInstance); | 108 SkASSERT(verticesPerInstance); |
109 SkASSERT(indicesPerInstance); | 109 SkASSERT(indicesPerInstance); |
110 SkASSERT(startVertex >= 0); | 110 SkASSERT(startVertex >= 0); |
111 fPrimitiveType = primType; | 111 fPrimitiveType = primType; |
112 fVertexBuffer.reset(vertexBuffer); | 112 fVertexBuffer.reset(vertexBuffer, NULL); |
113 fIndexBuffer.reset(indexBuffer); | 113 fIndexBuffer.reset(indexBuffer, NULL); |
114 fStartVertex = startVertex; | 114 fStartVertex = startVertex; |
115 fStartIndex = 0; | 115 fStartIndex = 0; |
116 fVerticesPerInstance = verticesPerInstance; | 116 fVerticesPerInstance = verticesPerInstance; |
117 fIndicesPerInstance = indicesPerInstance; | 117 fIndicesPerInstance = indicesPerInstance; |
118 fInstanceCount = instanceCount; | 118 fInstanceCount = instanceCount; |
119 fVertexCount = instanceCount * fVerticesPerInstance; | 119 fVertexCount = instanceCount * fVerticesPerInstance; |
120 fIndexCount = instanceCount * fIndicesPerInstance; | 120 fIndexCount = instanceCount * fIndicesPerInstance; |
121 fMaxInstancesPerDraw = maxInstancesPerDraw; | 121 fMaxInstancesPerDraw = maxInstancesPerDraw; |
122 } | 122 } |
123 | 123 |
124 | 124 |
125 /** These return 0 if initInstanced was not used to initialize the GrVertice
s. */ | 125 /** These return 0 if initInstanced was not used to initialize the GrVertice
s. */ |
126 int verticesPerInstance() const { return fVerticesPerInstance; } | 126 int verticesPerInstance() const { return fVerticesPerInstance; } |
127 int indicesPerInstance() const { return fIndicesPerInstance; } | 127 int indicesPerInstance() const { return fIndicesPerInstance; } |
128 int instanceCount() const { return fInstanceCount; } | 128 int instanceCount() const { return fInstanceCount; } |
129 | 129 |
130 bool isInstanced() const { return fInstanceCount > 0; } | 130 bool isInstanced() const { return fInstanceCount > 0; } |
131 | 131 |
132 class Iterator { | 132 class Iterator { |
133 public: | 133 public: |
134 const GrNonInstancedVertices* init(const GrVertices& vertices) { | 134 const GrNonInstancedVertices* init(const GrVertices& vertices) { |
135 fVertices = &vertices; | 135 fVertices = &vertices; |
136 if (vertices.fInstanceCount <= vertices.fMaxInstancesPerDraw) { | 136 if (vertices.fInstanceCount <= vertices.fMaxInstancesPerDraw) { |
137 fInstancesRemaining = 0; | 137 fInstancesRemaining = 0; |
138 // Note, this also covers the non-instanced case! | 138 // Note, this also covers the non-instanced case! |
139 return &vertices; | 139 return &vertices; |
140 } | 140 } |
141 SkASSERT(vertices.isInstanced()); | 141 SkASSERT(vertices.isInstanced()); |
142 fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get()); | 142 fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get(), NULL)
; |
143 fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get()); | 143 fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get(), NUL
L); |
144 fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw * | 144 fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw * |
145 vertices.fIndicesPerInstance; | 145 vertices.fIndicesPerInstance; |
146 fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw * | 146 fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw * |
147 vertices.fVerticesPerInstance; | 147 vertices.fVerticesPerInstance; |
148 fInstanceBatch.fPrimitiveType = vertices.fPrimitiveType; | 148 fInstanceBatch.fPrimitiveType = vertices.fPrimitiveType; |
149 fInstanceBatch.fStartIndex = vertices.fStartIndex; | 149 fInstanceBatch.fStartIndex = vertices.fStartIndex; |
150 fInstanceBatch.fStartVertex = vertices.fStartVertex; | 150 fInstanceBatch.fStartVertex = vertices.fStartVertex; |
151 fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstanc
esPerDraw; | 151 fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstanc
esPerDraw; |
152 return &fInstanceBatch; | 152 return &fInstanceBatch; |
153 } | 153 } |
(...skipping 16 matching lines...) Expand all Loading... |
170 }; | 170 }; |
171 | 171 |
172 private: | 172 private: |
173 int fInstanceCount; | 173 int fInstanceCount; |
174 int fVerticesPerInstance; | 174 int fVerticesPerInstance; |
175 int fIndicesPerInstance; | 175 int fIndicesPerInstance; |
176 int fMaxInstancesPerDraw; | 176 int fMaxInstancesPerDraw; |
177 }; | 177 }; |
178 | 178 |
179 #endif | 179 #endif |
OLD | NEW |