Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c3af40c
refactor: move OpenGL renderer code to backend directory
revmischa Apr 17, 2025
11a2943
fix: remove default parameter from CopyTexture::Draw targetTexture
revmischa Apr 17, 2025
fa0c5e2
refactor: comment out OpenGL-specific code in PresetTransition
revmischa Apr 17, 2025
e25497c
refactor: move PresetTransition OpenGL code to backend
revmischa Apr 17, 2025
33d40b3
refactor: move OpenGL transition rendering to backend implementation
revmischa Apr 17, 2025
df7ca36
chore: update gitignore and vendor submodule status
revmischa Apr 17, 2025
3b651b8
fix: update CustomShape to use OpenGL backend implementation
revmischa Apr 17, 2025
9450d16
refactor: add optional Init method to RenderItem base class
revmischa Apr 17, 2025
982f6c9
fix: resolve namespace and include issues in OpenGL render items
revmischa Apr 17, 2025
cce3fec
fix: Update render items to use OpenGL backend implementation
revmischa Apr 17, 2025
4114ab0
refactor: use flip texture for preset output instead of framebuffer
revmischa Apr 17, 2025
ade9715
The changes update the inheritance of several classes (`PerPixelMesh`…
revmischa Apr 17, 2025
bf2c490
fix: resolve OpenGL renderer initialization and texture creation errors
revmischa Apr 17, 2025
58bab5b
fix: resolve compilation errors in MilkdropPreset and UserSprites
revmischa Apr 17, 2025
717e9a2
fix: Resolve OpenGL initialization and header inclusion issues
revmischa Apr 17, 2025
064a93f
fix: add missing include for OpenGLCopyTexture in MilkdropPreset.cpp
revmischa Apr 17, 2025
f25ebda
fix: change include to relative path in OpenGLCopyTexture.hpp
revmischa Apr 17, 2025
c2da9ff
refactor: update destructor override and return type for Texture()
revmischa Apr 17, 2025
c1ace90
fix: remove 'override' from destructor and methods in OpenGLRenderIte…
revmischa Apr 17, 2025
76bf076
fix: update method declarations to match base class and resolve errors
revmischa Apr 17, 2025
2ad7161
fix: change include to local path in OpenGLRenderItem.hpp for correct…
revmischa Apr 17, 2025
f815366
fix: use global namespace for RenderItem base class in OpenGLRenderIt…
revmischa Apr 17, 2025
3636eb4
fix: add missing include for OpenGLPresetTransition in ProjectM.cpp
revmischa Apr 17, 2025
b0148f3
refactor: add override specifiers to virtual functions for clarity an…
revmischa Apr 17, 2025
e4cfcba
refactor: unhide base Init() in derived classes to fix virtual warning
revmischa Apr 17, 2025
da2e74a
fix: ensure all Init() calls invoke base class methods for proper init
revmischa Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ src/libprojectM/build/
# CLion
cmake-build-*
.idea
.aider*
5 changes: 2 additions & 3 deletions src/libprojectM/MilkdropPreset/Border.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ namespace MilkdropPreset {

Border::Border(PresetState& presetState)
: m_presetState(presetState)
, m_borderMesh(Renderer::VertexBufferUsage::StreamDraw)
{
m_borderMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::Triangles);
m_borderMesh.SetVertexCount(8);
Init();
}

m_borderMesh.Indices().Set({
{
Expand Down
5 changes: 2 additions & 3 deletions src/libprojectM/MilkdropPreset/Border.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

#include "PresetState.hpp"

#include <Renderer/Mesh.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

namespace libprojectM {
namespace MilkdropPreset {


/**
* @brief Renders a border around the screen.
*/
class Border
class Border : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
Border() = delete;
Expand Down
33 changes: 31 additions & 2 deletions src/libprojectM/MilkdropPreset/CustomShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,37 @@ CustomShape::CustomShape(PresetState& presetState)
m_outlineMesh.SetVertexCount(100);
m_outlineMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::LineLoop);

m_fillMesh.SetVertexCount(102);
m_fillMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleFan);
glGenVertexArrays(1, &m_vaoIdTextured);
glGenBuffers(1, &m_vboIdTextured);

glGenVertexArrays(1, &m_vaoIdUntextured);
glGenBuffers(1, &m_vboIdUntextured);

glBindVertexArray(m_vaoIdTextured);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIdTextured);

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast<void*>(offsetof(TexturedPoint, x))); // Position
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast<void*>(offsetof(TexturedPoint, r))); // Color
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast<void*>(offsetof(TexturedPoint, u))); // Texture coordinate

