24static bool IsDepthStencilFormat(
PixelFormat format) {
49 const TextureDescriptor& desc,
50 const std::shared_ptr<const CapabilitiesGLES>& capabilities) {
54 if (usage == render_target && IsDepthStencilFormat(desc.format)) {
58 return is_msaa ? (capabilities->SupportsImplicitResolvingMSAA()
64struct TexImage2DData {
68 std::shared_ptr<const fml::Mapping>
data;
71 switch (pixel_format) {
75 type = GL_UNSIGNED_BYTE;
80 type = GL_UNSIGNED_BYTE;
88 type = GL_UNSIGNED_BYTE;
109 type = GL_UNSIGNED_INT_24_8;
123 std::shared_ptr<const fml::Mapping> mapping)
124 : TexImage2DData(pixel_format) {
125 data = std::move(mapping);
128 bool IsValid()
const {
return is_valid_; }
131 bool is_valid_ =
false;
148 std::shared_ptr<ReactorGLES> reactor,
151 auto texture = std::shared_ptr<TextureGLES>(
152 new TextureGLES(std::move(reactor), desc,
false, fbo, std::nullopt));
160 std::shared_ptr<ReactorGLES> reactor,
163 if (external_handle.
IsDead()) {
172 std::move(reactor), desc,
false, std::nullopt, external_handle));
180 std::shared_ptr<ReactorGLES> reactor,
198 std::optional<GLuint> fbo,
199 std::optional<HandleGLES> external_handle)
201 reactor_(
std::move(reactor)),
202 type_(GetTextureTypeFromDescriptor(
203 GetTextureDescriptor(),
204 reactor_->GetProcTable().GetCapabilities())),
205 handle_(external_handle.has_value()
206 ? external_handle.
value()
207 : (threadsafe ? reactor_->CreateHandle(
ToHandleType(type_))
208 : reactor_->CreateUntrackedHandle(
210 is_wrapped_(fbo.has_value() || external_handle.has_value()),
219 const auto max_size =
220 reactor_->GetProcTable().GetCapabilities()->max_texture_size;
221 if (tex_size.Max(max_size) != max_size) {
223 <<
" would exceed max supported size of " << max_size <<
".";
232 reactor_->CollectHandle(handle_);
233 if (!cached_fbo_.
IsDead()) {
234 reactor_->CollectHandle(cached_fbo_);
248void TextureGLES::SetLabel(std::string_view label) {
250 reactor_->SetDebugLabel(handle_, label);
255void TextureGLES::SetLabel(std::string_view label, std::string_view trailing) {
257 if (reactor_->CanSetDebugLabels()) {
258 reactor_->SetDebugLabel(handle_, std::format(
"{} {}", label, trailing));
264bool TextureGLES::OnSetContents(
const uint8_t* contents,
271bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
277 if (mapping->GetSize() == 0u) {
281 if (mapping->GetMapping() ==
nullptr) {
286 VALIDATION_LOG <<
"Incorrect texture usage flags for setting contents on "
287 "this texture object.";
292 VALIDATION_LOG <<
"Cannot set the contents of a wrapped texture.";
298 if (tex_descriptor.size.IsEmpty()) {
302 if (!tex_descriptor.IsValid() ||
303 mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
308 GLenum texture_target;
309 switch (tex_descriptor.type) {
311 texture_type = GL_TEXTURE_2D;
312 texture_target = GL_TEXTURE_2D;
315 VALIDATION_LOG <<
"Multisample texture uploading is not supported for "
316 "the OpenGLES backend.";
319 texture_type = GL_TEXTURE_CUBE_MAP;
320 texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
323 texture_type = GL_TEXTURE_EXTERNAL_OES;
324 texture_target = GL_TEXTURE_EXTERNAL_OES;
328 auto data = std::make_shared<TexImage2DData>(tex_descriptor.format,
337 size = tex_descriptor.size,
340 ](
const auto& reactor) {
341 auto gl_handle = reactor.GetGLHandle(handle);
342 if (!gl_handle.has_value()) {
344 <<
"Texture was collected before it could be uploaded to the GPU.";
347 const auto& gl = reactor.GetProcTable();
348 gl.BindTexture(texture_type, gl_handle.value());
349 const GLvoid* tex_data =
nullptr;
351 tex_data =
data->data->GetMapping();
356 std::to_string(
data->data->GetSize()).c_str());
357 gl.PixelStorei(GL_UNPACK_ALIGNMENT, 1);
358 gl.TexImage2D(texture_target,
360 data->internal_format,
364 data->external_format,
371 slices_initialized_ = reactor_->AddOperation(texture_upload);
372 return slices_initialized_[0];
376ISize TextureGLES::GetSize()
const {
390 return GL_STENCIL_INDEX8;
392 return GL_DEPTH24_STENCIL8;
394 return GL_DEPTH32F_STENCIL8;
418void TextureGLES::InitializeContentsIfNecessary()
const {
419 if (!
IsValid() || slices_initialized_[0]) {
422 slices_initialized_[0] =
true;
428 auto size = GetSize();
430 if (
size.IsEmpty()) {
434 const auto& gl = reactor_->GetProcTable();
435 std::optional<GLuint> handle = reactor_->GetGLHandle(handle_);
436 if (!handle.has_value()) {
437 VALIDATION_LOG <<
"Could not initialize the contents of texture.";
445 if (!tex_data.IsValid()) {
449 gl.BindTexture(GL_TEXTURE_2D, handle.value());
452 gl.TexImage2D(GL_TEXTURE_2D,
454 tex_data.internal_format,
458 tex_data.external_format,
466 auto render_buffer_format =
468 if (!render_buffer_format.has_value()) {
472 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
478 if (gl.GetCapabilities()->SupportsImplicitResolvingMSAA()) {
479 gl.RenderbufferStorageMultisampleEXT(
482 render_buffer_format.value(),
487 gl.RenderbufferStorageMultisample(
490 render_buffer_format.value(),
496 gl.RenderbufferStorage(
498 render_buffer_format.value(),
512 return reactor_->GetGLHandle(handle_);
517 if (!handle.has_value()) {
520 const auto& gl = reactor_->GetProcTable();
522 if (fence_.has_value()) {
523 std::optional<GLsync> fence = reactor_->GetGLFence(fence_.value());
524 if (fence.has_value()) {
525 gl.WaitSync(fence.value(), 0, GL_TIMEOUT_IGNORED);
527 reactor_->CollectHandle(fence_.value());
528 fence_ = std::nullopt;
535 if (!
target.has_value()) {
539 gl.BindTexture(
target.value(), handle.value());
543 gl.BindRenderbuffer(GL_RENDERBUFFER, handle.value());
546 InitializeContentsIfNecessary();
551 for (
size_t i = 0;
i < slices_initialized_.size();
i++) {
552 slices_initialized_[
i] =
true;
557 slices_initialized_[slice] =
true;
561 return slices_initialized_[slice];
574 VALIDATION_LOG <<
"Generating mipmaps for multisample textures is not "
575 "supported in the GLES backend.";
588 if (!handle.has_value()) {
592 const auto& gl = reactor_->GetProcTable();
605 return GL_COLOR_ATTACHMENT0;
607 return GL_DEPTH_ATTACHMENT;
609 return GL_STENCIL_ATTACHMENT;
619 InitializeContentsIfNecessary();
621 if (!handle.has_value()) {
624 const auto& gl = reactor_->GetProcTable();
628 gl.FramebufferTexture2D(
target,
636 gl.FramebufferTexture2DMultisampleEXT(
647 gl.FramebufferRenderbuffer(
660Scalar TextureGLES::GetYCoordScale()
const {
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
constexpr bool IsDead() const
Determines if the handle is dead.
HandleType GetType() const
static HandleGLES DeadHandle()
Creates a dead handle.
std::function< void(const ReactorGLES &reactor)> Operation
static std::shared_ptr< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
void MarkContentsInitialized()
Indicates that all texture storage has already been allocated and contents initialized.
const HandleGLES & GetCachedFBO() const
Retrieve the cached FBO object, or a dead handle if there is no object.
std::optional< HandleGLES > GetSyncFence() const
bool IsSliceInitialized(size_t slice) const
@ kRenderBufferMultisampled
bool IsValid() const override
void SetFence(HandleGLES fence)
Attach a sync fence to this texture that will be waited on before encoding a rendering operation that...
void Leak()
Reset the internal texture state so that the reactor will not free the associated handle.
void SetCachedFBO(HandleGLES fbo)
TextureGLES(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, bool threadsafe=false)
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
static std::shared_ptr< TextureGLES > CreatePlaceholder(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way....
std::optional< GLuint > GetFBO() const
Type ComputeTypeForBinding(GLenum target) const
void MarkSliceInitialized(size_t slice) const
Indicates that a specific texture slice has been initialized.
std::optional< GLuint > GetGLHandle() const
static std::shared_ptr< TextureGLES > WrapTexture(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is as...
const TextureDescriptor & GetTextureDescriptor() const
TextureCoordinateSystem GetCoordinateSystem() const
uint32_t uint32_t * format
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
std::shared_ptr< fml::Mapping > CreateMappingWithCopy(const uint8_t *contents, Bytes length)
Creates a mapping with copy of the bytes.
AllocationSize< 1u > Bytes
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
constexpr GLenum ToTextureType(TextureType type)
static std::optional< GLenum > ToRenderBufferFormat(PixelFormat format)
static GLenum ToAttachmentType(TextureGLES::AttachmentType point)
Mask< TextureUsage > TextureUsageMask
HandleType ToHandleType(TextureGLES::Type type)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)