2019-06-02 19:37:57 +02:00
|
|
|
// Copyright 2019 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2024-09-14 09:08:57 +02:00
|
|
|
package gl
|
2019-06-02 19:37:57 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"syscall/js"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2021-10-30 11:43:46 +02:00
|
|
|
func copyUint8SliceToTemporaryArrayBuffer(src []uint8) {
|
|
|
|
if len(src) == 0 {
|
|
|
|
return
|
2019-06-02 19:37:57 +02:00
|
|
|
}
|
2024-09-14 09:08:57 +02:00
|
|
|
js.CopyBytesToJS(tmpUint8Array, src)
|
2019-06-02 19:37:57 +02:00
|
|
|
}
|
|
|
|
|
2022-11-12 10:38:15 +01:00
|
|
|
type numeric interface {
|
|
|
|
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
|
2021-10-30 11:43:46 +02:00
|
|
|
}
|
|
|
|
|
2022-11-12 10:38:15 +01:00
|
|
|
func copySliceToTemporaryArrayBuffer[T numeric](src []T) {
|
2021-10-30 11:43:46 +02:00
|
|
|
if len(src) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2024-09-14 09:08:57 +02:00
|
|
|
js.CopyBytesToJS(tmpUint8Array, unsafe.Slice((*byte)(unsafe.Pointer(&src[0])), len(src)*int(unsafe.Sizeof(T(0)))))
|
2021-10-30 11:43:46 +02:00
|
|
|
runtime.KeepAlive(src)
|
2019-06-02 19:37:57 +02:00
|
|
|
}
|