Skip to content

Commit c055843

Browse files
committed
guisys: try both init modes
1 parent 05b93ad commit c055843

2 files changed

Lines changed: 13 additions & 30 deletions

File tree

libopenage/gui/guisys/private/gui_renderer_impl.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
1+
// Copyright 2015-2017 the openage authors. See copying.md for legal info.
22

33
#include "gui_renderer_impl.h"
44

@@ -12,7 +12,6 @@
1212
#include <QThread>
1313

1414
#include "../public/gui_renderer.h"
15-
#include "platforms/context_extraction.h"
1615

1716

1817
namespace qtsdl {
@@ -77,6 +76,7 @@ void EventHandlingQuickWindow::on_resized(const QSize &size) {
7776
GuiRendererImpl::GuiRendererImpl(SDL_Window *window)
7877
:
7978
QObject{},
79+
gui_rendering_setup_routines{window},
8080
need_fbo_resize{true},
8181
need_sync{},
8282
need_render{},
@@ -85,26 +85,6 @@ GuiRendererImpl::GuiRendererImpl(SDL_Window *window)
8585

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

88-
QVariant handle;
89-
WId id;
90-
91-
std::tie(handle, id) = extract_native_context(window);
92-
93-
// pass the SDL opengl context so qt can use it
94-
this->ctx = std::make_unique<QOpenGLContext>();
95-
this->ctx->setNativeHandle(handle);
96-
this->ctx->create();
97-
assert(this->ctx->isValid());
98-
99-
// reuse the sdl window
100-
QWindow *w = QWindow::fromWinId(id);
101-
w->setSurfaceType(QSurface::OpenGLSurface);
102-
103-
if (!this->ctx->makeCurrent(w)) {
104-
assert(false);
105-
return;
106-
}
107-
10888
QObject::connect(&this->render_control, &QQuickRenderControl::renderRequested, [&] () {
10989
this->need_render = true;
11090
});
@@ -125,9 +105,9 @@ GuiRendererImpl::GuiRendererImpl(SDL_Window *window)
125105
QObject::connect(&*this->window, &QQuickWindow::widthChanged, [this] { this->new_fbo_width = this->window->width(); this->need_fbo_resize = true; });
126106
QObject::connect(&*this->window, &QQuickWindow::heightChanged, [this] { this->new_fbo_height = this->window->height(); this->need_fbo_resize = true; });
127107

128-
this->render_control.initialize(&*this->ctx);
108+
GuiRenderingCtxActivator activate_render(this->gui_rendering_setup_routines);
129109

130-
assert(this->ctx->isValid());
110+
this->render_control.initialize(this->gui_rendering_setup_routines.get_ctx());
131111
}
132112

133113
void GuiRendererImpl::on_scene_changed() {
@@ -137,7 +117,7 @@ void GuiRendererImpl::on_scene_changed() {
137117
}
138118

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

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

165145
GLuint GuiRendererImpl::render() {
146+
GuiRenderingCtxActivator activate_render(this->gui_rendering_setup_routines);
147+
166148
this->reinit_fbo_if_needed();
167149

168150
// QQuickRenderControl::sync() must be called from the render thread while the gui thread is stopped.

libopenage/gui/guisys/private/gui_renderer_impl.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
1+
// Copyright 2015-2017 the openage authors. See copying.md for legal info.
22

33
#pragma once
44

55
#include <memory>
6-
#include <functional>
76
#include <atomic>
87
#include <mutex>
98
#include <condition_variable>
@@ -14,9 +13,10 @@
1413
#include <QQuickRenderControl>
1514
#include <QOffscreenSurface>
1615

16+
#include "gui_rendering_setup_routines.h"
17+
1718
struct SDL_Window;
1819

19-
QT_FORWARD_DECLARE_CLASS(QOpenGLContext)
2020
QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject)
2121

2222
namespace qtsdl {
@@ -111,9 +111,10 @@ private slots:
111111
void reinit_fbo_if_needed();
112112

113113
/**
114-
* GL context of the game
114+
* Contains rendering context
115+
* Use GuiRenderingCtxActivator to enable it
115116
*/
116-
std::unique_ptr<QOpenGLContext> ctx;
117+
GuiRenderingSetupRoutines gui_rendering_setup_routines;
117118

118119
/**
119120
* Contains scene graph of the GUI

0 commit comments

Comments
 (0)