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

141 {
142 TextureGLES& texture_gles = TextureGLES::Cast(*destination);
143
144 if (texture_gles.GetType() != TextureGLES::Type::kTexture) {
145 VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
146 "this texture object.";
147 return false;
148 }
149
150 if (texture_gles.IsWrapped()) {
151 VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
152 return false;
153 }
154
155 const auto& tex_descriptor = texture_gles.GetTextureDescriptor();
156
157 if (tex_descriptor.size.IsEmpty()) {
158 return true;
159 }
160
161 if (!tex_descriptor.IsValid() ||
163 BytesForTextureRegion(tex_descriptor.format,
166 return false;
167 }
168
169 GLenum texture_type;
170 GLenum texture_target;
171 switch (tex_descriptor.type) {
173 texture_type = GL_TEXTURE_2D;
174 texture_target = GL_TEXTURE_2D;
175 break;
177 VALIDATION_LOG << "Multisample texture uploading is not supported for "
178 "the OpenGLES backend.";
179 return false;
181 texture_type = GL_TEXTURE_CUBE_MAP;
182 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
183 break;
185 texture_type = GL_TEXTURE_EXTERNAL_OES;
186 texture_target = GL_TEXTURE_EXTERNAL_OES;
187 break;
188 }
189
190 std::optional<PixelFormatGLES> gles_format =
191 ToPixelFormatGLES(tex_descriptor.format,
192 /*supports_bgra=*/
193 reactor.GetProcTable().GetDescription()->HasExtension(
194 "GL_EXT_texture_format_BGRA8888"));
195 if (!gles_format.has_value()) {
196 VALIDATION_LOG << "Invalid texture format.";
197 return false;
198 }
199
200 auto gl_handle = texture_gles.GetGLHandle();
201 if (!gl_handle.has_value()) {
203 << "Texture was collected before it could be uploaded to the GPU.";
204 return false;
205 }
206 const auto& gl = reactor.GetProcTable();
207 gl.BindTexture(texture_type, gl_handle.value());
208 const GLvoid* tex_data =
210
211 // Block-compressed textures cannot be allocated empty and then filled with a
212 // sub-image; glCompressedTexImage2D redefines the entire mip level. Require
213 // the upload to cover the full mip level starting at the origin.
214 if (gles_format->is_compressed) {
215 const auto mip_width =
216 std::max<int32_t>(1, tex_descriptor.size.width >> mip_level);
217 const auto mip_height =
218 std::max<int32_t>(1, tex_descriptor.size.height >> mip_level);
219 if (destination_region.GetX() != 0 || destination_region.GetY() != 0 ||
220 destination_region.GetWidth() != mip_width ||
221 destination_region.GetHeight() != mip_height) {
222 VALIDATION_LOG << "Compressed textures must be uploaded as a full mip "
223 "level starting at the origin.";
224 return false;
225 }
226 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
227 gl.CompressedTexImage2D(texture_target, // target
228 mip_level, // LOD level
229 gles_format->internal_format, // internal format
230 mip_width, // width
231 mip_height, // height
232 0u, // border
233 source.GetRange().length, // image size
234 tex_data); // data
235 texture_gles.MarkSliceMipLevelInitialized(slice, mip_level);
236 return true;
237 }
238
239 // GL_INVALID_OPERATION if the requested mip level has not been defined by
240 // a previous glTexImage2D operation. Allocate the requested mip lazily on
241 // first write, only for the level the upload is actually targeting. The
242 // snapshot pipeline (single base-level allocation followed by
243 // glGenerateMipmap) keeps its existing GL footprint, and per-level uploads
244 // pay only for the levels they touch.
245 if (!texture_gles.IsSliceMipLevelInitialized(slice, mip_level)) {
246 const auto level_width =
247 std::max<int32_t>(1, tex_descriptor.size.width >> mip_level);
248 const auto level_height =
249 std::max<int32_t>(1, tex_descriptor.size.height >> mip_level);
250 gl.TexImage2D(texture_target, // target
251 mip_level, // LOD level
252 gles_format->internal_format, // internal format
253 level_width, // width
254 level_height, // height
255 0u, // border
256 gles_format->external_format, // format
257 gles_format->type, // type
258 nullptr); // data
259 texture_gles.MarkSliceMipLevelInitialized(slice, mip_level);
260 }
261
262 {
263 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
264 gl.TexSubImage2D(texture_target, // target
265 mip_level, // LOD level
266 destination_region.GetX(), // xoffset
267 destination_region.GetY(), // yoffset
268 destination_region.GetWidth(), // width
269 destination_region.GetHeight(), // height
270 gles_format->external_format, // format
271 gles_format->type, // type
272 tex_data); // data
273 }
274 return true;
275}
static TextureGLES & Cast(Texture &base)
virtual uint8_t * OnGetContents() const =0
std::optional< PixelFormatGLES > ToPixelFormatGLES(PixelFormat pixel_format, bool supports_bgra)
constexpr size_t BytesForTextureRegion(PixelFormat format, int64_t width, int64_t height)
The number of bytes required to store a width x height texel region in format. Block-compressed forma...
Definition formats.h:727
std::shared_ptr< ReactorGLES > reactor
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 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::BytesForTextureRegion(), impeller::BackendCast< TextureGLES, Texture >::Cast(), impeller::BlitCopyBufferToTextureCommand::destination, impeller::BlitCopyBufferToTextureCommand::destination_region, impeller::BufferView::GetBuffer(), impeller::TextureGLES::GetGLHandle(), impeller::TRect< T >::GetHeight(), impeller::BufferView::GetRange(), impeller::Texture::GetTextureDescriptor(), impeller::TextureGLES::GetType(), impeller::TRect< T >::GetWidth(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::TextureGLES::IsSliceMipLevelInitialized(), impeller::TextureGLES::IsWrapped(), impeller::TextureGLES::kTexture, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::kTextureCube, impeller::kTextureExternalOES, impeller::Range::length, impeller::TextureGLES::MarkSliceMipLevelInitialized(), impeller::BlitCopyBufferToTextureCommand::mip_level, impeller::Range::offset, impeller::DeviceBuffer::OnGetContents(), reactor, 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 136 of file blit_command_gles.cc.

136 {
137 return label;
138}

References impeller::BlitCommand::label.


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