summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-03-14 02:29:15 +0200
committergrm <grm@eyesin.space>2026-03-14 02:29:15 +0200
commit650e5afde271d22b3653832daf339e1bd09a10d6 (patch)
treecc5e536b0150de1109daa43a055547d2266e60dd /src
parent20e64711ce2a09b657fb79d59cb824e9e34d2b07 (diff)
downloadcgame-650e5afde271d22b3653832daf339e1bd09a10d6.tar.gz
cgame-650e5afde271d22b3653832daf339e1bd09a10d6.tar.bz2
cgame-650e5afde271d22b3653832daf339e1bd09a10d6.zip
Migrate to imgui 1.92.6 and SDL3HEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/cplusplus.cpp35
-rw-r--r--src/render.c47
-rw-r--r--src/vksetup.h40
3 files changed, 51 insertions, 71 deletions
diff --git a/src/cplusplus.cpp b/src/cplusplus.cpp
index b8dd787..26809bb 100644
--- a/src/cplusplus.cpp
+++ b/src/cplusplus.cpp
@@ -9,7 +9,7 @@
#include "vk_mem_alloc.h"
#include <imgui.h>
-#include <backends/imgui_impl_sdl2.h>
+#include <backends/imgui_impl_sdl3.h>
#include <backends/imgui_impl_vulkan.h>
static void check_vk_result(VkResult err)
@@ -38,7 +38,7 @@ imgui_new_frame(vks_context vk)
{
ImGui_ImplVulkan_NewFrame();
- ImGui_ImplSDL2_NewFrame();
+ ImGui_ImplSDL3_NewFrame();
ImGui::NewFrame();
@@ -52,7 +52,7 @@ imgui_new_frame(vks_context vk)
bool
imgui_proc_event(SDL_Event* e)
{
- return ImGui_ImplSDL2_ProcessEvent(e);
+ return ImGui_ImplSDL3_ProcessEvent(e);
}
static VkDescriptorPool imguiPool;
@@ -86,37 +86,30 @@ init_imgui(vks_context *vk)
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
- io.ConfigFlags |=
- ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
- ImGui_ImplSDL2_InitForVulkan(vk->window);
+ ImGui_ImplSDL3_InitForVulkan(vk->window);
ImGui_ImplVulkan_InitInfo init_info = {};
+ init_info.ApiVersion = VK_API_VERSION_1_3;
init_info.Instance = vk->instance;
init_info.PhysicalDevice = vk->physical_device;
init_info.Device = vk->device;
- //init_info.QueueFamily = ;
init_info.Queue = vk->graphics_and_compute_queue;
- //init_info.PipelineCache = YOUR_PIPELINE_CACHE;
init_info.DescriptorPool = imguiPool;
- init_info.Subpass = 0;
+ init_info.PipelineInfoMain.Subpass = 0;
init_info.MinImageCount = 2;
init_info.ImageCount = 2;
- init_info.MSAASamples = vk->msaa_samples;
+ init_info.PipelineInfoMain.MSAASamples = vk->msaa_samples;
init_info.CheckVkResultFn = check_vk_result;
init_info.UseDynamicRendering = true;
- //init_info.
- init_info.PipelineRenderingCreateInfo.sType =
- VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR;
- init_info.PipelineRenderingCreateInfo.colorAttachmentCount = 1;
- init_info.PipelineRenderingCreateInfo.pColorAttachmentFormats = &vk->swapchain.image_format;
- init_info.PipelineRenderingCreateInfo.depthAttachmentFormat = vks_find_depth_format(*vk);
+ init_info.PipelineInfoMain.PipelineRenderingCreateInfo.sType =
+ VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR;
+ init_info.PipelineInfoMain.PipelineRenderingCreateInfo.colorAttachmentCount = 1;
+ init_info.PipelineInfoMain.PipelineRenderingCreateInfo.pColorAttachmentFormats = &vk->swapchain.image_format;
+ init_info.PipelineInfoMain.PipelineRenderingCreateInfo.depthAttachmentFormat = vks_find_depth_format(*vk);
ImGui_ImplVulkan_Init(&init_info);
- // (this gets a bit more complicated, see example app for full reference)
- ImGui_ImplVulkan_CreateFontsTexture();
- // (your code submit a queue)
- ImGui_ImplVulkan_DestroyFontsTexture();
}
void
diff --git a/src/render.c b/src/render.c
index 591442f..fc8388a 100644
--- a/src/render.c
+++ b/src/render.c
@@ -80,10 +80,9 @@ const int INDICES_SIZE = VK_ARRAY_LEN(indices);
/* }; */
/* const int INDICES_SIZE = VK_ARRAY_LEN(indices); */
-static int resizing_event_watcher(void *data, SDL_Event *event) {
+static bool resizing_event_watcher(void *data, SDL_Event *event) {
(void) data;
- if (event->type == SDL_WINDOWEVENT &&
- event->window.event == SDL_WINDOWEVENT_RESIZED) {
+ if (event->type == SDL_EVENT_WINDOW_RESIZED) {
s.sdl_window_resized = 1;
}
return 0;
@@ -111,17 +110,15 @@ move_towards(vec3 position, vec3 front, float step)
bool
sdl_init()
{
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ if (!SDL_Init(SDL_INIT_VIDEO)) {
vk_log(VK_INFO, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return false;
}
s.vk.window = SDL_CreateWindow("Vulkanizater",
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
s.window_w,
s.window_h,
- SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN);
+ SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN);
if (s.vk.window == NULL) {
vk_log(VK_INFO, "Window could not be created! SDL_Error: %s\n", SDL_GetError());
return false;
@@ -277,7 +274,7 @@ update_camera(float xoffset, float yoffset)
void
mouseCallback(SDL_Event *event)
{
- if (event->type != SDL_MOUSEMOTION) return;
+ if (event->type != SDL_EVENT_MOUSE_MOTION) return;
float xoffset = event->motion.xrel;
float yoffset = -event->motion.yrel; // Reversed since y-coordinates range from bottom to top
@@ -1047,50 +1044,50 @@ handle_input(bool * quit)
imgui_proc_event(&e);
// User requests quit
- if (e.type == SDL_QUIT) {
+ if (e.type == SDL_EVENT_QUIT) {
*quit = true;
}
// User presses a key
- else if (e.type == SDL_KEYDOWN) {
- switch (e.key.keysym.sym) {
- case SDLK_w:
+ else if (e.type == SDL_EVENT_KEY_DOWN) {
+ switch (e.key.key) {
+ case SDLK_W:
// s.camera.pos[0] += 0.1f;
move_towards(s.camera.front, s.camera.pos, -0.1f);
move_towards(s.camera.pos, s.camera.front, 0.1f);
break;
- case SDLK_s:
+ case SDLK_S:
//s.camera.pos[0] -= 0.1f;
move_towards(s.camera.front, s.camera.pos, 0.1f);
move_towards(s.camera.pos, s.camera.front, -0.1f);
break;
- case SDLK_a:
+ case SDLK_A:
move_relative(s.camera.front, s.camera.pos, -0.1f, 1);
move_relative(s.camera.pos, s.camera.front, 0.1f, 1);
break;
- case SDLK_d:
+ case SDLK_D:
move_relative(s.camera.front, s.camera.pos, 0.1f, 1);
move_relative(s.camera.pos, s.camera.front, -0.1f, 1);
break;
- case SDLK_q:
+ case SDLK_Q:
move_relative(s.camera.front, s.camera.pos, 0.1f, 0);
move_relative(s.camera.pos, s.camera.front, 0.1f, 0);
break;
- case SDLK_e:
+ case SDLK_E:
move_relative(s.camera.front, s.camera.pos, -0.1f, 0);
move_relative(s.camera.pos, s.camera.front, -0.1f, 0);
break;
- case SDLK_g: // reload shaders
+ case SDLK_G: // reload shaders
recreate_graphics_pipeline();
break;
- case SDLK_z: // toggle polygon mode
+ case SDLK_Z: // toggle polygon mode
polygon_mode_n = (polygon_mode_n + 1) % 3;
s.polygon_mode = polygon_modes[polygon_mode_n];
recreate_graphics_pipeline();
break;
- case SDLK_l:
+ case SDLK_L:
s.rotate = s.rotate ? 0 : 1;
break;
- case SDLK_m:
+ case SDLK_M:
vkDeviceWaitIdle(s.vk.device);
free(s.vertices);
free(s.indices);
@@ -1118,7 +1115,7 @@ handle_input(bool * quit)
vulkan_create_vertex_buffer();
vulkan_create_index_buffer();
break;
- case SDLK_r:
+ case SDLK_R:
s.camera.pos[0] = 1.0f;
s.camera.pos[1] = 1.0f;
s.camera.pos[2] = 1.0f;
@@ -1144,7 +1141,7 @@ handle_input(bool * quit)
break;
}
}
- else if (e.type == SDL_MOUSEWHEEL) {
+ else if (e.type == SDL_EVENT_MOUSE_WHEEL) {
if(e.wheel.y > 0) // scroll up
{
s.zoom -= 1;
@@ -1155,7 +1152,7 @@ handle_input(bool * quit)
if (s.zoom == -100) s.zoom = 1;
}
}
- else if (e.type == SDL_MOUSEBUTTONDOWN) {
+ else if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (e.button.button != 2) {
s.mouse_pressed = 1;
} else {
@@ -1163,7 +1160,7 @@ handle_input(bool * quit)
}
}
- else if (e.type == SDL_MOUSEBUTTONUP) {
+ else if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) {
if (e.button.button != 2) {
s.mouse_pressed = 0;
} else {
diff --git a/src/vksetup.h b/src/vksetup.h
index 505bdec..a659136 100644
--- a/src/vksetup.h
+++ b/src/vksetup.h
@@ -38,8 +38,8 @@
#define SDL_MAIN_HANDLED
#define VK_USE_PLATFORM_XCB_KHR
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_vulkan.h>
+#include <SDL3/SDL.h>
+#include <SDL3/SDL_vulkan.h>
#include <vulkan/vulkan.h>
#include <vulkan/vk_enum_string_helper.h> // for string_VkResult
@@ -348,8 +348,7 @@ _has_stencil_component(VkFormat format)
static VkInstance
_vks_create_instance(bool validation_layers_toggle,
const char* const validation_layers[],
- uint32_t validation_layer_count,
- SDL_Window* window)
+ uint32_t validation_layer_count)
{
if (validation_layers_toggle &&
!_vks_check_validation_layer_support(validation_layers,
@@ -389,37 +388,29 @@ _vks_create_instance(bool validation_layers_toggle,
};
uint32_t sdlExtensionCount = 0;
-
- if (SDL_Vulkan_GetInstanceExtensions(window, &sdlExtensionCount, NULL) ==
- SDL_FALSE) {
+ const char* const* sdlExtensionsBase = SDL_Vulkan_GetInstanceExtensions(&sdlExtensionCount);
+ if (sdlExtensionsBase == NULL) {
vk_log(VK_ERROR,
"SDL_Vulkan_GetInstanceExtensions failed: %s\n",
SDL_GetError());
abort();
}
- // make space for debug extenetion
+ // Copy pointers into a local array so we can append the debug extension
+ uint32_t totalExtensionCount = sdlExtensionCount;
if (validation_layers_toggle) {
- sdlExtensionCount++;
+ totalExtensionCount++;
}
-
- const char* sdlExtensions[sdlExtensionCount];
-
- if (SDL_Vulkan_GetInstanceExtensions(
- window, &sdlExtensionCount, sdlExtensions) == SDL_FALSE) {
- vk_log(VK_ERROR,
- "SDL_Vulkan_GetInstanceExtensions failed: %s\n",
- SDL_GetError());
- abort();
+ const char* sdlExtensions[totalExtensionCount];
+ for (uint32_t i = 0; i < sdlExtensionCount; i++) {
+ sdlExtensions[i] = sdlExtensionsBase[i];
}
-
- // add debug extenetion
if (validation_layers_toggle) {
sdlExtensions[sdlExtensionCount] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
}
vk_log(VK_INFO, "The sdl extensions:\n");
- for (uint32_t i = 0; i < sdlExtensionCount; i++) {
+ for (uint32_t i = 0; i < totalExtensionCount; i++) {
vk_log(VK_INFO, "\t%s\n", sdlExtensions[i]);
}
@@ -1021,12 +1012,11 @@ vks_create_vulkan_context(vks_context* vk)
/* Create vulkan instance */
vk->instance = _vks_create_instance(enable_validation_layers,
validation_layers,
- validation_layer_count,
- vk->window);
+ validation_layer_count);
/* Create render surface */
- if (SDL_Vulkan_CreateSurface(vk->window, vk->instance, &vk->surface) ==
- SDL_FALSE) {
+ if (SDL_Vulkan_CreateSurface(vk->window, vk->instance, NULL, &vk->surface) ==
+ false) {
vk_log(VK_ERROR, "Failed to create surface\n");
} else {
vk_log(VK_INFO, "Vulkan surface created\n");