Ocean
Texture2D.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_2D_H
9 #define META_OCEAN_RENDERING_TEXTURE_2D_H
10 
13 
14 #include "ocean/base/Frame.h"
15 #include "ocean/base/Utilities.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Rendering
21 {
22 
23 // Forward declaration
24 class Texture2D;
25 
26 /**
27  * Definition of a smart object reference holding a 2D texture.
28  * @see SmartObjectRef, Texture2D.
29  * @ingroup rendering
30  */
32 
33 /**
34  * This class is the base class for all 2D textures.
35  * @ingroup rendering
36  */
37 class OCEAN_RENDERING_EXPORT Texture2D : virtual public Texture
38 {
39  public:
40 
41  /**
42  * Returns the ratio between original image dimension and actual texture dimension in horizontal and vertical dimensions.
43  * The returned value is calculated by: (image width / texture width, image height / texture height).<br>
44  * If the graphic system supports non-power-of-two texture the ratio will normaly be 1.0 for each dimension.
45  * @return Ratio between image and texture dimensions.
46  * @see adjustedToPowerOfTwo().
47  */
48  virtual Vector2 imageTextureRatio() const;
49 
50  /**
51  * Returns the texture wrap type in s direction.
52  * The default is WRAP_CLAMP.
53  * @return Wrap type in s direction
54  * @exception NotSupportedException Is thrown if this function is not supported
55  * @see setWrapTypeS(), wrapTypeT().
56  */
57  virtual WrapType wrapTypeS() const;
58 
59  /**
60  * Returns the texture wrap type in t direction.
61  * The default is WRAP_CLAMP.
62  * @return Wrap type in t direction
63  * @exception NotSupportedException Is thrown if this function is not supported
64  * @see setWrapTypeT(), wrapTypeS().
65  */
66  virtual WrapType wrapTypeT() const;
67 
68  /**
69  * Sets the texture wrap type in s direction.
70  * @param type Wrap type to set
71  * @return True, if succeeded
72  * @exception NotSupportedException Is thrown if this function is not supported
73  * @see wrapTypeS(), setWrapTypeT().
74  */
75  virtual bool setWrapTypeS(const WrapType type);
76 
77  /**
78  * Sets the texture wrap type in t direction.
79  * @param type Wrap type to set
80  * @return True, if succeeded
81  * @exception NotSupportedException Is thrown if this function is not supported
82  * @see wrapTypeT(), setWrapTypeS().
83  */
84  virtual bool setWrapTypeT(const WrapType type);
85 
86  /**
87  * Returns the frame type of this 2D texture.
88  * @return Texture frame type
89  */
90  virtual FrameType frameType() const;
91 
92  /**
93  * Returns whether this texture contains at least one transparent pixel.
94  * @return True, if so
95  */
96  virtual bool hasTransparentPixel() const;
97 
98  /**
99  * Returns the type of this object.
100  * @see Object::type().
101  */
102  ObjectType type() const override;
103 
104  protected:
105 
106  /**
107  * Creates a new 2D texture object.
108  */
110 
111  /**
112  * Destructs a 2D texture object.
113  */
114  ~Texture2D() override;
115 
116  /**
117  * Calculates the smallest power of two texture in which a given image with arbitrary dimension fits.
118  * @param width The width of the image for which the smallest power-of-two width will be calculated, with range [1, infinity)
119  * @param height The height of the image for which the smallest power-of-two height will be calculated, with range [1, infinity)
120  * @param powerOfTwoWidth Resulting power of two width, with range [width, infinity), will be a power of two
121  * @param powerOfTwoHeight Resulting power of two height, with range [height, infinity), will be a power of two
122  */
123  static inline void calculatePowerOfTwoDimension(const unsigned int width, const unsigned int height, unsigned int& powerOfTwoWidth, unsigned int& powerOfTwoHeight);
124 };
125 
126 inline void Texture2D::calculatePowerOfTwoDimension(const unsigned int width, const unsigned int height, unsigned int& powerOfTwoWidth, unsigned int& powerOfTwoHeight)
127 {
128  ocean_assert(width != 0u && height != 0u);
129 
130  powerOfTwoWidth = Utilities::smallestPowerOfTwo(width);
131  powerOfTwoHeight = Utilities::smallestPowerOfTwo(height);
132 }
133 
134 }
135 
136 }
137 
138 #endif // META_OCEAN_RENDERING_TEXTURE_2D_H
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
ObjectType
Definition of different object type.
Definition: Object.h:63
This class is the base class for all 2D textures.
Definition: Texture2D.h:38
virtual WrapType wrapTypeT() const
Returns the texture wrap type in t direction.
virtual FrameType frameType() const
Returns the frame type of this 2D texture.
virtual bool setWrapTypeS(const WrapType type)
Sets the texture wrap type in s direction.
~Texture2D() override
Destructs a 2D texture object.
Texture2D()
Creates a new 2D texture object.
virtual WrapType wrapTypeS() const
Returns the texture wrap type in s direction.
ObjectType type() const override
Returns the type of this object.
virtual bool setWrapTypeT(const WrapType type)
Sets the texture wrap type in t direction.
virtual Vector2 imageTextureRatio() const
Returns the ratio between original image dimension and actual texture dimension in horizontal and ver...
static void calculatePowerOfTwoDimension(const unsigned int width, const unsigned int height, unsigned int &powerOfTwoWidth, unsigned int &powerOfTwoHeight)
Calculates the smallest power of two texture in which a given image with arbitrary dimension fits.
Definition: Texture2D.h:126
virtual bool hasTransparentPixel() const
Returns whether this texture contains at least one transparent pixel.
This class is the base class for all textures.
Definition: rendering/Texture.h:38
WrapType
Definition of different texture wrapping types.
Definition: rendering/Texture.h:96
static unsigned int smallestPowerOfTwo(const unsigned int value)
Returns the smallest power of two value that is equal or larger than a given value.
Definition: base/Utilities.h:885
SmartObjectRef< Texture2D > Texture2DRef
Definition of a smart object reference holding a 2D texture.
Definition: Texture2D.h:24
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15