Esempio n. 1
0
func (t *Texture) ReadTextureFromGPU() []byte {
	t.Bind()
	b := gl.GenBuffer()
	b.Bind(gl.PIXEL_UNPACK_BUFFER)
	gl.BufferData(gl.PIXEL_UNPACK_BUFFER, t.Width()*t.Height()*t.PixelSize(), 0, gl.STREAM_DRAW)
	//gl.GetTexImage(t.target, 0, t.format, buffer)
	b.Bind(gl.PIXEL_UNPACK_BUFFER)

	gl.TexSubImage2D(t.target, 0, 0, 0, t.Width(), t.Height(), t.format, t.typ, unsafe.Pointer(uintptr(0)))
	b.Bind(gl.PIXEL_UNPACK_BUFFER)

	l := t.Width() * t.Height() * t.PixelSize()

	gl.BufferData(gl.PIXEL_UNPACK_BUFFER, t.Width()*t.Height()*t.PixelSize(), 0, gl.STREAM_DRAW)
	ptr := gl.MapBuffer(gl.PIXEL_UNPACK_BUFFER, gl.WRITE_ONLY)

	var x []byte
	s := (*reflect.SliceHeader)(unsafe.Pointer(&x))
	s.Data = uintptr(ptr)
	s.Len = l
	s.Cap = l

	gl.UnmapBuffer(gl.PIXEL_UNPACK_BUFFER)

	return x
}
Esempio n. 2
0
func HeightMapUpdate(loc *renderstuff.RenderLocations, entity renderstuff.IRenderEntity, etc interface{}) {
	heightMap := entity.(*gamestate.HeightMap)

	if heightMap.HasChanges {
		min_h, max_h := heightMap.Bounds()
		loc.LowerBound.Uniform3f(0, 0, min_h)
		loc.UpperBound.Uniform3f(float32(heightMap.W), float32(heightMap.H), max_h)
		gl.ActiveTexture(gl.TEXTURE0 + constants.TextureHeightMap)
		gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, heightMap.W, heightMap.H, gl.RED, gl.FLOAT, heightMap.TexturePixels())
		gl.ActiveTexture(gl.TEXTURE0)
		heightMap.HasChanges = false
	}
}