add sdl build flag

This commit is contained in:
Matthew 2026-06-19 16:15:53 +10:00
parent d6580c58f4
commit b3726d3627
3 changed files with 74 additions and 47 deletions

View File

@ -42,12 +42,12 @@
# include "../external/vma/vk_mem_alloc.h" # include "../external/vma/vk_mem_alloc.h"
#endif #endif
#ifndef BUILD_WASM #ifdef BUILD_SDL
# include <SDL3/SDL.h> # include <SDL3/SDL.h>
#ifdef BUILD_VULKAN # ifdef BUILD_VULKAN
# include <SDL3/SDL_vulkan.h> # include <SDL3/SDL_vulkan.h>
#endif # endif
#endif #endif

View File

@ -50,7 +50,19 @@ static if(!__traits(compiles, { glActiveTexture(0x84C0); }))
PFNGLACTIVETEXTUREPROC glActiveTexture; PFNGLACTIVETEXTUREPROC glActiveTexture;
} }
alias GLLoadProcAddr = SDL_GL_GetProcAddress; static if(__traits(compiles, { SDL_GL_GetProcAddress("Test"); }))
{
alias GLLoadProcAddr = SDL_GL_GetProcAddress;
}
else
{
void* GLLoadProcAddr(const char* name)
{
assert(false, "Currently requires SDL");
return null;
}
}
bool bool
GLLoadFuncs() GLLoadFuncs()

View File

@ -15,6 +15,8 @@ import core.stdc.stdio : Printf = printf;
import std.format : sformat; import std.format : sformat;
import std.math.rounding : Ceil = ceil; import std.math.rounding : Ceil = ceil;
enum bool SDL_ENABLED = __traits(compiles, { u32 count; SDL_Vulkan_GetInstanceExtensions(&count); });
version(VULKAN_DEBUG) version(VULKAN_DEBUG)
{ {
const BUILD_DEBUG = true; const BUILD_DEBUG = true;
@ -68,8 +70,11 @@ version(Windows)
struct PlatformHandles struct PlatformHandles
{ {
bool sdl; bool sdl;
SDL_Window* sdl_window; static if(SDL_ENABLED)
{
SDL_Window* sdl_window;
}
version(linux) version(linux)
{ {
Display* display; Display* display;
@ -2768,55 +2773,62 @@ Init(VulkanBuildInfo build_info, u64 permanent_mem, u64 frame_mem)
char*[] instance_ext = instance_ext_base; char*[] instance_ext = instance_ext_base;
if(build_info.platform_handles.sdl) if(build_info.platform_handles.sdl)
{ {
u32 total_extension_count = cast(u32)instance_ext.length; static if(SDL_ENABLED)
u32 sdl_extension_count;
const char** sdl_extensions_ptr = SDL_Vulkan_GetInstanceExtensions(&sdl_extension_count);
const char*[] sdl_extensions = sdl_extensions_ptr[0 .. sdl_extension_count];
if(sdl_extensions == null)
{ {
Errf("Failed to query Vulkan extensions for SDL, make sure the SDL_WINDOW_VULKAN flag is passed to SDL_CreateWindow [%s]", SDL_GetError()); u32 total_extension_count = cast(u32)instance_ext.length;
assert(false);
}
foreach(i; 0 .. sdl_extensions.length) u32 sdl_extension_count;
{ const char** sdl_extensions_ptr = SDL_Vulkan_GetInstanceExtensions(&sdl_extension_count);
bool exists; const char*[] sdl_extensions = sdl_extensions_ptr[0 .. sdl_extension_count];
foreach(j; 0 .. instance_ext.length) if(sdl_extensions == null)
{ {
if(strcmp(sdl_extensions[i], instance_ext[i]) == 0) Errf("Failed to query Vulkan extensions for SDL, make sure the SDL_WINDOW_VULKAN flag is passed to SDL_CreateWindow [%s]", SDL_GetError());
assert(false);
}
foreach(i; 0 .. sdl_extensions.length)
{
bool exists;
foreach(j; 0 .. instance_ext.length)
{ {
exists = true; if(strcmp(sdl_extensions[i], instance_ext[i]) == 0)
break; {
exists = true;
break;
}
}
if(!exists)
{
total_extension_count += 1;
} }
} }
if(!exists) instance_ext = Alloc!(char*)(arena, total_extension_count);
{ instance_ext[0 .. instance_ext.length] = instance_ext_base[0 .. $];
total_extension_count += 1;
}
}
instance_ext = Alloc!(char*)(arena, total_extension_count); u32 ext_count = cast(u32)instance_ext_base.length;
instance_ext[0 .. instance_ext.length] = instance_ext_base[0 .. $]; foreach(i; 0 .. sdl_extensions.length)
u32 ext_count = cast(u32)instance_ext_base.length;
foreach(i; 0 .. sdl_extensions.length)
{
bool exists;
foreach(j; 0 .. instance_ext_base.length)
{ {
if(strcmp(sdl_extensions[i], instance_ext_base[i]) == 0) bool exists;
foreach(j; 0 .. instance_ext_base.length)
{ {
exists = true; if(strcmp(sdl_extensions[i], instance_ext_base[i]) == 0)
break; {
exists = true;
break;
}
}
if(!exists)
{
instance_ext[ext_count++] = cast(char*)sdl_extensions[i];
} }
} }
}
if(!exists) else
{ {
instance_ext[ext_count++] = cast(char*)sdl_extensions[i]; assert(false, "Must be built with SDL or have the SDL flag disabled");
}
} }
} }
@ -2902,10 +2914,13 @@ Init(VulkanBuildInfo build_info, u64 permanent_mem, u64 frame_mem)
{ {
if(g_vk.platform_handles.sdl) if(g_vk.platform_handles.sdl)
{ {
if(!SDL_Vulkan_CreateSurface(g_vk.platform_handles.sdl_window, g_vk.instance, null, &g_vk.surface)) static if(SDL_ENABLED)
{ {
Errf("Failed to initialize Vulkan surface through SDL [%s]", Str(SDL_GetError())); if(!SDL_Vulkan_CreateSurface(g_vk.platform_handles.sdl_window, g_vk.instance, null, &g_vk.surface))
assert(false); {
Errf("Failed to initialize Vulkan surface through SDL [%s]", Str(SDL_GetError()));
assert(false);
}
} }
} }
else else