| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::TextureGLES Class Referencefinal

`#include <texture_gles.h>`

Inheritance diagram for impeller::TextureGLES:

## Public Types
enum class | Type { kTexture , kTextureMultisampled , kRenderBuffer , kRenderBufferMultisampled }
enum class | AttachmentType { kColor0 , kDepth , kStencil }

## Public Member Functions
| TextureGLES (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
| ~TextureGLES () override
bool | IsValid () const override
std::optional< GLuint > | GetGLHandle () const
bool | Bind () const
bool | GenerateMipmap ()
bool | SetAsFramebufferAttachment (GLenum target, AttachmentType attachment_type) const
Type | GetType () const
bool | IsWrapped () const
std::optional< GLuint > | GetFBO () const
void | MarkContentsInitialized ()
| Indicates that all texture storage has already been allocated and contents initialized. More...
void | MarkSliceInitialized (size_t slice) const
| Indicates that a specific texture slice has been initialized. More...
bool | IsSliceInitialized (size_t slice) const
void | SetFence (HandleGLES fence)
| Attach a sync fence to this texture that will be waited on before encoding a rendering operation that references it. More...
void | SetCachedFBO (HandleGLES fbo)
const HandleGLES & | GetCachedFBO () const
| Retrieve the cached FBO object, or a dead handle if there is no object. More...
std::optional< HandleGLES > | GetSyncFence () const
Type | ComputeTypeForBinding (GLenum target) const
Public Member Functions inherited from impeller::Texture
virtual | ~Texture ()
bool | SetContents (const uint8_t *contents, size_t length, size_t slice=0, bool is_opaque=false)
bool | SetContents (std::shared_ptr< const fml::Mapping > mapping, size_t slice=0, bool is_opaque=false)
bool | IsOpaque () const
size_t | GetMipCount () const
const TextureDescriptor & | GetTextureDescriptor () const
void | SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
TextureCoordinateSystem | GetCoordinateSystem () const
bool | NeedsMipmapGeneration () const

## Static Public Member Functions
static std::shared_ptr< TextureGLES > | WrapFBO (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
| Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller. More...
static std::shared_ptr< TextureGLES > | WrapTexture (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
| Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is assumed by the reactor. More...
static std::shared_ptr< TextureGLES > | CreatePlaceholder (std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
| Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way. It only exists to setup a render pass description. More...
Static Public Member Functions inherited from impeller::BackendCast< TextureGLES, Texture >
static TextureGLES & | Cast (Texture &base)
static const TextureGLES & | Cast (const Texture &base)
static TextureGLES * | Cast (Texture *base)
static const TextureGLES * | Cast (const Texture *base)

## Additional Inherited Members
Protected Member Functions inherited from impeller::Texture
| Texture (TextureDescriptor desc)
Protected Attributes inherited from impeller::Texture
bool | mipmap_generated_ = false

## Detailed Description

Definition at line 18 of file texture_gles.h.

## Member Enumeration Documentation

## ◆ AttachmentType

enum impeller::TextureGLES::AttachmentType
| strong

Enumerator
kColor0 |
kDepth |
kStencil |

Definition at line 92 of file texture_gles.h.

92 {
93 kColor0,
94 kDepth,
95 kStencil,
96 };

## ◆ Type

enum impeller::TextureGLES::Type
| strong

Enumerator
kTexture |
kTextureMultisampled |
kRenderBuffer |
kRenderBufferMultisampled |

Definition at line 21 of file texture_gles.h.

21 {
22 kTexture,
23 kTextureMultisampled,
24 kRenderBuffer,
25 kRenderBufferMultisampled,
26 };
impeller::HandleType::kTexture
@ kTexture
impeller::HandleType::kRenderBuffer
@ kRenderBuffer

## Constructor & Destructor Documentation

## ◆ TextureGLES()

impeller::TextureGLES::TextureGLES | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc
| ) |  |

Definition at line 184 of file texture_gles.cc.

186 : TextureGLES(std::move(reactor), //
187 desc, //
188 std::nullopt, //
189 std::nullopt //
190 ) {}
impeller::TextureGLES::TextureGLES
TextureGLES(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
Definition: texture_gles.cc:184

Referenced by WrapFBO(), and WrapTexture().

## ◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES | ( |  | ) |
| override

Definition at line 225 of file texture_gles.cc.

225 {
226 reactor_->CollectHandle(handle_);
227 if (!cached_fbo_.IsDead()) {
228 reactor_->CollectHandle(cached_fbo_);
229 }
230 }
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Determines if the handle is dead.
Definition: handle_gles.h:53

References impeller::HandleGLES::IsDead().

## Member Function Documentation

## ◆ Bind()

bool impeller::TextureGLES::Bind | ( |  | ) | const

Definition at line 506 of file texture_gles.cc.

506 {
507 auto handle = GetGLHandle();
508 if (!handle.has_value()) {
509 return false;
510 }
511 const auto& gl = reactor_->GetProcTable();
512
513 if (fence_.has_value()) {
514 std::optional<GLsync> fence = reactor_->GetGLFence(fence_.value());
515 if (fence.has_value()) {
516 gl.WaitSync(fence.value(), 0, GL_TIMEOUT_IGNORED);
517 }
518 reactor_->CollectHandle(fence_.value());
519 fence_ = std::nullopt;
520 }
521
522 switch (type_) {
523 case Type::kTexture:
524 case Type::kTextureMultisampled: {
525 const auto target = ToTextureTarget(GetTextureDescriptor().type);
526 if (!target.has_value()) {
527 VALIDATION_LOG << "Could not bind texture of this type.";
528 return false;
529 }
530 gl.BindTexture(target.value(), handle.value());
531 } break;
532 case Type::kRenderBuffer:
533 case Type::kRenderBufferMultisampled:
534 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
535 break;
536 }
537 InitializeContentsIfNecessary();
538 return true;
539 }
impeller::TextureGLES::Type::kTexture
@ kTexture
impeller::TextureGLES::Type::kRenderBuffer
@ kRenderBuffer
impeller::TextureGLES::Type::kTextureMultisampled
@ kTextureMultisampled
impeller::TextureGLES::Type::kRenderBufferMultisampled
@ kRenderBufferMultisampled
impeller::TextureGLES::GetGLHandle
std::optional< GLuint > GetGLHandle() const
Definition: texture_gles.cc:499
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:185
type
GLenum type
Definition: texture_gles.cc:66
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References GetGLHandle(), impeller::Texture::GetTextureDescriptor(), kRenderBuffer, kRenderBufferMultisampled, kTexture, kTextureMultisampled, impeller::ToTextureTarget(), type, and VALIDATION_LOG.

Referenced by GenerateMipmap().

## ◆ ComputeTypeForBinding()

TextureGLES::Type impeller::TextureGLES::ComputeTypeForBinding | ( | GLenum | target | ) | const

Definition at line 400 of file texture_gles.cc.

400 {
401 // When binding to a GL_READ_FRAMEBUFFER, any multisampled
402 // textures must be bound as single sampled.
403 if (target == GL_READ_FRAMEBUFFER && type_ == Type::kTextureMultisampled) {
404 return Type::kTexture;
405 }
406 return type_;
407 }

References kTexture, and kTextureMultisampled.

Referenced by SetAsFramebufferAttachment().

## ◆ CreatePlaceholder()

std::shared_ptr< TextureGLES > impeller::TextureGLES::CreatePlaceholder | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc
| ) |  |
| static

Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way. It only exists to setup a render pass description.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description

Returns
  If a texture placeholder could be created.

Definition at line 178 of file texture_gles.cc.

180 {
181 return TextureGLES::WrapFBO(std::move(reactor), desc, 0u);
182 }
impeller::TextureGLES::WrapFBO
static std::shared_ptr< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
Definition: texture_gles.cc:146

References WrapFBO().

Referenced by impeller::SurfaceGLES::WrapFBO().

## ◆ GenerateMipmap()

bool impeller::TextureGLES::GenerateMipmap | ( |  | ) |

Definition at line 555 of file texture_gles.cc.

555 {
556 if (!IsValid()) {
557 return false;
558 }
559
560 auto type = GetTextureDescriptor().type;
561 switch (type) {
562 case TextureType::kTexture2D:
563 break;
564 case TextureType::kTexture2DMultisample:
565 VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
566 "supported in the GLES backend.";
567 return false;
568 case TextureType::kTextureCube:
569 break;
570 case TextureType::kTextureExternalOES:
571 break;
572 }
573
574 if (!Bind()) {
575 return false;
576 }
577
578 auto handle = GetGLHandle();
579 if (!handle.has_value()) {
580 return false;
581 }
582
583 const auto& gl = reactor_->GetProcTable();
584 gl.GenerateMipmap(ToTextureType(type));
585 mipmap_generated_ = true;
586 return true;
587 }
impeller::TextureGLES::Bind
bool Bind() const
Definition: texture_gles.cc:506
impeller::TextureGLES::IsValid
bool IsValid() const override
Definition: texture_gles.cc:233
impeller::Texture::mipmap_generated_
bool mipmap_generated_
Definition: texture.h:79
impeller::ToTextureType
constexpr GLenum ToTextureType(TextureType type)
Definition: formats_gles.h:171
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:40

References Bind(), GetGLHandle(), impeller::Texture::GetTextureDescriptor(), IsValid(), impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::Texture::mipmap_generated_, impeller::ToTextureType(), impeller::TextureDescriptor::type, type, and VALIDATION_LOG.

## ◆ GetCachedFBO()

const HandleGLES & impeller::TextureGLES::GetCachedFBO | ( |  | ) | const

Retrieve the cached FBO object, or a dead handle if there is no object.

Definition at line 683 of file texture_gles.cc.

683 {
684 return cached_fbo_;
685 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ GetFBO()

std::optional< GLuint > impeller::TextureGLES::GetFBO | ( |  | ) | const

Definition at line 665 of file texture_gles.cc.

665 {
666 return wrapped_fbo_;
667 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ GetGLHandle()

std::optional< GLuint > impeller::TextureGLES::GetGLHandle | ( |  | ) | const

Definition at line 499 of file texture_gles.cc.

499 {
500 if (!IsValid()) {
501 return std::nullopt;
502 }
503 return reactor_->GetGLHandle(handle_);
504 }

References IsValid().

Referenced by Bind(), impeller::ConfigureFBO(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), GenerateMipmap(), impeller::interop::ImpellerTextureGetOpenGLHandle(), and SetAsFramebufferAttachment().

## ◆ GetSyncFence()

std::optional< HandleGLES > impeller::TextureGLES::GetSyncFence | ( |  | ) | const

Definition at line 675 of file texture_gles.cc.

675 {
676 return fence_;
677 }

## ◆ GetType()

TextureGLES::Type impeller::TextureGLES::GetType | ( |  | ) | const

Definition at line 589 of file texture_gles.cc.

589 {
590 return type_;
591 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ IsSliceInitialized()

bool impeller::TextureGLES::IsSliceInitialized | ( | size_t | slice | ) | const

Definition at line 551 of file texture_gles.cc.

551 {
552 return slices_initialized_[slice];
553 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ IsValid()

bool impeller::TextureGLES::IsValid | ( |  | ) | const
| override virtual

Implements impeller::Texture.

Definition at line 233 of file texture_gles.cc.

233 {
234 return is_valid_;
235 }

Referenced by GenerateMipmap(), GetGLHandle(), and SetAsFramebufferAttachment().

## ◆ IsWrapped()

bool impeller::TextureGLES::IsWrapped | ( |  | ) | const

Definition at line 661 of file texture_gles.cc.

661 {
662 return is_wrapped_;
663 }

Referenced by impeller::ConfigureFBO(), impeller::BlitCopyBufferToTextureCommandGLES::Encode(), and impeller::EncodeCommandsInReactor().

## ◆ MarkContentsInitialized()

void impeller::TextureGLES::MarkContentsInitialized | ( |  | ) |

Indicates that all texture storage has already been allocated and contents initialized.

This is similar to calling `MarkSliceInitialized` with all slices.

See also
  MarkSliceInitialized.

Definition at line 541 of file texture_gles.cc.

541 {
542 for (size_t i = 0; i < slices_initialized_.size(); i++) {
543 slices_initialized_[i] = true;
544 }
545 }

## ◆ MarkSliceInitialized()

void impeller::TextureGLES::MarkSliceInitialized | ( | size_t | slice | ) | const

Indicates that a specific texture slice has been initialized.

Parameters

  [in] | slice | The slice to mark as being initialized.

Definition at line 547 of file texture_gles.cc.

547 {
548 slices_initialized_[slice] = true;
549 }

Referenced by impeller::BlitCopyBufferToTextureCommandGLES::Encode().

## ◆ SetAsFramebufferAttachment()

bool impeller::TextureGLES::SetAsFramebufferAttachment | ( | GLenum | target,
|  | AttachmentType | attachment_type
| ) |  | const

Definition at line 604 of file texture_gles.cc.

606 {
607 if (!IsValid()) {
608 return false;
609 }
610 InitializeContentsIfNecessary();
611 auto handle = GetGLHandle();
612 if (!handle.has_value()) {
613 return false;
614 }
615 const auto& gl = reactor_->GetProcTable();
616
617 switch (ComputeTypeForBinding(target)) {
618 case Type::kTexture:
619 gl.FramebufferTexture2D(target, // target
620 ToAttachmentType(attachment_type), // attachment
621 GL_TEXTURE_2D, // textarget
622 handle.value(), // texture
623 0 // level
624 );
625 break;
626 case Type::kTextureMultisampled:
627 gl.FramebufferTexture2DMultisampleEXT(
628 target, // target
629 ToAttachmentType(attachment_type), // attachment
630 GL_TEXTURE_2D, // textarget
631 handle.value(), // texture
632 0, // level
633 4 // samples
634 );
635 break;
636 case Type::kRenderBuffer:
637 case Type::kRenderBufferMultisampled:
638 gl.FramebufferRenderbuffer(
639 target, // target
640 ToAttachmentType(attachment_type), // attachment
641 GL_RENDERBUFFER, // render-buffer target
642 handle.value() // render-buffer
643 );
644 break;
645 }
646
647 return true;
648 }
impeller::TextureGLES::ComputeTypeForBinding
Type ComputeTypeForBinding(GLenum target) const
Definition: texture_gles.cc:400
impeller::ToAttachmentType
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)
Definition: texture_gles.cc:593

References ComputeTypeForBinding(), GetGLHandle(), IsValid(), kRenderBuffer, kRenderBufferMultisampled, kTexture, kTextureMultisampled, and impeller::ToAttachmentType().

Referenced by impeller::ConfigureFBO(), and impeller::EncodeCommandsInReactor().

## ◆ SetCachedFBO()

void impeller::TextureGLES::SetCachedFBO | ( | HandleGLES | fbo | ) |

Store the FBO object for recycling in the 2D renderer.

The color0 texture used by the 2D renderer will use this texture object to store the associated FBO the first time it is used.

Definition at line 679 of file texture_gles.cc.

679 {
680 cached_fbo_ = fbo;
681 }

Referenced by impeller::EncodeCommandsInReactor().

## ◆ SetFence()

void impeller::TextureGLES::SetFence | ( | HandleGLES | fence | ) |

Attach a sync fence to this texture that will be waited on before encoding a rendering operation that references it.

Parameters

  [in] | fence | A handle to a sync fence.

Definition at line 669 of file texture_gles.cc.

669 {
670 FML_DCHECK(!fence_.has_value());
671 fence_ = fence;
672 }

## ◆ WrapFBO()

std::shared_ptr< TextureGLES > impeller::TextureGLES::WrapFBO | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc,
|  | GLuint | fbo
| ) |  |
| static

Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.

This is useful for creating a render target for the default window managed framebuffer.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description
  [in] | fbo | The fbo

Returns
  If a texture representation of the framebuffer could be created.

Definition at line 146 of file texture_gles.cc.

149 {
150 auto texture = std::shared_ptr<TextureGLES>(
151 new TextureGLES(std::move(reactor), desc, fbo, std::nullopt));
152 if (!texture->IsValid()) {
153 return nullptr;
154 }
155 return texture;
156 }

References TextureGLES().

Referenced by CreatePlaceholder(), and impeller::SurfaceGLES::WrapFBO().

## ◆ WrapTexture()

std::shared_ptr< TextureGLES > impeller::TextureGLES::WrapTexture | ( | std::shared_ptr< ReactorGLES > | reactor,
|  | TextureDescriptor | desc,
|  | HandleGLES | external_handle
| ) |  |
| static

Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is assumed by the reactor.

Parameters

  [in] | reactor | The reactor
  [in] | desc | The description
  [in] | external_handle | The external handle

Returns
  If a texture representation of the framebuffer could be created.

Definition at line 158 of file texture_gles.cc.

161 {
162 if (external_handle.IsDead()) {
163 VALIDATION_LOG << "Cannot wrap a dead handle.";
164 return nullptr;
165 }
166 if (external_handle.GetType() != HandleType::kTexture) {
167 VALIDATION_LOG << "Cannot wrap a non-texture handle.";
168 return nullptr;
169 }
170 auto texture = std::shared_ptr<TextureGLES>(
171 new TextureGLES(std::move(reactor), desc, std::nullopt, external_handle));
172 if (!texture->IsValid()) {
173 return nullptr;
174 }
175 return texture;
176 }

References impeller::HandleGLES::GetType(), impeller::HandleGLES::IsDead(), impeller::kTexture, TextureGLES(), and VALIDATION_LOG.

Referenced by impeller::interop::ImpellerTextureCreateWithOpenGLTextureHandleNew().

The documentation for this class was generated from the following files:

- impeller/renderer/backend/gles/texture_gles.h
- impeller/renderer/backend/gles/texture_gles.cc