Skip to content

Commit

Permalink
Move background options to the renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Feb 20, 2024
1 parent e1d8d67 commit b11e44d
Show file tree
Hide file tree
Showing 26 changed files with 321 additions and 314 deletions.
72 changes: 72 additions & 0 deletions lib/tlCore/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,78 @@ namespace tl
return out;
}

geom::TriangleMesh2 checkers(
const math::Box2i& box,
const image::Color4f& color0,
const image::Color4f& color1,
const math::Size2i& checkerSize)
{
geom::TriangleMesh2 out;

// X points.
std::vector<int> xs;
int x = box.min.x;
for (; x < box.max.x; x += checkerSize.w)
{
xs.push_back(x);
}
if (x >= box.max.x)
{
xs.push_back(box.max.x);
}

// Y points.
std::vector<int> ys;
int y = box.min.y;
for (; y < box.max.y; y += checkerSize.h)
{
ys.push_back(y);
}
if (y >= box.max.y)
{
ys.push_back(box.max.y);
}

if (!xs.empty() && !ys.empty())
{
// 2D points.
for (int j = 0; j < ys.size(); ++j)
{
for (int i = 0; i < xs.size(); ++i)
{
out.v.push_back(math::Vector2f(xs[i], ys[j]));
}
}

// Colors.
out.c.push_back(math::Vector4f(color0.r, color0.g, color0.b, color0.a));
out.c.push_back(math::Vector4f(color1.r, color1.g, color1.b, color1.a));

// Triangles.
for (int j = 0; j < ys.size() - 1; ++j)
{
for (int i = 0; i < xs.size() - 1; ++i)
{
const int v0 = j * xs.size() + i + 1;
const int v1 = j * xs.size() + (i + 1) + 1;
const int v2 = (j + 1) * xs.size() + (i + 1) + 1;
const int v3 = (j + 1) * xs.size() + i + 1;
const int c = (j + i) % 2 + 1;
out.triangles.push_back({
geom::Vertex2(v0, 0, c),
geom::Vertex2(v1, 0, c),
geom::Vertex2(v2, 0, c) });
out.triangles.push_back({
geom::Vertex2(v2, 0, c),
geom::Vertex2(v3, 0, c),
geom::Vertex2(v0, 0, c) });
}
}
}

return out;
}

TriangleMesh3 sphere(
float radius,
size_t xResolution,
Expand Down
12 changes: 10 additions & 2 deletions lib/tlCore/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <tlCore/Box.h>
#include <tlCore/Color.h>

#include <array>
#include <vector>
Expand Down Expand Up @@ -68,12 +69,19 @@ namespace tl
std::vector<Triangle3> triangles;
};

//! Create a two-dimensional axis aligned box mesh.
//! Create a two-dimensional box mesh.
TriangleMesh2 box(const math::Box2i&, bool flipV = false);

//! Create a two-dimensional axis aligned box mesh.
//! Create a two-dimensional box mesh.
TriangleMesh2 box(const math::Box2f&, bool flipV = false);

//! Create a mesh for drawing checkers.
geom::TriangleMesh2 checkers(
const math::Box2i&,
const image::Color4f& color0,
const image::Color4f& color1,
const math::Size2i& checkerSize);

//! Edge function.
float edge(
const math::Vector2f& p,
Expand Down
26 changes: 22 additions & 4 deletions lib/tlDevice/BMDOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace tl
HDRMode hdrMode = HDRMode::FromFile;
image::HDRData hdrData;
timeline::CompareOptions compareOptions;
timeline::BackgroundOptions backgroundOptions;
math::Vector2i viewPos;
double viewZoom = 1.0;
bool frameView = true;
Expand Down Expand Up @@ -327,6 +328,16 @@ namespace tl
p.thread.cv.notify_one();
}

void OutputDevice::setBackgroundOptions(const timeline::BackgroundOptions& value)
{
TLRENDER_P();
{
std::unique_lock<std::mutex> lock(p.mutex.mutex);
p.mutex.backgroundOptions = value;
}
p.thread.cv.notify_one();
}

