mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Remove glMatrix
This commit is contained in:
parent
6de9e6696e
commit
49fb2635ec
@ -26,15 +26,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func glMatrix(m *[4][4]float64) []float32 {
|
|
||||||
return []float32{
|
|
||||||
float32(m[0][0]), float32(m[1][0]), float32(m[2][0]), float32(m[3][0]),
|
|
||||||
float32(m[0][1]), float32(m[1][1]), float32(m[2][1]), float32(m[3][1]),
|
|
||||||
float32(m[0][2]), float32(m[1][2]), float32(m[2][2]), float32(m[3][2]),
|
|
||||||
float32(m[0][3]), float32(m[1][3]), float32(m[2][3]), float32(m[3][3]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Matrix interface {
|
type Matrix interface {
|
||||||
Element(i, j int) float64
|
Element(i, j int) float64
|
||||||
}
|
}
|
||||||
@ -213,7 +204,7 @@ func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, h := c.dst.Size()
|
_, h := c.dst.Size()
|
||||||
proj := glMatrix(c.dst.framebuffer.projectionMatrix(h))
|
proj := c.dst.framebuffer.projectionMatrix(h)
|
||||||
p := programContext{
|
p := programContext{
|
||||||
state: &theOpenGLState,
|
state: &theOpenGLState,
|
||||||
program: theOpenGLState.programTexture,
|
program: theOpenGLState.programTexture,
|
||||||
|
@ -18,24 +18,24 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 {
|
func orthoProjectionMatrix(left, right, bottom, top int) []float32 {
|
||||||
e11 := float64(2) / float64(right-left)
|
e11 := 2 / float32(right-left)
|
||||||
e22 := float64(2) / float64(top-bottom)
|
e22 := 2 / float32(top-bottom)
|
||||||
e14 := -1 * float64(right+left) / float64(right-left)
|
e14 := -1 * float32(right+left) / float32(right-left)
|
||||||
e24 := -1 * float64(top+bottom) / float64(top-bottom)
|
e24 := -1 * float32(top+bottom) / float32(top-bottom)
|
||||||
|
|
||||||
return &[4][4]float64{
|
return []float32{
|
||||||
{e11, 0, 0, e14},
|
e11, 0, 0, 0,
|
||||||
{0, e22, 0, e24},
|
0, e22, 0, 0,
|
||||||
{0, 0, 1, 0},
|
0, 0, 1, 0,
|
||||||
{0, 0, 0, 1},
|
e14, e24, 0, 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type framebuffer struct {
|
type framebuffer struct {
|
||||||
native opengl.Framebuffer
|
native opengl.Framebuffer
|
||||||
flipY bool
|
flipY bool
|
||||||
proMatrix *[4][4]float64
|
proMatrix []float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*framebuffer, error) {
|
func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*framebuffer, error) {
|
||||||
@ -56,14 +56,14 @@ func (f *framebuffer) setAsViewport(context *opengl.Context) error {
|
|||||||
return context.SetViewport(f.native, width, height)
|
return context.SetViewport(f.native, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *framebuffer) projectionMatrix(height int) *[4][4]float64 {
|
func (f *framebuffer) projectionMatrix(height int) []float32 {
|
||||||
if f.proMatrix != nil {
|
if f.proMatrix != nil {
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
}
|
}
|
||||||
m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize)
|
m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize)
|
||||||
if f.flipY {
|
if f.flipY {
|
||||||
m[1][1] *= -1
|
m[4*1+1] *= -1
|
||||||
m[1][3] += float64(height) / float64(viewportSize) * 2
|
m[4*3+1] += float32(height) / float32(viewportSize) * 2
|
||||||
}
|
}
|
||||||
f.proMatrix = m
|
f.proMatrix = m
|
||||||
return f.proMatrix
|
return f.proMatrix
|
||||||
|
Loading…
Reference in New Issue
Block a user