/
SDL_shaders_metal.metal
59 lines (50 loc) · 1.9 KB
1
#include <metal_texture>
2
#include <metal_matrix>
3
4
5
using namespace metal;
6
struct SolidVertexOutput
7
{
8
9
10
11
float4 position [[position]];
float pointSize [[point_size]];
};
12
13
14
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
constant float4x4 &projection [[buffer(2)]],
uint vid [[vertex_id]])
15
{
16
17
SolidVertexOutput v;
v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
18
19
v.pointSize = 0.5f;
return v;
20
21
}
22
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
23
24
25
26
{
return col;
}
27
struct CopyVertexOutput
28
29
30
31
32
{
float4 position [[position]];
float2 texcoord;
};
33
34
35
36
vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
const device float2 *texcoords [[buffer(1)]],
constant float4x4 &projection [[buffer(2)]],
uint vid [[vertex_id]])
37
{
38
39
CopyVertexOutput v;
v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
40
41
v.texcoord = texcoords[vid];
return v;
42
43
}
44
45
46
fragment float4 SDL_Copy_fragment_nearest(CopyVertexOutput vert [[stage_in]],
constant float4 &col [[buffer(0)]],
texture2d<float> tex [[texture(0)]])
47
{
48
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
49
50
51
return tex.sample(s, vert.texcoord) * col;
}
52
53
54
fragment float4 SDL_Copy_fragment_linear(CopyVertexOutput vert [[stage_in]],
constant float4 &col [[buffer(0)]],
texture2d<float> tex [[texture(0)]])
55
{
56
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
57
return tex.sample(s, vert.texcoord) * col;
58
}