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 the image which was provided for this texture.
89 * This is the frame type before any conversion, so it can differ from textureFrameType().
90 * @return The frame type of the source image, invalid if the texture does not have an image yet
91 */
92 virtual FrameType sourceFrameType() const;
93
94 /**
95 * Returns the frame type of the image data which is stored in the graphic hardware.
96 * Pixel formats without a matching texture format are converted first, so this can differ from sourceFrameType().
97 * @return The frame type of the texture, invalid as long as no image has been uploaded
98 */
99 virtual FrameType textureFrameType() const;
100
101 /**
102 * Returns whether this texture contains at least one transparent pixel.
103 * @return True, if so
104 */
105 virtual bool hasTransparentPixel() const;
106
107 /**
108 * Returns the type of this object.
109 * @see Object::type().
110 */
111 ObjectType type() const override;
112
113 protected:
114
115 /**
116 * Creates a new 2D texture object.
117 */
119
120 /**
121 * Destructs a 2D texture object.
122 */
123 ~Texture2D() override;
124
125 /**
126 * Calculates the smallest power of two texture in which a given image with arbitrary dimension fits.
127 * @param width The width of the image for which the smallest power-of-two width will be calculated, with range [1, infinity)
128 * @param height The height of the image for which the smallest power-of-two height will be calculated, with range [1, infinity)
129 * @param powerOfTwoWidth Resulting power of two width, with range [width, infinity), will be a power of two
130 * @param powerOfTwoHeight Resulting power of two height, with range [height, infinity), will be a power of two
131 */
132 static inline void calculatePowerOfTwoDimension(const unsigned int width, const unsigned int height, unsigned int& powerOfTwoWidth, unsigned int& powerOfTwoHeight);
133
134 protected:
135
136 /// The frame type of the image which was provided for this texture.
138
139 /// The frame type of the image data which is stored in the graphic hardware.
141
142 /// The timestamp of the current frame.
144};
145
146inline void Texture2D::calculatePowerOfTwoDimension(const unsigned int width, const unsigned int height, unsigned int& powerOfTwoWidth, unsigned int& powerOfTwoHeight)
147{
148 ocean_assert(width != 0u && height != 0u);
149
150 powerOfTwoWidth = Utilities::smallestPowerOfTwo(width);
151 powerOfTwoHeight = Utilities::smallestPowerOfTwo(height);
152}
153
154}
155
156}
157
158#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:62
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:143
virtual WrapType wrapTypeT() const
Returns the texture wrap type in t direction.
virtual FrameType sourceFrameType() const
Returns the frame type of the image which was provided for this texture.
virtual bool setWrapTypeS(const WrapType type)
Sets the texture wrap type in s direction.
FrameType textureFrameType_
The frame type of the image data which is stored in the graphic hardware.
Definition Texture2D.h:140
~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:146
virtual bool hasTransparentPixel() const
Returns whether this texture contains at least one transparent pixel.
virtual FrameType textureFrameType() const
Returns the frame type of the image data which is stored in the graphic hardware.
FrameType sourceFrameType_
The frame type of the image which was provided for this texture.
Definition Texture2D.h:137
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:64
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