Skip to content

Commit

Permalink
Update ImGui to 1.90.4 (#260)
Browse files Browse the repository at this point in the history
* Update ImGui to 1.90.4

* Disable obsolete ImGui function + use IsKeyDown function.

* Set ImGui context with each frame.

* Remove debugging assert.

* Set ImGui std to C++11.

* Only disable obsolete imgui function for toplevel polyscope.

* Rollback set context change.

* Set first context.

* Make it work with ImGui docking branch.

* Workaround overzealous ImGui assertion.

* remove cmake toplevel project check, add IMGUI_DISABLE_OBSOLETE to test and demo apps

* Try a different fix for ImGui context.

* Copy data outside the ifdef.

* move event loop processing, scroll events were getting lost

* run formatter

---------

Co-authored-by: Nicholas Sharp <[email protected]>
  • Loading branch information
jdumas and nmwsharp authored Mar 14, 2024
1 parent 96d42e4 commit 153fe8a
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 65 deletions.
9 changes: 5 additions & 4 deletions deps/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand 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()
Expand All @@ -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(
Expand All @@ -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
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/polyscope/render/opengl/gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
45 changes: 27 additions & 18 deletions src/polyscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -584,18 +592,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.");
Expand All @@ -610,7 +618,7 @@ void buildPolyscopeGui() {
render::engine->buildEngineGui();

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

// fps
Expand All @@ -631,7 +639,7 @@ void buildPolyscopeGui() {
ImGui::TreePop();
}

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

if (ImGui::Button("Force refresh")) {
Expand Down Expand Up @@ -692,7 +700,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) {
Expand All @@ -701,8 +709,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++;
Expand Down Expand Up @@ -784,6 +792,10 @@ void draw(bool withUI, bool withContextCallback) {

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

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

// Build the GUI components
Expand Down Expand Up @@ -854,9 +866,6 @@ void mainLoopIteration() {

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

// Housekeeping
purgeWidgets();
Expand Down
16 changes: 8 additions & 8 deletions src/render/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();}
Expand Down
4 changes: 2 additions & 2 deletions src/render/ground_plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/render/opengl/gl_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/slice_plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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)
)
);
Expand Down
Loading

0 comments on commit 153fe8a

Please sign in to comment.