| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::BufferBindingsGLES Class Reference

Sets up stage bindings for single draw call in the OpenGLES backend. More...

`#include <buffer_bindings_gles.h>`

## Public Member Functions
| BufferBindingsGLES ()
| ~BufferBindingsGLES ()
bool | RegisterVertexStageInput (const ProcTableGLES &gl, const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
bool | ReadUniformsBindings (const ProcTableGLES &gl, GLuint program)
bool | BindVertexAttributes (const ProcTableGLES &gl, size_t vertex_offset) const
bool | BindUniformData (const ProcTableGLES &gl, Allocator &transients_allocator, const Bindings &vertex_bindings, const Bindings &fragment_bindings)
bool | UnbindVertexAttributes (const ProcTableGLES &gl) const

## Detailed Description

Sets up stage bindings for single draw call in the OpenGLES backend.

Definition at line 22 of file buffer_bindings_gles.h.

## Constructor & Destructor Documentation

## ◆ BufferBindingsGLES()

impeller::BufferBindingsGLES::BufferBindingsGLES | ( |  | ) |
| default

## ◆ ~BufferBindingsGLES()

impeller::BufferBindingsGLES::~BufferBindingsGLES | ( |  | ) |
| default

## Member Function Documentation

## ◆ BindUniformData()

bool impeller::BufferBindingsGLES::BindUniformData | ( | const ProcTableGLES & | gl,
|  | Allocator & | transients_allocator,
|  | const Bindings & | vertex_bindings,
|  | const Bindings & | fragment_bindings
| ) |  |

Definition at line 162 of file buffer_bindings_gles.cc.

165 {
166 for (const auto& buffer : vertex_bindings.buffers) {
167 if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
168 return false;
169 }
170 }
171 for (const auto& buffer : fragment_bindings.buffers) {
172 if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
173 return false;
174 }
175 }
176
177 std::optional<size_t> next_unit_index =
178 BindTextures(gl, vertex_bindings, ShaderStage::kVertex);
179 if (!next_unit_index.has_value()) {
180 return false;
181 }
182
183 if (!BindTextures(gl, fragment_bindings, ShaderStage::kFragment,
184 *next_unit_index)
185 .has_value()) {
186 return false;
187 }
188
189 return true;
190 }

References impeller::Bindings::buffers, impeller::kFragment, and impeller::kVertex.

## ◆ BindVertexAttributes()

bool impeller::BufferBindingsGLES::BindVertexAttributes | ( | const ProcTableGLES & | gl,
|  | size_t | vertex_offset
| ) |  | const

Definition at line 145 of file buffer_bindings_gles.cc.

146 {
147 for (const auto& array : vertex_attrib_arrays_) {
148 gl.EnableVertexAttribArray(array.index);
149 gl.VertexAttribPointer(array.index, // index
150 array.size, // size (must be 1, 2, 3, or 4)
151 array.type, // type
152 array.normalized, // normalized
153 array.stride, // stride
154 reinterpret_cast<const GLvoid*>(static_cast<GLsizei>(
155 vertex_offset + array.offset)) // pointer
156 );
157 }
158
159 return true;
160 }

## ◆ ReadUniformsBindings()

bool impeller::BufferBindingsGLES::ReadUniformsBindings | ( | const ProcTableGLES & | gl,
|  | GLuint | program
| ) |  |

Definition at line 89 of file buffer_bindings_gles.cc.

