Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
GrGLAttribArrayState Class Reference

#include <GrGLVertexArray.h>

Public Member Functions

 GrGLAttribArrayState (int arrayCount=0)
 
void resize (int newCount)
 
void set (GrGLGpu *, int attribIndex, const GrBuffer *vertexBuffer, GrVertexAttribType cpuType, SkSLType gpuType, GrGLsizei stride, size_t offsetInBytes, int divisor=0)
 
void enableVertexArrays (const GrGLGpu *, int enabledCount, GrPrimitiveRestart=GrPrimitiveRestart::kNo)
 
void invalidate ()
 
int count () const
 

Detailed Description

This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray (below) but is separate because it is also used to track the state of vertex array object 0.

Definition at line 26 of file GrGLVertexArray.h.

Constructor & Destructor Documentation

◆ GrGLAttribArrayState()

GrGLAttribArrayState::GrGLAttribArrayState ( int  arrayCount = 0)
inlineexplicit

Definition at line 28 of file GrGLVertexArray.h.

28 {
29 this->resize(arrayCount);
30 }
void resize(int newCount)

Member Function Documentation

◆ count()

int GrGLAttribArrayState::count ( ) const
inline

The number of attrib arrays that this object is configured to track.

Definition at line 68 of file GrGLVertexArray.h.

68{ return fAttribArrayStates.size(); }
int size() const
Definition: SkTArray.h:421

◆ enableVertexArrays()

void GrGLAttribArrayState::enableVertexArrays ( const GrGLGpu gpu,
int  enabledCount,
GrPrimitiveRestart  enablePrimitiveRestart = GrPrimitiveRestart::kNo 
)

This function enables the first 'enabledCount' vertex arrays and disables the rest.

Definition at line 156 of file GrGLVertexArray.cpp.

157 {
158 SkASSERT(enabledCount <= fAttribArrayStates.size());
159
160 if (!fEnableStateIsValid || enabledCount != fNumEnabledArrays) {
161 int firstIdxToEnable = fEnableStateIsValid ? fNumEnabledArrays : 0;
162 for (int i = firstIdxToEnable; i < enabledCount; ++i) {
163 GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(i));
164 }
165
166 int endIdxToDisable = fEnableStateIsValid ? fNumEnabledArrays : fAttribArrayStates.size();
167 for (int i = enabledCount; i < endIdxToDisable; ++i) {
168 GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i));
169 }
170
171 fNumEnabledArrays = enabledCount;
172 }
173
174 SkASSERT(GrPrimitiveRestart::kNo == enablePrimitiveRestart ||
175 gpu->caps()->usePrimitiveRestart());
176
177 if (gpu->caps()->usePrimitiveRestart() &&
178 (!fEnableStateIsValid || enablePrimitiveRestart != fPrimitiveRestartEnabled)) {
179 if (GrPrimitiveRestart::kYes == enablePrimitiveRestart) {
181 } else {
183 }
184
185 fPrimitiveRestartEnabled = enablePrimitiveRestart;
186 }
187
188 fEnableStateIsValid = true;
189}
#define GR_GL_PRIMITIVE_RESTART_FIXED_INDEX
Definition: GrGLDefines.h:844
#define GR_GL_CALL(IFACE, X)
Definition: GrGLUtil.h:381
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool usePrimitiveRestart() const
Definition: GrCaps.h:112
const GrGLInterface * glInterface() const
Definition: GrGLGpu.h:103
const GrCaps * caps() const
Definition: GrGpu.h:73

◆ invalidate()

void GrGLAttribArrayState::invalidate ( )
inline

Definition at line 57 of file GrGLVertexArray.h.

57 {
58 int count = fAttribArrayStates.size();
59 for (int i = 0; i < count; ++i) {
60 fAttribArrayStates[i].invalidate();
61 }
62 fEnableStateIsValid = false;
63 }

◆ resize()

void GrGLAttribArrayState::resize ( int  newCount)
inline

