diff --git a/graphics/graphics.go b/graphics/graphics.go index f211fa3fd..554d3fd9e 100644 --- a/graphics/graphics.go +++ b/graphics/graphics.go @@ -20,6 +20,17 @@ const ( FilterLinear ) +type TextureQuad struct { + VertexX1 float32 + VertexX2 float32 + VertexY1 float32 + VertexY2 float32 + TextureCoordU1 float32 + TextureCoordU2 float32 + TextureCoordV1 float32 + TextureCoordV2 float32 +} + type TextureId int // A render target is essentially same as a texture, but it is assumed that the diff --git a/graphics/opengl/offscreen/offscreen.go b/graphics/opengl/offscreen/offscreen.go index 7d80e223b..ad3f3a962 100644 --- a/graphics/opengl/offscreen/offscreen.go +++ b/graphics/opengl/offscreen/offscreen.go @@ -103,7 +103,7 @@ type drawable struct { colorMatrix matrix.Color } -func (d *drawable) Draw(native interface{}, quads []gtexture.Quad) { +func (d *drawable) Draw(native interface{}, quads []graphics.TextureQuad) { shader.DrawTexture(native.(texture.Native), d.offscreen.projectionMatrix, quads, d.geometryMatrix, d.colorMatrix) diff --git a/graphics/opengl/shader/draw_texture.go b/graphics/opengl/shader/draw_texture.go index 37f8fe50b..4f18189ac 100644 --- a/graphics/opengl/shader/draw_texture.go +++ b/graphics/opengl/shader/draw_texture.go @@ -6,17 +6,16 @@ package shader // #include import "C" import ( + "github.com/hajimehoshi/go-ebiten/graphics" "github.com/hajimehoshi/go-ebiten/graphics/matrix" "github.com/hajimehoshi/go-ebiten/graphics/opengl/texture" - gtexture "github.com/hajimehoshi/go-ebiten/graphics/texture" "sync" "unsafe" ) var once sync.Once -func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []gtexture.Quad, - geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { +func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []graphics.TextureQuad, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { once.Do(func() { initialize() }) diff --git a/graphics/texture/texture.go b/graphics/texture/texture.go index 04d5aac67..77ca4f1a0 100644 --- a/graphics/texture/texture.go +++ b/graphics/texture/texture.go @@ -62,19 +62,8 @@ func (texture *Texture) v(y int) float32 { return float32(y) / float32(AdjustSize(texture.height)) } -type Quad struct { - VertexX1 float32 - VertexX2 float32 - VertexY1 float32 - VertexY2 float32 - TextureCoordU1 float32 - TextureCoordU2 float32 - TextureCoordV1 float32 - TextureCoordV2 float32 -} - type Drawable interface { - Draw(native interface{}, quads []Quad) + Draw(native interface{}, quads []graphics.TextureQuad) } func (texture *Texture) Draw(drawable Drawable) { @@ -86,12 +75,12 @@ func (texture *Texture) Draw(drawable Drawable) { u2 := texture.u(texture.width) v1 := texture.v(0) v2 := texture.v(texture.height) - quad := Quad{x1, x2, y1, y2, u1, u2, v1, v2} - drawable.Draw(texture.native, []Quad{quad}) + quad := graphics.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2} + drawable.Draw(texture.native, []graphics.TextureQuad{quad}) } func (texture *Texture) DrawParts(parts []graphics.TexturePart, drawable Drawable) { - quads := []Quad{} + quads := []graphics.TextureQuad{} for _, part := range parts { x1 := float32(part.LocationX) x2 := float32(part.LocationX + part.Source.Width) @@ -101,7 +90,7 @@ func (texture *Texture) DrawParts(parts []graphics.TexturePart, drawable Drawabl u2 := texture.u(part.Source.X + part.Source.Width) v1 := texture.v(part.Source.Y) v2 := texture.v(part.Source.Y + part.Source.Height) - quad := Quad{x1, x2, y1, y2, u1, u2, v1, v2} + quad := graphics.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2} quads = append(quads, quad) } drawable.Draw(texture.native, quads)