add clear_mark to clear only selected channels in the framebuffer
This commit is contained in:
35
src/rtt.cpp
35
src/rtt.cpp
@@ -98,16 +98,18 @@ void RTT::copy(const RTT & source)
|
||||
{
|
||||
App::I->render_task([&]
|
||||
{
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
|
||||
GLint old_draw = 0;
|
||||
GLint old_read = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read);
|
||||
|
||||
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);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,16 +119,18 @@ void RTT::copy(const RTT& source, const glm::vec4& rect)
|
||||
{
|
||||
auto r = rect_intersection(rect, { 0, 0, w, h });
|
||||
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
|
||||
GLint old_draw = 0;
|
||||
GLint old_read = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, source.fboID);
|
||||
glBlitFramebuffer(r.x, r.y, r.z, r.w, r.x, r.y, r.z, r.w,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -251,6 +255,21 @@ void RTT::clear(glm::vec4 color)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void RTT::clear_mask(glm::bool4 mask, glm::vec4 color)
|
||||
{
|
||||
// save old state
|
||||
std::array<GLboolean, 4> old_mask;
|
||||
glGetBooleanv(GL_COLOR_WRITEMASK, std::data(old_mask));
|
||||
|
||||
// clear with mask
|
||||
glColorMask(mask.r, mask.g, mask.b, mask.a);
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// restore old state
|
||||
glColorMask(old_mask[0], old_mask[1], old_mask[2], old_mask[3]);
|
||||
}
|
||||
|
||||
glm::ivec4 RTT::calc_bounds()
|
||||
{
|
||||
auto data = std::unique_ptr<glm::u8vec4[]>(reinterpret_cast<glm::u8vec4*>(readTextureData()));
|
||||
|
||||
Reference in New Issue
Block a user