Skip to content
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

improve glsl pre-roll triangles #12100

Merged
merged 14 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion src/shaders/endoftrackshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace mixxx;

void EndOfTrackShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) to assign directly to gl_Position
attribute highp float gradient;
varying highp float vgradient;
void main()
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/patternshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void PatternShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform highp mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
attribute highp vec2 texcoor;
varying highp vec2 vTexcoor;
void main()
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/rgbashader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void RGBAShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
attribute highp vec4 color;
varying highp vec4 vColor;
void main()
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/rgbshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void RGBShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
attribute highp vec3 color;
varying highp vec3 vColor;
void main()
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/textureshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void TextureShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform highp mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
attribute highp vec2 texcoord;
varying highp vec2 vTexcoord;
void main()
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/unicolorshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void UnicolorShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
void main()
{
gl_Position = matrix * position;
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/vinylqualityshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace mixxx;
void VinylQualityShader::init() {
QString vertexShaderCode = QStringLiteral(R"--(
uniform mat4 matrix;
attribute highp vec4 position;
attribute highp vec4 position; // use vec4 here (will be padded) for matrix multiplication
attribute highp vec2 texcoord;
varying highp vec2 vTexcoord;
void main()
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
16 changes: 8 additions & 8 deletions src/util/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#include "util/texture.h"

QOpenGLTexture* createTexture(const QImage& image) {
std::unique_ptr<QOpenGLTexture> createTexture(const QImage& image) {
if (image.isNull()) {
return nullptr;
return std::unique_ptr<QOpenGLTexture>{};
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved
}
QOpenGLTexture* pTexture = new QOpenGLTexture(image);
std::unique_ptr<QOpenGLTexture> pTexture{new QOpenGLTexture(image)};
m0dB marked this conversation as resolved.
Show resolved Hide resolved
pTexture->setMinificationFilter(QOpenGLTexture::Linear);
pTexture->setMagnificationFilter(QOpenGLTexture::Linear);
pTexture->setWrapMode(QOpenGLTexture::ClampToEdge);

return pTexture;
}

QOpenGLTexture* createTexture(const QPixmap& pixmap) {
std::unique_ptr<QOpenGLTexture> createTexture(const QPixmap& pixmap) {
return createTexture(pixmap.toImage());
}

QOpenGLTexture* createTexture(const QSharedPointer<Paintable>& pPaintable) {
std::unique_ptr<QOpenGLTexture> createTexture(const QSharedPointer<Paintable>& pPaintable) {
if (pPaintable.isNull()) {
return nullptr;
return std::unique_ptr<QOpenGLTexture>{};
}
return createTexture(pPaintable->toImage());
}

QOpenGLTexture* createTexture(const std::shared_ptr<QImage>& pImage) {
std::unique_ptr<QOpenGLTexture> createTexture(const std::shared_ptr<QImage>& pImage) {
if (!pImage) {
return nullptr;
return std::unique_ptr<QOpenGLTexture>{};
}
return createTexture(*pImage);
}
8 changes: 4 additions & 4 deletions src/util/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "widget/paintable.h"

QOpenGLTexture* createTexture(const QImage& image);
QOpenGLTexture* createTexture(const QPixmap& pixmap);
QOpenGLTexture* createTexture(const QSharedPointer<Paintable>& pPaintable);
QOpenGLTexture* createTexture(const std::shared_ptr<QImage>& pImage);
std::unique_ptr<QOpenGLTexture> createTexture(const QImage& image);
std::unique_ptr<QOpenGLTexture> createTexture(const QPixmap& pixmap);
std::unique_ptr<QOpenGLTexture> createTexture(const QSharedPointer<Paintable>& pPaintable);
std::unique_ptr<QOpenGLTexture> createTexture(const std::shared_ptr<QImage>& pImage);
6 changes: 3 additions & 3 deletions src/waveform/renderers/allshader/waveformrendererpreroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "widget/wwidget.h"

namespace {
QOpenGLTexture* generateTexture(float markerLength,
std::unique_ptr<QOpenGLTexture> generateTexture(float markerLength,
float markerBreadth,
float devicePixelRatio,
QColor color) {
Expand Down Expand Up @@ -121,10 +121,10 @@ void WaveformRendererPreroll::paintGL() {
// has changed size last time.
m_markerLength = markerLength;
m_markerBreadth = markerBreadth;
m_pTexture.reset(generateTexture(m_markerLength,
m_pTexture = generateTexture(m_markerLength,
m_markerBreadth,
m_waveformRenderer->getDevicePixelRatio(),
m_color));
m_color);
}

if (!m_pTexture) {
Expand Down
6 changes: 3 additions & 3 deletions src/waveform/renderers/allshader/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void allshader::WaveformRenderMark::generatePlayPosMarkTexture(float breadth) {
}
painter.end();

m_pPlayPosMarkTexture.reset(createTexture(image));
m_pPlayPosMarkTexture = createTexture(image);
}

void allshader::WaveformRenderMark::drawTriangle(QPainter* painter,
Expand Down Expand Up @@ -405,7 +405,7 @@ void allshader::WaveformRenderMark::generateMarkImage(WaveformMarkPointer pMark,
// Also, without this some Qt-internal issue results in an offset
// image when calculating the center line of pixmaps in draw().
pMark->m_image.setDevicePixelRatio(devicePixelRatio);
pMark->m_pTexture.reset(createTexture(pMark->m_image));
pMark->m_pTexture = createTexture(pMark->m_image);
return;
}
}
Expand Down Expand Up @@ -547,5 +547,5 @@ void allshader::WaveformRenderMark::generateMarkImage(WaveformMarkPointer pMark,
painter.drawText(labelRect, Qt::AlignCenter, label);
}

pMark->m_pTexture.reset(createTexture(pMark->m_image));
pMark->m_pTexture = createTexture(pMark->m_image);
}
24 changes: 12 additions & 12 deletions src/widget/wspinnyglsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void WSpinnyGLSL::cleanupGL() {
void WSpinnyGLSL::coverChanged() {
if (isContextValid()) {
makeCurrentIfNeeded();
m_pLoadedCoverTextureScaled.reset(createTexture(m_loadedCoverScaled));
m_pLoadedCoverTextureScaled = createTexture(m_loadedCoverScaled);
doneCurrent();
}
// otherwise this will happen in initializeGL
Expand All @@ -53,11 +53,11 @@ void WSpinnyGLSL::resizeGL(int w, int h) {
}

void WSpinnyGLSL::updateTextures() {
m_pBgTexture.reset(createTexture(m_pBgImage));
m_pMaskTexture.reset(createTexture(m_pMaskImage));
m_pFgTextureScaled.reset(createTexture(m_fgImageScaled));
m_pGhostTextureScaled.reset(createTexture(m_ghostImageScaled));
m_pLoadedCoverTextureScaled.reset(createTexture(m_loadedCoverScaled));
m_pBgTexture = createTexture(m_pBgImage);
m_pMaskTexture = createTexture(m_pMaskImage);
m_pFgTextureScaled = createTexture(m_fgImageScaled);
m_pGhostTextureScaled = createTexture(m_ghostImageScaled);
m_pLoadedCoverTextureScaled = createTexture(m_loadedCoverScaled);
}

void WSpinnyGLSL::setupVinylSignalQuality() {
Expand Down Expand Up @@ -101,7 +101,7 @@ void WSpinnyGLSL::paintGL() {
int positionLocation = m_textureShader.positionLocation();
int texcoordLocation = m_textureShader.texcoordLocation();

QMatrix matrix;
QMatrix4x4 matrix;
m_textureShader.setUniformValue(matrixLocation, matrix);

m_textureShader.enableAttributeArray(positionLocation);
Expand Down Expand Up @@ -137,16 +137,16 @@ void WSpinnyGLSL::paintGL() {
bool paintGhost = m_bGhostPlayback && m_pGhostTextureScaled;

if (paintGhost) {
QMatrix rotate;
rotate.rotate(-m_fGhostAngle);
QMatrix4x4 rotate;
rotate.rotate(-m_fGhostAngle, 0, 0);
m0dB marked this conversation as resolved.
Show resolved Hide resolved
m_textureShader.setUniformValue(matrixLocation, rotate);

drawTexture(m_pGhostTextureScaled.get());
}

if (m_pFgTextureScaled) {
QMatrix rotate;
rotate.rotate(-m_fAngle);
QMatrix4x4 rotate;
rotate.rotate(-m_fAngle, 0, 0);
m0dB marked this conversation as resolved.
Show resolved Hide resolved
m_textureShader.setUniformValue(matrixLocation, rotate);

drawTexture(m_pFgTextureScaled.get());
Expand Down Expand Up @@ -224,7 +224,7 @@ void WSpinnyGLSL::drawVinylQuality() {
int positionLocation = m_vinylQualityShader.positionLocation();
int texcoordLocation = m_vinylQualityShader.texcoordLocation();

QMatrix matrix;
QMatrix4x4 matrix;
m_vinylQualityShader.setUniformValue(matrixLocation, matrix);
m_vinylQualityShader.setUniformValue(colorLocation, m_vinylQualityColor);

Expand Down
4 changes: 2 additions & 2 deletions src/widget/wvumeterglsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void WVuMeterGLSL::draw() {
void WVuMeterGLSL::initializeGL() {
initializeOpenGLFunctions();

m_pTextureBack.reset(createTexture(m_pPixmapBack));
m_pTextureVu.reset(createTexture(m_pPixmapVu));
m_pTextureBack = createTexture(m_pPixmapBack);
m_pTextureVu = createTexture(m_pPixmapVu);
m_textureShader.init();
}

Expand Down