mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-06 06:25:54 +01:00
Module support is easy to break from the header side, e.g. by a new system include, a forward-declared platform type, or an export block that misses a declaration. This adds a CMake project that builds every module whose platform library is found, alongside the header build of the same code. Linking alone doesn't show that the module behaves like the headers, so the main check is differential. 'DIFF' tests are compiled once with 'import imgui;' and once with '#include "imgui.h"'. Both builds run the same scripted frames and must print the same hash of the draw data and texture uploads (test_diff.h, compare_output.cmake). Backends that need a GPU or a display are only linked, and wgpu is only compiled. The core module and the null backend are also built for each compile-time configuration that CI builds example_null with, because IMGUI_DISABLE_* and friends change what gets exported. Presets use Clang, Ninja and 'import std'. Toolchains for cross builds belong in CMakeUserPresets.json, which is ignored along with build/.
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
// dear imgui: compile/link test for the C++20 backend modules that need a GPU/display to run:
|
|
// 'imgui.impl.opengl2', 'imgui.impl.opengl3', 'imgui.impl.glut', 'imgui.impl.glfw', 'imgui.impl.vulkan'.
|
|
// Checks that their API is exported, usable from an importer, and links (not run).
|
|
|
|
#include <GLFW/glfw3.h> // application-side platform headers
|
|
#include <vulkan/vulkan.h>
|
|
import std;
|
|
import imgui;
|
|
import imgui.impl.opengl2;
|
|
import imgui.impl.opengl3;
|
|
import imgui.impl.glut;
|
|
import imgui.impl.glfw;
|
|
import imgui.impl.vulkan;
|
|
|
|
// Exported structs are complete types
|
|
static_assert(sizeof(ImGui_ImplVulkan_InitInfo) > 0);
|
|
static_assert(sizeof(ImGui_ImplVulkanH_Window) > 0);
|
|
static_assert(sizeof(ImGui_ImplOpenGL3_RenderState) > 0);
|
|
static_assert(std::is_same_v<decltype(&ImGui_ImplGlfw_InitForOpenGL), bool (*)(GLFWwindow*, bool)>);
|
|
|
|
void RenderFrameOpenGL3(GLFWwindow* window)
|
|
{
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
ImGui_ImplOpenGL3_Init("#version 130");
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
ImGui::Render();
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
}
|
|
|
|
void RenderFrameOpenGL2()
|
|
{
|
|
ImGui_ImplGLUT_Init();
|
|
ImGui_ImplOpenGL2_Init();
|
|
ImGui_ImplOpenGL2_NewFrame();
|
|
ImGui_ImplGLUT_NewFrame();
|
|
ImGui::NewFrame();
|
|
ImGui::Render();
|
|
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
|
|
}
|
|
|
|
void RenderFrameVulkan(VkInstance instance, VkDevice device, VkQueue queue, VkCommandBuffer command_buffer)
|
|
{
|
|
ImGui_ImplVulkan_InitInfo init_info = {};
|
|
init_info.ApiVersion = VK_API_VERSION_1_3;
|
|
init_info.Instance = instance;
|
|
init_info.PhysicalDevice = ImGui_ImplVulkanH_SelectPhysicalDevice(instance);
|
|
init_info.Device = device;
|
|
init_info.Queue = queue;
|
|
init_info.MinImageCount = 2;
|
|
init_info.ImageCount = 2;
|
|
ImGui_ImplVulkan_Init(&init_info);
|
|
ImGui_ImplVulkan_NewFrame();
|
|
ImGui::NewFrame();
|
|
ImGui::Render();
|
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), command_buffer);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
return 0;
|
|
}
|