Move libmpv render function to update function

This commit is contained in:
Ylva Selling
2023-02-27 11:22:05 -05:00
parent a6827ae8e6
commit cc4e92e7fb
7 changed files with 35 additions and 16 deletions

View File

@@ -56,8 +56,8 @@ public:
bool isReady() const override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
void update(const UpdateData& data) override;
virtual void render(const RenderData& data, RendererTasks& rendererTask) override;
virtual void update(const UpdateData& data) override;
static documentation::Documentation Documentation();

View File

@@ -42,6 +42,7 @@ public:
bool deinitializeGL() override;
void update() override;
void render() override;
static documentation::Documentation Documentation();

View File

@@ -64,6 +64,7 @@ public:
void reset();
void destroy();
void update();
virtual void preSync(bool isMaster) override;
virtual void encode(SyncBuffer* syncBuffer) override;

View File

@@ -368,6 +368,8 @@ void RenderableVideoSphere::render(const RenderData& data, RendererTasks&) {
}
void RenderableVideoSphere::update(const UpdateData&) {
_videoPlayer.update();
if (_shader->isDirty()) {
_shader->rebuildFromFile();
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);

View File

@@ -70,6 +70,8 @@ ScreenSpaceVideo::ScreenSpaceVideo(const ghoul::Dictionary& dictionary)
}
void ScreenSpaceVideo::update() {
_videoPlayer.update();
if (!_videoPlayer.isInitialized()) {
return;
}
@@ -79,6 +81,13 @@ void ScreenSpaceVideo::update() {
}
}
void ScreenSpaceVideo::render() {
if (!_videoPlayer.isInitialized()) {
return;
}
ScreenSpaceRenderable::render();
}
bool ScreenSpaceVideo::deinitializeGL() {
_videoPlayer.destroy();

View File

@@ -281,17 +281,7 @@ VideoPlayer::VideoPlayer(const ghoul::Dictionary& dictionary)
}
global::callback::postSyncPreDraw->emplace_back([this]() {
if (_isDestroying) {
return;
}
// Initialize mpv here to ensure that the opengl context is the same as in for
// the rendering
if (!_isInitialized) {
initializeMpv();
}
else if(_mpvRenderContext && _mpvHandle) {
renderMpv();
}
});
global::callback::postDraw->emplace_back([this]() {
@@ -491,6 +481,20 @@ void VideoPlayer::toggleMute() {
setPropertyAsyncMpv(mute, MpvKey::Mute);
}
void VideoPlayer::update() {
if (_isDestroying) {
return;
}
// Initialize mpv here to ensure that the opengl context is the same as in for
// the rendering
if (!_isInitialized) {
initializeMpv();
}
else if (_mpvRenderContext && _mpvHandle) {
renderMpv();
}
}
void VideoPlayer::renderMpv() {
handleMpvEvents();
@@ -519,8 +523,8 @@ void VideoPlayer::renderMpv() {
/* TODO: remove this comment in case we never encounter this issue again */
// We have to set the Viewport on every cycle because
// mpv_render_context_render internally rescales the fb of the context(?!)...
//glm::ivec2 window = global::windowDelegate->currentDrawBufferResolution();
//glViewport(0, 0, window.x, window.y);
glm::ivec2 window = global::windowDelegate->currentDrawBufferResolution();
glViewport(0, 0, window.x, window.y);
_didRender = true;
}
}

View File

@@ -108,7 +108,9 @@ TileDepthTransform VideoTileProvider::depthTransform() {
return { 0.f, 1.f };
}
void VideoTileProvider::update() {}
void VideoTileProvider::update() {
_videoPlayer.update();
}
void VideoTileProvider::reset() {
_videoPlayer.reset();