Skip to content

Commit 539c59b

Browse files
WIP gfx backend working
1 parent 29a3a06 commit 539c59b

11 files changed

Lines changed: 612 additions & 3732 deletions

extensions/pl_dear_imgui_ext.cpp

Lines changed: 570 additions & 119 deletions
Large diffs are not rendered by default.

extensions/pl_dear_imgui_ext.h

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ Index of this file:
1919
#ifndef PL_DEAR_IMGUI_EXT_H
2020
#define PL_DEAR_IMGUI_EXT_H
2121

22-
#define ImTextureID void*
23-
2422
//-----------------------------------------------------------------------------
2523
// [SECTION] APIs
2624
//-----------------------------------------------------------------------------
2725

28-
#define plDearImGuiI_version {0, 2, 0}
26+
#define plDearImGuiI_version {0, 3, 0}
2927

3028
//-----------------------------------------------------------------------------
3129
// [SECTION] includes
@@ -38,12 +36,15 @@ Index of this file:
3836
// [SECTION] forward declarations
3937
//-----------------------------------------------------------------------------
4038

39+
// basic types
40+
typedef struct _plImGuiPipelineInitInfo plImGuiPipelineInitInfo;
41+
typedef struct _plImGuiGraphicsInitInfo plImGuiGraphicsInitInfo;
42+
4143
// external (pl_graphics_ext.h)
42-
typedef union plBindGroupHandle plBindGroupHandle;
43-
typedef struct _plSwapchain plSwapchain;
44-
typedef struct _plCommandBuffer plCommandBuffer;
45-
typedef struct _plDevice plDevice;
44+
typedef struct _plCommandBuffer plCommandBuffer;
45+
typedef struct _plDevice plDevice;
4646
typedef struct _plRenderAttachmentInfo plRenderAttachmentInfo;
47+
typedef int plSampleCount;
4748

4849
//-----------------------------------------------------------------------------
4950
// [SECTION] public api
@@ -54,31 +55,43 @@ PL_API void pl_load_dear_imgui_ext (const plApiRegistryI*, bool reload);
5455
PL_API void pl_unload_dear_imgui_ext(const plApiRegistryI*, bool reload);
5556

5657
// setup/shutdown
57-
PL_API void pl_dear_imgui_initialize(plDevice*, plSwapchain*, const plRenderAttachmentInfo*);
58+
PL_API void pl_dear_imgui_initialize(plImGuiGraphicsInitInfo*);
5859
PL_API void pl_dear_imgui_cleanup (void);
5960

6061
// per frame
6162
PL_API void pl_dear_imgui_new_frame(plDevice*);
6263
PL_API void pl_dear_imgui_render (plCommandBuffer*);
6364

64-
// for using texture in Dear ImGui specifically
65-
PL_API ImTextureID pl_dear_imgui_get_texture_id_from_bindgroup(plDevice*, plBindGroupHandle);
66-
6765
//-----------------------------------------------------------------------------
6866
// [SECTION] public api struct
6967
//-----------------------------------------------------------------------------
7068

7169
typedef struct _plDearImGuiI
7270
{
7371
// setup/shutdown
74-
void (*initialize)(plDevice*, plSwapchain*, const plRenderAttachmentInfo*);
72+
void (*initialize)(plImGuiGraphicsInitInfo*);
7573
void (*cleanup) (void);
7674

7775
// per frame
7876
void (*new_frame)(plDevice*);
7977
void (*render) (plCommandBuffer*);
80-
81-
ImTextureID (*get_texture_id_from_bindgroup)(plDevice*, plBindGroupHandle);
8278
} plDearImGuiI;
8379

80+
//-----------------------------------------------------------------------------
81+
// [SECTION] structs
82+
//-----------------------------------------------------------------------------
83+
84+
typedef struct _plImGuiPipelineInitInfo
85+
{
86+
plRenderAttachmentInfo* ptRenderAttachmentInfo;
87+
plSampleCount eMsaaSamples;
88+
} plImGuiPipelineInitInfo;
89+
90+
typedef struct _plImGuiGraphicsInitInfo
91+
{
92+
plDevice* ptDevice;
93+
uint32_t uImageCount;
94+
plImGuiPipelineInitInfo tPipelineInfoMain;
95+
} plImGuiGraphicsInitInfo;
96+
8497
#endif // PL_DEAR_IMGUI_EXT_H

extensions/pl_starter_ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ pl_starter_get_staging_buffer(uint64_t uSize, plBufferHandle* ptHandleOut, const
12941294
}
12951295

