mirror of
https://github.com/cimgui/cimgui.git
synced 2025-10-10 11:41:39 +01:00
Compare commits
5 Commits
1.91.9
...
38c093b44e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
38c093b44e | ||
![]() |
c32d1c0c9b | ||
![]() |
3530b937f1 | ||
![]() |
bb6f212993 | ||
![]() |
e3af31fb9c |
@@ -24,6 +24,8 @@
|
||||
#define igButton igButton_Str
|
||||
#endif
|
||||
|
||||
#define igGetIO igGetIO_Nil
|
||||
|
||||
GLFWwindow *window;
|
||||
|
||||
// Data
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#define igButton igButton_Str
|
||||
#endif
|
||||
|
||||
#define igGetIO igGetIO_Nil
|
||||
|
||||
GLFWwindow *window;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#define igButton igButton_Str
|
||||
#endif
|
||||
|
||||
#define igGetIO igGetIO_Nil
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@@ -26,6 +26,8 @@
|
||||
#define igButton igButton_Str
|
||||
#endif
|
||||
|
||||
#define igGetIO igGetIO_Nil
|
||||
|
||||
#define IM_UNUSED(_VAR) ((void)(_VAR))
|
||||
#define IM_ASSERT(_EXPR) assert(_EXPR)
|
||||
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*(_ARR))))
|
||||
|
30
backend_test/example_sdlgpu3_fetchcontent/CMakeLists.txt
Normal file
30
backend_test/example_sdlgpu3_fetchcontent/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
project(cimgui_sdlgpu3 LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
sdl3
|
||||
URL https://github.com/libsdl-org/SDL/releases/download/release-3.2.8/SDL3-3.2.8.tar.gz
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(sdl3)
|
||||
|
||||
include(GenerateCimguiBindings.cmake)
|
||||
|
||||
GenerateCimguiBindings(cimgui_with_backend)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.c
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 cimgui_with_backend)
|
||||
target_compile_definitions(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE
|
||||
CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
|
||||
CIMGUI_USE_SDL3=1
|
||||
CIMGUI_USE_SDLGPU3=1
|
||||
)
|
@@ -0,0 +1,52 @@
|
||||
# This downloads cimgui, configures it to generate the SDL3 and SDLGPU3 bindings,
|
||||
# and adds it as a cmake target for you to link to. Feel free to copy this file
|
||||
# into your project, or refit it to your needs.
|
||||
|
||||
function(GenerateCimguiBindings target)
|
||||
include(FetchContent)
|
||||
|
||||
# NOTE: In your own project, you may want to pin this project to a particular commit
|
||||
FetchContent_Declare(
|
||||
cimgui
|
||||
EXCLUDE_FROM_ALL
|
||||
GIT_REPOSITORY https://github.com/cimgui/cimgui.git
|
||||
# GIT_HASH githashgoeshere
|
||||
GIT_SUBMODULES_RECURSE true
|
||||
GIT_PROGRESS true
|
||||
GIT_SHALLOW true
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cimgui)
|
||||
|
||||
file(READ ${cimgui_SOURCE_DIR}/generator/output/cimgui_impl.h cimgui_impl)
|
||||
|
||||
# We're checking to see if the cimgui_impl.h file already has SDLGPU3 bindings,
|
||||
# since this will be executed on each "configure" (whenever you run cmake)
|
||||
string(FIND "${cimgui_impl}" "SDLGPU3" sdlgpu_position)
|
||||
# If we don't find it, sdlgpu_position will be -1
|
||||
if(sdlgpu_position EQUAL -1)
|
||||
# NOTE: This requires a luajit on your path. If your binary is named different, you will
|
||||
# need to modify this command
|
||||
execute_process(
|
||||
COMMAND luajit generator.lua clang internal sdl3 sdlgpu3 -I../imgui -I${sdl3_SOURCE_DIR}/include
|
||||
WORKING_DIRECTORY ${cimgui_SOURCE_DIR}/generator
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(${target} SHARED
|
||||
${cimgui_SOURCE_DIR}/cimgui.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/imgui.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/imgui_draw.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/imgui_demo.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/imgui_widgets.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/imgui_tables.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/backends/imgui_impl_sdl3.cpp
|
||||
${cimgui_SOURCE_DIR}/imgui/backends/imgui_impl_sdlgpu3.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${target} PUBLIC ${cimgui_SOURCE_DIR} ${cimgui_SOURCE_DIR}/generator/output)
|
||||
target_include_directories(${target} PRIVATE ${cimgui_SOURCE_DIR}/imgui ${cimgui_SOURCE_DIR}/imgui/backends)
|
||||
target_compile_definitions(${target} PRIVATE "-DIMGUI_IMPL_API=extern\t\"C\"\t")
|
||||
target_compile_features(${target} PRIVATE cxx_std_11)
|
||||
target_link_libraries(${target} PRIVATE SDL3::SDL3)
|
||||
endfunction()
|
9
backend_test/example_sdlgpu3_fetchcontent/README.md
Normal file
9
backend_test/example_sdlgpu3_fetchcontent/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# SDLGPU3
|
||||
|
||||
This example is a little different from the others, because `cimgui` doesn't come with bindings for the SDLGPU3 backend out of the box. Instead, this example shows how to generate the necessary bindings during cmake's configure time, then add the compiled library as a target for your application to link to.
|
||||
|
||||
## Building
|
||||
|
||||
```sh
|
||||
cmake -B build . && cmake --build build
|
||||
```
|
164
backend_test/example_sdlgpu3_fetchcontent/main.c
Normal file
164
backend_test/example_sdlgpu3_fetchcontent/main.c
Normal file
@@ -0,0 +1,164 @@
|
||||
#include "SDL3/SDL_pixels.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
#include <cimgui.h>
|
||||
#include <cimgui_impl.h>
|
||||
|
||||
#define CHECK(x) \
|
||||
do { \
|
||||
void *value = (void *)x; \
|
||||
if (!value || (void *)value == NULL) { \
|
||||
fprintf(stderr, "SDL Error: %s", SDL_GetError()); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SCREEN_WIDTH 800
|
||||
#define SCREEN_HEIGHT 600
|
||||
#define SCREEN_FPS 60
|
||||
#define SCREEN_TICKS_PER_FRAME 1000 / SCREEN_FPS
|
||||
|
||||
int main() {
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
fprintf(stderr, "Failed to init video! %s", SDL_GetError());
|
||||
return 1;
|
||||
};
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
window = SDL_CreateWindow("Dung", SCREEN_WIDTH, SCREEN_HEIGHT, 0);
|
||||
assert(window);
|
||||
|
||||
SDL_GPUDevice *device =
|
||||
SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_MSL, true, NULL);
|
||||
assert(device);
|
||||
|
||||
const char *device_driver = SDL_GetGPUDeviceDriver(device);
|
||||
CHECK(device_driver);
|
||||
|
||||
CHECK(SDL_ClaimWindowForGPUDevice(device, window));
|
||||
|
||||
// setup imgui
|
||||
igCreateContext(NULL);
|
||||
|
||||
// set docking
|
||||
ImGuiIO *ioptr = igGetIO();
|
||||
ioptr->ConfigFlags |=
|
||||
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
// ioptr->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable
|
||||
// Gamepad Controls
|
||||
#ifdef IMGUI_HAS_DOCK
|
||||
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
ioptr->ConfigFlags |=
|
||||
ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform
|
||||
// Windows
|
||||
#endif
|
||||
|
||||
assert(ImGui_ImplSDL3_InitForSDLGPU(window));
|
||||
assert(ImGui_ImplSDLGPU3_Init(&(ImGui_ImplSDLGPU3_InitInfo){
|
||||
.ColorTargetFormat = SDL_GetGPUSwapchainTextureFormat(device, window),
|
||||
.Device = device,
|
||||
.MSAASamples = SDL_GPU_SAMPLECOUNT_1,
|
||||
}));
|
||||
|
||||
// finish loading data
|
||||
|
||||
bool running = true;
|
||||
SDL_Event e;
|
||||
uint64_t now = SDL_GetTicks();
|
||||
uint64_t previous = now;
|
||||
uint64_t last_frame_time = now;
|
||||
const bool *keyboard_state = SDL_GetKeyboardState(NULL);
|
||||
bool demo_window_open = true;
|
||||
|
||||
while (running) {
|
||||
const uint64_t ts = now - previous;
|
||||
|
||||
while (SDL_PollEvent(&e)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(&e);
|
||||
switch (e.type) {
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
switch (e.key.scancode) {
|
||||
case SDL_SCANCODE_GRAVE: {
|
||||
demo_window_open = !demo_window_open;
|
||||
} break;
|
||||
|
||||
case SDL_SCANCODE_ESCAPE: {
|
||||
running = false;
|
||||
} break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
} break;
|
||||
case SDL_EVENT_QUIT: {
|
||||
running = false;
|
||||
} break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
previous = now;
|
||||
now = SDL_GetTicks();
|
||||
if (now - last_frame_time >= SCREEN_TICKS_PER_FRAME) {
|
||||
last_frame_time = now;
|
||||
|
||||
ImGui_ImplSDLGPU3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
igNewFrame();
|
||||
|
||||
if (demo_window_open) {
|
||||
igShowDemoWindow(&demo_window_open);
|
||||
}
|
||||
|
||||
igRender();
|
||||
|
||||
SDL_GPUCommandBuffer *cmdbuf = SDL_AcquireGPUCommandBuffer(device);
|
||||
if (cmdbuf == NULL) {
|
||||
fprintf(stderr, "ERROR: SDL_AcquireGPUCommandBuffer failed: %s\n",
|
||||
SDL_GetError());
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_GPUTexture *swapchain_texture;
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(
|
||||
cmdbuf, window, &swapchain_texture, NULL, NULL)) {
|
||||
fprintf(stderr,
|
||||
"ERROR: SDL_WaitAndAcquireGPUSwapchainTexture failed: %s\n",
|
||||
SDL_GetError());
|
||||
break;
|
||||
}
|
||||
|
||||
if (swapchain_texture == NULL) {
|
||||
fprintf(stderr, "ERROR: swapchain_texture is NULL\n");
|
||||
SDL_SubmitGPUCommandBuffer(cmdbuf);
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_GPUColorTargetInfo color_target_info = {0};
|
||||
color_target_info.texture = swapchain_texture;
|
||||
color_target_info.clear_color = (SDL_FColor){0, 0, 0, 1};
|
||||
color_target_info.load_op = SDL_GPU_LOADOP_CLEAR;
|
||||
color_target_info.store_op = SDL_GPU_STOREOP_STORE;
|
||||
|
||||
ImDrawData *imgui_draw_data = igGetDrawData();
|
||||
Imgui_ImplSDLGPU3_PrepareDrawData(imgui_draw_data, cmdbuf);
|
||||
|
||||
SDL_GPURenderPass *render_pass =
|
||||
SDL_BeginGPURenderPass(cmdbuf, &color_target_info, 1, NULL);
|
||||
CHECK(render_pass);
|
||||
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(imgui_draw_data, cmdbuf, render_pass,
|
||||
NULL);
|
||||
|
||||
SDL_EndGPURenderPass(render_pass);
|
||||
CHECK(SDL_SubmitGPUCommandBuffer(cmdbuf));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@@ -53,7 +53,7 @@ CIMGUI_API void igSetCurrentContext(ImGuiContext* ctx)
|
||||
{
|
||||
return ImGui::SetCurrentContext(ctx);
|
||||
}
|
||||
CIMGUI_API ImGuiIO* igGetIO()
|
||||
CIMGUI_API ImGuiIO* igGetIO_Nil()
|
||||
{
|
||||
return &ImGui::GetIO();
|
||||
}
|
||||
@@ -3999,7 +3999,7 @@ CIMGUI_API ImGuiTableColumnSettings* ImGuiTableSettings_GetColumnSettings(ImGuiT
|
||||
{
|
||||
return self->GetColumnSettings();
|
||||
}
|
||||
CIMGUI_API ImGuiIO* igGetIOEx(ImGuiContext* ctx)
|
||||
CIMGUI_API ImGuiIO* igGetIO_ContextPtr(ImGuiContext* ctx)
|
||||
{
|
||||
return &ImGui::GetIO(ctx);
|
||||
}
|
||||
|
4
cimgui.h
4
cimgui.h
@@ -3633,7 +3633,7 @@ CIMGUI_API ImGuiContext* igCreateContext(ImFontAtlas* shared_font_atlas);
|
||||
CIMGUI_API void igDestroyContext(ImGuiContext* ctx);
|
||||
CIMGUI_API ImGuiContext* igGetCurrentContext(void);
|
||||
CIMGUI_API void igSetCurrentContext(ImGuiContext* ctx);
|
||||
CIMGUI_API ImGuiIO* igGetIO(void);
|
||||
CIMGUI_API ImGuiIO* igGetIO_Nil(void);
|
||||
CIMGUI_API ImGuiPlatformIO* igGetPlatformIO_Nil(void);
|
||||
CIMGUI_API ImGuiStyle* igGetStyle(void);
|
||||
CIMGUI_API void igNewFrame(void);
|
||||
@@ -4607,7 +4607,7 @@ CIMGUI_API void ImGuiTableColumnSettings_destroy(ImGuiTableColumnSettings* self)
|
||||
CIMGUI_API ImGuiTableSettings* ImGuiTableSettings_ImGuiTableSettings(void);
|
||||
CIMGUI_API void ImGuiTableSettings_destroy(ImGuiTableSettings* self);
|
||||
CIMGUI_API ImGuiTableColumnSettings* ImGuiTableSettings_GetColumnSettings(ImGuiTableSettings* self);
|
||||
CIMGUI_API ImGuiIO* igGetIOEx(ImGuiContext* ctx);
|
||||
CIMGUI_API ImGuiIO* igGetIO_ContextPtr(ImGuiContext* ctx);
|
||||
CIMGUI_API ImGuiPlatformIO* igGetPlatformIO_ContextPtr(ImGuiContext* ctx);
|
||||
CIMGUI_API ImGuiWindow* igGetCurrentWindowRead(void);
|
||||
CIMGUI_API ImGuiWindow* igGetCurrentWindow(void);
|
||||
|
@@ -193,6 +193,6 @@ CIMGUI_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice
|
||||
CIMGUI_API VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance);
|
||||
CIMGUI_API uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device);
|
||||
CIMGUI_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||
CIMGUI_API ImGui_ImplVulkanH_Window* ImGui_ImplVulkanH_Window_ImGui_ImplVulkanH_Window();
|
||||
CIMGUI_API ImGui_ImplVulkanH_Window* ImGui_ImplVulkanH_Window_ImGui_ImplVulkanH_Window(void);
|
||||
|
||||
#endif
|
||||
|
@@ -91,10 +91,10 @@ local cimgui_skipped = {
|
||||
--desired name
|
||||
---------------------------------------------------------------------------
|
||||
local cimgui_overloads = {
|
||||
igGetIO = {
|
||||
["()"] = "igGetIO",
|
||||
["(ImGuiContext*)"] = "igGetIOEx",
|
||||
},
|
||||
-- igGetIO = {
|
||||
-- ["()"] = "igGetIO",
|
||||
-- ["(ImGuiContext*)"] = "igGetIOEx",
|
||||
-- },
|
||||
--igPushID = {
|
||||
--["(const char*)"] = "igPushIDStr",
|
||||
--["(const char*,const char*)"] = "igPushIDRange",
|
||||
@@ -128,6 +128,7 @@ local function func_header_impl_generate(FP)
|
||||
local cimf = FP.defsT[t.cimguiname]
|
||||
local def = cimf[t.signature]
|
||||
local addcoment = def.comment or ""
|
||||
local empty = def.args:match("^%(%)") --no args
|
||||
if def.constructor then
|
||||
-- only vulkan is manually created
|
||||
assert(def.ov_cimguiname=="ImGui_ImplVulkanH_Window_ImGui_ImplVulkanH_Window" or
|
||||
@@ -139,7 +140,6 @@ local function func_header_impl_generate(FP)
|
||||
else
|
||||
|
||||
if def.stname == "" then --ImGui namespace or top level
|
||||
local empty = def.args:match("^%(%)") --no args
|
||||
table.insert(outtab,"CIMGUI_API".." "..def.ret.." "..def.ov_cimguiname..(empty and "(void)" or def.args)..";"..addcoment.."\n")
|
||||
else
|
||||
cpp2ffi.prtable(def)
|
||||
|
@@ -21987,7 +21987,7 @@
|
||||
"funcname": "GetIO",
|
||||
"location": "imgui:340",
|
||||
"namespace": "ImGui",
|
||||
"ov_cimguiname": "igGetIO",
|
||||
"ov_cimguiname": "igGetIO_Nil",
|
||||
"ret": "ImGuiIO*",
|
||||
"retref": "&",
|
||||
"signature": "()",
|
||||
@@ -22008,7 +22008,7 @@
|
||||
"funcname": "GetIO",
|
||||
"location": "imgui_internal:3238",
|
||||
"namespace": "ImGui",
|
||||
"ov_cimguiname": "igGetIOEx",
|
||||
"ov_cimguiname": "igGetIO_ContextPtr",
|
||||
"ret": "ImGuiIO*",
|
||||
"retref": "&",
|
||||
"signature": "(ImGuiContext*)",
|
||||
|
@@ -18663,7 +18663,7 @@ local t={
|
||||
funcname="GetIO",
|
||||
location="imgui:340",
|
||||
namespace="ImGui",
|
||||
ov_cimguiname="igGetIO",
|
||||
ov_cimguiname="igGetIO_Nil",
|
||||
ret="ImGuiIO*",
|
||||
retref="&",
|
||||
signature="()",
|
||||
@@ -18681,7 +18681,7 @@ local t={
|
||||
funcname="GetIO",
|
||||
location="imgui_internal:3238",
|
||||
namespace="ImGui",
|
||||
ov_cimguiname="igGetIOEx",
|
||||
ov_cimguiname="igGetIO_ContextPtr",
|
||||
ret="ImGuiIO*",
|
||||
retref="&",
|
||||
signature="(ImGuiContext*)",
|
||||
|
@@ -124,8 +124,8 @@ igGetIDWithSeed 2
|
||||
1 ImGuiID igGetIDWithSeed_Str (const char*,const char*,ImGuiID)
|
||||
2 ImGuiID igGetIDWithSeed_Int (int,ImGuiID)
|
||||
igGetIO 2
|
||||
1 ImGuiIO* igGetIO ()
|
||||
2 ImGuiIO* igGetIOEx (ImGuiContext*)
|
||||
1 ImGuiIO* igGetIO_Nil ()
|
||||
2 ImGuiIO* igGetIO_ContextPtr (ImGuiContext*)
|
||||
igGetKeyData 2
|
||||
1 ImGuiKeyData* igGetKeyData_ContextPtr (ImGuiContext*,ImGuiKey)
|
||||
2 ImGuiKeyData* igGetKeyData_Key (ImGuiKey)
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#define igDebugCheckVersionAndDataLayout igDebugCheckVersionAndDataLayout_Str
|
||||
#endif
|
||||
|
||||
#define igGetIO igGetIO_Nil
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(igDebugCheckVersionAndDataLayout(igGetVersion(), sizeof(ImGuiIO), sizeof(ImGuiStyle),
|
||||
|
Reference in New Issue
Block a user