Skip to content

Commit

Permalink
guisys: try both init modes
Browse files Browse the repository at this point in the history
  • Loading branch information
VelorumS committed Apr 29, 2017
1 parent 2b90c96 commit 3ea6df9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
32 changes: 7 additions & 25 deletions libopenage/gui/guisys/private/gui_renderer_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
// Copyright 2015-2017 the openage authors. See copying.md for legal info.

#include "gui_renderer_impl.h"

Expand All @@ -12,7 +12,6 @@
#include <QThread>

#include "../public/gui_renderer.h"
#include "platforms/context_extraction.h"


namespace qtsdl {
Expand Down Expand Up @@ -77,6 +76,7 @@ void EventHandlingQuickWindow::on_resized(const QSize &size) {
GuiRendererImpl::GuiRendererImpl(SDL_Window *window)
:
QObject{},
gui_rendering_setup_routines{window},
need_fbo_resize{true},
need_sync{},
need_render{},
Expand All @@ -85,26 +85,6 @@ GuiRendererImpl::GuiRendererImpl(SDL_Window *window)

this->moveToThread(QCoreApplication::instance()->thread());

QVariant handle;
WId id;

std::tie(handle, id) = extract_native_context(window);

// pass the SDL opengl context so qt can use it
this->ctx = std::make_unique<QOpenGLContext>();
this->ctx->setNativeHandle(handle);
this->ctx->create();
assert(this->ctx->isValid());

// reuse the sdl window
QWindow *w = QWindow::fromWinId(id);
w->setSurfaceType(QSurface::OpenGLSurface);

if (!this->ctx->makeCurrent(w)) {
assert(false);
return;
}

QObject::connect(&this->render_control, &QQuickRenderControl::renderRequested, [&] () {
this->need_render = true;
});
Expand All @@ -125,9 +105,9 @@ GuiRendererImpl::GuiRendererImpl(SDL_Window *window)
QObject::connect(&*this->window, &QQuickWindow::widthChanged, [this] { this->new_fbo_width = this->window->width(); this->need_fbo_resize = true; });
QObject::connect(&*this->window, &QQuickWindow::heightChanged, [this] { this->new_fbo_height = this->window->height(); this->need_fbo_resize = true; });

this->render_control.initialize(&*this->ctx);
GuiRenderingCtxActivator activate_render(this->gui_rendering_setup_routines);

assert(this->ctx->isValid());
this->render_control.initialize(this->gui_rendering_setup_routines.get_ctx());
}

void GuiRendererImpl::on_scene_changed() {
Expand All @@ -137,7 +117,7 @@ void GuiRendererImpl::on_scene_changed() {
}

void GuiRendererImpl::reinit_fbo_if_needed() {
assert(QThread::currentThread() == this->ctx->thread());
assert(QThread::currentThread() == this->gui_rendering_setup_routines.get_ctx()->thread());

if (this->need_fbo_resize) {
this->fbo = std::make_unique<QOpenGLFramebufferObject>(QSize(this->new_fbo_width, this->new_fbo_height), QOpenGLFramebufferObject::CombinedDepthStencil);
Expand All @@ -163,6 +143,8 @@ GuiRendererImpl* GuiRendererImpl::impl(GuiRenderer *renderer) {
}

GLuint GuiRendererImpl::render() {
GuiRenderingCtxActivator activate_render(this->gui_rendering_setup_routines);

this->reinit_fbo_if_needed();

// QQuickRenderControl::sync() must be called from the render thread while the gui thread is stopped.
Expand Down
11 changes: 6 additions & 5 deletions libopenage/gui/guisys/private/gui_renderer_impl.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
// Copyright 2015-2017 the openage authors. See copying.md for legal info.

#pragma once

#include <memory>
#include <functional>
#include <atomic>
#include <mutex>
#include <condition_variable>
Expand All @@ -14,9 +13,10 @@
#include <QQuickRenderControl>
#include <QOffscreenSurface>

#include "gui_rendering_setup_routines.h"

struct SDL_Window;

QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject)

namespace qtsdl {
Expand Down Expand Up @@ -111,9 +111,10 @@ private slots:
void reinit_fbo_if_needed();

/**
* GL context of the game
* Contains rendering context
* Use GuiRenderingCtxActivator to enable it
*/
std::unique_ptr<QOpenGLContext> ctx;
GuiRenderingSetupRoutines gui_rendering_setup_routines;

/**
* Contains scene graph of the GUI
Expand Down

0 comments on commit 3ea6df9

Please sign in to comment.