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