forked from vulkan-go/vulkan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
54 lines (48 loc) · 1.74 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package vulkan
import (
"errors"
"unsafe"
)
// #include "vk_wrapper.h"
import "C"
// SetGetInstanceProcAddr sets the GetInstanceProcAddr function pointer used to load Vulkan symbols.
// The function can be retrieved from GLFW using GetInstanceProcAddress or from SDL2 using
// VulkanGetVkGetInstanceProcAddr. This function must be called before Init().
func SetGetInstanceProcAddr(getProcAddr unsafe.Pointer) {
C.setProcAddr(getProcAddr)
}
// SetDefaultGetInstanceProcAddr looks for the Vulkan library in the system-specific default
// location and returns an error if it cannot be located. This function functions the same way as
// SetGetInstanceProcAddr but without relying on a separate windowing library to load Vulkan.
func SetDefaultGetInstanceProcAddr() error {
C.setDefaultProcAddr()
if C.isProcAddrSet() == 0 {
return errors.New("vulkan: error loading default getProcAddr")
}
return nil
}
// Init checks for Vulkan support on the platform and obtains PFNs for global Vulkan API functions.
// Either SetGetInstanceProcAddr or SetDefaultGetInstanceGetProcAddr must have been called prior to
// calling Init.
func Init() error {
if C.isProcAddrSet() == 0 {
return errors.New("vulkan: GetInstanceProcAddr is not set")
}
ret := C.vkInit()
if ret < 0 {
return errors.New("vkInit failed")
}
return nil
}
// InitInstance obtains instance PFNs for Vulkan API functions, this is necessary on
// OS X using MoltenVK, but for the other platforms it's an option. Not implemented for Android.
func InitInstance(instance Instance) error {
if C.isProcAddrSet() == 0 {
return errors.New("vulkan: GetInstanceProcAddr is not set")
}
ret := C.vkInitInstance((C.VkInstance)(instance))
if ret < 0 {
return errors.New("vkInitInstance failed")
}
return nil
}