Check qml gl context on create

This commit is contained in:
Zach Pomerantz 2016-03-17 16:27:36 -07:00
parent edcf642410
commit 60f22c51b9
3 changed files with 21 additions and 7 deletions

View file

@ -32,17 +32,27 @@ OffscreenGLCanvas::~OffscreenGLCanvas() {
_context->doneCurrent();
}
void OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
if (nullptr != sharedContext) {
sharedContext->doneCurrent();
_context->setShareContext(sharedContext);
}
_context->setFormat(getDefaultOpenGLSurfaceFormat());
_context->create();
if (_context->create()) {
_offscreenSurface->setFormat(_context->format());
_offscreenSurface->create();
return true;
}
_offscreenSurface->setFormat(_context->format());
_offscreenSurface->create();
std::call_once(_reportOnce, []{
qWarning() << "GL Version: " << QString((const char*) glGetString(GL_VERSION));
qWarning() << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
qWarning() << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR));
qWarning() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
qWarning() << "Failed to create OffscreenGLCanvas";
});
return false;
}
bool OffscreenGLCanvas::makeCurrent() {

View file

@ -23,7 +23,7 @@ class OffscreenGLCanvas : public QObject {
public:
OffscreenGLCanvas();
~OffscreenGLCanvas();
void create(QOpenGLContext* sharedContext = nullptr);
bool create(QOpenGLContext* sharedContext = nullptr);
bool makeCurrent();
void doneCurrent();
QOpenGLContext* getContext() {

View file

@ -65,7 +65,11 @@ class OffscreenQmlRenderer : public OffscreenGLCanvas {
public:
OffscreenQmlRenderer(OffscreenQmlSurface* surface, QOpenGLContext* shareContext) : _surface(surface) {
OffscreenGLCanvas::create(shareContext);
if (!OffscreenGLCanvas::create(shareContext)) {
static const char* error = "Failed to create OffscreenGLCanvas";
qWarning() << error;
throw error;
};
_renderControl = new QMyQuickRenderControl();
@ -153,7 +157,7 @@ private:
qWarning("Failed to make context current on render thread");
return;
}
_renderControl->initialize(_context);
_renderControl->initialize(getContext());
setupFbo();
_escrow.setRecycler([this](GLuint texture){
_textures.recycleTexture(texture);