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
1212#include < QThread>
1313
1414#include " ../public/gui_renderer.h"
15- #include " platforms/context_extraction.h"
1615
1716
1817namespace qtsdl {
@@ -77,6 +76,7 @@ void EventHandlingQuickWindow::on_resized(const QSize &size) {
7776GuiRendererImpl::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
133113void GuiRendererImpl::on_scene_changed () {
@@ -137,7 +117,7 @@ void GuiRendererImpl::on_scene_changed() {
137117}
138118
139119void 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
165145GLuint 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.
0 commit comments