App::I static singleton to pointer

This commit is contained in:
2019-07-11 18:08:17 +02:00
parent 92dd00d910
commit b89274e7a6
33 changed files with 417 additions and 412 deletions

View File

@@ -291,7 +291,7 @@ std::array<std::vector<vertex_t>, 6> Canvas::stroke_draw_project(std::array<vert
{
glm::vec4 plane_local = plane_camera * glm::vec4(hit, 1);
//P[j].uvs2 = xy(P[j].pos) / glm::vec2(App::I.width, App::I.height);
//P[j].uvs2 = xy(P[j].pos) / glm::vec2(App::I->width, App::I->height);
vertex_t v;
v.pos.x = -(plane_local.x * 0.5f - 0.5f) * m_width;
v.pos.y = (plane_local.y * 0.5f + 0.5f) * m_height;
@@ -411,18 +411,18 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) con
+dx - dy, // D - bottom-right
};
glm::vec2 mixer_sz(App::I.width, App::I.height);
glm::vec2 mixer_sz(App::I->width, App::I->height);
glm::vec2 mixer_bb_min(mixer_sz);
glm::vec2 mixer_bb_max(0, 0);
for (int j = 0; j < 4; j++)
{
auto p = (xy(prev.pos) + App::I.zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
auto p = (xy(prev.pos) + App::I->zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p));
mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p));
if (s.pos.z == 0.f)
{
B[j].pos = glm::vec4(xy(s.pos) + App::I.zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].pos = glm::vec4(xy(s.pos) + App::I->zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
}
else
{
@@ -433,7 +433,7 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) con
B[j].uvs2 = p / mixer_sz;
}
f.m_mixer_rect = glm::vec4(glm::floor(mixer_bb_min), glm::ceil(mixer_bb_max - mixer_bb_min)) / App::I.zoom;
f.m_mixer_rect = glm::vec4(glm::floor(mixer_bb_min), glm::ceil(mixer_bb_max - mixer_bb_min)) / App::I->zoom;
f.col = glm::vec4(s.col, 1);
f.flow = s.flow;
f.opacity = s.opacity;
@@ -695,7 +695,7 @@ void Canvas::stroke_commit()
m_dirty = false;
m_dirty_stroke = true; // new stroke ready for timelapse capture
App::I.redraw = true;
App::I->redraw = true;
// save viewport and clear color states
GLint vp[4];
@@ -709,7 +709,7 @@ void Canvas::stroke_commit()
action->was_saved = !m_unsaved;
m_unsaved = true;
App::I.title_update();
App::I->title_update();
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1217,7 +1217,7 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
{
m_dirty = false;
App::I.render_task([&]
App::I->render_task([&]
{
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1438,7 +1438,7 @@ void Canvas::FloodData::apply()
if (!dirty[plane])
continue;
auto& rtt = layer->m_rtt[plane];
App::I.render_task([&]
App::I->render_task([&]
{
rtt.bindTexture();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rtt.getWidth(), rtt.getHeight(),
@@ -1575,7 +1575,7 @@ void Canvas::clear_context()
void Canvas::import_equirectangular(std::string file_path, std::shared_ptr<Layer> layer /*= nullptr*/)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -1657,7 +1657,7 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
void Canvas::export_equirectangular(std::string file_path, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -1672,16 +1672,16 @@ void Canvas::export_equirectangular(std::string file_path, std::function<void()>
void Canvas::export_equirectangular_thread(std::string file_path)
{
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Export Pano Image");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
RTT m_latlong;
@@ -1697,7 +1697,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
App::I.render_task([&]
App::I->render_task([&]
{
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
@@ -1716,7 +1716,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
for (int i = 0; i < 6; i++)
{
App::I.render_task([&]
App::I->render_task([&]
{
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1795,7 +1795,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
@@ -1813,7 +1813,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
// int ret = stbi_write_png(name, m_tmp[i].getWidth(), m_tmp[i].getHeight(), 4, data.get(), m_tmp[i].stride());
//}
App::I.render_task([&]
App::I->render_task([&]
{
glDisable(GL_BLEND);
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
@@ -1836,7 +1836,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
progress++;
LOG("progress: %f", (float)progress / total * 100.f);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP((float)progress / total * 100.f);
}
@@ -1855,7 +1855,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
progress++;
LOG("progress: %f", (float)progress / total * 100.f);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP((float)progress / total * 100.f);
}
@@ -1876,13 +1876,13 @@ void Canvas::export_equirectangular_thread(std::string file_path)
}];
#endif
App::I.render_task_async([id=cube_id]
App::I->render_task_async([id=cube_id]
{
glDeleteTextures(1, &id);
});
m_latlong.destroy();
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
}
@@ -1938,7 +1938,7 @@ void Canvas::inject_xmp(std::string jpg_path)
void Canvas::export_depth(std::string file_name, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
export_depth_thread(file_name);
@@ -1957,7 +1957,7 @@ void Canvas::export_depth_thread(std::string file_name)
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)rtt.getWidth() / (float)rtt.getHeight(), 0.1f, 100.f);
glm::mat4 camera = m_cam_rot;
App::I.render_task([&]
App::I->render_task([&]
{
draw_merge();
@@ -1999,11 +1999,11 @@ void Canvas::export_depth_thread(std::string file_name)
uint8_t* rgba_data = rtt.readTextureData();
stbi_flip_vertically_on_write(true);
std::string path_rgba = App::I.work_path + "/" + file_name + ".png";
std::string path_rgba = App::I->work_path + "/" + file_name + ".png";
stbi_write_jpg(path_rgba.c_str(), rtt.getWidth(), rtt.getHeight(), 4, rgba_data, 100);
delete rgba_data;
App::I.render_task([&]
App::I->render_task([&]
{
rtt.bindFramebuffer();
rtt.clear({ 0, 0, 0, 1 });
@@ -2041,7 +2041,7 @@ void Canvas::export_depth_thread(std::string file_name)
});
uint8_t* depth_data = rtt.readTextureData();
std::string path_depth = App::I.work_path + "/" + file_name + "_depth.png";
std::string path_depth = App::I->work_path + "/" + file_name + "_depth.png";
stbi_write_jpg(path_depth.c_str(), rtt.getWidth(), rtt.getHeight(), 4, depth_data, 100);
delete depth_data;
stbi_flip_vertically_on_write(false);
@@ -2051,7 +2051,7 @@ void Canvas::export_depth_thread(std::string file_name)
void Canvas::export_layers(std::string file_name, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -2066,16 +2066,16 @@ void Canvas::export_layers(std::string file_name, std::function<void()> on_compl
void Canvas::export_layers_thread(std::string file_name)
{
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Export Pano Layers");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
int progress = 0;
int total = (int)(m_layers.size() + 1) * 6;
@@ -2092,7 +2092,7 @@ void Canvas::export_layers_thread(std::string file_name)
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // top
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
App::I.render_task([&]
App::I->render_task([&]
{
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
@@ -2105,7 +2105,7 @@ void Canvas::export_layers_thread(std::string file_name)
{
for (int i = 0; i < 6; i++)
{
App::I.render_task([&]
App::I->render_task([&]
{
glEnable(GL_BLEND);
glViewport(0, 0, m_width, m_height);
@@ -2150,13 +2150,13 @@ void Canvas::export_layers_thread(std::string file_name)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
}
App::I.render_task([&]
App::I->render_task([&]
{
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
glActiveTexture(GL_TEXTURE0);
@@ -2178,7 +2178,7 @@ void Canvas::export_layers_thread(std::string file_name)
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
m_latlong.readTextureData(latlong_data.get());
static char name[128];
sprintf(name, "%s/%s-layer-%02d.png", App::I.work_path.c_str(), file_name.c_str(), seq);
sprintf(name, "%s/%s-layer-%02d.png", App::I->work_path.c_str(), file_name.c_str(), seq);
seq++;
LOG("writing %s", name);
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
@@ -2188,19 +2188,19 @@ void Canvas::export_layers_thread(std::string file_name)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
}
App::I.render_task([&]
App::I->render_task([&]
{
glDeleteTextures(1, &cube_id);
m_latlong.destroy();
});
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
}
@@ -2208,7 +2208,7 @@ void Canvas::export_layers_thread(std::string file_name)
void Canvas::export_cubes()
{
if (!App::I.check_license())
if (!App::I->check_license())
return;
#ifdef __OBJC__
NSMutableArray* files = [NSMutableArray array];
@@ -2255,7 +2255,7 @@ void Canvas::export_cubes()
}
static char name[128];
sprintf(name, "%s-%02d-%d.png", App::I.work_path.c_str(), layer, plane);
sprintf(name, "%s-%02d-%d.png", App::I->work_path.c_str(), layer, plane);
int ret = stbi_write_png(name, m_width, m_height, 4, buffer.get(), 0);
@@ -2280,7 +2280,7 @@ void Canvas::export_cubes()
}
#ifdef __OBJC__
static char name[128];
sprintf(name, "%s.zip", App::I.work_path.c_str());
sprintf(name, "%s.zip", App::I->work_path.c_str());
auto zip_path = [NSString stringWithUTF8String : name];
//[SSZipArchive createZipFileAtPath:zip_path withFilesAtPaths:files];
for (NSString* f : files)
@@ -2290,11 +2290,11 @@ void Canvas::export_cubes()
void Canvas::project_save(std::function<void(bool)> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
bool ret = project_save_thread(App::I.doc_path);
bool ret = project_save_thread(App::I->doc_path);
if (on_complete)
on_complete(ret);
});
@@ -2305,7 +2305,7 @@ void Canvas::project_save(std::function<void(bool)> on_complete)
void Canvas::project_save(std::string file_path, std::function<void(bool)> on_complete)
{
LOG("saving %s", file_path.c_str());
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -2324,7 +2324,7 @@ void Canvas::project_save(std::string file_path, std::function<void(bool)> on_co
bool Canvas::project_save_thread(std::string file_path)
{
// already saved, nothing to do
if (!m_unsaved && file_path == App::I.doc_path)
if (!m_unsaved && file_path == App::I->doc_path)
{
LOG("already saved");
return true;
@@ -2336,7 +2336,7 @@ bool Canvas::project_save_thread(std::string file_path)
auto start = file_path.rfind('/') + 1;
std::string file_name = file_path.substr(start, file_path.length() - start - strlen(".ppi"));
std::string tmp_path = App::I.data_path + '/' + file_name + ".tmp.ppi";
std::string tmp_path = App::I->data_path + '/' + file_name + ".tmp.ppi";
LOG("file name %s", file_name.c_str());
LOG("tmp path %s", tmp_path.c_str());
@@ -2375,13 +2375,13 @@ bool Canvas::project_save_thread(std::string file_path)
// load thumbnail
Image thumb = thumbnail_generate(ppi_header.thumb_header.width, ppi_header.thumb_header.height);
auto pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Saving Pano Project");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
thumb.flip();
fwrite(thumb.data(), thumb.size(), 1, fp);
@@ -2484,7 +2484,7 @@ bool Canvas::project_save_thread(std::string file_path)
}
pb->destroy();
App::I.title_update();
App::I->title_update();
return success;
}
@@ -2519,16 +2519,16 @@ bool Canvas::project_open_thread(std::string file_path)
}
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Opening Pano Project");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
// skip thumbnail
@@ -2615,7 +2615,7 @@ bool Canvas::project_open_thread(std::string file_path)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
@@ -2643,10 +2643,10 @@ bool Canvas::project_open_thread(std::string file_path)
memset(m_pick_ready, 0, sizeof(bool) * 6);
m_unsaved = false;
m_newdoc = false;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
App::I.title_update();
App::I->title_update();
}
return true;
}
@@ -2656,7 +2656,7 @@ Image Canvas::thumbnail_generate(int w, int h)
Image image;
image.create(w, h);
App::I.render_task([this, w, h, &image]
App::I->render_task([this, w, h, &image]
{
// save viewport and clear color states
GLint vp[4];
@@ -2795,7 +2795,7 @@ Image Canvas::thumbnail_read(std::string file_path)
void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
{
App::I.render_task([&]
App::I->render_task([&]
{
// save viewport and clear color states
GLint vp[4];
@@ -2842,7 +2842,7 @@ void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, con
void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
{
App::I.render_task([&]
App::I->render_task([&]
{
// save viewport and clear color states
GLint vp[4];
@@ -3105,7 +3105,7 @@ void Layer::restore(const Snapshot& snap)
// it's just a quick fix DON'T SHIP!!
//m_rtt[i].recreate();
App::I.render_task_async([this,i,&snap]
App::I->render_task_async([this,i,&snap]
{
m_rtt[i].bindTexture();
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
@@ -3118,7 +3118,7 @@ void Layer::restore(const Snapshot& snap)
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
});
}
App::I.render_sync();
App::I->render_sync();
}
Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr*/, std::array<bool, 6> * dirty_face /*= nullptr*/)
@@ -3136,7 +3136,7 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr
snap.image[i] = std::make_unique<uint8_t[]>(m_rtt[i].bytes());
App::I.render_task_async([this,i,&snap]
App::I->render_task_async([this,i,&snap]
{
m_rtt[i].bindFramebuffer();
glm::vec2 box_sz = zw(snap.m_dirty_box[i]) - xy(snap.m_dirty_box[i]);
@@ -3145,13 +3145,13 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr
m_rtt[i].unbindFramebuffer();
});
}
App::I.render_sync();
App::I->render_sync();
return snap;
}
void Layer::clear(const glm::vec4& c)
{
App::I.render_task([&]
App::I->render_task([&]
{
// push clear color state
GLfloat cc[4];
@@ -3188,7 +3188,7 @@ bool Layer::create(int width, int height, std::string name)
m_name = name;
w = width;
h = height;
App::I.render_task([&]
App::I->render_task([&]
{
for (int i = 0; i < 6; i++)
{