Go to the documentation of this file.
30 #include "../../Platforms/interface/PlatformDefinitions.h"
34 #include "../../Graphics/GraphicsEngine/interface/Sampler.h"
82 return i0 == rhs.
i0 &&
i1 == rhs.
i1 &&
w == rhs.
w;
87 return !(*
this == rhs);
99 template <TEXTURE_ADDRESS_MODE AddressMode,
bool IsNormalizedCoord>
102 float x = IsNormalizedCoord ? u *
static_cast<float>(Width) : u;
108 static_cast<Int32>(x0),
109 static_cast<Int32>(x0 + 1),
116 auto w =
static_cast<Int32>(Width);
121 return i < 0 ? i + w : i;
124 auto MirrorCoord = [WrapCoord](
Int32 i,
Uint32 Width)
126 i = WrapCoord(i, Width * 2);
128 auto w =
static_cast<Int32>(Width);
129 return i >= w ? (w * 2 - 1) - i : i;
139 SampleInfo.i0 = WrapCoord(SampleInfo.i0, Width);
140 SampleInfo.i1 = WrapCoord(SampleInfo.i1, Width);
144 SampleInfo.i0 = MirrorCoord(SampleInfo.i0, Width);
145 SampleInfo.i1 = MirrorCoord(SampleInfo.i1, Width);
149 SampleInfo.i0 =
clamp(SampleInfo.i0, 0,
static_cast<Int32>(Width - 1));
150 SampleInfo.i1 =
clamp(SampleInfo.i1, 0,
static_cast<Int32>(Width - 1));
154 UNEXPECTED(
"Unexpected texture address mode");
160 #ifdef DILIGENT_DEBUG
161 template <TEXTURE_ADDRESS_MODE AddressMode>
162 void _DbgVerifyFilterInfo(
const LinearTexFilterSampleInfo& FilterInfo,
Uint32 Width,
const char* Direction,
float u)
167 inline void _DbgVerifyFilterInfo<TEXTURE_ADDRESS_UNKNOWN>(
const LinearTexFilterSampleInfo& FilterInfo,
Uint32 Width,
const char* Direction,
float u)
169 VERIFY(FilterInfo.i0 >= 0 && FilterInfo.i0 <
static_cast<Int32>(Width),
"First ", Direction,
" sample index (", FilterInfo.i0,
170 ") is out of allowed range [0, ", Width - 1,
"]. Correct sample coordinate (", u,
") or use one of the texture address modes.");
171 VERIFY(FilterInfo.i1 >= 0 && FilterInfo.i1 <
static_cast<Int32>(Width),
"Second ", Direction,
" sample index (", FilterInfo.i1,
172 ") is out of allowed range [0, ", Width - 1,
"]. Correct sample coordinate (", u,
") or use one of the texture address modes.");
191 template <
typename SrcType,
195 bool IsNormalizedCoord>
198 const SrcType* pData,
203 auto UFilterInfo = GetLinearTexFilterSampleInfo<AddressModeU, IsNormalizedCoord>(Width, u);
204 auto VFilterInfo = GetLinearTexFilterSampleInfo<AddressModeV, IsNormalizedCoord>(Height, v);
206 #ifdef DILIGENT_DEBUG
208 _DbgVerifyFilterInfo<AddressModeU>(UFilterInfo, Width,
"horizontal", u);
209 _DbgVerifyFilterInfo<AddressModeV>(VFilterInfo, Height,
"horizontal", v);
213 auto S00 =
static_cast<DstType
>(pData[UFilterInfo.i0 + VFilterInfo.i0 * Stride]);
214 auto S10 =
static_cast<DstType
>(pData[UFilterInfo.i1 + VFilterInfo.i0 * Stride]);
215 auto S01 =
static_cast<DstType
>(pData[UFilterInfo.i0 + VFilterInfo.i1 * Stride]);
216 auto S11 =
static_cast<DstType
>(pData[UFilterInfo.i1 + VFilterInfo.i1 * Stride]);
217 return lerp(
lerp(S00, S10, UFilterInfo.w),
lerp(S01, S11, UFilterInfo.w), VFilterInfo.w);
222 template <
typename SrcType,
typename DstType>
225 const SrcType* pData,
231 return FilterTexture2DBilinear<SrcType, DstType, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP, true>(Width, Height, pData, Stride, u, v);
236 template <
typename SrcType,
typename DstType>
239 const SrcType* pData,
245 return FilterTexture2DBilinear<SrcType, DstType, TEXTURE_ADDRESS_CLAMP, TEXTURE_ADDRESS_CLAMP, false>(Width, Height, pData, Stride, u, v);
Int32 i[2]
Sample indices.
Definition: FilteringTools.hpp:62
LinearTexFilterSampleInfo() noexcept
Definition: FilteringTools.hpp:68
DstType FilterTexture2DBilinearClampUC(Uint32 Width, Uint32 Height, const SrcType *pData, size_t Stride, float u, float v)
Specialization of FilterTexture2DBilinear function that uses CLAMP texture address mode and takes unn...
Definition: FilteringTools.hpp:237
DstType FilterTexture2DBilinear(Uint32 Width, Uint32 Height, const SrcType *pData, size_t Stride, float u, float v)
Samples 2D texture using bilinear filter.
Definition: FilteringTools.hpp:196
TEXTURE_ADDRESS_MODE
Texture address mode.
Definition: GraphicsTypes.h:889
float w
Blend weight.
Definition: FilteringTools.hpp:66
#define UNEXPECTED(...)
Definition: DebugUtilities.hpp:77
LinearTexFilterSampleInfo(Int32 _i0, Int32 _i1, float _w) noexcept
Definition: FilteringTools.hpp:73
T clamp(T val, T _min, T _max)
Definition: BasicMath.hpp:1700
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:46
DstType FilterTexture2DBilinearClamp(Uint32 Width, Uint32 Height, const SrcType *pData, size_t Stride, float u, float v)
Specialization of FilterTexture2DBilinear function that uses CLAMP texture address mode and takes nor...
Definition: FilteringTools.hpp:223
Int32 i0
First sample index.
Definition: FilteringTools.hpp:55
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
@ TEXTURE_ADDRESS_MIRROR
Flip the texture at every integer junction. Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_MIRROR/D3D1...
Definition: GraphicsTypes.h:900
T lerp(const T &Left, const T &Right, float w)
Definition: BasicMath.hpp:2023
Int32 i1
Second sample index.
Definition: FilteringTools.hpp:58
T FastFloor(T x)
Definition: BasicMath.hpp:2093
@ TEXTURE_ADDRESS_UNKNOWN
Unknown mode.
Definition: GraphicsTypes.h:892
LinearTexFilterSampleInfo GetLinearTexFilterSampleInfo(Uint32 Width, float u)
Returns linear texture filter sample info, see Diligent::LinearTexFilterSampleInfo.
Definition: FilteringTools.hpp:100
Linear texture filter sample info.
Definition: FilteringTools.hpp:48
@ TEXTURE_ADDRESS_CLAMP
Texture coordinates outside the range [0.0, 1.0] are set to the texture color at 0....
Definition: GraphicsTypes.h:905
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
bool operator==(const LinearTexFilterSampleInfo &rhs) const
Definition: FilteringTools.hpp:80
bool operator!=(const LinearTexFilterSampleInfo &rhs) const
Definition: FilteringTools.hpp:85
@ TEXTURE_ADDRESS_WRAP
Tile the texture at every integer junction. Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_WRAP/D3D12_...
Definition: GraphicsTypes.h:896
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37