ebiten/internal/graphicsdriver/opengl/gl/procaddr_windows.go
2022-01-23 18:30:40 +09:00

38 lines
738 B
Go

// SPDX-License-Identifier: MIT
package gl
import (
"fmt"
"unsafe"
"golang.org/x/sys/windows"
)
var (
opengl32 = windows.NewLazySystemDLL("opengl32")
wglGetProcAddress = opengl32.NewProc("wglGetProcAddress")
)
func getProcAddress(namea string) uintptr {
cname, err := windows.BytePtrFromString(namea)
if err != nil {
panic(err)
}
r, _, err := wglGetProcAddress.Call(uintptr(unsafe.Pointer(cname)))
if err != nil && err != windows.ERROR_SUCCESS && err != windows.ERROR_PROC_NOT_FOUND {
panic(fmt.Sprintf("gl: wglGetProcAddress failed: %s", err.Error()))
}
if r != 0 {
return r
}
p := opengl32.NewProc(namea)
if err := p.Find(); err != nil {
// The proc is not found.
return 0
}
return p.Addr()
}