Ocean
GLESFrameTexture2D.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_FRAME_TEXTURE_2D_H
9 #define META_OCEAN_RENDERING_GLES_FRAME_TEXTURE_2D_H
10 
13 
15 
16 namespace Ocean
17 {
18 
19 namespace Rendering
20 {
21 
22 namespace GLESceneGraph
23 {
24 
25 /**
26  * This class wraps a GLESceneGraph frame texture object.
27  * @ingroup renderinggles
28  */
29 class OCEAN_RENDERING_GLES_EXPORT GLESFrameTexture2D final :
30  virtual public GLESTexture2D,
31  virtual public FrameTexture2D
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  * Sets or updates the texture with a given frame.
51  * @see FrameTexture2D::setTexture().
52  */
53  bool setTexture(Frame&& frame) override;
54 
55  /**
56  * Sets or updates the texture with a given buffer.
57  * @see FrameTexture2D::setTexture().
58  */
59  bool setTexture(CompressedFrame&& compressedFrame) override;
60 
61  /**
62  * Returns the frame type of this 2D texture.
63  * @see Texture2D::frameType()
64  */
65  FrameType frameType() const override;
66 
67  /**
68  * Returns whether this texture contains at least one transparent pixel.
69  * @see Texture2D::hasTransparentPixel();
70  */
71  bool hasTransparentPixel() const override;
72 
73  /**
74  * Returns the texture id of the texture.
75  * @return The id of the texture, 0 if invalid
76  */
77  inline GLuint textureId() const;
78 
79  /**
80  * Binds this texture.
81  * @see GLESTexture::bindTexture().
82  */
83  unsigned int bindTexture(GLESShaderProgram& shaderProgram, const unsigned int id) override;
84 
85  /**
86  * Returns whether the texture internally holds valid data.
87  * @see Texture::isValid().
88  */
89  bool isValid() const override;
90 
91  protected:
92 
93  /**
94  * Creates a new GLESceneGraph texture 2D object.
95  */
97 
98  /**
99  * Destructs a GLESceneGraph texture 2D object.
100  */
102 
103  /**
104  * Updates the mipmap for this texture.
105  * @see GLESTexture::createMipmap().
106  */
107  void createMipmap() override;
108 
109  /**
110  * Update function called by the framebuffer.
111  * @see DynamicObject::onDynamicUpdate().
112  */
113  void onDynamicUpdate(const ViewRef& view, const Timestamp timestamp) override;
114 
115  /**
116  * Updates the texture.
117  */
119 
120  /**
121  * Determines the properties of the texture for a given frame type.
122  * @param frameType The frame type for which the properties will be determined, must be valid
123  * @param format The resulting GL format of the primary texture
124  * @param type The resulting GL type of the primary texture
125  * @return True, if succeeded; False, if the frame type is not supported
126  */
127  static bool determineTextureProperties(const FrameType& frameType, GLenum& format, GLenum& type);
128 
129  /**
130  * Determines the OpenGL format for a given compressed texture format.
131  * @param compressedFormat The texture format for which the OpenGL format will be determined, must be valid
132  * @param internalFormat The resulting OpenGL texture format
133  * @return True, if succeeded
134  */
135  static bool determineCompressedFormat(const CompressedFormat compressedFormat, GLenum& internalFormat);
136 
137  /**
138  * Returns the image size for a compressed texture.
139  * @param compressedFormat The texture format of the compressed texture, must be valid
140  * @param width The width of the texture in pixel, with range [1, infinity)
141  * @param height The height of the texture in pixel, with range [1, infinity)
142  * @param size The resulting size of the compressed texture, in bytes
143  * @return True, if succeeded
144  */
145  static bool compressedImageSize(const CompressedFormat compressedFormat, const unsigned int width, const unsigned int height, unsigned int& size);
146 
147  protected:
148 
149  /// The OpenGL ES texture id.
150  GLuint textureId_ = 0u;
151 
152  /// The texture's frame, if any.
154 
155  /// The texture's compressed frame, if any.
157 
158  /// True, if the texture needs to be updated.
159  bool updateNeeded_ = false;
160 
161  /// The name of the texture in the shader.
162  std::string textureName_ = std::string("primaryTexture");
163 };
164 
165 inline GLuint GLESFrameTexture2D::textureId() const
166 {
167  return textureId_;
168 }
169 
170 }
171 
172 }
173 
174 }
175 
176 #endif // META_OCEAN_RENDERING_GLES_FRAME_TEXTURE_2D_H
This class implements Ocean's image class.
Definition: Frame.h:1792
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
This class is the base class for all 2D textures receiving their image content from a frame or a buff...
Definition: FrameTexture2D.h:38
CompressedFormat
Definition of individual compressed texture formats.
Definition: FrameTexture2D.h:45
This class implements a class factory for all GLESceneGraph objects.
Definition: GLESFactory.h:30
This class wraps a GLESceneGraph frame texture object.
Definition: GLESFrameTexture2D.h:32
void onDynamicUpdate(const ViewRef &view, const Timestamp timestamp) override
Update function called by the framebuffer.
Frame frame_
The texture's frame, if any.
Definition: GLESFrameTexture2D.h:153
FrameType frameType() const override
Returns the frame type of this 2D texture.
void createMipmap() override
Updates the mipmap for this texture.
bool setTexture(CompressedFrame &&compressedFrame) override
Sets or updates the texture with a given buffer.
bool isValid() const override
Returns whether the texture internally holds valid data.
~GLESFrameTexture2D() override
Destructs a GLESceneGraph texture 2D object.
static bool determineTextureProperties(const FrameType &frameType, GLenum &format, GLenum &type)
Determines the properties of the texture for a given frame type.
static bool compressedImageSize(const CompressedFormat compressedFormat, const unsigned int width, const unsigned int height, unsigned int &size)
Returns the image size for a compressed texture.
unsigned int bindTexture(GLESShaderProgram &shaderProgram, const unsigned int id) override
Binds this texture.
bool hasTransparentPixel() const override
Returns whether this texture contains at least one transparent pixel.
bool setTexture(Frame &&frame) override
Sets or updates the texture with a given frame.
GLuint textureId() const
Returns the texture id of the texture.
Definition: GLESFrameTexture2D.h:165
static bool determineCompressedFormat(const CompressedFormat compressedFormat, GLenum &internalFormat)
Determines the OpenGL format for a given compressed texture format.
CompressedFrame compressedFrame_
The texture's compressed frame, if any.
Definition: GLESFrameTexture2D.h:156
bool setTextureName(const std::string &name) override
Sets the name of the texture e.g., in a shader.
GLuint textureId_
The OpenGL ES texture id.
Definition: GLESFrameTexture2D.h:150
GLESFrameTexture2D()
Creates a new GLESceneGraph texture 2D object.
std::string textureName() const override
Returns the name of the texture e.g., in a shader.
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 implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15