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 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 201 of file blit_command_gles.cc.

202  {
203  TextureGLES& texture_gles = TextureGLES::Cast(*destination);
204 
205  if (texture_gles.GetType() != TextureGLES::Type::kTexture) {
206  VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
207  "this texture object.";
208  return false;
209  }
210 
211  if (texture_gles.IsWrapped()) {
212  VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
213  return false;
214  }
215 
216  const auto& tex_descriptor = texture_gles.GetTextureDescriptor();
217 
218  if (tex_descriptor.size.IsEmpty()) {
219  return true;
220  }
221 
222  if (!tex_descriptor.IsValid() ||
223  source.range.length !=
224  BytesPerPixelForPixelFormat(tex_descriptor.format) *
226  return false;
227  }
228 
230 
231  GLenum texture_type;
232  GLenum texture_target;
233  switch (tex_descriptor.type) {
235  texture_type = GL_TEXTURE_2D;
236  texture_target = GL_TEXTURE_2D;
237  break;
239  VALIDATION_LOG << "Multisample texture uploading is not supported for "
240  "the OpenGLES backend.";
241  return false;
243  texture_type = GL_TEXTURE_CUBE_MAP;
244  texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
245  break;
247  texture_type = GL_TEXTURE_EXTERNAL_OES;
248  texture_target = GL_TEXTURE_EXTERNAL_OES;
249  break;
250  }
251 
252  TexImage2DData data = TexImage2DData(tex_descriptor.format, source);
253  if (!data.IsValid()) {
254  VALIDATION_LOG << "Invalid texture format.";
255  return false;
256  }
257 
258  auto gl_handle = texture_gles.GetGLHandle();
259  if (!gl_handle.has_value()) {
261  << "Texture was collected before it could be uploaded to the GPU.";
262  return false;
263  }
264  const auto& gl = reactor.GetProcTable();
265  gl.BindTexture(texture_type, gl_handle.value());
266  const GLvoid* tex_data =
267  data.buffer_view.buffer->OnGetContents() + data.buffer_view.range.offset;
268 
269  // GL_INVALID_OPERATION if the texture array has not been
270  // defined by a previous glTexImage2D operation.
271  if (!texture_gles.IsSliceInitialized(slice)) {
272  gl.TexImage2D(texture_target, // target
273  0u, // LOD level
274  data.internal_format, // internal format
275  tex_descriptor.size.width, // width
276  tex_descriptor.size.height, // height
277  0u, // border
278  data.external_format, // external format
279  data.type, // type
280  nullptr // data
281  );
282  texture_gles.MarkSliceInitialized(slice);
283  }
284 
285  {
286  gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
287  gl.TexSubImage2D(texture_target, // target
288  0u, // LOD level
289  destination_region.GetX(), // xoffset
290  destination_region.GetY(), // yoffset
291  destination_region.GetWidth(), // width
292  destination_region.GetHeight(), // height
293  data.external_format, // external format
294  data.type, // type
295  tex_data // data
296 
297  );
298  }
299  return true;
300 }

References impeller::TRect< T >::Area(), impeller::BytesPerPixelForPixelFormat(), impeller::BackendCast< TextureGLES, Texture >::Cast(), data, impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::TextureGLES::GetGLHandle(), impeller::TRect< T >::GetHeight(), impeller::ReactorGLES::GetProcTable(), impeller::Texture::GetTextureDescriptor(), impeller::TextureGLES::GetType(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TextureGLES::IsSliceInitialized(), impeller::TextureGLES::kTexture, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::kUploadFromHost, impeller::Range::length, impeller::TextureGLES::MarkSliceInitialized(), impeller::BufferView::range, impeller::BlitCopyBufferToTextureCommand::slice, impeller::BlitCopyBufferToTextureCommand::source, and VALIDATION_LOG.

◆ GetLabel()

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

Implements impeller::BlitEncodeGLES.

Definition at line 197 of file blit_command_gles.cc.

197  {
198  return label;
199 }

References impeller::BlitCommand::label.


The documentation for this struct was generated from the following files:
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
impeller::TRect::GetX
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition: rect.h:327
impeller::BlitCopyBufferToTextureCommand::destination_region
IRect destination_region
Definition: blit_command.h:40
impeller::BufferView::range
Range range
Definition: buffer_view.h:17
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:341
impeller::TextureCoordinateSystem::kUploadFromHost
@ kUploadFromHost
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:15
impeller::BlitCopyBufferToTextureCommand::source
BufferView source
Definition: blit_command.h:38
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:466
impeller::BlitCopyBufferToTextureCommand::slice
uint32_t slice
Definition: blit_command.h:41
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:335
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::TextureType::kTexture2D
@ kTexture2D
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::BackendCast< TextureGLES, Texture >::Cast
static TextureGLES & Cast(Texture &base)
Definition: backend_cast.h:13
impeller::TRect::Area
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
Definition: rect.h:370
impeller::Range::length
size_t length
Definition: range.h:15
impeller::TextureGLES::Type::kTexture
@ kTexture
impeller::TRect::GetY
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition: rect.h:331
impeller::BlitCopyBufferToTextureCommand::destination
std::shared_ptr< Texture > destination
Definition: blit_command.h:39