implement layer bounds optminize function, add history to draw_objects with the right bounds.

This commit is contained in:
2019-01-18 19:03:53 +01:00
parent ff4ce5f379
commit e0bb60980a
6 changed files with 146 additions and 6 deletions

View File

@@ -70,6 +70,19 @@ void RTT::destroy()
// h = 0;
}
void RTT::copy(const RTT & source)
{
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, source.fboID);
glBlitFramebuffer(0, 0, source.w, source.h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
}
bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
{
// Destroy any previously created object
@@ -182,6 +195,25 @@ void RTT::clear(glm::vec4 color)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
glm::ivec4 RTT::calc_bounds()
{
auto data = std::unique_ptr<glm::i8vec4[]>(reinterpret_cast<glm::i8vec4*>(readTextureData()));
glm::ivec2 bbmin(w, h);
glm::ivec2 bbmax(0);
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
if (data[x + y * w].a > 0)
{
bbmin = glm::min(bbmin, { x, y });
bbmax = glm::max(bbmax, { x + 1, y + 1 });
}
}
}
return { bbmin, bbmax };
}
uint8_t* RTT::readTextureData(uint8_t* buffer)
{
if (!buffer)