Flutter Impeller
impeller::TextureGLES Class Referencefinal

#include <texture_gles.h>

Inheritance diagram for impeller::TextureGLES:
impeller::Texture impeller::BackendCast< TextureGLES, Texture >

Public Types

enum  Type {
  Type::kTexture,
  Type::kRenderBuffer,
  Type::kRenderBufferMultisampled
}
 
enum  IsWrapped { IsWrapped::kWrapped }
 
enum  AttachmentPoint {
  AttachmentPoint::kColor0,
  AttachmentPoint::kDepth,
  AttachmentPoint::kStencil
}
 

Public Member Functions

 TextureGLES (ReactorGLES::Ref reactor, TextureDescriptor desc)
 
 TextureGLES (ReactorGLES::Ref reactor, TextureDescriptor desc, IsWrapped wrapped)
 
 ~TextureGLES () override
 
std::optional< GLuint > GetGLHandle () const
 
bool Bind () const
 
bool GenerateMipmap ()
 
bool SetAsFramebufferAttachment (GLenum target, GLuint fbo, AttachmentPoint point) const
 
Type GetType () const
 
bool IsWrapped () 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 TextureDescriptorGetTextureDescriptor () const
 
void SetCoordinateSystem (TextureCoordinateSystem coordinate_system)
 
TextureCoordinateSystem GetCoordinateSystem () const
 
bool NeedsMipmapGeneration () const
 

Friends

class AllocatorMTL
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< TextureGLES, Texture >
static TextureGLESCast (Texture &base)
 
static const TextureGLESCast (const Texture &base)
 
static TextureGLESCast (Texture *base)
 
static const TextureGLESCast (const Texture *base)
 
- 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 15 of file texture_gles.h.

Member Enumeration Documentation

◆ AttachmentPoint

Enumerator
kColor0 
kDepth 
kStencil 

Definition at line 43 of file texture_gles.h.

43  {
44  kColor0,
45  kDepth,
46  kStencil,
47  };

◆ IsWrapped

Enumerator
kWrapped 

Definition at line 24 of file texture_gles.h.

24  {
25  kWrapped,
26  };

◆ Type

Enumerator
kTexture 
kRenderBuffer 
kRenderBufferMultisampled 

Definition at line 18 of file texture_gles.h.

18  {
19  kTexture,
21  kRenderBufferMultisampled,
22  };

Constructor & Destructor Documentation

◆ TextureGLES() [1/2]

impeller::TextureGLES::TextureGLES ( ReactorGLES::Ref  reactor,
TextureDescriptor  desc 
)

Definition at line 42 of file texture_gles.cc.

43  : TextureGLES(std::move(reactor), desc, false) {}

◆ TextureGLES() [2/2]

impeller::TextureGLES::TextureGLES ( ReactorGLES::Ref  reactor,
TextureDescriptor  desc,
IsWrapped  wrapped 
)

Definition at line 45 of file texture_gles.cc.

48  : TextureGLES(std::move(reactor), desc, true) {}

◆ ~TextureGLES()

impeller::TextureGLES::~TextureGLES ( )
override

Definition at line 76 of file texture_gles.cc.

76  {
77  reactor_->CollectHandle(handle_);
78 }

Member Function Documentation

◆ Bind()

bool impeller::TextureGLES::Bind ( ) const

Definition at line 434 of file texture_gles.cc.

434  {
435  auto handle = GetGLHandle();
436  if (!handle.has_value()) {
437  return false;
438  }
439  const auto& gl = reactor_->GetProcTable();
440  switch (type_) {
441  case Type::kTexture: {
442  const auto target = ToTextureTarget(GetTextureDescriptor().type);
443  if (!target.has_value()) {
444  VALIDATION_LOG << "Could not bind texture of this type.";
445  return false;
446  }
447  gl.BindTexture(target.value(), handle.value());
448  } break;
449  case Type::kRenderBuffer:
450  // MSAA textures are treated as render buffers.
452  gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
453  break;
454  }
455  InitializeContentsIfNecessary();
456  return true;
457 }

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

Referenced by GenerateMipmap().

◆ GenerateMipmap()

bool impeller::TextureGLES::GenerateMipmap ( )

Definition at line 459 of file texture_gles.cc.

