40 int opengl_minor_version)
41 : parent_thread_(QThread::currentThread()),
42 current_thread_(nullptr),
43 make_current_action_(new QAction(this)) {
44 CHECK_NOTNULL(QCoreApplication::instance());
45 CHECK_EQ(QCoreApplication::instance()->thread(), QThread::currentThread());
48 format.setDepthBufferSize(24);
49 format.setMajorVersion(opengl_major_version);
50 format.setMinorVersion(opengl_minor_version);
52 format.setProfile(QSurfaceFormat::CompatibilityProfile);
53 context_.setFormat(
format);
56 CHECK(context_.create());
57 context_.makeCurrent(&surface_);
58 CHECK(context_.isValid()) <<
"Could not create valid OpenGL context";
61 make_current_action_, &QAction::triggered,
this,
63 CHECK_NOTNULL(current_thread_);
64 context_.doneCurrent();
65 context_.moveToThread(current_thread_);
67 Qt::BlockingQueuedConnection);
70 void OpenGLContextManager::MakeCurrent() {
71 current_thread_ = QThread::currentThread();
72 make_current_action_->trigger();
73 context_.makeCurrent(&surface_);
74 CHECK(context_.isValid()) <<
"Could not make current valid OpenGL context";
77 bool OpenGLContextManager::HasOpenGL() {
79 QOffscreenSurface surface;
83 return surface.isValid() &&
context.isValid();
90 std::thread opengl_thread([thread]() {
93 CHECK_NOTNULL(QCoreApplication::instance())->exit();
95 CHECK_NOTNULL(QCoreApplication::instance())->exec();
99 QCoreApplication::processEvents();
102 void GLError(
const char* file,
const int line) {
103 GLenum error_code(glGetError());
104 while (error_code != GL_NO_ERROR) {
105 std::string error_name;
106 switch (error_code) {
107 case GL_INVALID_OPERATION:
108 error_name =
"INVALID_OPERATION";
110 case GL_INVALID_ENUM:
111 error_name =
"INVALID_ENUM";
113 case GL_INVALID_VALUE:
114 error_name =
"INVALID_VALUE";
116 case GL_OUT_OF_MEMORY:
117 error_name =
"OUT_OF_MEMORY";
119 case GL_INVALID_FRAMEBUFFER_OPERATION:
120 error_name =
"INVALID_FRAMEBUFFER_OPERATION";
123 error_name =
"UNKNOWN_ERROR";
126 fprintf(stderr,
"OpenGL error [%s, line %i]: GL_%s", file, line,
128 error_code = glGetError();
filament::Texture::InternalFormat format
OpenGLContextManager(int opengl_major_version=2, int opengl_minor_version=1)
void GLError(const char *file, const int line)
void RunThreadWithOpenGLContext(Thread *thread)