Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ImGui to 1.90.4 #260

Merged
merged 15 commits into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions deps/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -29,9 +29,9 @@ if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/")
target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glfw/include/")
target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glad/include/")

target_link_libraries(imgui PRIVATE glfw)

if(APPLE)
# On macOS, get openGL & friends from Frameworks; do not use GLAD at all

@@ -41,7 +41,7 @@ if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")

# Apple is playing hardball and deprecating openGL... we'll cross that bridge when we come to it
# Silence warnings about openGL deprecation
add_definitions(-DGL_SILENCE_DEPRECATION)
add_definitions(-DGL_SILENCE_DEPRECATION)
find_library(opengl_library OpenGL)
target_link_libraries(imgui PRIVATE ${opengl_library})
else()
@@ -58,7 +58,7 @@ elseif("${POLYSCOPE_BACKEND_OPENGL_MOCK}")
add_definitions(-DIMGUI_DISABLE_WIN32_FUNCTIONS)
add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS)
add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)

set(SRCS imgui/imgui.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/imgui_demo.cpp)

add_library(
@@ -71,5 +71,6 @@ elseif("${POLYSCOPE_BACKEND_OPENGL_MOCK}")
endif()


target_compile_features(imgui PUBLIC cxx_std_11)

set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
2 changes: 1 addition & 1 deletion deps/imgui/imgui
Submodule imgui updated 189 files
3 changes: 3 additions & 0 deletions examples/demo-app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -69,6 +69,9 @@ endif()
# Add polyscope
add_subdirectory(../../ "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")

# Catch the usage of obsolete functions in imgui
target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS)

