clipping bugfix

This commit is contained in:
Thomas Friedel 2019-03-28 10:53:49 +01:00
parent 3590b73c8b
commit 6a082a74a3
6 changed files with 24 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import (
)
func (b *GoGLBackend) ClearClip() {
b.curClip = nil
b.activate()
gl.StencilMask(0xFF)
@ -14,7 +15,9 @@ func (b *GoGLBackend) ClearClip() {
}
func (b *GoGLBackend) Clip(pts [][2]float64) {
b.curClip = nil
b.activate()
b.curClip = pts
b.ptsBuf = b.ptsBuf[:0]
b.ptsBuf = append(b.ptsBuf,

View file

@ -100,10 +100,12 @@ func (b *GoGLBackend) Fill(style *backendbase.FillStyle, pts [][2]float64) {
if style.Color.A >= 255 {
vertex := b.useShader(style)
gl.StencilFunc(gl.EQUAL, 0, 0xFF)
gl.EnableVertexAttribArray(vertex)
gl.VertexAttribPointer(vertex, 2, gl.FLOAT, false, 0, nil)
gl.DrawArrays(mode, 4, int32(len(pts)))
gl.DisableVertexAttribArray(vertex)
gl.StencilFunc(gl.ALWAYS, 0, 0xFF)
} else {
gl.ColorMask(false, false, false, false)
gl.StencilFunc(gl.ALWAYS, 1, 0xFF)

View file

@ -206,6 +206,8 @@ type GoGLBackend struct {
*GLContext
curClip [][2]float64
activateFn func()
disableTextureRenderTarget func()
}
@ -244,6 +246,11 @@ func New(x, y, w, h int, ctx *GLContext) (*GoGLBackend, error) {
b.activateFn = func() {
gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
gl.Viewport(int32(b.x), int32(b.y), int32(b.w), int32(b.h))
gl.Clear(gl.STENCIL_BUFFER_BIT)
if c := b.curClip; c != nil {
b.curClip = nil
b.Clip(c)
}
}
b.disableTextureRenderTarget = func() {
gl.BindFramebuffer(gl.FRAMEBUFFER, 0)

View file

@ -7,6 +7,7 @@ import (
)
func (b *XMobileBackend) ClearClip() {
b.curClip = nil
b.activate()
b.glctx.StencilMask(0xFF)
@ -14,7 +15,9 @@ func (b *XMobileBackend) ClearClip() {
}
func (b *XMobileBackend) Clip(pts [][2]float64) {
b.curClip = nil
b.activate()
b.curClip = pts
b.ptsBuf = b.ptsBuf[:0]
b.ptsBuf = append(b.ptsBuf,

View file

@ -100,10 +100,12 @@ func (b *XMobileBackend) Fill(style *backendbase.FillStyle, pts [][2]float64) {
if style.Color.A >= 255 {
vertex := b.useShader(style)
b.glctx.StencilFunc(gl.EQUAL, 0, 0xFF)
b.glctx.EnableVertexAttribArray(vertex)
b.glctx.VertexAttribPointer(vertex, 2, gl.FLOAT, false, 0, 0)
b.glctx.DrawArrays(mode, 4, len(pts))
b.glctx.DisableVertexAttribArray(vertex)
b.glctx.StencilFunc(gl.ALWAYS, 0, 0xFF)
} else {
b.glctx.ColorMask(false, false, false, false)
b.glctx.StencilFunc(gl.ALWAYS, 1, 0xFF)

View file

@ -211,6 +211,8 @@ type XMobileBackend struct {
*GLContext
curClip [][2]float64
activateFn func()
disableTextureRenderTarget func()
}
@ -239,6 +241,11 @@ func New(x, y, w, h int, ctx *GLContext) (*XMobileBackend, error) {
b.activateFn = func() {
b.glctx.BindFramebuffer(gl.FRAMEBUFFER, gl.Framebuffer{Value: 0})
b.glctx.Viewport(b.x, b.y, b.w, b.h)
b.glctx.Clear(gl.STENCIL_BUFFER_BIT)
if c := b.curClip; c != nil {
b.curClip = nil
b.Clip(c)
}
}
b.disableTextureRenderTarget = func() {
b.glctx.BindFramebuffer(gl.FRAMEBUFFER, gl.Framebuffer{Value: 0})