func fill(canv *Canvas, alphaTex *glh.Texture, paint *Paint) { gGl.GlColorConfig.SetColor(paint.fillColor) defer gGl.GlColorConfig.Reset() gGl.Activate(gGl.FillDrawer) gl.ColorMask(true, true, true, true) gl.StencilMask(0x3) gl.StencilFunc(gl.LESS, 0, 0xff) w, h := canv.W, canv.H p := canv.toGLPoints([]Point{ iPt(0, 0), iPt(w, 0), iPt(w, h), iPt(0, h), }) vertices := []float32{ p[0].X, p[0].Y, 0, 1, p[1].X, p[1].Y, 1, 1, p[2].X, p[2].Y, 1, 0, p[3].X, p[3].Y, 0, 0, } gl.BufferData(gl.ARRAY_BUFFER, len(vertices)*4, vertices, gl.STATIC_DRAW) elements := []uint32{ 0, 1, 2, 2, 3, 0, } gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, len(elements)*4, elements, gl.STATIC_DRAW) glh.With(alphaTex, func() { gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) }) }
func (p *Path) draw(canv *Canvas, alphaBuffer *glh.Framebuffer, clrStencil bool) { gGl.QuadraticDrawConfig.SetExcludeTransluFrags(false) glh.With(alphaBuffer, func() { gl.ClearColor(0, 0, 0, 0) gl.Clear(gl.COLOR_BUFFER_BIT) p.glDraw(canv) }) if clrStencil { gl.StencilMask(0x3) gl.ClearStencil(0x0) gl.Clear(gl.STENCIL_BUFFER_BIT) } gl.ColorMask(false, false, false, false) gl.StencilMask(0x3) gl.StencilFunc(gl.ALWAYS, 0, 0xff) gl.StencilOp(gl.KEEP, gl.KEEP, gl.INVERT) p.glDraw(canv) gl.StencilMask(0x1) gGl.QuadraticDrawConfig.SetExcludeTransluFrags(true) p.glDraw(canv) }