2022-11-13 17:55:26 +01:00
|
|
|
// Copyright 2022 The Ebitengine 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.
|
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")
|
2022-11-13 18:03:36 +01:00
|
|
|
isES = false
|
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 {
|
2022-11-13 07:37:18 +01:00
|
|
|
panic(fmt.Sprintf("gl: wglGetProcAddress failed for %s: %s", namea, err.Error()))
|
2022-01-30 07:36:09 +01:00
|
|
|
}
|
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
|
|
|
}
|