2019-09-22 17:42:51 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-12-08 18:35:13 +01:00
|
|
|
|
|
|
|
package gl
|
|
|
|
|
|
|
|
import (
|
2022-01-23 10:26:29 +01:00
|
|
|
"fmt"
|
2018-12-08 18:35:13 +01:00
|
|
|
"unsafe"
|
2019-09-22 17:42:51 +02:00
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
2018-12-08 18:35:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-30 07:36:09 +01:00
|
|
|
opengl32 = windows.NewLazySystemDLL("opengl32")
|
|
|
|
procWglGetProcAddress = opengl32.NewProc("wglGetProcAddress")
|
2018-12-08 18:35:13 +01:00
|
|
|
)
|
|
|
|
|
2019-10-06 16:19:56 +02:00
|
|
|
func getProcAddress(namea string) uintptr {
|
2019-01-04 07:05:27 +01:00
|
|
|
cname, err := windows.BytePtrFromString(namea)
|
2018-12-08 18:35:13 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-01-23 10:26:29 +01:00
|
|
|
|
2022-01-30 07:36:09 +01:00
|
|
|
r, _, err := procWglGetProcAddress.Call(uintptr(unsafe.Pointer(cname)))
|
2022-01-23 10:26:29 +01:00
|
|
|
if r != 0 {
|
2019-10-06 16:19:56 +02:00
|
|
|
return r
|
2018-12-08 18:35:13 +01:00
|
|
|
}
|
2022-01-30 07:36:09 +01:00
|
|
|
if err != nil && err != windows.ERROR_SUCCESS && err != windows.ERROR_PROC_NOT_FOUND {
|
|
|
|
panic(fmt.Sprintf("gl: wglGetProcAddress failed: %s", err.Error()))
|
|
|
|
}
|
2022-01-23 10:26:29 +01:00
|
|
|
|
2018-12-08 18:35:13 +01:00
|
|
|
p := opengl32.NewProc(namea)
|
|
|
|
if err := p.Find(); err != nil {
|
|
|
|
// The proc is not found.
|
2019-10-06 16:19:56 +02:00
|
|
|
return 0
|
2018-12-08 18:35:13 +01:00
|
|
|
}
|
2019-10-06 16:19:56 +02:00
|
|
|
return p.Addr()
|
2018-12-08 18:35:13 +01:00
|
|
|
}
|