12961296
const plBufferDesc tStagingBufferDesc = {
1297-
.eUsage = PL_BUFFER_USAGE_TRANSFER | PL_BUFFER_USAGE_STORAGE | PL_BUFFER_USAGE_UNIFORM,
1297+
.eUsage = PL_BUFFER_USAGE_TRANSFER | PL_BUFFER_USAGE_STORAGE | PL_BUFFER_USAGE_UNIFORM | PL_BUFFER_USAGE_INDEX | PL_BUFFER_USAGE_VERTEX,
12981298
.szByteSize = uSize,
12991299
.pcDebugName = pcName
13001300
};

internal/demo/demo.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
323323

324324
pl__find_models(ptAppData);
325325

326-
plRenderAttachmentInfo tRenderInfo = {};
327-
gptStarter->get_render_attachment_info(&tRenderInfo);
328-
gptDearImGui->initialize(ptAppData->ptDevice, gptStarter->get_swapchain(), &tRenderInfo);
326+
gptDearImGui->initialize(nullptr);
329327
// ImGui::GetIO().ConfigFlags &= ~ImGuiBackendFlags_PlatformHasViewports;
330328
ImPlot::SetCurrentContext((ImPlotContext*)ptDataRegistry->get_data("implot"));
331329
ImGuiIO& tImGuiIO = ImGui::GetIO();
@@ -713,7 +711,7 @@ pl_app_update(plAppData* ptAppData)
713711

714712
plVec2 tUV = {};
715713
plBindGroupHandle tTextureHandle = gptRenderer->get_view_color_bind_group(ptAppData->ptView, &tUV);
716-
ImTextureRef tTexture = ImTextureRef(gptDearImGui->get_texture_id_from_bindgroup(ptAppData->ptDevice, tTextureHandle));
714+
ImTextureRef tTexture = ImTextureRef(tTextureHandle.uData);
717715
ImGui::Image(tTexture, tContextSize, ImVec2(0, 0), ImVec2(tUV.x, tUV.y));
718716

719717
}
@@ -730,7 +728,7 @@ pl_app_update(plAppData* ptAppData)
730728
ImVec2 tContextSize = ImGui::GetContentRegionAvail();
731729
gptCamera->set_viewport((plCamera*)gptEcs->get_component(ptAppData->ptCompLibrary, gptCameraEcs->get_ecs_type_key(), ptAppData->tSecondaryCamera), tContextSize.x, tContextSize.y);
732730

733-
ImTextureRef tTexture = ImTextureRef(gptDearImGui->get_texture_id_from_bindgroup(ptAppData->ptDevice, tTextureHandle));
731+
ImTextureRef tTexture = ImTextureRef(tTextureHandle.uData);
734732
ImGui::Image(tTexture, tContextSize, ImVec2(0, 0), ImVec2(tUV.x, tUV.y));
735733
}
736734
ImGui::End();

src/pl_main_glfw.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int main(int argc, char *argv[])
331331
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
332332
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
333333
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
334-
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
334+
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
335335
//io.ConfigViewportsNoAutoMerge = true;
336336
//io.ConfigViewportsNoTaskBarIcon = true;
337337

@@ -754,13 +754,13 @@ pl_create_window(plWindowDesc tDesc, plWindow** pptWindowOut)
754754
glfwSetWindowIconifyCallback(ptGlfwWindow, pl_glfw_window_iconified_callback);
755755
glfwSetWindowCloseCallback(ptGlfwWindow, pl_glfw_window_close_callback);
756756

757-
#ifdef PL_METAL_BACKEND
758-
if(pl_sb_size(gsbtWindows) == 0)
757+
// #ifdef PL_METAL_BACKEND
758+
// if(pl_sb_size(gsbtWindows) == 0)
759759
ImGui_ImplGlfw_InitForOther(ptGlfwWindow, true);
760-
#else
761-
if(pl_sb_size(gsbtWindows) == 0)
762-
ImGui_ImplGlfw_InitForVulkan(ptGlfwWindow, true);
763-
#endif
760+
// #else
761+
// if(pl_sb_size(gsbtWindows) == 0)
762+
// ImGui_ImplGlfw_InitForVulkan(ptGlfwWindow, true);
763+
// #endif
764764

765765
#ifdef _WIN32
766766
HWND tHandle = glfwGetWin32Window(ptGlfwWindow);

thirdparty/imgui/imconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#pragma once
1616

17+
#include <stdint.h>
18+
#define ImTextureID uint32_t
19+
#define ImDrawIdx uint32_t
20+
1721
//---- Define assertion handler. Defaults to calling assert().
1822
// - If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
1923
// - Compiling with NDEBUG will usually strip out assert() to nothing, which is NOT recommended because we use asserts to notify of programmer mistakes.

0 commit comments

Comments
 (0)