summaryrefslogtreecommitdiffstats
path: root/third_party/rust/metal/examples/window/shaders.metal
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/metal/examples/window/shaders.metal
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/metal/examples/window/shaders.metal')
-rw-r--r--third_party/rust/metal/examples/window/shaders.metal97
1 files changed, 97 insertions, 0 deletions
diff --git a/third_party/rust/metal/examples/window/shaders.metal b/third_party/rust/metal/examples/window/shaders.metal
new file mode 100644
index 0000000000..cc05f5d57e
--- /dev/null
+++ b/third_party/rust/metal/examples/window/shaders.metal
@@ -0,0 +1,97 @@
+#include <metal_stdlib>
+
+using namespace metal;
+
+typedef struct {
+ packed_float2 position;
+ packed_float3 color;
+} vertex_t;
+
+struct ColorInOut {
+ float4 position [[position]];
+ float4 color;
+};
+// vertex shader function
+vertex ColorInOut triangle_vertex(const device vertex_t* vertex_array [[ buffer(0) ]],
+ unsigned int vid [[ vertex_id ]])
+{
+ ColorInOut out;
+
+ auto device const &v = vertex_array[vid];
+ out.position = float4(v.position.x, v.position.y, 0.0, 1.0);
+ out.color = float4(v.color.x, v.color.y, v.color.z, 0.2);
+
+ return out;
+}
+
+// fragment shader function
+fragment float4 triangle_fragment(ColorInOut in [[stage_in]])
+{
+ return in.color;
+};
+
+
+struct Rect {
+ float x;
+ float y;
+ float w;
+ float h;
+};
+
+struct Color {
+ float r;
+ float g;
+ float b;
+ float a;
+};
+
+struct ClearRect {
+ Rect rect;
+ Color color;
+};
+
+float2 rect_vert(
+ Rect rect,
+ uint vid
+) {
+ float2 pos;
+
+ float left = rect.x;
+ float right = rect.x + rect.w;
+ float bottom = rect.y;
+ float top = rect.y + rect.h;
+
+ switch (vid) {
+ case 0:
+ pos = float2(right, top);
+ break;
+ case 1:
+ pos = float2(left, top);
+ break;
+ case 2:
+ pos = float2(right, bottom);
+ break;
+ case 3:
+ pos = float2(left, bottom);
+ break;
+ }
+ return pos;
+}
+
+vertex ColorInOut clear_rect_vertex(
+ const device ClearRect *clear_rect [[ buffer(0) ]],
+ unsigned int vid [[ vertex_id ]]
+) {
+ ColorInOut out;
+ float4 pos = float4(rect_vert(clear_rect->rect, vid), 0, 1);
+ auto col = clear_rect->color;
+
+ out.position = pos;
+ out.color = float4(col.r, col.g, col.b, col.a);
+ return out;
+}
+
+fragment float4 clear_rect_fragment(ColorInOut in [[stage_in]])
+{
+ return in.color;
+};