mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
44 lines
946 B
Go
44 lines
946 B
Go
package opengl
|
|
|
|
import (
|
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
|
)
|
|
|
|
type Device struct {
|
|
context *Context
|
|
screenScale int
|
|
}
|
|
|
|
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
|
context := newContext(screenWidth, screenHeight, screenScale)
|
|
return &Device{
|
|
context: context,
|
|
screenScale: screenScale,
|
|
}
|
|
}
|
|
|
|
func (device *Device) Update(draw func(graphics.Canvas)) {
|
|
context := device.context
|
|
context.Init()
|
|
context.ResetOffscreen()
|
|
context.Clear()
|
|
|
|
draw(context)
|
|
|
|
context.flush()
|
|
context.setMainFramebufferOffscreen()
|
|
context.Clear()
|
|
|
|
scale := float64(device.screenScale)
|
|
geometryMatrix := matrix.IdentityGeometry()
|
|
geometryMatrix.Scale(scale, scale)
|
|
context.DrawRenderTarget(context.screenId,
|
|
geometryMatrix, matrix.IdentityColor())
|
|
context.flush()
|
|
}
|
|
|
|
func (device *Device) TextureFactory() graphics.TextureFactory {
|
|
return device.context
|
|
}
|