Skip to content

Commit

Permalink
removed some dead code; small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tfriedel6 committed Feb 20, 2020
1 parent 239026d commit 82290ac
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 75 deletions.
21 changes: 5 additions & 16 deletions backend/goglbackend/gogl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package goglbackend

import (
"fmt"
"image/color"
"math"

"github.com/tfriedel6/canvas/backend/backendbase"
Expand Down Expand Up @@ -275,19 +274,6 @@ func (b *GoGLBackendOffscreen) AsImage() backendbase.Image {
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) {
gl.UseProgram(b.shd.ID)
gl.Uniform2f(b.shd.CanvasSize, float32(b.fw), float32(b.fh))
Expand Down Expand Up @@ -355,8 +341,11 @@ func (b *GoGLBackend) useShader(style *backendbase.FillStyle, useAlpha bool, alp
return b.shd.Vertex, b.shd.TexCoord
}

c := colorGoToGL(style.Color)
gl.Uniform4f(b.shd.Color, float32(c.r), float32(c.g), float32(c.b), float32(c.a))
cr := float32(style.Color.R) / 255
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.Uniform1i(b.shd.Func, shdFuncSolid)
return b.shd.Vertex, b.shd.TexCoord
Expand Down
11 changes: 1 addition & 10 deletions canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,6 @@ type offscreenBuffer struct {
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
// 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
Expand Down Expand Up @@ -362,6 +352,7 @@ func (cv *Canvas) SetLineDash(dash []float64) {
cv.state.lineDashOffset = 0
}

// SetLineDashOffset sets the line dash offset
func (cv *Canvas) SetLineDashOffset(offset float64) {
cv.state.lineDashOffset = offset
}
Expand Down
43 changes: 0 additions & 43 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,6 @@ import (
"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) {
switch {
case rn >= '0' && rn <= '9':
Expand Down
3 changes: 1 addition & 2 deletions path2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ func runSubPaths(path []pathPoint, close bool, fn func(subPath []pathPoint) bool
continue
}
if i >= start+3 {
end := i
if runSubPath(path[start:end], close, fn) {
if runSubPath(path[start:i], close, fn) {
return
}
}
Expand Down
8 changes: 4 additions & 4 deletions paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ func appendSubPathTriangles(tris [][2]float64, mat mat, path []pathPoint) [][2]f
last := path[len(path)-1]
if last.flags&pathIsConvex != 0 {
p0, p1 := path[0].pos.mulMat(mat), path[1].pos.mulMat(mat)
last := len(path)
if path[0].pos == path[last-1].pos {
last--
lastIdx := len(path)
if path[0].pos == path[lastIdx-1].pos {
lastIdx--
}
for i := 2; i < last; i++ {
for i := 2; i < lastIdx; i++ {
p2 := path[i].pos.mulMat(mat)
tris = append(tris, p0, p1, p2)
p1 = p2
Expand Down

0 comments on commit 82290ac

Please sign in to comment.