| Flutter Impeller |

buffer_bindings_gles_unittests.cc
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 #include "flutter/testing/testing.h" // IWYU pragma: keep
6 #include "gtest/gtest.h"
7 #include "impeller/renderer/backend/gles/buffer_bindings_gles.h"
8 #include "impeller/renderer/backend/gles/device_buffer_gles.h"
9 #include "impeller/renderer/backend/gles/test/mock_gles.h"
10 #include "impeller/renderer/command.h"
11
12 namespace impeller {
13 namespace testing {
14
15 using ::testing::_;
16
17 TEST(BufferBindingsGLESTest, BindUniformData) {
18 BufferBindingsGLES bindings;
19 absl::flat_hash_map<std::string, GLint> uniform_bindings;
20 uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
21 bindings.SetUniformBindings(std::move(uniform_bindings));
22 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
23
24 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
25
26 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
27 std::vector<BufferResource> bound_buffers;
28 std::vector<TextureAndSampler> bound_textures;
29
30 ShaderMetadata shader_metadata = {
31 .name = "shader_metadata",
32 .members = {ShaderStructMemberMetadata{.type = ShaderType::kFloat,
33 .name = "foobar",
34 .offset = 0,
35 .size = sizeof(float),
36 .byte_length = sizeof(float),
37 .array_elements = 0}}};
38 std::shared_ptr<ReactorGLES> reactor;
39 std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
40 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
41 DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
42 reactor, backing_store);
43 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
44 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
45
46 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
47 bound_buffers, Range{0, 0},
48 Range{0, 1}));
49 }
50
51 TEST(BufferBindingsGLESTest, BindArrayData) {
52 BufferBindingsGLES bindings;
53 absl::flat_hash_map<std::string, GLint> uniform_bindings;
54 uniform_bindings["SHADERMETADATA.FOOBAR[0]"] = 1;
55 bindings.SetUniformBindings(std::move(uniform_bindings));
56 auto mock_gles_impl = std::make_unique<MockGLESImpl>();
57
58 EXPECT_CALL(*mock_gles_impl, Uniform1fv(_, _, _)).Times(1);
59
60 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl));
61 std::vector<BufferResource> bound_buffers;
62 std::vector<TextureAndSampler> bound_textures;
63
64 ShaderMetadata shader_metadata = {
65 .name = "shader_metadata",
66 .members = {ShaderStructMemberMetadata{.type = ShaderType::kFloat,
67 .name = "foobar",
68 .offset = 0,
69 .size = sizeof(float),
70 .byte_length = sizeof(float) * 4,
71 .array_elements = 4}}};
72 std::shared_ptr<ReactorGLES> reactor;
73 std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
74 ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float) * 4}));
75 DeviceBufferGLES device_buffer(
76 DeviceBufferDescriptor{.size = sizeof(float) * 4}, reactor,
77 backing_store);
78 BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
79 bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view));
80
81 EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures,
82 bound_buffers, Range{0, 0},
83 Range{0, 1}));
84 }
85
86 } // namespace testing
87 } // namespace impeller
buffer_view
BufferView buffer_view
Definition: blit_command_gles.cc:154
buffer_bindings_gles.h
impeller::AllocationSize< 1u >
impeller::BufferBindingsGLES
Sets up stage bindings for single draw call in the OpenGLES backend.
Definition: buffer_bindings_gles.h:28
impeller::BufferBindingsGLES::BindUniformData
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
Definition: buffer_bindings_gles.cc:222
impeller::DeviceBufferGLES
Definition: device_buffer_gles.h:20
command.h
device_buffer_gles.h
impeller::testing::TEST
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: allocation_size_unittests.cc:10
impeller
Definition: allocation.cc:12
impeller::BufferResource
Resource< BufferView > BufferResource
Definition: command.h:54
impeller::ShaderType::kFloat
@ kFloat
impeller::BufferView
Definition: buffer_view.h:19
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::Range
Definition: range.h:13
impeller::ShaderMetadata
Definition: shader_types.h:72
impeller::ShaderMetadata::name
std::string name
Definition: shader_types.h:74
impeller::ShaderStructMemberMetadata
Definition: shader_types.h:63
impeller::ShaderStructMemberMetadata::type
ShaderType type
Definition: shader_types.h:64