mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user