Пример #1
0
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)
	}
}
Пример #2
0
Файл: gla.go Проект: spate/gla
// TexImage2DFromImage loads texture data from an image.Image into the currently
// bound GL texture using the glTexImage2D call. If you wish to load only part of
// an image, pass a subimage as the argument.
//
// Precondition: no buffer object bound to PIXEL_UNPACK_BUFFER
//
// Additional state modified: UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH
func TexImage2DFromImage(target GLenum, level int, internalformat int, border int, img image.Image) {
	bounds := img.Bounds()
	if bounds.Empty() {
		return
	}

	info := getImageInfo(img)

	C.glPixelStorei(C.GLenum(gl.UNPACK_ALIGNMENT), C.GLint(1))
	C.glPixelStorei(C.GLenum(gl.UNPACK_ROW_LENGTH), C.GLint(info.RowLength))
	C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat),
		C.GLsizei(bounds.Dx()), C.GLsizei(bounds.Dy()), C.GLint(border),
		C.GLenum(info.Format), C.GLenum(info.Type),
		info.Data)
}
Пример #3
0
Файл: gla.go Проект: spate/gla
// TexSubImage2DFromImage loads texture data from an image.Image into the currently
// bound GL texture using the glTexSubImage2D call. If you wish to load only part of
// an image, pass a subimage as the argument.
//
// Precondition: no buffer object bound to PIXEL_UNPACK_BUFFER
//
// Additional state modified: UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH
func TexSubImage2DFromImage(target GLenum, level int, dest image.Rectangle, img image.Image) {
	bounds := img.Bounds()
	if dest.Dx() > bounds.Dx() || dest.Dy() > bounds.Dy() {
		return
	}

	info := getImageInfo(img)

	C.glPixelStorei(C.GLenum(gl.UNPACK_ALIGNMENT), C.GLint(1))
	C.glPixelStorei(C.GLenum(gl.UNPACK_ROW_LENGTH), C.GLint(info.RowLength))
	C.glTexSubImage2D(C.GLenum(target), C.GLint(level),
		C.GLint(dest.Min.X), C.GLint(dest.Min.Y),
		C.GLsizei(dest.Dx()), C.GLsizei(dest.Dy()),
		C.GLenum(info.Format), C.GLenum(info.Type),
		info.Data)
}
Пример #4
0
func PixelStorei(pname Enum, param int32) {
	defer func() {
		errstr := errDrain()
		log.Printf("gl.PixelStorei(%v, %v) %v", pname, param, errstr)
	}()
	C.glPixelStorei(pname.c(), C.GLint(param))
}
Пример #5
0
func ReadRGBA(image *image.NRGBA) {

	alignment := C.GLint(0)
	C.glGetIntegerv(C.GL_PACK_ALIGNMENT, &alignment)

	align := image.Stride % int(alignment) // align: 4 or 0

	// need smaller alignment
	if align > 0 {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, C.GLint(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_RGBA, C.GL_UNSIGNED_BYTE, unsafe.Pointer(&image.Pix[0]))

	// restore alignment
	if align > 0 {
		C.glPixelStorei(C.GL_PACK_ALIGNMENT, alignment)
	}
}
Пример #6
0
func adjustUnpackAlignment(stride int) C.GLint {

	alignment := C.GLint(0)
	C.glGetIntegerv(C.GL_UNPACK_ALIGNMENT, &alignment)

	align := C.GLint(1)

	for align < alignment && stride%(int(align)*2) == 0 {
		align *= 2
	}

	// need smaller alignment
	if align < alignment {
		C.glPixelStorei(C.GL_UNPACK_ALIGNMENT, align)
		// return old alignment
		return alignment
	} else {
		return 0
	}
}
Пример #7
0
func PixelStorei(pname Enum, param int32) {
	C.glPixelStorei(pname.c(), C.GLint(param))
}
Пример #8
0
func PixelStorei(
	pname Enum, param int32) {
	C.glPixelStorei(
		C.GLenum(pname),
		C.GLint(param))
}
Пример #9
0
func PixelStorei(pname Packing, param int) {
	C.glPixelStorei(C.GLenum(pname), C.GLint(param))
}
Пример #10
0
func restoreAlignment(alignment C.GLint) {
	if alignment > 0 {
		C.glPixelStorei(C.GL_UNPACK_ALIGNMENT, alignment)
	}
}
Пример #11
0
func PixelStorei(pname, param uint) {
	C.glPixelStorei(C.GLenum(pname), C.GLint(param))
}