Ocean
rendering/Texture.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_TEXTURE_H
9 #define META_OCEAN_RENDERING_TEXTURE_H
10 
12 #include "ocean/rendering/Object.h"
14 
16 
17 namespace Ocean
18 {
19 
20 namespace Rendering
21 {
22 
23 // Forward declaration
24 class Texture;
25 
26 /**
27  * Definition of a smart object reference holding a texture.
28  * @see SmartObjectRef, Texture.
29  * @ingroup rendering
30  */
32 
33 /**
34  * This class is the base class for all textures.
35  * @ingroup rendering
36  */
37 class OCEAN_RENDERING_EXPORT Texture : virtual public Object
38 {
39  public:
40 
41  /**
42  * Definition of possible texture environment modes.
43  */
45  {
46  /// Invalid texture environment mode.
53  MODE_SUBTRACT
54  };
55 
56  /**
57  * Definition of possible minification filter modes.<br>
58  * Minification: One screen pixel corresponds to a large area of texels.
59  */
61  {
62  /// Invalid minification filter mode.
64  /// Linear interpolation between neighboring texel only in one texture layer.
66  /// Chooses the nearest pixel only in one texture layer.
68  /// Chooses the nearest pixel in the nearest mipmap texture layer.
70  /// Linear interpolation between neighboring texel in the nearest mipmap texture layer.
72  /// Chooses the nearest pixel and interpolates between neighboring mipmap texture layers.
74  /// Linear interpolation between neighboring texel between neighboring mipmap texture layers.
75  MIN_MODE_LINEAR_MIPMAP_LINEAR
76  };
77 
78  /**
79  * Definition of possible magnification filter modes.<br>
80  * Magnification: A large screen area corresponds to a single texel.
81  */
83  {
84  /// Invalid magnification filter mode.
86  /// Linear interpolation between neighboring texel.
88  /// Chooses the nearest pixel.
89  MAG_MODE_NEAREST
90  };
91 
92  /**
93  * Definition of different texture wrapping types.
94  */
95  enum WrapType
96  {
97  /// Invalid wrap mode.
99  /// The texture will be clamped at the border.
101  /// The texture will be repeated at the border.
102  WRAP_REPEAT
103  };
104 
105  public:
106 
107  /**
108  * Returns the name of the texture e.g., in a shader.
109  * @return The texture's name
110  */
111  virtual std::string textureName() const = 0;
112 
113  /**
114  * Returns the texture transformation matrix.
115  * @return Matrix transforming the corresponding texture
116  * @exception NotSupportedException Is thrown if this function is not supported
117  */
119 
120  /**
121  * Returns the environment mode for this texture.
122  * @return Environment mode
123  * @exception NotSupportedException Is thrown if this function is not supported
124  */
126 
127  /**
128  * Returns the minification filter mode for this texture.
129  * @return Minification mode
130  * @exception NotSupportedException Is thrown if this function is not supported
131  */
133 
134  /**
135  * Returns the magnification filter mode for this texture.
136  * @return Magnification mode
137  * @exception NotSupportedException Is thrown if this function is not supported
138  */
140 
141  /**
142  * Returns whether mipmaps are used.
143  * @return True, if so
144  */
145  virtual bool usingMipmaps() const;
146 
147  /**
148  * Returns whether the internal texture size has been extended to power-of-two dimensions to hand the reduced graphic power of the system.
149  * Systems not providing the necessary graphic extensions to support non-power-of-two textures will use power-of-two textures automatically.
150  * Therefore, the texture transformation cannot be used on systems with reduced graphic power.
151  * @return True, if so
152  * @see imageTextureRatio().
153  */
154  virtual bool adjustedToPowerOfTwo() const;
155 
156  /**
157  * Sets the name of the texture e.g., in a shader.
158  * @param name The texture's name
159  * @return True, if succeeded
160  */
161  virtual bool setTextureName(const std::string& name) = 0;
162 
163  /**
164  * Sets the texture transformation matrix.
165  * @param transformation Matrix transforming the corresponding texture
166  * @exception NotSupportedException Is thrown if this function is not supported
167  */
168  virtual void setTransformation(const HomogenousMatrix4& transformation);
169 
170  /**
171  * Sets the environment mode for this texture.
172  * @param mode New environment mode to set
173  * @exception NotSupportedException Is thrown if this function is not supported
174  */
175  virtual void setEnvironmentMode(const EnvironmentMode mode);
176 
177  /**
178  * Sets the minification filter mode for this texture.
179  * @param mode New minification filter mode to set
180  * @exception NotSupportedException Is thrown if this function is not supported
181  */
182  virtual void setMinificationFilterMode(const MinFilterMode mode);
183 
184  /**
185  * Sets the magnification filter mode for this texture.
186  * @param mode New magnification filter mode to set
187  * @exception NotSupportedException Is thrown if this function is not supported
188  */
189  virtual void setMagnificationFilterMode(const MagFilterMode mode);
190 
191  /**
192  * Specifies whether mipmaps will be used.
193  * @param flag True, to use mipmaps; False, to avoid mipmaps
194  */
195  virtual void setUseMipmaps(const bool flag);
196 
197  /**
198  * Returns whether the texture internally holds valid data.
199  * @return True, if so
200  */
201  virtual bool isValid() const;
202 
203  /**
204  * Returns the type of this object.
205  * @see Object::type().
206  */
207  ObjectType type() const override;
208 
209  protected:
210 
211  /**
212  * Creates a new texture object.
213  */
215 
216  /**
217  * Destructs a texture object.
218  */
219  ~Texture() override;
220 };
221 
222 }
223 
224 }
225 
226 #endif // META_OCEAN_RENDERING_TEXTURE_H
This class is the base class for all rendering objects.
Definition: Object.h:54
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 textures.
Definition: rendering/Texture.h:38
virtual std::string textureName() const =0
Returns the name of the texture e.g., in a shader.
~Texture() override
Destructs a texture object.
MagFilterMode
Definition of possible magnification filter modes.
Definition: rendering/Texture.h:83
@ MAG_MODE_LINEAR
Linear interpolation between neighboring texel.
Definition: rendering/Texture.h:87
@ MAG_MODE_INVALID
Invalid magnification filter mode.
Definition: rendering/Texture.h:85
virtual EnvironmentMode environmentMode() const
Returns the environment mode for this texture.
WrapType
Definition of different texture wrapping types.
Definition: rendering/Texture.h:96
@ WRAP_INVALID
Invalid wrap mode.
Definition: rendering/Texture.h:98
@ WRAP_CLAMP
The texture will be clamped at the border.
Definition: rendering/Texture.h:100
virtual void setTransformation(const HomogenousMatrix4 &transformation)
Sets the texture transformation matrix.
virtual bool usingMipmaps() const
Returns whether mipmaps are used.
virtual bool setTextureName(const std::string &name)=0
Sets the name of the texture e.g., in a shader.
EnvironmentMode
Definition of possible texture environment modes.
Definition: rendering/Texture.h:45
@ MODE_REPLACE
Definition: rendering/Texture.h:52
@ MODE_ADD
Definition: rendering/Texture.h:48
@ MODE_MODULATE
Definition: rendering/Texture.h:51
@ MODE_ADD_SIGNED
Definition: rendering/Texture.h:49
@ MODE_BLEND
Definition: rendering/Texture.h:50
@ MODE_INVALID
Invalid texture environment mode.
Definition: rendering/Texture.h:47
MinFilterMode
Definition of possible minification filter modes.
Definition: rendering/Texture.h:61
@ MIN_MODE_LINEAR
Linear interpolation between neighboring texel only in one texture layer.
Definition: rendering/Texture.h:65
@ MIN_MODE_NEAREST
Chooses the nearest pixel only in one texture layer.
Definition: rendering/Texture.h:67
@ MIN_MODE_LINEAR_MIPMAP_NEAREST
Linear interpolation between neighboring texel in the nearest mipmap texture layer.
Definition: rendering/Texture.h:71
@ MIN_MODE_INVALID
Invalid minification filter mode.
Definition: rendering/Texture.h:63
@ MIN_MODE_NEAREST_MIPMAP_LINEAR
Chooses the nearest pixel and interpolates between neighboring mipmap texture layers.
Definition: rendering/Texture.h:73
@ MIN_MODE_NEAREST_MIPMAP_NEAREST
Chooses the nearest pixel in the nearest mipmap texture layer.
Definition: rendering/Texture.h:69
virtual void setEnvironmentMode(const EnvironmentMode mode)
Sets the environment mode for this texture.
virtual void setMinificationFilterMode(const MinFilterMode mode)
Sets the minification filter mode for this texture.
ObjectType type() const override
Returns the type of this object.
virtual MinFilterMode minificationFilterMode() const
Returns the minification filter mode for this texture.
virtual MagFilterMode magnificationFilterMode() const
Returns the magnification filter mode for this texture.
virtual bool adjustedToPowerOfTwo() const
Returns whether the internal texture size has been extended to power-of-two dimensions to hand the re...
virtual HomogenousMatrix4 transformation() const
Returns the texture transformation matrix.
virtual bool isValid() const
Returns whether the texture internally holds valid data.
virtual void setUseMipmaps(const bool flag)
Specifies whether mipmaps will be used.
Texture()
Creates a new texture object.
virtual void setMagnificationFilterMode(const MagFilterMode mode)
Sets the magnification filter mode for this texture.
SmartObjectRef< Texture > TextureRef
Definition of a smart object reference holding a texture.
Definition: rendering/Texture.h:24
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15