• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrSimpleMesh_DEFINED
9 #define GrSimpleMesh_DEFINED
10 
11 #include "src/gpu/GrBuffer.h"
12 #include "src/gpu/GrGpuBuffer.h"
13 #include "src/gpu/GrOpsRenderPass.h"
14 
15 class GrGeometryProcessor;
16 
17 /**
18  * Used to communicate simple (non-instanced, direct) draws from GrOp to GrOpsRenderPass.
19  * TODO: Consider migrating every Op to make the appropriate draw directly on GrOpsRenderPass.
20  */
21 struct GrSimpleMesh {
22     void set(sk_sp<const GrBuffer> vertexBuffer, int vertexCount, int baseVertex);
23     void setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex,
24                     uint16_t minIndexValue, uint16_t maxIndexValue, GrPrimitiveRestart,
25                     sk_sp<const GrBuffer> vertexBuffer, int baseVertex);
26     void setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer, int indexCount,
27                              int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer,
28                              sk_sp<const GrBuffer> vertexBuffer, int patternVertexCount,
29                              int baseVertex);
30 
31     sk_sp<const GrBuffer> fIndexBuffer;
32     int fIndexCount;
33     int fPatternRepeatCount;
34     int fMaxPatternRepetitionsInIndexBuffer;
35     int fBaseIndex;
36     uint16_t fMinIndexValue;
37     uint16_t fMaxIndexValue;
38     GrPrimitiveRestart fPrimitiveRestart = GrPrimitiveRestart::kNo;
39 
40     sk_sp<const GrBuffer> fVertexBuffer;
41     int fVertexCount;
42     int fBaseVertex = 0;
43 
44     SkDEBUGCODE(bool fIsInitialized = false;)
45 };
46 
set(sk_sp<const GrBuffer> vertexBuffer,int vertexCount,int baseVertex)47 inline void GrSimpleMesh::set(sk_sp<const GrBuffer> vertexBuffer, int vertexCount, int baseVertex) {
48     SkASSERT(baseVertex >= 0);
49     fIndexBuffer.reset();
50     fVertexBuffer = std::move(vertexBuffer);
51     fVertexCount = vertexCount;
52     fBaseVertex = baseVertex;
53     SkDEBUGCODE(fIsInitialized = true;)
54 }
55 
setIndexed(sk_sp<const GrBuffer> indexBuffer,int indexCount,int baseIndex,uint16_t minIndexValue,uint16_t maxIndexValue,GrPrimitiveRestart primitiveRestart,sk_sp<const GrBuffer> vertexBuffer,int baseVertex)56 inline void GrSimpleMesh::setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount,
57                                      int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
58                                      GrPrimitiveRestart primitiveRestart,
59                                      sk_sp<const GrBuffer> vertexBuffer, int baseVertex) {
60     SkASSERT(indexBuffer);
61     SkASSERT(indexCount >= 1);
62     SkASSERT(baseIndex >= 0);
63     SkASSERT(maxIndexValue >= minIndexValue);
64     SkASSERT(baseVertex >= 0);
65     fIndexBuffer = std::move(indexBuffer);
66     fIndexCount = indexCount;
67     fPatternRepeatCount = 0;
68     fBaseIndex = baseIndex;
69     fMinIndexValue = minIndexValue;
70     fMaxIndexValue = maxIndexValue;
71     fPrimitiveRestart = primitiveRestart;
72     fVertexBuffer = std::move(vertexBuffer);
73     fBaseVertex = baseVertex;
74     SkDEBUGCODE(fIsInitialized = true;)
75 }
76 
setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer,int indexCount,int patternRepeatCount,int maxPatternRepetitionsInIndexBuffer,sk_sp<const GrBuffer> vertexBuffer,int patternVertexCount,int baseVertex)77 inline void GrSimpleMesh::setIndexedPatterned(
78         sk_sp<const GrBuffer> indexBuffer, int indexCount, int patternRepeatCount,
79         int maxPatternRepetitionsInIndexBuffer, sk_sp<const GrBuffer> vertexBuffer,
80         int patternVertexCount, int baseVertex) {
81     SkASSERT(indexBuffer);
82     SkASSERT(indexCount >= 1);
83     SkASSERT(patternVertexCount >= 1);
84     SkASSERT(patternRepeatCount >= 1);
85     SkASSERT(maxPatternRepetitionsInIndexBuffer >= 1);
86     SkASSERT(baseVertex >= 0);
87     fIndexBuffer = std::move(indexBuffer);
88     fIndexCount = indexCount;
89     fPatternRepeatCount = patternRepeatCount;
90     fVertexCount = patternVertexCount;
91     fMaxPatternRepetitionsInIndexBuffer = maxPatternRepetitionsInIndexBuffer;
92     fPrimitiveRestart = GrPrimitiveRestart::kNo;
93     fVertexBuffer = std::move(vertexBuffer);
94     fBaseVertex = baseVertex;
95     SkDEBUGCODE(fIsInitialized = true;)
96 }
97 
98 #endif
99