예제 #1
0
파일: gldebug.go 프로젝트: Miaque/mojo
func RenderbufferStorage(target, internalFormat Enum, width, height int) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.RenderbufferStorage(%v, %v, %v, %v) %v", target, internalFormat, width, height, errstr)
	}()
	C.glRenderbufferStorage(target.c(), internalFormat.c(), C.GLsizei(width), C.GLsizei(height))
}
예제 #2
0
파일: gldebug.go 프로젝트: Miaque/mojo
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))
}
예제 #3
0
파일: shader.go 프로젝트: jackscan/go-gles3
func (program *Program) GetAttrib(name string) VertexAttrib {

	cname := (*C.GLchar)(C.CString(name))
	defer C.free(unsafe.Pointer(cname))

	iloc := C.glGetAttribLocation(program.id, cname)
	if iloc < 0 {
		panic(fmt.Errorf("not an active attribute: %s", name))
	}

	loc := C.GLuint(iloc)

	datatype := C.GLenum(0)
	length := C.GLsizei(0)
	size := C.GLint(0)

	aname := [32]byte{}

	C.glGetActiveAttrib(program.id, C.GLuint(loc), C.GLsizei(len(aname)), &length, &size, &datatype, (*C.GLchar)(unsafe.Pointer(&aname[0])))

	switch datatype {
	case C.GL_FLOAT:
		return FloatAttrib{vattrib{loc}}
	case C.GL_FLOAT_VEC2:
		return Vec2Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC3:
		return Vec3Attrib{FloatAttrib{vattrib{loc}}}
	case C.GL_FLOAT_VEC4:
		return Vec4Attrib{FloatAttrib{vattrib{loc}}}
	default:
		panic(fmt.Errorf("unsupported attribute type: %#x", datatype))
	}
}
예제 #4
0
파일: gldebug.go 프로젝트: Miaque/mojo
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))
}
예제 #5
0
파일: gl.go 프로젝트: jackscan/go-gles2
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)
	}
}
예제 #6
0
파일: es2.go 프로젝트: nick-fedesna/egles
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))
}
예제 #7
0
파일: gl.go 프로젝트: extrame/gl
// Link links the attached shader objects
func (p *Program) Link() error {
	var val, val2 C.GLint
	C.glLinkProgram(p.i)
	C.glGetProgramiv(p.i, LINK_STATUS, &val)
	if val != TRUE {
		C.glGetProgramiv(p.i, INFO_LOG_LENGTH, &val)
		buf := make([]C.GLchar, val+1)
		C.glGetProgramInfoLog(p.i, C.GLsizei(val), nil, &buf[0])
		return errors.New(C.GoString((*C.char)(&buf[0])))
	}
	p.attr = make(map[string]C.GLuint)
	C.glGetProgramiv(p.i, ACTIVE_ATTRIBUTES, &val)
	C.glGetProgramiv(p.i, ACTIVE_ATTRIBUTE_MAX_LENGTH, &val2)
	buf := make([]C.char, val2)
	for i := C.GLuint(0); i < C.GLuint(val); i++ {
		C.glGetActiveAttrib(p.i, i, C.GLsizei(val2), nil, nil, nil, (*C.GLchar)(&buf[0]))
		p.attr[C.GoString(&buf[0])] = C.GLuint(C.glGetAttribLocation(p.i, (*C.GLchar)(&buf[0])))
	}
	p.uni = make(map[string]C.GLint)
	C.glGetProgramiv(p.i, ACTIVE_UNIFORMS, &val)
	C.glGetProgramiv(p.i, ACTIVE_UNIFORM_MAX_LENGTH, &val2)
	buf = make([]C.char, val2)
	for i := C.GLuint(0); i < C.GLuint(val); i++ {
		C.glGetActiveUniform(p.i, i, C.GLsizei(val2), nil, nil, nil, (*C.GLchar)(&buf[0]))
		p.uni[C.GoString(&buf[0])] = C.glGetUniformLocation(p.i, (*C.GLchar)(&buf[0]))
	}
	return nil
}
예제 #8
0
파일: es2.go 프로젝트: nick-fedesna/egles
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))
}
예제 #9
0
파일: gl_opengles.go 프로젝트: shibukawa/gl
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)
}
예제 #10
0
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))
	}
}
예제 #11
0
파일: gldebug.go 프로젝트: Miaque/mojo
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]))
}
예제 #12
0
파일: blendish.go 프로젝트: james4k/exp
func BeginFrame(width, height int, devicePixelRatio float32) {
	w := C.GLsizei(float32(width) * devicePixelRatio)
	h := C.GLsizei(float32(height) * devicePixelRatio)
	C.glViewport(0, 0, w, h)
	C.glClearColor(0, 0, 0, 1)
	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT | C.GL_STENCIL_BUFFER_BIT)
	C.nvgBeginFrame(vg, C.int(width), C.int(height), C.float(devicePixelRatio))
}
예제 #13
0
파일: es2.go 프로젝트: nick-fedesna/egles
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))
}
예제 #14
0
파일: es2.go 프로젝트: nick-fedesna/egles
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))
}
예제 #15
0
파일: gl.go 프로젝트: TriangleGo/golang.org
// 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)
}
예제 #16
0
파일: gles2.go 프로젝트: remogatto/egles
func Viewport(
	x int32, y int32, width Sizei, height Sizei) {
	C.glViewport(
		C.GLint(x),
		C.GLint(y),
		C.GLsizei(width),
		C.GLsizei(height))
}
예제 #17
0
파일: imp.go 프로젝트: CaptainSoOmA/Uni
func initialize() {
	//
	if !initialized {
		initialized = true
		scr.Switch(scr.XGA) // (scr.MaxMode())
		C.glViewport(0, 0, C.GLsizei(scr.NX()), C.GLsizei(scr.NY()))
	}
}
예제 #18
0
파일: gles2.go 프로젝트: remogatto/egles
func Scissor(
	x int32, y int32, width Sizei, height Sizei) {
	C.glScissor(
		C.GLint(x),
		C.GLint(y),
		C.GLsizei(width),
		C.GLsizei(height))
}
예제 #19
0
파일: shader.go 프로젝트: jackscan/go-gles3
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))
	}
}
예제 #20
0
파일: gles2.go 프로젝트: remogatto/egles
func RenderbufferStorage(
	target Enum, internalformat Enum,
	width Sizei, height Sizei) {
	C.glRenderbufferStorage(
		C.GLenum(target),
		C.GLenum(internalformat),
		C.GLsizei(width),
		C.GLsizei(height))
}
예제 #21
0
파일: es2.go 프로젝트: nick-fedesna/egles
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))
}
예제 #22
0
파일: gles2.go 프로젝트: remogatto/egles
func ShaderBinary(
	n Sizei, shaders *uint32,
	binaryformat Enum, binary Void, length Sizei) {
	C.glShaderBinary(
		C.GLsizei(n),
		(*C.GLuint)(shaders),
		C.GLenum(binaryformat),
		unsafe.Pointer(binary),
		C.GLsizei(length))
}
예제 #23
0
func Build2DMipmaps(target uint32, internalFormat int, width, height int, format, typ uint32, data unsafe.Pointer) int {
	return int(C.gluBuild2DMipmaps(
		C.GLenum(target),
		C.GLint(internalFormat),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(typ),
		data))
}
예제 #24
0
파일: glu.go 프로젝트: sirctseb/glu
func Build2DMipmaps(target gl.GLenum, internalFormat int, width, height int, format, typ gl.GLenum, data interface{}) int {
	return int(C.gluBuild2DMipmaps(
		C.GLenum(target),
		C.GLint(internalFormat),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(typ),
		ptr(data),
	))
}
예제 #25
0
파일: glu.go 프로젝트: krakensden/Go-OpenGL
func Build2DMipmaps(target gl.GLenum, internalFormat gl.GLint, width, height gl.GLsizei, format, kind gl.GLenum, data unsafe.Pointer) gl.GLint {
	return gl.GLint(C.gluBuild2DMipmaps(
		C.GLenum(target),
		C.GLint(internalFormat),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(kind),
		data,
	))
}
예제 #26
0
파일: gldebug.go 프로젝트: Miaque/mojo
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)
}
예제 #27
0
파일: gles2.go 프로젝트: remogatto/egles
func ReadPixels(
	x int32, y int32, width Sizei, height Sizei,
	format Enum, type_ Enum, pixels Void) {
	C.glReadPixels(
		C.GLint(x),
		C.GLint(y),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(type_),
		unsafe.Pointer(pixels))
}
예제 #28
0
파일: gl.go 프로젝트: extrame/gl
// Add the interface to export image
func ReadPixels(x int, y int, w int, h int) image.Image {
	data := make([]uint16, 4*w*h)
	p := unsafe.Pointer(&data[0])
	C.glReadPixels(C.GLint(x), C.GLint(y), C.GLsizei(w), C.GLsizei(h), C.GLenum(RGBA), C.GLenum(UNSIGNED_SHORT), p)
	rec := image.Rect(x, y, x+w, y+h)
	rgba := image.NewRGBA64(rec)
	for i := 0; i < w*h; i++ {
		c := color.RGBA64{data[4*i], data[4*i+1], data[4*i+2], data[4*i+3]}
		rgba.Set(i%w, h-i/w-1, c)
	}
	return rgba
}
예제 #29
0
func Build2DMipmaps(target gl.GLenum, internalFormat int, width, height int, format gl.GLenum, data interface{}) int {
	t, p := gl.GetGLenumType(data)
	return int(C.gluBuild2DMipmaps(
		C.GLenum(target),
		C.GLint(internalFormat),
		C.GLsizei(width),
		C.GLsizei(height),
		C.GLenum(format),
		C.GLenum(t),
		p,
	))
}
예제 #30
0
파일: texture.go 프로젝트: eaburns/gl
// TexImage2D specifies a two-dimensional texture image.
func TexImage2D(targ TextureTarget, lvl int, ifmt TextureFormat, w, h, border int, fmt TextureFormat, data interface{}) {
	tipe, _, ptr := rawData(data)
	C.glTexImage2D(C.GLenum(targ),
		C.GLint(lvl),
		C.GLint(ifmt),
		C.GLsizei(w),
		C.GLsizei(h),
		C.GLint(border),
		C.GLenum(fmt),
		C.GLenum(tipe),
		ptr)
}