fix action history with frames
This commit is contained in:
@@ -117,6 +117,7 @@ void Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
|
||||
{
|
||||
auto a = new ActionLayerClear;
|
||||
a->m_layer = m_layers[m_current_layer_idx];
|
||||
a->m_frame = layer().m_frame_index;
|
||||
a->m_snap = std::make_shared<Layer::Snapshot>(a->m_layer->snapshot());
|
||||
a->m_color = c;
|
||||
ActionManager::add(a);
|
||||
@@ -917,6 +918,7 @@ void Canvas::stroke_commit()
|
||||
|
||||
// save history
|
||||
action->m_layer_idx = m_current_layer_idx;
|
||||
action->m_frame_idx = layer().m_frame_index;
|
||||
action->m_canvas = this;
|
||||
//action->m_stroke = std::move(m_current_stroke);
|
||||
ActionManager::add(action);
|
||||
@@ -1680,7 +1682,7 @@ void Canvas::import_equirectangular(std::string file_path, std::shared_ptr<Layer
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::import_equirectangular_thread(std::string file_path, std::shared_ptr<Layer> layer /*= nullptr*/)
|
||||
void Canvas::import_equirectangular_thread(std::string file_path, std::shared_ptr<Layer> layer /*= nullptr*/, int frame /*= -1*/)
|
||||
{
|
||||
Image img;
|
||||
if (!img.load_file(file_path))
|
||||
@@ -1688,10 +1690,14 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
|
||||
|
||||
if (!layer)
|
||||
layer = m_layers[m_current_layer_idx];
|
||||
|
||||
if (frame == -1)
|
||||
frame = layer->m_frame_index;
|
||||
|
||||
auto a = new ActionImportEquirect;
|
||||
a->m_layer = layer;
|
||||
a->m_snap = std::make_shared<Layer::Snapshot>(layer->snapshot());
|
||||
a->m_frame = frame;
|
||||
a->m_snap = std::make_shared<Layer::Snapshot>(layer->snapshot(frame));
|
||||
a->m_path = file_path;
|
||||
ActionManager::add(a);
|
||||
|
||||
@@ -1719,7 +1725,7 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
|
||||
plane.draw_fill();
|
||||
tex.unbind();
|
||||
m_sampler.unbind();
|
||||
});
|
||||
}, frame, false);
|
||||
plane.destroy();
|
||||
}
|
||||
else
|
||||
@@ -1740,7 +1746,7 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
|
||||
sphere.draw_fill();
|
||||
tex.unbind();
|
||||
m_sampler.unbind();
|
||||
});
|
||||
}, frame, false);
|
||||
sphere.destroy();
|
||||
}
|
||||
for (int i = 0; i < 6; i++)
|
||||
@@ -2557,7 +2563,7 @@ Image Canvas::thumbnail_read(std::string file_path)
|
||||
return thumb;
|
||||
}
|
||||
|
||||
void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
|
||||
void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer, int frame)
|
||||
{
|
||||
App::I->render_task([&]
|
||||
{
|
||||
@@ -2582,16 +2588,16 @@ void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, con
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
glm::mat4 plane_camera = glm::lookAt(glm::vec3(0), m_plane_origin[i], m_plane_tangent[i]);
|
||||
layer.rtt(i).bindFramebuffer();
|
||||
layer.rtt(i, frame).bindFramebuffer();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
|
||||
|
||||
observer(plane_camera, proj, i);
|
||||
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
layer.rtt(i).unbindFramebuffer();
|
||||
layer.rtt(i, frame).unbindFramebuffer();
|
||||
|
||||
layer.face(i) = true;
|
||||
layer.box(i) = { 0, 0, layer.w, layer.h };
|
||||
layer.face(i, frame) = true;
|
||||
layer.box(i, frame) = { 0, 0, layer.w, layer.h };
|
||||
}
|
||||
|
||||
glDeleteRenderbuffers(1, &rboID);
|
||||
@@ -2604,7 +2610,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)
|
||||
void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer, int frame, bool save_history)
|
||||
{
|
||||
App::I->render_task([&]
|
||||
{
|
||||
@@ -2632,8 +2638,13 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
rtt.unbindFramebuffer();
|
||||
|
||||
// allocate action to add to history
|
||||
auto action = new ActionStroke;
|
||||
action->was_saved = !m_unsaved;
|
||||
ActionStroke* action;
|
||||
|
||||
if (save_history)
|
||||
{
|
||||
action = new ActionStroke;
|
||||
action->was_saved = !m_unsaved;
|
||||
}
|
||||
|
||||
glm::mat4 proj = glm::perspective(glm::radians(90.f), 1.f, .01f, 1000.f);
|
||||
for (int i = 0; i < 6; i++)
|
||||
@@ -2646,20 +2657,23 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
|
||||
glm::vec4 bounds = rtt.calc_bounds();
|
||||
|
||||
layer.rtt(i).bindFramebuffer();
|
||||
layer.rtt(i, frame).bindFramebuffer();
|
||||
|
||||
// save image before commit
|
||||
glm::vec2 box_sz = zw(bounds) - xy(bounds);
|
||||
bool has_data = box_sz.x > 0 && box_sz.y > 0;
|
||||
if (has_data)
|
||||
{
|
||||
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
|
||||
glReadPixels(bounds.x, bounds.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
|
||||
action->m_box[i] = bounds;
|
||||
}
|
||||
|
||||
action->m_old_box[i] = layer.box(i);
|
||||
action->m_old_dirty[i] = layer.face(i);
|
||||
if (save_history)
|
||||
{
|
||||
// save image before commit
|
||||
if (has_data)
|
||||
{
|
||||
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
|
||||
glReadPixels(bounds.x, bounds.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
|
||||
action->m_box[i] = bounds;
|
||||
}
|
||||
action->m_old_box[i] = layer.box(i, frame);
|
||||
action->m_old_dirty[i] = layer.face(i, frame);
|
||||
}
|
||||
|
||||
// draw the tmp layer into the actual layer
|
||||
if (has_data)
|
||||
@@ -2673,18 +2687,22 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
m_plane.draw_fill();
|
||||
rtt.unbindTexture();
|
||||
|
||||
layer.face(i) = true;
|
||||
layer.box(i) = { glm::min(xy(layer.box(i)), xy(bounds)), glm::max(zw(layer.box(i)), zw(bounds)) };
|
||||
layer.face(i, frame) = true;
|
||||
layer.box(i, frame) = { glm::min(xy(layer.box(i, frame)), xy(bounds)), glm::max(zw(layer.box(i, frame)), zw(bounds)) };
|
||||
}
|
||||
|
||||
layer.rtt(i).unbindFramebuffer();
|
||||
layer.rtt(i, frame).unbindFramebuffer();
|
||||
}
|
||||
|
||||
// save history
|
||||
action->m_layer_idx = m_current_layer_idx;
|
||||
action->m_canvas = this;
|
||||
//action->m_stroke = std::move(m_current_stroke);
|
||||
ActionManager::add(action);
|
||||
if (save_history)
|
||||
{
|
||||
// save history
|
||||
action->m_layer_idx = m_current_layer_idx;
|
||||
action->m_frame_idx = frame;
|
||||
action->m_canvas = this;
|
||||
//action->m_stroke = std::move(m_current_stroke);
|
||||
ActionManager::add(action);
|
||||
}
|
||||
|
||||
glDeleteRenderbuffers(1, &rboID);
|
||||
rtt.destroy();
|
||||
@@ -2697,9 +2715,9 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
});
|
||||
}
|
||||
|
||||
void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer)
|
||||
void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, int frame, bool save_history)
|
||||
{
|
||||
draw_objects(observer, *m_layers[m_current_layer_idx]);
|
||||
draw_objects(observer, layer(), frame, save_history);
|
||||
}
|
||||
|
||||
void Canvas::project2Dpoints(std::vector<vertex_t>& vertices)
|
||||
|
||||
Reference in New Issue
Block a user