def glShaderSource(shader, source): source_lines = source.splitlines() count = len(source_lines) strings = ffi.new('char*[]', count) lengths = ffi.new('int[]', count) ref_strings = [] for i, line in enumerate(source_lines): cb = line.encode('ascii') s = ffi.new('char[]', cb) ref_strings.append(s) strings[i] = s lengths[i] = len(cb) lib.glShaderSource(shader, count, strings, lengths)
def glGenBuffers(n): buffers = ffi.new('unsigned int[]', n) lib.glGenBuffers(n, buffers) return buffers
def glGetUniformLocation(program, name): cname = ffi.new('char*', name) return lib.glGetUniformLocation(program, cname)
def glGetAttribLocation(program, name): cname = ffi.new('char[]', name.encode('ascii')) return lib.glGetAttribLocation(program, cname)
def glGetProgramInfoLog(program): max_length = 1024 length = ffi.new('int*') infolog = ffi.new('char[]', max_length) lib.glGetProgramInfoLog(program, max_length, length, infolog) return infolog
def glGetProgramiv(program, pname): params = ffi.new('int*') lib.glGetProgramiv(program, pname, params) return params[0]
def glGetShaderInfoLog(shader): max_length = 2048 length = ffi.new('int*') infolog = ffi.new('char[]', max_length) lib.glGetShaderInfoLog(shader, max_length, length, infolog) return ffi.string(infolog).decode('utf-8')
def glGetShaderiv(shader, pname): params = ffi.new('int*') lib.glGetShaderiv(shader, pname, params) return params[0]