Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ endif()
if(NOT TARGET stb)
add_subdirectory(stb)
endif()

## IconFontCppHeaders
if(NOT TARGET IconFontCppHeaders)
add_subdirectory(IconFontCppHeaders)
endif()
3 changes: 3 additions & 0 deletions deps/IconFontCppHeaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(IconFontCppHeaders INTERFACE)

target_include_directories(IconFontCppHeaders INTERFACE "include")
246 changes: 246 additions & 0 deletions deps/IconFontCppHeaders/README.md

Large diffs are not rendered by default.

1,661 changes: 1,661 additions & 0 deletions deps/IconFontCppHeaders/include/IconFontCppHeaders/IconsLucide.h

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions deps/IconFontCppHeaders/licence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Copyright (c) 2017 Juliette Foucaut and Doug Binks

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
100 changes: 62 additions & 38 deletions deps/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,63 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STR
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything")
endif()
endif()



# imgui sources
list(APPEND SRCS
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_tables.cpp
imgui/imgui_widgets.cpp
imgui/imgui_demo.cpp
)

# implot sources
list(APPEND SRCS
implot/implot.cpp
implot/implot_items.cpp
)

# imguizmo sources
list(APPEND SRCS
ImGuizmo/ImGuizmo.cpp
)


# Add per-backend sources
if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")

# imgui sources
list(APPEND SRCS
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_tables.cpp
imgui/imgui_widgets.cpp
imgui/imgui_demo.cpp
imgui/backends/imgui_impl_glfw.cpp
imgui/backends/imgui_impl_opengl3.cpp
)
imgui/backends/imgui_impl_opengl3.cpp
imgui/backends/imgui_impl_glfw.cpp
)
endif()
if("${POLYSCOPE_BACKEND_OPENGL3_EGL}")
# this backend supports linux only

# implot sources
list(APPEND SRCS
implot/implot.cpp
implot/implot_items.cpp
imgui/backends/imgui_impl_opengl3.cpp
)

# imguizmosources
endif()
if("${POLYSCOPE_BACKEND_OPENGL_MOCK}")

list(APPEND SRCS
ImGuizmo/ImGuizmo.cpp
imgui/backends/imgui_impl_null.cpp
)
endif()


add_library(
imgui
${SRCS}
)
add_library(imgui ${SRCS})
target_compile_features(imgui PUBLIC cxx_std_11)
set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

# Per-backend settings
if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")

target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/custom_backends/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/implot/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ImGuizmo/")
target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glad/include/")

target_link_libraries(imgui PRIVATE glfw)

if(APPLE)
Expand All @@ -71,27 +92,30 @@ if("${POLYSCOPE_BACKEND_OPENGL3_GLFW}")
add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui PRIVATE glad)
endif()
endif()

elseif("${POLYSCOPE_BACKEND_OPENGL_MOCK}")

# Disable every platform-specific thing I can find in imgui
add_definitions(-DIMGUI_DISABLE_OSX_FUNCTIONS)
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(
imgui
${SRCS}
)
if("${POLYSCOPE_BACKEND_OPENGL3_EGL}")
# this backend supports linux only

