Skip to content

[WIP] Renderer backend selection #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f3d6cca
doc
revmischa Apr 5, 2025
4049231
refactor: move OpenGL renderer code to backend directory
revmischa Apr 17, 2025
4fb83d4
fix: remove default parameter from CopyTexture::Draw targetTexture
revmischa Apr 17, 2025
6647484
refactor: comment out OpenGL-specific code in PresetTransition
revmischa Apr 17, 2025
e3192d0
refactor: move PresetTransition OpenGL code to backend
revmischa Apr 17, 2025
4a25a0b
refactor: move OpenGL transition rendering to backend implementation
revmischa Apr 17, 2025
9db68e5
chore: update gitignore and vendor submodule status
revmischa Apr 17, 2025
ef04f5b
fix: update CustomShape to use OpenGL backend implementation
revmischa Apr 17, 2025
fb1454b
refactor: add optional Init method to RenderItem base class
revmischa Apr 17, 2025
f075c52
fix: update OpenGL backend references in CustomShape
revmischa Apr 17, 2025
bc6533a
fix: resolve namespace and include issues in OpenGL render items
revmischa Apr 17, 2025
5cdfc8f
fix: Update render items to use OpenGL backend implementation
revmischa Apr 17, 2025
ee3873a
refactor: use flip texture for preset output instead of framebuffer
revmischa Apr 17, 2025
050966a
The changes update the inheritance of several classes (`PerPixelMesh`…
revmischa Apr 17, 2025
18273e5
fix: resolve OpenGL renderer initialization and texture creation errors
revmischa Apr 17, 2025
915ea97
fix: resolve compilation errors in MilkdropPreset and UserSprites
revmischa Apr 17, 2025
1480cab
fix: Resolve OpenGL initialization and header inclusion issues
revmischa Apr 17, 2025
219cfe2
fix: add missing include for OpenGLCopyTexture in MilkdropPreset.cpp
revmischa Apr 17, 2025
da05e7e
fix: change include to relative path in OpenGLCopyTexture.hpp
revmischa Apr 17, 2025
b18a5aa
refactor: update destructor override and return type for Texture()
revmischa Apr 17, 2025
6357e91
fix: remove 'override' from destructor and methods in OpenGLRenderIte…
revmischa Apr 17, 2025
8876cd5
fix: update method declarations to match base class and resolve errors
revmischa Apr 17, 2025
c72e401
fix: change include to local path in OpenGLRenderItem.hpp for correct…
revmischa Apr 17, 2025
542bfab
fix: use global namespace for RenderItem base class in OpenGLRenderIt…
revmischa Apr 17, 2025
2f80198
fix: add missing include for OpenGLPresetTransition in ProjectM.cpp
revmischa Apr 17, 2025
dd58ff4
refactor: add override specifiers to virtual functions for clarity an…
revmischa Apr 17, 2025
5cdddf9
refactor: unhide base Init() in derived classes to fix virtual warning
revmischa Apr 17, 2025
e136655
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 @@ -4,10 +4,9 @@ namespace libprojectM {
namespace MilkdropPreset {

Border::Border(PresetState& presetState)
: RenderItem()
, m_presetState(presetState)
: m_presetState(presetState)
{
RenderItem::Init();
Init();
}

void Border::InitVertexAttrib()
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 @@ -3,16 +3,15 @@
#include "PerFrameContext.hpp"
#include "PresetState.hpp"

#include "Renderer/RenderItem.hpp"
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

namespace libprojectM {
namespace MilkdropPreset {


/**
* @brief Renders a border around the screen.
*/
class Border : public Renderer::RenderItem
class Border : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
Border() = delete;
Expand Down
8 changes: 4 additions & 4 deletions src/libprojectM/MilkdropPreset/CustomShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "PresetFileParser.hpp"

#include <Renderer/TextureManager.hpp>
#include <Renderer/RenderItem.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

#include <vector>

Expand Down Expand Up @@ -47,7 +47,7 @@ CustomShape::CustomShape(PresetState& presetState)

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

RenderItem::Init();
Init();

m_perFrameContext.RegisterBuiltinVariables();
}
Expand Down Expand Up @@ -285,8 +285,8 @@ void CustomShape::Draw()
glEnable(GL_LINE_SMOOTH);
#endif

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

const auto iterations = m_thickOutline ? 4 : 1;

Expand Down
4 changes: 2 additions & 2 deletions src/libprojectM/MilkdropPreset/CustomShape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "ShapePerFrameContext.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 : public Renderer::RenderItem
class CustomShape : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem
{
public:
CustomShape(PresetState& presetState);
Expand Down
5 changes: 2 additions & 3 deletions src/libprojectM/MilkdropPreset/CustomWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace MilkdropPreset {
static constexpr int CustomWaveformMaxSamples = std::max(libprojectM::Audio::WaveformSamples, libprojectM::Audio::SpectrumSamples);

CustomWaveform::CustomWaveform(PresetState& presetState)
: RenderItem()
, m_presetState(presetState)
: m_presetState(presetState)
, m_perFrameContext(presetState.globalMemory, &presetState.globalRegisters)
, m_perPointContext(presetState.globalMemory, &presetState.globalRegisters)
{
RenderItem::Init();
Init();

m_perFrameContext.RegisterBuiltinVariables();
m_perPointContext.RegisterBuiltinVariables();
Expand Down
44 changes: 2 additions & 42 deletions src/libprojectM/MilkdropPreset/CustomWaveform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "WaveformPerFrameContext.hpp"
#include "WaveformPerPointContext.hpp"

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

#include <vector>

Expand All @@ -13,7 +13,7 @@ class PresetFileParser;

namespace MilkdropPreset {

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

Expand All @@ -23,61 +23,21 @@ class CustomWaveform : public Renderer::RenderItem
*/
explicit CustomWaveform(PresetState& presetState);

/**
* @brief Initializes the waveform's vertex buffer and attribute data.
*/
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(::libprojectM::PresetFileParser& parsedFile, int index);

/**
* @brief Compiles all code blocks and runs the init expression.
* @throws MilkdropCompileException Thrown if one of the code blocks couldn't be compiled.
* @param presetPerFrameContext The per-frame context to retrieve the init Q vars from.
*/
void CompileCodeAndRunInitExpressions(const PerFrameContext& presetPerFrameContext);

/**
* @brief Renders the waveform.
* @param presetPerFrameContext The per-frame context to retrieve the init Q vars from.
*/
void Draw(const PerFrameContext& presetPerFrameContext);

private:
/**
* @brief Initializes the per-frame context with the preset per-frame state.
* @param presetPerFrameContext The preset per-frame context to pull q vars from.
*/
void LoadPerFrameEvaluationVariables(const PerFrameContext& presetPerFrameContext);

/**
* @brief Loads the Q and T variables from the per-frame code into the per-point context.
*/
void InitPerPointEvaluationVariables();

/**
* @brief Loads the variables for each point into the per-point evaluation context.
* @param sample The sample index being rendered.
* @param value1 The left channel value.
* @param value2 The right channel value.
*/
void LoadPerPointEvaluationVariables(float sample, float value1, float value2);

/**
* @brief Does a better-than-linear smooth on a wave.
*
* Roughly doubles the number of points.
*
* @param inputVertices Pointer to an array of vertices to be smoothed.
* @param vertexCount Number of vertices/points in the input data.
* @param outputVertices Pointer to a buffer that will receive the smoothed data. Must be able to hold 2 * vertexCount vertices.
* @return The number of vertices in outputVertices after smoothing.
*/
static int SmoothWave(const ColoredPoint* inputVertices, int vertexCount, ColoredPoint* outputVertices);

int m_index{0}; //!< Custom waveform index in the preset.
Expand Down
5 changes: 2 additions & 3 deletions src/libprojectM/MilkdropPreset/DarkenCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ namespace libprojectM {
namespace MilkdropPreset {

DarkenCenter::DarkenCenter(PresetState& presetState)
: RenderItem()
, m_presetState(presetState)
: m_presetState(presetState)
{
RenderItem::Init();
Init();
}

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

#include "PresetState.hpp"

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

namespace libprojectM {
namespace MilkdropPreset {

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

explicit DarkenCenter(PresetState& presetState);

void InitVertexAttrib();
void InitVertexAttrib() override;

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

Filters::Filters(const PresetState& presetState)
: RenderItem()
, m_presetState(presetState)
: m_presetState(presetState)
{
RenderItem::Init();
Init();
}

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

#include "PresetState.hpp"

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

namespace libprojectM {
namespace MilkdropPreset {

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

void InitVertexAttrib();
void InitVertexAttrib() override;

/**
* @brief Applies the configured filters to the current output.
Expand Down
2 changes: 1 addition & 1 deletion src/libprojectM/MilkdropPreset/FinalComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static std::string const defaultCompositeShader = "shader_body\n{\nret = tex2D(s

FinalComposite::FinalComposite()
{
RenderItem::Init();
Init();
}

void FinalComposite::InitVertexAttrib()
Expand Down
35 changes: 2 additions & 33 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/RenderItem.hpp>
#include <Renderer/Backend/OpenGL/OpenGLRenderItem.hpp>

#include <array>
#include <memory>
Expand All @@ -15,43 +15,23 @@ namespace MilkdropPreset {
/**
* @brief Draws the final composite effect, either a shader or Milkdrop 1 effects.
*/
class FinalComposite : public Renderer::RenderItem
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.
*/
void LoadCompositeShader(const PresetState& presetState);

/**
* @brief Loads the required textures and compiles the composite shader.
* @param presetState The preset state to retrieve the configuration values from.
*/
void CompileCompositeShader(PresetState& presetState);

/**
* @brief Renders the composite quad with the appropriate effects or shaders.
* @param presetState The preset state to retrieve the configuration values from.
* @param presetPerFrameContext The per-frame context to retrieve the initial vars from.
*/
void Draw(const PresetState& presetState,
const PerFrameContext& perFrameContext);

/**
* @brief Returns if the final composite is using a shader or classic filters.
* @return true if the final composite is done via a shader, false if not.
*/
auto HasCompositeShader() const -> bool;

private:
/**
* Composite mesh vertex with all required attributes.
*/
struct MeshVertex {
float x{}; //!< Vertex X coordinate.
float y{}; //!< Vertex Y coordinate.
Expand All @@ -65,24 +45,13 @@ class FinalComposite : public Renderer::RenderItem
float angle{};
};

/**
* @brief Initializes the vertex array and fills in static data if needed.
*
* The vertices will only be reinitialized if the viewport size changed.
*
* @param presetState The preset state to retrieve the configuration values from.
*/
void InitializeMesh(const PresetState& presetState);

static float SquishToCenter(float x, float exponent);

static void UvToMathSpace(float aspectX, float aspectY,
float u, float v, float& rad, float& ang);

/**
* @brief Calculates the randomized, slowly changing diffuse colors.
* @param presetState The preset state to retrieve the configuration values from.
*/
void ApplyHueShaderColors(const PresetState& presetState);

static constexpr int compositeGridWidth{32};
Expand Down
Loading
Loading