Ocean
Loading...
Searching...
No Matches
GLESMediaTexture2D.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_MEDIA_TEXTURE_2D_H
9#define META_OCEAN_RENDERING_GLES_MEDIA_TEXTURE_2D_H
10
13
15
16namespace Ocean
17{
18
19namespace Rendering
20{
21
22namespace GLESceneGraph
23{
24
25/**
26 * This class wraps a GLESceneGraph media texture object.
27 * @ingroup renderinggles
28 */
29class OCEAN_RENDERING_GLES_EXPORT GLESMediaTexture2D final :
30 virtual public GLESTexture2D,
31 virtual public MediaTexture2D
32{
33 friend class GLESFactory;
34
35 public:
36
37 /**
38 * Returns the name of the texture e.g., in a shader.
39 * @see Texture::textureName().
40 */
41 std::string textureName() const override;
42
43 /**
44 * Sets the name of the texture e.g., in a shader.
45 * @see Texture::setTextureName().
46 */
47 bool setTextureName(const std::string& name) override;
48
49 /**
50 * Returns the texture id of the primary texture.
51 * @return The id of the primary texture, 0 if invalid
52 */
53 inline GLuint primaryTextureId() const;
54
55 /**
56 * Returns the texture id of the secondary texture.
57 * @return The id of the primary texture, 0 if invalid
58 */
59 inline GLuint secondaryTextureId() const;
60
61 /**
62 * Binds this texture.
63 * @see GLESTexture::bindTexture().
64 */
65 unsigned int bindTexture(GLESShaderProgram& shaderProgram, const unsigned int id) override;
66
67 /**
68 * Returns whether the texture internally holds valid data.
69 * @see Texture::isValid().
70 */
71 bool isValid() const override;
72
73 /**
74 * Returns descriptive information about the object as string.
75 * @see Object::descriptiveInformation().
76 */
77 std::string descriptiveInformation() const override;
78
79 protected:
80
81 /**
82 * Creates a new GLESceneGraph texture 2D object.
83 */
85
86 /**
87 * Destructs a GLESceneGraph texture 2D object.
88 */
90
91 /**
92 * Updates the mipmap for this texture.
93 * @see GLESTexture::createMipmap().
94 */
95 void createMipmap() override;
96
97 /**
98 * Creates a new GLESceneGraph texture object.
99 * @param frameType Frame type to create the new texture object for
100 * @return True, if succeeded
101 */
102 bool defineTextureObject(const FrameType& frameType);
103
104 /**
105 * Creates a primary GLESceneGraph texture object.
106 * @param frameType Frame type to create the new texture object for
107 * @return True, if succeeded
108 */
109 bool definePrimaryTextureObject(const FrameType& frameType);
110
111 /**
112 * Creates a secondary GLESceneGraph texture object.
113 * @param frameType Frame type to create the new texture object for
114 * @return True, if succeeded
115 */
117
118 /**
119 * Update function called by the framebuffer.
120 * @see DynamicObject::onDynamicUpdate().
121 */
122 void onDynamicUpdate(const ViewRef& view, const Timestamp timestamp) override;
123
124 /**
125 * Returns whether a second texture is necessary for a given frame type.
126 * @param frameType The frame type for which the check will be done, must be valid
127 * @return True, if so; False, if the frame type can be handled with just one texture
128 */
129 static bool needsSecondaryTextureObjects(const FrameType& frameType);
130
131 /**
132 * Returns the frame type of the internal frame for which a GL texture format exists.
133 * @param frameType The external (given) frame type for which the internal frame type will be determined, must be valid
134 * @param internalFrameType The resulting internal frame type
135 * @return True, if succeeded
136 */
137 static bool determineInternalFrameType(const FrameType& frameType, FrameType& internalFrameType);
138
139 /**
140 * Determines the properties of the primary texture for a given frame type.
141 * @param frameType The frame type for which the properties will be determined, must be valid
142 * @param width The resulting width of the primary texture in pixel, with range [1, infinity)
143 * @param height The resulting height of the primary texture in pixel, with range [1, infinity)
144 * @param format The resulting GL format of the primary texture
145 * @param type The resulting GL type of the primary texture
146 * @return True, if succeeded
147 */
148 static bool determinePrimaryTextureProperties(const FrameType& frameType, unsigned int& width, unsigned int& height, GLenum& format, GLenum& type);
149
150 /**
151 * Determines the properties of the secondary texture for a given frame type.
152 * @param frameType The frame type for which the properties will be determined, must be valid
153 * @param width The resulting width of the secondary texture in pixel, with range [1, infinity)
154 * @param height The resulting height of the secondary texture in pixel, with range [1, infinity)
155 * @param format The resulting GL format of the secondary texture
156 * @param type The resulting GL type of the secondary texture
157 * @return True, if succeeded
158 */
159 static bool determineSecondaryTextureProperties(const FrameType& frameType, unsigned int& width, unsigned int& height, GLenum& format, GLenum& type);
160
161 /**
162 * Returns the name of the primary texture.
163 * The input must have the format '<PRIMARY>,<SECONDARY>'.
164 * @param names The names of all textures, must be valid
165 * @param name The resulting name of the primary texture
166 * @return True, if succeeded
167 */
168 static bool primaryTextureName(const std::string& names, std::string& name);
169
170 /**
171 * Returns the name of the secondary texture.
172 * The input must have the format '<PRIMARY>,<SECONDARY>'.
173 * @param names The names of all textures, must be valid
174 * @param name The resulting name of the secondary texture
175 * @return True, if succeeded
176 */
177 static bool secondaryTextureName(const std::string& names, std::string& name);
178
179 protected:
180
181 /// The recent timestamp of the rendering engine.
183
184 /// The OpenGL ES texture id.
185 GLuint primaryTextureId_ = 0u;
186
187 /// Additional OpenGL ES texture id.
188 GLuint secondaryTextureId_ = 0u;
189
190 /// Optional temp conversion frame.
192
193 /// The name of the texture in the shader.
194 std::string textureName_ = std::string("primaryTexture,secondaryTexture");
195};
196
198{
199 return primaryTextureId_;
200}
201
203{
204 return secondaryTextureId_;
205}
206
207}
208
209}
210
211}
212
213#endif // META_OCEAN_RENDERING_GLES_MEDIA_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 class factory for all GLESceneGraph objects.
Definition GLESFactory.h:30
This class wraps a GLESceneGraph media texture object.
Definition GLESMediaTexture2D.h:32
std::string textureName() const override
Returns the name of the texture e.g., in a shader.
bool setTextureName(const std::string &name) override
Sets the name of the texture e.g., in a shader.
bool defineSecondaryTextureObject(const FrameType &frameType)
Creates a secondary GLESceneGraph texture object.
GLuint primaryTextureId() const
Returns the texture id of the primary texture.
Definition GLESMediaTexture2D.h:197
static bool determineInternalFrameType(const FrameType &frameType, FrameType &internalFrameType)
Returns the frame type of the internal frame for which a GL texture format exists.
void createMipmap() override
Updates the mipmap for this texture.
void onDynamicUpdate(const ViewRef &view, const Timestamp timestamp) override
Update function called by the framebuffer.
bool isValid() const override
Returns whether the texture internally holds valid data.
bool defineTextureObject(const FrameType &frameType)
Creates a new GLESceneGraph texture object.
GLuint primaryTextureId_
The OpenGL ES texture id.
Definition GLESMediaTexture2D.h:185
unsigned int bindTexture(GLESShaderProgram &shaderProgram, const unsigned int id) override
Binds this texture.
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 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.
GLESMediaTexture2D()
Creates a new GLESceneGraph texture 2D object.
bool definePrimaryTextureObject(const FrameType &frameType)
Creates a primary GLESceneGraph texture object.
static bool primaryTextureName(const std::string &names, std::string &name)
Returns the name of the primary texture.
Timestamp renderTimestamp_
The recent timestamp of the rendering engine.
Definition GLESMediaTexture2D.h:182
~GLESMediaTexture2D() override
Destructs a GLESceneGraph texture 2D object.
std::string descriptiveInformation() const override
Returns descriptive information about the object as string.
Frame conversionFrame_
Optional temp conversion frame.
Definition GLESMediaTexture2D.h:191
static bool secondaryTextureName(const std::string &names, std::string &name)
Returns the name of the secondary texture.
GLuint secondaryTextureId_
Additional OpenGL ES texture id.
Definition GLESMediaTexture2D.h:188
static bool needsSecondaryTextureObjects(const FrameType &frameType)
Returns whether a second texture is necessary for a given frame type.
GLuint secondaryTextureId() const
Returns the texture id of the secondary texture.
Definition GLESMediaTexture2D.h:202
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
This class is the base class for all 2D textures receiving their image content from Media objects.
Definition MediaTexture2D.h:41
This class implements a timestamp.
Definition Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition Accessor.h:15