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