diff options
-rw-r--r-- | CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/util/texture.cpp | 31 | ||||
-rw-r--r-- | src/util/texture.h | 12 | ||||
-rw-r--r-- | src/widget/paintable.cpp | 4 | ||||
-rw-r--r-- | src/widget/paintable.h | 1 | ||||
-rw-r--r-- | src/widget/wspinnyglsl.cpp | 27 | ||||
-rw-r--r-- | src/widget/wvumeterglsl.cpp | 21 |
7 files changed, 63 insertions, 50 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1b7f4d83..804fabc4a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1124,12 +1124,6 @@ if(QT6) else() target_sources(mixxx-lib PRIVATE src/mixxxmainwindow.cpp - src/shaders/endoftrackshader.cpp - src/shaders/rgbashader.cpp - src/shaders/rgbshader.cpp - src/shaders/shader.cpp - src/shaders/textureshader.cpp - src/shaders/unicolorshader.cpp src/waveform/guitick.cpp src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbackground.cpp @@ -1201,19 +1195,26 @@ else() src/widget/woverviewrgb.cpp src/widget/wspinny.cpp src/widget/wspinnybase.cpp - src/widget/wspinnyglsl.cpp src/widget/wvumeter.cpp src/widget/wvumeterbase.cpp - src/widget/wvumeterglsl.cpp src/widget/wvumeterlegacy.cpp src/widget/wwaveformviewer.cpp ) if(QOPENGL) target_sources(mixxx-lib PRIVATE + src/shaders/endoftrackshader.cpp + src/shaders/rgbashader.cpp + src/shaders/rgbshader.cpp + src/shaders/shader.cpp + src/shaders/textureshader.cpp + src/shaders/unicolorshader.cpp + src/util/texture.cpp src/widget/openglwindow.cpp src/widget/tooltipqopengl.cpp src/widget/wglwidgetqopengl.cpp src/widget/winitialglwidget.cpp + src/widget/wspinnyglsl.cpp + src/widget/wvumeterglsl.cpp ) else() target_sources(mixxx-lib PRIVATE diff --git a/src/util/texture.cpp b/src/util/texture.cpp new file mode 100644 index 0000000000..65763ce6c4 --- /dev/null +++ b/src/util/texture.cpp @@ -0,0 +1,31 @@ +#include "util/texture.h" + +QOpenGLTexture* createTexture(const QImage& image) { + if (image.isNull()) { + return nullptr; + } + QOpenGLTexture* pTexture = new QOpenGLTexture(image); + pTexture->setMinificationFilter(QOpenGLTexture::Linear); + pTexture->setMagnificationFilter(QOpenGLTexture::Linear); + pTexture->setWrapMode(QOpenGLTexture::ClampToBorder); + + return pTexture; +} + +QOpenGLTexture* createTexture(const QPixmap& pixmap) { + return createTexture(pixmap.toImage()); +} + +QOpenGLTexture* createTexture(const QSharedPointer<Paintable>& pPaintable) { + if (pPaintable.isNull()) { + return nullptr; + } + return createTexture(pPaintable->toImage()); +} + +QOpenGLTexture* createTexture(const std::shared_ptr<QImage>& pImage) { + if (!pImage) { + return nullptr; + } + return createTexture(*pImage); +} diff --git a/src/util/texture.h b/src/util/texture.h new file mode 100644 index 0000000000..22e3aabde7 --- /dev/null +++ b/src/util/texture.h @@ -0,0 +1,12 @@ +#include <QImage> +#include <QOpenGLTexture> +#include <QPixmap> +#include <QSharedPointer> +#include <memory> + +#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); diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 159de34292..8968447693 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -96,10 +96,6 @@ bool Paintable::isNull() const { return m_source.isEmpty(); } -bool Paintable::isPixmapNull() const { - return m_pPixmap.isNull(); -} - QSize Paintable::size() const { if (!m_pPixmap.isNull()) { return m_pPixmap->size(); diff --git a/src/widget/paintable.h b/src/widget/paintable.h index 6d0914006f..3dcb185cdf 100644 --- a/src/widget/paintable.h +++ b/src/widget/paintable.h @@ -46,7 +46,6 @@ class Paintable { void drawCentered(const QRectF& targetRect, QPainter* pPainter, const QRectF& sourceRect); bool isNull() const; - bool isPixmapNull() const; static DrawMode DrawModeFromString(const QString& str); static QString DrawModeToString(DrawMode mode); diff --git a/src/widget/wspinnyglsl.cpp b/src/widget/wspinnyglsl.cpp index 67f8159842..ca9363511c 100644 --- a/src/widget/wspinnyglsl.cpp +++ b/src/widget/wspinnyglsl.cpp @@ -1,6 +1,7 @@ #include "widget/wspinnyglsl.h" #include "util/assert.h" +#include "util/texture.h" WSpinnyGLSL::WSpinnyGLSL( QWidget* parent, @@ -29,9 +30,7 @@ void WSpinnyGLSL::cleanupGL() { void WSpinnyGLSL::coverChanged() { if (isContextValid()) { makeCurrentIfNeeded(); - m_pLoadedCoverTextureScaled.reset(!m_loadedCoverScaled.isNull() - ? new QOpenGLTexture(m_loadedCoverScaled.toImage()) - : nullptr); + m_pLoadedCoverTextureScaled.reset(createTexture(m_loadedCoverScaled)); doneCurrent(); } // otherwise this will happen in initializeGL @@ -113,22 +112,12 @@ void WSpinnyGLSL::paintGL() { } void WSpinnyGLSL::initializeGL() { - m_pBgTexture.reset(m_pBgImage && !m_pBgImage->isNull() - ? new QOpenGLTexture(*m_pBgImage) - : nullptr); - m_pMaskTexture.reset(m_pMaskImage && !m_pMaskImage->isNull() - ? new QOpenGLTexture(*m_pMaskImage) - : nullptr); - m_pFgTextureScaled.reset(!m_fgImageScaled.isNull() - ? new QOpenGLTexture(m_fgImageScaled) - : nullptr); - m_pGhostTextureScaled.reset(!m_ghostImageScaled.isNull() - ? new QOpenGLTexture(m_ghostImageScaled) - : nullptr); - m_pLoadedCoverTextureScaled.reset(!m_loadedCoverScaled.isNull() - ? new QOpenGLTexture(m_loadedCoverScaled.toImage()) - : nullptr); - m_pQTexture.reset(!m_qImage.isNull() ? new QOpenGLTexture(m_qImage) : nullptr); + 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_pQTexture.reset(createTexture(m_qImage)); m_textureShader.init(); } diff --git a/src/widget/wvumeterglsl.cpp b/src/widget/wvumeterglsl.cpp index 20efb02d50..8a751b58e6 100644 --- a/src/widget/wvumeterglsl.cpp +++ b/src/widget/wvumeterglsl.cpp @@ -2,6 +2,7 @@ #include "util/assert.h" #include "util/math.h" +#include "util/texture.h" WVuMeterGLSL::WVuMeterGLSL(QWidget* parent) : WVuMeterBase(parent) { @@ -20,24 +21,8 @@ void WVuMeterGLSL::draw() { } void WVuMeterGLSL::initializeGL() { - if (m_pPixmapBack.isNull() || m_pPixmapBack->isPixmapNull()) { - m_pTextureBack.reset(); - } else { - m_pTextureBack.reset(new QOpenGLTexture(m_pPixmapBack->toImage())); - m_pTextureBack->setMinificationFilter(QOpenGLTexture::Linear); - m_pTextureBack->setMagnificationFilter(QOpenGLTexture::Linear); - m_pTextureBack->setWrapMode(QOpenGLTexture::ClampToBorder); - } - - if (m_pPixmapVu.isNull() || m_pPixmapVu->isPixmapNull()) { - m_pTextureVu.reset(); - } else { - m_pTextureVu.reset(new QOpenGLTexture(m_pPixmapVu->toImage())); - m_pTextureVu->setMinificationFilter(QOpenGLTexture::Linear); - m_pTextureVu->setMagnificationFilter(QOpenGLTexture::Linear); - m_pTextureVu->setWrapMode(QOpenGLTexture::ClampToBorder); - } - + m_pTextureBack.reset(createTexture(m_pPixmapBack)); + m_pTextureVu.reset(createTexture(m_pPixmapVu)); m_textureShader.init(); } |