Skip to content

Commit

Permalink
Background works correctly now.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Oct 13, 2023
1 parent 047b0e6 commit f75cf3d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 19 deletions.
73 changes: 54 additions & 19 deletions mrv2/lib/mrvGL/mrvGLViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace mrv
#ifdef USE_ONE_PIXEL_LINES
gl.outline.reset();
#endif
gl.background.reset();
gl.buffer.reset();
gl.annotation.reset();
gl.shader.reset();
Expand Down Expand Up @@ -202,6 +203,9 @@ namespace mrv

const auto& viewportSize = getViewportSize();
const auto& renderSize = getRenderSize();
bool transparent =
p.backgroundOptions.type == timeline::Background::Transparent;

try
{
if (renderSize.isValid())
Expand All @@ -215,6 +219,13 @@ namespace mrv
}
offscreenBufferOptions.depth = gl::OffscreenDepth::_24;
offscreenBufferOptions.stencil = gl::OffscreenStencil::_8;
if (gl::doCreate(
gl.background, renderSize, offscreenBufferOptions))
{
gl.background = gl::OffscreenBuffer::create(
renderSize, offscreenBufferOptions);
}

if (gl::doCreate(gl.buffer, renderSize, offscreenBufferOptions))
{
gl.buffer = gl::OffscreenBuffer::create(
Expand Down Expand Up @@ -250,10 +261,23 @@ namespace mrv
}
else
{
gl.background.reset();
gl.buffer.reset();
gl.stereoBuffer.reset();
}

if (gl.background && !transparent)
{
gl::OffscreenBufferBinding binding(gl.background);

locale::SetAndRestore saved;

gl.render->begin(
renderSize, p.colorConfigOptions, p.lutOptions);
_drawBackground();
gl.render->end();
}

if (gl.buffer && gl.render)
{
if (p.stereo3DOptions.output == Stereo3DOutput::OpenGL &&
Expand All @@ -272,8 +296,6 @@ namespace mrv

gl.render->begin(
renderSize, p.colorConfigOptions, p.lutOptions);

_drawBackground();
CHECK_GL;
if (p.missingFrame &&
p.missingFrameType != MissingFrameType::kBlackFrame)
Expand Down Expand Up @@ -323,23 +345,12 @@ namespace mrv
float r = 0.F, g = 0.F, b = 0.F, a = 1.F;
if (!p.presentation)
{
switch (p.backgroundOptions.type)
{
case timeline::Background::Solid:
case timeline::Background::Transparent:
{
uint8_t ur, ug, ub;
Fl::get_color(
p.ui->uiPrefs->uiPrefsViewBG->color(), ur, ug, ub);
r = ur / 255.0f;
g = ug / 255.0f;
b = ub / 255.0f;
p.backgroundOptions.solidColor = image::Color4f(r, g, b, a);
break;
}
default:
break;
}
uint8_t ur, ug, ub;
Fl::get_color(p.ui->uiPrefs->uiPrefsViewBG->color(), ur, ug, ub);
r = ur / 255.0f;
g = ug / 255.0f;
b = ub / 255.0f;
p.backgroundOptions.solidColor = image::Color4f(r, g, b, a);
}

glDrawBuffer(GL_BACK_LEFT);
Expand All @@ -349,6 +360,30 @@ namespace mrv
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
CHECK_GL;

if (gl.background && !transparent && !p.presentation)
{
math::Matrix4x4f mvp;
mvp = _createTexturedRectangle();

gl.shader->bind();
CHECK_GL;
gl.shader->setUniform("transform.mvp", mvp);
CHECK_GL;

glActiveTexture(GL_TEXTURE0);
CHECK_GL;
glBindTexture(GL_TEXTURE_2D, gl.background->getColorID());
CHECK_GL;

if (gl.vao && gl.vbo)
{
gl.vao->bind();
CHECK_GL;
gl.vao->draw(GL_TRIANGLES, 0, gl.vbo->getSize());
CHECK_GL;
}
}

if (gl.buffer && gl.shader)
{
math::Matrix4x4f mvp;
Expand Down
1 change: 1 addition & 0 deletions mrv2/lib/mrvGL/mrvGLViewportPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace mrv

// GL variables
//! OpenGL Offscreen buffers
std::shared_ptr<tl::gl::OffscreenBuffer> background = nullptr;
std::shared_ptr<tl::gl::OffscreenBuffer> buffer = nullptr;
std::shared_ptr<tl::gl::OffscreenBuffer> stereoBuffer = nullptr;
std::shared_ptr<tl::gl::OffscreenBuffer> annotation = nullptr;
Expand Down

0 comments on commit f75cf3d

Please sign in to comment.