Add wasm test with wasmbrowsertest

Fixes #881
This commit is contained in:
Hajime Hoshi 2019-08-23 01:37:32 +09:00
parent 045c743021
commit 899fc38d23
2 changed files with 20 additions and 2 deletions

View File

@ -28,10 +28,15 @@ install:
- cd /tmp/work - cd /tmp/work
- go mod init example.com/m - go mod init example.com/m
- go get github.com/hajimehoshi/ebiten@$TRAVIS_BRANCH - go get github.com/hajimehoshi/ebiten@$TRAVIS_BRANCH
- # gopath-get for the current GopherJS and gjbt. - # GopherJS
- GO111MODULE=off go get -tags example github.com/hajimehoshi/ebiten/... - GO111MODULE=off go get -tags example github.com/hajimehoshi/ebiten/...
- GO111MODULE=off go1.12.9 get github.com/gopherjs/gopherjs - GO111MODULE=off go1.12.9 get github.com/gopherjs/gopherjs
- # gjbt
- GO111MODULE=off go1.12.9 get myitcv.io/cmd/gjbt - GO111MODULE=off go1.12.9 get myitcv.io/cmd/gjbt
- # wasmbrowsertest
- go get github.com/agnivade/wasmbrowsertest
- mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_exec
- # Chrome
- mkdir /tmp/google-chrome-bin - mkdir /tmp/google-chrome-bin
- ln -s /usr/bin/google-chrome-stable /tmp/google-chrome-bin/google-chrome - ln -s /usr/bin/google-chrome-stable /tmp/google-chrome-bin/google-chrome
- export PATH=/tmp/google-chrome-bin:$PATH - export PATH=/tmp/google-chrome-bin:$PATH
@ -46,6 +51,7 @@ script:
- cd /tmp/work - cd /tmp/work
- go build -tags example -v github.com/hajimehoshi/ebiten/... - go build -tags example -v github.com/hajimehoshi/ebiten/...
- go test -v github.com/hajimehoshi/ebiten/... - go test -v github.com/hajimehoshi/ebiten/...
- GOOS=js GOARCH=wasm go test -v github.com/hajimehoshi/ebiten/...
- GOOS=windows GOARCH=amd64 go build -tags example -v github.com/hajimehoshi/ebiten/... - GOOS=windows GOARCH=amd64 go build -tags example -v github.com/hajimehoshi/ebiten/...
- GOOS=windows GOARCH=386 go build -tags example -v github.com/hajimehoshi/ebiten/... - GOOS=windows GOARCH=386 go build -tags example -v github.com/hajimehoshi/ebiten/...
- GO111MODULE=off go1.12.9 run github.com/gopherjs/gopherjs build --tags example -v github.com/hajimehoshi/ebiten/examples/blocks - GO111MODULE=off go1.12.9 run github.com/gopherjs/gopherjs build --tags example -v github.com/hajimehoshi/ebiten/examples/blocks

View File

@ -90,6 +90,11 @@ var (
unsignedShort = contextPrototype.Get("UNSIGNED_SHORT") unsignedShort = contextPrototype.Get("UNSIGNED_SHORT")
) )
// temporaryBuffer is a temporary buffer used at gl.readPixels.
// The read data is converted to Go's byte slice as soon as possible.
// To avoid often allocating ArrayBuffer, reuse the buffer whenever possible.
var temporaryBuffer = js.Global().Get("ArrayBuffer").New(16)
type contextImpl struct { type contextImpl struct {
gl js.Value gl js.Value
lastProgramID programID lastProgramID programID
@ -191,7 +196,14 @@ func (c *context) framebufferPixels(f *framebuffer, width, height int) ([]byte,
c.bindFramebuffer(f.native) c.bindFramebuffer(f.native)
p := js.Global().Get("Uint8Array").New(4 * width * height) l := 4 * width * height
if bufl := temporaryBuffer.Get("byteLength").Int(); bufl < l {
for bufl < l {
bufl *= 2
}
temporaryBuffer = js.Global().Get("ArrayBuffer").New(bufl)
}
p := js.Global().Get("Uint8Array").New(temporaryBuffer, 0, l)
gl.Call("readPixels", 0, 0, width, height, rgba, unsignedByte, p) gl.Call("readPixels", 0, 0, width, height, rgba, unsignedByte, p)
return jsutil.Uint8ArrayToSlice(p), nil return jsutil.Uint8ArrayToSlice(p), nil