Merge branch 'feature/texture_displacement' of https://github.com/OrcaSlicer/OrcaSlicer into feature/texture_displacement

This commit is contained in:
ExPikaPaka committed 2026-07-21 10:12:16 +02:00
commit 129b612af5
874 files changed
+110241 -7192

No files matched your search

+26 -1
View File
@@ -2785,6 +2785,11 @@ void ImGuiWrapper::init_font(bool compress)
builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted)
io.Fonts->Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;
// TexDesiredWidth will be increased adaptively below if the built height
// exceeds GL_MAX_TEXTURE_SIZE. Leave it at 0 so ImGui picks the minimum
// width for small glyph sets and we only widen when actually necessary.
io.Fonts->TexDesiredWidth = 0;
ImFontConfig cfg = ImFontConfig();
cfg.OversampleH = cfg.OversampleV = 1;
//FIXME replace with io.Fonts->AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, m_font_size, nullptr, ranges.Data);
@@ -2856,7 +2861,23 @@ void ImGuiWrapper::init_font(bool compress)
io.Fonts->AddCustomRectFontGlyph(default_font, icon.first, icon_sz * 4, icon_sz * 4, 3.0 * font_scale + icon_sz * 4);
}
// Build texture atlas
// Build texture atlas, widening it if the height would exceed GL_MAX_TEXTURE_SIZE.
// Increasing the width allows the packing algorithm to grow more horizontally which reduces the height.
io.Fonts->Build();
GLint gl_max_tex_size = 0;
glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max_tex_size));
constexpr int max_retries = 6;
for (int attempt = 0; attempt < max_retries && io.Fonts->TexHeight > gl_max_tex_size; ++attempt) {
io.Fonts->TexDesiredWidth = (io.Fonts->TexDesiredWidth > 0 ? io.Fonts->TexDesiredWidth : io.Fonts->TexWidth) * 2;
io.Fonts->Build();
}
if (io.Fonts->TexHeight > gl_max_tex_size) {
// Shouldn't really happen
BOOST_LOG_TRIVIAL(error) << "Font atlas height " << io.Fonts->TexHeight
<< " still exceeds GL_MAX_TEXTURE_SIZE (" << gl_max_tex_size << ")"
<< " after " << max_retries << " attempts; rendering may be incomplete";
}
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
@@ -3141,6 +3162,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
shader->set_uniform("Texture", 0);
shader->set_uniform("ProjMtx", ortho_projection);
const uint8_t stage = 0;
shader->set_uniform("s_texture", stage);
// Will project scissor/clipping rectangles into framebuffer space
const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
const ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
@@ -3205,6 +3229,7 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
glsafe(::glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)));
// Bind texture, Draw
glsafe(::glActiveTexture(GL_TEXTURE0 + stage));
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()));
glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))));
}