90 {
91 if (!gl.IsProgram(program)) {
92 return false;
93 }
94 GLint max_name_size = 0;
95 gl.GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_size);
96
97 GLint uniform_count = 0;
98 gl.GetProgramiv(program, GL_ACTIVE_UNIFORMS, &uniform_count);
99
100 // Query the Program for all active uniform locations, and
101 // record this via normalized key.
102 for (GLint i = 0; i < uniform_count; i++) {
103 std::vector<GLchar> name;
104 name.resize(max_name_size);
105 GLsizei written_count = 0u;
106 GLint uniform_var_size = 0u;
107 GLenum uniform_type = GL_FLOAT;
108 // Note: Active uniforms are defined as uniforms that may have an impact on
109 // the output of the shader. Drivers are allowed to (and often do)
110 // optimize out unused uniforms.
111 gl.GetActiveUniform(program, // program
112 i, // index
113 max_name_size, // buffer_size
114 &written_count, // length
115 &uniform_var_size, // size
116 &uniform_type, // type
117 name.data() // name
118 );
119
120 // Skip unrecognized variables generated by ANGLE.
121 if (gl.GetCapabilities()->IsANGLE()) {
122 if (written_count >=
123 static_cast<GLsizei>(kAngleInputAttachmentPrefix.length()) &&
124 std::string_view(name.data(), kAngleInputAttachmentPrefix.length()) ==
125 kAngleInputAttachmentPrefix) {
126 continue;
127 }
128 }
129
130 auto location = gl.GetUniformLocation(program, name.data());
131 if (location == -1) {
132 VALIDATION_LOG << "Could not query the location of an active uniform.";
133 return false;
134 }
135 if (written_count <= 0) {
136 VALIDATION_LOG << "Uniform name could not be read for active uniform.";
137 return false;
138 }
139 uniform_locations_[NormalizeUniformKey(std::string{
140 name.data(), static_cast<size_t>(written_count)})] = location;
141 }
142 return true;
143 }

References impeller::ProcTableGLES::GetCapabilities(), impeller::kAngleInputAttachmentPrefix, impeller::NormalizeUniformKey(), and VALIDATION_LOG.

## ◆ RegisterVertexStageInput()

bool impeller::BufferBindingsGLES::RegisterVertexStageInput | ( | const ProcTableGLES & | gl,
|  | const std::vector< ShaderStageIOSlot > & | inputs,
|  | const std::vector< ShaderStageBufferLayout > & | layouts
| ) |  |

Definition at line 28 of file buffer_bindings_gles.cc.

31 {
32 std::vector<VertexAttribPointer> vertex_attrib_arrays;
33 for (auto i = 0u; i < p_inputs.size(); i++) {
34 const auto& input = p_inputs[i];
35 const auto& layout = layouts[input.binding];
36 VertexAttribPointer attrib;
37 attrib.index = input.location;
38 // Component counts must be 1, 2, 3 or 4. Do that validation now.
39 if (input.vec_size < 1u || input.vec_size > 4u) {
40 return false;
41 }
42 attrib.size = input.vec_size;
43 auto type = ToVertexAttribType(input.type);
44 if (!type.has_value()) {
45 return false;
46 }
47 attrib.type = type.value();
48 attrib.normalized = GL_FALSE;
49 attrib.offset = input.offset;
50 attrib.stride = layout.stride;
51 vertex_attrib_arrays.emplace_back(attrib);
52 }
53 vertex_attrib_arrays_ = std::move(vertex_attrib_arrays);
54 return true;
55 }

References impeller::ToVertexAttribType().

## ◆ UnbindVertexAttributes()

bool impeller::BufferBindingsGLES::UnbindVertexAttributes | ( | const ProcTableGLES & | gl | ) | const

Definition at line 192 of file buffer_bindings_gles.cc.

192 {
193 for (const auto& array : vertex_attrib_arrays_) {
194 gl.DisableVertexAttribArray(array.index);
195 }
196 return true;
197 }

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

- impeller/renderer/backend/gles/buffer_bindings_gles.h
- impeller/renderer/backend/gles/buffer_bindings_gles.cc

impeller::NormalizeUniformKey
static std::string NormalizeUniformKey(const std::string &key)
Definition: buffer_bindings_gles.cc:57
impeller::kAngleInputAttachmentPrefix
static constexpr std::string_view kAngleInputAttachmentPrefix
Definition: buffer_bindings_gles.cc:21
impeller::ShaderStage::kFragment
@ kFragment
impeller::ToVertexAttribType
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
Definition: formats_gles.h:139
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::ShaderStage::kVertex
@ kVertex