2013-06-19 01:49:54 +02:00
|
|
|
package opengl
|
2013-06-15 10:07:14 +02:00
|
|
|
|
2013-06-18 17:48:41 +02:00
|
|
|
import (
|
2013-10-14 04:34:58 +02:00
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
2013-12-06 18:20:48 +01:00
|
|
|
"image"
|
2013-06-18 17:48:41 +02:00
|
|
|
)
|
2013-06-15 10:07:14 +02:00
|
|
|
|
2013-06-17 16:10:55 +02:00
|
|
|
type Device struct {
|
2013-11-27 03:56:44 +01:00
|
|
|
context *Context
|
|
|
|
screenScale int
|
2013-06-15 10:07:14 +02:00
|
|
|
}
|
|
|
|
|
2013-10-05 18:47:19 +02:00
|
|
|
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
2013-11-22 18:56:18 +01:00
|
|
|
context := newContext(screenWidth, screenHeight, screenScale)
|
2013-11-20 16:05:57 +01:00
|
|
|
return &Device{
|
2013-11-27 03:56:44 +01:00
|
|
|
context: context,
|
|
|
|
screenScale: screenScale,
|
2013-06-15 10:07:14 +02:00
|
|
|
}
|
2013-10-05 18:47:19 +02:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:20:48 +01:00
|
|
|
func (d *Device) Update(draw func(graphics.Canvas)) {
|
|
|
|
context := d.context
|
2013-11-25 14:27:59 +01:00
|
|
|
context.Init()
|
2013-10-16 16:06:35 +02:00
|
|
|
context.ResetOffscreen()
|
2013-07-04 17:49:17 +02:00
|
|
|
context.Clear()
|
2013-06-25 17:56:01 +02:00
|
|
|
|
2013-10-06 11:22:45 +02:00
|
|
|
draw(context)
|
2013-06-25 17:56:01 +02:00
|
|
|
|
2013-07-04 17:49:17 +02:00
|
|
|
context.flush()
|
2013-10-17 17:45:12 +02:00
|
|
|
context.setMainFramebufferOffscreen()
|
2013-07-04 17:49:17 +02:00
|
|
|
context.Clear()
|
2013-06-20 18:47:39 +02:00
|
|
|
|
2013-12-06 18:20:48 +01:00
|
|
|
scale := float64(d.screenScale)
|
2013-10-27 15:11:26 +01:00
|
|
|
geometryMatrix := matrix.IdentityGeometry()
|
|
|
|
geometryMatrix.Scale(scale, scale)
|
2013-11-29 14:45:18 +01:00
|
|
|
context.DrawRenderTarget(context.screenId,
|
2013-06-20 18:47:39 +02:00
|
|
|
geometryMatrix, matrix.IdentityColor())
|
2013-07-04 17:49:17 +02:00
|
|
|
context.flush()
|
2013-06-15 10:07:14 +02:00
|
|
|
}
|
2013-06-19 16:08:24 +02:00
|
|
|
|
2013-12-07 17:35:24 +01:00
|
|
|
// TODO: Remove 'tag'
|
2013-12-06 18:20:48 +01:00
|
|
|
func (d *Device) CreateRenderTarget(tag string, width, height int) (graphics.RenderTargetId, error) {
|
2013-12-07 17:35:24 +01:00
|
|
|
return d.context.CreateRenderTarget(width, height)
|
2013-12-06 18:20:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) CreateTextureFromImage(tag string, img image.Image) (graphics.TextureId, error) {
|
2013-12-07 17:35:24 +01:00
|
|
|
return d.context.CreateTextureFromImage(img)
|
2013-06-19 16:08:24 +02:00
|
|
|
}
|