implement frames save and open from ppi
This commit is contained in:
@@ -101,15 +101,17 @@ void Layer::destroy()
|
||||
rtt(i).destroy();
|
||||
}
|
||||
|
||||
void Layer::optimize()
|
||||
void Layer::optimize(int frame /*= -1*/)
|
||||
{
|
||||
if (frame == -1)
|
||||
frame = m_frame_index;
|
||||
int saved_bytes = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (!face(i))
|
||||
if (!face(i, frame))
|
||||
continue;
|
||||
|
||||
auto data = std::unique_ptr<glm::u8vec4[]>(reinterpret_cast<glm::u8vec4*>(rtt(i).readTextureData()));
|
||||
auto data = std::unique_ptr<glm::u8vec4[]>(reinterpret_cast<glm::u8vec4*>(rtt(i, frame).readTextureData()));
|
||||
glm::ivec2 bbmin(w, h);
|
||||
glm::ivec2 bbmax(0);
|
||||
for (int y = 0; y < h; y++)
|
||||
@@ -124,17 +126,17 @@ void Layer::optimize()
|
||||
}
|
||||
}
|
||||
glm::vec2 bbsz = bbmax - bbmin;
|
||||
glm::vec2 old_size = zw(box(i)) - xy(box(i));
|
||||
glm::vec2 old_size = zw(box(i, frame)) - xy(box(i, frame));
|
||||
glm::vec2 diff;
|
||||
if (bbsz.x <= 0 || bbmax.y <= 0)
|
||||
{
|
||||
face(i) = false;
|
||||
box(i) = glm::vec4(0);
|
||||
face(i, frame) = false;
|
||||
box(i, frame) = glm::vec4(0);
|
||||
diff = old_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
box(i) = { bbmin, bbmax };
|
||||
box(i, frame) = { bbmin, bbmax };
|
||||
|
||||
diff = old_size - bbsz;
|
||||
}
|
||||
@@ -143,73 +145,79 @@ void Layer::optimize()
|
||||
LOG("optimized %d bytes", saved_bytes);
|
||||
}
|
||||
|
||||
void Layer::restore(const Snapshot& snap)
|
||||
void Layer::restore(const Snapshot& snap, int frame /*= -1*/)
|
||||
{
|
||||
clear({ 0, 0, 0, 0 });
|
||||
if (frame == -1)
|
||||
frame = m_frame_index;
|
||||
clear({ 0, 0, 0, 0 }, frame);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (snap.image[i] == nullptr || snap.m_dirty_face[i] == false || box_area(snap.m_dirty_box[i]) <= 0)
|
||||
{
|
||||
box(i) = glm::vec4(snap.width, snap.height, 0, 0);
|
||||
face(i) = false;
|
||||
box(i, frame) = glm::vec4(snap.width, snap.height, 0, 0);
|
||||
face(i, frame) = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
box(i) = snap.m_dirty_box[i];
|
||||
face(i) = snap.m_dirty_face[i];
|
||||
box(i, frame) = snap.m_dirty_box[i];
|
||||
face(i, frame) = snap.m_dirty_face[i];
|
||||
|
||||
// TODO: this should not be recreated here!
|
||||
// Sorry I messed up with this,
|
||||
// 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, frame]
|
||||
{
|
||||
rtt(i).bindTexture();
|
||||
glm::vec2 box_sz = zw(box(i)) - xy(box(i));
|
||||
rtt(i, frame).bindTexture();
|
||||
glm::vec2 box_sz = zw(box(i, frame)) - xy(box(i, frame));
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
box(i).x, box(i).y,
|
||||
box(i, frame).x, box(i, frame).y,
|
||||
box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
snap.image[i].get());
|
||||
rtt(i).unbindTexture();
|
||||
LOG("restore face %d - %d bytes (%dx%d)", i,
|
||||
rtt(i, frame).unbindTexture();
|
||||
LOG("restore frame %d face %d - %d bytes (%dx%d)", frame, i,
|
||||
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
|
||||
});
|
||||
}
|
||||
App::I->render_sync();
|
||||
}
|
||||
|
||||
Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6>* dirty_box /*= nullptr*/, std::array<bool, 6>* dirty_face /*= nullptr*/)
|
||||
Layer::Snapshot Layer::snapshot(int frame /*= -1*/, std::array<glm::vec4, 6>* dirty_box /*= nullptr*/, std::array<bool, 6>* dirty_face /*= nullptr*/)
|
||||
{
|
||||
if (frame == -1)
|
||||
frame = m_frame_index;
|
||||
Snapshot snap;
|
||||
snap.width = w;
|
||||
snap.height = h;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
snap.m_dirty_box[i] = dirty_box ? dirty_box->at(i) : box(i);
|
||||
snap.m_dirty_face[i] = dirty_face ? dirty_face->at(i) : face(i);
|
||||
snap.m_dirty_box[i] = dirty_box ? dirty_box->at(i) : box(i, frame);
|
||||
snap.m_dirty_face[i] = dirty_face ? dirty_face->at(i) : face(i, frame);
|
||||
|
||||
if (!snap.m_dirty_face[i])
|
||||
continue;
|
||||
|
||||
snap.image[i] = std::make_unique<uint8_t[]>(rtt(i).bytes());
|
||||
snap.image[i] = std::make_unique<uint8_t[]>(rtt(i, frame).bytes());
|
||||
|
||||
App::I->render_task_async([this, i, &snap]
|
||||
App::I->render_task_async([this, i, &snap, frame]
|
||||
{
|
||||
rtt(i).bindFramebuffer();
|
||||
rtt(i, frame).bindFramebuffer();
|
||||
glm::vec2 box_sz = zw(snap.m_dirty_box[i]) - xy(snap.m_dirty_box[i]);
|
||||
glReadPixels(snap.m_dirty_box[i].x, snap.m_dirty_box[i].y,
|
||||
box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get());
|
||||
rtt(i).unbindFramebuffer();
|
||||
rtt(i, frame).unbindFramebuffer();
|
||||
});
|
||||
}
|
||||
App::I->render_sync();
|
||||
return snap;
|
||||
}
|
||||
|
||||
void Layer::clear(const glm::vec4& c)
|
||||
void Layer::clear(const glm::vec4& c, int frame /*= -1*/)
|
||||
{
|
||||
frame().clear(c);
|
||||
if (frame == -1)
|
||||
frame = m_frame_index;
|
||||
m_frames[frame].clear(c);
|
||||
}
|
||||
|
||||
bool Layer::create(int width, int height, std::string name)
|
||||
@@ -218,9 +226,9 @@ bool Layer::create(int width, int height, std::string name)
|
||||
w = width;
|
||||
h = height;
|
||||
m_frame_index = 0;
|
||||
if (m_frames.empty())
|
||||
m_frames.emplace_back();
|
||||
frame().create(width, height);
|
||||
m_frames.clear();
|
||||
m_frames.emplace_back();
|
||||
m_frames.back().create(width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user