mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Remove rectVertexQuads
This commit is contained in:
parent
887e2fc675
commit
22e6996f74
2
image.go
2
image.go
@ -103,7 +103,7 @@ func (i *Image) DrawRect(x, y, width, height int, clr color.Color) error {
|
||||
// DrawRects draws rectangles on the image.
|
||||
func (i *Image) DrawRects(rects Rects) (err error) {
|
||||
ui.Use(func(c *opengl.Context) {
|
||||
err = i.framebuffer.DrawRects(c, &rectVertexQuads{rects})
|
||||
err = i.framebuffer.DrawRects(c, rects)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
type VertexQuads interface {
|
||||
type Rects interface {
|
||||
Len() int
|
||||
Vertex(i int) (x0, y0, x1, y1 int)
|
||||
Rect(i int) (x, y, width, height int)
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
p := f.projectionMatrix()
|
||||
return shader.DrawRects(c, p, quads)
|
||||
return shader.DrawRects(c, p, rects)
|
||||
}
|
||||
|
@ -89,20 +89,13 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
|
||||
return nil
|
||||
}
|
||||
|
||||
type VertexQuads interface {
|
||||
type Rects interface {
|
||||
Len() int
|
||||
Vertex(i int) (x0, y0, x1, y1 int)
|
||||
Rect(i int) (x, y, width, height int)
|
||||
Color(i int) color.Color
|
||||
}
|
||||
|
||||
func max(a, b float32) float32 {
|
||||
if a < b {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQuads) error {
|
||||
func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, rects Rects) error {
|
||||
if !initialized {
|
||||
if err := initialize(c); err != nil {
|
||||
return err
|
||||
@ -110,7 +103,7 @@ func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQ
|
||||
initialized = true
|
||||
}
|
||||
|
||||
if quads.Len() == 0 {
|
||||
if rects.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -119,12 +112,13 @@ func DrawRects(c *opengl.Context, projectionMatrix *[4][4]float64, quads VertexQ
|
||||
|
||||
vertices := vertices[0:0]
|
||||
num := 0
|
||||
for i := 0; i < quads.Len(); i++ {
|
||||
x0, y0, x1, y1 := quads.Vertex(i)
|
||||
if x0 == x1 || y0 == y1 {
|
||||
for i := 0; i < rects.Len(); i++ {
|
||||
x, y, w, h := rects.Rect(i)
|
||||
if w == 0 || h == 0 {
|
||||
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,
|
||||
int16(x0), int16(y0), int16(r), int16(g), int16(b), int16(a),
|
||||
int16(x1), int16(y0), int16(r), int16(g), int16(b), int16(a),
|
||||
|
17
shapes.go
17
shapes.go
@ -42,20 +42,3 @@ func (r *rect) Rect(i int) (x, y, width, height int) {
|
||||
func (r *rect) Color(i int) color.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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user