5 #include "flutter/testing/testing.h"
6 #include "gtest/gtest.h"
11 #include "impeller/renderer/backend/gles/test/mock_gles.h"
19 TEST(BufferBindingsGLESTest, ToVertexAttribTypeSupportedFormats) {
21 std::optional<GLenum>(GL_FLOAT));
23 std::optional<GLenum>(GL_BYTE));
25 std::optional<GLenum>(GL_UNSIGNED_BYTE));
27 std::optional<GLenum>(GL_SHORT));
29 std::optional<GLenum>(GL_UNSIGNED_SHORT));
32 TEST(BufferBindingsGLESTest, ToVertexAttribTypeRejectsUnsupportedFormats) {
42 TEST(BufferBindingsGLESTest, BindUniformData) {
44 absl::flat_hash_map<std::string, GLint> uniform_bindings;
45 uniform_bindings[
"SHADERMETADATA.FOOBAR"] = 1;
46 bindings.SetUniformBindings(std::move(uniform_bindings));
47 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
49 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
51 std::shared_ptr<MockGLES>
mock_gl = MockGLES::Init(std::move(mock_gles_impl));
52 std::vector<BufferResource> bound_buffers;
53 std::vector<TextureAndSampler> bound_textures;
56 .
name =
"shader_metadata",
61 .size =
sizeof(float),
62 .byte_length =
sizeof(
float),
63 .array_elements = std::nullopt,
65 std::shared_ptr<ReactorGLES>
reactor;
66 auto backing_store = std::make_unique<Allocation>();
67 ASSERT_TRUE(backing_store->Truncate(
Bytes{sizeof(float)}));
69 reactor, std::move(backing_store));
71 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
74 bound_buffers,
Range{0, 0},
78 TEST(BufferBindingsGLESTest, BindArrayData) {
80 absl::flat_hash_map<std::string, GLint> uniform_bindings;
81 uniform_bindings[
"SHADERMETADATA.FOOBAR[0]"] = 1;
82 bindings.SetUniformBindings(std::move(uniform_bindings));
83 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
85 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
87 std::shared_ptr<MockGLES>
mock_gl = MockGLES::Init(std::move(mock_gles_impl));
88 std::vector<BufferResource> bound_buffers;
89 std::vector<TextureAndSampler> bound_textures;
92 .
name =
"shader_metadata",
97 .size =
sizeof(float),
98 .byte_length =
sizeof(
float) * 4,
101 std::shared_ptr<ReactorGLES>
reactor;
102 auto backing_store = std::make_unique<Allocation>();
103 ASSERT_TRUE(backing_store->Truncate(
Bytes{sizeof(float) * 4}));
106 std::move(backing_store));
108 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
111 bound_buffers,
Range{0, 0},
115 TEST(BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices) {
117 absl::flat_hash_map<std::string, GLint> uniform_bindings;
118 uniform_bindings[
"SHADERMETADATA.VEC2"] = 1;
119 uniform_bindings[
"SHADERMETADATA.VEC3"] = 2;
120 uniform_bindings[
"SHADERMETADATA.VEC4"] = 3;
121 uniform_bindings[
"SHADERMETADATA.MAT2"] = 4;
122 uniform_bindings[
"SHADERMETADATA.MAT3"] = 5;
123 uniform_bindings[
"SHADERMETADATA.MAT4"] = 6;
124 bindings.SetUniformBindings(std::move(uniform_bindings));
125 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
127 EXPECT_CALL(*mock_gles_impl, Uniform2fv(1, 1, _)).Times(1);
128 EXPECT_CALL(*mock_gles_impl, Uniform3fv(2, 1, _)).Times(1);
129 EXPECT_CALL(*mock_gles_impl, Uniform4fv(3, 1, _)).Times(1);
130 EXPECT_CALL(*mock_gles_impl, UniformMatrix2fv(4, 1, GL_FALSE, _)).Times(1);
131 EXPECT_CALL(*mock_gles_impl, UniformMatrix3fv(5, 1, GL_FALSE, _)).Times(1);
132 EXPECT_CALL(*mock_gles_impl, UniformMatrix4fv(6, 1, GL_FALSE, _)).Times(1);
134 std::shared_ptr<MockGLES>
mock_gl = MockGLES::Init(std::move(mock_gles_impl));
135 std::vector<BufferResource> bound_buffers;
136 std::vector<TextureAndSampler> bound_textures;
145 .array_elements = std::nullopt,
146 .float_type = float_type};
150 .
name =
"shader_metadata",
160 std::shared_ptr<ReactorGLES>
reactor;
161 auto backing_store = std::make_unique<Allocation>();
162 ASSERT_TRUE(backing_store->Truncate(
Bytes{1024}));
164 std::move(backing_store));
166 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
169 bound_buffers,
Range{0, 0},
179 TEST(BufferBindingsGLESTest, BindUniformFailsWithoutFloatType) {
181 absl::flat_hash_map<std::string, GLint> uniform_bindings;
182 uniform_bindings[
"SHADERMETADATA.FOOBAR"] = 1;
183 bindings.SetUniformBindings(std::move(uniform_bindings));
184 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
185 std::shared_ptr<MockGLES>
mock_gl = MockGLES::Init(std::move(mock_gles_impl));
186 std::vector<BufferResource> bound_buffers;
187 std::vector<TextureAndSampler> bound_textures;
190 .
name =
"shader_metadata",
194 .size =
sizeof(float),
195 .byte_length =
sizeof(
float),
196 .array_elements = std::nullopt,
197 .float_type = std::nullopt}}};
198 std::shared_ptr<ReactorGLES>
reactor;
199 auto backing_store = std::make_unique<Allocation>();
200 ASSERT_TRUE(backing_store->Truncate(
Bytes{sizeof(float)}));
202 reactor, std::move(backing_store));
204 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
207 bound_buffers,
Range{0, 0},
215 TEST(BufferBindingsGLESTest, BindVertexAttributesSetsInstanceRateDivisor) {
216 auto mock_gles_impl = std::make_unique<::testing::NiceMock<MockGLESImpl>>();
217 EXPECT_CALL(*mock_gles_impl, VertexAttribDivisor(0, 0)).Times(1);
218 EXPECT_CALL(*mock_gles_impl, VertexAttribDivisor(1, 1)).Times(1);
219 std::shared_ptr<MockGLES>
mock_gl = MockGLES::Init(std::move(mock_gles_impl));
229 .bit_width =
sizeof(float) * 8,
235 .
name =
"instance_offset",
240 .bit_width =
sizeof(float) * 8,
245 std::vector<ShaderStageIOSlot> inputs = {per_vertex_input,
247 std::vector<ShaderStageBufferLayout> layouts = {
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 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)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
@ kInstance
The binding is read once per instance.
@ kVertex
The binding is read once per vertex. This is the default.
constexpr std::optional< GLenum > ToVertexAttribType(VertexAttributeFormat type)
Resource< BufferView > BufferResource
std::shared_ptr< ReactorGLES > reactor
std::shared_ptr< MockGLES > mock_gl
A 4x4 matrix using column-major storage.