qt: QOpenGLFunctions_3_0 -> QOpenGLExtraFunctions

This commit is contained in:
ts-korhonen
2022-02-28 22:13:11 +02:00
parent 911c300123
commit 7af0069693
2 changed files with 17 additions and 45 deletions

View File

@@ -104,9 +104,9 @@ OpenGLRenderer::event(QEvent *event)
void void
OpenGLRenderer::initialize() OpenGLRenderer::initialize()
{ {
if (!context->makeCurrent(this) || !initializeOpenGLFunctions()) { if (!context->makeCurrent(this)) {
/* TODO: This could be done much better */ /* TODO: This could be done much better */
QMessageBox::critical((QWidget *) qApp->findChild<QWindow *>(), tr("Error initializing OpenGL"), tr("OpenGL functions could not be initialized. Falling back to software rendering.")); QMessageBox::critical((QWidget *) qApp->findChild<QWindow *>(), tr("Error initializing OpenGL"), tr("Error setting OpenGL context. Falling back to software rendering."));
context->doneCurrent(); context->doneCurrent();
isFinalized = true; isFinalized = true;
isInitialized = true; isInitialized = true;
@@ -114,6 +114,8 @@ OpenGLRenderer::initialize()
return; return;
} }
initializeOpenGLFunctions();
setupExtensions(); setupExtensions();
setupBuffers(); setupBuffers();
@@ -199,32 +201,13 @@ OpenGLRenderer::getOptions(QWidget *parent)
void void
OpenGLRenderer::setupExtensions() OpenGLRenderer::setupExtensions()
{ {
#ifndef Q_OS_MACOS
if (context->hasExtension("GL_ARB_buffer_storage")) { if (context->hasExtension("GL_ARB_buffer_storage")) {
hasBufferStorage = true; hasBufferStorage = true;
glBufferStorage = (PFNGLBUFFERSTORAGEPROC) context->getProcAddress("glBufferStorage"); glBufferStorage = (PFNGLBUFFERSTORAGEPROC) context->getProcAddress("glBufferStorage");
} }
#endif
if (context->hasExtension("GL_ARB_debug_output")) {
hasDebugOutput = true;
glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC) context->getProcAddress("glDebugMessageControlARB");
glDebugMessageInsertARB = (PFNGLDEBUGMESSAGEINSERTARBPROC) context->getProcAddress("glDebugMessageInsertARB");
glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC) context->getProcAddress("glDebugMessageCallbackARB");
glGetDebugMessageLogARB = (PFNGLGETDEBUGMESSAGELOGARBPROC) context->getProcAddress("glGetDebugMessageLogARB");
}
if (context->hasExtension("GL_ARB_sync")) {
hasSync = true;
glFenceSync = (PFNGLFENCESYNCPROC) context->getProcAddress("glFenceSync");
glIsSync = (PFNGLISSYNCPROC) context->getProcAddress("glIsSync");
glDeleteSync = (PFNGLDELETESYNCPROC) context->getProcAddress("glDeleteSync");
glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) context->getProcAddress("glClientWaitSync");
glWaitSync = (PFNGLWAITSYNCPROC) context->getProcAddress("glWaitSync");
glGetInteger64v = (PFNGLGETINTEGER64VPROC) context->getProcAddress("glGetInteger64v");
glGetSynciv = (PFNGLGETSYNCIVPROC) context->getProcAddress("glGetSynciv");
}
} }
void void
@@ -235,10 +218,12 @@ OpenGLRenderer::setupBuffers()
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBufferID); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBufferID);
if (hasBufferStorage) { if (hasBufferStorage) {
#ifndef Q_OS_MACOS
/* Create persistent buffer for pixel transfer. */ /* Create persistent buffer for pixel transfer. */
glBufferStorage(GL_PIXEL_UNPACK_BUFFER, BUFFERBYTES * BUFFERCOUNT, NULL, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); glBufferStorage(GL_PIXEL_UNPACK_BUFFER, BUFFERBYTES * BUFFERCOUNT, NULL, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
unpackBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, BUFFERBYTES * BUFFERCOUNT, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); unpackBuffer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, BUFFERBYTES * BUFFERCOUNT, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
#endif
} else { } else {
/* Fallback; create our own buffer. */ /* Fallback; create our own buffer. */
unpackBuffer = malloc(BUFFERBYTES * BUFFERCOUNT); unpackBuffer = malloc(BUFFERBYTES * BUFFERCOUNT);

View File

@@ -18,12 +18,14 @@
#define QT_OPENGLRENDERER_HPP #define QT_OPENGLRENDERER_HPP
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QOpenGLFunctions_3_0> #include <QOpenGLExtraFunctions>
#include <QResizeEvent> #include <QResizeEvent>
#include <QTimer> #include <QTimer>
#include <QWidget> #include <QWidget>
#include <QWindow> #include <QWindow>
#include <QtOpenGLExtensions/QOpenGLExtensions> #ifndef Q_OS_MACOS
# include <QtOpenGLExtensions/QOpenGLExtensions>
#endif
#include <atomic> #include <atomic>
#include <tuple> #include <tuple>
@@ -32,7 +34,7 @@
#include "qt_opengloptions.hpp" #include "qt_opengloptions.hpp"
#include "qt_renderercommon.hpp" #include "qt_renderercommon.hpp"
class OpenGLRenderer : public QWindow, protected QOpenGLFunctions_3_0, public RendererCommon { class OpenGLRenderer : public QWindow, protected QOpenGLExtraFunctions, public RendererCommon {
Q_OBJECT Q_OBJECT
public: public:
@@ -91,25 +93,10 @@ private:
bool notReady() const { return !isInitialized || isFinalized; } bool notReady() const { return !isInitialized || isFinalized; }
/* GL_ARB_buffer_storage */ /* GL_ARB_buffer_storage */
bool hasBufferStorage = false; bool hasBufferStorage = false;
PFNGLBUFFERSTORAGEPROC glBufferStorage = nullptr; #ifndef Q_OS_MACOS
PFNGLBUFFERSTORAGEPROC glBufferStorage = nullptr;
/* GL_ARB_debug_output */ #endif
bool hasDebugOutput = false;
PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControlARB = nullptr;
PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB = nullptr;
PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB = nullptr;
PFNGLGETDEBUGMESSAGELOGARBPROC glGetDebugMessageLogARB = nullptr;
/* GL_ARB_sync */
bool hasSync = false;
PFNGLFENCESYNCPROC glFenceSync = nullptr;
PFNGLISSYNCPROC glIsSync = nullptr;
PFNGLDELETESYNCPROC glDeleteSync = nullptr;
PFNGLCLIENTWAITSYNCPROC glClientWaitSync = nullptr;
PFNGLWAITSYNCPROC glWaitSync = nullptr;
PFNGLGETINTEGER64VPROC glGetInteger64v = nullptr;
PFNGLGETSYNCIVPROC glGetSynciv = nullptr;
private slots: private slots:
void render(); void render();