~eliasnaur/gio

2 2

combine textures in GPU ?

Jamil Djadala
Details
Message ID
<20210604142847.7829bd44@beast>
DKIM signature
pass
Download raw message
Hi,
i want to apply operators to textures ( i assume that  paint.NewImageOp
store image as texture in GPU), paint src over dst (with transparency).


currently i do :

dstop := paint.NewImageOp(dstimg)
srcop := paint.NewImageOp(srcimg)

.....

case system.FrameEvent:

ops.Reset()
dstop.Add(ops)
srcop.Add(ops)

paint.PaintOp{}.Add(ops)
e.Frame(ops)




but result is that src replace dst, dst is not visible.

Is there a way to do this, or is it planned in future ?

Regards,
-- 
Jamil Djadala
Details
Message ID
<03e6fc9a-52d6-42d5-b965-a3878c0c9063@www.fastmail.com>
In-Reply-To
<20210604142847.7829bd44@beast> (view parent)
DKIM signature
missing
Download raw message
Hi,

I think you need to use `op.Save` and then `op.Load`, something like:

```
case system.FrameEvent:
 
ops.Reset()

stack := op.Save(gtx.Ops)
dstop.Add(ops)
paint.PaintOp{}.Add(ops)
stack.Load()

stack = op.Save(gtx.Ops)
srcop.Add(ops)
paint.PaintOp{}.Add(ops)
stack.Load()

e.Frame(ops)
```

The `op.Save` will "isolate" the `paint.Op`, but will draw in the same place. I didn't test it, but I think it may fix the issue. 
-- 
  Lucas Rodrigues
  inkeliz@inkeliz.com

On Fri, Jun 4, 2021, at 12:28 PM, Jamil Djadala wrote:
> Hi,
> i want to apply operators to textures ( i assume that  paint.NewImageOp
> store image as texture in GPU), paint src over dst (with transparency).
> 
> 
> currently i do :
> 
> dstop := paint.NewImageOp(dstimg)
> srcop := paint.NewImageOp(srcimg)
> 
> .....
> 
> case system.FrameEvent:
> 
> ops.Reset()
> dstop.Add(ops)
> srcop.Add(ops)
> 
> paint.PaintOp{}.Add(ops)
> e.Frame(ops)
> 
> 
> 
> 
> but result is that src replace dst, dst is not visible.
> 
> Is there a way to do this, or is it planned in future ?
> 
> Regards,
> -- 
> Jamil Djadala
> 
Details
Message ID
<CAFcc3FRLBsuSLFX-L8-UsPJA3tvA9B9MJoTQJBQU+ekAgGwGBA@mail.gmail.com>
In-Reply-To
<20210604142847.7829bd44@beast> (view parent)
DKIM signature
pass
Download raw message
Hi Jamil,

> i want to apply operators to textures ( i assume that  paint.NewImageOp
> store image as texture in GPU), paint src over dst (with transparency).
>
> currently i do :
>
> dstop := paint.NewImageOp(dstimg)
> srcop := paint.NewImageOp(srcimg)
>
> .....
>
> case system.FrameEvent:
>
> ops.Reset()
> dstop.Add(ops)
> srcop.Add(ops)
>
> paint.PaintOp{}.Add(ops)
> e.Frame(ops)
>
> but result is that src replace dst, dst is not visible.
>
> Is there a way to do this, or is it planned in future ?

So the image op itself sets the "brush" of the paintbrush to be an
image: https://pkg.go.dev/gioui.org/op/paint#ImageOp

Then, your paint.PaintOp{}.Add(ops) paints the current brush, which is
the most recently configured image.

I believe that the way to achieve the effect that you want is to
interleave the image ops and the paint ops:

dstop.Add(ops)
paint.PaintOp{}.Add(ops)
srcop.Add(ops)
paint.PaintOp{}.Add(ops)

I built a simple example here: https://play.golang.org/p/Y6oPAKiY1xs

Run that with two textures in the current working directory called
"top.png" and "bottom.png". They will be laid out on top of one
another. Note that if "top.png" is not transparent, it will block what
is underneath it. If you're looking to transform the top image to be
transparent, you'll need to modify the image.Image before you create
the paint.ImageOp.

Cheers,
Chris
Reply to thread Export thread (mbox)