#include <QOffscreenSurface>
#include <QWindow>
-CubeRenderer::CubeRenderer()
- : m_context(0),
+CubeRenderer::CubeRenderer(QOffscreenSurface *offscreenSurface)
+ : m_offscreenSurface(offscreenSurface),
+ m_context(0),
m_program(0),
m_vbo(0)
{
{
// Use a temporary offscreen surface to do the cleanup.
// There may not be a native window surface available anymore at this stage.
- QScopedPointer<QOffscreenSurface> offscreenSurface(new QOffscreenSurface);
- offscreenSurface->setFormat(m_context->format());
- offscreenSurface->create();
- m_context->makeCurrent(offscreenSurface.data());
+ m_context->makeCurrent(m_offscreenSurface);
delete m_program;
delete m_vbo;
QT_FORWARD_DECLARE_CLASS(QOpenGLBuffer)
QT_FORWARD_DECLARE_CLASS(QOpenGLVertexArrayObject)
QT_FORWARD_DECLARE_CLASS(QWindow)
+QT_FORWARD_DECLARE_CLASS(QOffscreenSurface)
class CubeRenderer
{
public:
- CubeRenderer();
+ CubeRenderer(QOffscreenSurface *offscreenSurface);
~CubeRenderer();
void resize(int w, int h);
void init(QWindow *w, QOpenGLContext *share);
void setupVertexAttribs();
+ QOffscreenSurface *m_offscreenSurface;
QOpenGLContext *m_context;
QOpenGLShaderProgram *m_program;
QOpenGLBuffer *m_vbo;
{
m_context->makeCurrent(m_surface);
- m_cubeRenderer = new CubeRenderer;
+ // Pass our offscreen surface to the cube renderer just so that it will
+ // have something is can make current during cleanup. QOffscreenSurface,
+ // just like QWindow, must always be created on the gui thread (as it might
+ // be backed by an actual QWindow).
+ m_cubeRenderer = new CubeRenderer(m_surface);
m_cubeRenderer->resize(m_window->width(), m_window->height());
m_renderControl->initialize(m_context);
m_offscreenSurface->setFormat(m_context->format());
m_offscreenSurface->create();
- m_cubeRenderer = new CubeRenderer;
+ m_cubeRenderer = new CubeRenderer(m_offscreenSurface);
m_renderControl = new QQuickRenderControl(this);
m_context->doneCurrent();
+ delete m_cubeRenderer;
+
delete m_offscreenSurface;
delete m_context;
-
- delete m_cubeRenderer;
}
void WindowSingleThreaded::createFbo()