mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
Move texture.Quad -> graphics.TextureQuad
This commit is contained in:
parent
2b4dc28d91
commit
0cbf6a58aa
@ -20,6 +20,17 @@ const (
|
|||||||
FilterLinear
|
FilterLinear
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TextureQuad struct {
|
||||||
|
VertexX1 float32
|
||||||
|
VertexX2 float32
|
||||||
|
VertexY1 float32
|
||||||
|
VertexY2 float32
|
||||||
|
TextureCoordU1 float32
|
||||||
|
TextureCoordU2 float32
|
||||||
|
TextureCoordV1 float32
|
||||||
|
TextureCoordV2 float32
|
||||||
|
}
|
||||||
|
|
||||||
type TextureId int
|
type TextureId int
|
||||||
|
|
||||||
// A render target is essentially same as a texture, but it is assumed that the
|
// A render target is essentially same as a texture, but it is assumed that the
|
||||||
|
@ -103,7 +103,7 @@ type drawable struct {
|
|||||||
colorMatrix matrix.Color
|
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),
|
shader.DrawTexture(native.(texture.Native),
|
||||||
d.offscreen.projectionMatrix, quads,
|
d.offscreen.projectionMatrix, quads,
|
||||||
d.geometryMatrix, d.colorMatrix)
|
d.geometryMatrix, d.colorMatrix)
|
||||||
|
@ -6,17 +6,16 @@ package shader
|
|||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
|
"github.com/hajimehoshi/go-ebiten/graphics/opengl/texture"
|
||||||
gtexture "github.com/hajimehoshi/go-ebiten/graphics/texture"
|
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
|
|
||||||
func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []gtexture.Quad,
|
func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []graphics.TextureQuad, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
initialize()
|
initialize()
|
||||||
})
|
})
|
||||||
|
@ -62,19 +62,8 @@ func (texture *Texture) v(y int) float32 {
|
|||||||
return float32(y) / float32(AdjustSize(texture.height))
|
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 {
|
type Drawable interface {
|
||||||
Draw(native interface{}, quads []Quad)
|
Draw(native interface{}, quads []graphics.TextureQuad)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (texture *Texture) Draw(drawable Drawable) {
|
func (texture *Texture) Draw(drawable Drawable) {
|
||||||
@ -86,12 +75,12 @@ func (texture *Texture) Draw(drawable Drawable) {
|
|||||||
u2 := texture.u(texture.width)
|
u2 := texture.u(texture.width)
|
||||||
v1 := texture.v(0)
|
v1 := texture.v(0)
|
||||||
v2 := texture.v(texture.height)
|
v2 := texture.v(texture.height)
|
||||||
quad := Quad{x1, x2, y1, y2, u1, u2, v1, v2}
|
quad := graphics.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2}
|
||||||
drawable.Draw(texture.native, []Quad{quad})
|
drawable.Draw(texture.native, []graphics.TextureQuad{quad})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (texture *Texture) DrawParts(parts []graphics.TexturePart, drawable Drawable) {
|
func (texture *Texture) DrawParts(parts []graphics.TexturePart, drawable Drawable) {
|
||||||
quads := []Quad{}
|
quads := []graphics.TextureQuad{}
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
x1 := float32(part.LocationX)
|
x1 := float32(part.LocationX)
|
||||||
x2 := float32(part.LocationX + part.Source.Width)
|
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)
|
u2 := texture.u(part.Source.X + part.Source.Width)
|
||||||
v1 := texture.v(part.Source.Y)
|
v1 := texture.v(part.Source.Y)
|
||||||
v2 := texture.v(part.Source.Y + part.Source.Height)
|
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)
|
quads = append(quads, quad)
|
||||||
}
|
}
|
||||||
drawable.Draw(texture.native, quads)
|
drawable.Draw(texture.native, quads)
|
||||||
|
Loading…
Reference in New Issue
Block a user