bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 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 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 8 | #ifndef GrMesh_DEFINED |
| 9 | #define GrMesh_DEFINED |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 10 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 11 | #include "GrBuffer.h" |
Brian Salomon | ae5f953 | 2018-07-31 11:03:40 -0400 | [diff] [blame] | 12 | #include "GrPendingIOResource.h" |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 13 | #include "GrGpuBuffer.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 14 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 15 | class GrPrimitiveProcessor; |
| 16 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 17 | /** |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 18 | * Used to communicate index and vertex buffers, counts, and offsets for a draw from GrOp to |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 19 | * GrGpu. It also holds the primitive type for the draw. TODO: Consider moving ownership of this |
| 20 | * and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vertex info lives there |
| 21 | * already (stride, attribute mappings). |
| 22 | */ |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 23 | class GrMesh { |
| 24 | public: |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 25 | GrMesh(GrPrimitiveType primitiveType = GrPrimitiveType::kTriangles) |
| 26 | : fPrimitiveType(primitiveType), fBaseVertex(0) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 27 | SkDEBUGCODE(fNonIndexNonInstanceData.fVertexCount = -1;) |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 28 | } |
| 29 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 30 | void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 31 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 32 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 33 | bool isIndexed() const { return SkToBool(fIndexBuffer.get()); } |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 34 | GrPrimitiveRestart primitiveRestart() const { |
| 35 | return GrPrimitiveRestart(fFlags & Flags::kUsePrimitiveRestart); |
| 36 | } |
| 37 | bool isInstanced() const { return fFlags & Flags::kIsInstanced; } |
| 38 | bool hasInstanceData() const { return SkToBool(fInstanceBuffer.get()); } |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 39 | bool hasVertexData() const { return SkToBool(fVertexBuffer.get()); } |
| 40 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 41 | void setNonIndexedNonInstanced(int vertexCount); |
| 42 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 43 | void setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 44 | uint16_t minIndexValue, uint16_t maxIndexValue, GrPrimitiveRestart); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 45 | void setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer, int indexCount, int vertexCount, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 46 | int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer); |
| 47 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 48 | void setInstanced(sk_sp<const GrBuffer> instanceBuffer, int instanceCount, int baseInstance, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 49 | int vertexCount); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 50 | void setIndexedInstanced(sk_sp<const GrBuffer> indexBuffer, int indexCount, |
| 51 | sk_sp<const GrBuffer> instanceBuffer, int instanceCount, |
| 52 | int baseInstance, GrPrimitiveRestart); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 53 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 54 | void setVertexData(sk_sp<const GrBuffer> vertexBuffer, int baseVertex = 0); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 55 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 56 | class SendToGpuImpl { |
| 57 | public: |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 58 | virtual void sendMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount, |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 59 | int baseVertex) = 0; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 60 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 61 | virtual void sendIndexedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, |
| 62 | int indexCount, int baseIndex, uint16_t minIndexValue, |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 63 | uint16_t maxIndexValue, const GrBuffer* vertexBuffer, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 64 | int baseVertex, GrPrimitiveRestart) = 0; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 65 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 66 | virtual void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, |
| 67 | int vertexCount, int baseVertex, |
| 68 | const GrBuffer* instanceBuffer, int instanceCount, |
| 69 | int baseInstance) = 0; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 70 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 71 | virtual void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, |
| 72 | int indexCount, int baseIndex, |
| 73 | const GrBuffer* vertexBuffer, int baseVertex, |
| 74 | const GrBuffer* instanceBuffer, |
| 75 | int instanceCount, int baseInstance, |
| 76 | GrPrimitiveRestart) = 0; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 77 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 78 | virtual ~SendToGpuImpl() {} |
| 79 | }; |
| 80 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 81 | void sendToGpu(SendToGpuImpl*) const; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 82 | |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 83 | private: |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 84 | enum class Flags { |
| 85 | kNone = 0, |
| 86 | kUsePrimitiveRestart = 1 << 0, |
| 87 | kIsInstanced = 1 << 1, |
| 88 | }; |
| 89 | |
| 90 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); |
| 91 | GR_STATIC_ASSERT(Flags(GrPrimitiveRestart::kNo) == Flags::kNone); |
| 92 | GR_STATIC_ASSERT(Flags(GrPrimitiveRestart::kYes) == Flags::kUsePrimitiveRestart); |
| 93 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 94 | GrPrimitiveType fPrimitiveType; |
Brian Salomon | 924a10e | 2019-02-01 12:15:18 -0500 | [diff] [blame] | 95 | sk_sp<const GrBuffer> fIndexBuffer; |
| 96 | sk_sp<const GrBuffer> fInstanceBuffer; |
| 97 | sk_sp<const GrBuffer> fVertexBuffer; |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 98 | int fBaseVertex; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 99 | Flags fFlags; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 100 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 101 | union { |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 102 | struct { // When fIndexBuffer == nullptr and isInstanced() == false. |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 103 | int fVertexCount; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 104 | } fNonIndexNonInstanceData; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 105 | |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 106 | struct { // When fIndexBuffer != nullptr and isInstanced() == false. |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 107 | struct { |
| 108 | int fIndexCount; |
| 109 | int fPatternRepeatCount; |
| 110 | } fIndexData; |
| 111 | |
| 112 | union { |
| 113 | struct { // When fPatternRepeatCount == 0. |
| 114 | int fBaseIndex; |
| 115 | uint16_t fMinIndexValue; |
| 116 | uint16_t fMaxIndexValue; |
| 117 | } fNonPatternIndexData; |
| 118 | |
| 119 | struct { // When fPatternRepeatCount != 0. |
| 120 | int fVertexCount; |
| 121 | int fMaxPatternRepetitionsInIndexBuffer; |
| 122 | } fPatternData; |
| 123 | }; |
| 124 | }; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 125 | |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 126 | struct { // When isInstanced() != false. |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 127 | struct { |
| 128 | int fInstanceCount; |
| 129 | int fBaseInstance; |
| 130 | } fInstanceData; |
| 131 | |
| 132 | union { // When fIndexBuffer == nullptr. |
| 133 | struct { |
| 134 | int fVertexCount; |
| 135 | } fInstanceNonIndexData; |
| 136 | |
| 137 | struct { // When fIndexBuffer != nullptr. |
| 138 | int fIndexCount; |
| 139 | } fInstanceIndexData; |
| 140 | }; |
| 141 | }; |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 142 | }; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 143 | }; |
| 144 | |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 145 | GR_MAKE_BITFIELD_CLASS_OPS(GrMesh::Flags); |
| 146 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 147 | inline void GrMesh::setNonIndexedNonInstanced(int vertexCount) { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 148 | fIndexBuffer.reset(); |
| 149 | fInstanceBuffer.reset(); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 150 | fNonIndexNonInstanceData.fVertexCount = vertexCount; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 151 | fFlags = Flags::kNone; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 152 | } |
| 153 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 154 | inline void GrMesh::setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 155 | uint16_t minIndexValue, uint16_t maxIndexValue, |
| 156 | GrPrimitiveRestart primitiveRestart) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 157 | SkASSERT(indexBuffer); |
| 158 | SkASSERT(indexCount >= 1); |
| 159 | SkASSERT(baseIndex >= 0); |
Chris Dalton | a88da48 | 2017-06-06 12:25:28 -0600 | [diff] [blame] | 160 | SkASSERT(maxIndexValue >= minIndexValue); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 161 | fIndexBuffer = std::move(indexBuffer); |
| 162 | fInstanceBuffer.reset(); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 163 | fIndexData.fIndexCount = indexCount; |
| 164 | fIndexData.fPatternRepeatCount = 0; |
| 165 | fNonPatternIndexData.fBaseIndex = baseIndex; |
| 166 | fNonPatternIndexData.fMinIndexValue = minIndexValue; |
| 167 | fNonPatternIndexData.fMaxIndexValue = maxIndexValue; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 168 | fFlags = Flags(primitiveRestart); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 169 | } |
| 170 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 171 | inline void GrMesh::setIndexedPatterned(sk_sp<const GrBuffer> indexBuffer, int indexCount, |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 172 | int vertexCount, int patternRepeatCount, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 173 | int maxPatternRepetitionsInIndexBuffer) { |
| 174 | SkASSERT(indexBuffer); |
| 175 | SkASSERT(indexCount >= 1); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 176 | SkASSERT(vertexCount >= 1); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 177 | SkASSERT(patternRepeatCount >= 1); |
| 178 | SkASSERT(maxPatternRepetitionsInIndexBuffer >= 1); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 179 | fIndexBuffer = std::move(indexBuffer); |
| 180 | fInstanceBuffer.reset(); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 181 | fIndexData.fIndexCount = indexCount; |
| 182 | fIndexData.fPatternRepeatCount = patternRepeatCount; |
| 183 | fPatternData.fVertexCount = vertexCount; |
| 184 | fPatternData.fMaxPatternRepetitionsInIndexBuffer = maxPatternRepetitionsInIndexBuffer; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 185 | fFlags = Flags::kNone; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 186 | } |
| 187 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 188 | inline void GrMesh::setInstanced(sk_sp<const GrBuffer> instanceBuffer, int instanceCount, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 189 | int baseInstance, int vertexCount) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 190 | SkASSERT(instanceCount >= 1); |
| 191 | SkASSERT(baseInstance >= 0); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 192 | fIndexBuffer.reset(); |
| 193 | fInstanceBuffer = std::move(instanceBuffer); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 194 | fInstanceData.fInstanceCount = instanceCount; |
| 195 | fInstanceData.fBaseInstance = baseInstance; |
| 196 | fInstanceNonIndexData.fVertexCount = vertexCount; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 197 | fFlags = Flags::kIsInstanced; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 198 | } |
| 199 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 200 | inline void GrMesh::setIndexedInstanced(sk_sp<const GrBuffer> indexBuffer, int indexCount, |
| 201 | sk_sp<const GrBuffer> instanceBuffer, int instanceCount, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 202 | int baseInstance, GrPrimitiveRestart primitiveRestart) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 203 | SkASSERT(indexBuffer); |
| 204 | SkASSERT(indexCount >= 1); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 205 | SkASSERT(instanceCount >= 1); |
| 206 | SkASSERT(baseInstance >= 0); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 207 | fIndexBuffer = std::move(indexBuffer); |
| 208 | fInstanceBuffer = std::move(instanceBuffer); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 209 | fInstanceData.fInstanceCount = instanceCount; |
| 210 | fInstanceData.fBaseInstance = baseInstance; |
| 211 | fInstanceIndexData.fIndexCount = indexCount; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 212 | fFlags = Flags::kIsInstanced | Flags(primitiveRestart); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 213 | } |
| 214 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 215 | inline void GrMesh::setVertexData(sk_sp<const GrBuffer> vertexBuffer, int baseVertex) { |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 216 | SkASSERT(baseVertex >= 0); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 217 | fVertexBuffer = std::move(vertexBuffer); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 218 | fBaseVertex = baseVertex; |
| 219 | } |
| 220 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 221 | inline void GrMesh::sendToGpu(SendToGpuImpl* impl) const { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 222 | if (this->isInstanced()) { |
| 223 | if (!this->isIndexed()) { |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 224 | impl->sendInstancedMeshToGpu(fPrimitiveType, fVertexBuffer.get(), |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 225 | fInstanceNonIndexData.fVertexCount, fBaseVertex, |
| 226 | fInstanceBuffer.get(), fInstanceData.fInstanceCount, |
| 227 | fInstanceData.fBaseInstance); |
| 228 | } else { |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 229 | impl->sendIndexedInstancedMeshToGpu( |
| 230 | fPrimitiveType, fIndexBuffer.get(), fInstanceIndexData.fIndexCount, 0, |
| 231 | fVertexBuffer.get(), fBaseVertex, fInstanceBuffer.get(), |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 232 | fInstanceData.fInstanceCount, fInstanceData.fBaseInstance, |
| 233 | this->primitiveRestart()); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 234 | } |
| 235 | return; |
| 236 | } |
| 237 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 238 | if (!this->isIndexed()) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 239 | SkASSERT(fNonIndexNonInstanceData.fVertexCount > 0); |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 240 | impl->sendMeshToGpu(fPrimitiveType, fVertexBuffer.get(), |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 241 | fNonIndexNonInstanceData.fVertexCount, fBaseVertex); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 242 | return; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 245 | if (0 == fIndexData.fPatternRepeatCount) { |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 246 | impl->sendIndexedMeshToGpu( |
| 247 | fPrimitiveType, fIndexBuffer.get(), fIndexData.fIndexCount, |
| 248 | fNonPatternIndexData.fBaseIndex, fNonPatternIndexData.fMinIndexValue, |
| 249 | fNonPatternIndexData.fMaxIndexValue, fVertexBuffer.get(), fBaseVertex, |
| 250 | this->primitiveRestart()); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 251 | return; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 254 | SkASSERT(fIndexData.fPatternRepeatCount > 0); |
| 255 | int baseRepetition = 0; |
| 256 | do { |
| 257 | int repeatCount = SkTMin(fPatternData.fMaxPatternRepetitionsInIndexBuffer, |
| 258 | fIndexData.fPatternRepeatCount - baseRepetition); |
| 259 | // A patterned index buffer must contain indices in the range [0..vertexCount]. |
| 260 | int minIndexValue = 0; |
| 261 | int maxIndexValue = fPatternData.fVertexCount * repeatCount - 1; |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 262 | SkASSERT(!(fFlags & Flags::kUsePrimitiveRestart)); |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 263 | impl->sendIndexedMeshToGpu( |
| 264 | fPrimitiveType, fIndexBuffer.get(), fIndexData.fIndexCount * repeatCount, 0, |
| 265 | minIndexValue, maxIndexValue, fVertexBuffer.get(), |
| 266 | fBaseVertex + fPatternData.fVertexCount * baseRepetition, GrPrimitiveRestart::kNo); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 267 | baseRepetition += repeatCount; |
| 268 | } while (baseRepetition < fIndexData.fPatternRepeatCount); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 269 | } |
| 270 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 271 | #endif |