mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
GL helpers cleanup
This commit is contained in:
parent
fed9e27a66
commit
5d1277e1bb
5 changed files with 59 additions and 32 deletions
|
@ -195,6 +195,21 @@ GLAPI PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
|
||||||
|
|
||||||
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
|
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
|
||||||
|
|
||||||
|
#if defined(GL_CUSTOM_CONTEXT)
|
||||||
|
bool Context::makeCurrent() {
|
||||||
|
BOOL result = wglMakeCurrent(_hdc, _hglrc);
|
||||||
|
assert(result);
|
||||||
|
updateSwapchainMemoryCounter();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
void Context::swapBuffers() {
|
||||||
|
SwapBuffers(_hdc);
|
||||||
|
}
|
||||||
|
void Context::doneCurrent() {
|
||||||
|
wglMakeCurrent(0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Context::create(QOpenGLContext* shareContext) {
|
void Context::create(QOpenGLContext* shareContext) {
|
||||||
if (!shareContext) {
|
if (!shareContext) {
|
||||||
shareContext = qt_gl_global_share_context();
|
shareContext = qt_gl_global_share_context();
|
||||||
|
@ -297,7 +312,11 @@ void Context::create(QOpenGLContext* shareContext) {
|
||||||
contextAttribs.push_back(0);
|
contextAttribs.push_back(0);
|
||||||
}
|
}
|
||||||
contextAttribs.push_back(0);
|
contextAttribs.push_back(0);
|
||||||
HGLRC shareHglrc = (HGLRC)QOpenGLContextWrapper::nativeContext(shareContext);
|
HGLRC shareHglrc = nullptr;
|
||||||
|
if (shareContext) {
|
||||||
|
auto nativeContextPointer = QOpenGLContextWrapper(shareContext).getNativeContext();
|
||||||
|
shareHglrc = (HGLRC)nativeContextPointer->context();
|
||||||
|
}
|
||||||
_hglrc = wglCreateContextAttribsARB(_hdc, shareHglrc, &contextAttribs[0]);
|
_hglrc = wglCreateContextAttribsARB(_hdc, shareHglrc, &contextAttribs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,12 @@ void Context::debugMessageHandler(const QOpenGLDebugMessage& debugMessage) {
|
||||||
switch (severity) {
|
switch (severity) {
|
||||||
case QOpenGLDebugMessage::NotificationSeverity:
|
case QOpenGLDebugMessage::NotificationSeverity:
|
||||||
case QOpenGLDebugMessage::LowSeverity:
|
case QOpenGLDebugMessage::LowSeverity:
|
||||||
|
qCDebug(glLogging) << debugMessage;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
qCWarning(glLogging) << debugMessage;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qWarning(glLogging) << debugMessage;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::setupDebugLogging(QOpenGLContext *context) {
|
void Context::setupDebugLogging(QOpenGLContext *context) {
|
||||||
|
@ -82,6 +82,8 @@ void Context::setupDebugLogging(QOpenGLContext *context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(GL_CUSTOM_CONTEXT)
|
||||||
bool Context::makeCurrent() {
|
bool Context::makeCurrent() {
|
||||||
updateSwapchainMemoryCounter();
|
updateSwapchainMemoryCounter();
|
||||||
bool result = _qglContext->makeCurrent(_window);
|
bool result = _qglContext->makeCurrent(_window);
|
||||||
|
@ -98,6 +100,7 @@ void Context::doneCurrent() {
|
||||||
_qglContext->doneCurrent();
|
_qglContext->doneCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
|
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
|
||||||
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
|
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
|
||||||
|
|
|
@ -65,21 +65,9 @@ bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
|
||||||
|
|
||||||
_offscreenSurface->setFormat(_context->format());
|
_offscreenSurface->setFormat(_context->format());
|
||||||
_offscreenSurface->create();
|
_offscreenSurface->create();
|
||||||
|
|
||||||
// Due to a https://bugreports.qt.io/browse/QTBUG-65125 we can't rely on `isValid`
|
|
||||||
// to determine if the offscreen surface was successfully created, so we use
|
|
||||||
// makeCurrent as a proxy test. Bug is fixed in Qt 5.9.4
|
|
||||||
#if defined(Q_OS_ANDROID)
|
|
||||||
if (!_context->makeCurrent(_offscreenSurface)) {
|
|
||||||
qFatal("Unable to make offscreen surface current");
|
|
||||||
}
|
|
||||||
_context->doneCurrent();
|
|
||||||
#else
|
|
||||||
if (!_offscreenSurface->isValid()) {
|
if (!_offscreenSurface->isValid()) {
|
||||||
qFatal("Offscreen surface is invalid");
|
qFatal("Offscreen surface is invalid");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,22 @@
|
||||||
#include <QtPlatformHeaders/QWGLNativeContext>
|
#include <QtPlatformHeaders/QWGLNativeContext>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QOpenGLContextWrapper::Pointer QOpenGLContextWrapper::currentContextWrapper() {
|
||||||
|
return std::make_shared<QOpenGLContextWrapper>(QOpenGLContext::currentContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QOpenGLContextWrapper::NativeContextPointer QOpenGLContextWrapper::getNativeContext() const {
|
||||||
|
QOpenGLContextWrapper::NativeContextPointer result;
|
||||||
|
auto nativeHandle = _context->nativeHandle();
|
||||||
|
if (nativeHandle.canConvert<QGLNativeContext>()) {
|
||||||
|
result = std::make_shared<QGLNativeContext>();
|
||||||
|
*result = nativeHandle.value<QGLNativeContext>();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t QOpenGLContextWrapper::currentContextVersion() {
|
uint32_t QOpenGLContextWrapper::currentContextVersion() {
|
||||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
QOpenGLContext* context = QOpenGLContext::currentContext();
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
@ -49,19 +65,6 @@ void QOpenGLContextWrapper::setFormat(const QSurfaceFormat& format) {
|
||||||
_context->setFormat(format);
|
_context->setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
void* QOpenGLContextWrapper::nativeContext(QOpenGLContext* context) {
|
|
||||||
HGLRC result = 0;
|
|
||||||
if (context != nullptr) {
|
|
||||||
auto nativeHandle = context->nativeHandle();
|
|
||||||
if (nativeHandle.canConvert<QWGLNativeContext>()) {
|
|
||||||
result = nativeHandle.value<QWGLNativeContext>().context();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool QOpenGLContextWrapper::create() {
|
bool QOpenGLContextWrapper::create() {
|
||||||
return _context->create();
|
return _context->create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,31 @@
|
||||||
#ifndef hifi_QOpenGLContextWrapper_h
|
#ifndef hifi_QOpenGLContextWrapper_h
|
||||||
#define hifi_QOpenGLContextWrapper_h
|
#define hifi_QOpenGLContextWrapper_h
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class QOpenGLContext;
|
class QOpenGLContext;
|
||||||
class QSurface;
|
class QSurface;
|
||||||
class QSurfaceFormat;
|
class QSurfaceFormat;
|
||||||
class QThread;
|
class QThread;
|
||||||
|
|
||||||
|
#if defined(Q_OS_ANDROID)
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include <QtPlatformHeaders/QEGLNativeContext>
|
||||||
|
using QGLNativeContext = QEGLNativeContext;
|
||||||
|
#elif defined(Q_OS_WIN)
|
||||||
|
class QWGLNativeContext;
|
||||||
|
using QGLNativeContext = QWGLNativeContext;
|
||||||
|
#else
|
||||||
|
using QGLNativeContext = void*;
|
||||||
|
#endif
|
||||||
|
|
||||||
class QOpenGLContextWrapper {
|
class QOpenGLContextWrapper {
|
||||||
public:
|
public:
|
||||||
#ifdef Q_OS_WIN
|
using Pointer = std::shared_ptr<QOpenGLContextWrapper>;
|
||||||
static void* nativeContext(QOpenGLContext* context);
|
using NativeContextPointer = std::shared_ptr<QGLNativeContext>;
|
||||||
#endif
|
static Pointer currentContextWrapper();
|
||||||
|
|
||||||
|
|
||||||
QOpenGLContextWrapper();
|
QOpenGLContextWrapper();
|
||||||
QOpenGLContextWrapper(QOpenGLContext* context);
|
QOpenGLContextWrapper(QOpenGLContext* context);
|
||||||
|
@ -37,6 +49,8 @@ public:
|
||||||
void setShareContext(QOpenGLContext* otherContext);
|
void setShareContext(QOpenGLContext* otherContext);
|
||||||
void moveToThread(QThread* thread);
|
void moveToThread(QThread* thread);
|
||||||
|
|
||||||
|
NativeContextPointer getNativeContext() const;
|
||||||
|
|
||||||
static QOpenGLContext* currentContext();
|
static QOpenGLContext* currentContext();
|
||||||
static uint32_t currentContextVersion();
|
static uint32_t currentContextVersion();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue