gpu/internal/opengl: avoid PACK/UNPACK_ROW_LENGTH on WebGL 1

Fixes gio#259

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-09-05 10:23:45 +02:00
parent 0403b1ff8e
commit bde046de54
2 changed files with 20 additions and 3 deletions
+14 -3
View File
@@ -1200,8 +1200,14 @@ func (f *framebuffer) ReadPixels(src image.Rectangle, pixels []byte, stride int)
if len(pixels) < src.Dx()*src.Dy()*4 {
return errors.New("unexpected RGBA size")
}
f.backend.glstate.pixelStorei(f.backend.funcs, gl.PACK_ROW_LENGTH, stride/4)
f.backend.funcs.ReadPixels(src.Min.X, src.Min.Y, src.Dx(), src.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, pixels)
w, h := src.Dx(), src.Dy()
// WebGL 1 doesn't support PACK_ROW_LENGTH != 0. Avoid it if possible.
rowLen := 0
if n := stride / 4; n != w {
rowLen = n
}
f.backend.glstate.pixelStorei(f.backend.funcs, gl.PACK_ROW_LENGTH, rowLen)
f.backend.funcs.ReadPixels(src.Min.X, src.Min.Y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
return glErr(f.backend.funcs)
}
@@ -1262,7 +1268,12 @@ func (t *texture) Upload(offset, size image.Point, pixels []byte, stride int) {
panic(fmt.Errorf("size %d larger than data %d", min, len(pixels)))
}
t.backend.BindTexture(0, t)
t.backend.glstate.pixelStorei(t.backend.funcs, gl.UNPACK_ROW_LENGTH, stride/4)
// WebGL 1 doesn't support UNPACK_ROW_LENGTH != 0. Avoid it if possible.
rowLen := 0
if n := stride / 4; n != size.X {
rowLen = n
}
t.backend.glstate.pixelStorei(t.backend.funcs, gl.UNPACK_ROW_LENGTH, rowLen)
t.backend.funcs.TexSubImage2D(gl.TEXTURE_2D, 0, offset.X, offset.Y, size.X, size.Y, t.triple.format, t.triple.typ, pixels)
}
+6
View File
@@ -262,6 +262,12 @@ func (f *Functions) GetBindingi(pname Enum, idx int) Object {
return Object(obj)
}
func (f *Functions) GetInteger(pname Enum) int {
if !f.isWebGL2 {
switch pname {
case PACK_ROW_LENGTH, UNPACK_ROW_LENGTH:
return 0 // PACK_ROW_LENGTH and UNPACK_ROW_LENGTH is only available on WebGL 2
}
}
return paramVal(f.Ctx.Call("getParameter", int(pname)))
}
func (f *Functions) GetFloat(pname Enum) float32 {