internal/jsutil: Move a function to internal/graphicsdriver/opengl

This commit is contained in:
Hajime Hoshi 2021-10-30 18:33:43 +09:00
parent 610ebbbab5
commit a826ecb29b
2 changed files with 10 additions and 10 deletions

View File

@ -99,6 +99,15 @@ var (
webGL2MightBeAvailable = !forceWebGL1 && (js.Global().Get("WebGL2RenderingContext").Truthy() || js.Global().Get("go2cpp").Truthy()) webGL2MightBeAvailable = !forceWebGL1 && (js.Global().Get("WebGL2RenderingContext").Truthy() || js.Global().Get("go2cpp").Truthy())
) )
func uint8ArrayToSlice(value js.Value, length int) []byte {
if l := value.Get("byteLength").Int(); length > l {
length = l
}
s := make([]byte, length)
js.CopyBytesToGo(s, value)
return s
}
type contextImpl struct { type contextImpl struct {
gl *gl gl *gl
lastProgramID programID lastProgramID programID
@ -236,7 +245,7 @@ func (c *context) framebufferPixels(f *framebuffer, width, height int) []byte {
p := jsutil.TemporaryUint8Array(l, nil) p := jsutil.TemporaryUint8Array(l, nil)
gl.readPixels.Invoke(0, 0, width, height, gles.RGBA, gles.UNSIGNED_BYTE, p) gl.readPixels.Invoke(0, 0, width, height, gles.RGBA, gles.UNSIGNED_BYTE, p)
return jsutil.Uint8ArrayToSlice(p, l) return uint8ArrayToSlice(p, l)
} }
func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width, height int) { func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width, height int) {

View File

@ -22,15 +22,6 @@ import (
"unsafe" "unsafe"
) )
func Uint8ArrayToSlice(value js.Value, length int) []byte {
if l := value.Get("byteLength").Int(); length > l {
length = l
}
s := make([]byte, length)
js.CopyBytesToGo(s, value)
return s
}
func sliceToByteSlice(s interface{}) (bs []byte) { func sliceToByteSlice(s interface{}) (bs []byte) {
switch s := s.(type) { switch s := s.(type) {
case []int8: case []int8: