Implemented KrCreateWindowSurface and KrDeleteWindowSurface
This commit is contained in:
@@ -164,7 +164,7 @@ KRContext::~KRContext() {
|
|||||||
delete m_pBundleManager;
|
delete m_pBundleManager;
|
||||||
m_pBundleManager = NULL;
|
m_pBundleManager = NULL;
|
||||||
}
|
}
|
||||||
|
destroySurfaces();
|
||||||
destroyDeviceContexts();
|
destroyDeviceContexts();
|
||||||
if (m_resourceMap) {
|
if (m_resourceMap) {
|
||||||
delete m_resourceMap;
|
delete m_resourceMap;
|
||||||
@@ -676,6 +676,14 @@ KRContext::createDeviceContexts()
|
|||||||
app_info.engineVersion = 1;
|
app_info.engineVersion = 1;
|
||||||
app_info.apiVersion = VK_API_VERSION_1_0;
|
app_info.apiVersion = VK_API_VERSION_1_0;
|
||||||
|
|
||||||
|
// VK_KHR_surface and VK_KHR_win32_surface
|
||||||
|
|
||||||
|
char* extensions[] = {
|
||||||
|
"VK_KHR_surface",
|
||||||
|
#ifdef WIN32
|
||||||
|
"VK_KHR_win32_surface",
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
// initialize the VkInstanceCreateInfo structure
|
// initialize the VkInstanceCreateInfo structure
|
||||||
VkInstanceCreateInfo inst_info = {};
|
VkInstanceCreateInfo inst_info = {};
|
||||||
@@ -683,8 +691,12 @@ KRContext::createDeviceContexts()
|
|||||||
inst_info.pNext = NULL;
|
inst_info.pNext = NULL;
|
||||||
inst_info.flags = 0;
|
inst_info.flags = 0;
|
||||||
inst_info.pApplicationInfo = &app_info;
|
inst_info.pApplicationInfo = &app_info;
|
||||||
inst_info.enabledExtensionCount = 0;
|
#ifdef WIN32
|
||||||
inst_info.ppEnabledExtensionNames = NULL;
|
inst_info.enabledExtensionCount = 2;
|
||||||
|
#else
|
||||||
|
inst_info.enabledExtensionCount = 1;
|
||||||
|
#endif
|
||||||
|
inst_info.ppEnabledExtensionNames = extensions;
|
||||||
inst_info.enabledLayerCount = 0;
|
inst_info.enabledLayerCount = 0;
|
||||||
inst_info.ppEnabledLayerNames = NULL;
|
inst_info.ppEnabledLayerNames = NULL;
|
||||||
|
|
||||||
@@ -705,6 +717,19 @@ KRContext::destroyDeviceContexts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
KRContext::destroySurfaces()
|
||||||
|
{
|
||||||
|
if (m_vulkanInstance == VK_NULL_HANDLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto itr = m_surfaces.begin(); itr != m_surfaces.end(); itr++) {
|
||||||
|
SurfaceInfo* surfaceInfo = &(*itr).second;
|
||||||
|
vkDestroySurfaceKHR(m_vulkanInstance, surfaceInfo->surface, nullptr);
|
||||||
|
}
|
||||||
|
m_surfaces.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
KRContext::activateStreamerContext()
|
KRContext::activateStreamerContext()
|
||||||
{
|
{
|
||||||
@@ -795,16 +820,29 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
|||||||
if (createWindowSurfaceInfo->surfaceHandle < 0) {
|
if (createWindowSurfaceInfo->surfaceHandle < 0) {
|
||||||
return KR_ERROR_OUT_OF_BOUNDS;
|
return KR_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
if (m_vulkanInstance == VK_NULL_HANDLE) {
|
||||||
|
return KR_ERROR_VULKAN_REQUIRED;
|
||||||
|
}
|
||||||
if (m_surfaces.count(createWindowSurfaceInfo->surfaceHandle)) {
|
if (m_surfaces.count(createWindowSurfaceInfo->surfaceHandle)) {
|
||||||
return KR_ERROR_DUPLICATE_HANDLE;
|
return KR_ERROR_DUPLICATE_HANDLE;
|
||||||
}
|
}
|
||||||
SurfaceInfo info{};
|
SurfaceInfo info{};
|
||||||
info.surfaceHandle = createWindowSurfaceInfo->surfaceHandle;
|
info.surfaceHandle = createWindowSurfaceInfo->surfaceHandle;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
info.hWnd = static_cast<HWND>(createWindowSurfaceInfo->hWnd);
|
info.hWnd = static_cast<HWND>(createWindowSurfaceInfo->hWnd);
|
||||||
|
|
||||||
|
VkWin32SurfaceCreateInfoKHR createInfo{};
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||||
|
createInfo.hinstance = GetModuleHandle(nullptr);
|
||||||
|
createInfo.hwnd = info.hWnd;
|
||||||
|
|
||||||
|
if(vkCreateWin32SurfaceKHR(m_vulkanInstance, &createInfo, nullptr, &info.surface) != VK_SUCCESS) {
|
||||||
|
return KR_ERROR_VULKAN;
|
||||||
|
}
|
||||||
m_surfaces.insert(std::pair<KrSurfaceHandle, SurfaceInfo>(createWindowSurfaceInfo->surfaceHandle, info));
|
m_surfaces.insert(std::pair<KrSurfaceHandle, SurfaceInfo>(createWindowSurfaceInfo->surfaceHandle, info));
|
||||||
// TODO - Complete implementation
|
|
||||||
return KR_ERROR_NOT_IMPLEMENTED;
|
return KR_SUCCESS;
|
||||||
#else
|
#else
|
||||||
// Not implemented for this platform
|
// Not implemented for this platform
|
||||||
return KR_ERROR_NOT_IMPLEMENTED;
|
return KR_ERROR_NOT_IMPLEMENTED;
|
||||||
@@ -816,6 +854,15 @@ KrResult KRContext::deleteWindowSurface(const KrDeleteWindowSurfaceInfo* deleteW
|
|||||||
if (deleteWindowSurfaceInfo->surfaceHandle < 0) {
|
if (deleteWindowSurfaceInfo->surfaceHandle < 0) {
|
||||||
return KR_ERROR_OUT_OF_BOUNDS;
|
return KR_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
// TODO - Complete implementation
|
if (m_vulkanInstance == VK_NULL_HANDLE) {
|
||||||
return KR_ERROR_NOT_IMPLEMENTED;
|
return KR_ERROR_VULKAN_REQUIRED;
|
||||||
|
}
|
||||||
|
auto itr = m_surfaces.find(deleteWindowSurfaceInfo->surfaceHandle);
|
||||||
|
if (itr == m_surfaces.end()) {
|
||||||
|
return KR_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
SurfaceInfo* surfaceInfo = &(*itr).second;
|
||||||
|
vkDestroySurfaceKHR(m_vulkanInstance, surfaceInfo->surface, nullptr);
|
||||||
|
m_surfaces.erase(itr);
|
||||||
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,10 +171,12 @@ private:
|
|||||||
|
|
||||||
void createDeviceContexts();
|
void createDeviceContexts();
|
||||||
void destroyDeviceContexts();
|
void destroyDeviceContexts();
|
||||||
|
void destroySurfaces();
|
||||||
|
|
||||||
unordered_multimap<std::string, KRResource*> m_resources;
|
unordered_multimap<std::string, KRResource*> m_resources;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
KrSurfaceHandle surfaceHandle;
|
KrSurfaceHandle surfaceHandle;
|
||||||
|
VkSurfaceKHR surface;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,20 +42,20 @@ KrResult KrShutdown()
|
|||||||
return KR_SUCCESS;
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KrCreateSurface(const KrCreateWindowSurfaceInfo* pCreateSurfaceInfo)
|
KrResult KrCreateWindowSurface(const KrCreateWindowSurfaceInfo* pCreateWindowSurfaceInfo)
|
||||||
{
|
{
|
||||||
if (!sContext) {
|
if (!sContext) {
|
||||||
return KR_ERROR_NOT_INITIALIZED;
|
return KR_ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
return sContext->createWindowSurface(pCreateSurfaceInfo);
|
return sContext->createWindowSurface(pCreateWindowSurfaceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KrDeleteSurface(const KrDeleteWindowSurfaceInfo* pDeleteSurfaceInfo)
|
KrResult KrDeleteWindowSurface(const KrDeleteWindowSurfaceInfo* pDeleteWindowSurfaceInfo)
|
||||||
{
|
{
|
||||||
if (!sContext) {
|
if (!sContext) {
|
||||||
return KR_ERROR_NOT_INITIALIZED;
|
return KR_ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
return sContext->deleteWindowSurface(pDeleteSurfaceInfo);
|
return sContext->deleteWindowSurface(pDeleteWindowSurfaceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo)
|
KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo)
|
||||||
|
|||||||
@@ -38,14 +38,16 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
KR_SUCCESS = 0,
|
KR_SUCCESS = 0,
|
||||||
KR_ERROR_NOT_INITIALIZED = 1,
|
KR_ERROR_NOT_INITIALIZED,
|
||||||
KR_ERROR_NOT_IMPLEMENTED = 2,
|
KR_ERROR_NOT_IMPLEMENTED,
|
||||||
KR_ERROR_OUT_OF_BOUNDS = 3,
|
KR_ERROR_OUT_OF_BOUNDS,
|
||||||
KR_ERROR_NOT_MAPPED = 4,
|
KR_ERROR_NOT_MAPPED,
|
||||||
KR_ERROR_INCORRECT_TYPE = 5,
|
KR_ERROR_INCORRECT_TYPE,
|
||||||
KR_ERROR_NOT_FOUND = 6,
|
KR_ERROR_NOT_FOUND,
|
||||||
KR_ERROR_AMBIGUOUS_MATCH = 7,
|
KR_ERROR_AMBIGUOUS_MATCH,
|
||||||
KR_ERROR_DUPLICATE_HANDLE = 8,
|
KR_ERROR_DUPLICATE_HANDLE,
|
||||||
|
KR_ERROR_VULKAN,
|
||||||
|
KR_ERROR_VULKAN_REQUIRED,
|
||||||
KR_ERROR_UNEXPECTED = 0x10000000,
|
KR_ERROR_UNEXPECTED = 0x10000000,
|
||||||
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||||
} KrResult;
|
} KrResult;
|
||||||
@@ -54,6 +56,9 @@ typedef enum {
|
|||||||
KR_STRUCTURE_TYPE_INITIALIZE = 0,
|
KR_STRUCTURE_TYPE_INITIALIZE = 0,
|
||||||
KR_STRUCTURE_TYPE_SHUTDOWN,
|
KR_STRUCTURE_TYPE_SHUTDOWN,
|
||||||
|
|
||||||
|
KR_STRUCTURE_TYPE_CREATE_WINDOW_SURFACE,
|
||||||
|
KR_STRUCTURE_TYPE_DELETE_WINDOW_SURFACE,
|
||||||
|
|
||||||
KR_STRUCTURE_TYPE_LOAD_RESOURCE = 0x00010000,
|
KR_STRUCTURE_TYPE_LOAD_RESOURCE = 0x00010000,
|
||||||
KR_STRUCTURE_TYPE_UNLOAD_RESOURCE,
|
KR_STRUCTURE_TYPE_UNLOAD_RESOURCE,
|
||||||
KR_STRUCTURE_TYPE_SAVE_RESOURCE,
|
KR_STRUCTURE_TYPE_SAVE_RESOURCE,
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
if (!RegisterClass(&wc))
|
if (!RegisterClass(&wc))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!CreateWindow(wc.lpszClassName,
|
HWND hWnd = CreateWindow(wc.lpszClassName,
|
||||||
L"Kraken Smoke: Cube",
|
L"Kraken Smoke: Cube",
|
||||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||||
0, 0, 640, 480, 0, 0, hInstance, NULL))
|
0, 0, 640, 480, 0, 0, hInstance, NULL);
|
||||||
return 2;
|
|
||||||
|
|
||||||
|
if (!hWnd) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
KrInitializeInfo init_info = {};
|
KrInitializeInfo init_info = {};
|
||||||
init_info.sType = KR_STRUCTURE_TYPE_INITIALIZE;
|
init_info.sType = KR_STRUCTURE_TYPE_INITIALIZE;
|
||||||
@@ -44,11 +46,34 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KrCreateWindowSurfaceInfo create_surface_info = {};
|
||||||
|
create_surface_info.sType = KR_STRUCTURE_TYPE_CREATE_WINDOW_SURFACE;
|
||||||
|
create_surface_info.surfaceHandle = 1;
|
||||||
|
create_surface_info.hWnd = static_cast<void*>(hWnd);
|
||||||
|
res = KrCreateWindowSurface(&create_surface_info);
|
||||||
|
if (res != KR_SUCCESS) {
|
||||||
|
//printf("Failed to create window surface.\n");
|
||||||
|
KrShutdown();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
smoke_load();
|
smoke_load();
|
||||||
|
|
||||||
while (GetMessage(&msg, NULL, 0, 0) > 0)
|
while (GetMessage(&msg, NULL, 0, 0) > 0)
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
|
|
||||||
|
// KrShutdown will delete the window surfaces for us; however, we
|
||||||
|
// include this here for code coverage in tests.
|
||||||
|
KrDeleteWindowSurfaceInfo delete_surface_info = {};
|
||||||
|
delete_surface_info.sType = KR_STRUCTURE_TYPE_DELETE_WINDOW_SURFACE;
|
||||||
|
delete_surface_info.surfaceHandle = 1;
|
||||||
|
res = KrDeleteWindowSurface(&delete_surface_info);
|
||||||
|
if (res != KR_SUCCESS) {
|
||||||
|
//printf("Failed to delete window surface.\n");
|
||||||
|
KrShutdown();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
KrShutdown();
|
KrShutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user