Skip to content

Commit

Permalink
replaced use of qglwidget with wglwidget
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed Oct 20, 2022
1 parent ad8db40 commit 9e9f16f
Show file tree
Hide file tree
Showing 44 changed files with 553 additions and 248 deletions.
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ if(NOT CMAKE_CONFIGURATION_TYPES)
endif()

option(QT6 "Build with Qt6" OFF)
if(APPLE)
option(QOPENGL "Use QOpenGL... classes instead of QGLWidget" ON)
else()
option(QOPENGL "Use QOpenGL... classes instead of QGLWidget" OFF)
endif()

if(QOPENGL)
add_compile_definitions(MIXXX_USE_QOPENGL)
endif()

if(APPLE)
if(QT6)
Expand Down Expand Up @@ -1113,7 +1122,6 @@ else()
src/waveform/renderers/waveformrendermarkrange.cpp
src/waveform/renderers/waveformsignalcolors.cpp
src/waveform/renderers/waveformwidgetrenderer.cpp
src/waveform/sharedglcontext.cpp
src/waveform/visualsmanager.cpp
src/waveform/vsyncthread.cpp
src/waveform/waveformmarklabel.cpp
Expand All @@ -1138,10 +1146,22 @@ else()
src/widget/woverviewlmh.cpp
src/widget/woverviewrgb.cpp
src/widget/wspinny.cpp
src/widget/wvumetergl.cpp
src/widget/wvumetergl.cpp
src/widget/wwaveformviewer.cpp
)
if(QOPENGL)
target_sources(mixxx-lib PRIVATE
src/widget/openglwindow.cpp
src/widget/wglwidgetqopengl.cpp
)
else()
target_sources(mixxx-lib PRIVATE
src/waveform/sharedglcontext.cpp
src/widget/wglwidgetqglwidget.cpp
)
endif()
endif()

set_target_properties(mixxx-lib PROPERTIES AUTOMOC ON AUTOUIC ON CXX_CLANG_TIDY "${CLANG_TIDY}")
target_include_directories(mixxx-lib PUBLIC src "${CMAKE_CURRENT_BINARY_DIR}/src")
if(UNIX AND NOT APPLE)
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ int main(int argc, char * argv[]) {
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
#ifdef MIXXX_USE_QOPENGL
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif

// workaround for https://bugreports.qt.io/browse/QTBUG-84363
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && QT_VERSION < QT_VERSION_CHECK(5, 15, 1)
Expand Down
6 changes: 6 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <QDesktopServices>
#include <QFileDialog>

#ifndef MIXXX_USE_QOPENGL
#include <QGLFormat>
#endif

#include <QUrl>
#include <QtDebug>

Expand Down Expand Up @@ -152,6 +156,7 @@ void MixxxMainWindow::initialize() {
}
});

