Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/gpu/GrMesh.h

Issue 1825393002: Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: asserts Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrIndexBuffer.h ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GrMesh_DEFINED 8 #ifndef GrMesh_DEFINED
9 #define GrMesh_DEFINED 9 #define GrMesh_DEFINED
10 10
11 #include "GrIndexBuffer.h" 11 #include "GrBuffer.h"
12 #include "GrVertexBuffer.h" 12 #include "GrGpuResourceRef.h"
13 13
14 class GrNonInstancedMesh { 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 GrBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
24 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } 24 const GrBuffer* 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 GrBuffer, kRead_GrIOType> fVertexBuffer;
33 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; 33 GrPendingIOResource<const GrBuffer, kRead_GrIOType> fIndexBuffer;
34 friend class GrMesh; 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 GrMesh : public GrNonInstancedMesh { 43 class GrMesh : public GrNonInstancedMesh {
44 public: 44 public:
45 GrMesh() {} 45 GrMesh() {}
46 GrMesh(const GrMesh& di) { (*this) = di; } 46 GrMesh(const GrMesh& di) { (*this) = di; }
47 GrMesh& operator =(const GrMesh& 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 GrBuffer* vertexBuffer, int startV ertex,
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;
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 GrBuffer* vertexBuffer,
69 const GrIndexBuffer* indexBuffer, 69 const GrBuffer* 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);
82 fIndexBuffer.reset(indexBuffer); 82 fIndexBuffer.reset(indexBuffer);
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 GrBuffer* vertexBuffer,
99 const GrIndexBuffer* indexBuffer, 99 const GrBuffer* 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);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « src/gpu/GrIndexBuffer.h ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698