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) const
 
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 
) const

Definition at line 142 of file buffer_bindings_gles.cc.

146  {
147  for (const auto& buffer : vertex_bindings.buffers) {
148  if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
149  return false;
150  }
151  }
152  for (const auto& buffer : fragment_bindings.buffers) {
153  if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
154  return false;
155  }
156  }
157 
158  if (!BindTextures(gl, vertex_bindings, ShaderStage::kVertex)) {
159  return false;
160  }
161 
162  if (!BindTextures(gl, fragment_bindings, ShaderStage::kFragment)) {
163  return false;
164  }
165 
166  return true;
167 }

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

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

◆ 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  for (GLint i = 0; i < uniform_count; i++) {
94  std::vector<GLchar> name;
95  name.resize(max_name_size);
96  GLsizei written_count = 0u;
97  GLint uniform_var_size = 0u;
98  GLenum uniform_type = GL_FLOAT;
99  // Note: Active uniforms are defined as uniforms that may have an impact on
100  // the output of the shader. Drivers are allowed to (and often do)
101  // optimize out unused uniforms.
102  gl.GetActiveUniform(program, // program
103  i, // index
104  max_name_size, // buffer_size
105  &written_count, // length
106  &uniform_var_size, // size
107  &uniform_type, // type
108  name.data() // name
109  );
110  auto location = gl.GetUniformLocation(program, name.data());
111  if (location == -1) {
112  VALIDATION_LOG << "Could not query the location of an active uniform.";
113  return false;
114  }
115  if (written_count <= 0) {
116  VALIDATION_LOG << "Uniform name could not be read for active uniform.";
117  return false;
118  }
119  uniform_locations_[NormalizeUniformKey(std::string{
120  name.data(), static_cast<size_t>(written_count)})] = location;
121  }
122  return true;
123 }

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

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

References impeller::ToVertexAttribType().

◆ UnbindVertexAttributes()

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

Definition at line 169 of file buffer_bindings_gles.cc.

169  {
170  for (const auto& array : vertex_attrib_arrays_) {
171  gl.DisableVertexAttribArray(array.index);
172  }
173  return true;
174 }

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:53
impeller::ShaderStage::kFragment
@ kFragment
impeller::ToVertexAttribType
constexpr std::optional< GLenum > ToVertexAttribType(ShaderType type)
Definition: formats_gles.h:138
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::ShaderStage::kVertex
@ kVertex