From 242045f66252db6ae78a12888623fe2a242d1b48 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 10 Feb 2022 17:03:13 +0100 Subject: [PATCH] gpu/internal/opengl: ensure Backend.queryState is idempotent Backend.queryState sets GL_ACTIVE_TEXTURE to access texture bindings; this change makes sure GL_ACTIVE_TEXTURE is restored. Also, make sure GL state changes made in Backend.restoreState is reflected in Backend.glstate. Backend.glstate is not used after restoreState, so this is just for clarity. This is an alternative to https://github.com/gioui/gio/pull/77. Signed-off-by: Elias Naur --- gpu/internal/opengl/opengl.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gpu/internal/opengl/opengl.go b/gpu/internal/opengl/opengl.go index 8d4409aa..8dc92421 100644 --- a/gpu/internal/opengl/opengl.go +++ b/gpu/internal/opengl/opengl.go @@ -339,10 +339,12 @@ func (b *Backend) queryState() glState { s.storeBufs[i] = gl.Buffer(b.funcs.GetBindingi(gl.SHADER_STORAGE_BUFFER_BINDING, i)) } } + active := s.texUnits.active for i := range s.texUnits.binds { s.activeTexture(b.funcs, gl.TEXTURE0+gl.Enum(i)) s.texUnits.binds[i] = gl.Texture(b.funcs.GetBinding(gl.TEXTURE_BINDING_2D)) } + s.activeTexture(b.funcs, active) for i := range s.vertAttribs { a := &s.vertAttribs[i] a.enabled = b.funcs.GetVertexAttrib(i, gl.VERTEX_ATTRIB_ARRAY_ENABLED) != gl.FALSE @@ -357,7 +359,7 @@ func (b *Backend) queryState() glState { } func (b *Backend) restoreState(dst glState) { - src := b.glstate + src := &b.glstate f := b.funcs for i, unit := range dst.texUnits.binds { src.bindTexture(f, i, unit)