Skip to content

Commit

Permalink
set matrix with correct offset, minor fixes related with material cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
m0dB authored and m0dB committed Oct 6, 2024
1 parent 2f8098e commit 33606dc
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 131 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions src/qml/qmlwaveformdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSGSimpleRectNode*>(node);
if (!bgNode) {
static int k = 0;
Expand All @@ -110,6 +122,7 @@ QSGNode* QmlWaveformDisplay::updatePaintNode(QSGNode* node, UpdatePaintNodeData*
m_pEngine = std::make_unique<rendergraph::Engine>(std::move(pEndOfTrackNode));
m_pEngine->initialize();
}

return bgNode;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rendergraph/common/rendergraph/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/rendergraph/scenegraph/backend/basematerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

using namespace rendergraph;

bool BaseMaterial::updateUniformsByteArray(QByteArray* buf) {
bool BaseMaterial::updateUniformsByteArray(QByteArray* buf, bool materialChanged) {
auto pThis = static_cast<Material*>(this);
if (pThis->clearUniformsCacheDirty()) {
if (pThis->clearUniformsCacheDirty() || materialChanged) {
memcpy(buf->data(), pThis->uniformsCache().data(), pThis->uniformsCache().size());
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rendergraph/scenegraph/backend/basematerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
4 changes: 3 additions & 1 deletion src/rendergraph/scenegraph/backend/basematerialshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ using namespace rendergraph;
bool BaseMaterialShader::updateUniformData(RenderState& state,
QSGMaterial* newMaterial,
QSGMaterial* oldMaterial) {
return static_cast<Material*>(newMaterial)->updateUniformsByteArray(state.uniformData());
return static_cast<Material*>(newMaterial)
->updateUniformsByteArray(
state.uniformData(), oldMaterial != newMaterial);
}

// override for QSGMaterialShader; this function is called by the Qt scene graph to prepare use of
Expand Down
1 change: 0 additions & 1 deletion src/waveform/renderers/allshader/digitsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/waveform/renderers/allshader/matrixforwidgetgeometry.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/waveform/renderers/allshader/waveformrenderbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();

Expand Down
48 changes: 30 additions & 18 deletions src/waveform/renderers/allshader/waveformrendererendoftrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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++;
Expand All @@ -87,45 +90,54 @@ void WaveformRendererEndOfTrack::preprocess() {
WaveformWidgetFactory::instance()->getEndOfTrackWarningTime();
const double criticalIntensity = static_cast<double>(elapsed) /
static_cast<double>(
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<float>(rect.x());
const float posx1 = static_cast<float>(rect.x() + rect.width() / 2.0);
const float posx2 = static_cast<float>(rect.x() + rect.width());
const float posy1 = static_cast<float>(rect.y());
const float posy2 = static_cast<float>(rect.y() + rect.height());
const float posx0 = 0.f;
const float posx1 = size.width() / 2.f;

Check warning on line 108 in src/waveform/renderers/allshader/waveformrendererendoftrack.cpp

View workflow job for this annotation

GitHub Actions / coverage

conversion from ‘qreal’ {aka ‘double’} to ‘float’ may change value [-Wfloat-conversion]
const float posx2 = size.width();
const float posy1 = 0.f;
const float posy2 = size.height();

float minAlpha = 0.5f * static_cast<float>(alpha);
float maxAlpha = 0.83f * static_cast<float>(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<Geometry::RGBAColoredPoint2D>()};
vertexUpdater.addRectangleHGradient(
{posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha});
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/waveform/renderers/allshader/waveformrendererhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
24 changes: 11 additions & 13 deletions src/waveform/renderers/allshader/waveformrendererpreroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<PatternMaterial>());
setGeometry(std::make_unique<Geometry>(PatternMaterial::attributes(), 0));
geometry().setDrawingMode(Geometry::DrawingMode::Triangles);
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 5 additions & 4 deletions src/waveform/renderers/allshader/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/waveform/renderers/allshader/waveformrenderersimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/waveform/renderers/allshader/waveformrendererstem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 33606dc

Please sign in to comment.