Flutter Impeller
pipeline_gles.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 
6 
7 namespace impeller {
8 
9 PipelineGLES::PipelineGLES(ReactorGLES::Ref reactor,
10  std::weak_ptr<PipelineLibrary> library,
11  const PipelineDescriptor& desc)
12  : Pipeline(std::move(library), desc),
13  reactor_(std::move(reactor)),
14  handle_(reactor_ ? reactor_->CreateHandle(HandleType::kProgram)
15  : HandleGLES::DeadHandle()),
16  is_valid_(!handle_.IsDead()) {
17  if (is_valid_) {
18  reactor_->SetDebugLabel(handle_, GetDescriptor().GetLabel());
19  }
20 }
21 
22 // |Pipeline|
23 PipelineGLES::~PipelineGLES() {
24  if (!handle_.IsDead()) {
25  reactor_->CollectHandle(handle_);
26  }
27 }
28 
29 // |Pipeline|
30 bool PipelineGLES::IsValid() const {
31  return is_valid_;
32 }
33 
34 const HandleGLES& PipelineGLES::GetProgramHandle() const {
35  return handle_;
36 }
37 
38 BufferBindingsGLES* PipelineGLES::GetBufferBindings() const {
39  return buffer_bindings_.get();
40 }
41 
42 bool PipelineGLES::BuildVertexDescriptor(const ProcTableGLES& gl,
43  GLuint program) {
44  if (buffer_bindings_) {
45  return false;
46  }
47  auto vtx_desc = std::make_unique<BufferBindingsGLES>();
48  if (!vtx_desc->RegisterVertexStageInput(
49  gl, GetDescriptor().GetVertexDescriptor()->GetStageInputs(),
50  GetDescriptor().GetVertexDescriptor()->GetStageLayouts())) {
51  return false;
52  }
53  if (!vtx_desc->ReadUniformsBindings(gl, program)) {
54  return false;
55  }
56  buffer_bindings_ = std::move(vtx_desc);
57  return true;
58 }
59 
60 [[nodiscard]] bool PipelineGLES::BindProgram() const {
61  if (handle_.IsDead()) {
62  return false;
63  }
64  auto handle = reactor_->GetGLHandle(handle_);
65  if (!handle.has_value()) {
66  return false;
67  }
68  reactor_->GetProcTable().UseProgram(handle.value());
69  return true;
70 }
71 
72 [[nodiscard]] bool PipelineGLES::UnbindProgram() const {
73  if (reactor_) {
74  reactor_->GetProcTable().UseProgram(0u);
75  }
76  return true;
77 }
78 
79 } // namespace impeller
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:87
impeller::HandleType
HandleType
Definition: handle_gles.h:22
impeller::BufferBindingsGLES
Sets up stage bindings for single draw call in the OpenGLES backend.
Definition: buffer_bindings_gles.h:22
impeller::HandleGLES
Definition: handle_gles.h:35
impeller::ProcTableGLES
Definition: proc_table_gles.h:229
impeller::HandleType::kProgram
@ kProgram
pipeline_gles.h
std
Definition: comparable.h:95
impeller
Definition: aiks_blur_unittests.cc:20