mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphicsdriver/metal: Use template specialization
This commit is contained in:
parent
04dc1faa9c
commit
5c7f34827f
@ -100,21 +100,22 @@ float FloorMod(float x, float y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<uint8_t address>
|
template<uint8_t address>
|
||||||
float2 AdjustTexelByAddress(float2 p, float4 tex_region) {
|
float2 AdjustTexelByAddress(float2 p, float4 tex_region);
|
||||||
if (address == ADDRESS_CLAMP_TO_ZERO) {
|
|
||||||
return p;
|
template<>
|
||||||
}
|
float2 AdjustTexelByAddress<ADDRESS_CLAMP_TO_ZERO>(float2 p, float4 tex_region) {
|
||||||
if (address == ADDRESS_REPEAT) {
|
return p;
|
||||||
float2 o = float2(tex_region[0], tex_region[1]);
|
}
|
||||||
float2 size = float2(tex_region[2] - tex_region[0], tex_region[3] - tex_region[1]);
|
|
||||||
return float2(FloorMod((p.x - o.x), size.x) + o.x, FloorMod((p.y - o.y), size.y) + o.y);
|
template<>
|
||||||
}
|
float2 AdjustTexelByAddress<ADDRESS_REPEAT>(float2 p, float4 tex_region) {
|
||||||
// Not reached.
|
float2 o = float2(tex_region[0], tex_region[1]);
|
||||||
return 0.0;
|
float2 size = float2(tex_region[2] - tex_region[0], tex_region[3] - tex_region[1]);
|
||||||
|
return float2(FloorMod((p.x - o.x), size.x) + o.x, FloorMod((p.y - o.y), size.y) + o.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint8_t filter, uint8_t address>
|
template<uint8_t filter, uint8_t address>
|
||||||
float4 fragmentShader(
|
float4 FragmentShaderImpl(
|
||||||
VertexOut v,
|
VertexOut v,
|
||||||
texture2d<float> texture,
|
texture2d<float> texture,
|
||||||
constant float4x4& color_matrix_body,
|
constant float4x4& color_matrix_body,
|
||||||
@ -214,7 +215,7 @@ float4 fragmentShader(
|
|||||||
constant float4x4& color_matrix_body [[buffer(2)]], \
|
constant float4x4& color_matrix_body [[buffer(2)]], \
|
||||||
constant float4& color_matrix_translation [[buffer(3)]], \
|
constant float4& color_matrix_translation [[buffer(3)]], \
|
||||||
constant float& scale [[buffer(4)]]) { \
|
constant float& scale [[buffer(4)]]) { \
|
||||||
return fragmentShader<filter, address>( \
|
return FragmentShaderImpl<filter, address>( \
|
||||||
v, texture, color_matrix_body, color_matrix_translation, scale); \
|
v, texture, color_matrix_body, color_matrix_translation, scale); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user