@@ -68,6 +68,52 @@ void main() {
6868}
6969'
7070
71+ // Metal vertex shader source.
72+ const vs_source_metal = '#include <metal_stdlib>
73+ using namespace metal;
74+
75+ struct VSIn {
76+ float4 position [[attribute(0)]];
77+ float2 texcoord0 [[attribute(1)]];
78+ float4 color0 [[attribute(2)]];
79+ float psize [[attribute(3)]];
80+ };
81+
82+ struct VSOut {
83+ float4 position [[position]];
84+ float2 uv;
85+ float4 color;
86+ float psize [[point_size]];
87+ };
88+
89+ vertex VSOut main0(VSIn in [[stage_in]], constant float4* vs_params [[buffer(0)]]) {
90+ VSOut out;
91+ float4x4 mvp = float4x4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]);
92+ float4x4 tm = float4x4(vs_params[4], vs_params[5], vs_params[6], vs_params[7]);
93+ out.position = mvp * in.position;
94+ out.psize = in.psize;
95+ out.uv = (tm * float4(in.texcoord0, 0.0, 1.0)).xy;
96+ out.color = in.color0;
97+ return out;
98+ }
99+ '
100+
101+ // Metal fragment shader source.
102+ const fs_source_metal = '#include <metal_stdlib>
103+ using namespace metal;
104+
105+ struct FSIn {
106+ float2 uv;
107+ float4 color;
108+ float psize [[point_size]];
109+ };
110+
111+ fragment float4 main0(FSIn in [[stage_in]], texture2d<float> tex_smp [[texture(0)]],
112+ sampler smp [[sampler(0)]]) {
113+ return tex_smp.sample(smp, in.uv) * in.color;
114+ }
115+ '
116+
71117// Builds and returns the shader descriptor for the sgl shader.
72118// Selects the correct shader source/bytecode based on the active graphics backend.
73119fn make_shader_desc () gfx.ShaderDesc {
@@ -102,27 +148,28 @@ fn make_shader_desc() gfx.ShaderDesc {
102148 backend := gfx.query_backend ()
103149 match backend {
104150 .glcore33 {
105- desc.vs.source = vs_source_glsl410 .str
106- desc.fs.source = fs_source_glsl410 .str
151+ desc.vs.source = & char ( vs_source_glsl410 .str)
152+ desc.fs.source = & char ( fs_source_glsl410 .str)
107153 }
108154 .gles3 {
109- desc.vs.source = vs_source_glsl300 es.str
110- desc.fs.source = fs_source_glsl300 es.str
155+ desc.vs.source = & char ( vs_source_glsl300 es.str)
156+ desc.fs.source = & char ( fs_source_glsl300 es.str)
111157 }
112158 .metal_macos, .metal_ios, .metal_simulator {
113- // Metal backends - TODO: embed Metal shader bytecode
114- desc.vs.source = vs_source_glsl410 .str
115- desc.fs.source = fs_source_glsl410 .str
159+ desc.vs.entry = c 'main0'
160+ desc.fs.entry = c 'main0'
161+ desc.vs.source = & char (vs_source_metal.str)
162+ desc.fs.source = & char (fs_source_metal.str)
116163 }
117164 .d3 d11 {
118165 // D3D11 backend - TODO: embed HLSL shader bytecode
119- desc.vs.source = vs_source_glsl410 .str
120- desc.fs.source = fs_source_glsl410 .str
166+ desc.vs.source = & char ( vs_source_glsl410 .str)
167+ desc.fs.source = & char ( fs_source_glsl410 .str)
121168 }
122169 .wgpu {
123170 // WebGPU - TODO: embed WGSL shader source
124- desc.vs.source = vs_source_glsl410 .str
125- desc.fs.source = fs_source_glsl410 .str
171+ desc.vs.source = & char ( vs_source_glsl410 .str)
172+ desc.fs.source = & char ( fs_source_glsl410 .str)
126173 }
127174 .dummy {
128175 desc.vs.source = c ''
0 commit comments