Definition at line 32 of file GrGLVertexArray.h.

32 {
33 fAttribArrayStates.resize_back(newCount);
34 this->invalidate();
35 }
void resize_back(int newCount)
Definition: SkTArray.h:343

◆ set()

void GrGLAttribArrayState::set ( GrGLGpu gpu,
int  attribIndex,
const GrBuffer vertexBuffer,
GrVertexAttribType  cpuType,
SkSLType  gpuType,
GrGLsizei  stride,
size_t  offsetInBytes,
int  divisor = 0 
)

This function enables and sets vertex attrib state for the specified attrib index. It is assumed that the GrGLAttribArrayState is tracking the state of the currently bound vertex array object.

Definition at line 91 of file GrGLVertexArray.cpp.

98 {
99 SkASSERT(index >= 0 && index < fAttribArrayStates.size());
100 SkASSERT(0 == divisor || gpu->caps()->drawInstancedSupport());
101 AttribArrayState* array = &fAttribArrayStates[index];
102 const char* offsetAsPtr;
103 bool bufferChanged = false;
104 if (vertexBuffer->isCpuBuffer()) {
105 if (!array->fUsingCpuBuffer) {
106 bufferChanged = true;
107 array->fUsingCpuBuffer = true;
108 }
109 offsetAsPtr = static_cast<const GrCpuBuffer*>(vertexBuffer)->data() + offsetInBytes;
110 } else {
111 auto gpuBuffer = static_cast<const GrGpuBuffer*>(vertexBuffer);
112 if (array->fUsingCpuBuffer || array->fVertexBufferUniqueID != gpuBuffer->uniqueID()) {
113 bufferChanged = true;
114 array->fVertexBufferUniqueID = gpuBuffer->uniqueID();
115 }
116 offsetAsPtr = reinterpret_cast<const char*>(offsetInBytes);
117 }
118 if (bufferChanged ||
119 array->fCPUType != cpuType ||
120 array->fGPUType != gpuType ||
121 array->fStride != stride ||
122 array->fOffset != offsetAsPtr) {
123 // We always have to call this if we're going to change the array pointer. 'array' is
124 // tracking the last buffer used to setup attrib pointers, not the last buffer bound.
125 // GrGLGpu will avoid redundant binds.
126 gpu->bindBuffer(GrGpuBufferType::kVertex, vertexBuffer);
127 const AttribLayout& layout = attrib_layout(cpuType);
128 if (SkSLTypeIsFloatType(gpuType)) {
129 GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
130 layout.fCount,
131 layout.fType,
132 layout.fNormalized,
133 stride,
134 offsetAsPtr));
135 } else {
137 SkASSERT(!layout.fNormalized);
138 GR_GL_CALL(gpu->glInterface(), VertexAttribIPointer(index,
139 layout.fCount,
140 layout.fType,
141 stride,
142 offsetAsPtr));
143 }
144 array->fCPUType = cpuType;
145 array->fGPUType = gpuType;
146 array->fStride = stride;
147 array->fOffset = offsetAsPtr;
148 }
149 if (gpu->caps()->drawInstancedSupport() && array->fDivisor != divisor) {
150 SkASSERT(0 == divisor || 1 == divisor); // not necessarily a requirement but what we expect.
151 GR_GL_CALL(gpu->glInterface(), VertexAttribDivisor(index, divisor));
152 array->fDivisor = divisor;
153 }
154}
static AttribLayout attrib_layout(GrVertexAttribType type)
static constexpr bool SkSLTypeIsFloatType(SkSLType type)
virtual bool isCpuBuffer() const =0
const GrShaderCaps * shaderCaps() const
Definition: GrCaps.h:63
bool drawInstancedSupport() const
Definition: GrCaps.h:80
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer *)
Definition: GrGLGpu.cpp:2154
UniqueID uniqueID() const
bool fIntegerSupport
Definition: SkSLUtil.h:89
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

The documentation for this class was generated from the following files: