Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLVertexArray.h
Go to the documentation of this file.
1/*
2 * Copyright 2013 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 GrGLVertexArray_DEFINED
9#define GrGLVertexArray_DEFINED
10
15
16#include <cstddef>
17
18class GrBuffer;
19class GrGLGpu;
20enum class SkSLType : char;
21
22/**
23 * This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray
24 * (below) but is separate because it is also used to track the state of vertex array object 0.
25 */
27public:
28 explicit GrGLAttribArrayState(int arrayCount = 0) {
29 this->resize(arrayCount);
30 }
31
32 void resize(int newCount) {
33 fAttribArrayStates.resize_back(newCount);
34 this->invalidate();
35 }
36
37 /**
38 * This function enables and sets vertex attrib state for the specified attrib index. It is
39 * assumed that the GrGLAttribArrayState is tracking the state of the currently bound vertex
40 * array object.
41 */
42 void set(GrGLGpu*,
43 int attribIndex,
44 const GrBuffer* vertexBuffer,
45 GrVertexAttribType cpuType,
46 SkSLType gpuType,
47 GrGLsizei stride,
48 size_t offsetInBytes,
49 int divisor = 0);
50
51 /**
52 * This function enables the first 'enabledCount' vertex arrays and disables the rest.
53 */
54 void enableVertexArrays(const GrGLGpu*, int enabledCount,
56
57 void invalidate() {
58 int count = fAttribArrayStates.size();
59 for (int i = 0; i < count; ++i) {
60 fAttribArrayStates[i].invalidate();
61 }
62 fEnableStateIsValid = false;
63 }
64
65 /**
66 * The number of attrib arrays that this object is configured to track.
67 */
68 int count() const { return fAttribArrayStates.size(); }
69
70private:
71 inline static constexpr int kInvalidDivisor = -1;
72
73 /**
74 * Tracks the state of glVertexAttribArray for an attribute index.
75 */
76 struct AttribArrayState {
77 void invalidate() {
78 fVertexBufferUniqueID.makeInvalid();
79 fDivisor = kInvalidDivisor;
80 fUsingCpuBuffer = false;
81 }
82
83 GrGpuResource::UniqueID fVertexBufferUniqueID;
84 bool fUsingCpuBuffer;
85 GrVertexAttribType fCPUType;
86 SkSLType fGPUType;
87 GrGLsizei fStride;
88 const GrGLvoid* fOffset;
89 int fDivisor;
90 };
91
93 int fNumEnabledArrays;
94 GrPrimitiveRestart fPrimitiveRestartEnabled;
95 bool fEnableStateIsValid = false;
96};
97
98/**
99 * This class represents an OpenGL vertex array object. It manages the lifetime of the vertex array
100 * and is used to track the state of the vertex array to avoid redundant GL calls.
101 */
103public:
104 GrGLVertexArray(GrGLint id, int attribCount);
105
106 /**
107 * Binds this vertex array. If the ID has been deleted or abandoned then nullptr is returned.
108 * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's attrib bindings is
109 * returned.
110 */
112
113 /**
114 * This is a version of the above function that also binds an index buffer to the vertex
115 * array object.
116 */
117 GrGLAttribArrayState* bindWithIndexBuffer(GrGLGpu* gpu, const GrBuffer* indexBuffer);
118
119 GrGLuint arrayID() const { return fID; }
120
122
123private:
124 GrGLuint fID;
125 GrGLAttribArrayState fAttribArrays;
126 GrGpuResource::UniqueID fIndexBufferUniqueID;
127};
128
129#endif
unsigned int GrGLuint
Definition GrGLTypes.h:113
int GrGLsizei
Definition GrGLTypes.h:109
int GrGLint
Definition GrGLTypes.h:108
void GrGLvoid
Definition GrGLTypes.h:120
GrPrimitiveRestart
Definition GrTypesPriv.h:55
GrVertexAttribType
SkSLType
void resize(int newCount)
GrGLAttribArrayState(int arrayCount=0)
void enableVertexArrays(const GrGLGpu *, int enabledCount, GrPrimitiveRestart=GrPrimitiveRestart::kNo)
GrGLAttribArrayState * bind(GrGLGpu *)
GrGLAttribArrayState * bindWithIndexBuffer(GrGLGpu *gpu, const GrBuffer *indexBuffer)
GrGLuint arrayID() const
void resize_back(int newCount)
Definition SkTArray.h:338
int size() const
Definition SkTArray.h:416