mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/jsutil: Move a function to internal/graphicsdriver/opengl
This commit is contained in:
parent
610ebbbab5
commit
a826ecb29b
@ -99,6 +99,15 @@ var (
|
||||
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 {
|
||||
gl *gl
|
||||
lastProgramID programID
|
||||
@ -236,7 +245,7 @@ func (c *context) framebufferPixels(f *framebuffer, width, height int) []byte {
|
||||
p := jsutil.TemporaryUint8Array(l, nil)
|
||||
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) {
|
||||
|
@ -22,15 +22,6 @@ import (
|
||||
"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) {
|
||||
switch s := s.(type) {
|
||||
case []int8:
|
||||
|
Loading…
Reference in New Issue
Block a user