git.s-ol.nu glsl-view / 96d5ebf
zig-fmt for low-column-screens s-ol 2 years ago
6 changed file(s) with 93 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
391391 break;
392392 },
393393
394 c.yaml_event_type_t.YAML_SEQUENCE_START_EVENT, c.yaml_event_type_t.YAML_MAPPING_START_EVENT => depth += 1,
395
396 c.yaml_event_type_t.YAML_SEQUENCE_END_EVENT, c.yaml_event_type_t.YAML_MAPPING_END_EVENT => {
394 c.yaml_event_type_t.YAML_SEQUENCE_START_EVENT,
395 c.yaml_event_type_t.YAML_MAPPING_START_EVENT,
396 => depth += 1,
397
398 c.yaml_event_type_t.YAML_SEQUENCE_END_EVENT,
399 c.yaml_event_type_t.YAML_MAPPING_END_EVENT,
400 => {
397401 depth -= 1;
398402
399403 if (depth == 0)
1111 }
1212 }
1313
14 fn set_array(comptime T: type, dest: []T, argc: c_int, argv: [*c][*c]c.lo_arg, types: []const u8) !void {
14 fn set_array(
15 comptime T: type,
16 dest: []T,
17 argc: c_int,
18 argv: [*c][*c]c.lo_arg,
19 types: []const u8,
20 ) !void {
1521 if (argc != dest.len)
1622 return error.sizeMismatch;
1723
55
66 pub const is_on = if (builtin.mode == builtin.Mode.ReleaseFast) c.GL_FALSE else c.GL_TRUE;
77
8 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 {
8 fn glDebugMessage(
9 source: c.GLenum,
10 typ: c.GLenum,
11 id: c.GLuint,
12 severity: c.GLenum,
13 length: c.GLsizei,
14 _message: [*c]const u8,
15 user: ?*const c_void,
16 ) callconv(.C) void {
917 switch (typ) {
10 c.GL_DEBUG_TYPE_ERROR, c.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, c.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR => {},
18 c.GL_DEBUG_TYPE_ERROR,
19 c.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR,
20 c.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR,
21 => {},
1122 else => return,
1223 }
1324
00 const std = @import("std");
11 const c_allocator = @import("std").heap.c_allocator;
2 const panic = @import("std").debug.panic;
32 const c = @import("c.zig");
43 const cfg = @import("config.zig");
54
297296 c.glUseProgram(self.program_id);
298297 }
299298
300 pub fn attribLocation(self: ShaderProgram, name: [*]const u8) c.GLint {
301 const id = c.glGetAttribLocation(self.program_id, name);
302 if (id == -1) {
303 panic("invalid attrib: {}\n", .{name});
304 }
305 return id;
306 }
307
308299 pub fn uniformLocation(self: ShaderProgram, name: [*]const u8) !c.GLint {
309300 const id = c.glGetUniformLocation(self.program_id, name);
310301 if (id == -1)
398389 }
399390 }
400391
401 c.glGetUniformIndices(self.shader.program_id, @intCast(c.GLsizei, count), existing_names_c.ptr, existing_indices.ptr);
392 c.glGetUniformIndices(
393 self.shader.program_id,
394 @intCast(c.GLsizei, count),
395 existing_names_c.ptr,
396 existing_indices.ptr,
397 );
402398
403399 for (existing_indices) |index, i| {
404400 const name = existing_names[i];
449445
450446 const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
451447 c.glGetShaderInfoLog(shader_id, error_size, &error_size, message.ptr);
452 std.debug.warn("Error compiling {s} shader:\n{s}\n", .{ name, @ptrCast([*:0]const u8, message.ptr) });
448 std.debug.warn(
449 "Error compiling {s} shader:\n{s}\n",
450 .{ name, @ptrCast([*:0]const u8, message.ptr) },
451 );
453452 return error.CompileError;
454453 }
455454
472471
473472 c.glGenTextures(1, &self.texture_id);
474473 c.glBindTexture(c.GL_TEXTURE_2D, self.texture_id);
475 c.glTexImage2D(c.GL_TEXTURE_2D, 0, c.GL_RGBA, width, height, 0, c.GL_RGBA, c.GL_UNSIGNED_BYTE, null);
474 c.glTexImage2D(
475 c.GL_TEXTURE_2D,
476 0,
477 c.GL_RGBA,
478 width,
479 height,
480 0,
481 c.GL_RGBA,
482 c.GL_UNSIGNED_BYTE,
483 null,
484 );
476485 c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR);
477486 c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
478487 c.glBindTexture(c.GL_TEXTURE_2D, 0);
479488
480 c.glFramebufferTexture2D(c.GL_FRAMEBUFFER, c.GL_COLOR_ATTACHMENT0, c.GL_TEXTURE_2D, self.texture_id, 0);
489 c.glFramebufferTexture2D(
490 c.GL_FRAMEBUFFER,
491 c.GL_COLOR_ATTACHMENT0,
492 c.GL_TEXTURE_2D,
493 self.texture_id,
494 0,
495 );
481496
482497 if (c.glCheckFramebufferStatus(c.GL_FRAMEBUFFER) != c.GL_FRAMEBUFFER_COMPLETE)
483498 return error.FBONotComplete;
3030 var monitor_count: c_int = 0;
3131 const monitors = c.glfwGetMonitors(&monitor_count);
3232 for (monitors[0..@intCast(usize, monitor_count)]) |monitor, i| {
33 std.debug.warn("monitor {}: '{s}'\n", .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) });
33 std.debug.warn(
34 "monitor {}: '{s}'\n",
35 .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) },
36 );
3437 }
3538
3639 c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 4);
1313 };
1414 }
1515
16 pub fn create(allocator: *std.mem.Allocator, config: cfg.OutputConfig, constants: *gl.Constants) *Output {
16 pub fn create(
17 allocator: *std.mem.Allocator,
18 config: cfg.OutputConfig,
19 constants: *gl.Constants,
20 ) *Output {
1721 return switch (config.type) {
1822 .window => WindowOutput.create(allocator, config, constants),
1923 else => unreachable,
2832
2933 resized: bool = false,
3034
31 pub fn create(allocator: *std.mem.Allocator, config: cfg.OutputConfig, constants: *gl.Constants) *Output {
35 pub fn create(
36 allocator: *std.mem.Allocator,
37 config: cfg.OutputConfig,
38 constants: *gl.Constants,
39 ) *Output {
3240 const self = allocator.create(WindowOutput) catch unreachable;
3341
3442 c.glfwDefaultWindowHints();
3644 self.* = WindowOutput{
3745 .constants = constants,
3846 .output = Output.init(update, destroy),
39 .window = c.glfwCreateWindow(config.width, config.height, "glsl-view output", null, constants.main_window) orelse {
47 .window = c.glfwCreateWindow(
48 config.width,
49 config.height,
50 "glsl-view output",
51 null,
52 constants.main_window,
53 ) orelse {
4054 std.debug.panic("unable to create output window\n", .{});
4155 },
4256 };
7690 scaled_height = @floatToInt(c_int, @intToFloat(f32, width) / self.constants.aspect);
7791 }
7892
79 c.glViewport(@divFloor(width - scaled_width, 2), @divFloor(height - scaled_height, 2), scaled_width, scaled_height);
93 c.glViewport(
94 @divFloor(width - scaled_width, 2),
95 @divFloor(height - scaled_height, 2),
96 scaled_width,
97 scaled_height,
98 );
8099 }
81100
82101 c.glBindTexture(c.GL_TEXTURE_2D, texture_id);
95114 c.glfwDestroyWindow(self.window);
96115 }
97116
98 fn keyCallback(win: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
117 fn keyCallback(
118 win: ?*c.GLFWwindow,
119 key: c_int,
120 scancode: c_int,
121 action: c_int,
122 mods: c_int,
123 ) callconv(.C) void {
99124 if (action != c.GLFW_PRESS) return;
100 const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), c.glfwGetWindowUserPointer(win).?));
125 const userptr = c.glfwGetWindowUserPointer(win).?;
126 const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
101127
102128 switch (key) {
103129 // c.GLFW_KEY_F => // toggle fullscreen
108134 }
109135
110136 fn sizeCallback(win: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
111 const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), c.glfwGetWindowUserPointer(win).?));
137 const userptr = c.glfwGetWindowUserPointer(win).?;
138 const self = @ptrCast(*WindowOutput, @alignCast(@alignOf(WindowOutput), userptr));
112139 self.resized = true;
113140 }
114141 };