fix rtt copy/move

This commit is contained in:
2019-10-15 16:59:55 +02:00
parent 9ccd6ed2f4
commit 5f002cca53
6 changed files with 161 additions and 73 deletions

View File

@@ -158,17 +158,17 @@ void Layer::restore(const Snapshot& snap)
//m_rtt[i].recreate();
App::I->render_task_async([this, i, &snap]
{
rtt(i).bindTexture();
glm::vec2 box_sz = zw(box(i)) - xy(box(i));
glTexSubImage2D(GL_TEXTURE_2D, 0,
box(i).x, box(i).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,
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
});
{
rtt(i).bindTexture();
glm::vec2 box_sz = zw(box(i)) - xy(box(i));
glTexSubImage2D(GL_TEXTURE_2D, 0,
box(i).x, box(i).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,
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
});
}
App::I->render_sync();
}
@@ -189,13 +189,13 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6>* dirty_box /*= nullptr*
snap.image[i] = std::make_unique<uint8_t[]>(rtt(i).bytes());
App::I->render_task_async([this, i, &snap]
{
rtt(i).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).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();
});
}
App::I->render_sync();
return snap;
@@ -203,36 +203,7 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6>* dirty_box /*= nullptr*
void Layer::clear(const glm::vec4& c)
{
App::I->render_task([&]
{
// push clear color state
GLfloat cc[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
glClearColor(c.r, c.g, c.b, c.a);
bool erase = (c.a == 0.f);
for (int i = 0; i < 6; i++)
{
rtt(i).bindFramebuffer();
glClear(GL_COLOR_BUFFER_BIT);
rtt(i).unbindFramebuffer();
if (erase)
{
box(i) = glm::vec4(w, h, 0, 0); // reset bounding box
face(i) = false;
}
else
{
box(i) = glm::vec4(0, 0, w, h); // reset bounding box
face(i) = true;
}
}
// restore clear color state
glClearColor(cc[0], cc[1], cc[2], cc[3]);
});
frame().clear(c);
}
bool Layer::create(int width, int height, std::string name)
@@ -240,26 +211,18 @@ bool Layer::create(int width, int height, std::string name)
m_name = name;
w = width;
h = height;
m_frame_index = 0;
if (m_frames.empty())
m_frames.emplace_back();
App::I->render_task([&]
{
for (int i = 0; i < 6; i++)
{
rtt(i).create(width, height);
rtt(i).bindFramebuffer();
rtt(i).clear();
rtt(i).unbindFramebuffer();
box(i) = glm::vec4(w, h, 0, 0); // reset bounding box
face(i) = false;
}
});
frame().create(width, height);
return true;
}
bool Layer::add_frame()
{
return true;
m_frames.emplace_back();
m_frame_index = m_frames.size() - 1;
return frame().create(w, h);
}
void Layer::resize(int width, int height)
@@ -335,11 +298,52 @@ int Layer::Snapshot::memsize() const
///////////////////////////////////////////////////////////////////////////////////////////
/*
LayerFrame::LayerFrame(LayerFrame&& other)
{
LOG("LayerFrame move-ctor");
for (int i = 0; i < 6; i++)
{
m_rtt[i] = std::move(other.m_rtt[i]);
m_dirty_box[i] = other.m_dirty_box[i];
m_dirty_face[i] = other.m_dirty_face[i];
}
m_duration = other.m_duration;
w = other.w;
h = other.h;
}
LayerFrame& LayerFrame::operator=(LayerFrame&& other)
{
LOG("LayerFrame move-assignment");
for (int i = 0; i < 6; i++)
{
m_rtt[i] = std::move(other.m_rtt[i]);
m_dirty_box[i] = other.m_dirty_box[i];
m_dirty_face[i] = other.m_dirty_face[i];
}
m_duration = other.m_duration;
w = other.w;
h = other.h;
return *this;
}
*/
bool LayerFrame::create(int width, int height, int duration /*= 1*/)
{
for (auto& rtt : m_rtt)
if (!rtt.create(width, height))
return false;
App::I->render_task([&]
{
for (int i = 0; i < 6; i++)
{
if (!m_rtt[i].create(width, height))
return false;
m_rtt[i].bindFramebuffer();
m_rtt[i].clear();
m_rtt[i].unbindFramebuffer();
m_dirty_box[i] = glm::vec4(w, h, 0, 0); // reset bounding box
m_dirty_face[i] = false;
}
});
m_duration = duration;
w = width;
h = height;
@@ -359,3 +363,37 @@ bool LayerFrame::resize(int width, int height)
h = height;
return true;
}
void LayerFrame::clear(const glm::vec4& c)
{
App::I->render_task([&]
{
// push clear color state
GLfloat cc[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
glClearColor(c.r, c.g, c.b, c.a);
bool erase = (c.a == 0.f);
for (int i = 0; i < 6; i++)
{
m_rtt[i].bindFramebuffer();
glClear(GL_COLOR_BUFFER_BIT);
m_rtt[i].unbindFramebuffer();
if (erase)
{
m_dirty_box[i] = glm::vec4(w, h, 0, 0); // reset bounding box
m_dirty_face[i] = false;
}
else
{
m_dirty_box[i] = glm::vec4(0, 0, w, h); // reset bounding box
m_dirty_face[i] = true;
}
}
// restore clear color state
glClearColor(cc[0], cc[1], cc[2], cc[3]);
});
}