Ocean
Loading...
Searching...
No Matches
FrameTexture2D.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_FRAME_TEXTURE_2D_H
9#define META_OCEAN_RENDERING_FRAME_TEXTURE_2D_H
10
13
15
16namespace Ocean
17{
18
19namespace Rendering
20{
21
22// Forward declaration
23class FrameTexture2D;
24
25/**
26 * Definition of a smart object reference holding a 2D frame texture.
27 * @see SmartObjectRef, Texture2D.
28 * @ingroup rendering
29 */
31
32/**
33 * This class is the base class for all 2D textures receiving their image content from a frame or a buffer.
34 * @see MediaTexture2D.
35 * @ingroup rendering
36 */
37class OCEAN_RENDERING_EXPORT FrameTexture2D : virtual public Texture2D
38{
39 public:
40
41 /**
42 * Definition of individual compressed texture formats.
43 */
44 enum CompressedFormat : uint32_t
45 {
46 /// Invalid format.
47 CF_INVALID = 0u,
48 /// Compressed texture with format RGBA ASTC 4x4.
50 /// Compressed texture with format RGBA ASTC 6x6.
52 /// Compressed texture with format RGBA ASTC 8x8.
54 /// Compressed texture with format sRGBA ASTC 4x4.
56 /// Compressed texture with format sRGBA ASTC 6x6.
58 /// Compressed texture with format sRGBA ASTC 8x8.
59 CF_SRGBA_ASTC_8X8
60 };
61
62 /**
63 * Definition of a vector holding bytes.
64 */
65 typedef std::vector<uint8_t> Buffer;
66
67 /**
68 * This class implements a container for a compressed texture.
69 */
71 {
72 public:
73
74 /**
75 * Default constructor creating an invalid object.
76 */
77 CompressedFrame() = default;
78
79 /**
80 * Creates a new object based on valid compressed texture information.
81 * @param internalFrameType The texture's internal (uncompressed) frame type, must be valid
82 * @param buffer The memory containing the compressed texture, must not be empty
83 * @param compressedFormat The format of the compressed texture, must be valid
84 * @param mipmapLevels The number of mipmap levels the given buffer contains as consecutive memory blocks, with range [1, infinity)
85 */
86 inline CompressedFrame(const FrameType& internalFrameType, Buffer&& buffer, const CompressedFormat compressedFormat, const unsigned int mipmapLevels);
87
88 /**
89 * The texture's internal (uncompressed) frame type.
90 * @return The internal frame type
91 */
92 inline const FrameType& internalFrameType() const;
93
94 /**
95 * Returns the memory containing the compressed texture.
96 * @return The compressed texture memory
97 */
98 inline const Buffer& buffer() const;
99
100 /**
101 * Returns the format of the compressed texture.
102 * @return The texture's compressed format
103 */
104 inline CompressedFormat compressedFormat() const;
105
106 /**
107 * Returns the number of mipmap levels the data of the compressed texture contains.
108 * @return The texture's mipmap levels
109 */
110 inline unsigned int mipmapLevels() const;
111
112 /**
113 * Explicitly releases the data of this object.
114 */
115 inline void release();
116
117 /**
118 * Returns whether this object contains valid information for a compressed texture.
119 * @return True, if so
120 */
121 inline bool isValid() const;
122
123 protected:
124
125 /// The texture's internal (uncompressed) frame type.
127
128 /// The memory containing the compressed texture.
130
131 /// The format of the compressed texture.
132 CompressedFormat compressedFormat_ = CF_INVALID;
133
134 /// The number of mipmap levels the data of the compressed texture contains.
135 unsigned int mipmapLevels_ = 0u;
136 };
137
138 public:
139
140 /**
141 * Sets or updates the texture with a given frame.
142 * @param frame The frame containing the new texture information, must be valid
143 * @return True, if succeeded
144 */
145 virtual bool setTexture(Frame&& frame) = 0;
146
147 /**
148 * Sets or updates the texture with a given compressed frame.
149 * @param compressedFrame The compressed frame containing the new texture information, must be valid
150 * @return True, if succeeded
151 */
152 virtual bool setTexture(CompressedFrame&& compressedFrame) = 0;
153
154 /**
155 * Returns the type of this object.
156 * @see Object::type().
157 */
158 ObjectType type() const override;
159
160 protected:
161
162 /**
163 * Creates a new 2D frame texture object.
164 */
166
167 /**
168 * Destructs a 2D frame texture object.
169 */
170 ~FrameTexture2D() override;
171};
172
173inline FrameTexture2D::CompressedFrame::CompressedFrame(const FrameType& internalFrameType, Buffer&& buffer, const CompressedFormat compressedFormat, const unsigned int mipmapLevels) :
174 internalFrameType_(internalFrameType),
175 buffer_(std::move(buffer)),
176 compressedFormat_(compressedFormat),
177 mipmapLevels_(mipmapLevels)
178{
179 ocean_assert(isValid());
180}
181
183{
184 return internalFrameType_;
185}
186
188{
189 return buffer_;
190}
191
193{
194 return compressedFormat_;
195}
196
198{
199 return mipmapLevels_;
200}
201
203{
204 internalFrameType_ = FrameType();
205 buffer_.clear();
206 compressedFormat_ = CF_INVALID;
207 mipmapLevels_ = 0u;
208}
209
211{
212 return internalFrameType_.isValid() && !buffer_.empty() && compressedFormat_ != CF_INVALID && mipmapLevels_ >= 1u;
213}
214
215}
216
217}
218
219#endif // META_OCEAN_RENDERING_FRAME_TEXTURE_2D_H
This class implements Ocean's image class.
Definition Frame.h:1808
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
This class implements a container for a compressed texture.
Definition FrameTexture2D.h:71
const FrameType & internalFrameType() const
The texture's internal (uncompressed) frame type.
Definition FrameTexture2D.h:182
void release()
Explicitly releases the data of this object.
Definition FrameTexture2D.h:202
unsigned int mipmapLevels() const
Returns the number of mipmap levels the data of the compressed texture contains.
Definition FrameTexture2D.h:197
CompressedFrame()=default
Default constructor creating an invalid object.
CompressedFormat compressedFormat() const
Returns the format of the compressed texture.
Definition FrameTexture2D.h:192
bool isValid() const
Returns whether this object contains valid information for a compressed texture.
Definition FrameTexture2D.h:210
const Buffer & buffer() const
Returns the memory containing the compressed texture.
Definition FrameTexture2D.h:187
FrameType internalFrameType_
The texture's internal (uncompressed) frame type.
Definition FrameTexture2D.h:126
Buffer buffer_
The memory containing the compressed texture.
Definition FrameTexture2D.h:129
This class is the base class for all 2D textures receiving their image content from a frame or a buff...
Definition FrameTexture2D.h:38
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition FrameTexture2D.h:65
~FrameTexture2D() override
Destructs a 2D frame texture object.
CompressedFormat
Definition of individual compressed texture formats.
Definition FrameTexture2D.h:45
@ CF_RGBA_ASTC_6X6
Compressed texture with format RGBA ASTC 6x6.
Definition FrameTexture2D.h:51
@ CF_SRGBA_ASTC_6X6
Compressed texture with format sRGBA ASTC 6x6.
Definition FrameTexture2D.h:57
@ CF_RGBA_ASTC_4X4
Compressed texture with format RGBA ASTC 4x4.
Definition FrameTexture2D.h:49
@ CF_SRGBA_ASTC_4X4
Compressed texture with format sRGBA ASTC 4x4.
Definition FrameTexture2D.h:55
@ CF_RGBA_ASTC_8X8
Compressed texture with format RGBA ASTC 8x8.
Definition FrameTexture2D.h:53
@ CF_INVALID
Invalid format.
Definition FrameTexture2D.h:47
virtual bool setTexture(Frame &&frame)=0
Sets or updates the texture with a given frame.
FrameTexture2D()
Creates a new 2D frame texture object.
ObjectType type() const override
Returns the type of this object.
virtual bool setTexture(CompressedFrame &&compressedFrame)=0
Sets or updates the texture with a given compressed frame.
ObjectType
Definition of different object type.
Definition Object.h:63
This class implements a smart rendering object reference.
Definition rendering/ObjectRef.h:34
This class is the base class for all 2D textures.
Definition Texture2D.h:38
SmartObjectRef< FrameTexture2D > FrameTexture2DRef
Definition of a smart object reference holding a 2D frame texture.
Definition FrameTexture2D.h:30
The namespace covering the entire Ocean framework.
Definition Accessor.h:15