Flutter Engine
 
Loading...
Searching...
No Matches
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"
11
12namespace impeller {
13namespace testing {
14
15using ::testing::_;
16
17TEST(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",
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
51TEST(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",
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
BufferView buffer_view
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)
static std::shared_ptr< MockGLES > Init(std::unique_ptr< MockGLESImpl > impl, const std::optional< std::vector< const char * > > &extensions=std::nullopt)
Definition mock_gles.cc:260
TEST(FrameTimingsRecorderTest, RecordVsync)
Resource< BufferView > BufferResource
Definition command.h:55