Remove rectVertexQuads

This commit is contained in:
Hajime Hoshi 2015-01-17 03:51:21 +09:00
parent 887e2fc675
commit 22e6996f74
4 changed files with 14 additions and 37 deletions

View File

@ -103,7 +103,7 @@ func (i *Image) DrawRect(x, y, width, height int, clr color.Color) error {
// DrawRects draws rectangles on the image. // DrawRects draws rectangles on the image.
func (i *Image) DrawRects(rects Rects) (err error) { func (i *Image) DrawRects(rects Rects) (err error) {
ui.Use(func(c *opengl.Context) { ui.Use(func(c *opengl.Context) {
err = i.framebuffer.DrawRects(c, &rectVertexQuads{rects}) err = i.framebuffer.DrawRects(c, rects)
}) })
return return
} }

View File

@ -114,16 +114,16 @@ func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQu
return shader.DrawTexture(c, t.native, p, quads, geo, clr) return shader.DrawTexture(c, t.native, p, quads, geo, clr)
} }
type VertexQuads interface { type Rects interface {
Len() int Len() int
Vertex(i int) (x0, y0, x1, y1 int) Rect(i int) (x, y, width, height int)
Color(i int) color.Color Color(i int) color.Color
} }
func (f *Framebuffer) DrawRects(c *opengl.Context, quads VertexQuads) error { func (f *Framebuffer) DrawRects(c *opengl.Context, rects Rects) error {
if err := f.setAsViewport(c); err != nil { if err := f.setAsViewport(c); err != nil {
return err return err
} }
p := f.projectionMatrix() p := f.projectionMatrix()
return shader.DrawRects(c, p, quads) return shader.DrawRects(c, p, rects)
} }

View File

@ -89,20 +89,13 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
return nil return nil
} }
type VertexQuads interface { type Rects interface {
Len() int Len() int
Vertex(i int) (x0, y0, x1, y1 int) Rect(i int) (x, y, width, height int)
Color(i int) color.Color Color(i int) color.Color
} }
func max(a, b float32) float32 { func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, rects Rects) error {
if a < b {
return b
}
return a
}
func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQuads) error {
if !initialized { if !initialized {
if err := initialize(c); err != nil { if err := initialize(c); err != nil {
return err return err
@ -110,7 +103,7 @@ func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQ
initialized = true initialized = true
} }
if quads.Len() == 0 { if rects.Len() == 0 {
return nil return nil
} }
@ -119,12 +112,13 @@ func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQ
vertices := vertices[0:0] vertices := vertices[0:0]
num := 0 num := 0
for i := 0; i < quads.Len(); i++ { for i := 0; i < rects.Len(); i++ {
x0, y0, x1, y1 := quads.Vertex(i) x, y, w, h := rects.Rect(i)
if x0 == x1 || y0 == y1 { if w == 0 || h == 0 {
continue continue
} }
r, g, b, a := quads.Color(i).RGBA() x0, y0, x1, y1 := x, y, x+w, y+h
r, g, b, a := rects.Color(i).RGBA()
vertices = append(vertices, vertices = append(vertices,
int16(x0), int16(y0), int16(r), int16(g), int16(b), int16(a), int16(x0), int16(y0), int16(r), int16(g), int16(b), int16(a),
int16(x1), int16(y0), int16(r), int16(g), int16(b), int16(a), int16(x1), int16(y0), int16(r), int16(g), int16(b), int16(a),

View File

@ -42,20 +42,3 @@ func (r *rect) Rect(i int) (x, y, width, height int) {
func (r *rect) Color(i int) color.Color { func (r *rect) Color(i int) color.Color {
return r.color return r.color
} }
type rectVertexQuads struct {
Rects
}
func (l *rectVertexQuads) Len() int {
return l.Rects.Len()
}
func (l *rectVertexQuads) Vertex(i int) (x0, y0, x1, y1 int) {
x, y, width, height := l.Rects.Rect(i)
return x, y, x + width, y + height
}
func (l *rectVertexQuads) Color(i int) color.Color {
return l.Rects.Color(i)
}