Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created August 8, 2019 00:46
Show Gist options
  • Save kevinw/5fb443c5efcc68f7296b5439b9758029 to your computer and use it in GitHub Desktop.
Save kevinw/5fb443c5efcc68f7296b5439b9758029 to your computer and use it in GitHub Desktop.
pub fn setUniformInt(sp: ShaderProgram, uniform_id: c.GLint, value: c_int) void {
c.glUniform1i(uniform_id, value);
}
pub fn setUniformFloat(sp: ShaderProgram, uniform_id: c.GLint, value: f32) void {
c.glUniform1f(uniform_id, value);
}
pub fn setUniformFloatByName(sp: ShaderProgram, comptime name: []const u8, value: f32) void {
const uniformId = sp.uniformLoc(name);
if (uniformId != -1)
sp.setUniformFloat(uniformId, value);
}
pub fn setUniformVec3(sp: ShaderProgram, uniform_id: c.GLint, value: math3d.Vec3) void {
if (c.is_web) {
c.glUniform3fv(uniform_id, value.x, value.y, value.z);
} else {
var v = value;
c.glUniform3fv(uniform_id, 1, v.ptr());
}
}
pub fn setUniformVec4(sp: ShaderProgram, uniform_id: c.GLint, value: Vec4) void {
if (c.is_web) {
c.glUniform4fv(uniform_id, value.x, value.y, value.z, value.w);
} else {
var v = value;
c.glUniform4fv(uniform_id, 1, v.ptr());
}
}
pub fn setUniformVec3ByName(sp: ShaderProgram, comptime name: []const u8, value: Vec3) void {
const location = sp.uniformLoc(name);
if (location != -1) {
sp.setUniformVec3(location, value);
} else {
log("location for {}: {}", name, location);
}
debug_gl.assertNoErrorWithMessage("error getting uniform " ++ name);
}
pub fn setUniformVec4ByName(sp: ShaderProgram, comptime name: []const u8, value: Vec4) void {
const location = sp.uniformLoc(name);
if (location != -1) sp.setUniformVec4(location, value);
}
pub fn setUniformMat4x4(sp: ShaderProgram, uniform_id: c.GLint, value: Mat4x4) void {
c.glUniformMatrix4fv(uniform_id, 1, c.GL_FALSE, value.data[0][0..].ptr);
}
pub fn setUniformMat4x4ByName(sp: ShaderProgram, comptime name: []const u8, value: Mat4x4) void {
const location = sp.uniformLoc(name);
if (location != -1) c.glUniformMatrix4fv(location, 1, c.GL_FALSE, value.data[0][0..].ptr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment