Ocean
Loading...
Searching...
No Matches
GLESTexture2D.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_GLES_TEXTURE_2D_H
9#define META_OCEAN_RENDERING_GLES_TEXTURE_2D_H
10
13
16
17namespace Ocean
18{
19
20namespace Rendering
21{
22
23namespace GLESceneGraph
24{
25
26/**
27 * This class wraps a GLESceneGraph texture object.
28 * @ingroup renderinggles
29 */
30class OCEAN_RENDERING_GLES_EXPORT GLESTexture2D :
31 virtual public GLESTexture,
32 virtual public Texture2D,
33 virtual protected DynamicObject
34{
35 friend class GLESFactory;
36
37 public:
38
39 /**
40 * Returns the texture wrap type in s direction.
41 * @see Texture2D::wrapTypeS().
42 */
43 WrapType wrapTypeS() const override;
44
45 /**
46 * Returns the texture wrap type in t direction.
47 * @see Texture2D::wrapTypeT().
48 */
49 WrapType wrapTypeT() const override;
50
51 /**
52 * Sets the texture wrap type in s direction.
53 * @see Texture2D::setWrapTypeS().
54 */
55 bool setWrapTypeS(const WrapType type) override;
56
57 /**
58 * Sets the texture wrap type in t direction.
59 * @see Texture2D::setWrapTypeT().
60 */
61 bool setWrapTypeT(const WrapType type) override;
62
63 /**
64 * Returns the name of the texture e.g., in a shader.
65 * @return The name of the texture
66 */
67 std::string textureName() const override;
68
69 /**
70 * Sets the name of the texture e.g., in a shader.
71 * @param name The name to set
72 * @return True, if succeeded
73 */
74 bool setTextureName(const std::string& name) override;
75
76 /**
77 * Returns the texture id of the primary texture.
78 * @return The id of the primary texture, 0 if invalid
79 */
80 inline GLuint primaryTextureId() const;
81
82 /**
83 * Returns the texture id of the secondary texture.
84 * @return The id of the secondary texture, 0 if invalid
85 */
86 inline GLuint secondaryTextureId() const;
87
88 /**
89 * Binds this texture.
90 * @see GLESTexture::bindTexture().
91 */
92 unsigned int bindTexture(GLESShaderProgram& shaderProgram, const unsigned int id) override;
93
94 protected:
95
96 /**
97 * Creates a new GLESceneGraph texture 2D object.
98 */
100
101 /**
102 * Destructs a GLESceneGraph texture 2D object.
103 */
104 ~GLESTexture2D() override;
105
106 /**
107 * Updates the mipmap for this texture.
108 */
109 void createMipmap() override;
110
111 /**
112 * Creates a new GLESceneGraph texture object.
113 * @param frameType Frame type to create the new texture object for
114 * @return True, if succeeded
115 */
116 bool defineTextureObject(const FrameType& frameType);
117
118 /**
119 * Creates a primary GLESceneGraph texture object.
120 * @param frameType Frame type to create the new texture object for
121 * @return True, if succeeded
122 */
123 bool definePrimaryTextureObject(const FrameType& frameType);
124
125 /**
126 * Creates a secondary GLESceneGraph texture object.
127 * @param frameType Frame type to create the new texture object for
128 * @return True, if succeeded
129 */
131
132 /**
133 * Determines the alignment for a plane.
134 * @param planeStrideBytes The stride of the plane in bytes, with range [1, infinity)
135 * @param rowLength The resulting row length, with range [1, infinity)
136 * @param byteAlignment The resulting byte alignment, either 1, 2, or 4
137 * @return True, if succeeded
138 */
139 static bool determineAlignment(const unsigned int planeStrideBytes, unsigned int& rowLength, unsigned int& byteAlignment);
140
141 /**
142 * Returns whether a second texture is necessary for a given frame type.
143 * @param frameType The frame type for which the check will be done, must be valid
144 * @return True, if so; False, if the frame type can be handled with just one texture
145 */
146 static bool needsSecondaryTextureObjects(const FrameType& frameType);
147
148 /**
149 * Returns the frame type of the internal frame for which a GL texture format exists.
150 * @param frameType The external (given) frame type for which the internal frame type will be determined, must be valid
151 * @param internalFrameType The resulting internal frame type
152 * @return True, if succeeded
153 */
154 static bool determineInternalFrameType(const FrameType& frameType, FrameType& internalFrameType);
155
156 /**
157 * Determines the properties of the primary texture for a given frame type.
158 * @param frameType The frame type for which the properties will be determined, must be valid
159 * @param width The resulting width of the primary texture in pixel, with range [1, infinity)
160 * @param height The resulting height of the primary texture in pixel, with range [1, infinity)
161 * @param format The resulting GL format of the primary texture
162 * @param type The resulting GL type of the primary texture
163 * @return True, if succeeded
164 */
165 static bool determinePrimaryTextureProperties(const FrameType& frameType, unsigned int& width, unsigned int& height, GLenum& format, GLenum& type);
166
167 /**
168 * Determines the properties of the secondary texture for a given frame type.
169 * @param frameType The frame type for which the properties will be determined, must be valid
170 * @param width The resulting width of the secondary texture in pixel, with range [1, infinity)
171 * @param height The resulting height of the secondary texture in pixel, with range [1, infinity)
172 * @param format The resulting GL format of the secondary texture
173 * @param type The resulting GL type of the secondary texture
174 * @return True, if succeeded
175 */
176 static bool determineSecondaryTextureProperties(const FrameType& frameType, unsigned int& width, unsigned int& height, GLenum& format, GLenum& type);
177
178 /**
179 * Returns the name of the primary texture.
180 * The input must have the format '<PRIMARY>,<SECONDARY>'.
181 * @param names The names of all textures, must be valid
182 * @param name The resulting name of the primary texture
183 * @return True, if succeeded
184 */
185 static bool primaryTextureName(const std::string& names, std::string& name);
186
187 /**
188 * Returns the name of the secondary texture.
189 * The input must have the format '<PRIMARY>,<SECONDARY>'.
190 * @param names The names of all textures, must be valid
191 * @param name The resulting name of the secondary texture
192 * @return True, if succeeded
193 */
194 static bool secondaryTextureName(const std::string& names, std::string& name);
195
196 protected:
197
198 /**
199 * Updates the texture based on a given frame.
200 * @param frame The frame to be used to update the texture, must be valid
201 * @return True, if succeeded
202 */
203 bool updateTexture(const Frame& frame);
204
205 protected:
206
207 /// The texture wrap s type.
208 WrapType wrapTypeS_ = WRAP_CLAMP;
209
210 /// The texture wrap t type.
211 WrapType wrapTypeT_ = WRAP_CLAMP;
212
213 /// The OpenGL ES primary texture id.
214 GLuint primaryTextureId_ = 0u;
215
216 /// The OpenGL ES secondary texture id.
217 GLuint secondaryTextureId_ = 0u;
218
219 /// The name of the texture in the shader.
220 std::string textureName_ = std::string("primaryTexture,secondaryTexture");
221
222 /// Optional temp conversion frame.
224};
225
227{
228 return primaryTextureId_;
229}
230
232{
233 return secondaryTextureId_;
234}
235
236}
237
238}
239
240}
241
242#endif // META_OCEAN_RENDERING_GLES_TEXTURE_2D_H
This class implements Ocean's image class.
Definition Frame.h:1879
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
This class is the base class for all dynamic scene graph objects.
Definition DynamicObject.h:40
This class implements a class factory for all GLESceneGraph objects.
Definition GLESFactory.h:30
This class implements a container for an OpenGL ES shader program.
Definition GLESShaderProgram.h:53
This class wraps a GLESceneGraph texture object.
Definition GLESTexture2D.h:34
unsigned int bindTexture(GLESShaderProgram &shaderProgram, const unsigned int id) override
Binds this texture.
static bool needsSecondaryTextureObjects(const FrameType &frameType)
Returns whether a second texture is necessary for a given frame type.
static bool determineAlignment(const unsigned int planeStrideBytes, unsigned int &rowLength, unsigned int &byteAlignment)
Determines the alignment for a plane.
std::string textureName() const override
Returns the name of the texture e.g., in a shader.
GLESTexture2D()
Creates a new GLESceneGraph texture 2D object.
void createMipmap() override
Updates the mipmap for this texture.
static bool determineSecondaryTextureProperties(const FrameType &frameType, unsigned int &width, unsigned int &height, GLenum &format, GLenum &type)
Determines the properties of the secondary texture for a given frame type.
GLuint primaryTextureId_
The OpenGL ES primary texture id.
Definition GLESTexture2D.h:214
bool setWrapTypeT(const WrapType type) override
Sets the texture wrap type in t direction.
static bool determinePrimaryTextureProperties(const FrameType &frameType, unsigned int &width, unsigned int &height, GLenum &format, GLenum &type)
Determines the properties of the primary texture for a given frame type.
static bool primaryTextureName(const std::string &names, std::string &name)
Returns the name of the primary texture.
bool definePrimaryTextureObject(const FrameType &frameType)
Creates a primary GLESceneGraph texture object.
Frame conversionFrame_
Optional temp conversion frame.
Definition GLESTexture2D.h:223
bool setTextureName(const std::string &name) override
Sets the name of the texture e.g., in a shader.
WrapType wrapTypeS() const override
Returns the texture wrap type in s direction.
GLuint secondaryTextureId_
The OpenGL ES secondary texture id.
Definition GLESTexture2D.h:217
bool updateTexture(const Frame &frame)
Updates the texture based on a given frame.
bool defineSecondaryTextureObject(const FrameType &frameType)
Creates a secondary GLESceneGraph texture object.
WrapType wrapTypeT() const override
Returns the texture wrap type in t direction.
static bool determineInternalFrameType(const FrameType &frameType, FrameType &internalFrameType)
Returns the frame type of the internal frame for which a GL texture format exists.
GLuint secondaryTextureId() const
Returns the texture id of the secondary texture.
Definition GLESTexture2D.h:231
bool setWrapTypeS(const WrapType type) override
Sets the texture wrap type in s direction.
GLuint primaryTextureId() const
Returns the texture id of the primary texture.
Definition GLESTexture2D.h:226
bool defineTextureObject(const FrameType &frameType)
Creates a new GLESceneGraph texture object.
~GLESTexture2D() override
Destructs a GLESceneGraph texture 2D object.
static bool secondaryTextureName(const std::string &names, std::string &name)
Returns the name of the secondary texture.
This class is the base class for all GLESceneGraph texture objects.
Definition GLESTexture.h:37
This class is the base class for all 2D textures.
Definition Texture2D.h:39
WrapType
Definition of different texture wrapping types.
Definition rendering/Texture.h:96
The namespace covering the entire Ocean framework.
Definition Accessor.h:15