mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 15:22:09 +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();
|
||||
|
||||
#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) {
|
||||
if (!shareContext) {
|
||||
shareContext = qt_gl_global_share_context();
|
||||
|
@ -297,7 +312,11 @@ void Context::create(QOpenGLContext* shareContext) {
|
|||
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]);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,12 +61,12 @@ void Context::debugMessageHandler(const QOpenGLDebugMessage& debugMessage) {
|
|||
switch (severity) {
|
||||
case QOpenGLDebugMessage::NotificationSeverity:
|
||||
case QOpenGLDebugMessage::LowSeverity:
|
||||
qCDebug(glLogging) << debugMessage;
|
||||
return;
|
||||
default:
|
||||
qCWarning(glLogging) << debugMessage;
|
||||
break;
|
||||
}
|
||||
qWarning(glLogging) << debugMessage;
|
||||
return;
|
||||
}
|
||||
|
||||
void Context::setupDebugLogging(QOpenGLContext *context) {
|
||||
|
@ -82,6 +82,8 @@ void Context::setupDebugLogging(QOpenGLContext *context) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(GL_CUSTOM_CONTEXT)
|
||||
bool Context::makeCurrent() {
|
||||
updateSwapchainMemoryCounter();
|
||||
bool result = _qglContext->makeCurrent(_window);
|
||||
|
@ -98,6 +100,7 @@ void Context::doneCurrent() {
|
|||
_qglContext->doneCurrent();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
|
||||
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
|
||||
|
|
|
@ -65,21 +65,9 @@ bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
|
|||
|
||||
_offscreenSurface->setFormat(_context->format());
|
||||
_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()) {
|
||||
qFatal("Offscreen surface is invalid");
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,22 @@
|
|||
#include <QtPlatformHeaders/QWGLNativeContext>
|
||||
#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() {
|
||||
QOpenGLContext* context = QOpenGLContext::currentContext();
|
||||
if (!context) {
|
||||
|
@ -49,19 +65,6 @@ void QOpenGLContextWrapper::setFormat(const QSurfaceFormat& 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() {
|
||||
return _context->create();
|
||||
}
|
||||
|
|
|
@ -12,19 +12,31 @@
|
|||
#ifndef hifi_QOpenGLContextWrapper_h
|
||||
#define hifi_QOpenGLContextWrapper_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <QtGlobal>
|
||||
#include <memory>
|
||||
|
||||
class QOpenGLContext;
|
||||
class QSurface;
|
||||
class QSurfaceFormat;
|
||||
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 {
|
||||
public:
|
||||
#ifdef Q_OS_WIN
|
||||
static void* nativeContext(QOpenGLContext* context);
|
||||
#endif
|
||||
using Pointer = std::shared_ptr<QOpenGLContextWrapper>;
|
||||
using NativeContextPointer = std::shared_ptr<QGLNativeContext>;
|
||||
static Pointer currentContextWrapper();
|
||||
|
||||
|
||||
QOpenGLContextWrapper();
|
||||
QOpenGLContextWrapper(QOpenGLContext* context);
|
||||
|
@ -37,6 +49,8 @@ public:
|
|||
void setShareContext(QOpenGLContext* otherContext);
|
||||
void moveToThread(QThread* thread);
|
||||
|
||||
NativeContextPointer getNativeContext() const;
|
||||
|
||||
static QOpenGLContext* currentContext();
|
||||
static uint32_t currentContextVersion();
|
||||
|
||||
|
|
Loading…
Reference in a new issue