Flutter Engine
The Flutter Engine
GrDrawIndirectCommand.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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 GrDrawIndirectCommand_DEFINED
9#define GrDrawIndirectCommand_DEFINED
10
11#include <stdint.h>
12#include <utility>
13
15 uint32_t fVertexCount;
17 int32_t fBaseVertex;
18 uint32_t fBaseInstance;
19};
20
21static_assert(sizeof(GrDrawIndirectCommand) == 16, "GrDrawIndirectCommand must be tightly packed");
22
24 uint32_t fIndexCount;
26 uint32_t fBaseIndex;
27 int32_t fBaseVertex;
28 uint32_t fBaseInstance;
29};
30
31static_assert(sizeof(GrDrawIndexedIndirectCommand) == 20,
32 "GrDrawIndexedIndirectCommand must be tightly packed");
33
34// Helper for writing commands to an indirect draw buffer. Usage:
35//
36// GrDrawIndirectWriter indirectWriter = target->makeDrawIndirectSpace(...);
37// indirectWriter.write(...);
38// indirectWriter.write(...);
40public:
42 GrDrawIndirectWriter(void* data) : fData(static_cast<GrDrawIndirectCommand*>(data)) {}
44 GrDrawIndirectWriter(GrDrawIndirectWriter&& that) { *this = std::move(that); }
45
48 fData = that.fData;
49 that.fData = nullptr;
50 return *this;
51 }
52
53 bool operator==(const GrDrawIndirectWriter& that) { return fData == that.fData; }
54
55 explicit operator bool() const { return fData != nullptr; }
56
57 GrDrawIndirectWriter makeOffset(int drawCount) const { return {fData + drawCount}; }
58
59 inline void write(uint32_t instanceCount, uint32_t baseInstance, uint32_t vertexCount,
60 int32_t baseVertex) {
61 *fData++ = {vertexCount, instanceCount, baseVertex, baseInstance};
62 }
63
64private:
66};
67
68// Helper for writing commands to an indexed indirect draw buffer. Usage:
69//
70// GrDrawIndexedIndirectWriter indirectWriter = target->makeDrawIndexedIndirectSpace(...);
71// indirectWriter.writeIndexed(...);
72// indirectWriter.writeIndexed(...);
74public:
77 : fData(static_cast<GrDrawIndexedIndirectCommand*>(data)) {}
79 GrDrawIndexedIndirectWriter(GrDrawIndexedIndirectWriter&& that) { *this = std::move(that); }
80
83 fData = that.fData;
84 that.fData = nullptr;
85 return *this;
86 }
87
88 bool operator==(const GrDrawIndexedIndirectWriter& that) { return fData == that.fData; }
89
90 explicit operator bool() const { return fData != nullptr; }
91
92 GrDrawIndexedIndirectWriter makeOffset(int drawCount) const { return {fData + drawCount}; }
93
94 inline void writeIndexed(uint32_t indexCount, uint32_t baseIndex, uint32_t instanceCount,
95 uint32_t baseInstance, int32_t baseVertex) {
96 *fData++ = {indexCount, instanceCount, baseIndex, baseVertex, baseInstance};
97 }
98
99private:
101};
102
103#endif
GrDrawIndexedIndirectWriter(const GrDrawIndexedIndirectWriter &)=delete
GrDrawIndexedIndirectWriter & operator=(const GrDrawIndexedIndirectWriter &)=delete
GrDrawIndexedIndirectWriter(GrDrawIndexedIndirectWriter &&that)
void writeIndexed(uint32_t indexCount, uint32_t baseIndex, uint32_t instanceCount, uint32_t baseInstance, int32_t baseVertex)
GrDrawIndexedIndirectWriter & operator=(GrDrawIndexedIndirectWriter &&that)
GrDrawIndexedIndirectWriter makeOffset(int drawCount) const
bool operator==(const GrDrawIndexedIndirectWriter &that)
GrDrawIndirectWriter & operator=(GrDrawIndirectWriter &&that)
GrDrawIndirectWriter(GrDrawIndirectWriter &&that)
void write(uint32_t instanceCount, uint32_t baseInstance, uint32_t vertexCount, int32_t baseVertex)
bool operator==(const GrDrawIndirectWriter &that)
GrDrawIndirectWriter(const GrDrawIndirectWriter &)=delete
GrDrawIndirectWriter makeOffset(int drawCount) const
GrDrawIndirectWriter()=default
GrDrawIndirectWriter & operator=(const GrDrawIndirectWriter &)=delete
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63