1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Merge pull request #579 from madebr/no_openglcompat

wrap QOpenGLContext
This commit is contained in:
Daniel Evans 2018-08-12 10:40:13 +01:00 committed by GitHub
commit 1945d67818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 92 additions and 458 deletions

View File

@ -6,7 +6,6 @@ find_package(Qt5Widgets REQUIRED)
add_executable(rwviewer WIN32
main.cpp
OpenGLCompat.h
ViewerWindow.hpp
ViewerWindow.cpp
@ -44,6 +43,8 @@ add_executable(rwviewer WIN32
AnimationListModel.cpp
AnimationListWidget.hpp
AnimationListWidget.cpp
QOpenGLContextWrapper.cpp
QOpenGLContextWrapper.hpp
)
target_link_libraries(rwviewer

View File

@ -1,432 +0,0 @@
#pragma once
#undef __GLEW_H__
#if defined(RW_OSX) && !defined(_OPENGL_COMPAT_H_)
#define _OPENGL_COMPAT_H_
#undef glActiveShaderProgram
#undef glActiveTexture
#undef glAttachShader
#undef glBeginConditionalRender
#undef glBeginQuery
#undef glBeginTransformFeedback
#undef glBindAttribLocation
#undef glBindBuffer
#undef glBindBufferBase
#undef glBindBufferRange
#undef glBindFragDataLocation
#undef glBindFragDataLocationIndexed
#undef glBindFramebuffer
#undef glBindProgramPipeline
#undef glBindRenderbuffer
#undef glBindSampler
#undef glBindTexture
#undef glBindVertexArray
#undef glBlendColor
#undef glBlendEquation
#undef glBlendEquationSeparate
#undef glBlendFunc
#undef glBlendFuncSeparate
#undef glBlitFramebuffer
#undef glBufferData
#undef glBufferSubData
#undef glCheckFramebufferStatus
#undef glClampColor
#undef glClear
#undef glClearBufferfi
#undef glClearBufferfv
#undef glClearBufferiv
#undef glClearBufferuiv
#undef glClearColor
#undef glClearDepth
#undef glClearDepthf
#undef glClearStencil
#undef glClientWaitSync
#undef glColorMask
#undef glColorMaski
#undef glCompileShader
#undef glCompressedTexImage1D
#undef glCompressedTexImage2D
#undef glCompressedTexImage3D
#undef glCompressedTexSubImage1D
#undef glCompressedTexSubImage2D
#undef glCompressedTexSubImage3D
#undef glCopyBufferSubData
#undef glCopyTexImage1D
#undef glCopyTexImage2D
#undef glCopyTexSubImage1D
#undef glCopyTexSubImage2D
#undef glCopyTexSubImage3D
#undef glCreateProgram
#undef glCreateShader
#undef glCreateShaderProgramv
#undef glCullFace
#undef glDeleteBuffers
#undef glDeleteFramebuffers
#undef glDeleteProgram
#undef glDeleteProgramPipelines
#undef glDeleteQueries
#undef glDeleteRenderbuffers
#undef glDeleteSamplers
#undef glDeleteShader
#undef glDeleteSync
#undef glDeleteTextures
#undef glDeleteVertexArrays
#undef glDepthFunc
#undef glDepthMask
#undef glDepthRange
#undef glDepthRangeArrayv
#undef glDepthRangeIndexed
#undef glDepthRangef
#undef glDetachShader
#undef glDisable
#undef glDisableVertexAttribArray
#undef glDisablei
#undef glDrawArrays
#undef glDrawArraysInstanced
#undef glDrawBuffer
#undef glDrawBuffers
#undef glDrawElements
#undef glDrawElementsBaseVertex
#undef glDrawElementsInstanced
#undef glDrawElementsInstancedBaseVertex
#undef glDrawRangeElements
#undef glDrawRangeElementsBaseVertex
#undef glEnable
#undef glEnableVertexAttribArray
#undef glEnablei
#undef glEndConditionalRender
#undef glEndQuery
#undef glEndTransformFeedback
#undef glFenceSync
#undef glFinish
#undef glFlush
#undef glFlushMappedBufferRange
#undef glFramebufferRenderbuffer
#undef glFramebufferTexture
#undef glFramebufferTexture1D
#undef glFramebufferTexture2D
#undef glFramebufferTexture3D
#undef glFramebufferTextureLayer
#undef glFrontFace
#undef glGenBuffers
#undef glGenFramebuffers
#undef glGenProgramPipelines
#undef glGenQueries
#undef glGenRenderbuffers
#undef glGenSamplers
#undef glGenTextures
#undef glGenVertexArrays
#undef glGenerateMipmap
#undef glGetActiveAttrib
#undef glGetActiveUniform
#undef glGetActiveUniformBlockName
#undef glGetActiveUniformBlockiv
#undef glGetActiveUniformName
#undef glGetActiveUniformsiv
#undef glGetAttachedShaders
#undef glGetAttribLocation
#undef glGetBooleani_v
#undef glGetBooleanv
#undef glGetBufferParameteri64v
#undef glGetBufferParameteriv
#undef glGetBufferPointerv
#undef glGetBufferSubData
#undef glGetCompressedTexImage
#undef glGetDoublei_v
#undef glGetDoublev
#undef glGetError
#undef glGetFloati_v
#undef glGetFloatv
#undef glGetFragDataIndex
#undef glGetFragDataLocation
#undef glGetFramebufferAttachmentParameteriv
#undef glGetInteger64i_v
#undef glGetInteger64v
#undef glGetIntegeri_v
#undef glGetIntegerv
#undef glGetMultisamplefv
#undef glGetProgramBinary
#undef glGetProgramInfoLog
#undef glGetProgramPipelineInfoLog
#undef glGetProgramPipelineiv
#undef glGetProgramiv
#undef glGetQueryObjecti64v
#undef glGetQueryObjectiv
#undef glGetQueryObjectui64v
#undef glGetQueryObjectuiv
#undef glGetQueryiv
#undef glGetRenderbufferParameteriv
#undef glGetSamplerParameterIiv
#undef glGetSamplerParameterIuiv
#undef glGetSamplerParameterfv
#undef glGetSamplerParameteriv
#undef glGetShaderInfoLog
#undef glGetShaderPrecisionFormat
#undef glGetShaderSource
#undef glGetShaderiv
#undef glGetString
#undef glGetStringi
#undef glGetSynciv
#undef glGetTexImage
#undef glGetTexLevelParameterfv
#undef glGetTexLevelParameteriv
#undef glGetTexParameterIiv
#undef glGetTexParameterIuiv
#undef glGetTexParameterfv
#undef glGetTexParameteriv
#undef glGetTransformFeedbackVarying
#undef glGetUniformBlockIndex
#undef glGetUniformIndices
#undef glGetUniformLocation
#undef glGetUniformfv
#undef glGetUniformiv
#undef glGetUniformuiv
#undef glGetVertexAttribIiv
#undef glGetVertexAttribIuiv
#undef glGetVertexAttribPointerv
#undef glGetVertexAttribdv
#undef glGetVertexAttribfv
#undef glGetVertexAttribiv
#undef glHint
#undef glIsBuffer
#undef glIsEnabled
#undef glIsEnabledi
#undef glIsFramebuffer
#undef glIsProgram
#undef glIsProgramPipeline
#undef glIsQuery
#undef glIsRenderbuffer
#undef glIsSampler
#undef glIsShader
#undef glIsSync
#undef glIsTexture
#undef glIsVertexArray
#undef glLineWidth
#undef glLinkProgram
#undef glLogicOp
#undef glMapBuffer
#undef glMapBufferRange
#undef glMultiDrawArrays
#undef glMultiDrawElements
#undef glMultiDrawElementsBaseVertex
#undef glPixelStoref
#undef glPixelStorei
#undef glPointParameterf
#undef glPointParameterfv
#undef glPointParameteri
#undef glPointParameteriv
#undef glPointSize
#undef glPolygonMode
#undef glPolygonOffset
#undef glPrimitiveRestartIndex
#undef glProgramBinary
#undef glProgramParameteri
#undef glProgramUniform1d
#undef glProgramUniform1dv
#undef glProgramUniform1f
#undef glProgramUniform1fv
#undef glProgramUniform1i
#undef glProgramUniform1iv
#undef glProgramUniform1ui
#undef glProgramUniform1uiv
#undef glProgramUniform2d
#undef glProgramUniform2dv
#undef glProgramUniform2f
#undef glProgramUniform2fv
#undef glProgramUniform2i
#undef glProgramUniform2iv
#undef glProgramUniform2ui
#undef glProgramUniform2uiv
#undef glProgramUniform3d
#undef glProgramUniform3dv
#undef glProgramUniform3f
#undef glProgramUniform3fv
#undef glProgramUniform3i
#undef glProgramUniform3iv
#undef glProgramUniform3ui
#undef glProgramUniform3uiv
#undef glProgramUniform4d
#undef glProgramUniform4dv
#undef glProgramUniform4f
#undef glProgramUniform4fv
#undef glProgramUniform4i
#undef glProgramUniform4iv
#undef glProgramUniform4ui
#undef glProgramUniform4uiv
#undef glProgramUniformMatrix2dv
#undef glProgramUniformMatrix2fv
#undef glProgramUniformMatrix2x3dv
#undef glProgramUniformMatrix2x3fv
#undef glProgramUniformMatrix2x4dv
#undef glProgramUniformMatrix2x4fv
#undef glProgramUniformMatrix3dv
#undef glProgramUniformMatrix3fv
#undef glProgramUniformMatrix3x2dv
#undef glProgramUniformMatrix3x2fv
#undef glProgramUniformMatrix3x4dv
#undef glProgramUniformMatrix3x4fv
#undef glProgramUniformMatrix4dv
#undef glProgramUniformMatrix4fv
#undef glProgramUniformMatrix4x2dv
#undef glProgramUniformMatrix4x2fv
#undef glProgramUniformMatrix4x3dv
#undef glProgramUniformMatrix4x3fv
#undef glProvokingVertex
#undef glQueryCounter
#undef glReadBuffer
#undef glReadPixels
#undef glReleaseShaderCompiler
#undef glRenderbufferStorage
#undef glRenderbufferStorageMultisample
#undef glSampleCoverage
#undef glSampleMaski
#undef glSamplerParameterIiv
#undef glSamplerParameterIuiv
#undef glSamplerParameterf
#undef glSamplerParameterfv
#undef glSamplerParameteri
#undef glSamplerParameteriv
#undef glScissor
#undef glScissorArrayv
#undef glScissorIndexed
#undef glScissorIndexedv
#undef glShaderBinary
#undef glShaderSource
#undef glStencilFunc
#undef glStencilFuncSeparate
#undef glStencilMask
#undef glStencilMaskSeparate
#undef glStencilOp
#undef glStencilOpSeparate
#undef glTexBuffer
#undef glTexImage1D
#undef glTexImage2D
#undef glTexImage2DMultisample
#undef glTexImage3D
#undef glTexImage3DMultisample
#undef glTexParameterIiv
#undef glTexParameterIuiv
#undef glTexParameterf
#undef glTexParameterfv
#undef glTexParameteri
#undef glTexParameteriv
#undef glTexSubImage1D
#undef glTexSubImage2D
#undef glTexSubImage3D
#undef glTransformFeedbackVaryings
#undef glUniform1f
#undef glUniform1fv
#undef glUniform1i
#undef glUniform1iv
#undef glUniform1ui
#undef glUniform1uiv
#undef glUniform2f
#undef glUniform2fv
#undef glUniform2i
#undef glUniform2iv
#undef glUniform2ui
#undef glUniform2uiv
#undef glUniform3f
#undef glUniform3fv
#undef glUniform3i
#undef glUniform3iv
#undef glUniform3ui
#undef glUniform3uiv
#undef glUniform4f
#undef glUniform4fv
#undef glUniform4i
#undef glUniform4iv
#undef glUniform4ui
#undef glUniform4uiv
#undef glUniformBlockBinding
#undef glUniformMatrix2fv
#undef glUniformMatrix2x3fv
#undef glUniformMatrix2x4fv
#undef glUniformMatrix3fv
#undef glUniformMatrix3x2fv
#undef glUniformMatrix3x4fv
#undef glUniformMatrix4fv
#undef glUniformMatrix4x2fv
#undef glUniformMatrix4x3fv
#undef glUnmapBuffer
#undef glUseProgram
#undef glUseProgramStages
#undef glValidateProgram
#undef glValidateProgramPipeline
#undef glVertexAttrib1d
#undef glVertexAttrib1dv
#undef glVertexAttrib1f
#undef glVertexAttrib1fv
#undef glVertexAttrib1s
#undef glVertexAttrib1sv
#undef glVertexAttrib2d
#undef glVertexAttrib2dv
#undef glVertexAttrib2f
#undef glVertexAttrib2fv
#undef glVertexAttrib2s
#undef glVertexAttrib2sv
#undef glVertexAttrib3d
#undef glVertexAttrib3dv
#undef glVertexAttrib3f
#undef glVertexAttrib3fv
#undef glVertexAttrib3s
#undef glVertexAttrib3sv
#undef glVertexAttrib4Nbv
#undef glVertexAttrib4Niv
#undef glVertexAttrib4Nsv
#undef glVertexAttrib4Nub
#undef glVertexAttrib4Nubv
#undef glVertexAttrib4Nuiv
#undef glVertexAttrib4Nusv
#undef glVertexAttrib4bv
#undef glVertexAttrib4d
#undef glVertexAttrib4dv
#undef glVertexAttrib4f
#undef glVertexAttrib4fv
#undef glVertexAttrib4iv
#undef glVertexAttrib4s
#undef glVertexAttrib4sv
#undef glVertexAttrib4ubv
#undef glVertexAttrib4uiv
#undef glVertexAttrib4usv
#undef glVertexAttribDivisor
#undef glVertexAttribI1i
#undef glVertexAttribI1iv
#undef glVertexAttribI1ui
#undef glVertexAttribI1uiv
#undef glVertexAttribI2i
#undef glVertexAttribI2iv
#undef glVertexAttribI2ui
#undef glVertexAttribI2uiv
#undef glVertexAttribI3i
#undef glVertexAttribI3iv
#undef glVertexAttribI3ui
#undef glVertexAttribI3uiv
#undef glVertexAttribI4bv
#undef glVertexAttribI4i
#undef glVertexAttribI4iv
#undef glVertexAttribI4sv
#undef glVertexAttribI4ubv
#undef glVertexAttribI4ui
#undef glVertexAttribI4uiv
#undef glVertexAttribI4usv
#undef glVertexAttribIPointer
#undef glVertexAttribP1ui
#undef glVertexAttribP1uiv
#undef glVertexAttribP2ui
#undef glVertexAttribP2uiv
#undef glVertexAttribP3ui
#undef glVertexAttribP3uiv
#undef glVertexAttribP4ui
#undef glVertexAttribP4uiv
#undef glVertexAttribPointer
#undef glViewport
#undef glViewportArrayv
#undef glViewportIndexedf
#undef glViewportIndexedfv
#undef glWaitSync
#endif

View File

@ -0,0 +1,37 @@
#include "QOpenGLContextWrapper.hpp"
#include <QApplication>
#include <QMessageBox>
#include <QOpenGLContext>
QOpenGLContextWrapper::QOpenGLContextWrapper(QWidget *parent)
: m_parent(parent) {
}
void QOpenGLContextWrapper::setup(QSurfaceFormat format) {
m_context = new QOpenGLContext(m_parent);
m_context->setShareContext(QOpenGLContext::globalShareContext());
m_context->setFormat(format);
}
bool QOpenGLContextWrapper::create() {
if (!m_context->create()) {
QMessageBox::critical(m_parent, "OpenGL Failure",
"Failed to create OpenGL context");
QApplication::exit(1);
return false;
}
return true;
}
bool QOpenGLContextWrapper::makeCurrent(QSurface *surface) {
return m_context->makeCurrent(surface);
}
void QOpenGLContextWrapper::doneCurrent() {
m_context->doneCurrent();
}
void QOpenGLContextWrapper::swapBuffers(QSurface *surface) {
m_context->swapBuffers(surface);
}

View File

@ -0,0 +1,28 @@
#ifndef _RWVIEWER_QOPENGLWRAPPER_HPP
#define _RWVIEWER_QOPENGLWRAPPER_HPP
#include <QSurfaceFormat>
class QOpenGLContext;
class QSurface;
class QWidget;
class QOpenGLContextWrapper {
public:
QOpenGLContextWrapper(QWidget *parent);
void setup(QSurfaceFormat format);
bool create();
bool makeCurrent(QSurface *surface);
void doneCurrent();
void swapBuffers(QSurface *surface);
QOpenGLContext *get() {
return m_context;
}
private:
QOpenGLContext *m_context;
QWidget *m_parent;
};
#endif

View File

@ -1,6 +1,7 @@
#include "ViewerWidget.hpp"
#include <QFileDialog>
#include <QMouseEvent>
#include "QOpenGLContextWrapper.hpp"
#include <engine/Animator.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
@ -12,6 +13,9 @@
#include <render/ObjectRenderer.hpp>
#include <render/TextRenderer.hpp>
#include <QFileDialog>
#include <QMouseEvent>
constexpr float kViewFov = glm::radians(90.0f);
namespace {
@ -32,9 +36,9 @@ ViewCamera OrbitCamera (const glm::vec2& viewPort, const glm::vec2& viewAngles,
}
}
ViewerWidget::ViewerWidget(QOpenGLContext* context, QWindow* parent)
ViewerWidget::ViewerWidget(QOpenGLContextWrapper* context, QWindow* parent)
: QWindow(parent)
, context(context) {
, m_context(context) {
setSurfaceType(OpenGLSurface);
}
@ -335,7 +339,7 @@ void ViewerWidget::renderNow() {
return;
}
context->makeCurrent(this);
m_context->makeCurrent(this);
if (!initialised) {
initGL();
@ -343,7 +347,7 @@ void ViewerWidget::renderNow() {
}
paintGL();
context->swapBuffers(this);
m_context->swapBuffers(this);
requestUpdate();
}

View File

@ -10,13 +10,11 @@
#include <render/TextRenderer.hpp>
#include <glm/glm.hpp>
// Prevent Qt from conflicting with glLoadGen on macOS
#include "OpenGLCompat.h"
#include <QWindow>
#include <QOpenGLWindow>
class GameRenderer;
class Clump;
class GameRenderer;
class QOpenGLContextWrapper;
class ViewerWidget : public QWindow {
Q_OBJECT
@ -32,7 +30,7 @@ public:
Text,
};
ViewerWidget(QOpenGLContext* context, QWindow* parent);
ViewerWidget(QOpenGLContextWrapper* context, QWindow* parent);
void initGL();
void paintGL();
@ -80,7 +78,7 @@ protected:
Mode _viewMode = Mode::World;
QOpenGLContext* context;
QOpenGLContextWrapper* m_context;
GameWorld* _world = nullptr;
GameRenderer* _renderer = nullptr;

View File

@ -21,6 +21,7 @@ static int MaxRecentGames = 5;
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
, m_context(this)
, gameData(nullptr)
, gameWorld(nullptr)
, renderer(nullptr) {
@ -64,15 +65,13 @@ bool ViewerWindow::setupEngine() {
QSurfaceFormat format = windowHandle()->format();
format.setProfile(QSurfaceFormat::CoreProfile);
format.setVersion(3,3);
context_ = new QOpenGLContext(this);
context_->setShareContext(QOpenGLContext::globalShareContext());
context_->setFormat(format);
m_context.setup(format);
hiddenSurface = new QOffscreenSurface(windowHandle()->screen());
hiddenSurface->setFormat(format);
hiddenSurface->create();
if (!context_->create()) {
if (!m_context.create()) {
QMessageBox::critical(this, "OpenGL Failure",
"Failed to create OpenGL context");
QApplication::exit(1);
@ -194,16 +193,16 @@ ViewerWindow::~ViewerWindow() {
}
bool ViewerWindow::makeCurrent() {
if (!context_->makeCurrent(hiddenSurface)) {
if (!m_context.makeCurrent(hiddenSurface)) {
QMessageBox::critical(this, "OpenGL", "makeCurrent failed");
QApplication::exit(1);
return false;
}
return true;
return true;
}
ViewerWidget *ViewerWindow::createViewer() {
auto view = new ViewerWidget(context_, windowHandle());
auto view = new ViewerWidget(&m_context, windowHandle());
connect(this, &ViewerWindow::gameLoaded, view, &ViewerWidget::gameLoaded);
return view;
}

View File

@ -1,16 +1,15 @@
#ifndef _VIEWERWINDOW_HPP_
#define _VIEWERWINDOW_HPP_
#include "QOpenGLContextWrapper.hpp"
#include <core/Logger.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
// Prevent Qt from conflicting with glLoadGen on macOS
#include "OpenGLCompat.h"
#include <QMainWindow>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QOpenGLContext>
#include <QOffscreenSurface>
#include <memory>
@ -21,7 +20,7 @@ class GameRenderer;
class ViewerWindow : public QMainWindow {
Q_OBJECT
QOpenGLContext* context_;
QOpenGLContextWrapper m_context;
QOffscreenSurface* hiddenSurface;
QTabWidget* views;