clipping is now saved and restored

This commit is contained in:
Thomas Friedel 2018-02-05 12:27:34 +01:00
parent 56f9d04c91
commit 3ead983efa
2 changed files with 18 additions and 1 deletions

View file

@ -49,6 +49,8 @@ type drawState struct {
lineDash []float32 lineDash []float32
lineDashPoint int lineDashPoint int
lineDashOffset float32 lineDashOffset float32
clip []pathPoint
/* /*
The current transformation matrix. The current transformation matrix.
The current clipping region. The current clipping region.
@ -264,8 +266,16 @@ func (cv *Canvas) Restore() {
if l <= 0 { if l <= 0 {
return return
} }
hadClip := len(cv.state.clip) > 0
cv.state = cv.stateStack[l-1] cv.state = cv.stateStack[l-1]
cv.stateStack = cv.stateStack[:l-1] cv.stateStack = cv.stateStack[:l-1]
if len(cv.state.clip) > 0 {
cv.clip(cv.state.clip)
} else if hadClip {
gli.StencilMask(0x02)
gli.Clear(gl_STENCIL_BUFFER_BIT)
gli.StencilMask(0xFF)
}
} }
func (cv *Canvas) Scale(x, y float32) { func (cv *Canvas) Scale(x, y float32) {

View file

@ -334,6 +334,10 @@ func (cv *Canvas) Clip() {
return return
} }
cv.clip(cv.polyPath)
}
func (cv *Canvas) clip(path []pathPoint) {
cv.activate() cv.activate()
gli.ColorMask(false, false, false, false) gli.ColorMask(false, false, false, false)
@ -353,7 +357,7 @@ func (cv *Canvas) Clip() {
tris := buf[:0] tris := buf[:0]
tris = append(tris, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1) tris = append(tris, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1)
tris = triangulatePath(cv.polyPath, tris) tris = triangulatePath(path, tris)
total := len(tris) total := len(tris)
for i := 12; i < total; i += 2 { for i := 12; i < total; i += 2 {
x, y := tris[i], tris[i+1] x, y := tris[i], tris[i+1]
@ -373,4 +377,7 @@ func (cv *Canvas) Clip() {
gli.StencilOp(gl_KEEP, gl_KEEP, gl_KEEP) gli.StencilOp(gl_KEEP, gl_KEEP, gl_KEEP)
gli.StencilMask(0xFF) gli.StencilMask(0xFF)
gli.StencilFunc(gl_EQUAL, 0, 0xFF) gli.StencilFunc(gl_EQUAL, 0, 0xFF)
cv.state.clip = make([]pathPoint, len(cv.polyPath))
copy(cv.state.clip, cv.polyPath)
} }