459  {
460  if (!IsValid()) {
461  return false;
462  }
463 
464  auto type = GetTextureDescriptor().type;
465  switch (type) {
467  break;
469  VALIDATION_LOG << "Generating mipmaps for multisample textures is not "
470  "supported in the GLES backend.";
471  return false;
473  break;
475  break;
476  }
477 
478  if (!Bind()) {
479  return false;
480  }
481 
482  auto handle = GetGLHandle();
483  if (!handle.has_value()) {
484  return false;
485  }
486 
487  const auto& gl = reactor_->GetProcTable();
488  gl.GenerateMipmap(ToTextureType(type));
489  mipmap_generated_ = true;
490  return true;
491 }

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

◆ GetGLHandle()

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

Definition at line 427 of file texture_gles.cc.

427  {
428  if (!IsValid()) {
429  return std::nullopt;
430  }
431  return reactor_->GetGLHandle(handle_);
432 }

Referenced by Bind(), impeller::ConfigureFBO(), GenerateMipmap(), and SetAsFramebufferAttachment().

◆ GetType()

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

Definition at line 493 of file texture_gles.cc.

493  {
494  return type_;
495 }

◆ IsWrapped()

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

Definition at line 54 of file texture_gles.h.

54 { return is_wrapped_; }

◆ SetAsFramebufferAttachment()

bool impeller::TextureGLES::SetAsFramebufferAttachment ( GLenum  target,
GLuint  fbo,
AttachmentPoint  point 
) const

Definition at line 508 of file texture_gles.cc.

510  {
511  if (!IsValid()) {
512  return false;
513  }
514  InitializeContentsIfNecessary();
515  auto handle = GetGLHandle();
516  if (!handle.has_value()) {
517  return false;
518  }
519  const auto& gl = reactor_->GetProcTable();
520  switch (type_) {
521  case Type::kTexture:
522  gl.FramebufferTexture2D(target, // target
523  ToAttachmentPoint(point), // attachment
524  GL_TEXTURE_2D, // textarget
525  handle.value(), // texture
526  0 // level
527  );
528  break;
529  case Type::kRenderBuffer:
530  gl.FramebufferRenderbuffer(target, // target
531  ToAttachmentPoint(point), // attachment
532  GL_RENDERBUFFER, // render-buffer target
533  handle.value() // render-buffer
534  );
535  break;
537  // Assume that when MSAA is enabled, we're using 4x MSAA.
538  FML_DCHECK(GetTextureDescriptor().sample_count == SampleCount::kCount4);
539  gl.FramebufferTexture2DMultisampleEXT(
540  target, // target
541  ToAttachmentPoint(point), // attachment
542  GL_TEXTURE_2D, // textarget
543  handle.value(), // texture
544  0, // level
545  4 // samples
546  );
547  break;
548  }
549  return true;
550 }

References GetGLHandle(), impeller::Texture::GetTextureDescriptor(), impeller::kCount4, kRenderBuffer, kRenderBufferMultisampled, kTexture, and impeller::ToAttachmentPoint().

Referenced by impeller::ConfigureFBO().

Friends And Related Function Documentation

◆ AllocatorMTL

friend class AllocatorMTL
friend

Definition at line 57 of file texture_gles.h.


The documentation for this class was generated from the following files:
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::ToAttachmentPoint
static GLenum ToAttachmentPoint(TextureGLES::AttachmentPoint point)
Definition: texture_gles.cc:497
impeller::HandleType::kRenderBuffer
@ kRenderBuffer
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
impeller::TextureGLES::GetGLHandle
std::optional< GLuint > GetGLHandle() const
Definition: texture_gles.cc:427
impeller::HandleType::kTexture
@ kTexture
impeller::TextureGLES::Type::kRenderBufferMultisampled
@ kRenderBufferMultisampled
impeller::SampleCount::kCount4
@ kCount4
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:41
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureGLES::Type::kRenderBuffer
@ kRenderBuffer
impeller::TextureGLES::TextureGLES
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
Definition: texture_gles.cc:42
impeller::AttachmentKind::kStencil
@ kStencil
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::AttachmentKind::kDepth
@ kDepth
impeller::ToTextureType
constexpr GLenum ToTextureType(TextureType type)
Definition: formats_gles.h:169
impeller::Texture::mipmap_generated_
bool mipmap_generated_
Definition: texture.h:61
impeller::TextureType::kTexture2D
@ kTexture2D
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:183
impeller::TextureGLES::Bind
bool Bind() const
Definition: texture_gles.cc:434
impeller::TextureGLES::Type::kTexture
@ kTexture