glBufferData(GL_ARRAY_BUFFER, sizeof(TexturedPoint) * vertexData.size(), vertexData.data(), GL_STREAM_DRAW);

glBindVertexArray(m_vaoIdUntextured);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIdUntextured);

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast<void*>(offsetof(TexturedPoint, x))); // Position
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast<void*>(offsetof(TexturedPoint, r))); // Color

glBufferData(GL_ARRAY_BUFFER, sizeof(TexturedPoint) * vertexData.size(), vertexData.data(), GL_STREAM_DRAW);

Init();

m_perFrameContext.RegisterBuiltinVariables();
}
Expand Down
6 changes: 3 additions & 3 deletions src/libprojectM/MilkdropPreset/CustomShape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "PresetState.hpp"
#include "ShapePerFrameContext.hpp"

#include <Renderer/Mesh.hpp>

#include <Renderer/RenderItem.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>
#include <projectm-eval.h>

namespace libprojectM {
Expand All @@ -19,7 +19,7 @@ class PresetFileParser;
* The class creates two sets of VBO/VAO as it's only known later (in the Draw() call) whether the shape is textured
* or not.
*/
class CustomShape
class CustomShape : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
CustomShape(PresetState& presetState);
Expand Down
2 changes: 2 additions & 0 deletions src/libprojectM/MilkdropPreset/CustomWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ CustomWaveform::CustomWaveform(PresetState& presetState)
, m_perPointContext(presetState.globalMemory, &presetState.globalRegisters)
, m_mesh(Renderer::VertexBufferUsage::StreamDraw, true, false)
{
Init();

m_perFrameContext.RegisterBuiltinVariables();
m_perPointContext.RegisterBuiltinVariables();

Expand Down
20 changes: 12 additions & 8 deletions src/libprojectM/MilkdropPreset/CustomWaveform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include "WaveformPerFrameContext.hpp"
#include "WaveformPerPointContext.hpp"

#include <Renderer/Color.hpp>
#include <Renderer/Mesh.hpp>
#include <Renderer/Point.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

#include <vector>

Expand All @@ -14,7 +12,9 @@ namespace MilkdropPreset {

class PresetFileParser;

class CustomWaveform
namespace MilkdropPreset {

class CustomWaveform : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:

Expand All @@ -24,12 +24,14 @@ class CustomWaveform
*/
explicit CustomWaveform(PresetState& presetState);

void InitVertexAttrib() override;

/**
* @brief Loads the initial values and code from the preset file.
* @param parsedFile The file parser with the preset data.
* @param index The waveform index.
*/
void Initialize(PresetFileParser& parsedFile, int index);
void Initialize(::libprojectM::PresetFileParser& parsedFile, int index);

/**
* @brief Compiles all code blocks and runs the init expression.
Expand Down Expand Up @@ -69,10 +71,12 @@ class CustomWaveform
*
* Roughly doubles the number of points.
*
* @param points A vector of points to be smoothed.
* @param colors A vector of colors for the points.
* @param inputVertices Array of input vertices to be smoothed.
* @param vertexCount Number of vertices in the input array.
* @param outputVertices Array to store the smoothed vertices.
* @return The number of vertices in the output array.
*/
void SmoothWave(const std::vector<Renderer::Point>& points, const std::vector<Renderer::Color>& colors);
static int SmoothWave(const ColoredPoint* inputVertices, int vertexCount, ColoredPoint* outputVertices);

int m_index{0}; //!< Custom waveform index in the preset.
bool m_enabled{false}; //!< Render waveform if non-zero.
Expand Down
20 changes: 10 additions & 10 deletions src/libprojectM/MilkdropPreset/DarkenCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace MilkdropPreset {

DarkenCenter::DarkenCenter(PresetState& presetState)
: m_presetState(presetState)
, m_mesh(Renderer::VertexBufferUsage::StaticDraw, true, false)
{
m_mesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleFan);
m_mesh.SetVertexCount(6);
m_mesh.Colors().Set({{0.0f, 0.0f, 0.0f, 3.0f / 32.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f}});
m_mesh.Update();
Init();
}

void DarkenCenter::InitVertexAttrib()
{
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(ColoredPoint), nullptr); // points
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(ColoredPoint), reinterpret_cast<void*>(offsetof(ColoredPoint, r))); // colors
}

void DarkenCenter::Draw()
Expand Down
6 changes: 4 additions & 2 deletions src/libprojectM/MilkdropPreset/DarkenCenter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

#include "PresetState.hpp"

#include <Renderer/Mesh.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

namespace libprojectM {
namespace MilkdropPreset {

/**
* @brief Darkens the screen center a bit on each frame.
*/
class DarkenCenter
class DarkenCenter : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
DarkenCenter() = delete;

explicit DarkenCenter(PresetState& presetState);

void InitVertexAttrib() override;

/**
* Applies the darkening area.
*/
Expand Down
12 changes: 9 additions & 3 deletions src/libprojectM/MilkdropPreset/Filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ namespace MilkdropPreset {

Filters::Filters(const PresetState& presetState)
: m_presetState(presetState)
, m_filterMesh(Renderer::VertexBufferUsage::StaticDraw)
{
m_filterMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleStrip);
m_filterMesh.SetVertexCount(4);
Init();
}

void Filters::InitVertexAttrib()
{
glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x)));
}

void Filters::Draw()
Expand Down
6 changes: 4 additions & 2 deletions src/libprojectM/MilkdropPreset/Filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

#include "PresetState.hpp"

#include <Renderer/Mesh.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

namespace libprojectM {
namespace MilkdropPreset {

/**
* @brief Classic Milkdrop 1 postprocessing effects.
*/
class Filters
class Filters : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
Filters() = delete;
explicit Filters(const PresetState& presetState);

void InitVertexAttrib() override;

/**
* @brief Applies the configured filters to the current output.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/libprojectM/MilkdropPreset/FinalComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ static std::string const defaultCompositeShader = "shader_body\n{\nret = tex2D(s
FinalComposite::FinalComposite()
: m_compositeMesh(Renderer::VertexBufferUsage::StreamDraw, true, true)
{
m_compositeMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::Triangles);
Init();
}

// Add attribute array for radius and angle information to the mesh.
m_compositeMesh.Bind();
Expand Down
6 changes: 4 additions & 2 deletions src/libprojectM/MilkdropPreset/FinalComposite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "MilkdropShader.hpp"
#include "VideoEcho.hpp"

#include <Renderer/Mesh.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

#include <memory>

Expand All @@ -14,11 +14,13 @@ namespace MilkdropPreset {
/**
* @brief Draws the final composite effect, either a shader or Milkdrop 1 effects.
*/
class FinalComposite
class FinalComposite : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
FinalComposite();

void InitVertexAttrib() override;

/**
* @brief Loads the composite shader, if the preset uses one.
* @param presetState The preset state to retrieve the shader from.
Expand Down
21 changes: 14 additions & 7 deletions src/libprojectM/MilkdropPreset/MilkdropPreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Factory.hpp"
#include "MilkdropPresetExceptions.hpp"
#include "PresetFileParser.hpp"
#include <Renderer/Backend/OpenGL/OpenGLCopyTexture.hpp>

#include <Logging.hpp>

Expand All @@ -38,7 +39,10 @@ MilkdropPreset::MilkdropPreset(const std::string& absoluteFilePath)
, m_waveform(m_state)
, m_darkenCenter(m_state)
, m_border(m_state)
, m_flipTexture(std::make_unique<libprojectM::Renderer::Backend::OpenGL::OpenGLCopyTexture>())
{
// Ensure OpenGLCopyTexture is visible to this translation unit
// (include the header if not already included at the top of this file)
Load(absoluteFilePath);
}

Expand All @@ -49,7 +53,10 @@ MilkdropPreset::MilkdropPreset(std::istream& presetData)
, m_waveform(m_state)
, m_darkenCenter(m_state)
, m_border(m_state)
, m_flipTexture(std::make_unique<libprojectM::Renderer::Backend::OpenGL::OpenGLCopyTexture>())
{
// Ensure OpenGLCopyTexture is visible to this translation unit
// (include the header if not already included at the top of this file)
Load(presetData);
}

Expand Down Expand Up @@ -103,8 +110,8 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio
}

// y-flip the previous frame and assign the flipped texture as "main"
m_flipTexture.Draw(*renderContext.shaderCache, m_framebuffer.GetColorAttachmentTexture(m_previousFrameBuffer, 0), nullptr, true, false);
m_state.mainTexture = m_flipTexture.Texture();
m_flipTexture->Draw(m_framebuffer.GetColorAttachmentTexture(m_previousFrameBuffer, 0), nullptr, true, false);
m_state.mainTexture = m_flipTexture->Texture();

// We now draw to the current framebuffer.
m_framebuffer.Bind(m_currentFrameBuffer);
Expand Down Expand Up @@ -144,8 +151,8 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio
m_border.Draw(m_perFrameContext);

// y-flip the image for final compositing again
m_flipTexture.Draw(*renderContext.shaderCache, m_framebuffer.GetColorAttachmentTexture(m_currentFrameBuffer, 0), nullptr, true, false);
m_state.mainTexture = m_flipTexture.Texture();
m_flipTexture->Draw(m_framebuffer.GetColorAttachmentTexture(m_currentFrameBuffer, 0), nullptr, true, false);
m_state.mainTexture = m_flipTexture->Texture();

// We no longer need the previous frame image, use it to render the final composite.
m_framebuffer.BindRead(m_currentFrameBuffer);
Expand All @@ -156,7 +163,7 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio
if (!m_finalComposite.HasCompositeShader())
{
// Flip texture again in "previous" framebuffer as old-school effects are still upside down.
m_flipTexture.Draw(*renderContext.shaderCache, m_framebuffer.GetColorAttachmentTexture(m_previousFrameBuffer, 0), m_framebuffer, m_previousFrameBuffer, true, false);
m_flipTexture->Draw(m_framebuffer.GetColorAttachmentTexture(m_previousFrameBuffer, 0), m_framebuffer, m_previousFrameBuffer, true, false);
}

// Swap framebuffer IDs for the next frame.
Expand All @@ -168,15 +175,15 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio
auto MilkdropPreset::OutputTexture() const -> std::shared_ptr<Renderer::Texture>
{
// the composited image is always stored in the "current" framebuffer after a frame is rendered.
return m_framebuffer.GetColorAttachmentTexture(m_currentFrameBuffer, 0);
return m_flipTexture->Texture();
}

void MilkdropPreset::DrawInitialImage(const std::shared_ptr<Renderer::Texture>& image, const Renderer::RenderContext& renderContext)
{
m_framebuffer.SetSize(renderContext.viewportSizeX, renderContext.viewportSizeY);

// Render to previous framebuffer, as this is the image used to draw the next frame on.
m_flipTexture.Draw(*renderContext.shaderCache, image, m_framebuffer, m_previousFrameBuffer);
m_flipTexture->Draw(image, m_framebuffer, m_previousFrameBuffer);
}

void MilkdropPreset::BindFramebuffer()
Expand Down
2 changes: 1 addition & 1 deletion src/libprojectM/MilkdropPreset/MilkdropPreset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class MilkdropPreset : public ::libprojectM::Preset
std::array<std::unique_ptr<CustomShape>, CustomShapeCount> m_customShapes; //!< Custom shapes in this preset.
DarkenCenter m_darkenCenter; //!< Center darkening effect.
Border m_border; //!< Inner/outer borders.
Renderer::CopyTexture m_flipTexture; //!< Texture flip filter
std::unique_ptr<Renderer::CopyTexture> m_flipTexture; //!< Texture flip filter

FinalComposite m_finalComposite; //!< Final composite shader or filters.

Expand Down
Loading
Loading