# Create an executable
add_executable(
polyscopedemo
4 changes: 2 additions & 2 deletions include/polyscope/render/opengl/gl_engine.h
Original file line number Diff line number Diff line change
@@ -318,13 +318,13 @@ class GLShaderProgram : public ShaderProgram {
bool hasAttribute(std::string name) override;
bool attributeIsSet(std::string name) override;
std::shared_ptr<AttributeBuffer> getAttributeBuffer(std::string name) override;
void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer) override;
void setAttribute(std::string name, std::shared_ptr<AttributeBuffer> externalBuffer) override;
void setAttribute(std::string name, const std::vector<glm::vec2>& data) override;
void setAttribute(std::string name, const std::vector<glm::vec3>& data) override;
void setAttribute(std::string name, const std::vector<glm::vec4>& data) override;
void setAttribute(std::string name, const std::vector<float>& data) override;
void setAttribute(std::string name, const std::vector<double>& data) override;
void setAttribute(std::string name, const std::vector<int32_t>& data) override;
void setAttribute(std::string name, const std::vector<int32_t>& data) override;
void setAttribute(std::string name, const std::vector<uint32_t>& data) override;
// clang-format on

2 changes: 1 addition & 1 deletion src/group.cpp
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ void Group::buildUI() {

// Set this treenode to open if there's children
if (childrenGroups.size() > 0 || childrenStructures.size() > 0) {
ImGui::SetNextTreeNodeOpen(true, ImGuiCond_Once);
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
}


4 changes: 2 additions & 2 deletions src/messages.cpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ void buildErrorUI(std::string message, bool fatal) {
}

// Make a button
if (ImGui::Button("My bad.", ImVec2(buttonWidth, 0)) || ImGui::IsKeyPressed((int)' ')) {
if (ImGui::Button("My bad.", ImVec2(buttonWidth, 0)) || ImGui::IsKeyPressed(ImGuiKey_Space)) {
popContext();
ImGui::CloseCurrentPopup();
}
@@ -179,7 +179,7 @@ void buildWarningUI(std::string warningBaseString, std::string warningDetailStri
}

// Make a button
if (ImGui::Button("This is fine.", ImVec2(buttonWidth, 0)) || ImGui::IsKeyPressed((int)' ')) {
if (ImGui::Button("This is fine.", ImVec2(buttonWidth, 0)) || ImGui::IsKeyPressed(ImGuiKey_Space)) {
ImGui::CloseCurrentPopup();
popContext();
}
45 changes: 27 additions & 18 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
@@ -177,17 +177,22 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {

// Create a new context and push it on to the stack
ImGuiContext* newContext = ImGui::CreateContext(render::engine->getImGuiGlobalFontAtlas());
ImGuiIO& oldIO = ImGui::GetIO(); // used to copy below, see note
ImGuiIO& oldIO = ImGui::GetIO(); // used to GLFW + OpenGL data to the new IO object
#ifdef IMGUI_HAS_DOCK
ImGuiPlatformIO& oldPlatformIO = ImGui::GetPlatformIO();
#endif
ImGui::SetCurrentContext(newContext);
#ifdef IMGUI_HAS_DOCK
// Propagate GLFW window handle to new context
ImGui::GetMainViewport()->PlatformHandle = oldPlatformIO.Viewports[0]->PlatformHandle;
#endif
ImGui::GetIO().BackendPlatformUserData = oldIO.BackendPlatformUserData;
ImGui::GetIO().BackendRendererUserData = oldIO.BackendRendererUserData;

if (options::configureImGuiStyleCallback) {
options::configureImGuiStyleCallback();
}

ImGui::GetIO() = oldIO; // Copy all of the old IO values to new. With ImGUI 1.76 (and some previous versions), this
// was necessary to fix a bug where keys like delete, etc would break in subcontexts. The
// problem was that the key mappings (e.g. GLFW_KEY_BACKSPACE --> ImGuiKey_Backspace) need to
// be populated in io.KeyMap, and these entries would get lost on creating a new context.
contextStack.push_back(ContextEntry{newContext, callbackFunction, drawDefaultUI});

if (contextStack.size() > 50) {
@@ -224,8 +229,11 @@ void pushContext(std::function<void()> callbackFunction, bool drawDefaultUI) {
}
}

oldIO = ImGui::GetIO(); // Copy new IO values to old. I haven't encountered anything that strictly requires this, but
// it feels like we should mirror the behavior from pushing.
// Workaround overzealous ImGui assertion before destroying any inner context
// https://github.com/ocornut/imgui/pull/7175
ImGui::SetCurrentContext(newContext);
ImGui::GetIO().BackendPlatformUserData = nullptr;
ImGui::GetIO().BackendRendererUserData = nullptr;

ImGui::DestroyContext(newContext);

@@ -585,18 +593,18 @@ void buildPolyscopeGui() {

// clang-format off
ImGui::Begin("Controls", NULL, ImGuiWindowFlags_NoTitleBar);
ImGui::TextUnformatted("View Navigation:");
ImGui::TextUnformatted("View Navigation:");
ImGui::TextUnformatted(" Rotate: [left click drag]");
ImGui::TextUnformatted(" Translate: [shift] + [left click drag] OR [right click drag]");
ImGui::TextUnformatted(" Zoom: [scroll] OR [ctrl] + [shift] + [left click drag]");
ImGui::TextUnformatted(" Use [ctrl-c] and [ctrl-v] to save and restore camera poses");
ImGui::TextUnformatted(" via the clipboard.");
ImGui::TextUnformatted("\nMenu Navigation:");
ImGui::TextUnformatted("\nMenu Navigation:");
ImGui::TextUnformatted(" Menu headers with a '>' can be clicked to collapse and expand.");
ImGui::TextUnformatted(" Use [ctrl] + [left click] to manually enter any numeric value");
ImGui::TextUnformatted(" via the keyboard.");
ImGui::TextUnformatted(" Press [space] to dismiss popup dialogs.");
ImGui::TextUnformatted("\nSelection:");
ImGui::TextUnformatted("\nSelection:");
ImGui::TextUnformatted(" Select elements of a structure with [left click]. Data from");
ImGui::TextUnformatted(" that element will be shown on the right. Use [right click]");
ImGui::TextUnformatted(" to clear the selection.");
@@ -611,7 +619,7 @@ void buildPolyscopeGui() {
render::engine->buildEngineGui();

// Render options tree
ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Render")) {

// fps
@@ -632,7 +640,7 @@ void buildPolyscopeGui() {
ImGui::TreePop();
}

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Debug")) {

if (ImGui::Button("Force refresh")) {
@@ -693,7 +701,7 @@ void buildStructureGui() {
// identically-named labels

// Build the structure's UI
ImGui::SetNextTreeNodeOpen(structureMap.size() > 0, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(structureMap.size() > 0, ImGuiCond_FirstUseEver);
if (ImGui::CollapsingHeader((catName + " (" + std::to_string(structureMap.size()) + ")").c_str())) {
// Draw shared GUI elements for all instances of the structure
if (structureMap.size() > 0) {
@@ -702,8 +710,8 @@ void buildStructureGui() {

int32_t skipCount = 0;
for (auto& x : structureMap) {
ImGui::SetNextTreeNodeOpen(structureMap.size() <= 8,
ImGuiCond_FirstUseEver); // closed by default if more than 8
ImGui::SetNextItemOpen(structureMap.size() <= 8,
ImGuiCond_FirstUseEver); // closed by default if more than 8

if (structuresToSkip.find(x.second.get()) != structuresToSkip.end()) {
skipCount++;
@@ -785,6 +793,10 @@ void draw(bool withUI, bool withContextCallback) {

if (withUI) {
render::engine->ImGuiNewFrame();

processInputEvents();
view::updateFlight();
showDelayedWarnings();
}

// Build the GUI components
@@ -855,9 +867,6 @@ void mainLoopIteration() {

// Process UI events
render::engine->pollEvents();
processInputEvents();
view::updateFlight();
showDelayedWarnings();

// Housekeeping
purgeWidgets();
16 changes: 8 additions & 8 deletions src/render/engine.cpp
Original file line number Diff line number Diff line change
@@ -272,7 +272,7 @@ ShaderProgram::ShaderProgram(DrawMode dm) : drawMode(dm), uniqueID(render::engin

void Engine::buildEngineGui() {

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Appearance")) {

// == Display
@@ -292,7 +292,7 @@ void Engine::buildEngineGui() {
ImGui::ColorEdit4("background color", (float*)&view::bgColor, ImGuiColorEditFlags_NoInputs);

// == Transparency
ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Transparency")) {

if (ImGui::BeginCombo("Mode", modeName(transparencyMode).c_str())) {
@@ -332,7 +332,7 @@ void Engine::buildEngineGui() {
// == Ground plane
groundPlane.buildGui();

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Tone Mapping")) {
ImGui::SliderFloat("exposure", &exposure, 0.1, 2.0, "%.3f",
ImGuiSliderFlags_Logarithmic | ImGuiSliderFlags_NoRoundToFormat);
@@ -344,7 +344,7 @@ void Engine::buildEngineGui() {
}

// == Anti-aliasing
ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Anti-Aliasing")) {
if (ImGui::InputInt("SSAA (pretty)", &ssaaFactor, 1)) {
ssaaFactor = std::min(ssaaFactor, 4);
@@ -356,10 +356,10 @@ void Engine::buildEngineGui() {
}

// == Materials
ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Materials")) {

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Load material")) {

size_t buffLen = 512;
@@ -391,7 +391,7 @@ void Engine::buildEngineGui() {
// == Color maps
if (ImGui::TreeNode("Color Maps")) {

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Load color map")) {

size_t buffLen = 512;
@@ -906,7 +906,7 @@ void Engine::loadDefaultMaterial(std::string name) {
newMaterial->rules = {"LIGHT_PASSTHRU", "INVERSE_TONEMAP"};
newMaterial->setUniforms = [&](ShaderProgram& p){ setTonemapUniforms(p); };

}
}
else if(name == "mud") {
newMaterial->supportsRGB = false;
for(int i = 0; i < 4; i++) {buff[i] = &bindata_mud[0]; buffSize[i] = bindata_mud.size();}
4 changes: 2 additions & 2 deletions src/render/ground_plane.cpp
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ void GroundPlane::populateGroundPlaneGeometry() {
glm::vec4 v2{0., 0., 0., 0.}; v2[(iP+1)%3] = sign * 1.;
glm::vec4 v3{0., 0., 0., 0.}; v3[(iP+2)%3] = sign *-1.;
glm::vec4 v4{0., 0., 0., 0.}; v4[(iP+1)%3] = sign *-1.;

std::vector<glm::vec4> positions = {
cVert, v2, v1,
cVert, v3, v2,
@@ -387,7 +387,7 @@ void GroundPlane::buildGui() {
return "";
};

ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (ImGui::TreeNode("Ground Plane")) {

ImGui::PushItemWidth(160);
22 changes: 11 additions & 11 deletions src/render/opengl/gl_engine.cpp
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ inline GLenum formatF(const TextureFormat& x) {
case TextureFormat::RGB8: return GL_RGB;
case TextureFormat::RGBA8: return GL_RGBA;
case TextureFormat::RG16F: return GL_RG;
case TextureFormat::RGB16F: return GL_RGB;
case TextureFormat::RGB16F: return GL_RGB;
case TextureFormat::RGBA16F: return GL_RGBA;
case TextureFormat::R32F: return GL_RED;
case TextureFormat::R16F: return GL_RED;
@@ -117,7 +117,7 @@ inline GLenum native(const ShaderStageType& x) {
inline GLenum native(const RenderBufferType& x) {
switch (x) {
case RenderBufferType::ColorAlpha: return GL_RGBA;
case RenderBufferType::Color: return GL_RGB;
case RenderBufferType::Color: return GL_RGB;
case RenderBufferType::Depth: return GL_DEPTH_COMPONENT;
case RenderBufferType::Float4: return GL_RGBA32F;
}
@@ -2308,17 +2308,17 @@ bool GLEngine::windowRequestsClose() {
void GLEngine::pollEvents() { glfwPollEvents(); }

bool GLEngine::isKeyPressed(char c) {
if (c >= '0' && c <= '9') return ImGui::IsKeyPressed(GLFW_KEY_0 + (c - '0'));
if (c >= 'a' && c <= 'z') return ImGui::IsKeyPressed(GLFW_KEY_A + (c - 'a'));
if (c >= 'A' && c <= 'Z') return ImGui::IsKeyPressed(GLFW_KEY_A + (c - 'A'));
if (c >= '0' && c <= '9') return ImGui::IsKeyPressed(static_cast<ImGuiKey>(ImGuiKey_0 + (c - '0')));
if (c >= 'a' && c <= 'z') return ImGui::IsKeyPressed(static_cast<ImGuiKey>(ImGuiKey_A + (c - 'a')));
if (c >= 'A' && c <= 'Z') return ImGui::IsKeyPressed(static_cast<ImGuiKey>(ImGuiKey_A + (c - 'A')));
exception("keyPressed only supports 0-9, a-z, A-Z");
return false;
}

int GLEngine::getKeyCode(char c) {
if (c >= '0' && c <= '9') return static_cast<int>(GLFW_KEY_0) + (c - '0');
if (c >= 'a' && c <= 'z') return static_cast<int>(GLFW_KEY_A) + (c - 'a');
if (c >= 'A' && c <= 'Z') return static_cast<int>(GLFW_KEY_A) + (c - 'A');
if (c >= '0' && c <= '9') return static_cast<int>(ImGuiKey_0) + (c - '0');
if (c >= 'a' && c <= 'z') return static_cast<int>(ImGuiKey_A) + (c - 'a');
if (c >= 'A' && c <= 'Z') return static_cast<int>(ImGuiKey_A) + (c - 'A');
exception("getKeyCode only supports 0-9, a-z, A-Z");
return -1;
}
@@ -2699,12 +2699,12 @@ void GLEngine::populateDefaultShadersAndRules() {
registerShaderRule("DOWNSAMPLE_RESOLVE_2", DOWNSAMPLE_RESOLVE_2);
registerShaderRule("DOWNSAMPLE_RESOLVE_3", DOWNSAMPLE_RESOLVE_3);
registerShaderRule("DOWNSAMPLE_RESOLVE_4", DOWNSAMPLE_RESOLVE_4);

registerShaderRule("TRANSPARENCY_STRUCTURE", TRANSPARENCY_STRUCTURE);
registerShaderRule("TRANSPARENCY_RESOLVE_SIMPLE", TRANSPARENCY_RESOLVE_SIMPLE);
registerShaderRule("TRANSPARENCY_PEEL_STRUCTURE", TRANSPARENCY_PEEL_STRUCTURE);
registerShaderRule("TRANSPARENCY_PEEL_GROUND", TRANSPARENCY_PEEL_GROUND);

registerShaderRule("GENERATE_VIEW_POS", GENERATE_VIEW_POS);
registerShaderRule("COMPUTE_SHADE_NORMAL_FROM_POSITION", COMPUTE_SHADE_NORMAL_FROM_POSITION);
registerShaderRule("PREMULTIPLY_LIT_COLOR", PREMULTIPLY_LIT_COLOR);
@@ -2726,7 +2726,7 @@ void GLEngine::populateDefaultShadersAndRules() {
registerShaderRule("ISOLINE_STRIPE_VALUECOLOR", ISOLINE_STRIPE_VALUECOLOR);
registerShaderRule("CHECKER_VALUE2COLOR", CHECKER_VALUE2COLOR);
registerShaderRule("INVERSE_TONEMAP", INVERSE_TONEMAP);

// Texture and image things
registerShaderRule("TEXTURE_ORIGIN_UPPERLEFT", TEXTURE_ORIGIN_UPPERLEFT);
registerShaderRule("TEXTURE_ORIGIN_LOWERLEFT", TEXTURE_ORIGIN_LOWERLEFT);
8 changes: 4 additions & 4 deletions src/slice_plane.cpp
Original file line number Diff line number Diff line change
@@ -40,9 +40,9 @@ void removeLastSceneSlicePlane() {
void buildSlicePlaneGUI() {


ImGui::SetNextTreeNodeOpen(false, ImGuiCond_FirstUseEver);
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
if (openSlicePlaneMenu) {
ImGui::SetNextTreeNodeOpen(true);
ImGui::SetNextItemOpen(true);
openSlicePlaneMenu = false;
}
if (ImGui::TreeNode("Slice Planes")) {
@@ -158,10 +158,10 @@ void SlicePlane::createVolumeSliceProgram() {
VolumeMesh* meshToInspect = polyscope::getVolumeMesh(inspectedMeshName);

// clang-format off
volumeInspectProgram = render::engine->requestShader( "SLICE_TETS",
volumeInspectProgram = render::engine->requestShader( "SLICE_TETS",
render::engine->addMaterialRules(meshToInspect->getMaterial(),
meshToInspect->addVolumeMeshRules(
{"SLICE_TETS_BASECOLOR_SHADE"},
{"SLICE_TETS_BASECOLOR_SHADE"},
true, true)
)
);
Loading