aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-06-08 09:32:17 +0000
committers-ol <s-ol@users.noreply.github.com>2020-06-08 09:32:17 +0000
commit96d5ebf72ac395c57489b567c47d35d4807f1994 (patch)
treebf6431a5ae276cd2e59b33c6ec56ebd9a4735195
parenterror handling (diff)
downloadglsl-view-96d5ebf72ac395c57489b567c47d35d4807f1994.tar.gz
glsl-view-96d5ebf72ac395c57489b567c47d35d4807f1994.zip
zig-fmt for low-column-screens
-rw-r--r--src/config.zig8
-rw-r--r--src/control.zig8
-rw-r--r--src/debug_gl.zig15
-rw-r--r--src/gl.zig41
-rw-r--r--src/main.zig5
-rw-r--r--src/output.zig41
6 files changed, 92 insertions, 26 deletions
diff --git a/src/config.zig b/src/config.zig
index 5bc449d..9655a85 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -392,9 +392,13 @@ fn skipAny(parser: *c.yaml_parser_t) !void {
break;
},
- c.yaml_event_type_t.YAML_SEQUENCE_START_EVENT, c.yaml_event_type_t.YAML_MAPPING_START_EVENT => depth += 1,
+ c.yaml_event_type_t.YAML_SEQUENCE_START_EVENT,
+ c.yaml_event_type_t.YAML_MAPPING_START_EVENT,
+ => depth += 1,
- c.yaml_event_type_t.YAML_SEQUENCE_END_EVENT, c.yaml_event_type_t.YAML_MAPPING_END_EVENT => {
+ c.yaml_event_type_t.YAML_SEQUENCE_END_EVENT,
+ c.yaml_event_type_t.YAML_MAPPING_END_EVENT,
+ => {
depth -= 1;
if (depth == 0)
diff --git a/src/control.zig b/src/control.zig
index 822b044..ed5c987 100644
--- a/src/control.zig
+++ b/src/control.zig
@@ -12,7 +12,13 @@ fn verify_args(expected: u8, got: []const u8) !void {
}
}
-fn set_array(comptime T: type, dest: []T, argc: c_int, argv: [*c][*c]c.lo_arg, types: []const u8) !void {
+fn set_array(
+ comptime T: type,
+ dest: []T,
+ argc: c_int,
+ argv: [*c][*c]c.lo_arg,
+ types: []const u8,
+) !void {
if (argc != dest.len)
return error.sizeMismatch;
diff --git a/src/debug_gl.zig b/src/debug_gl.zig
index 7d02d2f..03078df 100644
--- a/src/debug_gl.zig
+++ b/src/debug_gl.zig
@@ -6,9 +6,20 @@ const builtin = @import("builtin");
pub const is_on = if (builtin.mode == builtin.Mode.ReleaseFast) c.GL_FALSE else c.GL_TRUE;
-fn glDebugMessage(source: c.GLenum, typ: c.GLenum, id: c.GLuint, severity: c.GLenum, length: c.GLsizei, _message: [*c]const u8, user: ?*const c_void) callconv(.C) void {
+fn glDebugMessage(
+ source: c.GLenum,
+ typ: c.GLenum,
+ id: c.GLuint,
+ severity: c.GLenum,
+ length: c.GLsizei,
+ _message: [*c]const u8,
+ user: ?*const c_void,
+) callconv(.C) void {
switch (typ) {
- c.GL_DEBUG_TYPE_ERROR, c.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, c.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR => {},
+ c.GL_DEBUG_TYPE_ERROR,
+ c.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR,
+ c.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR,
+ => {},
else => return,
}
diff --git a/src/gl.zig b/src/gl.zig
index 8d67bdf..9aab754 100644
--- a/src/gl.zig
+++ b/src/gl.zig
@@ -1,6 +1,5 @@
const std = @import("std");
const c_allocator = @import("std").heap.c_allocator;
-const panic = @import("std").debug.panic;
const c = @import("c.zig");
const cfg = @import("config.zig");
@@ -298,14 +297,6 @@ pub const ShaderProgram = struct {
c.glUseProgram(self.program_id);
}
- pub fn attribLocation(self: ShaderProgram, name: [*]const u8) c.GLint {
- const id = c.glGetAttribLocation(self.program_id, name);
- if (id == -1) {
- panic("invalid attrib: {}\n", .{name});
- }
- return id;
- }
-
pub fn uniformLocation(self: ShaderProgram, name: [*]const u8) !c.GLint {
const id = c.glGetUniformLocation(self.program_id, name);
if (id == -1)
@@ -399,7 +390,12 @@ pub const UniformCache = struct {
}
}
- c.glGetUniformIndices(self.shader.program_id, @intCast(c.GLsizei, count), existing_names_c.ptr, existing_indices.ptr);
+ c.glGetUniformIndices(
+ self.shader.program_id,
+ @intCast(c.GLsizei, count),
+ existing_names_c.ptr,
+ existing_indices.ptr,
+ );
for (existing_indices) |index, i| {
const name = existing_names[i];
@@ -450,7 +446,10 @@ fn initGlShader(source: []const u8, name: []const u8, kind: c.GLenum) !c.GLuint
const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
c.glGetShaderInfoLog(shader_id, error_size, &error_size, message.ptr);
- std.debug.warn("Error compiling {s} shader:\n{s}\n", .{ name, @ptrCast([*:0]const u8, message.ptr) });
+ std.debug.warn(
+ "Error compiling {s} shader:\n{s}\n",
+ .{ name, @ptrCast([*:0]const u8, message.ptr) },
+ );
return error.CompileError;
}
@@ -473,12 +472,28 @@ pub const FramebufferObject = struct {
c.glGenTextures(1, &self.texture_id);
c.glBindTexture(c.GL_TEXTURE_2D, self.texture_id);
- c.glTexImage2D(c.GL_TEXTURE_2D, 0, c.GL_RGBA, width, height, 0, c.GL_RGBA, c.GL_UNSIGNED_BYTE, null);
+ c.glTexImage2D(
+ c.GL_TEXTURE_2D,
+ 0,
+ c.GL_RGBA,
+ width,
+ height,
+ 0,
+ c.GL_RGBA,
+ c.GL_UNSIGNED_BYTE,
+ null,
+ );
c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR);
c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
c.glBindTexture(c.GL_TEXTURE_2D, 0);
- c.glFramebufferTexture2D(c.GL_FRAMEBUFFER, c.GL_COLOR_ATTACHMENT0, c.GL_TEXTURE_2D, self.texture_id, 0);
+ c.glFramebufferTexture2D(
+ c.GL_FRAMEBUFFER,
+ c.GL_COLOR_ATTACHMENT0,
+ c.GL_TEXTURE_2D,
+ self.texture_id,
+ 0,
+ );
if (c.glCheckFramebufferStatus(c.GL_FRAMEBUFFER) != c.GL_FRAMEBUFFER_COMPLETE)
return error.FBONotComplete;
diff --git a/src/main.zig b/src/main.zig
index 0a8ee9d..d69bd66 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -31,7 +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| {
- std.debug.warn("monitor {}: '{s}'\n", .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) });
+ std.debug.warn(
+ "monitor {}: '{s}'\n",
+ .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) },
+ );
}
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 4);
diff --git a/src/output.zig b/src/output.zig
index 770c0ba..5c8aa19 100644
--- a/src/output.zig
+++ b/src/output.zig
@@ -14,7 +14,11 @@ pub const Output = struct {
};
}
- pub fn create(allocator: *std.mem.Allocator, config: cfg.OutputConfig, constants: *gl.Constants) *Output {
+ pub fn create(
+ allocator: *std.mem.Allocator,
+ config: cfg.OutputConfig,
+ constants: *gl.Constants,
+ ) *Output {
return switch (config.type) {
.window => WindowOutput.create(allocator, config, constants),
else => unreachable,
@@ -29,7 +33,11 @@ pub const WindowOutput = struct {
resized: bool = false,
- pub fn create(allocator: *std.mem.Allocator, config: cfg.OutputConfig, constants: *gl.Constants) *Output {
+ pub fn create(
+ allocator: *std.mem.Allocator,
+ config: cfg.OutputConfig,
+ constants: *gl.Constants,
+ ) *Output {
const self = allocator.create(WindowOutput) catch unreachable;
c.glfwDefaultWindowHints();
@@ -37,7 +45,13 @@ pub const WindowOutput = struct {
self.* = WindowOutput{
.constants = constants,
.output = Output.init(update, destroy),
- .window = c.glfwCreateWindow(config.width, config.height, "glsl-view output", null, constants.main_window) orelse {
+ .window = c.glfwCreateWindow(
+ config.width,
+ config.height,
+ "glsl-view output",
+ null,
+ constants.main_window,
+ ) orelse {
std.debug.panic("unable to create output window\n", .{});
},
};
@@ -77,7 +91,12 @@ pub const WindowOutput = struct {
scaled_height = @floatToInt(c_int, @intToFloat(f32, width) / self.constants.aspect);
}
- c.glViewport(@divFloor(width - scaled_width, 2), @divFloor(height - scaled_height, 2), scaled_width, scaled_height);
+ c.glViewport(
+ @divFloor(width - scaled_width, 2),
+ @divFloor(height - scaled_height, 2),
+ scaled_width,
+ scaled_height,
+ );
}
c.glBindTexture(c.GL_TEXTURE_2D, texture_id);
@@ -96,9 +115,16 @@ pub const WindowOutput = struct {
c.glfwDestroyWindow(self.window);
}
- fn keyCallback(win: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
+ fn keyCallback(
+ win: ?*c.GLFWwindow,
+ key: c_int,
+ scancode: c_int,
+ action: c_int,
+ mods: c_int,
+ ) callconv(.C) void {
if (action != c.GLFW_PRESS) return;
- const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), c.glfwGetWindowUserPointer(win).?));
+ const userptr = c.glfwGetWindowUserPointer(win).?;
+ const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
switch (key) {
// c.GLFW_KEY_F => // toggle fullscreen
@@ -109,7 +135,8 @@ pub const WindowOutput = struct {
}
fn sizeCallback(win: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
- const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), c.glfwGetWindowUserPointer(win).?));
+ const userptr = c.glfwGetWindowUserPointer(win).?;
+ const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
self.resized = true;
}
};