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