mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphicsdriver/monogame: Create a RenderTarget2D for an image
Updates #1078
This commit is contained in:
parent
6236ba1f00
commit
8809076682
@ -19,11 +19,11 @@ package monogame
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/monogame"
|
||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
||||
)
|
||||
|
||||
type Graphics struct {
|
||||
t *thread.Thread
|
||||
}
|
||||
|
||||
var theGraphics Graphics
|
||||
@ -33,7 +33,7 @@ func Get() *Graphics {
|
||||
}
|
||||
|
||||
func (g *Graphics) SetThread(thread *thread.Thread) {
|
||||
g.t = thread
|
||||
panic("monogame: SetThread is not implemented yet")
|
||||
}
|
||||
|
||||
func (g *Graphics) Begin() {
|
||||
@ -49,7 +49,9 @@ func (g *Graphics) SetVertices(vertices []float32, indices []uint16) {
|
||||
}
|
||||
|
||||
func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
||||
v := monogame.CurrentGame().NewRenderTarget2D(width, height)
|
||||
return &Image{
|
||||
v: v,
|
||||
width: width,
|
||||
height: height,
|
||||
}, nil
|
||||
|
@ -18,14 +18,17 @@ package monogame
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/monogame"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
v *monogame.RenderTarget2D
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func (*Image) Dispose() {
|
||||
func (i *Image) Dispose() {
|
||||
i.v.Dispose()
|
||||
}
|
||||
|
||||
func (*Image) IsInvalidated() bool {
|
||||
|
@ -21,6 +21,9 @@ import (
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
// TODO: This implementation depends on some C# files that are not uploaded yet.
|
||||
// Create 'ebitenmonogame' command to generate C# project for the MonoGame.
|
||||
|
||||
// TODO: Update this
|
||||
const temporaryNamespace = "Go2DotNet.Example.Rotate"
|
||||
|
||||
@ -30,24 +33,17 @@ type UpdateDrawer interface {
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
v js.Value
|
||||
update js.Func
|
||||
draw js.Func
|
||||
binding js.Value
|
||||
update js.Func
|
||||
draw js.Func
|
||||
}
|
||||
|
||||
func (g *Game) Run() {
|
||||
// Methods named *FromGo is defined to avoid ambiguous matches of methods.
|
||||
g.v.Call("RunFromGo")
|
||||
}
|
||||
var currentGame *Game
|
||||
|
||||
func (g *Game) Dispose() {
|
||||
runtime.SetFinalizer(g, nil)
|
||||
g.update.Release()
|
||||
g.draw.Release()
|
||||
func CurrentGame() *Game {
|
||||
return currentGame
|
||||
}
|
||||
|
||||
type RenderTarget2D js.Value
|
||||
|
||||
func NewGame(ud UpdateDrawer) *Game {
|
||||
update := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
return ud.Update()
|
||||
@ -57,12 +53,41 @@ func NewGame(ud UpdateDrawer) *Game {
|
||||
return ud.Draw()
|
||||
})
|
||||
|
||||
v := js.Global().Get(".net").Get(temporaryNamespace+".GoGame").New(update, draw)
|
||||
v := js.Global().Get(".net").Get(temporaryNamespace+".GoBinding").New(update, draw)
|
||||
g := &Game{
|
||||
v: v,
|
||||
update: update,
|
||||
draw: draw,
|
||||
binding: v,
|
||||
update: update,
|
||||
draw: draw,
|
||||
}
|
||||
runtime.SetFinalizer(g, (*Game).Dispose)
|
||||
currentGame = g
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *Game) Dispose() {
|
||||
runtime.SetFinalizer(g, nil)
|
||||
g.update.Release()
|
||||
g.draw.Release()
|
||||
currentGame = nil
|
||||
}
|
||||
|
||||
func (g *Game) Run() {
|
||||
g.binding.Call("Run")
|
||||
}
|
||||
|
||||
func (g *Game) NewRenderTarget2D(width, height int) *RenderTarget2D {
|
||||
r := &RenderTarget2D{
|
||||
v: g.binding.Call("NewRenderTarget2D", width, height),
|
||||
}
|
||||
runtime.SetFinalizer(r, (*RenderTarget2D).Dispose)
|
||||
return r
|
||||
}
|
||||
|
||||
type RenderTarget2D struct {
|
||||
v js.Value
|
||||
}
|
||||
|
||||
func (r *RenderTarget2D) Dispose() {
|
||||
runtime.SetFinalizer(r, nil)
|
||||
r.v.Call("Dispose")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user