| 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 GrMesh_DEFINED |
| 9 #define GrVertices_DEFINED | 9 #define GrMesh_DEFINED |
| 10 | 10 |
| 11 #include "GrIndexBuffer.h" | 11 #include "GrIndexBuffer.h" |
| 12 #include "GrVertexBuffer.h" | 12 #include "GrVertexBuffer.h" |
| 13 | 13 |
| 14 class GrNonInstancedVertices { | 14 class GrNonInstancedMesh { |
| 15 public: | 15 public: |
| 16 GrPrimitiveType primitiveType() const { return fPrimitiveType; } | 16 GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 17 int startVertex() const { return fStartVertex; } | 17 int startVertex() const { return fStartVertex; } |
| 18 int startIndex() const { return fStartIndex; } | 18 int startIndex() const { return fStartIndex; } |
| 19 int vertexCount() const { return fVertexCount; } | 19 int vertexCount() const { return fVertexCount; } |
| 20 int indexCount() const { return fIndexCount; } | 20 int indexCount() const { return fIndexCount; } |
| 21 bool isIndexed() const { return fIndexCount > 0; } | 21 bool isIndexed() const { return fIndexCount > 0; } |
| 22 | 22 |
| 23 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } | 23 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
| 24 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 24 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 GrPrimitiveType fPrimitiveType; | 27 GrPrimitiveType fPrimitiveType; |
| 28 int fStartVertex; | 28 int fStartVertex; |
| 29 int fStartIndex; | 29 int fStartIndex; |
| 30 int fVertexCount; | 30 int fVertexCount; |
| 31 int fIndexCount; | 31 int fIndexCount; |
| 32 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; | 32 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
| 33 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; | 33 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
| 34 friend class GrVertices; | 34 friend class GrMesh; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Used to communicate index and vertex buffers, counts, and offsets for a draw
from GrBatch to | 38 * Used to communicate index and vertex buffers, counts, and offsets for a draw
from GrBatch to |
| 39 * GrGpu. It also holds the primitive type for the draw. TODO: Consider moving o
wnership of this | 39 * GrGpu. It also holds the primitive type for the draw. TODO: Consider moving o
wnership of this |
| 40 * and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vert
ex info lives there | 40 * and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vert
ex info lives there |
| 41 * already (stride, attribute mappings). | 41 * already (stride, attribute mappings). |
| 42 */ | 42 */ |
| 43 class GrVertices : public GrNonInstancedVertices { | 43 class GrMesh : public GrNonInstancedMesh { |
| 44 public: | 44 public: |
| 45 GrVertices() {} | 45 GrMesh() {} |
| 46 GrVertices(const GrVertices& di) { (*this) = di; } | 46 GrMesh(const GrMesh& di) { (*this) = di; } |
| 47 GrVertices& operator =(const GrVertices& di); | 47 GrMesh& operator =(const GrMesh& 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); |
| 56 fIndexBuffer.reset(nullptr); | 56 fIndexBuffer.reset(nullptr); |
| 57 fStartVertex = startVertex; | 57 fStartVertex = startVertex; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 GrNonInstancedMesh* init(const GrMesh& mesh) { |
| 135 fVertices = &vertices; | 135 fMesh = &mesh; |
| 136 if (vertices.fInstanceCount <= vertices.fMaxInstancesPerDraw) { | 136 if (mesh.fInstanceCount <= mesh.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 &mesh; |
| 140 } | 140 } |
| 141 SkASSERT(vertices.isInstanced()); | 141 SkASSERT(mesh.isInstanced()); |
| 142 fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get()); | 142 fInstanceBatch.fIndexBuffer.reset(mesh.fIndexBuffer.get()); |
| 143 fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get()); | 143 fInstanceBatch.fVertexBuffer.reset(mesh.fVertexBuffer.get()); |
| 144 fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw * | 144 fInstanceBatch.fIndexCount = mesh.fMaxInstancesPerDraw * |
| 145 vertices.fIndicesPerInstance; | 145 mesh.fIndicesPerInstance; |
| 146 fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw * | 146 fInstanceBatch.fVertexCount = mesh.fMaxInstancesPerDraw * |
| 147 vertices.fVerticesPerInstance; | 147 mesh.fVerticesPerInstance; |
| 148 fInstanceBatch.fPrimitiveType = vertices.fPrimitiveType; | 148 fInstanceBatch.fPrimitiveType = mesh.fPrimitiveType; |
| 149 fInstanceBatch.fStartIndex = vertices.fStartIndex; | 149 fInstanceBatch.fStartIndex = mesh.fStartIndex; |
| 150 fInstanceBatch.fStartVertex = vertices.fStartVertex; | 150 fInstanceBatch.fStartVertex = mesh.fStartVertex; |
| 151 fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstanc
esPerDraw; | 151 fInstancesRemaining = mesh.fInstanceCount - mesh.fMaxInstancesPerDra
w; |
| 152 return &fInstanceBatch; | 152 return &fInstanceBatch; |
| 153 } | 153 } |
| 154 | 154 |
| 155 const GrNonInstancedVertices* next() { | 155 const GrNonInstancedMesh* next() { |
| 156 if (!fInstancesRemaining) { | 156 if (!fInstancesRemaining) { |
| 157 return nullptr; | 157 return nullptr; |
| 158 } | 158 } |
| 159 fInstanceBatch.fStartVertex += fInstanceBatch.fVertexCount; | 159 fInstanceBatch.fStartVertex += fInstanceBatch.fVertexCount; |
| 160 int instances = SkTMin(fInstancesRemaining, fVertices->fMaxInstances
PerDraw); | 160 int instances = SkTMin(fInstancesRemaining, fMesh->fMaxInstancesPerD
raw); |
| 161 fInstanceBatch.fIndexCount = instances * fVertices->fIndicesPerInsta
nce; | 161 fInstanceBatch.fIndexCount = instances * fMesh->fIndicesPerInstance; |
| 162 fInstanceBatch.fVertexCount = instances * fVertices->fVerticesPerIns
tance; | 162 fInstanceBatch.fVertexCount = instances * fMesh->fVerticesPerInstanc
e; |
| 163 fInstancesRemaining -= instances; | 163 fInstancesRemaining -= instances; |
| 164 return &fInstanceBatch; | 164 return &fInstanceBatch; |
| 165 } | 165 } |
| 166 private: | 166 private: |
| 167 GrNonInstancedVertices fInstanceBatch; | 167 GrNonInstancedMesh fInstanceBatch; |
| 168 const GrVertices* fVertices; | 168 const GrMesh* fMesh; |
| 169 int fInstancesRemaining; | 169 int fInstancesRemaining; |
| 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 |