mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
graphics: Refactoring: Flip Y by geometry matrix instead of projection matrix
This commit is contained in:
parent
a644e92298
commit
9da5099060
@ -34,6 +34,8 @@ type graphicsContext struct {
|
||||
screen *Image
|
||||
initialized bool
|
||||
invalidated bool // browser only
|
||||
offsetX float64
|
||||
offsetY float64
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Invalidate() {
|
||||
@ -60,6 +62,9 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
|
||||
_ = c.screen.Clear()
|
||||
|
||||
c.offscreen = offscreen
|
||||
|
||||
c.offsetX = px0
|
||||
c.offsetY = py0
|
||||
}
|
||||
|
||||
func (c *graphicsContext) initializeIfNeeded() error {
|
||||
@ -93,7 +98,21 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
||||
afterFrameUpdate()
|
||||
}
|
||||
if 0 < updateCount {
|
||||
drawWithFittingScale(c.screen, c.offscreen, nil, filterScreen)
|
||||
dw, dh := c.screen.Size()
|
||||
sw, _ := c.offscreen.Size()
|
||||
scale := float64(dw) / float64(sw)
|
||||
|
||||
op := &DrawImageOptions{}
|
||||
|
||||
// c.screen is special: its Y axis is down to up,
|
||||
// and the origin point is lower left.
|
||||
op.GeoM.Scale(scale, -scale)
|
||||
op.GeoM.Translate(0, float64(dh))
|
||||
op.GeoM.Translate(c.offsetX, c.offsetY)
|
||||
|
||||
op.CompositeMode = CompositeModeCopy
|
||||
op.Filter = filterScreen
|
||||
_ = c.screen.DrawImage(c.offscreen, op)
|
||||
}
|
||||
|
||||
if err := restorable.ResolveStaleImages(); err != nil {
|
||||
|
@ -109,12 +109,6 @@ func (f *framebuffer) projectionMatrix(height int) []float32 {
|
||||
}
|
||||
w, h := f.viewportSize()
|
||||
m := orthoProjectionMatrix(0, w, 0, h)
|
||||
if f.flipY {
|
||||
m[4*1+1] *= -1
|
||||
m[4*3+1] += float32(height) / float32(h) * 2
|
||||
}
|
||||
m[4*3+0] += float32(f.offsetX) / float32(w) * 2
|
||||
m[4*3+1] += float32(f.offsetY) / float32(h) * 2
|
||||
f.proMatrix = m
|
||||
return f.proMatrix
|
||||
}
|
||||
|
@ -171,10 +171,10 @@ func (i *Image) clearIfVolatile() {
|
||||
}
|
||||
|
||||
w, h := i.image.Size()
|
||||
x0 := -float32(i.paddingX0)
|
||||
y0 := -float32(i.paddingY0)
|
||||
x1 := float32(w) + float32(i.paddingX1)
|
||||
y1 := float32(h) + float32(i.paddingY1)
|
||||
x0 := float32(0)
|
||||
y0 := float32(0)
|
||||
x1 := float32(w) + float32(i.paddingX0+i.paddingX1)
|
||||
y1 := float32(h) + float32(i.paddingY0+i.paddingY1)
|
||||
// For the rule of values, see vertices.go.
|
||||
clearVertices := []float32{
|
||||
x0, y0, 0, 0, 1, 1,
|
||||
|
Loading…
Reference in New Issue
Block a user