Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
17namespace impeller {
18
19namespace testing {
20FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData);
21FML_TEST_CLASS(BufferBindingsGLESTest, BindArrayData);
22FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices);
23FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformFailsWithoutFloatType);
24} // namespace testing
25
26//------------------------------------------------------------------------------
27/// @brief Sets up stage bindings for single draw call in the OpenGLES
28/// backend.
29///
31 public:
33
35
37 const ProcTableGLES& gl,
38 const std::vector<ShaderStageIOSlot>& inputs,
39 const std::vector<ShaderStageBufferLayout>& layouts);
40
41 bool ReadUniformsBindings(const ProcTableGLES& gl, GLuint program);
42
43 /// Bind the vertex attributes for buffer slot [binding].
44 ///
45 /// [instance] re-points instance-rate attributes at the given instance,
46 /// used to emulate an instanced draw on drivers without hardware
47 /// instancing support. It is 0 for a non-instanced or hardware-instanced
48 /// draw.
50 size_t binding,
51 size_t vertex_offset,
52 size_t instance = 0);
53
54 bool BindUniformData(const ProcTableGLES& gl,
55 const std::vector<TextureAndSampler>& bound_textures,
56 const std::vector<BufferResource>& bound_buffers,
57 Range texture_range,
58 Range buffer_range);
59
61
62 private:
63 FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindUniformData);
64 FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindArrayData);
65 FML_FRIEND_TEST(testing::BufferBindingsGLESTest,
66 BindUniformDataVerticesAndMatrices);
67 FML_FRIEND_TEST(testing::BufferBindingsGLESTest,
68 BindUniformFailsWithoutFloatType);
69 //----------------------------------------------------------------------------
70 /// @brief The arguments to glVertexAttribPointer.
71 ///
72 struct VertexAttribPointer {
73 GLuint index = 0u;
74 GLint size = 4;
75 GLenum type = GL_FLOAT;
76 GLenum normalized = GL_FALSE;
77 GLsizei stride = 0u;
78 GLsizei offset = 0u;
79 // glVertexAttribDivisor value: 0 advances per vertex, 1 per instance.
80 GLuint vertex_attrib_divisor = 0u;
81 };
82 std::vector<std::vector<VertexAttribPointer>> vertex_attrib_arrays_;
83
84 absl::flat_hash_map<std::string, GLint> uniform_locations_;
85 absl::flat_hash_map<std::string, std::pair<GLint, GLuint>> ubo_locations_;
86
87 using BindingMap = absl::flat_hash_map<std::string, std::vector<GLint>>;
88 BindingMap binding_map_ = {};
89 GLuint vertex_array_object_ = 0;
90 GLuint program_handle_ = GL_NONE;
91 bool use_ubo_ = false;
92
93 const std::vector<GLint>& ComputeUniformLocations(
94 const ShaderMetadata* metadata);
95
96 bool ReadUniformsBindingsV2(const ProcTableGLES& gl, GLuint program);
97
98 bool ReadUniformsBindingsV3(const ProcTableGLES& gl, GLuint program);
99
100 GLint ComputeTextureLocation(const ShaderMetadata* metadata);
101
102 bool BindUniformBuffer(const ProcTableGLES& gl, const BufferResource& buffer);
103
104 bool BindUniformBufferV2(const ProcTableGLES& gl,
105 const BufferView& buffer,
106 const ShaderMetadata* metadata,
107 const DeviceBufferGLES& device_buffer_gles);
108
109 bool BindUniformBufferV3(const ProcTableGLES& gl,
110 const BufferView& buffer,
111 const ShaderMetadata* metadata,
112 const DeviceBufferGLES& device_buffer_gles);
113
114 std::optional<size_t> BindTextures(
115 const ProcTableGLES& gl,
116 const std::vector<TextureAndSampler>& bound_textures,
117 Range texture_range,
118 ShaderStage stage,
119 size_t unit_start_index = 0);
120
121 BufferBindingsGLES(const BufferBindingsGLES&) = delete;
122
123 BufferBindingsGLES& operator=(const BufferBindingsGLES&) = delete;
124
125 // For testing.
126 void SetUniformBindings(
127 absl::flat_hash_map<std::string, GLint> uniform_locations) {
128 uniform_locations_ = std::move(uniform_locations);
129 }
130};
131
132} // namespace impeller
133
134#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, size_t instance=0)
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)
VkInstance instance
Definition main.cc:64
#define FML_FRIEND_TEST(test_case_name, test_name)
Definition macros.h:47
#define FML_TEST_CLASS(test_case_name, test_name)
Definition macros.h:44
Resource< BufferView > BufferResource
Definition command.h:55
impeller::ShaderType type