aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralaric <alaric@netmythos.org>2024-04-10 03:42:23 -0700
committeralaric <alaric@netmythos.org>2024-04-10 06:30:57 -0700
commitc89aa3b181e253f5980478ad4157912cd23fab72 (patch)
treebad17de162381bdbc26c91cbe91dd8eac262a4ff
parente1ff0e3d124151c4c965f4d731c795d31732e42e (diff)
downloadengine-c89aa3b181e253f5980478ad4157912cd23fab72.tar.gz
engine-c89aa3b181e253f5980478ad4157912cd23fab72.zip
feat: mouse input and vec2 shader input buffers
-rw-r--r--src/engine.zig4
-rw-r--r--src/input.zig4
-rw-r--r--src/matrix.zig4
-rw-r--r--src/shell/shell.html1
-rw-r--r--src/wasm.zig2
-rw-r--r--src/webgl.zig10
6 files changed, 19 insertions, 6 deletions
diff --git a/src/engine.zig b/src/engine.zig
index ba268d1..3c22ae5 100644
--- a/src/engine.zig
+++ b/src/engine.zig
@@ -55,6 +55,10 @@ pub const Color = struct {
return .{ self.r, self.g, self.b, self.a };
}
+ pub fn rgbFromScalar(v: f32) Color {
+ return .{ .r = v, .g = v, .b = v };
+ }
+
pub fn interpolate(comptime EaseFn: *const fn (f32) f32, lhs: Color, rhs: Color, pct: f32) Color {
const l = lhs.toVec();
const r = rhs.toVec();
diff --git a/src/input.zig b/src/input.zig
index bbdb897..870bca5 100644
--- a/src/input.zig
+++ b/src/input.zig
@@ -1,10 +1,10 @@
const root = @import("root");
pub const InputEvent = union(enum) {
- mouseInput: MouseInput,
+ mouse: MouseInfo,
};
-pub const MouseInput = struct {
+pub const MouseInfo = struct {
pos: [2]f32,
delta: [2]f32 = .{ 0, 0 },
buttons: MouseButtons,
diff --git a/src/matrix.zig b/src/matrix.zig
index 0221e36..355369e 100644
--- a/src/matrix.zig
+++ b/src/matrix.zig
@@ -87,6 +87,10 @@ pub fn Matrix(comptime T: type, row_count: usize, col_count: usize) type {
return base;
}
+ pub fn scaled(self: Self, vals: [@min(rows, cols) - 1]f32) Self {
+ return self.multiply(Self.scale(vals));
+ }
+
pub fn scale(vals: [@min(rows, cols) - 1]f32) Self {
var r = identity;
for (vals, 0..) |v, i| {
diff --git a/src/shell/shell.html b/src/shell/shell.html
index 26ace53..7f91847 100644
--- a/src/shell/shell.html
+++ b/src/shell/shell.html
@@ -20,6 +20,7 @@
height: 100%;
width: 1280px;
height: 720px;
+ max-height: 720px;
}
</style>
</head>
diff --git a/src/wasm.zig b/src/wasm.zig
index e5bce13..61c3fb2 100644
--- a/src/wasm.zig
+++ b/src/wasm.zig
@@ -29,7 +29,7 @@ export fn mouseEvent(
const pos = .{ x, y };
const delta = .{ dx, dy };
const buttons: input.MouseButtons = @bitCast(@as(u5, @intCast(btns)));
- handleInput(.{ .mouseInput = .{
+ handleInput(.{ .mouse = .{
.pos = pos,
.delta = delta,
.buttons = buttons,
diff --git a/src/webgl.zig b/src/webgl.zig
index 72afe89..abd9df4 100644
--- a/src/webgl.zig
+++ b/src/webgl.zig
@@ -7,7 +7,7 @@ const Mat4 = matrix.Matrix(f32, 4, 4);
const Color = engine.Color;
-const ShaderType = enum { vec3 };
+const ShaderType = enum { vec2, vec3 };
const UniformInfo = struct {
identifier: [:0]const u8,
@@ -38,7 +38,7 @@ pub const Buffer = struct {
handle: u32,
const Self = @This();
- pub fn create() Self {
+ pub fn init() Self {
return .{ .handle = bindings.createBuffer() };
}
@@ -48,6 +48,7 @@ pub const Buffer = struct {
fn FillDataType(comptime shader_type: ShaderType) type {
return switch (shader_type) {
+ .vec2 => []const [2]f32,
.vec3 => []const [3]f32,
};
}
@@ -61,6 +62,9 @@ pub const Buffer = struct {
) void {
bindings.bindBuffer(target, self.handle);
switch (kind) {
+ .vec2 => {
+ bindings.bufferData(target, @ptrCast(vals.ptr), vals.len * 2, usage_pattern);
+ },
.vec3 => {
bindings.bufferData(target, @ptrCast(vals.ptr), vals.len * 3, usage_pattern);
},
@@ -237,7 +241,7 @@ pub const General2DSolidProgram = Program(
.{ .identifier = "color", .shader_name = "color", .kind = .vec3 },
},
&.{
- .{ .identifier = "pos", .shader_name = "pos", .kind = .vec3 },
+ .{ .identifier = "pos", .shader_name = "pos", .kind = .vec2 },
},
);
pub fn createGeneral2DSolidProgram() !General2DSolidProgram {