Skip to content

Commit 83db408

Browse files
committed
move E_TEXTURE_CLAMP into hlsl headers
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
1 parent 987a5de commit 83db408

File tree

15 files changed

+66
-63
lines changed

15 files changed

+66
-63
lines changed

include/nbl/asset/ICPUSampler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ class ICPUSampler : public ISampler, public IAsset
3737
};
3838
switch (wrapModes[i])
3939
{
40-
case ISampler::ETC_REPEAT:
40+
case ISampler::E_TEXTURE_CLAMP::ETC_REPEAT:
4141
repeat();
4242
break;
43-
case ISampler::ETC_CLAMP_TO_EDGE:
44-
texelCoord[i] = core::clamp<int32_t,int32_t>(texelCoord[i],0,mipLastCoord[i]);
43+
case ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE:
44+
texelCoord[i] = core::clamp<int32_t, int32_t>(texelCoord[i], 0, mipLastCoord[i]);
4545
break;
46-
case ISampler::ETC_MIRROR_CLAMP_TO_EDGE:
47-
texelCoord[i] = core::clamp<int32_t,int32_t>(texelCoord[i],-int32_t(mipExtent[i]),mipExtent[i]+mipLastCoord[i]);
46+
case ISampler::E_TEXTURE_CLAMP::ETC_MIRROR_CLAMP_TO_EDGE:
47+
texelCoord[i] = core::clamp<int32_t, int32_t>(texelCoord[i], -int32_t(mipExtent[i]), mipExtent[i] + mipLastCoord[i]);
4848
[[fallthrough]];
49-
case ISampler::ETC_MIRROR:
49+
case ISampler::E_TEXTURE_CLAMP::ETC_MIRROR:
5050
{
5151
int32_t repeatID = (originalWasNegative+texelCoord[i])/int32_t(mipExtent[i]);
5252
repeat();

include/nbl/asset/ISampler.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define __NBL_ASSET_I_SAMPLER_H_INCLUDED__
77

88
#include "nbl/asset/IDescriptor.h"
9+
#include "nbl/builtin/hlsl/enums.hlsl"
910

1011
namespace nbl
1112
{
@@ -16,23 +17,7 @@ class ISampler : public IDescriptor
1617
{
1718
public:
1819
//! Texture coord clamp mode outside [0.0, 1.0]
19-
enum E_TEXTURE_CLAMP
20-
{
21-
//! Texture repeats
22-
ETC_REPEAT = 0,
23-
//! Texture is clamped to the edge pixel
24-
ETC_CLAMP_TO_EDGE,
25-
//! Texture is clamped to the border pixel (if exists)
26-
ETC_CLAMP_TO_BORDER,
27-
//! Texture is alternatingly mirrored (0..1..0..1..0..)
28-
ETC_MIRROR,
29-
//! Texture is mirrored once and then clamped to edge
30-
ETC_MIRROR_CLAMP_TO_EDGE,
31-
//! Texture is mirrored once and then clamped to border
32-
ETC_MIRROR_CLAMP_TO_BORDER,
33-
34-
ETC_COUNT
35-
};
20+
using E_TEXTURE_CLAMP = hlsl::TextureClamp;
3621

3722
enum E_TEXTURE_BORDER_COLOR
3823
{
@@ -75,11 +60,11 @@ class ISampler : public IDescriptor
7560
{
7661
struct {
7762
//! Valeus taken from E_TEXTURE_CLAMP
78-
uint32_t TextureWrapU : 3 = ETC_REPEAT;
63+
uint32_t TextureWrapU : 3 = E_TEXTURE_CLAMP::ETC_REPEAT;
7964
//! Valeus taken from E_TEXTURE_CLAMP
80-
uint32_t TextureWrapV : 3 = ETC_REPEAT;
65+
uint32_t TextureWrapV : 3 = E_TEXTURE_CLAMP::ETC_REPEAT;
8166
//! Valeus taken from E_TEXTURE_CLAMP
82-
uint32_t TextureWrapW : 3 = ETC_REPEAT;
67+
uint32_t TextureWrapW : 3 = E_TEXTURE_CLAMP::ETC_REPEAT;
8368
//! Values taken from E_TEXTURE_BORDER_COLOR
8469
uint32_t BorderColor : 3 = ETBC_FLOAT_OPAQUE_BLACK;
8570
//! Values taken from E_TEXTURE_FILTER

include/nbl/asset/filters/CBlitImageFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CBlitImageFilterBase : public impl::CSwizzleableAndDitherableFilterBase<Sw
3434
uint8_t* scratchMemory = nullptr;
3535
uint32_t scratchMemoryByteSize = 0u;
3636
_NBL_STATIC_INLINE_CONSTEXPR auto NumWrapAxes = 3;
37-
ISampler::E_TEXTURE_CLAMP axisWraps[NumWrapAxes] = { ISampler::ETC_REPEAT,ISampler::ETC_REPEAT,ISampler::ETC_REPEAT };
37+
ISampler::E_TEXTURE_CLAMP axisWraps[NumWrapAxes] = { ISampler::E_TEXTURE_CLAMP::ETC_REPEAT,ISampler::E_TEXTURE_CLAMP::ETC_REPEAT,ISampler::E_TEXTURE_CLAMP::ETC_REPEAT };
3838
ISampler::E_TEXTURE_BORDER_COLOR borderColor = ISampler::ETBC_FLOAT_TRANSPARENT_BLACK;
3939
IBlitUtilities::E_ALPHA_SEMANTIC alphaSemantic = IBlitUtilities::EAS_NONE_OR_PREMULTIPLIED;
4040
double alphaRefValue = 0.5; // only required to make sense if `alphaSemantic==EAS_REFERENCE_OR_COVERAGE`
@@ -56,7 +56,7 @@ class CBlitImageFilterBase : public impl::CSwizzleableAndDitherableFilterBase<Sw
5656
return false;
5757

5858
for (auto i=0; i<CStateBase::NumWrapAxes; i++)
59-
if (state->axisWraps[i]>=ISampler::ETC_COUNT)
59+
if (state->axisWraps[i]>=ISampler::E_TEXTURE_CLAMP::ETC_COUNT)
6060
return false;
6161

6262
if (state->borderColor>=ISampler::ETBC_COUNT)

include/nbl/asset/filters/CPaddedCopyImageFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CPaddedCopyImageFilter : public CImageFilter<CPaddedCopyImageFilter>, publ
3030
virtual ~CState() {}
3131

3232
_NBL_STATIC_INLINE_CONSTEXPR auto NumWrapAxes = 3;
33-
ISampler::E_TEXTURE_CLAMP axisWraps[NumWrapAxes] = {ISampler::ETC_REPEAT,ISampler::ETC_REPEAT,ISampler::ETC_REPEAT};
33+
ISampler::E_TEXTURE_CLAMP axisWraps[NumWrapAxes] = {ISampler::E_TEXTURE_CLAMP::ETC_REPEAT,ISampler::E_TEXTURE_CLAMP::ETC_REPEAT,ISampler::E_TEXTURE_CLAMP::ETC_REPEAT};
3434
ISampler::E_TEXTURE_BORDER_COLOR borderColor;
3535
VkOffset3D relativeOffset;
3636
VkExtent3D paddedExtent;
@@ -57,7 +57,7 @@ class CPaddedCopyImageFilter : public CImageFilter<CPaddedCopyImageFilter>, publ
5757
// TODO: eventually remove when we can encode blocks
5858
for (auto i=0; i<CState::NumWrapAxes; i++)
5959
{
60-
if ((isBlockCompressionFormat(inFormat)||isBlockCompressionFormat(outFormat))&&state->axisWraps[i]!=ISampler::ETC_REPEAT)
60+
if ((isBlockCompressionFormat(inFormat)||isBlockCompressionFormat(outFormat))&&state->axisWraps[i]!=ISampler::E_TEXTURE_CLAMP::ETC_REPEAT)
6161
return false;
6262
}
6363

include/nbl/builtin/hlsl/enums.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ enum ShaderStage : uint32_t
3232
ESS_ALL = 0x7fffffff
3333
};
3434

35+
enum TextureClamp : uint16_t
36+
{
37+
//! Texture repeats
38+
ETC_REPEAT = 0,
39+
//! Texture is clamped to the edge pixel
40+
ETC_CLAMP_TO_EDGE,
41+
//! Texture is clamped to the border pixel (if exists)
42+
ETC_CLAMP_TO_BORDER,
43+
//! Texture is alternatingly mirrored (0..1..0..1..0..)
44+
ETC_MIRROR,
45+
//! Texture is mirrored once and then clamped to edge
46+
ETC_MIRROR_CLAMP_TO_EDGE,
47+
//! Texture is mirrored once and then clamped to border
48+
ETC_MIRROR_CLAMP_TO_BORDER,
49+
50+
ETC_COUNT
51+
};
52+
3553
enum SampleCountFlags : uint16_t
3654
{
3755
ESCF_1_BIT = 0x01,

include/nbl/ext/FFT/FFT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class FFT final : public core::IReferenceCounted
108108
const auto passAxis = std::get<1u>(passes[i]);
109109
const auto paddedAxisLen = (&paddedInputDimensions.width)[passAxis];
110110
{
111-
assert(paddingType[i]<=asset::ISampler::ETC_MIRROR);
111+
assert(paddingType[i]<=asset::ISampler::E_TEXTURE_CLAMP::ETC_MIRROR);
112112
params.input_dimensions.w = (isInverse ? 0x80000000u:0x0u)|
113113
(passAxis<<28u)| // direction
114114
((numChannels-1u)<<26u)| // max channel

include/nbl/ext/MitsubaLoader/SContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ namespace MitsubaLoader
111111
switch (mode)
112112
{
113113
case CElementTexture::Bitmap::WRAP_MODE::CLAMP:
114-
return asset::ISampler::ETC_CLAMP_TO_EDGE;
114+
return asset::ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
115115
break;
116116
case CElementTexture::Bitmap::WRAP_MODE::MIRROR:
117-
return asset::ISampler::ETC_MIRROR;
117+
return asset::ISampler::E_TEXTURE_CLAMP::ETC_MIRROR;
118118
break;
119119
case CElementTexture::Bitmap::WRAP_MODE::ONE:
120120
_NBL_DEBUG_BREAK_IF(true); // TODO : replace whole texture?
@@ -125,11 +125,11 @@ namespace MitsubaLoader
125125
default:
126126
break;
127127
}
128-
return asset::ISampler::ETC_REPEAT;
128+
return asset::ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
129129
};
130130
params.TextureWrapU = getWrapMode(bitmap.wrapModeU);
131131
params.TextureWrapV = getWrapMode(bitmap.wrapModeV);
132-
params.TextureWrapW = asset::ISampler::ETC_REPEAT;
132+
params.TextureWrapW = asset::ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
133133
params.BorderColor = asset::ISampler::ETBC_FLOAT_OPAQUE_BLACK;
134134
switch (bitmap.filterType)
135135
{

include/nbl/video/CVulkanCommon.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,13 @@ inline VkSamplerAddressMode getVkAddressModeFromTexClamp(const IGPUSampler::E_TE
813813
{
814814
switch (in)
815815
{
816-
case IGPUSampler::ETC_REPEAT:
816+
case IGPUSampler::E_TEXTURE_CLAMP::ETC_REPEAT:
817817
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
818-
case IGPUSampler::ETC_CLAMP_TO_EDGE:
818+
case IGPUSampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE:
819819
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
820-
case IGPUSampler::ETC_CLAMP_TO_BORDER:
820+
case IGPUSampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER:
821821
return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
822-
case IGPUSampler::ETC_MIRROR:
822+
case IGPUSampler::E_TEXTURE_CLAMP::ETC_MIRROR:
823823
return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
824824
default:
825825
assert(!"ADDRESS MODE NOT SUPPORTED!");

src/nbl/asset/IAssetManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ void IAssetManager::insertBuiltinAssets()
307307
// samplers
308308
{
309309
asset::ISampler::SParams params;
310-
params.TextureWrapU = asset::ISampler::ETC_REPEAT;
311-
params.TextureWrapV = asset::ISampler::ETC_REPEAT;
312-
params.TextureWrapW = asset::ISampler::ETC_REPEAT;
310+
params.TextureWrapU = asset::ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
311+
params.TextureWrapV = asset::ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
312+
params.TextureWrapW = asset::ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
313313
params.BorderColor = asset::ISampler::ETBC_FLOAT_OPAQUE_BLACK;
314314
params.MinFilter = asset::ISampler::ETF_LINEAR;
315315
params.MaxFilter = asset::ISampler::ETF_LINEAR;
@@ -323,7 +323,7 @@ void IAssetManager::insertBuiltinAssets()
323323
auto sampler = core::make_smart_refctd_ptr<asset::ICPUSampler>(params);
324324
addBuiltInToCaches(sampler, "nbl/builtin/sampler/default");
325325

326-
params.TextureWrapU = params.TextureWrapV = params.TextureWrapW = asset::ISampler::ETC_CLAMP_TO_BORDER;
326+
params.TextureWrapU = params.TextureWrapV = params.TextureWrapW = asset::ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER;
327327
sampler = core::make_smart_refctd_ptr<asset::ICPUSampler>(params);
328328
addBuiltInToCaches(sampler, "nbl/builtin/sampler/default_clamp_to_border");
329329
}

src/nbl/asset/interchange/CGLTFLoader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,25 +286,25 @@ using namespace nbl::asset;
286286
switch (glTFSampler.wrapS)
287287
{
288288
case SGLTFSampler::STP_CLAMP_TO_EDGE:
289-
samplerParams.TextureWrapU = ISampler::ETC_CLAMP_TO_EDGE;
289+
samplerParams.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
290290
break;
291291
case SGLTFSampler::STP_MIRRORED_REPEAT:
292-
samplerParams.TextureWrapU = ISampler::ETC_MIRROR;
292+
samplerParams.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_MIRROR;
293293
break;
294294
case SGLTFSampler::STP_REPEAT:
295-
samplerParams.TextureWrapU = ISampler::ETC_REPEAT;
295+
samplerParams.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
296296
break;
297297
}
298298
switch (glTFSampler.wrapT)
299299
{
300300
case SGLTFSampler::STP_CLAMP_TO_EDGE:
301-
samplerParams.TextureWrapV = ISampler::ETC_CLAMP_TO_EDGE;
301+
samplerParams.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
302302
break;
303303
case SGLTFSampler::STP_MIRRORED_REPEAT:
304-
samplerParams.TextureWrapV = ISampler::ETC_MIRROR;
304+
samplerParams.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_MIRROR;
305305
break;
306306
case SGLTFSampler::STP_REPEAT:
307-
samplerParams.TextureWrapV = ISampler::ETC_REPEAT;
307+
samplerParams.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
308308
break;
309309
}
310310
sampler = getSampler(std::move(samplerParams),context.loadContext,_override);

0 commit comments

Comments
 (0)