Skip to content

Commit 269ff7a

Browse files
committed
Add dedicated high precision mode UI
1 parent 2e32e99 commit 269ff7a

File tree

4 files changed

+79
-26
lines changed

4 files changed

+79
-26
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_custom_command(
1414
set(SOURCE_FILES
1515
"graphics/graphics.cpp"
1616
"graphics/graphics.h"
17-
"types/types.h" "parser/tokenizer.h" "parser/checker.h" "parser/rpn.h" "parser/parser.h" "parser/checker.cpp" "parser/parser.cpp" "parser/rpn.cpp" "parser/tokenizer.cpp" "parser/simplifier.h" "parser/simplifier.cpp" "transformer/constant.h" "transformer/constant.cpp" "preprocessor/preprocessor.h" "preprocessor/string_builder.h" "transformer/operator.h" "transformer/operator.cpp" "transformer/transformer.h" "transformer/transformer.cpp" "preprocessor/string_builder.cpp" "preprocessor/preprocessor.cpp" "interactions/interactions.h" "interactions/interactions.cpp" "parser/validator.cpp" "parser/validator.h" "graphics/ui_init.h" "graphics/ui_init.cpp" "graphics/ui.h" "graphics/ui.cpp" "types/type_mapper.h" "types/type_mapper.cpp" "compiler/compiler_shader.h" "compiler/compiler_shader.cpp" "transformer/tree.h" "transformer/tree.cpp" "higher_order/derivative.h" "higher_order/higher_order.h" "higher_order/derivative.cpp" "higher_order/higher_order.cpp" "graphics/3d/mesh.h" "graphics/3d/mesh.cpp" "graphics/3d/camera_state.h" "graphics/3d/camera_state.cpp" "graphics/picker.cpp" "glad_include_guard.h" "interactions/export.h" "preprocessor/transpiler.cpp" "preprocessor/transpiler.h" "glsl_generated/types.h"
17+
"types/types.h" "parser/tokenizer.h" "parser/checker.h" "parser/rpn.h" "parser/parser.h" "parser/checker.cpp" "parser/parser.cpp" "parser/rpn.cpp" "parser/tokenizer.cpp" "parser/simplifier.h" "parser/simplifier.cpp" "transformer/constant.h" "transformer/constant.cpp" "preprocessor/preprocessor.h" "preprocessor/string_builder.h" "transformer/operator.h" "transformer/operator.cpp" "transformer/transformer.h" "transformer/transformer.cpp" "preprocessor/string_builder.cpp" "preprocessor/preprocessor.cpp" "interactions/interactions.h" "interactions/interactions.cpp" "parser/validator.cpp" "parser/validator.h" "graphics/ui_init.h" "graphics/ui_init.cpp" "graphics/ui.h" "graphics/ui.cpp" "types/type_mapper.h" "types/type_mapper.cpp" "compiler/compiler_shader.h" "compiler/compiler_shader.cpp" "transformer/tree.h" "transformer/tree.cpp" "higher_order/derivative.h" "higher_order/higher_order.h" "higher_order/derivative.cpp" "higher_order/higher_order.cpp" "graphics/3d/mesh.h" "graphics/3d/mesh.cpp" "graphics/3d/camera_state.h" "graphics/3d/camera_state.cpp" "graphics/picker.cpp" "glad_include_guard.h" "interactions/export.h" "preprocessor/transpiler.cpp" "preprocessor/transpiler.h" "glsl_generated/types.h" "interactions/export.cpp"
1818
"glsl_transpiled/glsl_big_number.h" "glsl_transpiled/glsl_types.h" "glsl_transpiled/glsl_constants.h" "glsl_transpiled/glsl_big_number.cpp" "high_precision/high_precision_constant.h" "high_precision/high_precision_constant.cpp" "cpu_drawing/cpu_render.h" "cpu_drawing/cpu_render.cpp")
1919
set(SHADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/shaders")
2020
set(HEADER_BUILD "${CMAKE_CURRENT_BINARY_DIR}/shaders/embedded_shaders.h")

src/graphics/ui.cpp

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,6 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
304304
ImGui::Unindent();
305305
}
306306
}
307-
if (ImGui::Button("Test Clipboard Callbacks")) {
308-
ImGui::SetClipboardText("Testing 123");
309-
310-
const char* text = ImGui::GetClipboardText();
311-
std::cout << "Manual check: " << (text ? text : "NULL") << std::endl;
312-
}
313-
314307
if (UI::CollapsingHeader("3D Keybinds")) {
315308
ImGui::BulletText("WASD: Move");
316309
ImGui::BulletText("Right click + Drag: Move camera");
@@ -347,6 +340,7 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
347340
state.needs_reparse = true;
348341
}
349342
}
343+
350344
if (UI::CollapsingHeader("Export")) {
351345
if (UI::Button("Render High Precision Popup")) {
352346
view_state.wants_high_precision = true;
@@ -404,24 +398,82 @@ void render_and_update(FunctionState& state, ViewState& view_state, unsigned int
404398

405399
ImGui::EndPopup();
406400
}
407-
if (view_state.is_high_precision) {
408-
ImGui::Begin("High Precision Render", &view_state.is_high_precision, ImGuiWindowFlags_AlwaysAutoResize);
409-
if (view_state.hp_texture != 0) {
410-
glBindTexture(GL_TEXTURE_2D, view_state.hp_texture);
411-
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, view_state.hp_width, view_state.hp_height, GL_RGBA, GL_UNSIGNED_BYTE, view_state.hp_cpu_buffer.data());
412-
ImGui::Text("Resolution: %dx%d", view_state.width, view_state.height);
413-
ImGui::Image(
414-
(void*)(intptr_t)view_state.hp_texture,
415-
ImVec2((float)view_state.hp_height, (float)view_state.hp_width),
416-
ImVec2(0, 0),
417-
ImVec2(1, 1)
418-
);
419-
if (ImGui::Button("Save to PNG")) {
401+
if (UI::CollapsingHeader("Arbitrary Precision Mode")) {
402+
ImGui::TextWrapped("Renders the current view using CPU-based arbitrary precision math. Required for extreme zoom levels.");
403+
ImGui::Spacing();
404+
405+
static std::string ui_shift_x = "0.0";
406+
static std::string ui_shift_y = "0.0";
407+
static std::string ui_range = "4.0";
408+
409+
if (UI::Button("Configure Deep Render")) {
410+
view_state.hp_width = 700;
411+
view_state.hp_height = 700;
412+
ui_range = std::to_string(view_state.range);
413+
ui_shift_x = std::to_string(view_state.shift.x);
414+
ui_shift_y = std::to_string(view_state.shift.y);
415+
ImGui::OpenPopup("Arbitrary Precision Setup");
416+
}
417+
418+
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
419+
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
420+
421+
if (ImGui::BeginPopupModal("Arbitrary Precision Setup", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
422+
423+
ImGui::InputInt("Width", &view_state.hp_width);
424+
ImGui::InputInt("Height", &view_state.hp_height);
425+
ImGui::Separator();
426+
427+
ImGui::TextDisabled("Supports up to 50 decimal places.");
428+
ImGui::InputText("Real (X) Center", &ui_shift_x);
429+
ImGui::InputText("Imaginary (Y) Center", &ui_shift_y);
430+
ImGui::InputText("Range (Zoom Level)", &ui_range);
431+
432+
ImGui::Spacing();
433+
if (ImGui::Button("Start Deep Render", ImVec2(140, 0))) {
434+
view_state.hp_range = big_float(ui_range);
435+
view_state.hp_shift = big_vec2(big_float(ui_shift_x), big_float(ui_shift_y));
436+
437+
view_state.wants_high_precision = true;
438+
ImGui::CloseCurrentPopup();
439+
}
440+
ImGui::SetItemDefaultFocus();
441+
ImGui::SameLine();
442+
if (ImGui::Button("Cancel", ImVec2(120, 0))) {
443+
ImGui::CloseCurrentPopup();
420444
}
421-
} else {
422-
ImGui::Text("Generating high precision render... please wait.");
445+
ImGui::EndPopup();
423446
}
424-
ImGui::End();
425447
}
448+
if (view_state.is_high_precision) {
449+
ImGui::Begin("High Precision Render", &view_state.is_high_precision, ImGuiWindowFlags_AlwaysAutoResize);
450+
if (view_state.hp_texture != 0) {
451+
ImGui::Text("Resolution: %dx%d", view_state.hp_width, view_state.hp_height);
452+
if (view_state.is_rendering_hp) {
453+
glBindTexture(GL_TEXTURE_2D, view_state.hp_texture);
454+
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, view_state.hp_width, view_state.hp_height, GL_RGBA, GL_UNSIGNED_BYTE, view_state.hp_cpu_buffer.data());
455+
456+
float progress = (float)view_state.hp_rows_completed / (float)view_state.hp_height;
457+
ImGui::ProgressBar(progress, ImVec2(-1.0f, 0.0f), "Loading...");
458+
}
459+
else {
460+
if (ImGui::Button("Save to PNG")) {
461+
std::string filename = "high_precision_" + std::to_string(view_state.hp_width) + "x" + std::to_string(view_state.hp_height) + ".png";
462+
export_plot_to_png(view_state.hp_width,view_state.hp_height,"complex-plot-high-precision");
463+
view_state.show_export_success = true;
464+
}
465+
}
466+
ImGui::Image(
467+
(void*)(intptr_t)view_state.hp_texture,
468+
ImVec2((float)view_state.hp_width, (float)view_state.hp_height),
469+
ImVec2(0, 0),
470+
ImVec2(1, 1)
471+
);
472+
}
473+
else {
474+
ImGui::Text("Initializing...");
475+
}
476+
ImGui::End();
477+
}
426478
ImGui::End();
427479
}

src/interactions/export.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stb_image/stb_image_write.h>
66
#include <interactions/export.h>
77

8+
89
#ifdef __EMSCRIPTEN__
910
#include <emscripten.h>
1011
#endif

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ void main_loop_step(AppContext* ctx) {
200200
init_imgui_loop();
201201

202202
if(ctx->view_state->wants_high_precision){
203-
const int hp_width = 700;//ctx->view_state->width;
204-
const int hp_height = 700;// ctx->view_state->height;
203+
const int hp_width = ctx->view_state->hp_width;
204+
const int hp_height = ctx->view_state->hp_height;
205205
ctx->view_state->hp_width = hp_width;
206206
ctx->view_state->hp_height = hp_height;
207207
ctx->view_state->hp_cpu_buffer.resize(hp_width * hp_height * 4);

0 commit comments

Comments
 (0)