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 
15 #include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
16 
17 namespace impeller {
18 
19 namespace testing {
20 FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData);
21 FML_TEST_CLASS(BufferBindingsGLESTest, BindArrayData);
22 FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices);
23 } // namespace testing
24 
25 //------------------------------------------------------------------------------
26 /// @brief Sets up stage bindings for single draw call in the OpenGLES
27 /// backend.
28 ///
30  public:
32 
34 
36  const ProcTableGLES& gl,
37  const std::vector<ShaderStageIOSlot>& inputs,
38  const std::vector<ShaderStageBufferLayout>& layouts);
39 
40  bool ReadUniformsBindings(const ProcTableGLES& gl, GLuint program);
41 
42  bool BindVertexAttributes(const ProcTableGLES& gl,
43  size_t binding,
44  size_t vertex_offset);
45 
46  bool BindUniformData(const ProcTableGLES& gl,
47  const std::vector<TextureAndSampler>& bound_textures,
48  const std::vector<BufferResource>& bound_buffers,
49  Range texture_range,
50  Range buffer_range);
51 
52  bool UnbindVertexAttributes(const ProcTableGLES& gl);
53 
54  private:
55  FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindUniformData);
56  FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindArrayData);
57  FML_FRIEND_TEST(testing::BufferBindingsGLESTest,
58  BindUniformDataVerticesAndMatrices);
59  //----------------------------------------------------------------------------
60  /// @brief The arguments to glVertexAttribPointer.
61  ///
62  struct VertexAttribPointer {
63  GLuint index = 0u;
64  GLint size = 4;
65  GLenum type = GL_FLOAT;
66  GLenum normalized = GL_FALSE;
67  GLsizei stride = 0u;
68  GLsizei offset = 0u;
69  };
70  std::vector<std::vector<VertexAttribPointer>> vertex_attrib_arrays_;
71 
72  absl::flat_hash_map<std::string, GLint> uniform_locations_;
73  absl::flat_hash_map<std::string, std::pair<GLint, GLuint>> ubo_locations_;
74 
75  using BindingMap = absl::flat_hash_map<std::string, std::vector<GLint>>;
76  BindingMap binding_map_ = {};
77  GLuint vertex_array_object_ = 0;
78  GLuint program_handle_ = GL_NONE;
79  bool use_ubo_ = false;
80 
81  const std::vector<GLint>& ComputeUniformLocations(
82  const ShaderMetadata* metadata);
83 
84  bool ReadUniformsBindingsV2(const ProcTableGLES& gl, GLuint program);
85 
86  bool ReadUniformsBindingsV3(const ProcTableGLES& gl, GLuint program);
87 
88  GLint ComputeTextureLocation(const ShaderMetadata* metadata);
89 
90  bool BindUniformBuffer(const ProcTableGLES& gl, const BufferResource& buffer);
91 
92  bool BindUniformBufferV2(const ProcTableGLES& gl,
93  const BufferView& buffer,
94  const ShaderMetadata* metadata,
95  const DeviceBufferGLES& device_buffer_gles);
96 
97  bool BindUniformBufferV3(const ProcTableGLES& gl,
98  const BufferView& buffer,
99  const ShaderMetadata* metadata,
100  const DeviceBufferGLES& device_buffer_gles);
101 
102  std::optional<size_t> BindTextures(
103  const ProcTableGLES& gl,
104  const std::vector<TextureAndSampler>& bound_textures,
105  Range texture_range,
106  ShaderStage stage,
107  size_t unit_start_index = 0);
108 
109  BufferBindingsGLES(const BufferBindingsGLES&) = delete;
110 
111  BufferBindingsGLES& operator=(const BufferBindingsGLES&) = delete;
112 
113  // For testing.
114  void SetUniformBindings(
115  absl::flat_hash_map<std::string, GLint> uniform_locations) {
116  uniform_locations_ = std::move(uniform_locations);
117  }
118 };
119 
120 } // namespace impeller
121 
122 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_BUFFER_BINDINGS_GLES_H_
Sets up stage bindings for single draw call in the OpenGLES backend.
bool BindVertexAttributes(const ProcTableGLES &gl, size_t binding, size_t vertex_offset)
bool ReadUniformsBindings(const ProcTableGLES &gl, GLuint program)
bool UnbindVertexAttributes(const ProcTableGLES &gl)
bool RegisterVertexStageInput(const ProcTableGLES &gl, const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData)
Resource< BufferView > BufferResource
Definition: command.h:55