5 #include "flutter/testing/testing.h"
6 #include "gtest/gtest.h"
10 #include "impeller/renderer/backend/gles/test/mock_gles.h"
18 TEST(BufferBindingsGLESTest, BindUniformData) {
20 absl::flat_hash_map<std::string, GLint> uniform_bindings;
21 uniform_bindings[
"SHADERMETADATA.FOOBAR"] = 1;
22 bindings.SetUniformBindings(std::move(uniform_bindings));
23 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
25 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
27 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
28 std::vector<BufferResource> bound_buffers;
29 std::vector<TextureAndSampler> bound_textures;
32 .
name =
"shader_metadata",
37 .size =
sizeof(float),
38 .byte_length =
sizeof(
float),
39 .array_elements = std::nullopt,
41 std::shared_ptr<ReactorGLES> reactor;
42 std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
43 ASSERT_TRUE(backing_store->Truncate(
Bytes{sizeof(float)}));
45 reactor, backing_store);
47 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
49 EXPECT_TRUE(bindings.
BindUniformData(mock_gl->GetProcTable(), bound_textures,
50 bound_buffers,
Range{0, 0},
54 TEST(BufferBindingsGLESTest, BindArrayData) {
56 absl::flat_hash_map<std::string, GLint> uniform_bindings;
57 uniform_bindings[
"SHADERMETADATA.FOOBAR[0]"] = 1;
58 bindings.SetUniformBindings(std::move(uniform_bindings));
59 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
61 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
63 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
64 std::vector<BufferResource> bound_buffers;
65 std::vector<TextureAndSampler> bound_textures;
68 .
name =
"shader_metadata",
73 .size =
sizeof(float),
74 .byte_length =
sizeof(
float) * 4,
77 std::shared_ptr<ReactorGLES> reactor;
78 std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
79 ASSERT_TRUE(backing_store->Truncate(
Bytes{sizeof(float) * 4}));
84 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
86 EXPECT_TRUE(bindings.
BindUniformData(mock_gl->GetProcTable(), bound_textures,
87 bound_buffers,
Range{0, 0},
91 TEST(BufferBindingsGLESTest, BindUniformDataVerticesAndMatrices) {
93 absl::flat_hash_map<std::string, GLint> uniform_bindings;
94 uniform_bindings[
"SHADERMETADATA.VEC2"] = 1;
95 uniform_bindings[
"SHADERMETADATA.VEC3"] = 2;
96 uniform_bindings[
"SHADERMETADATA.VEC4"] = 3;
97 uniform_bindings[
"SHADERMETADATA.MAT2"] = 4;
98 uniform_bindings[
"SHADERMETADATA.MAT3"] = 5;
99 uniform_bindings[
"SHADERMETADATA.MAT4"] = 6;
100 bindings.SetUniformBindings(std::move(uniform_bindings));
101 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
103 EXPECT_CALL(*mock_gles_impl, Uniform2fv(1, 1, _)).Times(1);
104 EXPECT_CALL(*mock_gles_impl, Uniform3fv(2, 1, _)).Times(1);
105 EXPECT_CALL(*mock_gles_impl, Uniform4fv(3, 1, _)).Times(1);
106 EXPECT_CALL(*mock_gles_impl, UniformMatrix2fv(4, 1, GL_FALSE, _)).Times(1);
107 EXPECT_CALL(*mock_gles_impl, UniformMatrix3fv(5, 1, GL_FALSE, _)).Times(1);
108 EXPECT_CALL(*mock_gles_impl, UniformMatrix4fv(6, 1, GL_FALSE, _)).Times(1);
110 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
111 std::vector<BufferResource> bound_buffers;
112 std::vector<TextureAndSampler> bound_textures;
121 .array_elements = std::nullopt,
122 .float_type = float_type};
126 .
name =
"shader_metadata",
136 std::shared_ptr<ReactorGLES> reactor;
137 std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
138 ASSERT_TRUE(backing_store->Truncate(
Bytes{1024}));
142 bound_buffers.push_back(
BufferResource(&shader_metadata, buffer_view));
144 EXPECT_TRUE(bindings.
BindUniformData(mock_gl->GetProcTable(), bound_textures,
145 bound_buffers,
Range{0, 0},
Sets up stage bindings for single draw call in the OpenGLES backend.
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)
Resource< BufferView > BufferResource
A 4x4 matrix using column-major storage.