|
6 | 6 | #include "flutter/testing/testing.h"
|
7 | 7 | #include "impeller/fixtures/box_fade.frag.h"
|
8 | 8 | #include "impeller/fixtures/box_fade.vert.h"
|
| 9 | +#include "impeller/fixtures/instanced_draw.frag.h" |
| 10 | +#include "impeller/fixtures/instanced_draw.vert.h" |
9 | 11 | #include "impeller/fixtures/test_texture.frag.h"
|
10 | 12 | #include "impeller/fixtures/test_texture.vert.h"
|
11 | 13 | #include "impeller/geometry/path_builder.h"
|
@@ -270,5 +272,60 @@ TEST_F(RendererTest, CanRenderToTexture) {
|
270 | 272 | ASSERT_TRUE(r2t_pass->EncodeCommands(*context->GetTransientsAllocator()));
|
271 | 273 | }
|
272 | 274 |
|
| 275 | +TEST_F(RendererTest, CanRenderInstanced) { |
| 276 | + using VS = InstancedDrawVertexShader; |
| 277 | + using FS = InstancedDrawFragmentShader; |
| 278 | + |
| 279 | + VertexBufferBuilder<VS::PerVertexData> builder; |
| 280 | + |
| 281 | + ASSERT_TRUE( |
| 282 | + Tessellator{}.Tessellate(FillType::kPositive, |
| 283 | + PathBuilder{} |
| 284 | + .AddRect(Rect::MakeXYWH(10, 10, 100, 100)) |
| 285 | + .TakePath() |
| 286 | + .CreatePolyline(), |
| 287 | + [&builder](Point vtx) { |
| 288 | + VS::PerVertexData data; |
| 289 | + data.vtx = vtx; |
| 290 | + builder.AppendVertex(data); |
| 291 | + })); |
| 292 | + |
| 293 | + auto pipeline = |
| 294 | + GetContext() |
| 295 | + ->GetPipelineLibrary() |
| 296 | + ->GetRenderPipeline( |
| 297 | + PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor( |
| 298 | + *GetContext()) |
| 299 | + ->SetSampleCount(SampleCount::kCount4)) |
| 300 | + .get(); |
| 301 | + ASSERT_TRUE(pipeline && pipeline->IsValid()); |
| 302 | + |
| 303 | + Command cmd; |
| 304 | + cmd.pipeline = pipeline; |
| 305 | + cmd.label = "InstancedDraw"; |
| 306 | + |
| 307 | + static constexpr size_t kInstancesCount = 5u; |
| 308 | + std::vector<VS::InstanceInfo> instances; |
| 309 | + for (size_t i = 0; i < kInstancesCount; i++) { |
| 310 | + VS::InstanceInfo info; |
| 311 | + info.colors = Color::Random(); |
| 312 | + instances.emplace_back(info); |
| 313 | + } |
| 314 | + |
| 315 | + ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool { |
| 316 | + VS::FrameInfo frame_info; |
| 317 | + frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()); |
| 318 | + VS::BindFrameInfo(cmd, |
| 319 | + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); |
| 320 | + VS::BindInstanceInfo( |
| 321 | + cmd, pass.GetTransientsBuffer().EmplaceStorageBuffer(instances)); |
| 322 | + cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer())); |
| 323 | + |
| 324 | + cmd.instance_count = kInstancesCount; |
| 325 | + pass.AddCommand(cmd); |
| 326 | + return true; |
| 327 | + })); |
| 328 | +} |
| 329 | + |
273 | 330 | } // namespace testing
|
274 | 331 | } // namespace impeller
|
0 commit comments