mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Revert to using QGLWidget
This commit is contained in:
parent
6364072c10
commit
382ef057b0
15 changed files with 305 additions and 244 deletions
|
@ -62,7 +62,6 @@
|
|||
#include <EntityScriptingInterface.h>
|
||||
#include <ErrorDialog.h>
|
||||
#include <FramebufferCache.h>
|
||||
#include <GlWindow.h>
|
||||
#include <gpu/Batch.h>
|
||||
#include <gpu/Context.h>
|
||||
#include <gpu/GLBackend.h>
|
||||
|
@ -100,6 +99,7 @@
|
|||
|
||||
#include "AudioClient.h"
|
||||
#include "DiscoverabilityManager.h"
|
||||
#include "GLCanvas.h"
|
||||
#include "InterfaceVersion.h"
|
||||
#include "LODManager.h"
|
||||
#include "Menu.h"
|
||||
|
@ -521,25 +521,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
|
||||
ResourceCache::setRequestLimit(3);
|
||||
|
||||
_offscreenContext = new OffscreenGlCanvas();
|
||||
_offscreenContext->create();
|
||||
_offscreenContext->makeCurrent();
|
||||
_glWidget = new GLCanvas();
|
||||
_window->setCentralWidget(_glWidget);
|
||||
|
||||
_glWindow = new GlWindow(_offscreenContext->getContext());
|
||||
|
||||
QWidget* container = QWidget::createWindowContainer(_glWindow);
|
||||
_window->setCentralWidget(container);
|
||||
_window->restoreGeometry();
|
||||
_window->setVisible(true);
|
||||
_window->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
container->setFocusPolicy(Qt::StrongFocus);
|
||||
container->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
container->setFocus();
|
||||
container->installEventFilter(DependencyManager::get<OffscreenUi>().data());
|
||||
|
||||
_offscreenContext->makeCurrent();
|
||||
initializeGL();
|
||||
// initialization continues in initializeGL when OpenGL context is ready
|
||||
_glWidget->setFocusPolicy(Qt::StrongFocus);
|
||||
_glWidget->setFocus();
|
||||
#ifdef Q_OS_MAC
|
||||
// OSX doesn't seem to provide for hiding the cursor only on the GL widget
|
||||
_window->setCursor(Qt::BlankCursor);
|
||||
|
@ -547,11 +535,20 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
// On windows and linux, hiding the top level cursor also means it's invisible
|
||||
// when hovering over the window menu, which is a pain, so only hide it for
|
||||
// the GL surface
|
||||
container->setCursor(Qt::BlankCursor);
|
||||
_glWidget->setCursor(Qt::BlankCursor);
|
||||
#endif
|
||||
|
||||
// enable mouse tracking; otherwise, we only get drag events
|
||||
container->setMouseTracking(true);
|
||||
_glWidget->setMouseTracking(true);
|
||||
|
||||
_offscreenContext = new OffscreenGlCanvas();
|
||||
_offscreenContext->create(_glWidget->context()->contextHandle());
|
||||
_offscreenContext->makeCurrent();
|
||||
initializeGL();
|
||||
|
||||
_window->setVisible(true);
|
||||
_offscreenContext->makeCurrent();
|
||||
|
||||
|
||||
_toolWindow = new ToolWindow();
|
||||
_toolWindow->setWindowFlags(_toolWindow->windowFlags() | Qt::WindowStaysOnTopHint);
|
||||
|
@ -858,6 +855,7 @@ void Application::initializeUi() {
|
|||
offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
||||
offscreenUi->load("Root.qml");
|
||||
offscreenUi->load("RootMenu.qml");
|
||||
_glWidget->installEventFilter(offscreenUi.data());
|
||||
VrMenu::load();
|
||||
VrMenu::executeQueuedLambdas();
|
||||
offscreenUi->setMouseTranslator([=](const QPointF& pt) {
|
||||
|
@ -1284,53 +1282,6 @@ bool Application::eventFilter(QObject* object, QEvent* event) {
|
|||
}
|
||||
}
|
||||
|
||||
if (object == _glWindow) {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
if (offscreenUi->eventFilter(object, event)) {
|
||||
return true;
|
||||
}
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
mouseMoveEvent((QMouseEvent*)event);
|
||||
return true;
|
||||
case QEvent::MouseButtonPress:
|
||||
mousePressEvent((QMouseEvent*)event);
|
||||
return true;
|
||||
case QEvent::MouseButtonDblClick:
|
||||
mouseDoublePressEvent((QMouseEvent*)event);
|
||||
return true;
|
||||
case QEvent::MouseButtonRelease:
|
||||
mouseReleaseEvent((QMouseEvent*)event);
|
||||
return true;
|
||||
case QEvent::KeyPress:
|
||||
keyPressEvent((QKeyEvent*)event);
|
||||
return true;
|
||||
case QEvent::KeyRelease:
|
||||
keyReleaseEvent((QKeyEvent*)event);
|
||||
return true;
|
||||
case QEvent::FocusOut:
|
||||
focusOutEvent((QFocusEvent*)event);
|
||||
return true;
|
||||
case QEvent::TouchBegin:
|
||||
touchBeginEvent(static_cast<QTouchEvent*>(event));
|
||||
event->accept();
|
||||
return true;
|
||||
case QEvent::TouchEnd:
|
||||
touchEndEvent(static_cast<QTouchEvent*>(event));
|
||||
return true;
|
||||
case QEvent::TouchUpdate:
|
||||
touchUpdateEvent(static_cast<QTouchEvent*>(event));
|
||||
return true;
|
||||
case QEvent::Wheel:
|
||||
wheelEvent(static_cast<QWheelEvent*>(event));
|
||||
return true;
|
||||
case QEvent::Drop:
|
||||
dropEvent(static_cast<QDropEvent*>(event));
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -4682,7 +4633,7 @@ void Application::shutdownPlugins() {
|
|||
}
|
||||
|
||||
glm::uvec2 Application::getCanvasSize() const {
|
||||
return toGlm(_glWindow->size());
|
||||
return glm::uvec2(_glWidget->width(), _glWidget->height());
|
||||
}
|
||||
|
||||
glm::uvec2 Application::getUiSize() const {
|
||||
|
@ -4702,7 +4653,7 @@ bool Application::isThrottleRendering() const {
|
|||
}
|
||||
|
||||
ivec2 Application::getTrueMouse() const {
|
||||
return toGlm(_glWindow->mapFromGlobal(QCursor::pos()));
|
||||
return toGlm(_glWidget->mapFromGlobal(QCursor::pos()));
|
||||
}
|
||||
|
||||
bool Application::hasFocus() const {
|
||||
|
@ -4760,11 +4711,6 @@ void Application::updateDisplayMode() {
|
|||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
DisplayPluginPointer oldDisplayPlugin = _displayPlugin;
|
||||
if (oldDisplayPlugin != newDisplayPlugin) {
|
||||
if (oldDisplayPlugin) {
|
||||
oldDisplayPlugin->removeEventFilter(qApp);
|
||||
oldDisplayPlugin->removeEventFilter(offscreenUi.data());
|
||||
}
|
||||
|
||||
if (!_currentDisplayPluginActions.isEmpty()) {
|
||||
auto menu = Menu::getInstance();
|
||||
foreach(auto itemInfo, _currentDisplayPluginActions) {
|
||||
|
@ -4776,16 +4722,7 @@ void Application::updateDisplayMode() {
|
|||
if (newDisplayPlugin) {
|
||||
_offscreenContext->makeCurrent();
|
||||
newDisplayPlugin->activate(this);
|
||||
|
||||
_offscreenContext->makeCurrent();
|
||||
newDisplayPlugin->installEventFilter(qApp);
|
||||
newDisplayPlugin->installEventFilter(offscreenUi.data());
|
||||
QWindow* pluginWindow = newDisplayPlugin->getWindow();
|
||||
if (pluginWindow) {
|
||||
DependencyManager::get<OffscreenUi>()->setProxyWindow(pluginWindow);
|
||||
} else {
|
||||
DependencyManager::get<OffscreenUi>()->setProxyWindow(nullptr);
|
||||
}
|
||||
offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
|
||||
_offscreenContext->makeCurrent();
|
||||
}
|
||||
|
@ -4882,10 +4819,6 @@ void Application::setIsOptionChecked(const QString& path, bool checked) {
|
|||
Menu::getInstance()->setIsOptionChecked(path, checked);
|
||||
}
|
||||
|
||||
GlWindow* Application::getVisibleWindow() {
|
||||
return _glWindow;
|
||||
}
|
||||
|
||||
mat4 Application::getEyeProjection(int eye) const {
|
||||
if (isHMDMode()) {
|
||||
return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());
|
||||
|
@ -4941,3 +4874,12 @@ void Application::unsetFullscreen() {
|
|||
_window->setGeometry(_savedGeometry);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Application::showDisplayPluginsTools() {
|
||||
|
||||
}
|
||||
|
||||
QGLWidget* Application::getPrimarySurface() {
|
||||
return _glWidget;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ class FaceTracker;
|
|||
class MainWindow;
|
||||
class Node;
|
||||
class ScriptEngine;
|
||||
class GlWindow;
|
||||
|
||||
namespace gpu {
|
||||
class Context;
|
||||
|
@ -287,9 +286,10 @@ public:
|
|||
virtual void removeMenuItem(const QString& menuName, const QString& menuItem);
|
||||
virtual bool isOptionChecked(const QString& name);
|
||||
virtual void setIsOptionChecked(const QString& path, bool checked);
|
||||
virtual GlWindow* getVisibleWindow();
|
||||
virtual void setFullscreen(const QScreen* target) override;
|
||||
virtual void unsetFullscreen() override;
|
||||
virtual void showDisplayPluginsTools() override;
|
||||
virtual QGLWidget* Application::getPrimarySurface() override;
|
||||
|
||||
private:
|
||||
DisplayPlugin * getActiveDisplayPlugin();
|
||||
|
@ -639,7 +639,7 @@ private:
|
|||
QThread _settingsThread;
|
||||
QTimer _settingsTimer;
|
||||
|
||||
GlWindow* _glWindow{ nullptr };
|
||||
GLCanvas* _glWidget{ nullptr };
|
||||
|
||||
void checkSkeleton();
|
||||
|
||||
|
|
172
interface/src/GLCanvas.cpp
Normal file
172
interface/src/GLCanvas.cpp
Normal file
|
@ -0,0 +1,172 @@
|
|||
//
|
||||
// GLCanvas.cpp
|
||||
// interface/src
|
||||
//
|
||||
// Created by Stephen Birarda on 8/14/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Application.h"
|
||||
#include "GLCanvas.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QWindow>
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
const int MSECS_PER_FRAME_WHEN_THROTTLED = 66;
|
||||
|
||||
GLCanvas::GLCanvas() : QGLWidget(QGL::NoDepthBuffer | QGL::NoStencilBuffer),
|
||||
_throttleRendering(false),
|
||||
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
// Cause GLCanvas::eventFilter to be called.
|
||||
// It wouldn't hurt to do this on Mac and PC too; but apparently it's only needed on linux.
|
||||
qApp->installEventFilter(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void GLCanvas::stopFrameTimer() {
|
||||
_frameTimer.stop();
|
||||
}
|
||||
|
||||
bool GLCanvas::isThrottleRendering() const {
|
||||
return (_throttleRendering
|
||||
|| (Application::getInstance()->getWindow()->isMinimized() && Application::getInstance()->isThrottleFPSEnabled()));
|
||||
}
|
||||
|
||||
int GLCanvas::getDeviceWidth() const {
|
||||
return width() * (windowHandle() ? (float)windowHandle()->devicePixelRatio() : 1.0f);
|
||||
}
|
||||
|
||||
int GLCanvas::getDeviceHeight() const {
|
||||
return height() * (windowHandle() ? (float)windowHandle()->devicePixelRatio() : 1.0f);
|
||||
}
|
||||
|
||||
void GLCanvas::initializeGL() {
|
||||
setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
setAcceptDrops(true);
|
||||
connect(Application::getInstance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeChanged(Qt::ApplicationState)));
|
||||
connect(&_frameTimer, SIGNAL(timeout()), this, SLOT(throttleRender()));
|
||||
|
||||
// Note, we *DO NOT* want Qt to automatically swap buffers for us. This results in the "ringing" bug mentioned in WL#19514 when we're throttling the framerate.
|
||||
setAutoBufferSwap(false);
|
||||
}
|
||||
|
||||
void GLCanvas::paintGL() {
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
if (!_throttleRendering &&
|
||||
(!Application::getInstance()->getWindow()->isMinimized() || !Application::getInstance()->isThrottleFPSEnabled())) {
|
||||
Application::getInstance()->paintGL();
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas::resizeGL(int width, int height) {
|
||||
Application::getInstance()->resizeGL();
|
||||
}
|
||||
|
||||
void GLCanvas::activeChanged(Qt::ApplicationState state) {
|
||||
switch (state) {
|
||||
case Qt::ApplicationActive:
|
||||
// If we're active, stop the frame timer and the throttle.
|
||||
_frameTimer.stop();
|
||||
_throttleRendering = false;
|
||||
break;
|
||||
|
||||
case Qt::ApplicationSuspended:
|
||||
case Qt::ApplicationHidden:
|
||||
// If we're hidden or are about to suspend, don't render anything.
|
||||
_throttleRendering = false;
|
||||
_frameTimer.stop();
|
||||
break;
|
||||
|
||||
default:
|
||||
// Otherwise, throttle.
|
||||
if (!_throttleRendering && !Application::getInstance()->isAboutToQuit()
|
||||
&& Application::getInstance()->isThrottleFPSEnabled()) {
|
||||
_frameTimer.start(_idleRenderInterval);
|
||||
_throttleRendering = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas::throttleRender() {
|
||||
_frameTimer.start(_idleRenderInterval);
|
||||
if (!Application::getInstance()->getWindow()->isMinimized()) {
|
||||
Application::getInstance()->paintGL();
|
||||
}
|
||||
}
|
||||
|
||||
int updateTime = 0;
|
||||
bool GLCanvas::event(QEvent* event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
case QEvent::FocusIn:
|
||||
case QEvent::FocusOut:
|
||||
case QEvent::Resize:
|
||||
case QEvent::TouchBegin:
|
||||
case QEvent::TouchEnd:
|
||||
case QEvent::TouchUpdate:
|
||||
case QEvent::Wheel:
|
||||
case QEvent::DragEnter:
|
||||
case QEvent::Drop:
|
||||
if (QCoreApplication::sendEvent(QCoreApplication::instance(), event)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case QEvent::Paint:
|
||||
// Ignore paint events that occur after we've decided to quit
|
||||
if (Application::getInstance()->isAboutToQuit()) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QGLWidget::event(event);
|
||||
}
|
||||
|
||||
|
||||
// Pressing Alt (and Meta) key alone activates the menubar because its style inherits the
|
||||
// SHMenuBarAltKeyNavigation from QWindowsStyle. This makes it impossible for a scripts to
|
||||
// receive keyPress events for the Alt (and Meta) key in a reliable manner.
|
||||
//
|
||||
// This filter catches events before QMenuBar can steal the keyboard focus.
|
||||
// The idea was borrowed from
|
||||
// http://www.archivum.info/qt-interest@trolltech.com/2006-09/00053/Re-(Qt4)-Alt-key-focus-QMenuBar-(solved).html
|
||||
|
||||
bool GLCanvas::eventFilter(QObject*, QEvent* event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
case QEvent::ShortcutOverride:
|
||||
{
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||
if (keyEvent->key() == Qt::Key_Alt || keyEvent->key() == Qt::Key_Meta) {
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
keyPressEvent(keyEvent);
|
||||
} else if (event->type() == QEvent::KeyRelease) {
|
||||
keyReleaseEvent(keyEvent);
|
||||
} else {
|
||||
QGLWidget::event(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
55
interface/src/GLCanvas.h
Normal file
55
interface/src/GLCanvas.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// GLCanvas.h
|
||||
// interface/src
|
||||
//
|
||||
// Created by Stephen Birarda on 8/14/13.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_GLCanvas_h
|
||||
#define hifi_GLCanvas_h
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGLWidget>
|
||||
#include <QTimer>
|
||||
|
||||
class QOpenGLContext;
|
||||
|
||||
/// customized canvas that simply forwards requests/events to the singleton application
|
||||
class GLCanvas : public QGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GLCanvas();
|
||||
|
||||
void stopFrameTimer();
|
||||
|
||||
bool isThrottleRendering() const;
|
||||
|
||||
int getDeviceWidth() const;
|
||||
int getDeviceHeight() const;
|
||||
QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); }
|
||||
|
||||
protected:
|
||||
|
||||
QTimer _frameTimer;
|
||||
bool _throttleRendering;
|
||||
int _idleRenderInterval;
|
||||
|
||||
virtual void initializeGL();
|
||||
virtual void paintGL();
|
||||
virtual void resizeGL(int width, int height);
|
||||
virtual bool event(QEvent* event);
|
||||
|
||||
private slots:
|
||||
void activeChanged(Qt::ApplicationState state);
|
||||
void throttleRender();
|
||||
bool eventFilter(QObject*, QEvent* event);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_GLCanvas_h
|
|
@ -34,49 +34,3 @@ void Basic2DWindowOpenGLDisplayPlugin::deactivate(PluginContainer* container) {
|
|||
// container->removeMenu(MENU_PATH);
|
||||
MainWindowOpenGLDisplayPlugin::deactivate(container);
|
||||
}
|
||||
|
||||
void Basic2DWindowOpenGLDisplayPlugin::setFullscreen(bool fullscreen) {
|
||||
// The following code block is useful on platforms that can have a visible
|
||||
// app menu in a fullscreen window. However the OSX mechanism hides the
|
||||
// application menu for fullscreen apps, so the check is not required.
|
||||
//#ifndef Q_OS_MAC
|
||||
// if (fullscreen) {
|
||||
// // Move menu to a QWidget floating above _glWidget so that show/hide doesn't adjust viewport.
|
||||
// _menuBarHeight = Menu::getInstance()->height();
|
||||
// Menu::getInstance()->setParent(_fullscreenMenuWidget);
|
||||
// Menu::getInstance()->setFixedWidth(_window->windowHandle()->screen()->size().width());
|
||||
// _fullscreenMenuWidget->show();
|
||||
// }
|
||||
// else {
|
||||
// // Restore menu to being part of MainWindow.
|
||||
// _fullscreenMenuWidget->hide();
|
||||
// _window->setMenuBar(Menu::getInstance());
|
||||
// _window->menuBar()->setMaximumHeight(QWIDGETSIZE_MAX);
|
||||
// }
|
||||
//#endif
|
||||
|
||||
// Work around Qt bug that prevents floating menus being shown when in fullscreen mode.
|
||||
// https://bugreports.qt.io/browse/QTBUG-41883
|
||||
// Known issue: Top-level menu items don't highlight when cursor hovers. This is probably a side-effect of the work-around.
|
||||
// TODO: Remove this work-around once the bug has been fixed and restore the following lines.
|
||||
//_window->setWindowState(fullscreen ? (_window->windowState() | Qt::WindowFullScreen) :
|
||||
// (_window->windowState() & ~Qt::WindowFullScreen));
|
||||
auto window = this->getWindow();
|
||||
window->hide();
|
||||
if (fullscreen) {
|
||||
auto state = window->windowState() | Qt::WindowFullScreen;
|
||||
window->setWindowState(Qt::WindowState((int)state));
|
||||
// The next line produces the following warning in the log:
|
||||
// [WARNING][03 / 06 12:17 : 58] QWidget::setMinimumSize: (/ MainWindow) Negative sizes
|
||||
// (0, -1) are not possible
|
||||
// This is better than the alternative which is to have the window slightly less than fullscreen with a visible line
|
||||
// of pixels for the remainder of the screen.
|
||||
//window->setContentsMargins(0, 0, 0, -1);
|
||||
}
|
||||
else {
|
||||
window->setWindowState(Qt::WindowState(window->windowState() & ~Qt::WindowFullScreen));
|
||||
//window->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
window->show();
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@ public:
|
|||
|
||||
virtual const QString & getName() const override;
|
||||
|
||||
public slots:
|
||||
void setFullscreen(bool fullscreen);
|
||||
|
||||
private:
|
||||
static const QString NAME;
|
||||
};
|
||||
|
|
|
@ -114,12 +114,11 @@ public:
|
|||
virtual void resetSensors() {}
|
||||
virtual float devicePixelRatio() { return 1.0; }
|
||||
|
||||
//// The window for the surface, used for event interception. May be null.
|
||||
//virtual QWindow* getWindow() const = 0;
|
||||
|
||||
// The window for the surface, used for event interception. May be null.
|
||||
virtual QWindow* getWindow() const = 0;
|
||||
|
||||
virtual void installEventFilter(QObject* filter) {}
|
||||
virtual void removeEventFilter(QObject* filter) {}
|
||||
//virtual void installEventFilter(QObject* filter) {}
|
||||
//virtual void removeEventFilter(QObject* filter) {}
|
||||
|
||||
signals:
|
||||
void recommendedFramebufferSizeChanged(const QSize & size);
|
||||
|
|
|
@ -7,23 +7,3 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "MainWindowOpenGLDisplayPlugin.h"
|
||||
|
||||
#include <QOpenGLContext>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <GlWindow.h>
|
||||
#include <plugins/PluginContainer.h>
|
||||
|
||||
MainWindowOpenGLDisplayPlugin::MainWindowOpenGLDisplayPlugin() {
|
||||
}
|
||||
|
||||
GlWindow* MainWindowOpenGLDisplayPlugin::createWindow(PluginContainer * container) {
|
||||
return container->getVisibleWindow();
|
||||
}
|
||||
|
||||
void MainWindowOpenGLDisplayPlugin::customizeWindow(PluginContainer * container) {
|
||||
}
|
||||
|
||||
void MainWindowOpenGLDisplayPlugin::destroyWindow() {
|
||||
_window = nullptr;
|
||||
}
|
||||
|
|
|
@ -10,12 +10,4 @@
|
|||
#include "WindowOpenGLDisplayPlugin.h"
|
||||
|
||||
class MainWindowOpenGLDisplayPlugin : public WindowOpenGLDisplayPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindowOpenGLDisplayPlugin();
|
||||
|
||||
protected:
|
||||
virtual GlWindow* createWindow(PluginContainer * container) override final;
|
||||
virtual void customizeWindow(PluginContainer * container) override final;
|
||||
virtual void destroyWindow() override final;
|
||||
};
|
||||
|
|
|
@ -23,10 +23,6 @@ bool NullDisplayPlugin::hasFocus() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
QWindow* NullDisplayPlugin::getWindow() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NullDisplayPlugin::preRender() {}
|
||||
void NullDisplayPlugin::preDisplay() {}
|
||||
void NullDisplayPlugin::display(GLuint sceneTexture, const glm::uvec2& sceneSize) {}
|
||||
|
|
|
@ -20,7 +20,6 @@ public:
|
|||
|
||||
virtual glm::uvec2 getRecommendedRenderSize() const override;
|
||||
virtual bool hasFocus() const override;
|
||||
virtual QWindow* getWindow() const override;
|
||||
virtual void preRender() override;
|
||||
virtual void preDisplay() override;
|
||||
virtual void display(GLuint sceneTexture, const glm::uvec2& sceneSize) override;
|
||||
|
|
|
@ -31,9 +31,6 @@ public:
|
|||
virtual void display(GLuint sceneTexture, const glm::uvec2& sceneSize) override;
|
||||
|
||||
protected:
|
||||
|
||||
// Needs to be called by the activate method after the GL context has been created to
|
||||
// initialize OpenGL context settings needed by the plugin
|
||||
virtual void customizeContext(PluginContainer * container);
|
||||
virtual void drawUnitQuad();
|
||||
virtual void makeCurrent() = 0;
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
//
|
||||
#include "WindowOpenGLDisplayPlugin.h"
|
||||
|
||||
#include <GlWindow.h>
|
||||
#include <QGLWidget>
|
||||
#include <QOpenGLContext>
|
||||
|
||||
#include "plugins/PluginContainer.h"
|
||||
|
||||
WindowOpenGLDisplayPlugin::WindowOpenGLDisplayPlugin() {
|
||||
}
|
||||
|
||||
|
@ -30,55 +32,24 @@ glm::uvec2 WindowOpenGLDisplayPlugin::getRecommendedUiSize() const {
|
|||
}
|
||||
|
||||
bool WindowOpenGLDisplayPlugin::hasFocus() const {
|
||||
return _window ? _window->isActive() : false;
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::initSurfaceFormat(QSurfaceFormat& format) {
|
||||
// Qt Quick may need a depth and stencil buffer. Always make sure these are available.
|
||||
format.setDepthBufferSize(0);
|
||||
format.setStencilBufferSize(0);
|
||||
format.setVersion(4, 1);
|
||||
#ifdef DEBUG
|
||||
format.setOption(QSurfaceFormat::DebugContext);
|
||||
#endif
|
||||
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
|
||||
return _window ? _window->hasFocus() : false;
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::activate(PluginContainer * container) {
|
||||
OpenGLDisplayPlugin::activate(container);
|
||||
_window = createWindow(container);
|
||||
customizeWindow(container);
|
||||
|
||||
_window = container->getPrimarySurface();
|
||||
_window->makeCurrent();
|
||||
customizeContext(container);
|
||||
_window->doneCurrent();
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::deactivate(PluginContainer* container) {
|
||||
OpenGLDisplayPlugin::deactivate(container);
|
||||
destroyWindow();
|
||||
_window = nullptr;
|
||||
}
|
||||
|
||||
GlWindow* WindowOpenGLDisplayPlugin::createWindow(PluginContainer * container) {
|
||||
GlWindow* result = new GlWindow(QOpenGLContext::currentContext());
|
||||
QSurfaceFormat format;
|
||||
initSurfaceFormat(format);
|
||||
result->setFormat(format);
|
||||
result->create();
|
||||
result->installEventFilter(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::destroyWindow() {
|
||||
_window->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void WindowOpenGLDisplayPlugin::makeCurrent() {
|
||||
bool makeCurrentResult = _window->makeCurrent();
|
||||
if (!makeCurrentResult) {
|
||||
qDebug() << "Failed to make current";
|
||||
}
|
||||
_window->makeCurrent();
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::doneCurrent() {
|
||||
|
@ -88,15 +59,15 @@ void WindowOpenGLDisplayPlugin::doneCurrent() {
|
|||
void WindowOpenGLDisplayPlugin::swapBuffers() {
|
||||
_window->swapBuffers();
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::installEventFilter(QObject* filter) {
|
||||
_window->installEventFilter(filter);
|
||||
}
|
||||
|
||||
void WindowOpenGLDisplayPlugin::removeEventFilter(QObject* filter) {
|
||||
_window->removeEventFilter(filter);
|
||||
}
|
||||
|
||||
QWindow* WindowOpenGLDisplayPlugin::getWindow() const {
|
||||
return _window;
|
||||
}
|
||||
//
|
||||
//void WindowOpenGLDisplayPlugin::installEventFilter(QObject* filter) {
|
||||
// _window->installEventFilter(filter);
|
||||
//}
|
||||
//
|
||||
//void WindowOpenGLDisplayPlugin::removeEventFilter(QObject* filter) {
|
||||
// _window->removeEventFilter(filter);
|
||||
//}
|
||||
//
|
||||
//QWindow* WindowOpenGLDisplayPlugin::getWindow() const {
|
||||
// return _window;
|
||||
//}
|
||||
|
|
|
@ -9,33 +9,22 @@
|
|||
|
||||
#include "OpenGLDisplayPlugin.h"
|
||||
|
||||
class GlWindow;
|
||||
class QSurfaceFormat;
|
||||
class QGLWidget;
|
||||
|
||||
class WindowOpenGLDisplayPlugin : public OpenGLDisplayPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
WindowOpenGLDisplayPlugin();
|
||||
|
||||
virtual glm::uvec2 getRecommendedRenderSize() const override;
|
||||
virtual glm::uvec2 getRecommendedUiSize() const override;
|
||||
virtual bool hasFocus() const override;
|
||||
virtual QWindow* getWindow() const override;
|
||||
virtual void activate(PluginContainer * container) override;
|
||||
virtual void deactivate(PluginContainer* container) override;
|
||||
virtual void installEventFilter(QObject* filter) override;
|
||||
virtual void removeEventFilter(QObject* filter) override;
|
||||
//virtual void installEventFilter(QObject* filter) override;
|
||||
//virtual void removeEventFilter(QObject* filter) override;
|
||||
|
||||
protected:
|
||||
virtual GlWindow* createWindow(PluginContainer * container);
|
||||
virtual void customizeWindow(PluginContainer * container) = 0;
|
||||
|
||||
virtual void destroyWindow();
|
||||
|
||||
virtual void makeCurrent() override;
|
||||
virtual void doneCurrent() override;
|
||||
virtual void swapBuffers() override;
|
||||
virtual void initSurfaceFormat(QSurfaceFormat& format);
|
||||
|
||||
GlWindow* _window{ nullptr };
|
||||
QGLWidget* _window{ nullptr };
|
||||
};
|
||||
|
|
|
@ -3,18 +3,36 @@
|
|||
#include <QString>
|
||||
#include <functional>
|
||||
|
||||
class GlWindow;
|
||||
class QGLWidget;
|
||||
class QScreen;
|
||||
|
||||
class PluginContainer {
|
||||
public:
|
||||
//class Menu {
|
||||
// virtual void addMenu(const QString& menuName) = 0;
|
||||
// virtual void removeMenu(const QString& menuName) = 0;
|
||||
// virtual void addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
|
||||
// virtual void removeMenuItem(const QString& menuName, const QString& menuItem) = 0;
|
||||
// virtual bool isOptionChecked(const QString& name) = 0;
|
||||
// virtual void setIsOptionChecked(const QString& path, bool checked) = 0;
|
||||
//};
|
||||
//virtual Menu* getMenu();
|
||||
//class Surface {
|
||||
// virtual bool makeCurrent() = 0;
|
||||
// virtual void doneCurrent() = 0;
|
||||
// virtual void swapBuffers() = 0;
|
||||
// virtual void setFullscreen(const QScreen* targetScreen) = 0;
|
||||
// virtual void unsetFullscreen() = 0;
|
||||
//};
|
||||
//virtual Surface* getSurface();
|
||||
virtual void addMenu(const QString& menuName) = 0;
|
||||
virtual void removeMenu(const QString& menuName) = 0;
|
||||
virtual void addMenuItem(const QString& path, const QString& name, std::function<void(bool)> onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0;
|
||||
virtual void removeMenuItem(const QString& menuName, const QString& menuItem) = 0;
|
||||
virtual bool isOptionChecked(const QString& name) = 0;
|
||||
virtual void setIsOptionChecked(const QString& path, bool checked) = 0;
|
||||
virtual GlWindow* getVisibleWindow() = 0;
|
||||
virtual void setFullscreen(const QScreen* targetScreen) = 0;
|
||||
virtual void unsetFullscreen() = 0;
|
||||
virtual void showDisplayPluginsTools() = 0;
|
||||
virtual QGLWidget* getPrimarySurface() = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue