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(); _context->doneCurrent();
} }
void OffscreenGLCanvas::create(QOpenGLContext* sharedContext) { bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
if (nullptr != sharedContext) { if (nullptr != sharedContext) {
sharedContext->doneCurrent(); sharedContext->doneCurrent();
_context->setShareContext(sharedContext); _context->setShareContext(sharedContext);
} }
_context->setFormat(getDefaultOpenGLSurfaceFormat()); _context->setFormat(getDefaultOpenGLSurfaceFormat());
_context->create(); if (_context->create()) {
_offscreenSurface->setFormat(_context->format());
_offscreenSurface->create();
return true;
}
_offscreenSurface->setFormat(_context->format()); std::call_once(_reportOnce, []{
_offscreenSurface->create(); 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() { bool OffscreenGLCanvas::makeCurrent() {

View file

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

View file

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