diff --git a/.gitignore b/.gitignore index aface6d10e..6e5e388bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ src/libprojectM/build/ # CLion cmake-build-* .idea +.aider* diff --git a/src/libprojectM/MilkdropPreset/Border.cpp b/src/libprojectM/MilkdropPreset/Border.cpp index f5805e4e80..7f25c0364d 100644 --- a/src/libprojectM/MilkdropPreset/Border.cpp +++ b/src/libprojectM/MilkdropPreset/Border.cpp @@ -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({ { diff --git a/src/libprojectM/MilkdropPreset/Border.hpp b/src/libprojectM/MilkdropPreset/Border.hpp index 839398ca19..1baaafb467 100644 --- a/src/libprojectM/MilkdropPreset/Border.hpp +++ b/src/libprojectM/MilkdropPreset/Border.hpp @@ -2,16 +2,15 @@ #include "PresetState.hpp" -#include +#include namespace libprojectM { namespace MilkdropPreset { - /** * @brief Renders a border around the screen. */ -class Border +class Border : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: Border() = delete; diff --git a/src/libprojectM/MilkdropPreset/CustomShape.cpp b/src/libprojectM/MilkdropPreset/CustomShape.cpp index 1acbeb2395..122f89b1b0 100644 --- a/src/libprojectM/MilkdropPreset/CustomShape.cpp +++ b/src/libprojectM/MilkdropPreset/CustomShape.cpp @@ -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(offsetof(TexturedPoint, x))); // Position + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(offsetof(TexturedPoint, r))); // Color + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(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(offsetof(TexturedPoint, x))); // Position + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(offsetof(TexturedPoint, r))); // Color + + glBufferData(GL_ARRAY_BUFFER, sizeof(TexturedPoint) * vertexData.size(), vertexData.data(), GL_STREAM_DRAW); + + Init(); m_perFrameContext.RegisterBuiltinVariables(); } diff --git a/src/libprojectM/MilkdropPreset/CustomShape.hpp b/src/libprojectM/MilkdropPreset/CustomShape.hpp index 5090b37eb7..49c7d2a82d 100644 --- a/src/libprojectM/MilkdropPreset/CustomShape.hpp +++ b/src/libprojectM/MilkdropPreset/CustomShape.hpp @@ -4,8 +4,8 @@ #include "PresetState.hpp" #include "ShapePerFrameContext.hpp" -#include - +#include +#include #include namespace libprojectM { @@ -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); diff --git a/src/libprojectM/MilkdropPreset/CustomWaveform.cpp b/src/libprojectM/MilkdropPreset/CustomWaveform.cpp index 3ca7bbe755..8f5d83f9cd 100644 --- a/src/libprojectM/MilkdropPreset/CustomWaveform.cpp +++ b/src/libprojectM/MilkdropPreset/CustomWaveform.cpp @@ -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(); diff --git a/src/libprojectM/MilkdropPreset/CustomWaveform.hpp b/src/libprojectM/MilkdropPreset/CustomWaveform.hpp index 7c4c3df1a2..609aded314 100644 --- a/src/libprojectM/MilkdropPreset/CustomWaveform.hpp +++ b/src/libprojectM/MilkdropPreset/CustomWaveform.hpp @@ -3,9 +3,7 @@ #include "WaveformPerFrameContext.hpp" #include "WaveformPerPointContext.hpp" -#include -#include -#include +#include #include @@ -14,7 +12,9 @@ namespace MilkdropPreset { class PresetFileParser; -class CustomWaveform +namespace MilkdropPreset { + +class CustomWaveform : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: @@ -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. @@ -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& points, const std::vector& 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. diff --git a/src/libprojectM/MilkdropPreset/DarkenCenter.cpp b/src/libprojectM/MilkdropPreset/DarkenCenter.cpp index 1bd1d8a126..ae2266ae52 100644 --- a/src/libprojectM/MilkdropPreset/DarkenCenter.cpp +++ b/src/libprojectM/MilkdropPreset/DarkenCenter.cpp @@ -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(offsetof(ColoredPoint, r))); // colors } void DarkenCenter::Draw() diff --git a/src/libprojectM/MilkdropPreset/DarkenCenter.hpp b/src/libprojectM/MilkdropPreset/DarkenCenter.hpp index b6921d1a07..903c5ebb30 100644 --- a/src/libprojectM/MilkdropPreset/DarkenCenter.hpp +++ b/src/libprojectM/MilkdropPreset/DarkenCenter.hpp @@ -2,7 +2,7 @@ #include "PresetState.hpp" -#include +#include namespace libprojectM { namespace MilkdropPreset { @@ -10,13 +10,15 @@ 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. */ diff --git a/src/libprojectM/MilkdropPreset/Filters.cpp b/src/libprojectM/MilkdropPreset/Filters.cpp index e5d8702df1..225f6e6415 100644 --- a/src/libprojectM/MilkdropPreset/Filters.cpp +++ b/src/libprojectM/MilkdropPreset/Filters.cpp @@ -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(offsetof(Point, x))); } void Filters::Draw() diff --git a/src/libprojectM/MilkdropPreset/Filters.hpp b/src/libprojectM/MilkdropPreset/Filters.hpp index 1decfcafb8..9b915b4d43 100644 --- a/src/libprojectM/MilkdropPreset/Filters.hpp +++ b/src/libprojectM/MilkdropPreset/Filters.hpp @@ -2,7 +2,7 @@ #include "PresetState.hpp" -#include +#include namespace libprojectM { namespace MilkdropPreset { @@ -10,12 +10,14 @@ 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. */ diff --git a/src/libprojectM/MilkdropPreset/FinalComposite.cpp b/src/libprojectM/MilkdropPreset/FinalComposite.cpp index 693df44935..71692ad558 100644 --- a/src/libprojectM/MilkdropPreset/FinalComposite.cpp +++ b/src/libprojectM/MilkdropPreset/FinalComposite.cpp @@ -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(); diff --git a/src/libprojectM/MilkdropPreset/FinalComposite.hpp b/src/libprojectM/MilkdropPreset/FinalComposite.hpp index 9701447706..0876a47a84 100644 --- a/src/libprojectM/MilkdropPreset/FinalComposite.hpp +++ b/src/libprojectM/MilkdropPreset/FinalComposite.hpp @@ -4,7 +4,7 @@ #include "MilkdropShader.hpp" #include "VideoEcho.hpp" -#include +#include #include @@ -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. diff --git a/src/libprojectM/MilkdropPreset/MilkdropPreset.cpp b/src/libprojectM/MilkdropPreset/MilkdropPreset.cpp index ef1716115b..284b5a84bf 100755 --- a/src/libprojectM/MilkdropPreset/MilkdropPreset.cpp +++ b/src/libprojectM/MilkdropPreset/MilkdropPreset.cpp @@ -24,6 +24,7 @@ #include "Factory.hpp" #include "MilkdropPresetExceptions.hpp" #include "PresetFileParser.hpp" +#include #include @@ -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()) { + // Ensure OpenGLCopyTexture is visible to this translation unit + // (include the header if not already included at the top of this file) Load(absoluteFilePath); } @@ -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()) { + // Ensure OpenGLCopyTexture is visible to this translation unit + // (include the header if not already included at the top of this file) Load(presetData); } @@ -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); @@ -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); @@ -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. @@ -168,7 +175,7 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio auto MilkdropPreset::OutputTexture() const -> std::shared_ptr { // 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& image, const Renderer::RenderContext& renderContext) @@ -176,7 +183,7 @@ void MilkdropPreset::DrawInitialImage(const std::shared_ptr& 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() diff --git a/src/libprojectM/MilkdropPreset/MilkdropPreset.hpp b/src/libprojectM/MilkdropPreset/MilkdropPreset.hpp index db8eb43ba4..e702f05a78 100644 --- a/src/libprojectM/MilkdropPreset/MilkdropPreset.hpp +++ b/src/libprojectM/MilkdropPreset/MilkdropPreset.hpp @@ -124,7 +124,7 @@ class MilkdropPreset : public ::libprojectM::Preset std::array, 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 m_flipTexture; //!< Texture flip filter FinalComposite m_finalComposite; //!< Final composite shader or filters. diff --git a/src/libprojectM/MilkdropPreset/MotionVectors.cpp b/src/libprojectM/MilkdropPreset/MotionVectors.cpp index 5cd31b111b..2b9a197bf0 100644 --- a/src/libprojectM/MilkdropPreset/MotionVectors.cpp +++ b/src/libprojectM/MilkdropPreset/MotionVectors.cpp @@ -13,9 +13,18 @@ namespace MilkdropPreset { MotionVectors::MotionVectors(PresetState& presetState) : m_presetState(presetState) - , m_motionVectorMesh(Renderer::VertexBufferUsage::StreamDraw) { - m_motionVectorMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::Lines); + Init(); +} + +void MotionVectors::InitVertexAttrib() +{ + glEnableVertexAttribArray(0); + glDisableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(MotionVectorVertex), reinterpret_cast(offsetof(MotionVectorVertex, x))); + glVertexAttribIPointer(2, 1, GL_INT, sizeof(MotionVectorVertex), reinterpret_cast(offsetof(MotionVectorVertex, index))); } void MotionVectors::Draw(const PerFrameContext& presetPerFrameContext, std::shared_ptr motionTexture) diff --git a/src/libprojectM/MilkdropPreset/MotionVectors.hpp b/src/libprojectM/MilkdropPreset/MotionVectors.hpp index 93e44124b2..84fbb074b1 100644 --- a/src/libprojectM/MilkdropPreset/MotionVectors.hpp +++ b/src/libprojectM/MilkdropPreset/MotionVectors.hpp @@ -3,7 +3,7 @@ #include "PerFrameContext.hpp" #include "PresetState.hpp" -#include +#include #include @@ -12,24 +12,16 @@ namespace MilkdropPreset { /** * @brief Draws a flexible motion vector field. - * - * Uses the same drawing logic as Milkdrop, but instead of reverse-propagating the motion data - * on the CPU, projectM does this within the Motion Vector vertex shader. The Warp effect draws the - * final U/V coordinates to a float texture, which is then used in the next frame to calculate the - * vector length at the location of the line origin. */ -class MotionVectors +class MotionVectors : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: MotionVectors() = delete; explicit MotionVectors(PresetState& presetState); - /** - * Renders the motion vectors. - * @param presetPerFrameContext The per-frame context variables. - * @param motionTexture The u/v "motion" texture written by the warp shader. - */ + void InitVertexAttrib() override; + void Draw(const PerFrameContext& presetPerFrameContext, std::shared_ptr motionTexture); private: diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp index 6e2bf9cc1c..a3881677dd 100644 --- a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp +++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp @@ -17,9 +17,9 @@ namespace libprojectM { namespace MilkdropPreset { PerPixelMesh::PerPixelMesh() - : m_warpMesh(Renderer::VertexBufferUsage::StreamDraw) { - m_warpMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::Triangles); + Init(); +} m_warpMesh.Bind(); m_radiusAngleBuffer.Bind(); diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp index dda77f114b..01038f6299 100644 --- a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp +++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace libprojectM { @@ -24,7 +24,7 @@ class MilkdropShader; * * The mesh size can be changed between frames, the class will reallocate the buffers if needed. */ -class PerPixelMesh +class PerPixelMesh : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: PerPixelMesh(); diff --git a/src/libprojectM/MilkdropPreset/VideoEcho.cpp b/src/libprojectM/MilkdropPreset/VideoEcho.cpp index 21b7399d89..dfa0b42342 100644 --- a/src/libprojectM/MilkdropPreset/VideoEcho.cpp +++ b/src/libprojectM/MilkdropPreset/VideoEcho.cpp @@ -7,10 +7,19 @@ namespace MilkdropPreset { VideoEcho::VideoEcho(const PresetState& presetState) : m_presetState(presetState) - , m_echoMesh(Renderer::VertexBufferUsage::DynamicDraw, true, true) { - m_echoMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleStrip); - m_echoMesh.SetVertexCount(4); + Init(); +} + +void VideoEcho::InitVertexAttrib() +{ + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(offsetof(TexturedPoint, x))); // Position + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(offsetof(TexturedPoint, r))); // Color + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedPoint), reinterpret_cast(offsetof(TexturedPoint, u))); // Texture coordinates } void VideoEcho::Draw() diff --git a/src/libprojectM/MilkdropPreset/VideoEcho.hpp b/src/libprojectM/MilkdropPreset/VideoEcho.hpp index 1077ba4f66..1986f24a45 100644 --- a/src/libprojectM/MilkdropPreset/VideoEcho.hpp +++ b/src/libprojectM/MilkdropPreset/VideoEcho.hpp @@ -3,7 +3,9 @@ #include "PerFrameContext.hpp" #include "PresetState.hpp" -#include +#include + +#include namespace libprojectM { namespace MilkdropPreset { @@ -11,13 +13,15 @@ namespace MilkdropPreset { /** * @brief Renders a video "echo" (ghost image) effect and gamma adjustments. */ -class VideoEcho +class VideoEcho : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: - VideoEcho() = delete; + VideoEcho() = delete; explicit VideoEcho(const PresetState& presetState); - void Draw(); + void InitVertexAttrib() override; + + void Draw(); private: void DrawVideoEcho(); diff --git a/src/libprojectM/MilkdropPreset/Waveform.cpp b/src/libprojectM/MilkdropPreset/Waveform.cpp index 78c3a97b7a..e719f0e94e 100644 --- a/src/libprojectM/MilkdropPreset/Waveform.cpp +++ b/src/libprojectM/MilkdropPreset/Waveform.cpp @@ -17,8 +17,20 @@ namespace MilkdropPreset { Waveform::Waveform(PresetState& presetState) : m_presetState(presetState) - , m_waveMesh(Renderer::VertexBufferUsage::StreamDraw) { + Init(); +} + +void Waveform::InitVertexAttrib() +{ + glEnableVertexAttribArray(0); + glDisableVertexAttribArray(1); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr); + + std::vector vertexData; + vertexData.resize(std::max(libprojectM::Audio::SpectrumSamples, libprojectM::Audio::WaveformSamples) * 2 + 2); + glBufferData(GL_ARRAY_BUFFER, sizeof(Point) * vertexData.size(), vertexData.data(), GL_STREAM_DRAW); } void Waveform::Draw(const PerFrameContext& presetPerFrameContext) diff --git a/src/libprojectM/MilkdropPreset/Waveform.hpp b/src/libprojectM/MilkdropPreset/Waveform.hpp index 5e6084aab8..7fd25a1580 100644 --- a/src/libprojectM/MilkdropPreset/Waveform.hpp +++ b/src/libprojectM/MilkdropPreset/Waveform.hpp @@ -4,7 +4,7 @@ #include "Waveforms/WaveformMath.hpp" -#include +#include #include @@ -14,7 +14,7 @@ namespace MilkdropPreset { class PresetState; class PerFrameContext; -class Waveform +class Waveform : public libprojectM::Renderer::Backend::OpenGL::OpenGLRenderItem { public: explicit Waveform(PresetState& presetState); diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 9ec73afac7..5d36477553 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -25,10 +25,11 @@ #include "Preset.hpp" #include "PresetFactoryManager.hpp" #include "TimeKeeper.hpp" +#include "Renderer/Backend/OpenGL/OpenGLPresetTransition.hpp" #include