summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Justfile4
-rw-r--r--alligator.wgsl90
-rw-r--r--alligator_backend.libbin625152 -> 0 bytes
-rw-r--r--shader.hlsl125
-rw-r--r--shader.metal155
-rw-r--r--shader.vert110
-rw-r--r--src/main.rs19
-rw-r--r--sys/alligator_backend.libbin625152 -> 0 bytes
-rw-r--r--sys/build.rs7
-rw-r--r--sys/src/lib.rs32
-rw-r--r--sys/src/window.rs25
11 files changed, 535 insertions, 32 deletions
diff --git a/Justfile b/Justfile
new file mode 100644
index 0000000..e3e37c2
--- /dev/null
+++ b/Justfile
@@ -0,0 +1,4 @@
+set shell := ["cmd.exe", "/c"]
+
+build:
+ cargo install --path . --debug --target-dir target \ No newline at end of file
diff --git a/alligator.wgsl b/alligator.wgsl
new file mode 100644
index 0000000..319db89
--- /dev/null
+++ b/alligator.wgsl
@@ -0,0 +1,90 @@
+const SQRT_2: f32 = 0.70710678118654757;
+
+struct VertexInput {
+ @location(0) position: vec2<f32>,
+ @location(1) curve_uv: vec2<f32>,
+ @location(2) color_uv: vec2<f32>,
+ @location(3) color1: vec4<f32>,
+ @location(4) color2: vec4<f32>,
+ @location(5) color3: vec4<f32>,
+ @location(6) color4: vec4<f32>,
+ @location(7) normal_uv: vec2<f32>,
+ @location(8) normal1: vec3<f32>,
+ @location(9) normal2: vec3<f32>,
+ @location(10) normal3: vec3<f32>,
+ @location(11) normal4: vec3<f32>,
+}
+
+struct VertexOutput {
+ @builtin(position) position: vec4<f32>,
+ @location(0) curve_uv: vec2<f32>,
+ @location(1) color_uv: vec2<f32>,
+ @location(2) color1: vec4<f32>,
+ @location(3) color2: vec4<f32>,
+ @location(4) color3: vec4<f32>,
+ @location(5) color4: vec4<f32>,
+ @location(6) normal_uv: vec2<f32>,
+ @location(7) normal1: vec3<f32>,
+ @location(8) normal2: vec3<f32>,
+ @location(9) normal3: vec3<f32>,
+ @location(10) normal4: vec3<f32>,
+}
+
+fn square(in: f32) -> f32 {
+ return in * in;
+}
+
+fn cube(in: f32) -> f32 {
+ return in * in * in;
+}
+
+fn lerp(a: vec3<f32>, b: vec3<f32>, t: f32) -> vec3<f32> {
+ return (b - a) * t + a;
+}
+
+fn oklab_to_linear_srgb(color: vec3<f32>) -> vec3<f32> {
+ let l = cube(color.r + 0.3963377774 * color.g + 0.2158037573 * color.b);
+ let m = cube(color.r - 0.1055613458 * color.g - 0.0638541728 * color.b);
+ let s = cube(color.r - 0.0894841775 * color.g - 1.2914855480 * color.b);
+
+ return vec3<f32>(
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
+ -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,
+ );
+}
+
+@vertex
+fn vs_main(vertex: VertexInput) -> VertexOutput {
+ var out: VertexOutput;
+ out.position = vec4(vertex.position, 1.0, 1.0);
+ out.curve_uv = vertex.curve_uv;
+ out.color_uv = vertex.color_uv;
+ out.color1 = vertex.color1;
+ out.color2 = vertex.color2;
+ out.color3 = vertex.color3;
+ out.color4 = vertex.color4;
+ out.normal_uv = vertex.normal_uv;
+ out.normal1 = vertex.normal1;
+ out.normal2 = vertex.normal2;
+ out.normal3 = vertex.normal3;
+ out.normal4 = vertex.normal4;
+ return out;
+}
+
+@fragment
+fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
+ let radius = length(vertex.curve_uv);
+ let afwidth = length(vec2(dpdxFine(radius), dpdyFine(radius))) * SQRT_2;
+ let in_circle = 1.0 - smoothstep(1.0 - afwidth, 1.0 + afwidth, radius);
+
+ let inside_color = oklab_to_linear_srgb(lerp(vertex.color1.rgb, vertex.color2.rgb, length(vertex.color_uv)));
+ let outside_color = oklab_to_linear_srgb(lerp(vertex.color3.rgb, vertex.color4.rgb, 1.0 - length(vertex.color_uv)));
+ let color = lerp(outside_color, inside_color, in_circle);
+
+ let inside_normal = lerp(vertex.normal1, vertex.normal2, length(vertex.normal_uv));
+ let outside_normal = lerp(vertex.normal3, vertex.normal4, 1.0 - length(vertex.normal_uv));
+ let normal = lerp(outside_normal, inside_normal, in_circle);
+
+ return vec4<f32>(color, in_circle);
+} \ No newline at end of file
diff --git a/alligator_backend.lib b/alligator_backend.lib
deleted file mode 100644
index 1b79670..0000000
--- a/alligator_backend.lib
+++ /dev/null
Binary files differ
diff --git a/shader.hlsl b/shader.hlsl
new file mode 100644
index 0000000..00bed12
--- /dev/null
+++ b/shader.hlsl
@@ -0,0 +1,125 @@
+struct VertexInput {
+ float2 position : LOC0;
+ float2 curve_uv : LOC1;
+ float2 color_uv : LOC2;
+ float4 color1_ : LOC3;
+ float4 color2_ : LOC4;
+ float4 color3_ : LOC5;
+ float4 color4_ : LOC6;
+ float2 normal_uv : LOC7;
+ float3 normal1_ : LOC8;
+ float3 normal2_ : LOC9;
+ float3 normal3_ : LOC10;
+ float3 normal4_ : LOC11;
+};
+
+struct VertexOutput {
+ float4 position : SV_Position;
+ float2 curve_uv : LOC0;
+ float2 color_uv : LOC1;
+ float4 color1_ : LOC2;
+ float4 color2_ : LOC3;
+ float4 color3_ : LOC4;
+ float4 color4_ : LOC5;
+ float2 normal_uv : LOC6;
+ float3 normal1_ : LOC7;
+ float3 normal2_ : LOC8;
+ float3 normal3_ : LOC9;
+ float3 normal4_ : LOC10;
+};
+
+static const float SQRT_2_ = 0.70710677;
+
+struct VertexOutput_vs_main {
+ float2 curve_uv : LOC0;
+ float2 color_uv : LOC1;
+ float4 color1_ : LOC2;
+ float4 color2_ : LOC3;
+ float4 color3_ : LOC4;
+ float4 color4_ : LOC5;
+ float2 normal_uv : LOC6;
+ float3 normal1_ : LOC7;
+ float3 normal2_ : LOC8;
+ float3 normal3_ : LOC9;
+ float3 normal4_ : LOC10;
+ float4 position : SV_Position;
+};
+
+struct FragmentInput_fs_main {
+ float2 curve_uv_1 : LOC0;
+ float2 color_uv_1 : LOC1;
+ float4 color1_1 : LOC2;
+ float4 color2_1 : LOC3;
+ float4 color3_1 : LOC4;
+ float4 color4_1 : LOC5;
+ float2 normal_uv_1 : LOC6;
+ float3 normal1_1 : LOC7;
+ float3 normal2_1 : LOC8;
+ float3 normal3_1 : LOC9;
+ float3 normal4_1 : LOC10;
+ float4 position_1 : SV_Position;
+};
+
+float square(float in_)
+{
+ return (in_ * in_);
+}
+
+float cube(float in_1)
+{
+ return ((in_1 * in_1) * in_1);
+}
+
+float3 lerp_(float3 a, float3 b, float t)
+{
+ return (((b - a) * t) + a);
+}
+
+float3 oklab_to_linear_srgb(float3 color)
+{
+ const float _e10 = cube(((color.x + (0.39633778 * color.y)) + (0.21580376 * color.z)));
+ const float _e20 = cube(((color.x - (0.105561346 * color.y)) - (0.06385417 * color.z)));
+ const float _e30 = cube(((color.x - (0.08948418 * color.y)) - (1.2914855 * color.z)));
+ return float3((((4.0767417 * _e10) - (3.3077116 * _e20)) + (0.23096994 * _e30)), (((-1.268438 * _e10) + (2.6097574 * _e20)) - (0.34131938 * _e30)), (((-0.0041960864 * _e10) - (0.7034186 * _e20)) + (1.7076147 * _e30)));
+}
+
+VertexOutput_vs_main vs_main(VertexInput vertex)
+{
+ VertexOutput out_ = (VertexOutput)0;
+
+ out_.position = float4(vertex.position, 1.0, 1.0);
+ out_.curve_uv = vertex.curve_uv;
+ out_.color_uv = vertex.color_uv;
+ out_.color1_ = vertex.color1_;
+ out_.color2_ = vertex.color2_;
+ out_.color3_ = vertex.color3_;
+ out_.color4_ = vertex.color4_;
+ out_.normal_uv = vertex.normal_uv;
+ out_.normal1_ = vertex.normal1_;
+ out_.normal2_ = vertex.normal2_;
+ out_.normal3_ = vertex.normal3_;
+ out_.normal4_ = vertex.normal4_;
+ VertexOutput _e29 = out_;
+ const VertexOutput vertexoutput = _e29;
+ const VertexOutput_vs_main vertexoutput_1 = { vertexoutput.curve_uv, vertexoutput.color_uv, vertexoutput.color1_, vertexoutput.color2_, vertexoutput.color3_, vertexoutput.color4_, vertexoutput.normal_uv, vertexoutput.normal1_, vertexoutput.normal2_, vertexoutput.normal3_, vertexoutput.normal4_, vertexoutput.position };
+ return vertexoutput_1;
+}
+
+float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
+{
+ VertexOutput vertex_1 = { fragmentinput_fs_main.position_1, fragmentinput_fs_main.curve_uv_1, fragmentinput_fs_main.color_uv_1, fragmentinput_fs_main.color1_1, fragmentinput_fs_main.color2_1, fragmentinput_fs_main.color3_1, fragmentinput_fs_main.color4_1, fragmentinput_fs_main.normal_uv_1, fragmentinput_fs_main.normal1_1, fragmentinput_fs_main.normal2_1, fragmentinput_fs_main.normal3_1, fragmentinput_fs_main.normal4_1 };
+ float radius = length(vertex_1.curve_uv);
+ float _e3 = ddx_fine(radius);
+ float _e4 = ddy_fine(radius);
+ float afwidth = (length(float2(_e3, _e4)) * SQRT_2_);
+ float in_circle = (1.0 - smoothstep((1.0 - afwidth), (1.0 + afwidth), radius));
+ const float3 _e22 = lerp_(vertex_1.color1_.xyz, vertex_1.color2_.xyz, length(vertex_1.color_uv));
+ const float3 _e23 = oklab_to_linear_srgb(_e22);
+ const float3 _e32 = lerp_(vertex_1.color3_.xyz, vertex_1.color4_.xyz, (1.0 - length(vertex_1.color_uv)));
+ const float3 _e33 = oklab_to_linear_srgb(_e32);
+ const float3 _e34 = lerp_(_e33, _e23, in_circle);
+ const float3 _e39 = lerp_(vertex_1.normal1_, vertex_1.normal2_, length(vertex_1.normal_uv));
+ const float3 _e46 = lerp_(vertex_1.normal3_, vertex_1.normal4_, (1.0 - length(vertex_1.normal_uv)));
+ const float3 _e47 = lerp_(_e46, _e39, in_circle);
+ return float4(_e34, in_circle);
+}
diff --git a/shader.metal b/shader.metal
new file mode 100644
index 0000000..3b5943c
--- /dev/null
+++ b/shader.metal
@@ -0,0 +1,155 @@
+// language: metal1.0
+#include <metal_stdlib>
+#include <simd/simd.h>
+
+using metal::uint;
+
+struct VertexInput {
+ metal::float2 position;
+ metal::float2 curve_uv;
+ metal::float2 color_uv;
+ char _pad3[8];
+ metal::float4 color1_;
+ metal::float4 color2_;
+ metal::float4 color3_;
+ metal::float4 color4_;
+ metal::float2 normal_uv;
+ char _pad8[8];
+ metal::float3 normal1_;
+ metal::float3 normal2_;
+ metal::float3 normal3_;
+ metal::float3 normal4_;
+};
+struct VertexOutput {
+ metal::float4 position;
+ metal::float2 curve_uv;
+ metal::float2 color_uv;
+ metal::float4 color1_;
+ metal::float4 color2_;
+ metal::float4 color3_;
+ metal::float4 color4_;
+ metal::float2 normal_uv;
+ char _pad8[8];
+ metal::float3 normal1_;
+ metal::float3 normal2_;
+ metal::float3 normal3_;
+ metal::float3 normal4_;
+};
+constant float SQRT_2_ = 0.70710677;
+
+float square(
+ float in
+) {
+ return in * in;
+}
+
+float cube(
+ float in_1
+) {
+ return (in_1 * in_1) * in_1;
+}
+
+metal::float3 lerp(
+ metal::float3 a,
+ metal::float3 b,
+ float t
+) {
+ return ((b - a) * t) + a;
+}
+
+metal::float3 oklab_to_linear_srgb(
+ metal::float3 color
+) {
+ float _e10 = cube((color.x + (0.39633778 * color.y)) + (0.21580376 * color.z));
+ float _e20 = cube((color.x - (0.105561346 * color.y)) - (0.06385417 * color.z));
+ float _e30 = cube((color.x - (0.08948418 * color.y)) - (1.2914855 * color.z));
+ return metal::float3(((4.0767417 * _e10) - (3.3077116 * _e20)) + (0.23096994 * _e30), ((-1.268438 * _e10) + (2.6097574 * _e20)) - (0.34131938 * _e30), ((-0.0041960864 * _e10) - (0.7034186 * _e20)) + (1.7076147 * _e30));
+}
+
+struct vs_mainInput {
+ metal::float2 position [[attribute(0)]];
+ metal::float2 curve_uv [[attribute(1)]];
+ metal::float2 color_uv [[attribute(2)]];
+ metal::float4 color1_ [[attribute(3)]];
+ metal::float4 color2_ [[attribute(4)]];
+ metal::float4 color3_ [[attribute(5)]];
+ metal::float4 color4_ [[attribute(6)]];
+ metal::float2 normal_uv [[attribute(7)]];
+ metal::float3 normal1_ [[attribute(8)]];
+ metal::float3 normal2_ [[attribute(9)]];
+ metal::float3 normal3_ [[attribute(10)]];
+ metal::float3 normal4_ [[attribute(11)]];
+};
+struct vs_mainOutput {
+ metal::float4 position [[position]];
+ metal::float2 curve_uv [[user(loc0), center_perspective]];
+ metal::float2 color_uv [[user(loc1), center_perspective]];
+ metal::float4 color1_ [[user(loc2), center_perspective]];
+ metal::float4 color2_ [[user(loc3), center_perspective]];
+ metal::float4 color3_ [[user(loc4), center_perspective]];
+ metal::float4 color4_ [[user(loc5), center_perspective]];
+ metal::float2 normal_uv [[user(loc6), center_perspective]];
+ metal::float3 normal1_ [[user(loc7), center_perspective]];
+ metal::float3 normal2_ [[user(loc8), center_perspective]];
+ metal::float3 normal3_ [[user(loc9), center_perspective]];
+ metal::float3 normal4_ [[user(loc10), center_perspective]];
+};
+vertex vs_mainOutput vs_main(
+ vs_mainInput varyings [[stage_in]]
+) {
+ const VertexInput vertex_ = { varyings.position, varyings.curve_uv, varyings.color_uv, {}, varyings.color1_, varyings.color2_, varyings.color3_, varyings.color4_, varyings.normal_uv, {}, varyings.normal1_, varyings.normal2_, varyings.normal3_, varyings.normal4_ };
+ VertexOutput out = {};
+ out.position = metal::float4(vertex_.position, 1.0, 1.0);
+ out.curve_uv = vertex_.curve_uv;
+ out.color_uv = vertex_.color_uv;
+ out.color1_ = vertex_.color1_;
+ out.color2_ = vertex_.color2_;
+ out.color3_ = vertex_.color3_;
+ out.color4_ = vertex_.color4_;
+ out.normal_uv = vertex_.normal_uv;
+ out.normal1_ = vertex_.normal1_;
+ out.normal2_ = vertex_.normal2_;
+ out.normal3_ = vertex_.normal3_;
+ out.normal4_ = vertex_.normal4_;
+ VertexOutput _e29 = out;
+ const auto _tmp = _e29;
+ return vs_mainOutput { _tmp.position, _tmp.curve_uv, _tmp.color_uv, _tmp.color1_, _tmp.color2_, _tmp.color3_, _tmp.color4_, _tmp.normal_uv, _tmp.normal1_, _tmp.normal2_, _tmp.normal3_, _tmp.normal4_ };
+}
+
+
+struct fs_mainInput {
+ metal::float2 curve_uv [[user(loc0), center_perspective]];
+ metal::float2 color_uv [[user(loc1), center_perspective]];
+ metal::float4 color1_ [[user(loc2), center_perspective]];
+ metal::float4 color2_ [[user(loc3), center_perspective]];
+ metal::float4 color3_ [[user(loc4), center_perspective]];
+ metal::float4 color4_ [[user(loc5), center_perspective]];
+ metal::float2 normal_uv [[user(loc6), center_perspective]];
+ metal::float3 normal1_ [[user(loc7), center_perspective]];
+ metal::float3 normal2_ [[user(loc8), center_perspective]];
+ metal::float3 normal3_ [[user(loc9), center_perspective]];
+ metal::float3 normal4_ [[user(loc10), center_perspective]];
+};
+struct fs_mainOutput {
+ metal::float4 member_1 [[color(0)]];
+};
+fragment fs_mainOutput fs_main(
+ fs_mainInput varyings_1 [[stage_in]]
+, metal::float4 position [[position]]
+) {
+ const VertexOutput vertex_1 = { position, varyings_1.curve_uv, varyings_1.color_uv, varyings_1.color1_, varyings_1.color2_, varyings_1.color3_, varyings_1.color4_, varyings_1.normal_uv, {}, varyings_1.normal1_, varyings_1.normal2_, varyings_1.normal3_, varyings_1.normal4_ };
+ float radius = metal::length(vertex_1.curve_uv);
+ float _e3 = metal::dfdx(radius);
+ float _e4 = metal::dfdy(radius);
+ float afwidth = metal::length(metal::float2(_e3, _e4)) * SQRT_2_;
+ float in_circle = 1.0 - metal::smoothstep(1.0 - afwidth, 1.0 + afwidth, radius);
+ metal::float3 _e22 = lerp(vertex_1.color1_.xyz, vertex_1.color2_.xyz, metal::length(vertex_1.color_uv));
+ metal::float3 _e23 = oklab_to_linear_srgb(_e22);
+ metal::float3 _e32 = lerp(vertex_1.color3_.xyz, vertex_1.color4_.xyz, 1.0 - metal::length(vertex_1.color_uv));
+ metal::float3 _e33 = oklab_to_linear_srgb(_e32);
+ metal::float3 _e34 = lerp(_e33, _e23, in_circle);
+ metal::float3 _e39 = lerp(vertex_1.normal1_, vertex_1.normal2_, metal::length(vertex_1.normal_uv));
+ metal::float3 _e46 = lerp(vertex_1.normal3_, vertex_1.normal4_, 1.0 - metal::length(vertex_1.normal_uv));
+ metal::float3 _e47 = lerp(_e46, _e39, in_circle);
+ return fs_mainOutput { metal::float4(_e34, in_circle) };
+}
diff --git a/shader.vert b/shader.vert
new file mode 100644
index 0000000..7179918
--- /dev/null
+++ b/shader.vert
@@ -0,0 +1,110 @@
+#version 310 es
+
+precision highp float;
+precision highp int;
+
+struct VertexInput {
+ vec2 position;
+ vec2 curve_uv;
+ vec2 color_uv;
+ vec4 color1_;
+ vec4 color2_;
+ vec4 color3_;
+ vec4 color4_;
+ vec2 normal_uv;
+ vec3 normal1_;
+ vec3 normal2_;
+ vec3 normal3_;
+ vec3 normal4_;
+};
+struct VertexOutput {
+ vec4 position;
+ vec2 curve_uv;
+ vec2 color_uv;
+ vec4 color1_;
+ vec4 color2_;
+ vec4 color3_;
+ vec4 color4_;
+ vec2 normal_uv;
+ vec3 normal1_;
+ vec3 normal2_;
+ vec3 normal3_;
+ vec3 normal4_;
+};
+const float SQRT_2_ = 0.70710677;
+
+layout(location = 0) in vec2 _p2vs_location0;
+layout(location = 1) in vec2 _p2vs_location1;
+layout(location = 2) in vec2 _p2vs_location2;
+layout(location = 3) in vec4 _p2vs_location3;
+layout(location = 4) in vec4 _p2vs_location4;
+layout(location = 5) in vec4 _p2vs_location5;
+layout(location = 6) in vec4 _p2vs_location6;
+layout(location = 7) in vec2 _p2vs_location7;
+layout(location = 8) in vec3 _p2vs_location8;
+layout(location = 9) in vec3 _p2vs_location9;
+layout(location = 10) in vec3 _p2vs_location10;
+layout(location = 11) in vec3 _p2vs_location11;
+layout(location = 0) smooth out vec2 _vs2fs_location0;
+layout(location = 1) smooth out vec2 _vs2fs_location1;
+layout(location = 2) smooth out vec4 _vs2fs_location2;
+layout(location = 3) smooth out vec4 _vs2fs_location3;
+layout(location = 4) smooth out vec4 _vs2fs_location4;
+layout(location = 5) smooth out vec4 _vs2fs_location5;
+layout(location = 6) smooth out vec2 _vs2fs_location6;
+layout(location = 7) smooth out vec3 _vs2fs_location7;
+layout(location = 8) smooth out vec3 _vs2fs_location8;
+layout(location = 9) smooth out vec3 _vs2fs_location9;
+layout(location = 10) smooth out vec3 _vs2fs_location10;
+
+float square(float in_) {
+ return (in_ * in_);
+}
+
+float cube(float in_1) {
+ return ((in_1 * in_1) * in_1);
+}
+
+vec3 lerp(vec3 a, vec3 b, float t) {
+ return (((b - a) * t) + a);
+}
+
+vec3 oklab_to_linear_srgb(vec3 color) {
+ float _e10 = cube(((color.x + (0.39633778 * color.y)) + (0.21580376 * color.z)));
+ float _e20 = cube(((color.x - (0.105561346 * color.y)) - (0.06385417 * color.z)));
+ float _e30 = cube(((color.x - (0.08948418 * color.y)) - (1.2914855 * color.z)));
+ return vec3((((4.0767417 * _e10) - (3.3077116 * _e20)) + (0.23096994 * _e30)), (((-1.268438 * _e10) + (2.6097574 * _e20)) - (0.34131938 * _e30)), (((-0.0041960864 * _e10) - (0.7034186 * _e20)) + (1.7076147 * _e30)));
+}
+
+void main() {
+ VertexInput vertex = VertexInput(_p2vs_location0, _p2vs_location1, _p2vs_location2, _p2vs_location3, _p2vs_location4, _p2vs_location5, _p2vs_location6, _p2vs_location7, _p2vs_location8, _p2vs_location9, _p2vs_location10, _p2vs_location11);
+ VertexOutput out_ = VertexOutput(vec4(0.0), vec2(0.0), vec2(0.0), vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0), vec2(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
+ out_.position = vec4(vertex.position, 1.0, 1.0);
+ out_.curve_uv = vertex.curve_uv;
+ out_.color_uv = vertex.color_uv;
+ out_.color1_ = vertex.color1_;
+ out_.color2_ = vertex.color2_;
+ out_.color3_ = vertex.color3_;
+ out_.color4_ = vertex.color4_;
+ out_.normal_uv = vertex.normal_uv;
+ out_.normal1_ = vertex.normal1_;
+ out_.normal2_ = vertex.normal2_;
+ out_.normal3_ = vertex.normal3_;
+ out_.normal4_ = vertex.normal4_;
+ VertexOutput _e29 = out_;
+ gl_Position = _e29.position;
+ _vs2fs_location0 = _e29.curve_uv;
+ _vs2fs_location1 = _e29.color_uv;
+ _vs2fs_location2 = _e29.color1_;
+ _vs2fs_location3 = _e29.color2_;
+ _vs2fs_location4 = _e29.color3_;
+ _vs2fs_location5 = _e29.color4_;
+ _vs2fs_location6 = _e29.normal_uv;
+ _vs2fs_location7 = _e29.normal1_;
+ _vs2fs_location8 = _e29.normal2_;
+ _vs2fs_location9 = _e29.normal3_;
+ _vs2fs_location10 = _e29.normal4_;
+ gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
+ return;
+}
+
diff --git a/src/main.rs b/src/main.rs
index 100cfea..2bd4da5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -61,10 +61,10 @@ pub struct Config {
scripts: HashMap<String, ConfigScript>,
default_scene: String,
sprite_manager_capacity: u32,
- default_window_width: Option<NonZeroU32>,
- default_window_height: Option<NonZeroU32>,
+ default_window_width: NonZeroU32,
+ default_window_height: NonZeroU32,
default_window_mode: ConfigWindowMode,
- window_title: String,
+ window_title: Option<String>,
vsync: bool,
}
@@ -113,8 +113,8 @@ fn window(config: &Config) -> Window {
let config = WindowConfig {
title: config.window_title.clone(),
// TODO set window size properly
- default_width: config.default_window_width.unwrap().get(),
- default_height: config.default_window_height.unwrap().get(),
+ default_width: config.default_window_width,
+ default_height: config.default_window_height,
default_x: 200,
default_y: 200,
borderless_fullscreen: config.default_window_mode == ConfigWindowMode::BorderlessFullscreen,
@@ -126,11 +126,8 @@ fn window(config: &Config) -> Window {
fn renderer(config: &Config, window: &Window) -> Renderer {
let config = RendererConfig {
- // TODO set window size properly
- width: config.default_window_width.unwrap().get(),
- height: config.default_window_height.unwrap().get(),
- instance_capacity: config.sprite_manager_capacity,
- fullscreen: false,
+ width: config.default_window_width.get(),
+ height: config.default_window_height.get(),
vsync: config.vsync,
};
@@ -155,7 +152,7 @@ fn main() {
//std::env::set_current_dir(std::env::current_exe().unwrap().parent().unwrap()).unwrap();
- let config = match args.config {
+ let config: Config = match args.config {
Some(config) => serde_json::from_str(&config).unwrap(),
None => {
let config = File::open("game.json").unwrap();
diff --git a/sys/alligator_backend.lib b/sys/alligator_backend.lib
deleted file mode 100644
index 1b79670..0000000
--- a/sys/alligator_backend.lib
+++ /dev/null
Binary files differ
diff --git a/sys/build.rs b/sys/build.rs
index 8efc265..1703b4a 100644
--- a/sys/build.rs
+++ b/sys/build.rs
@@ -1,8 +1,5 @@
fn main() {
- let out_dir = std::env::var("OUT_DIR").unwrap();
- eprintln!("{out_dir}");
- println!("cargo:rustc-link-lib=d3d11");
- println!("cargo:rustc-link-search=native=./");
- println!("cargo:rustc-link-lib-static=alligator_backend");
+ println!("cargo:rustc-link-lib=static=alligator_backend");
+ println!("cargo:rustc-link-search=native=C:\\Users\\epice\\source\\repos\\WindowsAlligatorBackend\\x64\\Debug\\");
println!("cargo:rerun-if-changed=alligator_backend.lib");
}
diff --git a/sys/src/lib.rs b/sys/src/lib.rs
index ddce186..6d20488 100644
--- a/sys/src/lib.rs
+++ b/sys/src/lib.rs
@@ -1,4 +1,5 @@
-use std::ffi::{c_uchar, c_uint, c_void};
+use std::ffi::{c_int, c_uint, c_void};
+use std::num::NonZeroU32;
use std::os::raw::c_char;
mod renderer;
@@ -9,18 +10,24 @@ pub use window::{Window, WindowConfig, WindowEvent};
type CRenderer = *mut ();
type CWindow = *mut ();
+type CVertexBuffer = c_int;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub struct RendererConfig {
pub width: c_uint,
pub height: c_uint,
- pub instance_capacity: c_uint,
- pub fullscreen: bool,
pub vsync: bool,
}
#[repr(C)]
+pub struct DrawCommand {
+ vertex_count: c_uint,
+ start: c_uint,
+ end: c_uint,
+}
+
+#[repr(C)]
pub struct Vertex {
x: f32,
y: f32,
@@ -31,9 +38,6 @@ pub struct Vertex {
color1_g: f32,
color1_b: f32,
color1_a: f32,
- normal_x: f32,
- normal_y: f32,
- normal_z: f32,
}
#[derive(Debug, Clone, Copy)]
@@ -63,8 +67,8 @@ pub enum CWindowEvent {
extern "C" {
fn new_renderer(config: RendererConfig, window: CWindow) -> CRenderer;
fn resize_renderer(renderer: CRenderer, width: c_uint, height: c_uint);
+ fn is_vsync_available(renderer: CRenderer) -> bool;
fn set_vsync(renderer: CRenderer, vsync: bool);
- //fn create_vertex_buffer(renderer: CRenderer, count: c_uint, instances: *const Vertex);
fn set_camera(
renderer: CRenderer,
x: f32,
@@ -74,6 +78,12 @@ extern "C" {
width: f32,
height: f32,
);
+ //fn create_mesh(
+ // renderer: CRenderer,
+ // vertex_count: c_uint,
+ // vertices: *const Vertex,
+ //) -> CVertexBuffer;
+ fn destroy_vertex_buffer(renderer: CRenderer, buffer: CVertexBuffer);
fn render_frame(renderer: CRenderer);
fn destroy_renderer(renderer: CRenderer);
@@ -96,3 +106,11 @@ unsafe extern "C" fn alligator_run_closure(closure: *mut c_void, event: CWindowE
let closure: &mut &mut dyn FnMut(CWindowEvent) = unsafe { &mut *closure.cast() };
closure(event)
}
+
+// avoid linking errors in windows
+
+#[no_mangle]
+extern "C" fn __imp__CrtDbgReport() {}
+
+#[no_mangle]
+extern "C" fn __imp__invalid_parameter() {}
diff --git a/sys/src/window.rs b/sys/src/window.rs
index f9a8832..e66747d 100644
--- a/sys/src/window.rs
+++ b/sys/src/window.rs
@@ -1,13 +1,13 @@
-use std::ffi::{c_void, CString};
-use std::ops::ControlFlow;
+use std::ffi::CString;
+use std::num::NonZeroU32;
use crate::{CWindowConfig, CWindowEvent};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WindowConfig {
- pub title: String,
- pub default_width: u32,
- pub default_height: u32,
+ pub title: Option<String>,
+ pub default_width: NonZeroU32,
+ pub default_height: NonZeroU32,
pub default_x: u32,
pub default_y: u32,
pub visible: bool,
@@ -34,18 +34,24 @@ impl Drop for Window {
impl Window {
pub fn new(config: WindowConfig) -> Self {
- let title = CString::new(config.title.as_bytes()).unwrap();
+ let title = config
+ .title
+ .map(|title| CString::new(title.as_bytes()).unwrap());
let config = CWindowConfig {
- default_width: config.default_width,
- default_height: config.default_height,
+ default_width: config.default_width.get(),
+ default_height: config.default_height.get(),
default_x: config.default_x,
default_y: config.default_y,
visible: config.visible,
borderless_fullscreen: config.borderless_fullscreen,
- title: title.as_ptr(),
+ title: title
+ .as_ref()
+ .map(|title| title.as_ptr())
+ .unwrap_or(std::ptr::null()),
};
let window = unsafe { crate::create_window(config) };
+ drop(title);
Self { ptr: window }
}
@@ -58,6 +64,7 @@ impl Window {
let string = CString::new(title.to_string().as_bytes()).unwrap();
let bytes = string.as_ptr();
unsafe { crate::set_title(self.ptr, bytes) }
+ drop(string);
}
pub fn resize(&mut self, width: u32, height: u32) {