From b3726d362731ec63c16ee963eac6b950e55bdc29 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 19 Jun 2026 16:15:53 +1000 Subject: [PATCH] add sdl build flag --- dlib/dlibincludes.c | 8 ++-- opengl/opengl_native.d | 14 +++++- vulkan/vulkan.d | 99 ++++++++++++++++++++++++------------------ 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/dlib/dlibincludes.c b/dlib/dlibincludes.c index 315eb71..5f514aa 100644 --- a/dlib/dlibincludes.c +++ b/dlib/dlibincludes.c @@ -42,12 +42,12 @@ # include "../external/vma/vk_mem_alloc.h" #endif -#ifndef BUILD_WASM +#ifdef BUILD_SDL # include -#ifdef BUILD_VULKAN -# include -#endif +# ifdef BUILD_VULKAN +# include +# endif #endif diff --git a/opengl/opengl_native.d b/opengl/opengl_native.d index fd7df62..b17fc67 100644 --- a/opengl/opengl_native.d +++ b/opengl/opengl_native.d @@ -50,7 +50,19 @@ static if(!__traits(compiles, { glActiveTexture(0x84C0); })) 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 GLLoadFuncs() diff --git a/vulkan/vulkan.d b/vulkan/vulkan.d index c17f8fb..23d4639 100644 --- a/vulkan/vulkan.d +++ b/vulkan/vulkan.d @@ -15,6 +15,8 @@ import core.stdc.stdio : Printf = printf; import std.format : sformat; import std.math.rounding : Ceil = ceil; +enum bool SDL_ENABLED = __traits(compiles, { u32 count; SDL_Vulkan_GetInstanceExtensions(&count); }); + version(VULKAN_DEBUG) { const BUILD_DEBUG = true; @@ -68,8 +70,11 @@ version(Windows) struct PlatformHandles { - bool sdl; - SDL_Window* sdl_window; + bool sdl; + static if(SDL_ENABLED) + { + SDL_Window* sdl_window; + } version(linux) { Display* display; @@ -2768,55 +2773,62 @@ Init(VulkanBuildInfo build_info, u64 permanent_mem, u64 frame_mem) char*[] instance_ext = instance_ext_base; if(build_info.platform_handles.sdl) { - u32 total_extension_count = cast(u32)instance_ext.length; - - 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) + static if(SDL_ENABLED) { - 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); - } + u32 total_extension_count = cast(u32)instance_ext.length; - foreach(i; 0 .. sdl_extensions.length) - { - bool exists; - foreach(j; 0 .. instance_ext.length) + 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) { - 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; - break; + if(strcmp(sdl_extensions[i], instance_ext[i]) == 0) + { + exists = true; + break; + } + } + + if(!exists) + { + total_extension_count += 1; } } - if(!exists) - { - total_extension_count += 1; - } - } + instance_ext = Alloc!(char*)(arena, total_extension_count); + instance_ext[0 .. instance_ext.length] = instance_ext_base[0 .. $]; - instance_ext = Alloc!(char*)(arena, total_extension_count); - instance_ext[0 .. instance_ext.length] = instance_ext_base[0 .. $]; - - u32 ext_count = cast(u32)instance_ext_base.length; - foreach(i; 0 .. sdl_extensions.length) - { - bool exists; - foreach(j; 0 .. instance_ext_base.length) + u32 ext_count = cast(u32)instance_ext_base.length; + foreach(i; 0 .. sdl_extensions.length) { - if(strcmp(sdl_extensions[i], instance_ext_base[i]) == 0) + bool exists; + foreach(j; 0 .. instance_ext_base.length) { - exists = true; - break; + if(strcmp(sdl_extensions[i], instance_ext_base[i]) == 0) + { + exists = true; + break; + } + } + + if(!exists) + { + instance_ext[ext_count++] = cast(char*)sdl_extensions[i]; } } - - if(!exists) - { - instance_ext[ext_count++] = cast(char*)sdl_extensions[i]; - } + } + else + { + 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(!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())); - assert(false); + if(!SDL_Vulkan_CreateSurface(g_vk.platform_handles.sdl_window, g_vk.instance, null, &g_vk.surface)) + { + Errf("Failed to initialize Vulkan surface through SDL [%s]", Str(SDL_GetError())); + assert(false); + } } } else