| Flutter Impeller |

texture_gles.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEXTURE_GLES_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEXTURE_GLES_H_
7
8 #include <bitset>
9
10 #include "impeller/base/backend_cast.h"
11 #include "impeller/core/texture.h"
12 #include "impeller/renderer/backend/gles/handle_gles.h"
13 #include "impeller/renderer/backend/gles/reactor_gles.h"
14
15 namespace impeller {
16
17 class TextureGLES final : public Texture,
18 public BackendCast<TextureGLES, Texture> {
19 public:
20 enum class Type {
21 kTexture,
22 kTextureMultisampled,
23 kRenderBuffer,
24 kRenderBufferMultisampled,
25 };
26
27 enum class IsWrapped {
28 kWrapped,
29 };
30
31 TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc);
32
33 TextureGLES(ReactorGLES::Ref reactor,
34 TextureDescriptor desc,
35 IsWrapped wrapped);
36
37 TextureGLES(ReactorGLES::Ref reactor,
38 TextureDescriptor desc,
39 HandleGLES external_handle);
40
41 static std::shared_ptr<TextureGLES> WrapFBO(ReactorGLES::Ref reactor,
42 TextureDescriptor desc,
43 GLuint fbo);
44
45 // |Texture|
46 ~TextureGLES() override;
47
48 // |Texture|
49 bool IsValid() const override;
50
51 std::optional<GLuint> GetGLHandle() const;
52
53 [[nodiscard]] bool Bind() const;
54
55 [[nodiscard]] bool GenerateMipmap();
56
57 enum class AttachmentType {
58 kColor0,
59 kDepth,
60 kStencil,
61 };
62 [[nodiscard]] bool SetAsFramebufferAttachment(
63 GLenum target,
64 AttachmentType attachment_type) const;
65
66 Type GetType() const;
67
68 bool IsWrapped() const;
69
70 std::optional<GLuint> GetFBO() const;
71
72 // For non cubemap textures, 0 indicates uninitialized and 1 indicates
73 // initialized. For cubemap textures, each face is initialized separately with
74 // each bit tracking the initialization of the corresponding slice.
75 void MarkSliceInitialized(size_t slice) const;
76
77 bool IsSliceInitialized(size_t slice) const;
78
79 private:
80 ReactorGLES::Ref reactor_;
81 const Type type_;
82 HandleGLES handle_;
83 mutable std::bitset<6> slices_initialized_ = 0;
84 const bool is_wrapped_;
85 const std::optional<GLuint> wrapped_fbo_;
86 bool is_valid_ = false;
87
88 TextureGLES(std::shared_ptr<ReactorGLES> reactor,
89 TextureDescriptor desc,
90 bool is_wrapped,
91 std::optional<GLuint> fbo,
92 std::optional<HandleGLES> external_handle);
93
94 // |Texture|
95 void SetLabel(std::string_view label) override;
96
97 // |Texture|
98 bool OnSetContents(const uint8_t* contents,
99 size_t length,
100 size_t slice) override;
101
102 // |Texture|
103 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
104 size_t slice) override;
105
106 // |Texture|
107 ISize GetSize() const override;
108
109 // |Texture|
110 Scalar GetYCoordScale() const override;
111
112 void InitializeContentsIfNecessary() const;
113
114 TextureGLES(const TextureGLES&) = delete;
115
116 TextureGLES& operator=(const TextureGLES&) = delete;
117 };
118
119 } // namespace impeller
120
121 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEXTURE_GLES_H_
impeller::TextureGLES::Type
Type
Definition: texture_gles.h:20
impeller::TextureGLES::Type::kTextureMultisampled
@ kTextureMultisampled
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TextureGLES::GenerateMipmap
bool GenerateMipmap()
Definition: texture_gles.cc:477
impeller::TextureGLES::AttachmentType::kDepth
@ kDepth
impeller::TextureGLES::GetFBO
std::optional< GLuint > GetFBO() const
Definition: texture_gles.cc:587
impeller::TextureGLES::MarkSliceInitialized
void MarkSliceInitialized(size_t slice) const
Definition: texture_gles.cc:469
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:86
impeller::TextureGLES::GetGLHandle
std::optional< GLuint > GetGLHandle() const
Definition: texture_gles.cc:437
impeller::TextureGLES::Type::kRenderBufferMultisampled
@ kRenderBufferMultisampled
impeller::TextureGLES::IsWrapped
IsWrapped
Definition: texture_gles.h:27
impeller::TextureGLES::AttachmentType::kColor0
@ kColor0
impeller::TextureGLES::IsValid
bool IsValid() const override
Definition: texture_gles.cc:204
impeller::TextureGLES::IsSliceInitialized
bool IsSliceInitialized(size_t slice) const
Definition: texture_gles.cc:473
impeller::Texture
Definition: texture.h:17
impeller::TSize
Definition: size.h:19
impeller::TextureGLES::Type::kRenderBuffer
@ kRenderBuffer
impeller::TextureGLES::TextureGLES
TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
Definition: texture_gles.cc:142
impeller::TextureGLES::WrapFBO
static std::shared_ptr< TextureGLES > WrapFBO(ReactorGLES::Ref reactor, TextureDescriptor desc, GLuint fbo)
Definition: texture_gles.cc:160
backend_cast.h
impeller::HandleGLES
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition: handle_gles.h:36
impeller::TextureGLES::AttachmentType::kStencil
@ kStencil
impeller::TextureGLES::IsWrapped::kWrapped
@ kWrapped
impeller::TextureGLES::GetType
Type GetType() const
Definition: texture_gles.cc:511
reactor_gles.h
impeller::TextureGLES::~TextureGLES
~TextureGLES() override
Definition: texture_gles.cc:199
handle_gles.h
impeller::TextureGLES::AttachmentType
AttachmentType
Definition: texture_gles.h:57
impeller::BackendCast
Definition: backend_cast.h:11
texture.h
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureGLES
Definition: texture_gles.h:17
impeller::TextureGLES::Bind
bool Bind() const
Definition: texture_gles.cc:444
impeller::TextureGLES::Type::kTexture
@ kTexture
impeller
Definition: allocation.cc:12
impeller::TextureGLES::SetAsFramebufferAttachment
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
Definition: texture_gles.cc:526