Fixing preview / vsync functionality

This commit is contained in:
Brad Davis 2015-12-04 12:46:19 -08:00
parent 90ef7c6bf7
commit 11917ca501
10 changed files with 35 additions and 18 deletions

View file

@ -620,6 +620,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// enable mouse tracking; otherwise, we only get drag events
_glWidget->setMouseTracking(true);
_glWidget->makeCurrent();
_glWidget->initializeGL();
_offscreenContext = new OffscreenGLCanvas();
_offscreenContext->create(_glWidget->context()->contextHandle());
@ -1194,6 +1196,9 @@ void Application::paintGL() {
QSize size = getDeviceSize();
renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
_applicationOverlay.renderOverlay(&renderArgs);
gpu::FramebufferPointer overlayFramebuffer = _applicationOverlay.getOverlayFramebuffer();
}
{

View file

@ -150,7 +150,7 @@ void PluginContainerProxy::showDisplayPluginsTools() {
DependencyManager::get<DialogsManager>()->hmdTools(true);
}
QGLWidget* PluginContainerProxy::getPrimaryWidget() {
GLWidget* PluginContainerProxy::getPrimaryWidget() {
return qApp->_glWidget;
}

View file

@ -27,7 +27,7 @@ class PluginContainerProxy : public QObject, PluginContainer {
virtual bool makeRenderingContextCurrent() override;
virtual void releaseSceneTexture(uint32_t texture) override;
virtual void releaseOverlayTexture(uint32_t texture) override;
virtual QGLWidget* getPrimaryWidget() override;
virtual GLWidget* getPrimaryWidget() override;
virtual QWindow* getPrimaryWindow() override;
virtual QOpenGLContext* getPrimaryContext() override;
virtual bool isForeground() override;

View file

@ -17,6 +17,7 @@
#include <QtGui/QOpenGLContext>
#include <QtGui/QImage>
#include <gl/GLWidget.h>
#include <NumericalConstants.h>
#include <DependencyManager.h>
#include <plugins/PluginContainer.h>
@ -145,8 +146,6 @@ private:
QGLContext* _context { nullptr };
};
bool OpenGLDisplayPlugin::_vsyncSupported = false;
OpenGLDisplayPlugin::OpenGLDisplayPlugin() {
_sceneTextureEscrow.setRecycler([this](GLuint texture){
cleanupForSceneTexture(texture);
@ -172,19 +171,14 @@ void OpenGLDisplayPlugin::cleanupForSceneTexture(uint32_t sceneTexture) {
void OpenGLDisplayPlugin::activate() {
_timer.start(2);
_timer.start(1);
_vsyncSupported = _container->getPrimaryWidget()->isVsyncSupported();
// Start the present thread if necessary
auto presentThread = DependencyManager::get<PresentThread>();
if (!presentThread) {
auto widget = _container->getPrimaryWidget();
// TODO: write the proper code for linux
#if defined(Q_OS_WIN)
widget->makeCurrent();
_vsyncSupported = wglewGetExtension("WGL_EXT_swap_control");
widget->doneCurrent();
#endif
DependencyManager::set<PresentThread>();
presentThread = DependencyManager::get<PresentThread>();
@ -195,7 +189,6 @@ void OpenGLDisplayPlugin::activate() {
}
presentThread->setNewDisplayPlugin(this);
DisplayPlugin::activate();
emit requestRender();
}
void OpenGLDisplayPlugin::stop() {

View file

@ -81,7 +81,7 @@ protected:
GLTextureEscrow _overlayTextureEscrow;
GLTextureEscrow _sceneTextureEscrow;
static bool _vsyncSupported;
bool _vsyncSupported { false };
};

View file

@ -7,7 +7,7 @@
//
#include "WindowOpenGLDisplayPlugin.h"
#include <QGLWidget>
#include <gl/GLWidget.h>
#include "plugins/PluginContainer.h"

View file

@ -7,6 +7,7 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtGlobal>
#include "GLWidget.h"
@ -16,11 +17,14 @@
#include <QtCore/QUrl>
#include <QtCore/QCoreApplication>
#include <QtGui/QOpenGLContext>
#include <QtGui/QKeyEvent>
#include <QtGui/QWindow>
#include "GLHelpers.h"
GLWidget::GLWidget() : QGLWidget(getDefaultGLFormat()) {
#ifdef Q_OS_LINUX
// Cause GLWidget::eventFilter to be called.
@ -42,6 +46,12 @@ void GLWidget::initializeGL() {
setAcceptDrops(true);
// 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);
// TODO: write the proper code for linux
makeCurrent();
#if defined(Q_OS_WIN)
_vsyncSupported = context()->contextHandle()->hasExtension("WGL_EXT_swap_control");;
#endif
}
void GLWidget::paintEvent(QPaintEvent* event) {
@ -112,3 +122,8 @@ bool GLWidget::eventFilter(QObject*, QEvent* event) {
}
return false;
}
bool GLWidget::isVsyncSupported() const {
return _vsyncSupported;
}

View file

@ -21,15 +21,19 @@ public:
int getDeviceWidth() const;
int getDeviceHeight() const;
QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); }
bool isVsyncSupported() const;
virtual void initializeGL() override;
protected:
virtual void initializeGL() override;
virtual bool event(QEvent* event) override;
virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
private slots:
virtual bool eventFilter(QObject*, QEvent* event) override;
private:
bool _vsyncSupported { false };
};

View file

@ -16,7 +16,7 @@
#include "Forward.h"
class QAction;
class QGLWidget;
class GLWidget;
class QScreen;
class QOpenGLContext;
class QWindow;
@ -41,7 +41,7 @@ public:
virtual bool makeRenderingContextCurrent() = 0;
virtual void releaseSceneTexture(uint32_t texture) = 0;
virtual void releaseOverlayTexture(uint32_t texture) = 0;
virtual QGLWidget* getPrimaryWidget() = 0;
virtual GLWidget* getPrimaryWidget() = 0;
virtual QWindow* getPrimaryWindow() = 0;
virtual QOpenGLContext* getPrimaryContext() = 0;
virtual bool isForeground() = 0;

View file

@ -94,7 +94,7 @@ public:
virtual bool makeRenderingContextCurrent() override { return true; }
virtual void releaseSceneTexture(uint32_t texture) override {}
virtual void releaseOverlayTexture(uint32_t texture) override {}
virtual QGLWidget* getPrimaryWidget() override { return nullptr; }
virtual GLWidget* getPrimaryWidget() override { return nullptr; }
virtual QWindow* getPrimaryWindow() override { return nullptr; }
virtual QOpenGLContext* getPrimaryContext() override { return nullptr; }
virtual bool isForeground() override { return true; }