|
| 1 | +From: ProjectM TV contributors |
| 2 | +Subject: [PATCH] Build the warp and composite meshes once per viewport size |
| 3 | + |
| 4 | +PerPixelMesh and FinalComposite compare the viewport against m_viewportWidth/Height |
| 5 | +to skip rebuilding their static mesh data, but nothing ever stored those values. Both |
| 6 | +meshes were therefore rebuilt every frame: per-vertex hypotf/atan2f, the full index |
| 7 | +list, and (warp mesh) the vertex positions and index buffer uploaded again. |
| 8 | +Record the viewport size when the data is built; the warp mesh uploads its static |
| 9 | +vertices and indices only after a rebuild. The values written are unchanged, so the |
| 10 | +rendered image is identical; only the repeated CPU work and uploads are removed. |
| 11 | + |
| 12 | +--- |
| 13 | +diff --git a/src/libprojectM/MilkdropPreset/FinalComposite.cpp b/src/libprojectM/MilkdropPreset/FinalComposite.cpp |
| 14 | +index 18209831e..f07c802c4 100644 |
| 15 | +--- a/src/libprojectM/MilkdropPreset/FinalComposite.cpp |
| 16 | ++++ b/src/libprojectM/MilkdropPreset/FinalComposite.cpp |
| 17 | +@@ -139,6 +139,10 @@ void FinalComposite::InitializeMesh(const PresetState& presetState) |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | ++ // The grid only depends on the viewport size: build it once per size, not every frame. |
| 22 | ++ m_viewportWidth = presetState.renderContext.viewportSizeX; |
| 23 | ++ m_viewportHeight = presetState.renderContext.viewportSizeY; |
| 24 | ++ |
| 25 | + float const dividedByX = 1.0f / static_cast<float>(compositeGridWidth - 2); |
| 26 | + float const dividedByY = 1.0f / static_cast<float>(compositeGridHeight - 2); |
| 27 | + |
| 28 | +diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp |
| 29 | +index e3332dad6..c67423e87 100644 |
| 30 | +--- a/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp |
| 31 | ++++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.cpp |
| 32 | +@@ -158,6 +158,12 @@ void PerPixelMesh::InitializeMesh(const PresetState& presetState) |
| 33 | + const float aspectX = presetState.renderContext.aspectX; |
| 34 | + const float aspectY = presetState.renderContext.aspectY; |
| 35 | + |
| 36 | ++ // Remember what the static mesh data is built for, so it is only rebuilt and uploaded again |
| 37 | ++ // when the viewport or the grid changes, not every frame. |
| 38 | ++ m_viewportWidth = presetState.renderContext.viewportSizeX; |
| 39 | ++ m_viewportHeight = presetState.renderContext.viewportSizeY; |
| 40 | ++ m_meshDirty = true; |
| 41 | ++ |
| 42 | + // Either viewport size or mesh size changed, reinitialize the vertices. |
| 43 | + auto& vertices = m_warpMesh.Vertices(); |
| 44 | + int vertexIndex{0}; |
| 45 | +@@ -313,7 +319,12 @@ void PerPixelMesh::CalculateMesh(const PresetState& presetState, const PerFrameC |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | +- m_warpMesh.Update(); |
| 50 | ++ // Vertex positions and indices only change when InitializeMesh() rebuilt them. |
| 51 | ++ if (m_meshDirty) |
| 52 | ++ { |
| 53 | ++ m_warpMesh.Update(); |
| 54 | ++ m_meshDirty = false; |
| 55 | ++ } |
| 56 | + m_radiusAngleBuffer.Update(); |
| 57 | + m_zoomRotWarpBuffer.Update(); |
| 58 | + m_centerBuffer.Update(); |
| 59 | +diff --git a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp |
| 60 | +index 0b589bc54..ef866120e 100644 |
| 61 | +--- a/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp |
| 62 | ++++ b/src/libprojectM/MilkdropPreset/PerPixelMesh.hpp |
| 63 | +@@ -146,6 +146,7 @@ private: |
| 64 | + |
| 65 | + int m_viewportWidth{}; //!< Last known viewport width. |
| 66 | + int m_viewportHeight{}; //!< Last known viewport height. |
| 67 | ++ bool m_meshDirty{true}; //!< Vertex positions and indices must be uploaded before the next draw. |
| 68 | + |
| 69 | + Renderer::Mesh m_warpMesh; //!< The Warp effect mesh |
| 70 | + Renderer::VertexBuffer<RadiusAngle> m_radiusAngleBuffer{Renderer::VertexBufferUsage::StreamDraw}; //!< Vertex attribute buffer for radius and angle values. |
0 commit comments