Flutter Impeller
impeller::BlitCopyBufferToTextureCommandGLES Struct Reference

#include <blit_command_gles.h>

Inheritance diagram for impeller::BlitCopyBufferToTextureCommandGLES:
impeller::BlitEncodeGLES impeller::BlitCopyBufferToTextureCommand impeller::BackendCast< BlitEncodeGLES, BlitCommand > impeller::BlitCommand

Public Member Functions

 ~BlitCopyBufferToTextureCommandGLES () override
 
std::string GetLabel () const override
 
bool Encode (const ReactorGLES &reactor) const override
 
- Public Member Functions inherited from impeller::BlitEncodeGLES
virtual ~BlitEncodeGLES ()
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< BlitEncodeGLES, BlitCommand >
static BlitEncodeGLESCast (BlitCommand &base)
 
static const BlitEncodeGLESCast (const BlitCommand &base)
 
static BlitEncodeGLESCast (BlitCommand *base)
 
static const BlitEncodeGLESCast (const BlitCommand *base)
 
- Public Attributes inherited from impeller::BlitCopyBufferToTextureCommand
BufferView source
 
std::shared_ptr< Texturedestination
 
IRect destination_region
 
uint32_t mip_level = 0
 
uint32_t slice = 0
 
- Public Attributes inherited from impeller::BlitCommand
std::string label
 

Detailed Description

Definition at line 23 of file blit_command_gles.h.

Constructor & Destructor Documentation

◆ ~BlitCopyBufferToTextureCommandGLES()

impeller::BlitCopyBufferToTextureCommandGLES::~BlitCopyBufferToTextureCommandGLES ( )
overridedefault

Member Function Documentation

◆ Encode()

bool impeller::BlitCopyBufferToTextureCommandGLES::Encode ( const ReactorGLES reactor) const
overridevirtual

Implements impeller::BlitEncodeGLES.

Definition at line 156 of file blit_command_gles.cc.

157  {
158  TextureGLES& texture_gles = TextureGLES::Cast(*destination);
159 
160  if (texture_gles.GetType() != TextureGLES::Type::kTexture) {
161  VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
162  "this texture object.";
163  return false;
164  }
165 
166  if (texture_gles.IsWrapped()) {
167  VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
168  return false;
169  }
170 
171  const auto& tex_descriptor = texture_gles.GetTextureDescriptor();
172 
173  if (tex_descriptor.size.IsEmpty()) {
174  return true;
175  }
176 
177  if (!tex_descriptor.IsValid() ||
178  source.GetRange().length !=
179  BytesPerPixelForPixelFormat(tex_descriptor.format) *
181  return false;
182  }
183 
185 
186  GLenum texture_type;
187  GLenum texture_target;
188  switch (tex_descriptor.type) {
190  texture_type = GL_TEXTURE_2D;
191  texture_target = GL_TEXTURE_2D;
192  break;
194  VALIDATION_LOG << "Multisample texture uploading is not supported for "
195  "the OpenGLES backend.";
196  return false;
198  texture_type = GL_TEXTURE_CUBE_MAP;
199  texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
200  break;
202  texture_type = GL_TEXTURE_EXTERNAL_OES;
203  texture_target = GL_TEXTURE_EXTERNAL_OES;
204  break;
205  }
206 
207  std::optional<PixelFormatGLES> gles_format =
208  ToPixelFormatGLES(tex_descriptor.format,
209  /*supports_bgra=*/
210  reactor.GetProcTable().GetDescription()->HasExtension(
211  "GL_EXT_texture_format_BGRA8888"));
212  if (!gles_format.has_value()) {
213  VALIDATION_LOG << "Invalid texture format.";
214  return false;
215  }
216 
217  auto gl_handle = texture_gles.GetGLHandle();
218  if (!gl_handle.has_value()) {
220  << "Texture was collected before it could be uploaded to the GPU.";
221  return false;
222  }
223  const auto& gl = reactor.GetProcTable();
224  gl.BindTexture(texture_type, gl_handle.value());
225  const GLvoid* tex_data =
227 
228  // GL_INVALID_OPERATION if the texture array has not been
229  // defined by a previous glTexImage2D operation.
230  if (!texture_gles.IsSliceInitialized(slice)) {
231  gl.TexImage2D(texture_target, // target
232  mip_level, // LOD level
233  gles_format->internal_format, // internal format
234  tex_descriptor.size.width, // width
235  tex_descriptor.size.height, // height
236  0u, // border
237  gles_format->external_format, // format
238  gles_format->type, // type
239  nullptr); // data
240  texture_gles.MarkSliceInitialized(slice);
241  }
242 
243  {
244  gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
245  gl.TexSubImage2D(texture_target, // target
246  mip_level, // LOD level
247  destination_region.GetX(), // xoffset
248  destination_region.GetY(), // yoffset
249  destination_region.GetWidth(), // width
250  destination_region.GetHeight(), // height
251  gles_format->external_format, // format
252  gles_format->type, // type
253  tex_data); // data
254  }
255  return true;
256 }
static TextureGLES & Cast(Texture &base)
Definition: backend_cast.h:13
virtual uint8_t * OnGetContents() const =0
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:469
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
Definition: formats_gles.cc:26
std::shared_ptr< Texture > destination
Definition: blit_command.h:40
Range GetRange() const
Definition: buffer_view.h:27
const DeviceBuffer * GetBuffer() const
Definition: buffer_view.cc:17
size_t length
Definition: range.h:15
size_t offset
Definition: range.h:14
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition: rect.h:337
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:347
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
Definition: rect.h:376
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition: rect.h:333
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:341
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::TRect< T >::Area(), impeller::BytesPerPixelForPixelFormat(), impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BufferView::GetBuffer(), impeller::ProcTableGLES::GetDescription(), impeller::TextureGLES::GetGLHandle(), impeller::TRect< T >::GetHeight(), impeller::ReactorGLES::GetProcTable(), impeller::BufferView::GetRange(), impeller::Texture::GetTextureDescriptor(), impeller::TextureGLES::GetType(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::DescriptionGLES::HasExtension(), impeller::TextureGLES::IsSliceInitialized(), impeller::TextureGLES::IsWrapped(), impeller::TextureGLES::kTexture, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::kUploadFromHost, impeller::Range::length, impeller::TextureGLES::MarkSliceInitialized(), impeller::BlitCopyBufferToTextureCommand::mip_level, impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), impeller::BlitCopyBufferToTextureCommand::slice, impeller::BlitCopyBufferToTextureCommand::source, impeller::ToPixelFormatGLES(), and VALIDATION_LOG.

Referenced by impeller::testing::TEST().

◆ GetLabel()

std::string impeller::BlitCopyBufferToTextureCommandGLES::GetLabel ( ) const
overridevirtual

Implements impeller::BlitEncodeGLES.

Definition at line 152 of file blit_command_gles.cc.

152  {
153  return label;
154 }

References impeller::BlitCommand::label.


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