graphicsdriver/monogame: Implement Pixels

Updates #1078
This commit is contained in:
Hajime Hoshi 2020-04-22 01:46:07 +09:00
parent 33e850a6d4
commit 7ad3343e9c
3 changed files with 15 additions and 4 deletions

View File

@ -124,6 +124,10 @@ func (s *screen) SetAsSource() {
panic("monogame: SetAsSource on screen is forbidden")
}
func (s *screen) Pixels(width, height int) ([]byte, error) {
panic("monogame: Pixels on screen is forbidden")
}
func (s *screen) ReplacePixels(args []*driver.ReplacePixelsArgs) {
panic("monogame: ReplacePixels on screen is forbidden")
}

View File

@ -24,6 +24,7 @@ import (
type RenderTarget2D interface {
SetAsDestination(viewportWidth, viewportHeight int)
SetAsSource()
Pixels(width, height int) ([]byte, error)
ReplacePixels(args []*driver.ReplacePixelsArgs)
Dispose()
IsScreen() bool
@ -44,9 +45,8 @@ func (*Image) IsInvalidated() bool {
return false
}
func (*Image) Pixels() ([]byte, error) {
panic("monogame: Pixels is not implemented yet")
return nil, nil
func (i *Image) Pixels() ([]byte, error) {
return i.v.Pixels(i.width, i.height)
}
func (i *Image) SetAsDestination() {

View File

@ -126,7 +126,14 @@ type RenderTarget2D struct {
func (r *RenderTarget2D) Dispose() {
runtime.SetFinalizer(r, nil)
r.v.Call("Dispose")
r.binding.Call("Dispose", r.v)
}
func (r *RenderTarget2D) Pixels(width, height int) ([]byte, error) {
v := r.binding.Call("Pixels", r.v, width, height)
bs := make([]byte, v.Length())
js.CopyBytesToGo(bs, v)
return bs, nil
}
func (r *RenderTarget2D) ReplacePixels(args []*driver.ReplacePixelsArgs) {