| 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 static std::shared_ptr<TextureGLES> WrapFBO(ReactorGLES::Ref reactor,
38 TextureDescriptor desc,
39 GLuint fbo);
40
41 // |Texture|
42 ~TextureGLES() override;
43
44 std::optional<GLuint> GetGLHandle() const;
45
46 [[nodiscard]] bool Bind() const;
47
48 [[nodiscard]] bool GenerateMipmap();
49
50 enum class AttachmentType {
51 kColor0,
52 kDepth,
53 kStencil,
54 };
55 [[nodiscard]] bool SetAsFramebufferAttachment(
56 GLenum target,
57 AttachmentType attachment_type) const;
58
59 Type GetType() const;
60
61 bool IsWrapped() const { return is_wrapped_; }
62
63 std::optional<GLuint> GetFBO() const { return wrapped_fbo_; }
64
65 // For non cubemap textures, 0 indicates uninitialized and 1 indicates
66 // initialized. For cubemap textures, each face is initialized separately with
67 // each bit tracking the initialization of the corresponding slice.
68 void MarkSliceInitialized(size_t slice) const;
69
70 bool IsSliceInitialized(size_t slice) const;
71
72 private:
73 ReactorGLES::Ref reactor_;
74 const Type type_;
75 HandleGLES handle_;
76 mutable std::bitset<6> slices_initialized_ = 0;
77 const bool is_wrapped_;
78 const std::optional<GLuint> wrapped_fbo_;
79 bool is_valid_ = false;
80
81 TextureGLES(std::shared_ptr<ReactorGLES> reactor,
82 TextureDescriptor desc,
83 bool is_wrapped,
84 std::optional<GLuint> fbo);
85
86 // |Texture|
87 void SetLabel(std::string_view label) override;
88
89 // |Texture|
90 bool OnSetContents(const uint8_t* contents,
91 size_t length,
92 size_t slice) override;
93
94 // |Texture|
95 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
96 size_t slice) override;
97
98 // |Texture|
99 bool IsValid() const override;
100
101 // |Texture|
102 ISize GetSize() const override;
103
104 // |Texture|
105 Scalar GetYCoordScale() const override;
106
107 void InitializeContentsIfNecessary() const;
108
109 TextureGLES(const TextureGLES&) = delete;
110
111 TextureGLES& operator=(const TextureGLES&) = delete;
112 };
113
114 } // namespace impeller
115
116 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_TEXTURE_GLES_H_
impeller::TextureGLES::Type
Type
Definition: texture_gles.h:20
impeller::TextureGLES::Type::kTextureMultisampled
@ kTextureMultisampled
impeller::TextureGLES::GetFBO
std::optional< GLuint > GetFBO() const
Definition: texture_gles.h:63
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TextureGLES::GenerateMipmap
bool GenerateMipmap()
Definition: texture_gles.cc:464
impeller::TextureGLES::AttachmentType::kDepth
@ kDepth
impeller::TextureGLES::MarkSliceInitialized
void MarkSliceInitialized(size_t slice) const
Definition: texture_gles.cc:456
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:424
impeller::TextureGLES::Type::kRenderBufferMultisampled
@ kRenderBufferMultisampled
impeller::TextureGLES::AttachmentType::kColor0
@ kColor0
impeller::TextureGLES::IsSliceInitialized
bool IsSliceInitialized(size_t slice) const
Definition: texture_gles.cc:460
impeller::Texture
Definition: texture.h:17
impeller::TextureGLES::IsWrapped
bool IsWrapped() const
Definition: texture_gles.h:61
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:150
backend_cast.h
impeller::HandleGLES
Definition: handle_gles.h:31
impeller::TextureGLES::AttachmentType::kStencil
@ kStencil
impeller::TextureGLES::GetType
Type GetType() const
Definition: texture_gles.cc:498
reactor_gles.h
impeller::TextureGLES::~TextureGLES
~TextureGLES() override
Definition: texture_gles.cc:186
handle_gles.h
impeller::TextureGLES::AttachmentType
AttachmentType
Definition: texture_gles.h:50
impeller::BackendCast
Definition: backend_cast.h:11
texture.h
impeller::TextureGLES::IsWrapped::kWrapped
@ kWrapped
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::IsWrapped
IsWrapped
Definition: texture_gles.h:27
impeller::TextureGLES
Definition: texture_gles.h:17
impeller::TextureGLES::Bind
bool Bind() const
Definition: texture_gles.cc:431
impeller::TextureGLES::Type::kTexture
@ kTexture
impeller
Definition: aiks_blend_unittests.cc:18
impeller::TextureGLES::SetAsFramebufferAttachment
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
Definition: texture_gles.cc:513