From 33606dc07142c5b979f42cedc56be7551f8e4c66 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 6 Oct 2024 07:36:46 +0200 Subject: [PATCH] set matrix with correct offset, minor fixes related with material changes --- CMakeLists.txt | 2 - src/qml/qmlwaveformdisplay.cpp | 21 ++++++-- src/rendergraph/common/rendergraph/material.h | 2 +- .../scenegraph/backend/basematerial.cpp | 4 +- .../scenegraph/backend/basematerial.h | 2 +- .../scenegraph/backend/basematerialshader.cpp | 4 +- .../renderers/allshader/digitsrenderer.cpp | 1 - .../allshader/matrixforwidgetgeometry.cpp | 8 --- .../allshader/matrixforwidgetgeometry.h | 13 ----- .../allshader/waveformrenderbeat.cpp | 8 +-- .../allshader/waveformrendererendoftrack.cpp | 48 +++++++++++------- .../allshader/waveformrendererfiltered.cpp | 3 +- .../allshader/waveformrendererhsv.cpp | 3 +- .../allshader/waveformrendererpreroll.cpp | 24 +++++---- .../allshader/waveformrendererrgb.cpp | 9 ++-- .../allshader/waveformrenderersimple.cpp | 3 +- .../allshader/waveformrendererstem.cpp | 3 +- .../allshader/waveformrendermark.cpp | 22 ++++++--- .../allshader/waveformrendermarkrange.cpp | 20 +++++--- .../allshader/waveformrendermarkrange.h | 3 +- .../renderers/waveformwidgetrenderer.cpp | 39 +++++++++++++-- .../renderers/waveformwidgetrenderer.h | 49 +++++++------------ 22 files changed, 160 insertions(+), 131 deletions(-) delete mode 100644 src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp delete mode 100644 src/waveform/renderers/allshader/matrixforwidgetgeometry.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 26c9cb18d30..044ce09bd99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1513,7 +1513,6 @@ if(QOPENGL) src/shaders/vinylqualityshader.cpp src/util/opengltexture2d.cpp src/waveform/renderers/allshader/digitsrenderer.cpp - src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbackground.cpp src/waveform/renderers/allshader/waveformrenderbeat.cpp src/waveform/renderers/allshader/waveformrenderer.cpp @@ -2794,7 +2793,6 @@ if(QML) src/waveform/renderers/waveformdisplayrange.cpp src/waveform/renderers/allshader/digitsrenderer.cpp - src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbeat.cpp src/waveform/renderers/allshader/waveformrenderer.cpp src/waveform/renderers/allshader/waveformrendererendoftrack.cpp diff --git a/src/qml/qmlwaveformdisplay.cpp b/src/qml/qmlwaveformdisplay.cpp index bc89ac29964..a42360e70b9 100644 --- a/src/qml/qmlwaveformdisplay.cpp +++ b/src/qml/qmlwaveformdisplay.cpp @@ -87,12 +87,24 @@ void QmlWaveformDisplay::geometryChange(const QRectF& newGeometry, const QRectF& } QSGNode* QmlWaveformDisplay::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { - if (m_dirtyFlag.testFlag(DirtyFlag::Geometry)) { - m_dirtyFlag.setFlag(DirtyFlag::Geometry, false); - setRect(mapRectToScene(boundingRect())); - } + // TODO the flag is not set when the position changes, + // but only when the size changes. Until we found a way + // to detect position changed, call setRect always + // (we check internally if the rect changed anyway) + // + // if (m_dirtyFlag.testFlag(DirtyFlag::Geometry)) { + // m_dirtyFlag.setFlag(DirtyFlag::Geometry, false); + // setRect(mapRectToScene(boundingRect())); + //} + setRect(mapRectToScene(boundingRect())); setViewport(window()->size()); setDevicePixelRatio(window()->devicePixelRatio()); + + // Will recalculate the matrix if any of the above changed. + // Nodes can use getMatrixChanged() to check if the matrix + // has changed and take appropriate action. + updateMatrix(); + auto* bgNode = dynamic_cast(node); if (!bgNode) { static int k = 0; @@ -110,6 +122,7 @@ QSGNode* QmlWaveformDisplay::updatePaintNode(QSGNode* node, UpdatePaintNodeData* m_pEngine = std::make_unique(std::move(pEndOfTrackNode)); m_pEngine->initialize(); } + return bgNode; } diff --git a/src/rendergraph/common/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h index e15ef5c0f1c..ab18e89166a 100644 --- a/src/rendergraph/common/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -30,7 +30,7 @@ class rendergraph::Material : public rendergraph::BaseMaterial { pOther->m_uniformsCache.data(), m_uniformsCache.size()); if (cacheCompareResult != 0) { - return cacheCompareResult; + return cacheCompareResult < 0 ? -1 : 1; } // TODO multiple textures if (!texture(0) || !pOther->texture(0)) { diff --git a/src/rendergraph/scenegraph/backend/basematerial.cpp b/src/rendergraph/scenegraph/backend/basematerial.cpp index e49606f8147..e65df9ee88e 100644 --- a/src/rendergraph/scenegraph/backend/basematerial.cpp +++ b/src/rendergraph/scenegraph/backend/basematerial.cpp @@ -4,9 +4,9 @@ using namespace rendergraph; -bool BaseMaterial::updateUniformsByteArray(QByteArray* buf) { +bool BaseMaterial::updateUniformsByteArray(QByteArray* buf, bool materialChanged) { auto pThis = static_cast(this); - if (pThis->clearUniformsCacheDirty()) { + if (pThis->clearUniformsCacheDirty() || materialChanged) { memcpy(buf->data(), pThis->uniformsCache().data(), pThis->uniformsCache().size()); return true; } diff --git a/src/rendergraph/scenegraph/backend/basematerial.h b/src/rendergraph/scenegraph/backend/basematerial.h index 7c745f3d991..8464d1c7138 100644 --- a/src/rendergraph/scenegraph/backend/basematerial.h +++ b/src/rendergraph/scenegraph/backend/basematerial.h @@ -15,5 +15,5 @@ class rendergraph::BaseMaterial : public QSGMaterial { int compare(const QSGMaterial* other) const override; - bool updateUniformsByteArray(QByteArray* buf); + bool updateUniformsByteArray(QByteArray* buf, bool materialChanged); }; diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.cpp b/src/rendergraph/scenegraph/backend/basematerialshader.cpp index b75fc8cdf98..f82602f547a 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.cpp +++ b/src/rendergraph/scenegraph/backend/basematerialshader.cpp @@ -9,7 +9,9 @@ using namespace rendergraph; bool BaseMaterialShader::updateUniformData(RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) { - return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); + return static_cast(newMaterial) + ->updateUniformsByteArray( + state.uniformData(), oldMaterial != newMaterial); } // override for QSGMaterialShader; this function is called by the Qt scene graph to prepare use of diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index 156f3d9601f..4e0c9a1507e 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -14,7 +14,6 @@ #include "rendergraph/geometry.h" #include "rendergraph/material/texturematerial.h" #include "rendergraph/vertexupdaters/texturedvertexupdater.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" // Render digits using a texture (generated) with digits with blurred dark outline diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp deleted file mode 100644 index 250c2abbaf8..00000000000 --- a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" - -#include "waveform/renderers/waveformwidgetrenderer.h" - -QMatrix4x4 matrixForWidgetGeometry(WaveformWidgetRenderer* const waveformRenderer, - bool applyDevicePixelRatio) { - return waveformRenderer->getMatrix(applyDevicePixelRatio); -} diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.h b/src/waveform/renderers/allshader/matrixforwidgetgeometry.h deleted file mode 100644 index 3240104085c..00000000000 --- a/src/waveform/renderers/allshader/matrixforwidgetgeometry.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -class WaveformWidgetRenderer; - -// Calculate the orthogonal project matrix for the WaveformWidgetRenderer, taking into account -// width and height, but also orientation (to rotate the matrix). -// Note that this allows us to basically use the same renderer code for horizontal and vertical -// orientation of the waveform, as we simply multiple the vertices with a rotated matrix in -// the vertex shaders. -QMatrix4x4 matrixForWidgetGeometry( - WaveformWidgetRenderer* const widget, bool applyDevicePixelRatio); diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 3c64987f92c..9c7d96ff045 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -8,7 +8,6 @@ #include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" #include "track/track.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" @@ -129,9 +128,10 @@ bool WaveformRenderBeat::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - - material().setUniform(0, matrix); + if (m_waveformRenderer->getMatrixChanged()) { + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); + material().setUniform(0, matrix); + } material().setUniform(1, m_color); markDirtyMaterial(); diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 7e990382684..10d64da0b2c 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -10,7 +10,6 @@ #include "rendergraph/material/rgbamaterial.h" #include "rendergraph/vertexupdaters/rgbavertexupdater.h" #include "util/colorcomponents.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" #include "widget/wskincolor.h" @@ -66,15 +65,19 @@ void WaveformRendererEndOfTrack::preprocess() { m_waveformRenderer->getGroup(), "time_remaining"); } + static int offset = 0; const int elapsedTotal = m_timer.elapsed().toIntegerMillis(); - const int elapsed = elapsedTotal % kBlinkingPeriodMillis; + const int elapsed = (elapsedTotal + offset) % kBlinkingPeriodMillis; + + // for testing + offset = (offset == 0) ? kBlinkingPeriodMillis / 4 : 0; if (elapsedTotal >= m_lastFrameCountLogged + 1000) { if (elapsedTotal >= m_lastFrameCountLogged + 2000) { m_lastFrameCountLogged = elapsedTotal; } m_lastFrameCountLogged += 1000; - qDebug() << m_frameCount; + qDebug() << "FPS:" << m_frameCount; m_frameCount = 0; } m_frameCount++; @@ -87,27 +90,33 @@ void WaveformRendererEndOfTrack::preprocess() { WaveformWidgetFactory::instance()->getEndOfTrackWarningTime(); const double criticalIntensity = static_cast(elapsed) / static_cast( - kBlinkingPeriodMillis); //(remainingTimeTriggerSeconds - - // remainingTime) / - // remainingTimeTriggerSeconds; + kBlinkingPeriodMillis); // TODO put back: + //(remainingTimeTriggerSeconds - + // remainingTime) / + // remainingTimeTriggerSeconds; const double alpha = std::max(0.0, std::min(1.0, criticalIntensity * blinkIntensity)); + bool forceSetUniformMatrix = false; + if (alpha != 0.0) { + const QSizeF& size = m_waveformRenderer->getSize(); float r, g, b, a; getRgbF(m_color, &r, &g, &b, &a); - const QRectF& rect = m_waveformRenderer->getRect(); - - const float posx0 = static_cast(rect.x()); - const float posx1 = static_cast(rect.x() + rect.width() / 2.0); - const float posx2 = static_cast(rect.x() + rect.width()); - const float posy1 = static_cast(rect.y()); - const float posy2 = static_cast(rect.y() + rect.height()); + const float posx0 = 0.f; + const float posx1 = size.width() / 2.f; + const float posx2 = size.width(); + const float posy1 = 0.f; + const float posy2 = size.height(); float minAlpha = 0.5f * static_cast(alpha); float maxAlpha = 0.83f * static_cast(alpha); + // force setting the uniform matrix if we start drawing + // after not drawing. + forceSetUniformMatrix = geometry().vertexCount() == 0; + geometry().allocate(6 * 2); RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs()}; vertexUpdater.addRectangleHGradient( @@ -115,17 +124,20 @@ void WaveformRendererEndOfTrack::preprocess() { vertexUpdater.addRectangleHGradient( {posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha}); - QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - material().setUniform(0, matrix); - markDirtyGeometry(); - markDirtyMaterial(); - } else { + } else if (geometry().vertexCount() != 0) { geometry().allocate(0); + markDirtyGeometry(); + } + if (m_waveformRenderer->getMatrixChanged() || forceSetUniformMatrix) { + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); + material().setUniform(0, matrix); + markDirtyMaterial(); } } bool WaveformRendererEndOfTrack::isSubtreeBlocked() const { + // TODO put back return false; // return !(!m_pEndOfTrackControl || m_pEndOfTrackControl->toBool()); } diff --git a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp index f48b1136f59..8fc2ae12c03 100644 --- a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp +++ b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp @@ -2,7 +2,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -142,7 +141,7 @@ void WaveformRendererFiltered::paintGL() { xVisualFrame += visualIncrementPerPixel; } - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int colorLocation = m_shader.colorLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererhsv.cpp b/src/waveform/renderers/allshader/waveformrendererhsv.cpp index 75b34dbae00..0f7565ecbca 100644 --- a/src/waveform/renderers/allshader/waveformrendererhsv.cpp +++ b/src/waveform/renderers/allshader/waveformrendererhsv.cpp @@ -3,7 +3,6 @@ #include "track/track.h" #include "util/colorcomponents.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -179,7 +178,7 @@ void WaveformRendererHSV::paintGL() { DEBUG_ASSERT(reserved == m_vertices.size()); DEBUG_ASSERT(reserved == m_colors.size()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int positionLocation = m_shader.positionLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 3316fb4ce8e..cddce054427 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -11,7 +11,6 @@ #include "rendergraph/material/patternmaterial.h" #include "rendergraph/vertexupdaters/texturedvertexupdater.h" #include "skin/legacy/skincontext.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" @@ -70,8 +69,8 @@ WaveformRendererPreroll::WaveformRendererPreroll( WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type) : ::WaveformRendererAbstract(waveformWidget), - m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip), - m_color(QColor(200, 25, 20)) { + m_color(QColor(200, 25, 20)), + m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { setMaterial(std::make_unique()); setGeometry(std::make_unique(PatternMaterial::attributes(), 0)); geometry().setDrawingMode(Geometry::DrawingMode::Triangles); @@ -216,16 +215,15 @@ bool WaveformRendererPreroll::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - // const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - QMatrix4x4 matrix; - // qDebug() << m_geometry << m_context.window()->effectiveDevicePixelRatio() - // << m_markerLength << m_markerBreadth << - // m_waveformRenderer->getDevicePixelRatio(); matrix.ortho(QRectF(0, 0, - // 1280, 400)); - matrix.ortho(QRectF(QPointF(0, -36), m_context.window()->size())); - - material().setUniform(0, matrix); - + if (m_waveformRenderer->getMatrixChanged()) { + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); + // qDebug() << m_geometry << m_context.window()->effectiveDevicePixelRatio() + // << m_markerLength << m_markerBreadth << + // m_waveformRenderer->getDevicePixelRatio(); matrix.ortho(QRectF(0, 0, + // 1280, 400)); + material().setUniform(0, matrix); + markDirtyMaterial(); + } return true; } diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.cpp b/src/waveform/renderers/allshader/waveformrendererrgb.cpp index eb2e318f311..f78f63838e0 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.cpp +++ b/src/waveform/renderers/allshader/waveformrendererrgb.cpp @@ -6,7 +6,6 @@ #include "rendergraph/vertexupdaters/rgbvertexupdater.h" #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -254,9 +253,11 @@ bool WaveformRendererRGB::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); - material().setUniform(0, matrix); - markDirtyMaterial(); + if (m_waveformRenderer->getMatrixChanged()) { + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(true); + material().setUniform(0, matrix); + markDirtyMaterial(); + } return true; } diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.cpp b/src/waveform/renderers/allshader/waveformrenderersimple.cpp index 90a707d2373..d4ad4fb2829 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.cpp +++ b/src/waveform/renderers/allshader/waveformrenderersimple.cpp @@ -2,7 +2,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -137,7 +136,7 @@ void WaveformRendererSimple::paintGL() { xVisualFrame += visualIncrementPerPixel; } - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int colorLocation = m_shader.colorLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererstem.cpp b/src/waveform/renderers/allshader/waveformrendererstem.cpp index c8dbe5a949c..9f3fbed2793 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.cpp +++ b/src/waveform/renderers/allshader/waveformrendererstem.cpp @@ -6,7 +6,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/allshader/rgbdata.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -180,7 +179,7 @@ void WaveformRendererStem::paintGL() { DEBUG_ASSERT(reserved == m_vertices.size()); DEBUG_ASSERT(reserved == m_colors.size()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int positionLocation = m_shader.positionLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index c0e4c3f83f4..cc1f0cfc9d9 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -13,7 +13,6 @@ #include "track/track.h" #include "util/colorcomponents.h" #include "waveform/renderers/allshader/digitsrenderer.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" @@ -44,9 +43,11 @@ class WaveformMarkNode : public rendergraph::GeometryNode { m_textureWidth = image.width(); m_textureHeight = image.height(); } - void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { + void updateMatrix(const QMatrix4x4& matrix) { material().setUniform(0, matrix); - + markDirtyMaterial(); + } + void update(float x, float y, float devicePixelRatio) { TexturedVertexUpdater vertexUpdater{ geometry().vertexDataAs()}; vertexUpdater.addRectangle({x, y}, @@ -75,8 +76,11 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { void updateTexture(const QImage& image) { waveformMarkNode()->updateTexture(image); } - void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(matrix, x, y, devicePixelRatio); + void updateMatrix(const QMatrix4x4& matrix) { + waveformMarkNode()->updateMatrix(matrix); + } + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); } float textureWidth() const { return waveformMarkNode()->textureWidth(); @@ -243,7 +247,8 @@ void allshader::WaveformRenderMark::update() { // (Will create textures so requires OpenGL context) updateMarkImages(); - QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); + const bool matrixChanged = m_waveformRenderer->getMatrixChanged(); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); @@ -292,7 +297,10 @@ void allshader::WaveformRenderMark::update() { if (drawOffset > -markHalfWidth && drawOffset < m_waveformRenderer->getLength() + markHalfWidth) { - pMarkNodeGraphics->update(matrix, + if (matrixChanged) { + pMarkNodeGraphics->updateMatrix(matrix); + } + pMarkNodeGraphics->update( drawOffset, !m_isSlipRenderer && slipActive ? m_waveformRenderer->getBreadth() / 2 diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index d7a77bfed1a..6ff727c9945 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -5,7 +5,6 @@ #include "rendergraph/material/unicolormaterial.h" #include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" using namespace rendergraph; @@ -40,8 +39,8 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRenderMarkRange::update() { - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - + const bool matrixChanged = m_waveformRenderer->getMatrixChanged(); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); TreeNode* pChild = firstChild(); for (const auto& markRange : m_markRanges) { @@ -82,8 +81,11 @@ void WaveformRenderMarkRange::update() { static_cast(pChild)->initForRectangles(1); } + if (matrixChanged) { + updateNodeMatrix(static_cast(pChild), matrix); + } + updateNode(static_cast(pChild), - matrix, color, {static_cast(startPosition), 0.f}, {static_cast(endPosition) + 1.f, @@ -98,15 +100,21 @@ void WaveformRenderMarkRange::update() { } } +void WaveformRenderMarkRange::updateNodeMatrix(GeometryNode* pChild, + const QMatrix4x4& matrix) { + pChild->material().setUniform(0, matrix); + pChild->markDirtyMaterial(); +} + void WaveformRenderMarkRange::updateNode(GeometryNode* pChild, - const QMatrix4x4& matrix, QColor color, QVector2D lt, QVector2D rb) { VertexUpdater vertexUpdater{pChild->geometry().vertexDataAs()}; vertexUpdater.addRectangle(lt, rb); - pChild->material().setUniform(0, matrix); pChild->material().setUniform(1, color); + pChild->markDirtyGeometry(); + pChild->markDirtyMaterial(); } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.h b/src/waveform/renderers/allshader/waveformrendermarkrange.h index 416f9fce03d..0f9ef8cb65b 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.h +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.h @@ -34,8 +34,9 @@ class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstra void update(); private: + void updateNodeMatrix(rendergraph::GeometryNode* pChild, + const QMatrix4x4& matrix); void updateNode(rendergraph::GeometryNode* pChild, - const QMatrix4x4& matrix, QColor color, QVector2D lt, QVector2D rb); diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index 876e79c9bbd..949b592b89d 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -25,13 +25,10 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group) : m_group(group), m_orientation(Qt::Horizontal), m_dimBrightThreshold(kDefaultDimBrightThreshold), - m_height(-1), - m_width(-1), - m_matricesDirty(false), + m_matrixNeedUpdate(false), + m_matrixChanged(false), m_devicePixelRatio(1.0f), - m_trackPixelCount(0.0), - m_zoomFactor(1.0), m_visualSamplePerPixel(1.0), m_audioSamplePerPixel(1.0), @@ -509,3 +506,35 @@ CuePointer WaveformWidgetRenderer::getCuePointerFromIndex(int cueIndex) const { } return {}; } + +void WaveformWidgetRenderer::updateMatrix() { + if (m_matrixNeedUpdate) { + qDebug() << "updating matrix with" << m_rect << m_viewport; + + m_matrix = QMatrix4x4(); + m_matrix.ortho(QRectF( + -m_rect.x(), + -m_rect.y(), + m_viewport.width(), + m_viewport.height())); + if (getOrientation() == Qt::Vertical) { + m_matrix.rotate(90.f, 0.0f, 0.0f, 1.0f); + m_matrix.translate(0.f, -m_viewport.width(), 0.f); + } + m_matrixDevicePixelRatio = QMatrix4x4(); + m_matrixDevicePixelRatio.ortho(QRectF( + -m_rect.x() * m_devicePixelRatio, + -m_rect.y() * m_devicePixelRatio, + m_viewport.width() * m_devicePixelRatio, + m_viewport.height() * m_devicePixelRatio)); + if (getOrientation() == Qt::Vertical) { + m_matrixDevicePixelRatio.rotate(90.f, 0.0f, 0.0f, 1.0f); + m_matrixDevicePixelRatio.translate( + 0.f, -m_viewport.width() * m_devicePixelRatio, 0.f); + } + m_matrixNeedUpdate = false; + m_matrixChanged = true; + } else { + m_matrixChanged = false; + } +} diff --git a/src/waveform/renderers/waveformwidgetrenderer.h b/src/waveform/renderers/waveformwidgetrenderer.h index 42fadee2306..5ec76a00066 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.h +++ b/src/waveform/renderers/waveformwidgetrenderer.h @@ -146,41 +146,41 @@ class WaveformWidgetRenderer { void setDevicePixelRatio(float devicePixelRatio) { if (m_devicePixelRatio != devicePixelRatio) { m_devicePixelRatio = devicePixelRatio; - m_matricesDirty = true; + m_matrixNeedUpdate = true; } } void setViewport(const QSize& viewport) { if (m_viewport != viewport) { m_viewport = viewport; - m_matricesDirty = true; + m_matrixNeedUpdate = true; } } void setRect(const QRectF& rect) { if (m_rect != rect) { m_rect = rect; - m_matricesDirty = true; + m_matrixNeedUpdate = true; } } const QSize getViewport() const { return m_viewport; } - const QRectF getRect() const { - return m_rect; + const QSizeF getSize() const { + return m_rect.size(); } int getHeight() const { - return m_height; + return static_cast(m_rect.height()); } int getWidth() const { - return m_width; + return static_cast(m_rect.width()); } float getDevicePixelRatio() const { return m_devicePixelRatio; } int getLength() const { - return m_orientation == Qt::Horizontal ? m_width : m_height; + return m_orientation == Qt::Horizontal ? getWidth() : getHeight(); } int getBreadth() const { - return m_orientation == Qt::Horizontal ? m_height : m_width; + return m_orientation == Qt::Horizontal ? getHeight() : getWidth(); } Qt::Orientation getOrientation() const { return m_orientation; @@ -225,29 +225,13 @@ class WaveformWidgetRenderer { return m_trackSamples <= 0.0 || m_pos[::WaveformRendererAbstract::Play] == -1; } + void updateMatrix(); + + bool getMatrixChanged() const { + return m_matrixChanged; + } + const QMatrix4x4& getMatrix(bool applyDevicePixelRatio) { - if (m_matricesDirty) { - m_matrix = QMatrix4x4(); - m_matrix.ortho(QRectF(0.0f, - 0.0f, - m_viewport.width(), - m_viewport.height())); - if (getOrientation() == Qt::Vertical) { - m_matrix.rotate(90.f, 0.0f, 0.0f, 1.0f); - m_matrix.translate(0.f, -m_viewport.width(), 0.f); - } - m_matrixDevicePixelRatio = QMatrix4x4(); - m_matrixDevicePixelRatio.ortho(QRectF(0.0f, - 0.0f, - m_viewport.width() * m_devicePixelRatio, - m_viewport.height() * m_devicePixelRatio)); - if (getOrientation() == Qt::Vertical) { - m_matrixDevicePixelRatio.rotate(90.f, 0.0f, 0.0f, 1.0f); - m_matrixDevicePixelRatio.translate( - 0.f, -m_viewport.width() * m_devicePixelRatio, 0.f); - } - m_matricesDirty = false; - } return applyDevicePixelRatio ? m_matrixDevicePixelRatio : m_matrix; } @@ -259,7 +243,8 @@ class WaveformWidgetRenderer { int m_dimBrightThreshold; int m_height; int m_width; - bool m_matricesDirty; + bool m_matrixNeedUpdate; + bool m_matrixChanged; QRectF m_rect; QSize m_viewport; QMatrix4x4 m_matrix;