mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-05 00:50:53 +00:00
vulkan: mingw support
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@119 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
# $Id$
|
||||
|
||||
ifeq ($(TARGET),)
|
||||
TARGET = $(shell uname -s)
|
||||
endif
|
||||
|
||||
ifeq ($(CC),)
|
||||
CC = gcc
|
||||
endif
|
||||
|
||||
CFLAGS = -Wall -Wextra -Iinclude
|
||||
LDFLAGS =
|
||||
LIBS =
|
||||
ifeq (${DEBUG},1)
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -g
|
||||
endif
|
||||
|
||||
@@ -32,6 +38,7 @@ UNIX = 1
|
||||
VULKAN = 1
|
||||
else ifeq ($(TARGET),Windows)
|
||||
WINDOWS = 1
|
||||
VULKAN = 1
|
||||
else
|
||||
$(error Add your platform definition)
|
||||
endif
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
#include <windows.h>
|
||||
|
||||
struct _MwLL {
|
||||
HWND hWnd;
|
||||
HDC hDC;
|
||||
void* user;
|
||||
int copy_buffer;
|
||||
HINSTANCE hInstance;
|
||||
HWND hWnd;
|
||||
HDC hDC;
|
||||
void* user;
|
||||
int copy_buffer;
|
||||
|
||||
MwLLHandler handler;
|
||||
};
|
||||
|
||||
@@ -98,6 +98,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
||||
|
||||
r->copy_buffer = 1;
|
||||
r->hWnd = CreateWindow(parent == NULL ? "milsko" : "STATIC", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x, y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
|
||||
r->hInstance = wc.hInstance;
|
||||
|
||||
u->ll = r;
|
||||
if(parent == NULL) {
|
||||
|
||||
@@ -20,11 +20,22 @@
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vk_enum_string_helper.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <dlfcn.h>
|
||||
#include <vulkan/vulkan_xlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
#endif
|
||||
|
||||
// MinGW's copy of vulkan string helpers is just straight up busted.
|
||||
#ifndef __MINGW32__
|
||||
#include <vulkan/vk_enum_string_helper.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../external/stb_ds.h"
|
||||
@@ -36,12 +47,21 @@ MwVulkanConfig vulkan_config = {
|
||||
};
|
||||
|
||||
// convienence macro for handling vulkan errors
|
||||
#ifndef __MINGW32__
|
||||
#define VK_CMD(func) \
|
||||
vk_res = func; \
|
||||
if(vk_res != VK_SUCCESS) { \
|
||||
setLastError("Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
|
||||
return MwEerror; \
|
||||
}
|
||||
#else
|
||||
#define VK_CMD(func) \
|
||||
vk_res = func; \
|
||||
if(vk_res != VK_SUCCESS) { \
|
||||
setLastError("Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
|
||||
return MwEerror; \
|
||||
}
|
||||
#endif
|
||||
|
||||
// convienence macro for loading a vulkan function pointer into memory
|
||||
#define LOAD_VK_FUNCTION(name) \
|
||||
@@ -59,7 +79,11 @@ const char** enabledExtensions;
|
||||
const char** enabledLayers;
|
||||
|
||||
typedef struct vulkan {
|
||||
void* vulkanLibrary;
|
||||
#ifdef _WIN32
|
||||
HMODULE vulkanLibrary;
|
||||
#else
|
||||
void* vulkanLibrary;
|
||||
#endif
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||
VkInstance vkInstance;
|
||||
VkSurfaceKHR vkSurface;
|
||||
@@ -135,18 +159,28 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
|
||||
|
||||
VkResult vk_res;
|
||||
|
||||
// TODO: support for whatever win32's equivalants to dlopen/dlsym are
|
||||
// Load Vulkan and any other function pointers we need.
|
||||
#ifndef _WIN32
|
||||
o->vulkanLibrary = dlopen("libvulkan.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||
o->vkGetInstanceProcAddr = dlsym(o->vulkanLibrary, "vkGetInstanceProcAddr");
|
||||
VK_ASSERT(o->vkGetInstanceProcAddr);
|
||||
|
||||
// Load in any other function pointers we need.
|
||||
_vkEnumerateInstanceExtensionProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceExtensionProperties");
|
||||
VK_ASSERT(_vkEnumerateInstanceExtensionProperties);
|
||||
_vkEnumerateInstanceLayerProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceLayerProperties");
|
||||
VK_ASSERT(_vkEnumerateInstanceLayerProperties);
|
||||
_vkCreateInstance = dlsym(o->vulkanLibrary, "vkCreateInstance");
|
||||
VK_ASSERT(_vkCreateInstance);
|
||||
#else
|
||||
o->vulkanLibrary = LoadLibrary("vulkan-1.dll");
|
||||
o->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)(void*)GetProcAddress(o->vulkanLibrary, "vkGetInstanceProcAddr");
|
||||
VK_ASSERT(o->vkGetInstanceProcAddr);
|
||||
_vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties)(void*)GetProcAddress(o->vulkanLibrary, "vkEnumerateInstanceExtensionProperties");
|
||||
VK_ASSERT(_vkEnumerateInstanceExtensionProperties);
|
||||
_vkEnumerateInstanceLayerProperties = (PFN_vkEnumerateInstanceLayerProperties)(void*)GetProcAddress(o->vulkanLibrary, "vkEnumerateInstanceLayerProperties");
|
||||
VK_ASSERT(_vkEnumerateInstanceLayerProperties);
|
||||
_vkCreateInstance = (PFN_vkCreateInstance)(void*)GetProcAddress(o->vulkanLibrary, "vkCreateInstance");
|
||||
VK_ASSERT(_vkCreateInstance);
|
||||
#endif
|
||||
|
||||
// setup enabled extensions
|
||||
arrput(enabledExtensions, VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
Reference in New Issue
Block a user