Skip to content

Commit 1ed2967

Browse files
committed
Add transition/blending progress to render context
1 parent 458a63d commit 1ed2967

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/libprojectM/ProjectM.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ auto ProjectM::GetRenderContext() -> Renderer::RenderContext
456456
ctx.textureManager = m_textureManager.get();
457457
ctx.shaderCache = m_shaderCache.get();
458458

459+
if (m_transition)
460+
{
461+
ctx.blendProgress = m_transition->Progress(ctx.time);
462+
}
463+
else
464+
{
465+
ctx.blendProgress = 0.0;
466+
}
467+
459468
return ctx;
460469
}
461470

src/libprojectM/Renderer/PresetTransition.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "TextureManager.hpp"
44

5+
#include <algorithm>
56
#include <array>
67
#include <cmath>
78
#include <cstddef>
@@ -40,6 +41,11 @@ auto PresetTransition::IsDone(double currentFrameTime) const -> bool
4041
return m_durationSeconds <= 0.0 || secondsSinceStart >= m_durationSeconds;
4142
}
4243

44+
auto PresetTransition::Progress(double currentFrameTime) const -> double
45+
{
46+
return std::min(std::max((currentFrameTime - m_transitionStartTime) / m_durationSeconds, 0.0), 1.0);
47+
}
48+
4349
void PresetTransition::Draw(const Preset& oldPreset,
4450
const Preset& newPreset,
4551
const RenderContext& context,

src/libprojectM/Renderer/PresetTransition.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ class PresetTransition : public RenderItem
4040
*/
4141
auto IsDone(double currentFrameTime) const -> bool;
4242

43+
/**
44+
* @brief Returns the current linear blending progress according to the given frame time.
45+
* @param currentFrameTime The time in seconds since start of the current frame.
46+
* @return The linear blending progress from 0.0 to 1.0.
47+
*/
48+
auto Progress(double currentFrameTime) const -> double;
49+
4350
/**
4451
* @brief Updates the transition variables and renders the shader quad to the current FBO.
4552
* @param oldPreset A reference to the old (fading out) preset.

src/libprojectM/Renderer/RenderContext.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ class TextureManager;
1616
class RenderContext
1717
{
1818
public:
19-
float time{0.0f}; //!< Time since the preset started, in seconds.
20-
int frame{0}; //!< Frames rendered so far.
21-
float fps{0.0f}; //!< Frames per second.
22-
float progress{0.0f}; //!< Preset progress.
23-
int viewportSizeX{0}; //!< Horizontal viewport size in pixels
24-
int viewportSizeY{0}; //!< Vertical viewport size in pixels
25-
float aspectX{1.0}; //!< X aspect ratio.
26-
float aspectY{1.0}; //!< Y aspect ratio.
27-
float invAspectX{1.0}; //!< Inverse X aspect ratio.
28-
float invAspectY{1.0}; //!< Inverse Y aspect ratio.
19+
float time{0.0f}; //!< Time since the preset started, in seconds.
20+
int frame{0}; //!< Frames rendered so far.
21+
float fps{0.0f}; //!< Frames per second.
22+
float progress{0.0f}; //!< Preset progress.
23+
float blendProgress{0.0f}; //!< Preset transition/blending progress.
24+
int viewportSizeX{0}; //!< Horizontal viewport size in pixels
25+
int viewportSizeY{0}; //!< Vertical viewport size in pixels
26+
float aspectX{1.0}; //!< X aspect ratio.
27+
float aspectY{1.0}; //!< Y aspect ratio.
28+
float invAspectX{1.0}; //!< Inverse X aspect ratio.
29+
float invAspectY{1.0}; //!< Inverse Y aspect ratio.
2930

3031
int perPixelMeshX{64}; //!< Per-pixel/per-vertex mesh X resolution.
3132
int perPixelMeshY{48}; //!< Per-pixel/per-vertex mesh Y resolution.

0 commit comments

Comments
 (0)