| Flutter Impeller |

buffer_bindings_gles.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
7
8 #include <vector>
9
10 #include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"
11 #include "impeller/core/shader_types.h"
12 #include "impeller/renderer/backend/gles/device_buffer_gles.h"
13 #include "impeller/renderer/backend/gles/gles.h"
14 #include "impeller/renderer/backend/gles/proc_table_gles.h"
15 #include "impeller/renderer/command.h"
16
17 namespace impeller {
18
19 namespace testing {
20 FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData);
21 FML_TEST_CLASS(BufferBindingsGLESTest, BindArrayData);
22 } // namespace testing
23
24 //------------------------------------------------------------------------------
25 /// @brief Sets up stage bindings for single draw call in the OpenGLES
26 /// backend.
27 ///
28 class BufferBindingsGLES {
29 public:
30 BufferBindingsGLES();
31
32 ~BufferBindingsGLES();
33
34 bool RegisterVertexStageInput(
35 const ProcTableGLES& gl,
36 const std::vector<ShaderStageIOSlot>& inputs,
37 const std::vector<ShaderStageBufferLayout>& layouts);
38
39 bool ReadUniformsBindings(const ProcTableGLES& gl, GLuint program);
40
41 bool BindVertexAttributes(const ProcTableGLES& gl,
42 size_t binding,
43 size_t vertex_offset);
44
45 bool BindUniformData(const ProcTableGLES& gl,
46 const std::vector<TextureAndSampler>& bound_textures,
47 const std::vector<BufferResource>& bound_buffers,
48 Range texture_range,
49 Range buffer_range);
50
51 bool UnbindVertexAttributes(const ProcTableGLES& gl);
52
53 private:
54 FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindUniformData);
55 FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindArrayData);
56 //----------------------------------------------------------------------------
57 /// @brief The arguments to glVertexAttribPointer.
58 ///
59 struct VertexAttribPointer {
60 GLuint index = 0u;
61 GLint size = 4;
62 GLenum type = GL_FLOAT;
63 GLenum normalized = GL_FALSE;
64 GLsizei stride = 0u;
65 GLsizei offset = 0u;
66 };
67 std::vector<std::vector<VertexAttribPointer>> vertex_attrib_arrays_;
68
69 absl::flat_hash_map<std::string, GLint> uniform_locations_;
70 absl::flat_hash_map<std::string, std::pair<GLint, GLuint>> ubo_locations_;
71
72 using BindingMap = absl::flat_hash_map<std::string, std::vector<GLint>>;
73 BindingMap binding_map_ = {};
74 GLuint vertex_array_object_ = 0;
75 GLuint program_handle_ = GL_NONE;
76 bool use_ubo_ = false;
77
78 const std::vector<GLint>& ComputeUniformLocations(
79 const ShaderMetadata* metadata);
80
81 bool ReadUniformsBindingsV2(const ProcTableGLES& gl, GLuint program);
82
83 bool ReadUniformsBindingsV3(const ProcTableGLES& gl, GLuint program);
84
85 GLint ComputeTextureLocation(const ShaderMetadata* metadata);
86
87 bool BindUniformBuffer(const ProcTableGLES& gl, const BufferResource& buffer);
88
89 bool BindUniformBufferV2(const ProcTableGLES& gl,
90 const BufferView& buffer,
91 const ShaderMetadata* metadata,
92 const DeviceBufferGLES& device_buffer_gles);
93
94 bool BindUniformBufferV3(const ProcTableGLES& gl,
95 const BufferView& buffer,
96 const ShaderMetadata* metadata,
97 const DeviceBufferGLES& device_buffer_gles);
98
99 std::optional<size_t> BindTextures(
100 const ProcTableGLES& gl,
101 const std::vector<TextureAndSampler>& bound_textures,
102 Range texture_range,
103 ShaderStage stage,
104 size_t unit_start_index = 0);
105
106 BufferBindingsGLES(const BufferBindingsGLES&) = delete;
107
108 BufferBindingsGLES& operator=(const BufferBindingsGLES&) = delete;
109
110 // For testing.
111 void SetUniformBindings(
112 absl::flat_hash_map<std::string, GLint> uniform_locations) {
113 uniform_locations_ = std::move(uniform_locations);
114 }
115 };
116
117 } // namespace impeller
118
119 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::BufferBindingsGLES
Sets up stage bindings for single draw call in the OpenGLES backend.
Definition: buffer_bindings_gles.h:28
impeller::BufferBindingsGLES::BindVertexAttributes
bool BindVertexAttributes(const ProcTableGLES &gl, size_t binding, size_t vertex_offset)
Definition: buffer_bindings_gles.cc:194
impeller::BufferBindingsGLES::ReadUniformsBindings
bool ReadUniformsBindings(const ProcTableGLES &gl, GLuint program)
Definition: buffer_bindings_gles.cc:101
impeller::BufferBindingsGLES::BufferBindingsGLES
BufferBindingsGLES()
impeller::BufferBindingsGLES::UnbindVertexAttributes
bool UnbindVertexAttributes(const ProcTableGLES &gl)
Definition: buffer_bindings_gles.cc:247
impeller::BufferBindingsGLES::RegisterVertexStageInput
bool RegisterVertexStageInput(const ProcTableGLES &gl, const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
Definition: buffer_bindings_gles.cc:31
impeller::BufferBindingsGLES::BindUniformData
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
Definition: buffer_bindings_gles.cc:222
impeller::BufferBindingsGLES::~BufferBindingsGLES
~BufferBindingsGLES()
impeller::ProcTableGLES
Definition: proc_table_gles.h:282
command.h
device_buffer_gles.h
impeller::testing::FML_TEST_CLASS
FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData)
impeller
Definition: allocation.cc:12
impeller::BufferResource
Resource< BufferView > BufferResource
Definition: command.h:54
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
proc_table_gles.h
gles.h
shader_types.h
impeller::Range
Definition: range.h:13