gpu: add Framebuffer.ReadPixels

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-22 08:29:45 +01:00
parent 6fd545a4d8
commit e4a927982d
3 changed files with 12 additions and 0 deletions
+1
View File
@@ -127,6 +127,7 @@ type Framebuffer interface {
Bind()
Invalidate()
Release()
ReadPixels(src image.Rectangle, pixels []byte) error
}
type Timer interface {
+10
View File
@@ -589,6 +589,16 @@ func (b *gpuBuffer) BindIndex() {
b.backend.funcs.BindBuffer(ELEMENT_ARRAY_BUFFER, b.obj)
}
func (f *gpuFramebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
glErr(f.funcs)
f.Bind()
if len(pixels) < src.Dx()*src.Dy() {
return errors.New("unexpected RGBA size")
}
f.funcs.ReadPixels(src.Min.X, src.Min.Y, src.Dx(), src.Dy(), RGBA, UNSIGNED_BYTE, pixels)
return glErr(f.funcs)
}
func (f *gpuFramebuffer) Bind() {
f.funcs.BindFramebuffer(FRAMEBUFFER, f.obj)
}
+1
View File
@@ -139,6 +139,7 @@ type Functions interface {
GetUniformLocation(p Program, name string) Uniform
InvalidateFramebuffer(target, attachment Enum)
LinkProgram(p Program)
ReadPixels(x, y, width, height int, format, ty Enum, data []byte)
RenderbufferStorage(target, internalformat Enum, width, height int)
ShaderSource(s Shader, src string)
TexImage2D(target Enum, level int, internalFormat int, width, height int, format, ty Enum, data []byte)