Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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 158 of file blit_command_gles.cc.

159 {
160 TextureGLES& texture_gles = TextureGLES::Cast(*destination);
161
162 if (texture_gles.GetType() != TextureGLES::Type::kTexture) {
163 VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
164 "this texture object.";
165 return false;
166 }
167
168 if (texture_gles.IsWrapped()) {
169 VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
170 return false;
171 }
172
173 const auto& tex_descriptor = texture_gles.GetTextureDescriptor();
174
175 if (tex_descriptor.size.IsEmpty()) {
176 return true;
177 }
178
179 if (!tex_descriptor.IsValid() ||
181 BytesPerPixelForPixelFormat(tex_descriptor.format) *
183 return false;
184 }
185
187
188 GLenum texture_type;
189 GLenum texture_target;
190 switch (tex_descriptor.type) {
192 texture_type = GL_TEXTURE_2D;
193 texture_target = GL_TEXTURE_2D;
194 break;
196 VALIDATION_LOG << "Multisample texture uploading is not supported for "
197 "the OpenGLES backend.";
198 return false;
200 texture_type = GL_TEXTURE_CUBE_MAP;
201 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
202 break;
204 texture_type = GL_TEXTURE_EXTERNAL_OES;
205 texture_target = GL_TEXTURE_EXTERNAL_OES;
206 break;
207 }
208
209 std::optional<PixelFormatGLES> gles_format =
210 ToPixelFormatGLES(tex_descriptor.format,
211 /*supports_bgra=*/
212 reactor.GetProcTable().GetDescription()->HasExtension(
213 "GL_EXT_texture_format_BGRA8888"));
214 if (!gles_format.has_value()) {
215 VALIDATION_LOG << "Invalid texture format.";
216 return false;
217 }
218
219 auto gl_handle = texture_gles.GetGLHandle();
220 if (!gl_handle.has_value()) {
222 << "Texture was collected before it could be uploaded to the GPU.";
223 return false;
224 }
225 const auto& gl = reactor.GetProcTable();
226 gl.BindTexture(texture_type, gl_handle.value());
227 const GLvoid* tex_data =
229
230 // GL_INVALID_OPERATION if the requested mip level has not been defined by
231 // a previous glTexImage2D operation. Allocate the requested mip lazily on
232 // first write, only for the level the upload is actually targeting. The
233 // snapshot pipeline (single base-level allocation followed by
234 // glGenerateMipmap) keeps its existing GL footprint, and per-level uploads
235 // pay only for the levels they touch.
236 if (!texture_gles.IsSliceMipLevelInitialized(slice, mip_level)) {
237 const auto level_width =
238 std::max<int32_t>(1, tex_descriptor.size.width >> mip_level);
239 const auto level_height =
240 std::max<int32_t>(1, tex_descriptor.size.height >> mip_level);
241 gl.TexImage2D(texture_target, // target
242 mip_level, // LOD level
243 gles_format->internal_format, // internal format
244 level_width, // width
245 level_height, // height
246 0u, // border
247 gles_format->external_format, // format
248 gles_format->type, // type
249 nullptr); // data
250 texture_gles.MarkSliceMipLevelInitialized(slice, mip_level);
251 }
252
253 {
254 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
255 gl.TexSubImage2D(texture_target, // target
256 mip_level, // LOD level
257 destination_region.GetX(), // xoffset
258 destination_region.GetY(), // yoffset
259 destination_region.GetWidth(), // width
260 destination_region.GetHeight(), // height
261 gles_format->external_format, // format
262 gles_format->type, // type
263 tex_data); // data
264 }
265 return true;
266}
static TextureGLES & Cast(Texture &base)
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)
std::shared_ptr< Texture > destination
Range GetRange() const
Definition buffer_view.h:27
const DeviceBuffer * GetBuffer() const
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:371
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:381
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
Definition rect.h:410
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition rect.h:367
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:375
#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::IsSliceMipLevelInitialized(), impeller::TextureGLES::IsWrapped(), impeller::TextureGLES::kTexture, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::kUploadFromHost, impeller::Range::length, impeller::TextureGLES::MarkSliceMipLevelInitialized(), 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(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), impeller::testing::TEST(), and impeller::testing::TEST().

◆ GetLabel()

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

Implements impeller::BlitEncodeGLES.

Definition at line 154 of file blit_command_gles.cc.

154 {
155 return label;
156}

References impeller::BlitCommand::label.


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