66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package instance
|
|
|
|
import (
|
|
"github.com/go-gl/glfw/v3.3/glfw"
|
|
"github.com/vkngwrapper/core/v2"
|
|
"github.com/vkngwrapper/core/v2/common"
|
|
"github.com/vkngwrapper/core/v2/core1_0"
|
|
)
|
|
|
|
var (
|
|
engineName = "goworld"
|
|
layers = []string{
|
|
"VK_LAYER_KHRONOS_validation",
|
|
//"VK_LAYER_LUNARG_api_dump",
|
|
}
|
|
)
|
|
|
|
type T interface {
|
|
EnumeratePhysicalDevices() []core1_0.PhysicalDevice
|
|
Destroy()
|
|
Ptr() core1_0.Instance
|
|
}
|
|
|
|
type FInstance struct {
|
|
ptr core1_0.Instance
|
|
}
|
|
|
|
func New(appName string) T {
|
|
loader, err := core.CreateLoaderFromProcAddr(glfw.GetVulkanGetInstanceProcAddress())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
handle, _, err := loader.CreateInstance(nil, core1_0.InstanceCreateInfo{
|
|
APIVersion: common.APIVersion(common.CreateVersion(1, 1, 0)),
|
|
ApplicationName: appName,
|
|
ApplicationVersion: common.CreateVersion(0, 1, 0),
|
|
EngineName: "goworld",
|
|
EngineVersion: common.CreateVersion(0, 2, 1),
|
|
EnabledLayerNames: layers,
|
|
EnabledExtensionNames: extensions,
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &FInstance{
|
|
ptr: handle,
|
|
}
|
|
}
|
|
|
|
func (i *FInstance) Ptr() core1_0.Instance {
|
|
return i.ptr
|
|
}
|
|
|
|
func (i *FInstance) Destroy() {
|
|
i.ptr.Destroy(nil)
|
|
i.ptr = nil
|
|
}
|
|
|
|
func (i *FInstance) EnumeratePhysicalDevices() []core1_0.PhysicalDevice {
|
|
r, _, err := i.ptr.EnumeratePhysicalDevices()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return r
|
|
}
|