mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package opengl
|
|
|
|
import (
|
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
|
"runtime"
|
|
)
|
|
|
|
type Device struct {
|
|
screenScale int
|
|
context *Context
|
|
}
|
|
|
|
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
|
graphicsContext := newContext(screenWidth, screenHeight, screenScale)
|
|
device := &Device{
|
|
screenScale: screenScale,
|
|
context: graphicsContext,
|
|
}
|
|
return device
|
|
}
|
|
|
|
func (device *Device) Init() {
|
|
device.context.Init()
|
|
}
|
|
|
|
func (device *Device) Update(draw func(graphics.Context)) {
|
|
context := device.context
|
|
context.ResetOffscreen()
|
|
context.Clear()
|
|
|
|
draw(context)
|
|
|
|
context.flush()
|
|
context.setMainFramebufferOffscreen()
|
|
context.Clear()
|
|
|
|
scale := float64(context.screenScale)
|
|
geometryMatrix := matrix.IdentityGeometry()
|
|
geometryMatrix.Scale(scale, scale)
|
|
context.DrawTexture(context.ToTexture(context.screenId),
|
|
geometryMatrix, matrix.IdentityColor())
|
|
context.flush()
|
|
}
|
|
|
|
func (device *Device) TextureFactory() graphics.TextureFactory {
|
|
return device.context
|
|
}
|
|
|
|
func init() {
|
|
runtime.LockOSThread()
|
|
}
|