target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/implot/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ImGuizmo/")
target_include_directories(imgui PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../glad/include/")

# linux only
add_definitions(-DIMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui PRIVATE glad)
endif()

if("${POLYSCOPE_BACKEND_OPENGL_MOCK}")

target_compile_features(imgui PUBLIC cxx_std_11)
# Disable every platform-specific thing I can find in imgui
# add_definitions(-DIMGUI_DISABLE_OSX_FUNCTIONS)
# add_definitions(-DIMGUI_DISABLE_WIN32_FUNCTIONS)
# add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS)
# add_definitions(-DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)

set_target_properties(imgui PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/custom_backends/")

endif()
2 changes: 1 addition & 1 deletion deps/imgui/imgui
Submodule imgui updated 144 files
2 changes: 1 addition & 1 deletion include/polyscope/imgui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace polyscope {

// Default implementations of callbacks to set ImGui style / fonts
void configureImGuiStyle();
std::tuple<ImFontAtlas*, ImFont*, ImFont*> prepareImGuiFonts();
std::tuple<ImFont*, ImFont*> loadBaseFonts(ImFontAtlas* fontAtlas);

} // namespace polyscope
3 changes: 3 additions & 0 deletions include/polyscope/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace internal {
// Get a unique identifier
uint64_t getNextUniqueID();

// How many layers deep in the polyscope context stack are we
extern int contextStackSize;

// track various fire-once warnings
extern bool& pointCloudEfficiencyWarningReported;

Expand Down
10 changes: 5 additions & 5 deletions include/polyscope/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ extern bool doDefaultMouseInteraction;
// may assign your own function to create custom styles. If this callback is null, the default ImGui style will be used.
extern std::function<void()> configureImGuiStyleCallback;

// A callback function which will be invoked exactly once during initialization to construct a font atlas for ImGui to
// use. The callback should return a tuple of three pointers: a newly created global shared font atlas, a regular font,
// and a mono font. By default, this is set to invoke prepareImGuiFonts() from Polyscope's imgui_config.cpp, but you may
// assign your own function to create custom styles. If this callback is null, default fonts will be used.
extern std::function<std::tuple<ImFontAtlas*, ImFont*, ImFont*>()> prepareImGuiFontsCallback;
// A callback function which will be invoked exactly once during initialization to add fonts to a font atlas for ImGui
// to use. The callback should return two pointers: a regular font and a mono font. By default, this is set to invoke
// loadBaseFonts() from Polyscope's imgui_config.cpp, but you may assign your own function to create custom styles. If
// this callback is null, default fonts will be used.
extern std::function<std::tuple<ImFont*, ImFont*>(ImFontAtlas*)> prepareImGuiFontsCallback;

// === Backend and low-level options

Expand Down
14 changes: 12 additions & 2 deletions include/polyscope/render/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ class Engine {

// NOTE: the imgui backend depends on the window manager (e.g. GLFW), so these must be implemented by the lowest-level
// concrete engine implementation
virtual void initializeImGui() = 0;
virtual void createNewImGuiContext() = 0;
virtual void updateImGuiContext(ImGuiContext* oldContext, ImGuiIO* oldIO, ImGuiContext* newContext, ImGuiIO* newIO) {}
virtual void shutdownImGui() = 0;
virtual void ImGuiNewFrame() = 0;
virtual void ImGuiRender() = 0;
Expand Down Expand Up @@ -633,10 +634,14 @@ class Engine {
bool useAltDisplayBuffer = false; // if true, push final render results offscreen to the alt buffer instead

// Internal windowing and engine details
FrameBuffer* currRenderFramebuffer = nullptr;

// ImGui and Fonts
virtual void configureImGui() {}; // generates font things
ImFontAtlas* getSharedFontAtlas();
ImFont* regularFont = nullptr;
ImFont* monoFont = nullptr;
FrameBuffer* currRenderFramebuffer = nullptr;


// Manage some resources that we need to preserve because ImGui will use them to render at the end of the frame
// This matters if we delete something mid-frame but have already passed a pointer to a texture for imgui to render,
Expand All @@ -661,7 +666,12 @@ class Engine {
int currLightingSampleLevel = -1;
TransparencyMode currLightingTransparencyMode = TransparencyMode::None;

// ImGui/fonts
bool imguiInitialized = false;
ImFontAtlas* sharedFontAtlas;

// Helpers
virtual void freeAllOwnedResources(); // child callers should call parent
void loadDefaultMaterials();
void loadDefaultMaterial(std::string name);
std::shared_ptr<TextureBuffer> loadMaterialTexture(float* data, int width, int height);
Expand Down
2 changes: 1 addition & 1 deletion include/polyscope/render/ground_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GroundPlane {

void buildGui();
void prepare(); // does any and all setup work / allocations / etc, called automatically when drawing after a change

void freeAllOwnedResources();

// == Appearance Parameters
// These all now live in polyscope::options
Expand Down
4 changes: 3 additions & 1 deletion include/polyscope/render/mock_opengl/mock_gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ class MockGLEngine : public Engine {
void setClipboardText(std::string text) override;

// ImGui
void initializeImGui() override;
void createNewImGuiContext() override;
void updateImGuiContext(ImGuiContext* oldContext, ImGuiIO* oldIO, ImGuiContext* newContext, ImGuiIO* newIO) override;
void configureImGui() override;
void shutdownImGui() override;
void ImGuiNewFrame() override;
Expand Down Expand Up @@ -413,6 +414,7 @@ class MockGLEngine : public Engine {

protected:
// Helpers
virtual void freeAllOwnedResources() override;
virtual void createSlicePlaneFliterRule(std::string name) override;

// Shader program & rule caches
Expand Down
1 change: 1 addition & 0 deletions include/polyscope/render/opengl/gl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class GLEngine : public Engine {

protected:
// Helpers
virtual void freeAllOwnedResources() override;
virtual void createSlicePlaneFliterRule(std::string name) override;

// Shader program & rule caches
Expand Down
3 changes: 2 additions & 1 deletion include/polyscope/render/opengl/gl_engine_egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class GLEngineEGL : public GLEngine {

// === ImGui

void initializeImGui() override;
void createNewImGuiContext() override;
void updateImGuiContext(ImGuiContext* oldContext, ImGuiIO* oldIO, ImGuiContext* newContext, ImGuiIO* newIO) override;
void configureImGui() override;
void shutdownImGui() override;
void ImGuiNewFrame() override;
Expand Down
3 changes: 2 additions & 1 deletion include/polyscope/render/opengl/gl_engine_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class GLEngineGLFW : public GLEngine {

// === ImGui

void initializeImGui() override;
void createNewImGuiContext() override;
void updateImGuiContext(ImGuiContext* oldContext, ImGuiIO* oldIO, ImGuiContext* newContext, ImGuiIO* newIO) override;
void shutdownImGui() override;
void ImGuiNewFrame() override;
void ImGuiRender() override;
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ SET(SRCS
## Embedded binary data
render/bindata/bindata_font_lato_regular.cpp
render/bindata/bindata_font_cousine_regular.cpp
render/bindata/bindata_font_lucide_icons.cpp
render/bindata/concrete_seamless.cpp
render/bindata/bindata_clay.cpp
render/bindata/bindata_wax.cpp
Expand Down Expand Up @@ -382,3 +383,6 @@ target_include_directories(polyscope PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../incl
# Link settings
target_link_libraries(polyscope PUBLIC imgui glm::glm)
target_link_libraries(polyscope PRIVATE "${BACKEND_LIBS}" stb nlohmann_json::nlohmann_json MarchingCube::MarchingCube)

# For now, make this private, until we are sure we want to commit to it. We may expose it as public in the future.
target_link_libraries(polyscope PRIVATE IconFontCppHeaders)
56 changes: 27 additions & 29 deletions src/imgui_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ unsigned int getCousineRegularCompressedSize();
const unsigned int* getCousineRegularCompressedData();
unsigned int getLatoRegularCompressedSize();
const unsigned int* getLatoRegularCompressedData();
unsigned int getLucideIconsCompressedSize();
const unsigned char* getLucideIconsCompressedData();
} // namespace render

void configureImGuiStyle() {
Expand All @@ -27,6 +29,7 @@ void configureImGuiStyle() {
style->ScrollbarSize = 20;
style->ScaleAllSizes(options::uiScale);

style->FontScaleMain = options::uiScale;

// Colors
ImVec4* colors = style->Colors;
Expand Down Expand Up @@ -76,45 +79,40 @@ void configureImGuiStyle() {
}


std::tuple<ImFontAtlas*, ImFont*, ImFont*> prepareImGuiFonts() {
std::tuple<ImFont*, ImFont*> loadBaseFonts(ImFontAtlas* fontAtlas) {

ImGuiIO& io = ImGui::GetIO();

ImVec2 windowSize{static_cast<float>(view::windowWidth), static_cast<float>(view::windowHeight)};
ImVec2 bufferSize{static_cast<float>(view::bufferWidth), static_cast<float>(view::bufferHeight)};
ImVec2 imguiCoordScale = {bufferSize.x / windowSize.x, bufferSize.y / windowSize.y};

// outputs
ImFontAtlas* fontAtlas = nullptr; // right now this is unused by the caller, but I don't want to change
// this callback signature until I'm more confident about how this
// should work. (And it might be changing in an upcoming imgui version)
ImFont* regularFont;
ImFont* monoFont;

float fontSize = 16.0 * options::uiScale;
fontSize = std::max(1.0f, std::roundf(fontSize));
float fontSize = 18.0;

{ // add regular font
ImFontConfig config;
config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y);
regularFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(),
render::getLatoRegularCompressedSize(),
options::uiScale * 18.0f, &config);
}
// add regular font
regularFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(),
render::getLatoRegularCompressedSize(), fontSize);

{ // add mono font
// append icons to regular font
{
ImFontConfig config;
config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y);
monoFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(),
render::getCousineRegularCompressedSize(),
options::uiScale * 16.0f, &config);
}
config.MergeMode = true;
config.GlyphMinAdvanceX = fontSize; // make the icon monospaced

// this uses a tip from a helpful github issue to get teh alignment mostly right
// https://github.com/ocornut/imgui/issues/4127#issuecomment-2814162680

// io.Fonts->AddFontFromFileTTF("test-font-name.ttf", 16);
// Align vertically; the coefficients are specific to the particular icon font we're using.
float font_size_pixels = fontSize; // Or whatever you'd like.
float icon_scaling = 1.0f; // Or whatever you'd like.
config.GlyphOffset = {0.0f, font_size_pixels * (0.5f * icon_scaling - 0.3f)};

fontAtlas->AddFontFromMemoryCompressedTTF(render::getLucideIconsCompressedData(),
render::getLucideIconsCompressedSize(), fontSize, &config);
}

io.Fonts->Build();
// add mono font
monoFont = fontAtlas->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(),
render::getCousineRegularCompressedSize(), fontSize);

return std::tuple<ImFontAtlas*, ImFont*, ImFont*>{fontAtlas, regularFont, monoFont};
return std::tuple<ImFont*, ImFont*>(regularFont, monoFont);
}

} // namespace polyscope
Loading