#ifndef MIXXX_USE_QOPENGL
// Before creating the first skin we need to create a QGLWidget so that all
// the QGLWidget's we create can use it as a shared QGLContext.
if (!CmdlineArgs::Instance().getSafeMode() && QGLFormat::hasOpenGL()) {
Expand Down Expand Up @@ -181,6 +186,7 @@ void MixxxMainWindow::initialize() {
pContextWidget->hide();
SharedGLContext::setWidget(pContextWidget);
}
#endif

WaveformWidgetFactory::createInstance(); // takes a long time
WaveformWidgetFactory::instance()->setConfig(m_pCoreServices->getSettings());
Expand Down
11 changes: 8 additions & 3 deletions src/skin/legacy/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,8 +1314,13 @@ QWidget* LegacySkinParser::parseSpinny(const QDomElement& node) {
connect(waveformWidgetFactory,
&WaveformWidgetFactory::renderSpinnies,
pSpinny,
&WSpinny::render);
connect(waveformWidgetFactory, &WaveformWidgetFactory::swapSpinnies, pSpinny, &WSpinny::swap);
&WSpinny::render,
Qt::DirectConnection);
connect(waveformWidgetFactory,
&WaveformWidgetFactory::swapSpinnies,
pSpinny,
&WSpinny::swap,
Qt::DirectConnection);
connect(pSpinny,
&WSpinny::trackDropped,
m_pPlayerManager,
Expand Down Expand Up @@ -1348,7 +1353,7 @@ QWidget* LegacySkinParser::parseVuMeter(const QDomElement& node) {
return pVuMeterWidget;
}

// QGLWidget derived WVuMeterGL
// WGLWidget derived WVuMeterGL

if (CmdlineArgs::Instance().getSafeMode()) {
WLabel* dummy = new WLabel(m_pParent);
Expand Down
4 changes: 4 additions & 0 deletions src/util/widgetrendertimer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "util/widgetrendertimer.h"

#ifdef USE_WIDGET_RENDER_TIMER

#include "moc_widgetrendertimer.cpp"
#include "util/time.h"

Expand Down Expand Up @@ -28,3 +30,5 @@ void WidgetRenderTimer::activity() {
m_guiTickTimer.start(m_renderFrequency);
}
}

#endif
11 changes: 11 additions & 0 deletions src/util/widgetrendertimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
// Ironically, using this class somehow causes severe lagginess on mouse input
// with Windows, so use #ifdefs to only call activity() on macOS; just call
// QWidget::update() for other operating systems.
//
// Also when using the QOpenGLWindow based WGLWidget (when MIXXX_USE_QOPENGL is
// defined) using this seems not necessary and makes causes lagginess
#ifdef __APPLE__
#ifndef MIXXX_USE_QOPENGL
#define USE_WIDGET_RENDER_TIMER
#endif
#endif

#ifdef USE_WIDGET_RENDER_TIMER
class WidgetRenderTimer : public QObject {
Q_OBJECT
public:
Expand Down Expand Up @@ -53,3 +63,4 @@ class WidgetRenderTimer : public QObject {
mixxx::Duration m_lastActivity;
mixxx::Duration m_lastRender;
};
#endif
17 changes: 12 additions & 5 deletions src/waveform/renderers/glslwaveformrenderersignal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "waveform/renderers/glslwaveformrenderersignal.h"
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)

#ifdef MIXXX_USE_QOPENGL
#include <QOpenGLFramebufferObject>
#include <QOpenGLShaderProgram>
#else
#endif
#include <QGLFramebufferObject>
#include <QGLShaderProgram>

Expand Down Expand Up @@ -49,14 +54,16 @@ bool GLSLWaveformRendererSignal::loadShaders() {
m_frameShaderProgram->removeAllShaders();

if (!m_frameShaderProgram->addShaderFromSourceFile(
QGLShader::Vertex, ":/shaders/passthrough.vert")) {
GL_SHADER_CLASS::Vertex,
":/shaders/passthrough.vert")) {
qDebug() << "GLWaveformRendererSignalShader::loadShaders - "
<< m_frameShaderProgram->log();
return false;
}

if (!m_frameShaderProgram->addShaderFromSourceFile(
QGLShader::Fragment, m_pFragShader)) {
GL_SHADER_CLASS::Fragment,
m_pFragShader)) {
qDebug() << "GLWaveformRendererSignalShader::loadShaders - "
<< m_frameShaderProgram->log();
return false;
Expand Down Expand Up @@ -182,8 +189,8 @@ void GLSLWaveformRendererSignal::createFrameBuffers() {
static_cast<int>(
m_waveformRenderer->getHeight() * devicePixelRatio);

m_framebuffer = std::make_unique<QGLFramebufferObject>(bufferWidth,
bufferHeight);
m_framebuffer = std::make_unique<GL_FBO_CLASS>(bufferWidth,
bufferHeight);

if (!m_framebuffer->isValid()) {
qWarning() << "GLSLWaveformRendererSignal::createFrameBuffer - frame buffer not valid";
Expand All @@ -195,7 +202,7 @@ void GLSLWaveformRendererSignal::onInitializeGL() {
m_textureRenderedWaveformCompletion = 0;

if (!m_frameShaderProgram) {
m_frameShaderProgram = std::make_unique<QGLShaderProgram>();
m_frameShaderProgram = std::make_unique<GL_SHADER_PROGRAM_CLASS>();
}

if (!loadShaders()) {
Expand Down
18 changes: 14 additions & 4 deletions src/waveform/renderers/glslwaveformrenderersignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
#include "util/memory.h"
#include "waveform/renderers/glwaveformrenderer.h"

QT_FORWARD_DECLARE_CLASS(QGLFramebufferObject)
QT_FORWARD_DECLARE_CLASS(QGLShaderProgram)
#ifdef MIXXX_USE_QOPENGL
#define GL_FBO_CLASS QOpenGLFramebufferObject
#define GL_SHADER_CLASS QOpenGLShader
#define GL_SHADER_PROGRAM_CLASS QOpenGLShaderProgram
#else
#define GL_FBO_CLASS QGLFramebufferObject
#define GL_SHADER_CLASS QGLShader
#define GL_SHADER_PROGRAM_CLASS QGLShaderProgram
#endif

QT_FORWARD_DECLARE_CLASS(GL_FBO_CLASS)
QT_FORWARD_DECLARE_CLASS(GL_SHADER_PROGRAM_CLASS)

class GLSLWaveformRendererSignal : public QObject,
public GLWaveformRenderer {
Expand Down Expand Up @@ -50,15 +60,15 @@ class GLSLWaveformRendererSignal : public QObject,
int m_textureRenderedWaveformCompletion;

// Frame buffer for two pass rendering.
std::unique_ptr<QGLFramebufferObject> m_framebuffer;
std::unique_ptr<GL_FBO_CLASS> m_framebuffer;

bool m_bDumpPng;

// shaders
bool m_shadersValid;
ColorType m_colorType;
const QString m_pFragShader;
std::unique_ptr<QGLShaderProgram> m_frameShaderProgram;
std::unique_ptr<GL_SHADER_PROGRAM_CLASS> m_frameShaderProgram;
};

class GLSLWaveformRendererFilteredSignal: public GLSLWaveformRendererSignal {
Expand Down
14 changes: 12 additions & 2 deletions src/waveform/renderers/glwaveformrenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#ifndef MIXXX_USE_QOPENGL
#include <QGLContext>
#endif
#include <QOpenGLFunctions_2_1>

#include "waveform/renderers/waveformrenderersignalbase.h"
Expand All @@ -15,8 +17,12 @@
class GLWaveformRenderer : public WaveformRendererSignalBase, protected QOpenGLFunctions_2_1 {
public:
GLWaveformRenderer(WaveformWidgetRenderer* waveformWidgetRenderer)
: WaveformRendererSignalBase(waveformWidgetRenderer),
m_pLastContext(nullptr) {
: WaveformRendererSignalBase(waveformWidgetRenderer)
#ifndef MIXXX_USE_QOPENGL
,
m_pLastContext(nullptr)
#endif
{
}

virtual void onInitializeGL() {
Expand All @@ -28,14 +34,18 @@ class GLWaveformRenderer : public WaveformRendererSignalBase, protected QOpenGLF
// by calling this in `draw` when the QGLContext has been made current.
// TODO: remove this when upgrading to QOpenGLWidget
void maybeInitializeGL() {
#ifndef MIXXX_USE_QOPENGL
if (QGLContext::currentContext() != m_pLastContext) {
onInitializeGL();
m_pLastContext = QGLContext::currentContext();
}
#endif
}

private:
#ifndef MIXXX_USE_QOPENGL
const QGLContext* m_pLastContext;
#endif
};

#endif // !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
5 changes: 5 additions & 0 deletions src/waveform/renderers/waveformrenderbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) {
if (alpha == 0) {
return;
}
#ifdef MIXXX_USE_QOPENGL
// TODO @m0dB using alpha transparency for the beat lines causes has artifacts with QOpenGL.
m_beatColor.setAlphaF(1.f);
#else
m_beatColor.setAlphaF(alpha/100.0);
#endif

const int trackSamples = m_waveformRenderer->getTrackSamples();
if (trackSamples <= 0) {
Expand Down
1 change: 0 additions & 1 deletion src/waveform/vsyncthread.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "vsyncthread.h"

#include <QGLFormat>
#include <QThread>
#include <QTime>
#include <QtDebug>
Expand Down
14 changes: 7 additions & 7 deletions src/waveform/vsyncthread.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <QTime>
#include <QThread>
#include <QSemaphore>
#include <QPair>
#include <QGLWidget>
#include <QSemaphore>
#include <QThread>
#include <QTime>

#include "util/performancetimer.h"
#include "widget/wglwidget.h"

class VSyncThread : public QThread {
Q_OBJECT
Expand All @@ -25,7 +25,7 @@ class VSyncThread : public QThread {

void run();

bool waitForVideoSync(QGLWidget* glw);
bool waitForVideoSync(WGLWidget* glw);
int elapsed();
int toNextSyncMicros();
void setSyncIntervalTimeMicros(int usSyncTimer);
Expand All @@ -35,8 +35,8 @@ class VSyncThread : public QThread {
int fromTimerToNextSyncMicros(const PerformanceTimer& timer);
void vsyncSlotFinished();
void getAvailableVSyncTypes(QList<QPair<int, QString>>* list);
void setupSync(QGLWidget* glw, int index);
void waitUntilSwap(QGLWidget* glw);
void setupSync(WGLWidget* glw, int index);
void waitUntilSwap(WGLWidget* glw);
mixxx::Duration sinceLastSwap() const;
signals:
void vsyncRender();
Expand Down
Loading

0 comments on commit 9e9f16f

Please sign in to comment.