Flutter Impeller
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 145 of file buffer_bindings_gles.cc.

148  {
149  for (const auto& buffer : vertex_bindings.buffers) {
150  if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
151  return false;
152  }
153  }
154  for (const auto& buffer : fragment_bindings.buffers) {
155  if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
156  return false;
157  }
158  }
159 
160  std::optional<size_t> next_unit_index =
161  BindTextures(gl, vertex_bindings, ShaderStage::kVertex);
162  if (!next_unit_index.has_value()) {
163  return false;
164  }
165 
166  if (!BindTextures(gl, fragment_bindings, ShaderStage::kFragment,
167  *next_unit_index)
168  .has_value()) {
169  return false;
170  }
171 
172  return true;
173 }

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 128 of file buffer_bindings_gles.cc.

129  {
130  for (const auto& array : vertex_attrib_arrays_) {
131  gl.EnableVertexAttribArray(array.index);
132  gl.VertexAttribPointer(array.index, // index
133  array.size, // size (must be 1, 2, 3, or 4)
134  array.type, // type
135  array.normalized, // normalized
136  array.stride, // stride
137  reinterpret_cast<const GLvoid*>(static_cast<GLsizei>(
138  vertex_offset + array.offset)) // pointer
139  );
140  }
141 
142  return true;
143 }

◆ ReadUniformsBindings()

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

Definition at line 83 of file buffer_bindings_gles.cc.

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

References 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 22 of file buffer_bindings_gles.cc.

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

References impeller::ToVertexAttribType().

◆ UnbindVertexAttributes()

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

Definition at line 175 of file buffer_bindings_gles.cc.

175  {
176  for (const auto& array : vertex_attrib_arrays_) {
177  gl.DisableVertexAttribArray(array.index);
178  }
179  return true;
180 }

The documentation for this class was generated from the following files:
impeller::NormalizeUniformKey
static std::string NormalizeUniformKey(const std::string &key)
Definition: buffer_bindings_gles.cc:51
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:67
impeller::ShaderStage::kVertex
@ kVertex