Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TAbstractPixelTex2D.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
7
8#include <Common/assertion.h>
9
10namespace ph
11{
12
13enum class ETexWrapMode
14{
15 REPEAT,
17};
18
19template<typename T, std::size_t N>
20class TAbstractPixelTex2D : public TTexture<TTexPixel<T, N>>
21{
22public:
25 {}
26
27 inline TAbstractPixelTex2D(const uint32 widthPx, const uint32 heightPx) :
28 TTexture<TTexPixel<T, N>>(),
30 {
31 setWidthPx(widthPx);
32 setHeightPx(heightPx);
33 }
34
35 void sample(
36 const SampleLocation& sampleLocation,
37 TTexPixel<T, N>* out_value) const override = 0;
38
39 inline uint32 getWidthPx() const { return m_widthPx; }
40 inline uint32 getHeightPx() const { return m_heightPx; }
41 inline float64 getTexelSizeU() const { return m_texelSizeU; }
42 inline float64 getTexelSizeV() const { return m_texelSizeV; }
43 inline ETexWrapMode getWrapMode() const { return m_wrapMode; }
44
45 inline void setWrapMode(const ETexWrapMode mode)
46 {
47 m_wrapMode = mode;
48 }
49
50protected:
51 // Normalizing (u, v) coordinates to [0, 1] according to wrapping mode.
52 inline void normalizeUV(const float64 u, const float64 v,
53 float64* const out_u, float64* const out_v) const
54 {
55 switch(m_wrapMode)
56 {
58 {
59 const float64 fu = math::fractional_part(u);
60 const float64 fv = math::fractional_part(v);
61 *out_u = fu >= 0.0 ? fu : fu + 1.0;
62 *out_v = fv >= 0.0 ? fv : fv + 1.0;
63 break;
64 }
66 {
67 *out_u = math::clamp(u, 0.0, 1.0);
68 *out_v = math::clamp(v, 0.0, 1.0);
69 break;
70 }
71 default:
72 PH_ASSERT_UNREACHABLE_SECTION();
73 }
74
75 PH_ASSERT(*out_u >= 0.0 && *out_u <= 1.0 &&
76 *out_v >= 0.0 && *out_v <= 1.0);
77 }
78
79 inline void setWidthPx(const uint32 widthPx)
80 {
81 PH_ASSERT(widthPx > 0);
82
83 m_widthPx = widthPx;
84 m_texelSizeU = 1.0 / widthPx;
85 }
86
87 inline void setHeightPx(const uint32 heightPx)
88 {
89 PH_ASSERT(heightPx > 0);
90
91 m_heightPx = heightPx;
92 m_texelSizeV = 1.0 / heightPx;
93 }
94
95protected:
96 uint32 m_widthPx;
97 uint32 m_heightPx;
98 float64 m_texelSizeU;
99 float64 m_texelSizeV;
101};
102
103}// end namespace ph
Definition SampleLocation.h:22
Definition TAbstractPixelTex2D.h:21
float64 getTexelSizeV() const
Definition TAbstractPixelTex2D.h:42
float64 m_texelSizeV
Definition TAbstractPixelTex2D.h:99
void setWrapMode(const ETexWrapMode mode)
Definition TAbstractPixelTex2D.h:45
void sample(const SampleLocation &sampleLocation, TTexPixel< T, N > *out_value) const override=0
uint32 getWidthPx() const
Definition TAbstractPixelTex2D.h:39
TAbstractPixelTex2D()
Definition TAbstractPixelTex2D.h:23
uint32 m_widthPx
Definition TAbstractPixelTex2D.h:96
void setWidthPx(const uint32 widthPx)
Definition TAbstractPixelTex2D.h:79
uint32 getHeightPx() const
Definition TAbstractPixelTex2D.h:40
ETexWrapMode m_wrapMode
Definition TAbstractPixelTex2D.h:100
float64 getTexelSizeU() const
Definition TAbstractPixelTex2D.h:41
float64 m_texelSizeU
Definition TAbstractPixelTex2D.h:98
void setHeightPx(const uint32 heightPx)
Definition TAbstractPixelTex2D.h:87
ETexWrapMode getWrapMode() const
Definition TAbstractPixelTex2D.h:43
uint32 m_heightPx
Definition TAbstractPixelTex2D.h:97
void normalizeUV(const float64 u, const float64 v, float64 *const out_u, float64 *const out_v) const
Definition TAbstractPixelTex2D.h:52
TAbstractPixelTex2D(const uint32 widthPx, const uint32 heightPx)
Definition TAbstractPixelTex2D.h:27
Definition TTexture.h:12
Definition TArithmeticArray.h:13
Miscellaneous math utilities.
T fractional_part(const T value)
Retrieve the fractional part of value (with the sign unchanged). The result is not guaranteed to be t...
Definition math.h:258
T clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound]. None of value, lowerBound and upperBound can be NaN,...
Definition math.h:77
The root for all renderer implementations.
Definition EEngineProject.h:6
ETexWrapMode
Definition TAbstractPixelTex2D.h:14