clipping fixed
This commit is contained in:
parent
f57765cdc5
commit
649cffa1e3
3 changed files with 22 additions and 11 deletions
|
@ -262,7 +262,10 @@ func LoadGL(glimpl GL) (err error) {
|
|||
gli.Enable(gl_BLEND)
|
||||
gli.BlendFunc(gl_SRC_ALPHA, gl_ONE_MINUS_SRC_ALPHA)
|
||||
gli.Enable(gl_STENCIL_TEST)
|
||||
gli.StencilFunc(gl_EQUAL, 1, 0x00)
|
||||
gli.StencilMask(0xFF)
|
||||
gli.Clear(gl_STENCIL_BUFFER_BIT)
|
||||
gli.StencilOp(gl_KEEP, gl_KEEP, gl_KEEP)
|
||||
gli.StencilFunc(gl_EQUAL, 0, 0xFF)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
26
paths.go
26
paths.go
|
@ -465,17 +465,12 @@ func (cv *Canvas) Clip() {
|
|||
func (cv *Canvas) clip(path []pathPoint) {
|
||||
cv.activate()
|
||||
|
||||
gli.ColorMask(false, false, false, false)
|
||||
gli.StencilFunc(gl_ALWAYS, 2, 0xFF)
|
||||
gli.StencilOp(gl_REPLACE, gl_REPLACE, gl_REPLACE)
|
||||
gli.StencilMask(0x02)
|
||||
gli.Clear(gl_STENCIL_BUFFER_BIT)
|
||||
|
||||
var triBuf [1000]float32
|
||||
tris := triBuf[:0]
|
||||
tris = append(tris, 0, 0, float32(cv.fw), 0, float32(cv.fw), float32(cv.fh), 0, 0, float32(cv.fw), float32(cv.fh), 0, float32(cv.fh))
|
||||
baseLen := len(tris)
|
||||
tris = triangulatePath(path, tris)
|
||||
if len(tris) > 0 {
|
||||
if len(tris) <= baseLen {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -488,10 +483,23 @@ func (cv *Canvas) clip(path []pathPoint) {
|
|||
gli.Uniform2f(sr.canvasSize, float32(cv.fw), float32(cv.fh))
|
||||
gli.EnableVertexAttribArray(sr.vertex)
|
||||
|
||||
gli.DrawArrays(gl_TRIANGLES, 0, 6)
|
||||
gli.StencilFunc(gl_ALWAYS, 0, 0xFF)
|
||||
gli.ColorMask(false, false, false, false)
|
||||
|
||||
gli.StencilMask(0x04)
|
||||
gli.StencilFunc(gl_ALWAYS, 4, 0x04)
|
||||
gli.StencilOp(gl_REPLACE, gl_REPLACE, gl_REPLACE)
|
||||
gli.DrawArrays(gl_TRIANGLES, 6, int32(len(tris)/2-6))
|
||||
|
||||
gli.StencilMask(0x02)
|
||||
gli.StencilFunc(gl_EQUAL, 0, 0x06)
|
||||
gli.StencilOp(gl_KEEP, gl_INVERT, gl_INVERT)
|
||||
gli.DrawArrays(gl_TRIANGLES, 0, 6)
|
||||
|
||||
gli.StencilMask(0x04)
|
||||
gli.StencilFunc(gl_ALWAYS, 0, 0x04)
|
||||
gli.StencilOp(gl_ZERO, gl_ZERO, gl_ZERO)
|
||||
gli.DrawArrays(gl_TRIANGLES, 0, 6)
|
||||
|
||||
gli.DisableVertexAttribArray(sr.vertex)
|
||||
|
||||
gli.ColorMask(true, true, true, true)
|
||||
|
|
|
@ -38,7 +38,7 @@ func CreateCanvasWindow(w, h int, title string) (*Window, *canvas.Canvas, error)
|
|||
sdl.GL_SetAttribute(sdl.GL_BLUE_SIZE, 8)
|
||||
sdl.GL_SetAttribute(sdl.GL_ALPHA_SIZE, 8)
|
||||
sdl.GL_SetAttribute(sdl.GL_DEPTH_SIZE, 0)
|
||||
sdl.GL_SetAttribute(sdl.GL_STENCIL_SIZE, 1)
|
||||
sdl.GL_SetAttribute(sdl.GL_STENCIL_SIZE, 8)
|
||||
sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
|
||||
sdl.GL_SetAttribute(sdl.GL_MULTISAMPLEBUFFERS, 1)
|
||||
sdl.GL_SetAttribute(sdl.GL_MULTISAMPLESAMPLES, 4)
|
||||
|
|
Loading…
Reference in a new issue