Created
June 11, 2020 09:00
-
-
Save matjam/d5298e5acc94ae3622e6d1f664daf002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn compileShader(file: var, shader_type: c_uint) !c.GLuint { | |
std.debug.warn("shader loading file: {}\n", .{file}); | |
const source = try std.fs.cwd().readFileAlloc(std.heap.c_allocator, file, 1000000); | |
defer std.heap.c_allocator.free(source); | |
var shader = c.glCreateShader(shader_type); | |
c.glShaderSource(shader, 1, &(&source[0]), null); | |
c.glCompileShader(shader); | |
// check for shader compile errors | |
var success: c.GLint = 0; | |
var infoLog = [_]u8{0} ** 512; | |
c.glGetShaderiv(shader, c.GL_COMPILE_STATUS, &success); | |
if (success == 0) { | |
c.glGetShaderInfoLog(shader, 512, null, &infoLog); | |
std.debug.warn("error compiling shader: {}\n", .{infoLog}); | |
return error.ShaderCompilerError; | |
} | |
return shader; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment