func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { p := unsafe.Pointer(nil) if len(data) > 0 { p = unsafe.Pointer(&data[0]) } C.glTexImage2D(target.c(), C.GLint(level), C.GLint(format), C.GLsizei(width), C.GLsizei(height), 0, format.c(), ty.c(), p) }
func CopyTexSubImage2D(target uint, level, xoffset, yoffset, x, y, width, height int) { C.glCopyTexSubImage2D( C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func TexImage2D(target TextureTarget, level int, internalformat InternalFormat, width, height int, format TextureFormat, datatype DataType, pixels []uint8) { if pixels != nil { C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), C.GLsizei(width), C.GLsizei(height), 0, C.GLenum(format), C.GLenum(datatype), unsafe.Pointer(&pixels[0])) } else { C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), C.GLsizei(width), C.GLsizei(height), 0, C.GLenum(format), C.GLenum(datatype), unsafe.Pointer(nil)) } }
func ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) { defer func() { errstr := errDrain() log.Printf("gl.ReadPixels(len(%d), %v, %v, %v, %v, %v, %v) %v", len(dst), x, y, width, height, format, ty, errstr) }() C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&dst[0])) }
func Uniform3i(location, v0, v1, v2 int32) { defer func() { errstr := errDrain() log.Printf("gl.Uniform3i(%v, %v, %v, %v) %v", location, v0, v1, v2, errstr) }() C.glUniform3i(C.GLint(location), C.GLint(v0), C.GLint(v1), C.GLint(v2)) }
//void glMap1d (GLenum target, float64 u1, float64 u2, int stride, int order, const float64 *points) func Map1d(target GLenum, u1 float64, u2 float64, stride int, order int, points []float64) { if len(points) == 0 { panic("Invalid points size") } C.glMap1d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2), C.GLint(stride), C.GLint(order), (*C.GLdouble)(&points[0])) }
func CopyTexImage2D(target uint, level int, internalformat uint, x, y, width, height, border int) { C.glCopyTexImage2D( C.GLenum(target), C.GLint(level), C.GLenum(internalformat), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLint(border)) }
//void glMap1f (GLenum target, float32 u1, float32 u2, int stride, int order, const float32 *points) func Map1f(target GLenum, u1 float32, u2 float32, stride int, order int, points []float32) { if len(points) == 0 { panic("Invalid points size") } C.glMap1f(C.GLenum(target), C.GLfloat(u1), C.GLfloat(u2), C.GLint(stride), C.GLint(order), (*C.GLfloat)(&points[0])) }
func Uniform2i( location int32, x int32, y int32) { C.glUniform2i( C.GLint(location), C.GLint(x), C.GLint(y)) }
func CopyTexSubImage2D(target Enum, level, xoffset, yoffset, x, y, width, height int) { defer func() { errstr := errDrain() log.Printf("gl.CopyTexSubImage2D(%v, %v, %v, %v, %v, %v, %v, %v) %v", target, level, xoffset, yoffset, x, y, width, height, errstr) }() C.glCopyTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func CompressedTexSubImage2D(target Enum, level, xoffset, yoffset, width, height int, format Enum, data []byte) { defer func() { errstr := errDrain() log.Printf("gl.CompressedTexSubImage2D(%v, %v, %v, %v, %v, %v, %v, len(%d)) %v", target, level, xoffset, yoffset, width, height, format, len(data), errstr) }() C.glCompressedTexSubImage2D(target.c(), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), format.c(), C.GLsizei(len(data)), unsafe.Pointer(&data[0])) }
func Uniform4i(dst Uniform, v0, v1, v2, v3 int32) { defer func() { errstr := errDrain() log.Printf("gl.Uniform4i(%v, %v, %v, %v, %v) %v", dst, v0, v1, v2, v3, errstr) }() C.glUniform4i(dst.c(), C.GLint(v0), C.GLint(v1), C.GLint(v2), C.GLint(v3)) }
func Viewport(x, y, width, height int) { defer func() { errstr := errDrain() log.Printf("gl.Viewport(%v, %v, %v, %v) %v", x, y, width, height, errstr) }() C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func TexSubImage2D(target Enum, level int, x, y, width, height int, format, ty Enum, data []byte) { defer func() { errstr := errDrain() log.Printf("gl.TexSubImage2D(%v, %v, %v, %v, %v, %v, %v, %v, len(%d)) %v", target, level, x, y, width, height, format, ty, len(data), errstr) }() C.glTexSubImage2D(target.c(), C.GLint(level), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), format.c(), ty.c(), unsafe.Pointer(&data[0])) }
func Uniform2i(dst Uniform, v0, v1 int) { defer func() { errstr := errDrain() log.Printf("gl.Uniform2i(%v, %v, %v) %v", dst, v0, v1, errstr) }() C.glUniform2i(dst.c(), C.GLint(v0), C.GLint(v1)) }
func Scissor(x, y, width, height int32) { defer func() { errstr := errDrain() log.Printf("gl.Scissor(%v, %v, %v, %v) %v", x, y, width, height, errstr) }() C.glScissor(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func CopyTexImage2D(target Enum, level int, internalformat Enum, x, y, width, height, border int) { defer func() { errstr := errDrain() log.Printf("gl.CopyTexImage2D(%v, %v, %v, %v, %v, %v, %v, %v) %v", target, level, internalformat, x, y, width, height, border, errstr) }() C.glCopyTexImage2D(target.c(), C.GLint(level), internalformat.c(), C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height), C.GLint(border)) }
func ReadAlpha(image *image.Alpha) { alignment := C.GLint(0) C.glGetIntegerv(C.GL_PACK_ALIGNMENT, &alignment) align := C.GLint(1) for align < alignment && image.Stride%(int(align)*2) == 0 { align *= 2 } // need smaller alignment if align < alignment { C.glPixelStorei(C.GL_PACK_ALIGNMENT, align) } C.glReadPixels(C.GLint(image.Rect.Min.X), C.GLint(image.Rect.Min.Y), C.GLsizei(image.Rect.Dx()), C.GLsizei(image.Rect.Dy()), C.GL_ALPHA, C.GL_UNSIGNED_BYTE, unsafe.Pointer(&image.Pix[0])) // restore alignment if align < alignment { C.glPixelStorei(C.GL_PACK_ALIGNMENT, alignment) } }
func Viewport( x int32, y int32, width Sizei, height Sizei) { C.glViewport( C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func CompressedTexImage2D(target uint, level int, internalformat uint, width, height, border, imageSize int, data Void) { C.glCompressedTexImage2D( C.GLenum(target), C.GLint(level), C.GLenum(internalformat), C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLsizei(imageSize), unsafe.Pointer(data)) }
// TexImage2D writes a 2D texture image. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { // TODO(crawshaw): GLES3 offset for PIXEL_UNPACK_BUFFER and PIXEL_PACK_BUFFER. p := unsafe.Pointer(nil) if len(data) > 0 { p = unsafe.Pointer(&data[0]) } C.glTexImage2D(target.c(), C.GLint(level), C.GLint(format), C.GLsizei(width), C.GLsizei(height), 0, format.c(), ty.c(), p) }
//void glMap2f (GLenum target, float32 u1, float32 u2, int ustride, int uorder, float32 v1, float32 v2, int vstride, int vorder, const float32 *points) func Map2f(target GLenum, u1 float32, u2 float32, ustride int, uorder int, v1 float32, v2 float32, vstride int, vorder int, points []float32) { if len(points) == 0 { panic("Invalid points size") } C.glMap2f(C.GLenum(target), C.GLfloat(u1), C.GLfloat(u2), C.GLint(ustride), C.GLint(uorder), C.GLfloat(v1), C.GLfloat(v2), C.GLint(vstride), C.GLint(vorder), (*C.GLfloat)(&points[0])) }
//void glMap2d (GLenum target, float64 u1, float64 u2, int ustride, int uorder, float64 v1, float64 v2, int vstride, int vorder, const float64 *points) func Map2d(target GLenum, u1 float64, u2 float64, ustride int, uorder int, v1 float64, v2 float64, vstride int, vorder int, points []float64) { if len(points) == 0 { panic("Invalid points size") } C.glMap2d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2), C.GLint(ustride), C.GLint(uorder), C.GLdouble(v1), C.GLdouble(v2), C.GLint(vstride), C.GLint(vorder), (*C.GLdouble)(&points[0])) }
func TexSubImage2D(target uint, level, xoffset, yoffset, width, height int, format, type_ uint, pixels Void) { C.glTexSubImage2D(C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(type_), unsafe.Pointer(pixels)) }
func Uniform3i( location int32, x int32, y int32, z int32) { C.glUniform3i( C.GLint(location), C.GLint(x), C.GLint(y), C.GLint(z)) }
func Scissor( x int32, y int32, width Sizei, height Sizei) { C.glScissor( C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) }
func CompressedTexSubImage2D(target uint, level, xoffset, yoffset int, width, height int, format uint, imageSize int, data Void) { C.glCompressedTexSubImage2D( C.GLenum(target), C.GLint(level), C.GLint(xoffset), C.GLint(yoffset), C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLsizei(imageSize), unsafe.Pointer(data)) }
func (program *Program) GetUniform(name string) Uniform { cname := (*C.GLchar)(C.CString(name)) defer C.free(unsafe.Pointer(cname)) loc := C.GLint(C.glGetUniformLocation(program.id, cname)) if loc < 0 { panic(fmt.Errorf("not an active uniform: %s", name)) } datatype := C.GLenum(0) length := C.GLsizei(0) size := C.GLint(0) uname := [32]byte{} C.glGetActiveUniform(program.id, C.GLuint(loc), C.GLsizei(len(uname)), &length, &size, &datatype, (*C.GLchar)(unsafe.Pointer(&uname[0]))) switch datatype { case C.GL_FLOAT: return Uniform1f{uniformBase{loc}} case C.GL_FLOAT_VEC2: return Uniform2f{uniformBase{loc}} case C.GL_FLOAT_VEC3: return Uniform3f{uniformBase{loc}} case C.GL_FLOAT_VEC4: return Uniform4f{uniformBase{loc}} case C.GL_INT: return Uniform1i{uniformBase{loc}} case C.GL_INT_VEC2: return Uniform2i{uniformBase{loc}} case C.GL_INT_VEC3: return Uniform3i{uniformBase{loc}} case C.GL_INT_VEC4: return Uniform4i{uniformBase{loc}} case C.GL_BOOL: return Uniform1i{uniformBase{loc}} case C.GL_BOOL_VEC2: return Uniform2i{uniformBase{loc}} case C.GL_BOOL_VEC3: return Uniform3i{uniformBase{loc}} case C.GL_BOOL_VEC4: return Uniform4i{uniformBase{loc}} case C.GL_FLOAT_MAT2: return UniformMatrix2f{uniformBase{loc}} case C.GL_FLOAT_MAT3: return UniformMatrix3f{uniformBase{loc}} case C.GL_FLOAT_MAT4: return UniformMatrix4f{uniformBase{loc}} case C.GL_SAMPLER_2D: return Uniform1i{uniformBase{loc}} case C.GL_SAMPLER_CUBE: return Uniform1i{uniformBase{loc}} default: panic(fmt.Errorf("unsupported uniform type: %#x", datatype)) } }
func TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { defer func() { errstr := errDrain() log.Printf("gl.TexImage2D(%v, %v, %v, %v, %v, %v, len(%d)) %v", target, level, width, height, format, ty, len(data), errstr) }() p := unsafe.Pointer(nil) if len(data) > 0 { p = unsafe.Pointer(&data[0]) } C.glTexImage2D(target.c(), C.GLint(level), C.GLint(format), C.GLsizei(width), C.GLsizei(height), 0, format.c(), ty.c(), p) }
func (game *game) drawFrame() { time += .05 color := (C.GLclampf(math.Sin(time)) + 1) * .5 C.glUniform2f(C.GLint(game.offsetUni), C.GLfloat(game.offsetX), C.GLfloat(game.offsetY)) C.glUniform3f(C.GLint(game.colorUni), 1.0, C.GLfloat(color), 0) C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT) C.glUseProgram(game.prog) C.glDrawArrays(C.GL_TRIANGLES, 0, 3) }