blob: af05400f108e015f5d9a4f7ea7269cef7957a4d2 [file] [log] [blame]
bsalomoncb8979d2015-05-05 09:51:38 -07001/*
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
Chris Daltoneb694b72020-03-16 09:25:50 -06008#ifndef GrSimpleMesh_DEFINED
9#define GrSimpleMesh_DEFINED
bsalomoncb8979d2015-05-05 09:51:38 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrBuffer.h"
12#include "src/gpu/GrGpuBuffer.h"
Chris Dalton33db9fc2020-02-25 18:52:12 -070013#include "src/gpu/GrOpsRenderPass.h"
bsalomoncb8979d2015-05-05 09:51:38 -070014
Chris Dalton114a3c02017-05-26 15:17:19 -060015class GrPrimitiveProcessor;
16
bsalomoncb8979d2015-05-05 09:51:38 -070017/**
Chris Daltoneb694b72020-03-16 09:25:50 -060018 * 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.
bsalomoncb8979d2015-05-05 09:51:38 -070020 */
Chris Dalton765ed362020-03-16 17:34:44 -060021struct GrSimpleMesh {
Chris Dalton37c7bdd2020-03-13 09:21:12 -060022 void set(sk_sp<const GrBuffer> vertexBuffer, int vertexCount, int baseVertex);
Brian Salomon12d22642019-01-29 14:38:50 -050023 void setIndexed(sk_sp<const GrBuffer> indexBuffer, int indexCount, int baseIndex,
Chris Dalton37c7bdd2020-03-13 09:21:12 -060024 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);
Chris Daltonbca46e22017-05-15 11:03:26 -060030
Brian Salomon924a10e2019-02-01 12:15:18 -050031 sk_sp<const GrBuffer> fIndexBuffer;
Chris Dalton0f9c2c92020-03-12 15:49:03 -060032 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
Brian Salomon924a10e2019-02-01 12:15:18 -050040 sk_sp<const GrBuffer> fVertexBuffer;
Chris Dalton0f9c2c92020-03-12 15:49:03 -060041 int fVertexCount;
Chris Dalton34280e22019-12-20 11:08:25 -070042 int fBaseVertex = 0;
Chris Daltonff926502017-05-03 14:36:54 -040043
Chris Dalton0f9c2c92020-03-12 15:49:03 -060044 SkDEBUGCODE(bool fIsInitialized = false;)
Chris Daltonff926502017-05-03 14:36:54 -040045};
46
Chris Daltoneb694b72020-03-16 09:25:50 -060047inline void GrSimpleMesh::set(sk_sp<const GrBuffer> vertexBuffer, int vertexCount, int baseVertex) {
Chris Dalton37c7bdd2020-03-13 09:21:12 -060048 SkASSERT(baseVertex >= 0);
Brian Salomondbf70722019-02-07 11:31:24 -050049 fIndexBuffer.reset();
Chris Dalton37c7bdd2020-03-13 09:21:12 -060050 fVertexBuffer = std::move(vertexBuffer);
Chris Dalton0f9c2c92020-03-12 15:49:03 -060051 fVertexCount = vertexCount;
Chris Dalton37c7bdd2020-03-13 09:21:12 -060052 fBaseVertex = baseVertex;
Chris Dalton0f9c2c92020-03-12 15:49:03 -060053 SkDEBUGCODE(fIsInitialized = true;)
Chris Daltonbca46e22017-05-15 11:03:26 -060054}
55
Chris Daltoneb694b72020-03-16 09:25:50 -060056inline 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) {
Chris Daltonbca46e22017-05-15 11:03:26 -060060 SkASSERT(indexBuffer);
61 SkASSERT(indexCount >= 1);
62 SkASSERT(baseIndex >= 0);
Chris Daltona88da482017-06-06 12:25:28 -060063 SkASSERT(maxIndexValue >= minIndexValue);
Chris Dalton37c7bdd2020-03-13 09:21:12 -060064 SkASSERT(baseVertex >= 0);
Brian Salomon12d22642019-01-29 14:38:50 -050065 fIndexBuffer = std::move(indexBuffer);
Chris Dalton0f9c2c92020-03-12 15:49:03 -060066 fIndexCount = indexCount;
67 fPatternRepeatCount = 0;
68 fBaseIndex = baseIndex;
69 fMinIndexValue = minIndexValue;
70 fMaxIndexValue = maxIndexValue;
71 fPrimitiveRestart = primitiveRestart;
Chris Dalton37c7bdd2020-03-13 09:21:12 -060072 fVertexBuffer = std::move(vertexBuffer);
73 fBaseVertex = baseVertex;
Chris Dalton0f9c2c92020-03-12 15:49:03 -060074 SkDEBUGCODE(fIsInitialized = true;)
Chris Daltonbca46e22017-05-15 11:03:26 -060075}
76
Chris Daltoneb694b72020-03-16 09:25:50 -060077inline 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) {
Chris Daltonbca46e22017-05-15 11:03:26 -060081 SkASSERT(indexBuffer);
82 SkASSERT(indexCount >= 1);
Chris Dalton37c7bdd2020-03-13 09:21:12 -060083 SkASSERT(patternVertexCount >= 1);
Chris Daltonbca46e22017-05-15 11:03:26 -060084 SkASSERT(patternRepeatCount >= 1);
85 SkASSERT(maxPatternRepetitionsInIndexBuffer >= 1);
Chris Dalton37c7bdd2020-03-13 09:21:12 -060086 SkASSERT(baseVertex >= 0);
Brian Salomon12d22642019-01-29 14:38:50 -050087 fIndexBuffer = std::move(indexBuffer);
Chris Dalton0f9c2c92020-03-12 15:49:03 -060088 fIndexCount = indexCount;
89 fPatternRepeatCount = patternRepeatCount;
Chris Dalton37c7bdd2020-03-13 09:21:12 -060090 fVertexCount = patternVertexCount;
Chris Dalton0f9c2c92020-03-12 15:49:03 -060091 fMaxPatternRepetitionsInIndexBuffer = maxPatternRepetitionsInIndexBuffer;
92 fPrimitiveRestart = GrPrimitiveRestart::kNo;
Brian Salomon12d22642019-01-29 14:38:50 -050093 fVertexBuffer = std::move(vertexBuffer);
Chris Daltonbca46e22017-05-15 11:03:26 -060094 fBaseVertex = baseVertex;
Chris Dalton37c7bdd2020-03-13 09:21:12 -060095 SkDEBUGCODE(fIsInitialized = true;)
Chris Daltonbca46e22017-05-15 11:03:26 -060096}
97
bsalomoncb8979d2015-05-05 09:51:38 -070098#endif