removed some dead code; small code improvements
This commit is contained in:
parent
239026dd49
commit
82290ace4a
5 changed files with 11 additions and 75 deletions
|
@ -2,7 +2,6 @@ package goglbackend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/tfriedel6/canvas/backend/backendbase"
|
"github.com/tfriedel6/canvas/backend/backendbase"
|
||||||
|
@ -275,19 +274,6 @@ func (b *GoGLBackendOffscreen) AsImage() backendbase.Image {
|
||||||
return &b.offscrImg
|
return &b.offscrImg
|
||||||
}
|
}
|
||||||
|
|
||||||
type glColor struct {
|
|
||||||
r, g, b, a float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func colorGoToGL(c color.RGBA) glColor {
|
|
||||||
var glc glColor
|
|
||||||
glc.r = float64(c.R) / 255
|
|
||||||
glc.g = float64(c.G) / 255
|
|
||||||
glc.b = float64(c.B) / 255
|
|
||||||
glc.a = float64(c.A) / 255
|
|
||||||
return glc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *GoGLBackend) useShader(style *backendbase.FillStyle, useAlpha bool, alphaTexSlot int32) (vertexLoc, alphaTexCoordLoc uint32) {
|
func (b *GoGLBackend) useShader(style *backendbase.FillStyle, useAlpha bool, alphaTexSlot int32) (vertexLoc, alphaTexCoordLoc uint32) {
|
||||||
gl.UseProgram(b.shd.ID)
|
gl.UseProgram(b.shd.ID)
|
||||||
gl.Uniform2f(b.shd.CanvasSize, float32(b.fw), float32(b.fh))
|
gl.Uniform2f(b.shd.CanvasSize, float32(b.fw), float32(b.fh))
|
||||||
|
@ -355,8 +341,11 @@ func (b *GoGLBackend) useShader(style *backendbase.FillStyle, useAlpha bool, alp
|
||||||
return b.shd.Vertex, b.shd.TexCoord
|
return b.shd.Vertex, b.shd.TexCoord
|
||||||
}
|
}
|
||||||
|
|
||||||
c := colorGoToGL(style.Color)
|
cr := float32(style.Color.R) / 255
|
||||||
gl.Uniform4f(b.shd.Color, float32(c.r), float32(c.g), float32(c.b), float32(c.a))
|
cg := float32(style.Color.G) / 255
|
||||||
|
cb := float32(style.Color.B) / 255
|
||||||
|
ca := float32(style.Color.A) / 255
|
||||||
|
gl.Uniform4f(b.shd.Color, cr, cg, cb, ca)
|
||||||
gl.Uniform1f(b.shd.GlobalAlpha, 1)
|
gl.Uniform1f(b.shd.GlobalAlpha, 1)
|
||||||
gl.Uniform1i(b.shd.Func, shdFuncSolid)
|
gl.Uniform1i(b.shd.Func, shdFuncSolid)
|
||||||
return b.shd.Vertex, b.shd.TexCoord
|
return b.shd.Vertex, b.shd.TexCoord
|
||||||
|
|
11
canvas.go
11
canvas.go
|
@ -179,16 +179,6 @@ type offscreenBuffer struct {
|
||||||
alpha bool
|
alpha bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type gaussianShader struct {
|
|
||||||
id uint32
|
|
||||||
vertex uint32
|
|
||||||
texCoord uint32
|
|
||||||
canvasSize int32
|
|
||||||
kernelScale int32
|
|
||||||
image int32
|
|
||||||
kernel int32
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFillStyle sets the color, gradient, or image for any fill calls. To set a
|
// SetFillStyle sets the color, gradient, or image for any fill calls. To set a
|
||||||
// color, there are several acceptable formats: 3 or 4 int values for RGB(A) in
|
// color, there are several acceptable formats: 3 or 4 int values for RGB(A) in
|
||||||
// the range 0-255, 3 or 4 float values for RGB(A) in the range 0-1, hex strings
|
// the range 0-255, 3 or 4 float values for RGB(A) in the range 0-1, hex strings
|
||||||
|
@ -362,6 +352,7 @@ func (cv *Canvas) SetLineDash(dash []float64) {
|
||||||
cv.state.lineDashOffset = 0
|
cv.state.lineDashOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLineDashOffset sets the line dash offset
|
||||||
func (cv *Canvas) SetLineDashOffset(offset float64) {
|
func (cv *Canvas) SetLineDashOffset(offset float64) {
|
||||||
cv.state.lineDashOffset = offset
|
cv.state.lineDashOffset = offset
|
||||||
}
|
}
|
||||||
|
|
43
color.go
43
color.go
|
@ -8,49 +8,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type glColor struct {
|
|
||||||
r, g, b, a float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func colorGoToGL(color color.Color) glColor {
|
|
||||||
ir, ig, ib, ia := color.RGBA()
|
|
||||||
var c glColor
|
|
||||||
c.r = float64(ir) / 65535
|
|
||||||
c.g = float64(ig) / 65535
|
|
||||||
c.b = float64(ib) / 65535
|
|
||||||
c.a = float64(ia) / 65535
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func colorGLToGo(c glColor) color.RGBA {
|
|
||||||
if c.r < 0 {
|
|
||||||
c.r = 0
|
|
||||||
} else if c.r > 1 {
|
|
||||||
c.r = 1
|
|
||||||
}
|
|
||||||
if c.g < 0 {
|
|
||||||
c.g = 0
|
|
||||||
} else if c.g > 1 {
|
|
||||||
c.g = 1
|
|
||||||
}
|
|
||||||
if c.b < 0 {
|
|
||||||
c.b = 0
|
|
||||||
} else if c.b > 1 {
|
|
||||||
c.b = 1
|
|
||||||
}
|
|
||||||
if c.a < 0 {
|
|
||||||
c.a = 0
|
|
||||||
} else if c.a > 1 {
|
|
||||||
c.a = 1
|
|
||||||
}
|
|
||||||
return color.RGBA{
|
|
||||||
R: uint8(c.r * 255),
|
|
||||||
G: uint8(c.g * 255),
|
|
||||||
B: uint8(c.b * 255),
|
|
||||||
A: uint8(c.a * 255),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHexRune(rn rune) (int, bool) {
|
func parseHexRune(rn rune) (int, bool) {
|
||||||
switch {
|
switch {
|
||||||
case rn >= '0' && rn <= '9':
|
case rn >= '0' && rn <= '9':
|
||||||
|
|
|
@ -390,8 +390,7 @@ func runSubPaths(path []pathPoint, close bool, fn func(subPath []pathPoint) bool
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i >= start+3 {
|
if i >= start+3 {
|
||||||
end := i
|
if runSubPath(path[start:i], close, fn) {
|
||||||
if runSubPath(path[start:end], close, fn) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
paths.go
8
paths.go
|
@ -400,11 +400,11 @@ func appendSubPathTriangles(tris [][2]float64, mat mat, path []pathPoint) [][2]f
|
||||||
last := path[len(path)-1]
|
last := path[len(path)-1]
|
||||||
if last.flags&pathIsConvex != 0 {
|
if last.flags&pathIsConvex != 0 {
|
||||||
p0, p1 := path[0].pos.mulMat(mat), path[1].pos.mulMat(mat)
|
p0, p1 := path[0].pos.mulMat(mat), path[1].pos.mulMat(mat)
|
||||||
last := len(path)
|
lastIdx := len(path)
|
||||||
if path[0].pos == path[last-1].pos {
|
if path[0].pos == path[lastIdx-1].pos {
|
||||||
last--
|
lastIdx--
|
||||||
}
|
}
|
||||||
for i := 2; i < last; i++ {
|
for i := 2; i < lastIdx; i++ {
|
||||||
p2 := path[i].pos.mulMat(mat)
|
p2 := path[i].pos.mulMat(mat)
|
||||||
tris = append(tris, p0, p1, p2)
|
tris = append(tris, p0, p1, p2)
|
||||||
p1 = p2
|
p1 = p2
|
||||||
|
|
Loading…
Reference in a new issue