aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2023-10-27 18:29:26 +0000
committers-ol <s+removethis@s-ol.nu>2023-10-29 22:43:58 +0000
commita250d5bbe6eb215e345de4900e784140dfe73161 (patch)
tree3a9f3aa116f7d0ac2faca30b6ceab6a110d6eef2
parentupdate for zig 0.9.0 (diff)
downloadglsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.tar.gz
glsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.zip
update for zig 0.11.0
-rw-r--r--build.zig26
-rw-r--r--src/config.zig42
-rw-r--r--src/control.zig50
-rw-r--r--src/debug_gl.zig6
-rw-r--r--src/gl.zig32
-rw-r--r--src/main.zig38
-rw-r--r--src/output.zig23
7 files changed, 115 insertions, 102 deletions
diff --git a/build.zig b/build.zig
index 851fc29..11015fb 100644
--- a/build.zig
+++ b/build.zig
@@ -1,19 +1,31 @@
-const Builder = @import("std").build.Builder;
+const std = @import("std");
-pub fn build(b: *Builder) void {
- const mode = b.standardReleaseOptions();
- const exe = b.addExecutable("t", "src/main.zig");
- exe.setBuildMode(mode);
+pub fn build(b: *std.Build) void {
+ const optimize = b.standardOptimizeOption(.{});
+ const target = b.standardTargetOptions(.{});
+
+ const exe = b.addExecutable(.{
+ .name = "glsl-view",
+ .root_source_file = .{
+ .path = "src/main.zig",
+ },
+ .target = target,
+ .optimize = optimize,
+ });
exe.linkLibC();
exe.linkSystemLibrary("yaml-0.1");
exe.linkSystemLibrary("glfw3");
exe.linkSystemLibrary("epoxy");
exe.linkSystemLibrary("liblo");
- exe.install();
+ b.installArtifact(exe);
- const run_cmd = exe.run();
+ const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
+ if (b.args) |args| {
+ run_cmd.addArgs(args);
+ }
+
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
diff --git a/src/config.zig b/src/config.zig
index 09008f1..166fdf4 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -52,7 +52,7 @@ pub const Config = struct {
parameters: []const ParameterConfig,
osc: OSCConfig,
- pub fn parse(allocator: *std.mem.Allocator, filename: []const u8) !Config {
+ pub fn parse(allocator: *const std.mem.Allocator, filename: []const u8) !Config {
var parser: c.yaml_parser_t = undefined;
_ = c.yaml_parser_initialize(&parser);
defer c.yaml_parser_delete(&parser);
@@ -100,12 +100,12 @@ pub const Config = struct {
} else if (std.mem.eql(u8, key, "osc")) {
config.osc = try parseOSC(&parser, allocator);
} else {
- debug.warn("unknown key: '{s}'\n", .{key});
+ debug.print("unknown key: '{s}'\n", .{key});
try skipAny(&parser);
}
},
else => {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
},
}
@@ -126,21 +126,21 @@ fn expectEvent(parser: *c.yaml_parser_t, expectedType: c.yaml_event_type_t) !voi
defer c.yaml_event_delete(&event);
if (event.type != expectedType) {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
}
}
-fn parseStringEvent(event: *c.yaml_event_t, allocator: *std.mem.Allocator) ![]const u8 {
+fn parseStringEvent(event: *c.yaml_event_t, allocator: *const std.mem.Allocator) ![]const u8 {
if (event.type != c.YAML_SCALAR_EVENT)
return error.InvalidType;
const data = event.data.scalar;
const value: []const u8 = data.value[0..data.length];
- return try std.mem.dupe(allocator, u8, value);
+ return try allocator.dupe(u8, value);
}
-fn parseString(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]const u8 {
+fn parseString(parser: *c.yaml_parser_t, allocator: *const std.mem.Allocator) ![]const u8 {
var event: c.yaml_event_t = undefined;
if (c.yaml_parser_parse(parser, &event) != 1)
return error.YAMLParserError;
@@ -200,7 +200,7 @@ fn parseBool(parser: *c.yaml_parser_t) !bool {
return std.mem.eql(u8, value, "true") or std.mem.eql(u8, value, "1");
}
-fn parseOutputs(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]OutputConfig {
+fn parseOutputs(parser: *c.yaml_parser_t, allocator: *const std.mem.Allocator) ![]OutputConfig {
try expectEvent(parser, c.YAML_SEQUENCE_START_EVENT);
var outputs = try allocator.alloc(OutputConfig, 1024);
@@ -241,12 +241,12 @@ fn parseOutputs(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]Outp
} else if (std.mem.eql(u8, key, "fullscreen")) {
output.*.fullscreen = try parseBool(parser);
} else {
- debug.warn("unknown key: '{s}'\n", .{key});
+ debug.print("unknown key: '{s}'\n", .{key});
try skipAny(parser);
}
},
else => {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
},
}
@@ -255,7 +255,7 @@ fn parseOutputs(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]Outp
output_count += 1;
},
else => {
- debug.warn("unexpected event: {}\n", .{seqEvent.type});
+ debug.print("unexpected event: {}\n", .{seqEvent.type});
return error.InvalidConfiguration;
},
}
@@ -265,7 +265,7 @@ fn parseOutputs(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]Outp
return outputs[0..output_count];
}
-fn parseParameters(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]ParameterConfig {
+fn parseParameters(parser: *c.yaml_parser_t, allocator: *const std.mem.Allocator) ![]ParameterConfig {
try expectEvent(parser, c.YAML_SEQUENCE_START_EVENT);
var parameters = try allocator.alloc(ParameterConfig, 1024);
@@ -303,26 +303,26 @@ fn parseParameters(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]P
param.*.type = try parseString(parser, allocator);
have_type = true;
} else {
- debug.warn("unknown key: '{s}'\n", .{key});
+ debug.print("unknown key: '{s}'\n", .{key});
try skipAny(parser);
}
},
else => {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
},
}
}
if (!(have_name and have_type)) {
- debug.warn("name and type are mandatory for parameters.\n", .{});
+ debug.print("name and type are mandatory for parameters.\n", .{});
return error.InvalidConfiguration;
}
param_count += 1;
},
else => {
- debug.warn("unexpected event: {}\n", .{seqEvent.type});
+ debug.print("unexpected event: {}\n", .{seqEvent.type});
return error.InvalidConfiguration;
},
}
@@ -332,7 +332,7 @@ fn parseParameters(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) ![]P
return parameters[0..param_count];
}
-fn parseOSC(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) !OSCConfig {
+fn parseOSC(parser: *c.yaml_parser_t, allocator: *const std.mem.Allocator) !OSCConfig {
var event: c.yaml_event_t = undefined;
if (c.yaml_parser_parse(parser, &event) != 1)
return error.YAMLParserError;
@@ -342,7 +342,7 @@ fn parseOSC(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) !OSCConfig
const url = try parseStringEvent(&event, allocator);
return OSCConfig{ .URL = url };
} else if (event.type != c.YAML_MAPPING_START_EVENT) {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
}
@@ -364,12 +364,12 @@ fn parseOSC(parser: *c.yaml_parser_t, allocator: *std.mem.Allocator) !OSCConfig
} else if (std.mem.eql(u8, key, "port")) {
config.Manual.port = try parseInt(parser, u16);
} else {
- debug.warn("unknown key: '{s}'\n", .{key});
+ debug.print("unknown key: '{s}'\n", .{key});
try skipAny(parser);
}
},
else => {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
},
}
@@ -406,7 +406,7 @@ fn skipAny(parser: *c.yaml_parser_t) !void {
},
else => {
- debug.warn("unexpected event: {}\n", .{event.type});
+ debug.print("unexpected event: {}\n", .{event.type});
return error.InvalidConfiguration;
},
}
diff --git a/src/control.zig b/src/control.zig
index 43c232e..d7ce531 100644
--- a/src/control.zig
+++ b/src/control.zig
@@ -6,7 +6,7 @@ const cfg = @import("config.zig");
fn verify_args(expected: u8, got: []const u8) !void {
for (got) |typ| {
if (typ != expected) {
- std.debug.warn("expected '{c}' but got '{c}' element (expected {s})\n", .{ expected, typ, got });
+ std.debug.print("expected '{c}' but got '{c}' element (expected {s})\n", .{ expected, typ, got });
return error.typeMismatch;
}
}
@@ -25,26 +25,26 @@ fn set_array(
switch (T) {
f32 => {
try verify_args('f', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.f;
},
f64 => {
try verify_args('d', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.d;
},
i32 => {
try verify_args('i', types);
- for (dest) |*v, i|
+ for (dest, 0..) |*v, i|
v.* = argv[i].*.i;
},
u32 => {
try verify_args('i', types);
- for (dest) |*v, i| {
+ for (dest, 0..) |*v, i| {
const val = argv[i].*.i;
if (val < 0)
return error.signDisallowed;
- v.* = @intCast(u32, argv[i].*.i);
+ v.* = @as(u32, @intCast(argv[i].*.i));
}
},
else => return error.invalidType,
@@ -54,13 +54,15 @@ fn set_array(
pub const ControlServer = struct {
server: c.lo_server,
cache: *gl.UniformCache,
+ allocator: std.mem.Allocator,
pub fn init(
- allocator: *std.mem.Allocator,
+ allocator: std.mem.Allocator,
config: cfg.OSCConfig,
cache: *gl.UniformCache,
) !*ControlServer {
var self: *ControlServer = try allocator.create(ControlServer);
+ self.allocator = allocator;
self.cache = cache;
switch (config) {
@@ -73,21 +75,21 @@ pub const ControlServer = struct {
.unix => c.LO_UNIX,
};
- std.debug.warn(
+ std.debug.print(
"listening for OSC messages on {} port {}\n",
.{ conf.protocol, conf.port },
);
self.server = c.lo_server_new_with_proto(port[0..], proto, handle_error);
},
.URL => |url| {
- std.debug.warn("listening for OSC messages at {s}\n", .{url});
+ std.debug.print("listening for OSC messages at {s}\n", .{url});
self.server = c.lo_server_new_from_url(url[0..].ptr, handle_error);
},
}
if (self.server == null)
return error.serverInitializationError;
- _ = c.lo_server_add_method(self.server, null, null, handle_method, @ptrCast(*c_void, self));
+ _ = c.lo_server_add_method(self.server, null, null, handle_method, @as(*anyopaque, @ptrCast(self)));
return self;
}
@@ -101,9 +103,9 @@ pub const ControlServer = struct {
}
fn handle_error(num: c_int, msg: [*c]const u8, where: [*c]const u8) callconv(.C) void {
- std.debug.warn(
+ std.debug.print(
"OSC error {} @ {s}: {s}\n",
- .{ num, @ptrCast([*:0]const u8, where), @ptrCast([*:0]const u8, msg) },
+ .{ num, @as([*:0]const u8, @ptrCast(where)), @as([*:0]const u8, @ptrCast(msg)) },
);
}
@@ -121,11 +123,11 @@ pub const ControlServer = struct {
const uniform = (try self.cache.get(name)) orelse return error.notFound;
try switch (uniform.value) {
- .FLOAT => |*val| set_array(f32, @ptrCast([*]f32, val)[0..1], argc, argv, types),
- .DOUBLE => |*val| set_array(f64, @ptrCast([*]f64, val)[0..1], argc, argv, types),
- .INT => |*val| set_array(i32, @ptrCast([*]i32, val)[0..1], argc, argv, types),
- .UNSIGNED_INT => |*val| set_array(u32, @ptrCast([*]u32, val)[0..1], argc, argv, types),
- .BOOL => |*val| set_array(u32, @ptrCast([*]u32, val)[0..1], argc, argv, types),
+ .FLOAT => |*val| set_array(f32, @as([*]f32, @ptrCast(val))[0..1], argc, argv, types),
+ .DOUBLE => |*val| set_array(f64, @as([*]f64, @ptrCast(val))[0..1], argc, argv, types),
+ .INT => |*val| set_array(i32, @as([*]i32, @ptrCast(val))[0..1], argc, argv, types),
+ .UNSIGNED_INT => |*val| set_array(u32, @as([*]u32, @ptrCast(val))[0..1], argc, argv, types),
+ .BOOL => |*val| set_array(u32, @as([*]u32, @ptrCast(val))[0..1], argc, argv, types),
.FLOAT_VEC2 => |*val| set_array(f32, val[0..], argc, argv, types),
.FLOAT_VEC3 => |*val| set_array(f32, val[0..], argc, argv, types),
.FLOAT_VEC4 => |*val| set_array(f32, val[0..], argc, argv, types),
@@ -171,32 +173,32 @@ pub const ControlServer = struct {
argv: [*c][*c]c.lo_arg,
argc: c_int,
msg: c.lo_message,
- userdata: ?*c_void,
+ userdata: ?*anyopaque,
) callconv(.C) c_int {
_ = msg;
- const self = @ptrCast(*ControlServer, @alignCast(@alignOf(ControlServer), userdata.?));
+ const self = @as(*ControlServer, @ptrCast(@alignCast(userdata.?)));
const path = _path[0..c.strlen(_path)];
- const types = _types[0..@intCast(u32, argc)];
+ const types = _types[0..@as(u32, @intCast(argc))];
if (!std.mem.startsWith(u8, path, "/")) {
- std.debug.warn("invalid OSC message {s} ({s})\n", .{ path, types });
+ std.debug.print("invalid OSC message {s} ({s})\n", .{ path, types });
return 1;
}
self.set_uniform(path[1..], argv, argc, types) catch |err| {
- std.debug.warn("{} while processing {s}\n", .{ err, path });
+ std.debug.print("{} while processing {s}\n", .{ err, path });
};
return 0;
}
- fn handle_bundle_start(time: c.lo_timetag, userdata: ?*c_void) callconv(.C) c_int {
+ fn handle_bundle_start(time: c.lo_timetag, userdata: ?*anyopaque) callconv(.C) c_int {
_ = time;
_ = userdata;
return 1;
}
- fn handle_bundle_end(userdata: ?*c_void) callconv(.C) c_int {
+ fn handle_bundle_end(userdata: ?*anyopaque) callconv(.C) c_int {
_ = userdata;
return 1;
}
diff --git a/src/debug_gl.zig b/src/debug_gl.zig
index dc92e85..4a14591 100644
--- a/src/debug_gl.zig
+++ b/src/debug_gl.zig
@@ -13,7 +13,7 @@ fn glDebugMessage(
severity: c.GLenum,
length: c.GLsizei,
_message: [*c]const u8,
- user: ?*const c_void,
+ user: ?*const anyopaque,
) callconv(.C) void {
_ = id;
_ = user;
@@ -26,8 +26,8 @@ fn glDebugMessage(
else => return,
}
- const message = _message[0..@intCast(usize, length)];
- std.debug.warn("GL Callback [{}] {} / {}: {s}\n", .{ source, typ, severity, message });
+ const message = _message[0..@as(usize, @intCast(length))];
+ std.debug.print("GL Callback [{}] {} / {}: {s}\n", .{ source, typ, severity, message });
}
pub fn init() void {
diff --git a/src/gl.zig b/src/gl.zig
index 9f15aef..ce90506 100644
--- a/src/gl.zig
+++ b/src/gl.zig
@@ -158,7 +158,7 @@ const UniformValue = union(UniformType) {
pub fn init(utype: UniformType) UniformValue {
inline for (@typeInfo(UniformType).Enum.fields) |field| {
- if (@intToEnum(UniformType, field.value) == utype)
+ if (@as(UniformType, @enumFromInt(field.value)) == utype)
return @unionInit(UniformValue, field.name, undefined);
}
@@ -181,7 +181,7 @@ const CachedUniform = struct {
c.glGetActiveUniformsiv(shader.program_id, 1, &index, c.GL_UNIFORM_TYPE, &utype);
var self = CachedUniform{
- .value = UniformValue.init(@intToEnum(UniformType, utype)),
+ .value = UniformValue.init(@as(UniformType, @enumFromInt(utype))),
.location = try shader.uniformLocation(name),
};
@@ -326,9 +326,9 @@ pub const ShaderProgram = struct {
var error_size: c.GLint = undefined;
c.glGetProgramiv(self.program_id, c.GL_INFO_LOG_LENGTH, &error_size);
- const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
+ const message = try c_allocator.alloc(u8, @as(usize, @intCast(error_size)));
c.glGetProgramInfoLog(self.program_id, error_size, &error_size, message.ptr);
- std.debug.warn("Error linking shader program: {s}\n", .{@ptrCast([*:0]const u8, message.ptr)});
+ std.debug.print("Error linking shader program: {s}\n", .{@as([*:0]const u8, @ptrCast(message.ptr))});
return error.LinkError;
}
@@ -344,11 +344,11 @@ pub const ShaderProgram = struct {
};
pub const UniformCache = struct {
- allocator: *std.mem.Allocator,
+ allocator: std.mem.Allocator,
uniforms: std.StringHashMap(CachedUniform),
shader: *ShaderProgram,
- pub fn init(allocator: *std.mem.Allocator, shader: *ShaderProgram) UniformCache {
+ pub fn init(allocator: std.mem.Allocator, shader: *ShaderProgram) UniformCache {
return UniformCache{
.allocator = allocator,
.uniforms = std.StringHashMap(CachedUniform).init(allocator),
@@ -389,12 +389,12 @@ pub const UniformCache = struct {
c.glGetUniformIndices(
self.shader.program_id,
- @intCast(c.GLsizei, count),
+ @as(c.GLsizei, @intCast(count)),
existing_names_c.ptr,
existing_indices.ptr,
);
- for (existing_indices) |index, i| {
+ for (existing_indices, 0..) |index, i| {
const name = existing_names[i];
if (index == c.GL_INVALID_INDEX) {
if (self.uniforms.remove(name)) {
@@ -410,7 +410,7 @@ pub const UniformCache = struct {
// name has to be zero-terminated!
pub fn get(self: *UniformCache, name: []const u8) !?*CachedUniform {
- const cloned_name = try std.mem.dupe(self.allocator, u8, name);
+ const cloned_name = try self.allocator.dupe(u8, name);
errdefer self.allocator.free(cloned_name);
var result = try self.uniforms.getOrPut(cloned_name);
@@ -430,7 +430,7 @@ fn initGlShader(source: []const u8, name: []const u8, kind: c.GLenum) !c.GLuint
const shader_id = c.glCreateShader(kind);
errdefer c.glDeleteShader(shader_id);
const source_ptr: ?[*]const u8 = source.ptr;
- const source_len = @intCast(c.GLint, source.len);
+ const source_len = @as(c.GLint, @intCast(source.len));
c.glShaderSource(shader_id, 1, &source_ptr, &source_len);
c.glCompileShader(shader_id);
@@ -441,11 +441,11 @@ fn initGlShader(source: []const u8, name: []const u8, kind: c.GLenum) !c.GLuint
var error_size: c.GLint = undefined;
c.glGetShaderiv(shader_id, c.GL_INFO_LOG_LENGTH, &error_size);
- const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
+ const message = try c_allocator.alloc(u8, @as(usize, @intCast(error_size)));
c.glGetShaderInfoLog(shader_id, error_size, &error_size, message.ptr);
- std.debug.warn(
+ std.debug.print(
"Error compiling {s} shader:\n{s}\n",
- .{ name, @ptrCast([*:0]const u8, message.ptr) },
+ .{ name, @as([*:0]const u8, @ptrCast(message.ptr)) },
);
return error.CompileError;
}
@@ -526,14 +526,14 @@ pub const VertexObject = struct {
var self: VertexObject = undefined;
self.vertex_size = vertex_size;
- self.vertex_count = @intCast(i32, vertices.len);
+ self.vertex_count = @as(i32, @intCast(vertices.len));
c.glGenVertexArrays(1, &self.array_id);
c.glBindVertexArray(self.array_id);
c.glGenBuffers(1, &self.buffer_id);
c.glBindBuffer(c.GL_ARRAY_BUFFER, self.buffer_id);
- c.glBufferData(c.GL_ARRAY_BUFFER, @intCast(c_long, @sizeOf(T) * vertices.len), @ptrCast(*const c_void, vertices.ptr), c.GL_STATIC_DRAW);
+ c.glBufferData(c.GL_ARRAY_BUFFER, @as(c_long, @intCast(@sizeOf(T) * vertices.len)), @as(*const anyopaque, @ptrCast(vertices.ptr)), c.GL_STATIC_DRAW);
return self;
}
@@ -589,7 +589,7 @@ pub const Constants = struct {
.texture_shader = shader,
.normalized_quad = VertexObject.create(f32, vertices[0..], 2),
.config = config,
- .aspect = @intToFloat(f32, config.width) / @intToFloat(f32, config.height),
+ .aspect = @as(f32, @floatFromInt(config.width)) / @as(f32, @floatFromInt(config.height)),
};
}
diff --git a/src/main.zig b/src/main.zig
index 1edb4d9..328e73a 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,5 +1,5 @@
const std = @import("std");
-const fs = @import("std").fs;
+const fs = std.fs;
const debug = std.debug;
const panic = debug.panic;
const c = @import("c.zig");
@@ -8,7 +8,7 @@ const cfg = @import("config.zig");
const out = @import("output.zig");
const gl = @import("gl.zig");
const ctrl = @import("control.zig");
-const c_allocator = @import("std").heap.c_allocator;
+const c_allocator = std.heap.c_allocator;
var window: *c.GLFWwindow = undefined;
@@ -20,7 +20,7 @@ pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
- var config = try cfg.Config.parse(&arena.allocator, "config.yaml");
+ var config = try cfg.Config.parse(&arena.allocator(), "config.yaml");
_ = c.glfwSetErrorCallback(errorCallback);
@@ -31,10 +31,10 @@ pub fn main() !void {
var monitor_count: c_int = 0;
const monitors = c.glfwGetMonitors(&monitor_count);
- for (monitors[0..@intCast(usize, monitor_count)]) |monitor, i| {
- debug.warn(
+ for (monitors[0..@as(usize, @intCast(monitor_count))], 0..) |monitor, i| {
+ debug.print(
"monitor {}: '{s}'\n",
- .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) },
+ .{ i, @as([*:0]const u8, @ptrCast(c.glfwGetMonitorName(monitor))) },
);
}
@@ -58,10 +58,10 @@ pub fn main() !void {
var constants = try gl.Constants.create(window, &config);
defer constants.destroy();
- var outputs = try std.ArrayList(*out.Output).initCapacity(&arena.allocator, config.outputs.len);
+ var outputs = try std.ArrayList(*out.Output).initCapacity(arena.allocator(), config.outputs.len);
defer outputs.deinit();
for (config.outputs) |output_config| {
- try outputs.append(out.Output.create(&arena.allocator, output_config, &constants));
+ try outputs.append(out.Output.create(arena.allocator(), output_config, &constants));
}
defer for (outputs.items) |output| {
output.destroy(output);
@@ -110,7 +110,7 @@ pub fn main() !void {
var cache = gl.UniformCache.init(std.heap.c_allocator, &main_program);
defer cache.deinit();
- const control = try ctrl.ControlServer.init(&arena.allocator, config.osc, &cache);
+ const control = try ctrl.ControlServer.init(arena.allocator(), config.osc, &cache);
defer control.destroy();
while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
@@ -136,7 +136,7 @@ pub fn main() !void {
constants.normalized_quad.draw();
fbo.unbind();
- for (outputs.items) |output, i| {
+ for (outputs.items, 0..) |output, i| {
const close = output.update(output, fbo.texture_id);
if (close) {
const removed = outputs.swapRemove(i);
@@ -154,7 +154,7 @@ pub fn main() !void {
// given a file and the directory it is in, resolve references
fn loadFile(writer: anytype, dir: []const u8, filename: []const u8) !void {
- const file_dir = try std.fs.path.resolve(c_allocator, &[_][]const u8{
+ const file_dir = try fs.path.resolve(c_allocator, &[_][]const u8{
dir,
std.fs.path.dirname(filename) orelse "",
});
@@ -163,7 +163,7 @@ fn loadFile(writer: anytype, dir: []const u8, filename: []const u8) !void {
const file_path = try std.fs.path.resolve(c_allocator, &[_][]const u8{ dir, filename });
defer c_allocator.free(file_path);
- var file = try fs.openFileAbsolute(file_path, .{});
+ var file = try fs.cwd().openFile(file_path, .{});
defer file.close();
var reader = file.reader();
@@ -180,8 +180,8 @@ fn loadFile(writer: anytype, dir: []const u8, filename: []const u8) !void {
if (std.mem.eql(u8, pragma, "include")) {
var include_path = parts.next().?;
if (include_path[0] != '"' or include_path[include_path.len - 1] != '"') {
- debug.warn("{s}:{}: Invalid #pragma include\n", .{ file_path, line_number });
- debug.warn("{s}:{}: {s}\n", .{ file_path, line_number, line });
+ debug.print("{s}:{}: Invalid #pragma include\n", .{ file_path, line_number });
+ debug.print("{s}:{}: {s}\n", .{ file_path, line_number, line });
continue;
}
include_path = include_path[1 .. include_path.len - 1];
@@ -190,8 +190,8 @@ fn loadFile(writer: anytype, dir: []const u8, filename: []const u8) !void {
continue;
} else {
- debug.warn("{s}:{}: Unknown #pragma directive '{s}'\n", .{ file_path, line_number, pragma });
- debug.warn("{s}:{}: {s}\n", .{ file_path, line_number, line });
+ debug.print("{s}:{}: Unknown #pragma directive '{s}'\n", .{ file_path, line_number, pragma });
+ debug.print("{s}:{}: {s}\n", .{ file_path, line_number, line });
}
}
@@ -201,12 +201,12 @@ fn loadFile(writer: anytype, dir: []const u8, filename: []const u8) !void {
}
fn reloadShader(current: *gl.ShaderProgram, frag_filename: []const u8, size: u64) !void {
- var buffer = try std.ArrayList(u8).initCapacity(c_allocator, @intCast(usize, size));
+ var buffer = try std.ArrayList(u8).initCapacity(c_allocator, @as(usize, @intCast(size)));
errdefer buffer.deinit();
try loadFile(buffer.writer(), "", frag_filename);
- const frag_source = buffer.toOwnedSlice();
+ const frag_source = try buffer.toOwnedSlice();
defer c_allocator.free(frag_source);
const vert_source =
@@ -225,6 +225,6 @@ fn reloadShader(current: *gl.ShaderProgram, frag_filename: []const u8, size: u64
current.destroy();
current.* = new_program;
} else |err| {
- debug.warn("Error while reloading shader: {}\n", .{err});
+ debug.print("Error while reloading shader: {}\n", .{err});
}
}
diff --git a/src/output.zig b/src/output.zig
index f4c33d7..96b3f3e 100644
--- a/src/output.zig
+++ b/src/output.zig
@@ -4,10 +4,10 @@ const cfg = @import("config.zig");
const gl = @import("gl.zig");
pub const Output = struct {
- update: fn (*Output, c.GLuint) bool,
- destroy: fn (*Output) void,
+ update: *const fn (*Output, c.GLuint) bool,
+ destroy: *const fn (*Output) void,
- fn init(update: fn (*Output, c.GLuint) bool, destroy: fn (*Output) void) Output {
+ fn init(update: *const fn (*Output, c.GLuint) bool, destroy: *const fn (*Output) void) Output {
return Output{
.update = update,
.destroy = destroy,
@@ -15,7 +15,7 @@ pub const Output = struct {
}
pub fn create(
- allocator: *std.mem.Allocator,
+ allocator: std.mem.Allocator,
config: cfg.OutputConfig,
constants: *gl.Constants,
) *Output {
@@ -33,7 +33,7 @@ pub const WindowOutput = struct {
resized: bool = false,
pub fn create(
- allocator: *std.mem.Allocator,
+ allocator: std.mem.Allocator,
config: cfg.OutputConfig,
constants: *gl.Constants,
) *Output {
@@ -55,7 +55,7 @@ pub const WindowOutput = struct {
},
};
- c.glfwSetWindowUserPointer(self.window, @ptrCast(*c_void, self));
+ c.glfwSetWindowUserPointer(self.window, @as(*anyopaque, @ptrCast(self)));
_ = c.glfwSetKeyCallback(self.window, keyCallback);
_ = c.glfwSetFramebufferSizeCallback(self.window, sizeCallback);
@@ -81,13 +81,13 @@ pub const WindowOutput = struct {
var scaled_height: c_int = undefined;
c.glfwGetFramebufferSize(self.window, &width, &height);
- const window_aspect = @intToFloat(f32, width) / @intToFloat(f32, height);
+ const window_aspect = @as(f32, @floatFromInt(width)) / @as(f32, @floatFromInt(height));
if (window_aspect >= self.constants.aspect) {
scaled_height = height;
- scaled_width = @floatToInt(c_int, @intToFloat(f32, height) * self.constants.aspect);
+ scaled_width = @as(c_int, @intFromFloat(@as(f32, @floatFromInt(height)) * self.constants.aspect));
} else {
scaled_width = width;
- scaled_height = @floatToInt(c_int, @intToFloat(f32, width) / self.constants.aspect);
+ scaled_height = @as(c_int, @intFromFloat(@as(f32, @floatFromInt(width)) / self.constants.aspect));
}
c.glViewport(
@@ -123,11 +123,10 @@ pub const WindowOutput = struct {
) callconv(.C) void {
if (action != c.GLFW_PRESS) return;
const userptr = c.glfwGetWindowUserPointer(win).?;
- const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
+ const self = @as(*WindowOutput, @ptrCast(@alignCast(userptr)));
_ = self;
_ = scancode;
- _ = action;
_ = mods;
switch (key) {
@@ -140,7 +139,7 @@ pub const WindowOutput = struct {
fn sizeCallback(win: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
const userptr = c.glfwGetWindowUserPointer(win).?;
- const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
+ const self = @as(*WindowOutput, @ptrCast(@alignCast(userptr)));
self.resized = true;
_ = width;