aboutsummaryrefslogtreecommitdiffstats
path: root/src/gl.zig
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 /src/gl.zig
parentupdate for zig 0.9.0 (diff)
downloadglsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.tar.gz
glsl-view-a250d5bbe6eb215e345de4900e784140dfe73161.zip
update for zig 0.11.0
Diffstat (limited to 'src/gl.zig')
-rw-r--r--src/gl.zig32
1 files changed, 16 insertions, 16 deletions
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)),
};
}