From 526db27c753b2e10d8755f153da36ab59d2fd3de Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 1 Oct 2023 21:00:59 +0000 Subject: [PATCH] gpu: fix opacity layer rendering on OpenGL Fixes: https://todo.sr.ht/~eliasnaur/gio/536 Signed-off-by: Elias Naur --- go.mod | 2 +- go.sum | 4 ++-- gpu/gpu.go | 19 ++++++++++++------- gpu/path.go | 12 ++++++++---- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index d1e4f5fe..20d04df8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 - gioui.org/shader v1.0.7 + gioui.org/shader v1.0.8 github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 diff --git a/go.sum b/go.sum index dea79ffe..52773084 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8v gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc= gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= -gioui.org/shader v1.0.7 h1:fDoor1Id/tRxoIpzBSAr5TBo6QfSkMTOmdbMEyWDgGE= -gioui.org/shader v1.0.7/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= +gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA= +gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 h1:FQivqchis6bE2/9uF70M2gmmLpe82esEm2QadL0TEJo= github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k= github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22 h1:LBQTFxP2MfsyEDqSKmUBZaDuDHN1vpqDyOZjcqS7MYI= diff --git a/gpu/gpu.go b/gpu/gpu.go index 3b7198f3..5cd17f78 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -297,7 +297,8 @@ type blitUniforms struct { uvTransformR1 [4]float32 uvTransformR2 [4]float32 opacity float32 - _ [3]float32 + fbo float32 + _ [2]float32 } type colorUniforms struct { @@ -429,7 +430,7 @@ func (g *gpu) frame(target RenderTarget) error { } g.ctx.BeginRenderPass(defFBO, d) g.ctx.Viewport(0, 0, viewport.X, viewport.Y) - g.renderer.drawOps(g.cache, image.Point{}, g.renderer.blitter.viewport, g.drawOps.imageOps) + g.renderer.drawOps(g.cache, false, image.Point{}, g.renderer.blitter.viewport, g.drawOps.imageOps) g.coverTimer.end() g.ctx.EndRenderPass() g.cleanupTimer.begin() @@ -846,7 +847,7 @@ func (r *renderer) drawLayers(cache *resourceCache, layers []opacityLayer, ops [ } r.ctx.Viewport(v.Min.X, v.Min.Y, v.Max.X, v.Max.Y) f := r.layerFBOs.fbos[fbo] - r.drawOps(cache, l.clip.Min.Mul(-1), l.clip.Size(), ops[l.opStart:l.opEnd]) + r.drawOps(cache, true, l.clip.Min.Mul(-1), l.clip.Size(), ops[l.opStart:l.opEnd]) sr := f32.FRect(v) uvScale, uvOffset := texSpaceTransform(sr, f.size) uvTrans := f32.Affine2D{}.Scale(f32.Point{}, uvScale).Offset(uvOffset) @@ -1212,7 +1213,7 @@ func (r *renderer) prepareDrawOps(cache *resourceCache, ops []imageOp) { } } -func (r *renderer) drawOps(cache *resourceCache, opOff image.Point, viewport image.Point, ops []imageOp) { +func (r *renderer) drawOps(cache *resourceCache, isFBO bool, opOff image.Point, viewport image.Point, ops []imageOp) { var coverTex driver.Texture for i := 0; i < len(ops); i++ { img := ops[i] @@ -1231,7 +1232,7 @@ func (r *renderer) drawOps(cache *resourceCache, opOff image.Point, viewport ima p := r.blitter.pipelines[m.material] r.ctx.BindPipeline(p.pipeline) r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0) - r.blitter.blit(m.material, m.color, m.color1, m.color2, scale, off, m.opacity, m.uvTrans) + r.blitter.blit(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.opacity, m.uvTrans) continue case clipTypePath: fbo = r.pather.stenciler.cover(img.place.Idx) @@ -1250,11 +1251,11 @@ func (r *renderer) drawOps(cache *resourceCache, opOff image.Point, viewport ima p := r.pather.coverer.pipelines[m.material] r.ctx.BindPipeline(p.pipeline) r.ctx.BindVertexBuffer(r.blitter.quadVerts, 0) - r.pather.cover(m.material, m.color, m.color1, m.color2, scale, off, m.uvTrans, coverScale, coverOff) + r.pather.cover(m.material, isFBO, m.color, m.color1, m.color2, scale, off, m.uvTrans, coverScale, coverOff) } } -func (b *blitter) blit(mat materialType, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, opacity float32, uvTrans f32.Affine2D) { +func (b *blitter) blit(mat materialType, fbo bool, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, opacity float32, uvTrans f32.Affine2D) { p := b.pipelines[mat] b.ctx.BindPipeline(p.pipeline) var uniforms *blitUniforms @@ -1276,6 +1277,10 @@ func (b *blitter) blit(mat materialType, col f32color.RGBA, col1, col2 f32color. uniforms.uvTransformR1 = [4]float32{t1, t2, t3, 0} uniforms.uvTransformR2 = [4]float32{t4, t5, t6, 0} } + uniforms.fbo = 0 + if fbo { + uniforms.fbo = 1 + } uniforms.opacity = opacity uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y} p.UploadUniforms(b.ctx) diff --git a/gpu/path.go b/gpu/path.go index b92c4163..e4622677 100644 --- a/gpu/path.go +++ b/gpu/path.go @@ -58,7 +58,7 @@ type coverUniforms struct { uvCoverTransform [4]float32 uvTransformR1 [4]float32 uvTransformR2 [4]float32 - _ float32 + fbo float32 } type stenciler struct { @@ -375,11 +375,11 @@ func (s *stenciler) stencilPath(bounds image.Rectangle, offset f32.Point, uv ima } } -func (p *pather) cover(mat materialType, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, uvTrans f32.Affine2D, coverScale, coverOff f32.Point) { - p.coverer.cover(mat, col, col1, col2, scale, off, uvTrans, coverScale, coverOff) +func (p *pather) cover(mat materialType, isFBO bool, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, uvTrans f32.Affine2D, coverScale, coverOff f32.Point) { + p.coverer.cover(mat, isFBO, col, col1, col2, scale, off, uvTrans, coverScale, coverOff) } -func (c *coverer) cover(mat materialType, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, uvTrans f32.Affine2D, coverScale, coverOff f32.Point) { +func (c *coverer) cover(mat materialType, isFBO bool, col f32color.RGBA, col1, col2 f32color.RGBA, scale, off f32.Point, uvTrans f32.Affine2D, coverScale, coverOff f32.Point) { var uniforms *coverUniforms switch mat { case materialColor: @@ -399,6 +399,10 @@ func (c *coverer) cover(mat materialType, col f32color.RGBA, col1, col2 f32color c.texUniforms.uvTransformR2 = [4]float32{t4, t5, t6, 0} uniforms = &c.texUniforms.coverUniforms } + uniforms.fbo = 0 + if isFBO { + uniforms.fbo = 1 + } uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y} uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y} c.pipelines[mat].UploadUniforms(c.ctx)