26 const std::vector<ShaderStageIOSlot>& p_inputs,
27 const std::vector<ShaderStageBufferLayout>& layouts) {
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;
35 if (input.vec_size < 1u || input.vec_size > 4u) {
38 attrib.size = input.vec_size;
40 if (!type.has_value()) {
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);
49 vertex_attrib_arrays_ = std::move(vertex_attrib_arrays);
55 result.reserve(key.length());
58 result.push_back(toupper(ch));
65 const std::string& member,
68 result.reserve(struct_name.length() + member.length() + (is_array ? 4 : 1));
69 result += struct_name;
79 const std::string& non_struct_member) {
85 if (!gl.IsProgram(program)) {
88 GLint max_name_size = 0;
89 gl.GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_size);
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;
102 gl.GetActiveUniform(program,
110 auto location = gl.GetUniformLocation(program, name.data());
111 if (location == -1) {
112 VALIDATION_LOG <<
"Could not query the location of an active uniform.";
115 if (written_count <= 0) {
116 VALIDATION_LOG <<
"Uniform name could not be read for active uniform.";
120 name.data(),
static_cast<size_t>(written_count)})] = location;
126 size_t vertex_offset)
const {
127 for (
const auto& array : vertex_attrib_arrays_) {
128 gl.EnableVertexAttribArray(array.index);
129 gl.VertexAttribPointer(array.index,
134 reinterpret_cast<const GLvoid*
>(
static_cast<GLsizei
>(
135 vertex_offset + array.offset))
146 const Bindings& fragment_bindings)
const {
147 for (
const auto& buffer : vertex_bindings.
buffers) {
148 if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
152 for (
const auto& buffer : fragment_bindings.
buffers) {
153 if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
170 for (
const auto& array : vertex_attrib_arrays_) {
171 gl.DisableVertexAttribArray(array.index);
176 bool BufferBindingsGLES::BindUniformBuffer(
const ProcTableGLES& gl,
182 if (!device_buffer) {
187 const uint8_t* buffer_ptr =
190 if (metadata->members.empty()) {
191 VALIDATION_LOG <<
"Uniform buffer had no members. This is currently "
192 "unsupported in the OpenGL ES backend. Use a uniform "
197 for (
const auto& member : metadata->members) {
204 size_t element_count = member.array_elements.value_or(1);
206 const auto member_key =
208 const auto location = uniform_locations_.find(member_key);
209 if (location == uniform_locations_.end()) {
216 size_t element_stride = member.byte_length / element_count;
219 reinterpret_cast<const GLfloat*
>(buffer_ptr + member.offset);
221 std::vector<uint8_t> array_element_buffer;
222 if (element_count > 1) {
226 array_element_buffer.resize(member.size * element_count);
227 for (
size_t element_i = 0; element_i < element_count; element_i++) {
228 std::memcpy(array_element_buffer.data() + element_i * member.size,
229 reinterpret_cast<const char*
>(buffer_data) +
230 element_i * element_stride,
234 reinterpret_cast<const GLfloat*
>(array_element_buffer.data());
237 switch (member.type) {
239 switch (member.size) {
241 gl.UniformMatrix4fv(location->second,
247 case sizeof(Vector4):
248 gl.Uniform4fv(location->second,
253 case sizeof(Vector3):
254 gl.Uniform3fv(location->second,
260 gl.Uniform2fv(location->second,
266 gl.Uniform1fv(location->second,
298 bool BufferBindingsGLES::BindTextures(
const ProcTableGLES& gl,
299 const Bindings& bindings,
301 size_t active_index = 0;
302 for (
const auto& data : bindings.sampled_images) {
304 if (data.second.texture.GetMetadata() ==
nullptr) {
309 const auto uniform_key =
311 auto uniform = uniform_locations_.find(uniform_key);
312 if (uniform == uniform_locations_.end()) {
313 VALIDATION_LOG <<
"Could not find uniform for key: " << uniform_key;
320 if (active_index >= gl.GetCapabilities()->GetMaxTextureUnits(stage)) {
321 VALIDATION_LOG <<
"Texture units specified exceed the capabilities for "
322 "this shader stage.";
325 gl.ActiveTexture(GL_TEXTURE0 + active_index);
330 if (!texture_gles.Bind()) {
339 if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
346 gl.Uniform1i(uniform->second, active_index);