void OutputDevice::setOverlay(const std::shared_ptr<image::Image>& value)
{
TLRENDER_P();
Expand Down Expand Up @@ -510,6 +521,7 @@ namespace tl
std::vector<timeline::ImageOptions> imageOptions;
std::vector<timeline::DisplayOptions> displayOptions;
timeline::CompareOptions compareOptions;
timeline::BackgroundOptions backgroundOptions;
timeline::Playback playback = timeline::Playback::Stop;
otime::RationalTime currentTime = time::invalidTime;
float volume = 1.F;
Expand All @@ -536,7 +548,7 @@ namespace tl
timeout,
[this, config, enabled,
ocioOptions, lutOptions, imageOptions,
displayOptions, compareOptions,
displayOptions, compareOptions, backgroundOptions,
playback, currentTime,
volume, mute, audioOffset, audioData]
{
Expand All @@ -550,6 +562,7 @@ namespace tl
_p->thread.hdrMode != _p->mutex.hdrMode ||
_p->thread.hdrData != _p->mutex.hdrData ||
compareOptions != _p->mutex.compareOptions ||
backgroundOptions != _p->mutex.backgroundOptions ||
_p->thread.viewPos != _p->mutex.viewPos ||
_p->thread.viewZoom != _p->mutex.viewZoom ||
_p->thread.frameView != _p->mutex.frameView ||
Expand Down Expand Up @@ -584,6 +597,7 @@ namespace tl
p.thread.hdrMode != p.mutex.hdrMode ||
p.thread.hdrData != p.mutex.hdrData ||
compareOptions != p.mutex.compareOptions ||
backgroundOptions != p.mutex.backgroundOptions ||
p.thread.viewPos != p.mutex.viewPos ||
p.thread.viewZoom != p.mutex.viewZoom ||
p.thread.frameView != p.mutex.frameView ||
Expand All @@ -597,6 +611,7 @@ namespace tl
p.thread.hdrMode = p.mutex.hdrMode;
p.thread.hdrData = p.mutex.hdrData;
compareOptions = p.mutex.compareOptions;
backgroundOptions = p.mutex.backgroundOptions;
p.thread.viewPos = p.mutex.viewPos;
p.thread.viewZoom = p.mutex.viewZoom;
p.thread.frameView = p.mutex.frameView;
Expand Down Expand Up @@ -671,7 +686,8 @@ namespace tl
lutOptions,
imageOptions,
displayOptions,
compareOptions);
compareOptions,
backgroundOptions);
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -916,7 +932,8 @@ namespace tl
const timeline::LUTOptions& lutOptions,
const std::vector<timeline::ImageOptions>& imageOptions,
const std::vector<timeline::DisplayOptions>& displayOptions,
const timeline::CompareOptions& compareOptions)
const timeline::CompareOptions& compareOptions,
const timeline::BackgroundOptions& backgroundOptions)
{
TLRENDER_P();

Expand Down Expand Up @@ -977,7 +994,8 @@ namespace tl
timeline::getBoxes(compareOptions.mode, p.thread.sizes),
imageOptions,
displayOptions,
compareOptions);
compareOptions,
backgroundOptions);
if (p.thread.overlay)
{
p.thread.render->setTransform(pm);
Expand Down
6 changes: 5 additions & 1 deletion lib/tlDevice/BMDOutputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace tl
//! Set the comparison options.
void setCompareOptions(const timeline::CompareOptions&);

//! Set the background options.
void setBackgroundOptions(const timeline::BackgroundOptions&);

//! Set the overlay.
void setOverlay(const std::shared_ptr<image::Image>&);

Expand Down Expand Up @@ -120,7 +123,8 @@ namespace tl
const timeline::LUTOptions&,
const std::vector<timeline::ImageOptions>&,
const std::vector<timeline::DisplayOptions>&,
const timeline::CompareOptions&);
const timeline::CompareOptions&,
const timeline::BackgroundOptions&);
void _read();

TLRENDER_PRIVATE();
Expand Down
6 changes: 3 additions & 3 deletions lib/tlPlay/ViewportModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ namespace tl
const std::shared_ptr<Settings>&,
const std::shared_ptr<system::Context>&);

//! Get the timeline viewport background options.
//! Get the background options.
const timeline::BackgroundOptions& getBackgroundOptions() const;

//! Observer the timeline viewport background options.
//! Observe the background options.
std::shared_ptr<observer::IValue<timeline::BackgroundOptions> > observeBackgroundOptions() const;

//! Set the timeline viewport background options.
//! Set the background options.
void setBackgroundOptions(const timeline::BackgroundOptions&);

private:
Expand Down
8 changes: 8 additions & 0 deletions lib/tlPlayApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace tl
std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::CompareOptions> > compareOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
#endif // TLRENDER_BMD
};

Expand Down Expand Up @@ -639,6 +640,13 @@ namespace tl
{
_p->bmdOutputDevice->setCompareOptions(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
p.viewportModel->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->bmdOutputDevice->setBackgroundOptions(value);
});
#endif // TLRENDER_BMD
}

Expand Down
16 changes: 8 additions & 8 deletions lib/tlPlayApp/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ namespace tl
std::shared_ptr<observer::ValueObserver<double> > speedObserver2;
std::shared_ptr<observer::ValueObserver<timeline::Playback> > playbackObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > currentTimeObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::OCIOOptions> > ocioOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::LUTOptions> > lutOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::CompareOptions> > compareOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
std::shared_ptr<observer::ValueObserver<bool> > muteObserver;
std::shared_ptr<observer::ListObserver<log::Item> > logObserver;
};
Expand Down Expand Up @@ -550,13 +550,6 @@ namespace tl
}
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->timelineViewport->setBackgroundOptions(value);
});

p.ocioOptionsObserver = observer::ValueObserver<timeline::OCIOOptions>::create(
app->getColorModel()->observeOCIOOptions(),
[this](const timeline::OCIOOptions& value)
Expand Down Expand Up @@ -602,6 +595,13 @@ namespace tl
_p->timelineViewport->setCompareOptions(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->timelineViewport->setBackgroundOptions(value);
});

p.muteObserver = observer::ValueObserver<bool>::create(
app->getAudioModel()->observeMute(),
[this](bool value)
Expand Down
16 changes: 8 additions & 8 deletions lib/tlPlayApp/SecondaryWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace tl
std::shared_ptr<timelineui::TimelineViewport> viewport;

std::shared_ptr<observer::ListObserver<std::shared_ptr<timeline::Player> > > playersObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::OCIOOptions> > ocioOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::LUTOptions> > lutOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::CompareOptions> > compareOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
};

void SecondaryWindow::_init(
Expand All @@ -49,13 +49,6 @@ namespace tl
_p->viewport->setPlayers(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->viewport->setBackgroundOptions(value);
});

p.ocioOptionsObserver = observer::ValueObserver<timeline::OCIOOptions>::create(
app->getColorModel()->observeOCIOOptions(),
[this](const timeline::OCIOOptions& value)
Expand Down Expand Up @@ -90,6 +83,13 @@ namespace tl
{
_p->viewport->setCompareOptions(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->viewport->setBackgroundOptions(value);
});
}

SecondaryWindow::SecondaryWindow() :
Expand Down
Loading

0 comments on commit b11e44d

Please sign in to comment.