Skip to content

Commit 9ce9266

Browse files
committed
Use Mesh class in PresetTransition class
1 parent 0ad258d commit 9ce9266

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/libprojectM/Renderer/PresetTransition.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,24 @@ namespace Renderer {
1313
constexpr double PI = 3.14159265358979323846;
1414

1515
PresetTransition::PresetTransition(const std::shared_ptr<Shader>& transitionShader, double durationSeconds, double transitionStartTime)
16-
: m_transitionShader(transitionShader)
16+
: m_mesh(VertexBufferUsage::StaticDraw)
17+
, m_transitionShader(transitionShader)
1718
, m_durationSeconds(durationSeconds)
1819
, m_transitionStartTime(transitionStartTime)
1920
{
20-
std::mt19937 rand32(m_randomDevice());
21-
m_staticRandomValues = {rand32(), rand32(), rand32(), rand32()};
21+
m_mesh.SetRenderPrimitiveType(Mesh::PrimitiveType::TriangleStrip);
2222

23-
RenderItem::Init();
24-
}
23+
m_mesh.Vertices().Set({{-1.0f, 1.0f},
24+
{1.0f, 1.0f},
25+
{-1.0f, -1.0f},
26+
{1.0f, -1.0f}});
2527

26-
void PresetTransition::InitVertexAttrib()
27-
{
28-
static const std::array<RenderItem::Point, 4> points{{{-1.0f, 1.0f},
29-
{1.0f, 1.0f},
30-
{-1.0f, -1.0f},
31-
{1.0f, -1.0f}}};
32-
33-
glEnableVertexAttribArray(0);
34-
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x))); // Position
35-
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
28+
m_mesh.Indices().Set({0, 1, 2, 3});
29+
30+
m_mesh.Update();
31+
32+
std::mt19937 rand32(m_randomDevice());
33+
m_staticRandomValues = {rand32(), rand32(), rand32(), rand32()};
3634
}
3735

3836
auto PresetTransition::IsDone(double currentFrameTime) const -> bool
@@ -120,9 +118,7 @@ void PresetTransition::Draw(const Preset& oldPreset,
120118
}
121119

122120
// Render the transition quad
123-
glBindVertexArray(m_vaoID);
124-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
125-
glBindVertexArray(0);
121+
m_mesh.Draw();
126122

127123
// Clean up
128124
oldPreset.OutputTexture()->Unbind(0);
@@ -133,6 +129,7 @@ void PresetTransition::Draw(const Preset& oldPreset,
133129
noiseDescriptors[i - 2].Unbind(textureUnit);
134130
}
135131

132+
Mesh::Unbind();
136133
Shader::Unbind();
137134

138135
// Update last frame time.

src/libprojectM/Renderer/PresetTransition.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#pragma once
22

3-
#include "Renderer/RenderItem.hpp"
3+
#include "Renderer/Mesh.hpp"
44
#include "Renderer/Shader.hpp"
5-
#include "Renderer/TextureSamplerDescriptor.hpp"
65

76
#include <Preset.hpp>
87

@@ -16,7 +15,7 @@ namespace Renderer {
1615
/**
1716
* @brief Implements the shader and rendering logic to blend two presets into each other.
1817
*/
19-
class PresetTransition : public RenderItem
18+
class PresetTransition
2019
{
2120
public:
2221
PresetTransition() = delete;
@@ -31,8 +30,6 @@ class PresetTransition : public RenderItem
3130
double durationSeconds,
3231
double transitionStartTime);
3332

34-
void InitVertexAttrib() override;
35-
3633
/**
3734
* @brief Returns true if the transition is done.
3835
* @param currentFrameTime The time in seconds since start of the current frame.
@@ -58,7 +55,7 @@ class PresetTransition : public RenderItem
5855
void Draw(const Preset& oldPreset,
5956
const Preset& newPreset,
6057
const RenderContext& context,
61-
const libprojectM::Audio::FrameAudioData& audioData,
58+
const Audio::FrameAudioData& audioData,
6259
double currentFrameTime);
6360

6461
private:
@@ -73,6 +70,7 @@ class PresetTransition : public RenderItem
7370
"noisevol_hq",
7471
"pw_noisevol_hq"}; //!< Names of noise textures to retrieve from TextureManager.
7572

73+
Mesh m_mesh; //!< The mesh used to draw the transition effect.
7674
std::shared_ptr<Shader> m_transitionShader; //!< The compiled shader used for this transition.
7775
std::shared_ptr<Sampler> m_presetSampler{std::make_shared<Sampler>(GL_CLAMP_TO_EDGE, GL_LINEAR)}; //!< Sampler for preset textures. Uses bilinear interpolation and no repeat.
7876

0 commit comments

Comments
 (0)