2023-12-22 22:04:27 +08:00
|
|
|
package instance
|
|
|
|
|
|
2024-01-08 22:01:42 +08:00
|
|
|
//#cgo LDFLAGS: -LF:/Coding/GoModule/cgo -lvulkan
|
|
|
|
|
import "C"
|
|
|
|
|
|
2023-12-22 22:04:27 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/vkngwrapper/core/v2"
|
|
|
|
|
"github.com/vkngwrapper/core/v2/common"
|
|
|
|
|
"github.com/vkngwrapper/core/v2/core1_0"
|
2024-01-08 22:01:42 +08:00
|
|
|
"zworld/engine/window"
|
2023-12-22 22:04:27 +08:00
|
|
|
)
|
|
|
|
|
|
2023-12-23 18:01:28 +08:00
|
|
|
var (
|
|
|
|
|
engineName = "goworld"
|
|
|
|
|
layers = []string{
|
|
|
|
|
"VK_LAYER_KHRONOS_validation",
|
|
|
|
|
//"VK_LAYER_LUNARG_api_dump",
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-12-22 22:04:27 +08:00
|
|
|
|
|
|
|
|
type T interface {
|
|
|
|
|
EnumeratePhysicalDevices() []core1_0.PhysicalDevice
|
|
|
|
|
Destroy()
|
|
|
|
|
Ptr() core1_0.Instance
|
|
|
|
|
}
|
2024-01-08 22:01:42 +08:00
|
|
|
type FLoaderCreate func() *core.VulkanLoader
|
2023-12-23 18:01:28 +08:00
|
|
|
type FInstance struct {
|
2024-01-08 22:01:42 +08:00
|
|
|
loader *core.VulkanLoader
|
|
|
|
|
ptr core1_0.Instance
|
2023-12-22 22:04:27 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-08 22:01:42 +08:00
|
|
|
func New(appName string, win *window.FSDLWindow, LoaderCreate FLoaderCreate) T {
|
|
|
|
|
loader := LoaderCreate()
|
|
|
|
|
instanceOptions := &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),
|
2023-12-22 22:04:27 +08:00
|
|
|
}
|
2024-01-08 22:01:42 +08:00
|
|
|
help.getCreateInstanceExtension(instanceOptions, loader, win)
|
|
|
|
|
handle, _, err := loader.CreateInstance(nil, *instanceOptions)
|
2023-12-22 22:04:27 +08:00
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2023-12-23 18:01:28 +08:00
|
|
|
return &FInstance{
|
2023-12-22 22:04:27 +08:00
|
|
|
ptr: handle,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-23 18:01:28 +08:00
|
|
|
func (i *FInstance) Ptr() core1_0.Instance {
|
2023-12-22 22:04:27 +08:00
|
|
|
return i.ptr
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-23 18:01:28 +08:00
|
|
|
func (i *FInstance) Destroy() {
|
2023-12-22 22:04:27 +08:00
|
|
|
i.ptr.Destroy(nil)
|
|
|
|
|
i.ptr = nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-23 18:01:28 +08:00
|
|
|
func (i *FInstance) EnumeratePhysicalDevices() []core1_0.PhysicalDevice {
|
2023-12-22 22:04:27 +08:00
|
|
|
r, _, err := i.ptr.EnumeratePhysicalDevices()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return r
|
|
|
|
|
}
|