void QMinimalEglScreen::createAndSetPlatformContext() { QSurfaceFormat platformFormat; QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH"); if (depthString.toInt() == 16) { platformFormat.setDepthBufferSize(16); platformFormat.setRedBufferSize(5); platformFormat.setGreenBufferSize(6); platformFormat.setBlueBufferSize(5); m_depth = 16; m_format = QImage::Format_RGB16; } else { platformFormat.setDepthBufferSize(24); platformFormat.setStencilBufferSize(8); platformFormat.setRedBufferSize(8); platformFormat.setGreenBufferSize(8); platformFormat.setBlueBufferSize(8); m_depth = 32; m_format = QImage::Format_RGB32; } if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE")) platformFormat.setSamples(4); EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat); EGLNativeWindowType eglWindow = 0; #ifdef Q_OPENKODE if (kdInitializeNV() == KD_ENOTINITIALIZED) { qFatal("Did not manage to initialize openkode"); } KDWindow *window = kdCreateWindow(m_dpy,config,0); kdRealizeWindow(window,&eglWindow); #endif #ifdef QEGL_EXTRA_DEBUG q_printEglConfig(m_dpy, config); #endif m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL); if (m_surface == EGL_NO_SURFACE) { qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError()); eglTerminate(m_dpy); qFatal("EGL error"); } // qWarning("Created surface %dx%d\n", w, h); QEGLPlatformContext *platformContext = new QMinimalEglContext(platformFormat, 0, m_dpy); m_platformContext = platformContext; EGLint w,h; // screen size detection eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w); eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h); m_geometry = QRect(0,0,w,h); }
static QSurfaceFormat qSurfaceFormatFromPixelFormat(const PIXELFORMATDESCRIPTOR &pfd, QWindowsOpenGLAdditionalFormat *additionalIn = 0) { QSurfaceFormat format; if (pfd.dwFlags & PFD_DOUBLEBUFFER) format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setDepthBufferSize(pfd.cDepthBits); if (pfd.iPixelType == PFD_TYPE_RGBA) format.setAlphaBufferSize(pfd.cAlphaBits); format.setRedBufferSize(pfd.cRedBits); format.setGreenBufferSize(pfd.cGreenBits); format.setBlueBufferSize(pfd.cBlueBits); format.setStencilBufferSize(pfd.cStencilBits); format.setStereo(pfd.dwFlags & PFD_STEREO); if (additionalIn) { QWindowsOpenGLAdditionalFormat additional; if (isDirectRendering(pfd)) additional.formatFlags |= QWindowsGLDirectRendering; if (hasGLOverlay(pfd)) additional.formatFlags |= QWindowsGLOverlay; if (pfd.cAccumRedBits) additional.formatFlags |= QWindowsGLAccumBuffer; if (testFlag(pfd.dwFlags, PFD_DRAW_TO_BITMAP)) { additional.formatFlags |= QWindowsGLRenderToPixmap; additional.pixmapDepth = pfd.cColorBits; } *additionalIn = additional; } return format; }
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() { static QSurfaceFormat format; static std::once_flag once; std::call_once(once, [] { #if defined(USE_GLES) format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(8); #else format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); #endif if (gl::Context::enableDebugLogger()) { format.setOption(QSurfaceFormat::DebugContext); } // Qt Quick may need a depth and stencil buffer. Always make sure these are available. format.setDepthBufferSize(DEFAULT_GL_DEPTH_BUFFER_BITS); format.setStencilBufferSize(DEFAULT_GL_STENCIL_BUFFER_BITS); int major, minor; ::gl::getTargetVersion(major, minor); format.setMajorVersion(major); format.setMinorVersion(minor); }); return format; }
QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced) { QSurfaceFormat retFormat = format; *reduced = true; if (retFormat.redBufferSize() > 1) { retFormat.setRedBufferSize(1); } else if (retFormat.greenBufferSize() > 1) { retFormat.setGreenBufferSize(1); } else if (retFormat.blueBufferSize() > 1) { retFormat.setBlueBufferSize(1); } else if (retFormat.samples() > 1) { retFormat.setSamples(qMin(retFormat.samples() / 2, 16)); } else if (retFormat.stereo()) { retFormat.setStereo(false); }else if (retFormat.stencilBufferSize() > 0) { retFormat.setStencilBufferSize(0); }else if (retFormat.hasAlpha()) { retFormat.setAlphaBufferSize(0); }else if (retFormat.depthBufferSize() > 0) { retFormat.setDepthBufferSize(0); }else if (retFormat.swapBehavior() != QSurfaceFormat::SingleBuffer) { retFormat.setSwapBehavior(QSurfaceFormat::SingleBuffer); }else{ *reduced = false; } return retFormat; }
QSurfaceFormat brcmFixFormat(const QSurfaceFormat &f) { QSurfaceFormat format = f; format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(8); return format; }
QSurfaceFormat QKmsScreen::tweakFormat(const QSurfaceFormat &format) { QSurfaceFormat fmt = format; fmt.setRedBufferSize(8); fmt.setGreenBufferSize(8); fmt.setBlueBufferSize(8); if (fmt.alphaBufferSize() != -1) fmt.setAlphaBufferSize(8); return fmt; }
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) { QSurfaceFormat format; EGLint redSize = 0; EGLint greenSize = 0; EGLint blueSize = 0; EGLint alphaSize = 0; EGLint depthSize = 0; EGLint stencilSize = 0; EGLint sampleCount = 0; EGLint renderableType = 0; eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType); if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT)) format.setRenderableType(QSurfaceFormat::OpenVG); #ifdef EGL_VERSION_1_4 else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType #ifndef QT_NO_OPENGL && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL #endif && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); #endif else format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); format.setSamples(sampleCount); format.setStereo(false); // EGL doesn't support stereo buffers format.setSwapInterval(referenceFormat.swapInterval()); // Clear the EGL error state because some of the above may // have errored out because the attribute is not applicable // to the surface type. Such errors don't matter. eglGetError(); return format; }
QSurfaceFormat QEGLDeviceIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const { QSurfaceFormat format = inputFormat; static const bool force888 = qEnvironmentVariableIntValue("QT_QPA_EGLFS_FORCE888"); if (force888) { format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); } return format; }
QSurfaceFormat QEglFSHooks::surfaceFormatFor(const QSurfaceFormat &inputFormat) const { QSurfaceFormat format = inputFormat; static const bool force888 = qgetenv("QT_QPA_EGLFS_FORCE888").toInt(); if (force888) { format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); } return format; }
QMapboxGL::QMapboxGL(QWindow *parent) : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent) , d_ptr(new QMapboxGLPrivate(this)) { QSurfaceFormat format; format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setStencilBufferSize(8); format.setAlphaBufferSize(8); format.setDepthBufferSize(16); setFormat(format); }
void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3, TestFunction const & fn) { std::vector<char> buf(strlen(testName) + 1); strcpy(buf.data(), testName); char * raw = buf.data(); int argc = 1; QApplication app(argc, &raw); QSurfaceFormat fmt; fmt.setAlphaBufferSize(8); fmt.setBlueBufferSize(8); fmt.setGreenBufferSize(8); fmt.setRedBufferSize(8); fmt.setStencilBufferSize(0); fmt.setSamples(0); fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer); fmt.setSwapInterval(1); fmt.setDepthBufferSize(16); if (apiOpenGLES3) { fmt.setProfile(QSurfaceFormat::CoreProfile); fmt.setVersion(3, 2); } else { fmt.setProfile(QSurfaceFormat::CompatibilityProfile); fmt.setVersion(2, 1); } auto surface = std::make_unique<QOffscreenSurface>(); surface->setFormat(fmt); surface->create(); auto context = std::make_unique<QOpenGLContext>(); context->setFormat(fmt); context->create(); context->makeCurrent(surface.get()); if (fn) fn(apiOpenGLES3); context->doneCurrent(); surface->destroy(); QTimer::singleShot(0, &app, SLOT(quit())); app.exec(); }
int main(int argc, char *argv[]) { // Work around us defaulting to 16 bit colour depth on the pi QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setAlphaBufferSize(8); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); QSurfaceFormat::setDefaultFormat(format); QGuiApplication app(argc, argv); app.setOrganizationName("QPi"); QQmlApplicationEngine appEngine(QUrl("qrc:///qml/main.qml")); return app.exec(); }
/*! Returns a window format for the OpenGL format specified by \a format. */ QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format) { QSurfaceFormat retFormat; if (format.alpha()) retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); if (format.blueBufferSize() >= 0) retFormat.setBlueBufferSize(format.blueBufferSize()); if (format.greenBufferSize() >= 0) retFormat.setGreenBufferSize(format.greenBufferSize()); if (format.redBufferSize() >= 0) retFormat.setRedBufferSize(format.redBufferSize()); if (format.depth()) retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::DefaultSwapBehavior); if (format.sampleBuffers()) retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); if (format.stencil()) retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); retFormat.setStereo(format.stereo()); return retFormat; }
QSurfaceFormat qglx_surfaceFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext) { QSurfaceFormat format; int redSize = 0; int greenSize = 0; int blueSize = 0; int alphaSize = 0; int depthSize = 0; int stencilSize = 0; int sampleBuffers = 0; int sampleCount = 0; int stereo = 0; XVisualInfo *vi = glXGetVisualFromFBConfig(display,config); XFree(vi); glXGetFBConfigAttrib(display, config, GLX_RED_SIZE, &redSize); glXGetFBConfigAttrib(display, config, GLX_GREEN_SIZE, &greenSize); glXGetFBConfigAttrib(display, config, GLX_BLUE_SIZE, &blueSize); glXGetFBConfigAttrib(display, config, GLX_ALPHA_SIZE, &alphaSize); glXGetFBConfigAttrib(display, config, GLX_DEPTH_SIZE, &depthSize); glXGetFBConfigAttrib(display, config, GLX_STENCIL_SIZE, &stencilSize); glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleBuffers); glXGetFBConfigAttrib(display, config, GLX_STEREO, &stereo); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); if (sampleBuffers) { glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleCount); format.setSamples(sampleCount); } format.setStereo(stereo); return format; }
int main(int argc, char ** argv) { QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setAlphaBufferSize(8); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); QSurfaceFormat::setDefaultFormat(format); QGuiApplication app(argc, argv); QWindow *window = 0; QQmlEngine *engine = 0; CodeModel *model = 0; model = new CodeModel(); int exitCode = 0; // Want nicer fonts qputenv("QT_DF_RANGE",QByteArray("0.15")); //qputenv("QML_FIXED_ANIMATION_STEP",QByteArray("1")); QQuickView *qxView = new QuintView(); engine = qxView->engine(); window = qxView; qxView->rootContext()->setContextProperty("codemodel",model); qxView->rootContext()->setContextProperty("view",qxView); qxView->setSource(QUrl("qrc:/quint.qml")); QObject::connect(engine, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); app.setOverrideCursor( QCursor( Qt::BlankCursor ) ); window->showFullScreen(); exitCode = app.exec(); delete window; return exitCode; }
void NcQuickView::ensureOpenGLFormat() { //QGLFormat glFormat; //glFormat.setVersion(3,2); //glFormat.setProfile(QGLFormat::CoreProfile); //QGLFormat::setDefaultFormat(glFormat); QSurfaceFormat glf = QSurfaceFormat::defaultFormat(); glf.setVersion(4,1); glf.setProfile(QSurfaceFormat::CoreProfile); // glf.setOption(QSurfaceFormat::DebugContext); glf.setSamples(4); glf.setSwapBehavior(QSurfaceFormat::SingleBuffer); glf.setRedBufferSize(8); glf.setGreenBufferSize(8); glf.setBlueBufferSize(8); glf.setDepthBufferSize(8); // qDebug() <<"glversion = "<< glf.version(); QSurfaceFormat::setDefaultFormat(glf); // QGLFormat::setDefaultFormat(glFormat); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QSurfaceFormat format; format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat::CoreProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSamples(2); format.setDepthBufferSize(24); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(0); format.setStencilBufferSize(8); QSurfaceFormat::setDefaultFormat(format); DemoGLWindow window; window.show(); return a.exec(); }
/*! Returns a window format for the OpenGL format specified by \a format. */ QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format) { QSurfaceFormat retFormat; if (format.alpha()) retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); if (format.blueBufferSize() >= 0) retFormat.setBlueBufferSize(format.blueBufferSize()); if (format.greenBufferSize() >= 0) retFormat.setGreenBufferSize(format.greenBufferSize()); if (format.redBufferSize() >= 0) retFormat.setRedBufferSize(format.redBufferSize()); if (format.depth()) retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::DefaultSwapBehavior); if (format.sampleBuffers()) retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); if (format.stencil()) retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize()); retFormat.setStereo(format.stereo()); retFormat.setMajorVersion(format.majorVersion()); retFormat.setMinorVersion(format.minorVersion()); retFormat.setProfile(static_cast<QSurfaceFormat::OpenGLContextProfile>(format.profile())); return retFormat; }
void Engine::init() { if (mIsInitialized) { return; } // Create renderer. mRenderer.reset(new Renderer()); mRenderList.reset(new RenderList()); // Create window. mViewer.reset(new QQuickView()); mViewer->setSource(Util::getUrlPathToAsset("Engine/qml/main.qml")); mViewer->setResizeMode(QQuickView::SizeRootObjectToView); // Initially set the window to call glClear for us. This is to prevent an uninitialized frame // buffer from being displayed to the user. We prevent the window from calling glClear later // so that we can render under it. mViewer->setColor(QColor::fromRgba(0x00000000)); mViewer->setClearBeforeRendering(true); // Attempt to select RGB565 with a 16-bit depth buffer. // TODO: According to comments in q_createConfigAttributesFromFormat (qeglconvenience.cpp) this // doesn't work. QSurfaceFormat surfaceFormat; surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); surfaceFormat.setRedBufferSize(5); surfaceFormat.setGreenBufferSize(6); surfaceFormat.setBlueBufferSize(5); surfaceFormat.setDepthBufferSize(16); surfaceFormat.setStencilBufferSize(8); surfaceFormat.setAlphaBufferSize(0); surfaceFormat.setSamples(0); mViewer->setFormat(surfaceFormat); showViewer(); // Load materials. mTextureManager.reset(new TextureManager()); mTerrainMaterials.reset(new TerrainMaterials(Util::getPathToData("materials.json"))); mSoundManager.reset(new SoundManager(this)); // Create UI components. mInputArea = getRoot()->findChild<InputArea*>("inputArea"); Q_ASSERT(mInputArea); mCamera = mViewer->rootObject()->findChild<Camera*>("camera"); mLevelLoader = mCamera->findChild<QQuickItem*>("levelLoader"); // Other connections. connect(mViewer.get(), &QQuickView::beforeSynchronizing, this, &Engine::onBeforeSynchronizing, Qt::DirectConnection); connect(mViewer.get(), &QQuickView::beforeRendering, this, &Engine::onBeforeRendering, Qt::DirectConnection); connect(mViewer.get(), &QQuickView::afterRendering, this, &Engine::onAfterRendering, Qt::DirectConnection); connect(mViewer.get(), &QQuickView::afterAnimating, this, &Engine::update, Qt::DirectConnection); connect(mLevelLoader, SIGNAL(loadCompleted(bool)), this, SLOT(onLoadCompleted(bool))); mContactListener.reset(new ContactListener()); mDestructionListener.reset(new DestructionListener()); mDebugDraw.reset(new LiquidFunDebugDraw()); mIsInitialized = true; }
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QSurfaceFormat format; format.setMajorVersion(4); format.setMinorVersion(1); format.setProfile(QSurfaceFormat::CoreProfile); format.setRenderableType(QSurfaceFormat::OpenGL); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSamples(2); // Today I learned: the surface itself doesn't need an alpha channel. // When we blend colours in OpenGL, the alpha value passed in with the colour // is only used internally by OpenGL in order to calculate the physical RGB // to write back into the colour buffer. We don't need to set any alpha on the // surface itself, since the RGB values will already have been blended by the // time they're written back to the colour buffer. If we do set the alpha, that // means we'll actually be able to see through the surface and whatever is behind // will be visible. This isn't what we want for the application main window! // If we want to create a frame buffer later on where the actual colour buffer // output should be translucent, override the default alpha buffer size to 8 bits. format.setDepthBufferSize(24); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(0); format.setStencilBufferSize(8); QSurfaceFormat::setDefaultFormat(format); qDebug() << "Set default OpenGL format:" << format; QApplication a(argc, argv); a.setApplicationName("Calliper"); a.setApplicationDisplayName("Calliper"); a.setOrganizationName("Infra"); a.setOrganizationName("Infra"); // Initialise the resource manager. ResourceManager::initialise(); // Initialise the renderer. OpenGLRenderer::initialise(); // Initialise the over-arching application. Application::initialise(new MainWindow()); // Set up resources. resourceManager()->makeCurrent(); resourceManager()->setUpOpenGLResources(); renderer()->setUpOpenGLResources(); resourceManager()->doneCurrent(); application()->mainWindow()->show(); int ret = a.exec(); // Shut down the application. Application::shutdown(); // Shut down the renderer. OpenGLRenderer::shutdown(); // Shut down the resource manager. ResourceManager::shutdown(); return ret; return a.exec(); }
static QSurfaceFormat qSurfaceFormatFromHDC(const QOpenGLStaticContext &staticContext, HDC hdc, int pixelFormat, QWindowsOpenGLAdditionalFormat *additionalIn = 0) { enum { attribSize =40 }; QSurfaceFormat result; if (!staticContext.hasExtensions()) return result; int iAttributes[attribSize]; int iValues[attribSize]; qFill(iAttributes, iAttributes + attribSize, int(0)); qFill(iValues, iValues + attribSize, int(0)); int i = 0; const bool hasSampleBuffers = testFlag(staticContext.extensions, QOpenGLStaticContext::SampleBuffers); iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB; // 0 iAttributes[i++] = WGL_DEPTH_BITS_ARB; // 1 iAttributes[i++] = WGL_PIXEL_TYPE_ARB; // 2 iAttributes[i++] = WGL_RED_BITS_ARB; // 3 iAttributes[i++] = WGL_GREEN_BITS_ARB; // 4 iAttributes[i++] = WGL_BLUE_BITS_ARB; // 5 iAttributes[i++] = WGL_ALPHA_BITS_ARB; // 6 iAttributes[i++] = WGL_ACCUM_BITS_ARB; // 7 iAttributes[i++] = WGL_STENCIL_BITS_ARB; // 8 iAttributes[i++] = WGL_STEREO_ARB; // 9 iAttributes[i++] = WGL_ACCELERATION_ARB; // 10 iAttributes[i++] = WGL_NUMBER_OVERLAYS_ARB; // 11 if (hasSampleBuffers) { iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB; // 12 iAttributes[i++] = WGL_SAMPLES_ARB; // 13 } if (!staticContext.wglGetPixelFormatAttribIVARB(hdc, pixelFormat, 0, i, iAttributes, iValues)) { qErrnoWarning("%s: wglGetPixelFormatAttribIVARB() failed for basic parameters.", __FUNCTION__); return result; } result.setSwapBehavior(iValues[0] ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::SingleBuffer); result.setDepthBufferSize(iValues[1]); result.setRedBufferSize(iValues[3]); result.setGreenBufferSize(iValues[4]); result.setBlueBufferSize(iValues[5]); result.setAlphaBufferSize(iValues[6]); result.setStencilBufferSize(iValues[8]); if (iValues[9]) result.setOption(QSurfaceFormat::StereoBuffers); if (hasSampleBuffers) result.setSamples(iValues[13]); if (additionalIn) { if (iValues[7]) additionalIn->formatFlags |= QWindowsGLAccumBuffer; if (iValues[10] == WGL_FULL_ACCELERATION_ARB) additionalIn->formatFlags |= QWindowsGLDirectRendering; if (iValues[11]) additionalIn->formatFlags |= QWindowsGLOverlay; } return result; }
/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); // Utility. QStringList args = app.arguments(); POC_Mode currentMode; if (args.contains("--animations")) currentMode = MODE_ANIMATIONS; else if (args.contains("--loop")) currentMode = MODE_LOOP; else if (args.contains("--seektest")) currentMode = MODE_SEEK; else currentMode = MODE_PLAYER; POC_QMLUtils qmlUtils; QQuickView view; // Set EGL to 24bit color depth. QSurfaceFormat curSurface = view.format(); curSurface.setRedBufferSize(8); curSurface.setGreenBufferSize(8); curSurface.setBlueBufferSize(8); curSurface.setAlphaBufferSize(0); view.setFormat(curSurface); view.engine()->rootContext()->setContextProperty("utils", &qmlUtils); switch (currentMode) { case MODE_ANIMATIONS: view.setSource(QUrl("qrc:///qml/main_animations.qml")); break; case MODE_LOOP: view.setSource(QUrl("qrc:///qml/main_loop.qml")); break; case MODE_SEEK: view.setSource(QUrl(QStringLiteral("qrc:///qml/main_seektest.qml"))); break; default: view.setSource(QUrl("qrc:///qml/main.qml")); break; } qInstallMessageHandler(&log_handler); LC_QMLLogger::registerObject(view.rootContext()); view.setResizeMode(QQuickView::SizeRootObjectToView); #ifdef RASPBERRY view.showFullScreen(); #else view.resize(800, 400); view.show(); #endif // RASPBERRY qApp->connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); // If file path is provided from the command line, I start the player // immediately. switch (currentMode) { case MODE_LOOP: { QStringList list; for (int i = 2; i < args.size(); i++) list << args.at(i); if (list.size() < 1) return log_warn("No items to play."); if (!show_media(&view, list)) return 1; break; } case MODE_PLAYER: if (args.size() > 1) if (!show_media(&view, args.at(1))) return 1; break; default: if (args.size() > 2) if (!show_media(&view, args.at(2))) return 1; break; } return app.exec(); }
QQnxGLContext::QQnxGLContext(QOpenGLContext *glContext) : QPlatformOpenGLContext(), m_glContext(glContext), m_currentEglSurface(EGL_NO_SURFACE) { qGLContextDebug() << Q_FUNC_INFO; QSurfaceFormat format = m_glContext->format(); // Set current rendering API EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API); if (eglResult != EGL_TRUE) qFatal("QQNX: failed to set EGL API, err=%d", eglGetError()); // Get colour channel sizes from window format int alphaSize = format.alphaBufferSize(); int redSize = format.redBufferSize(); int greenSize = format.greenBufferSize(); int blueSize = format.blueBufferSize(); // Check if all channels are don't care if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) { // Set colour channels based on depth of window's screen QQnxScreen *screen = static_cast<QQnxScreen*>(glContext->screen()->handle()); int depth = screen->depth(); if (depth == 32) { // SCREEN_FORMAT_RGBA8888 alphaSize = 8; redSize = 8; greenSize = 8; blueSize = 8; } else { // SCREEN_FORMAT_RGB565 alphaSize = 0; redSize = 5; greenSize = 6; blueSize = 5; } } else { // Choose best match based on supported pixel formats if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) { // SCREEN_FORMAT_RGB565 alphaSize = 0; redSize = 5; greenSize = 6; blueSize = 5; } else { // SCREEN_FORMAT_RGBA8888 alphaSize = 8; redSize = 8; greenSize = 8; blueSize = 8; } } // Update colour channel sizes in window format format.setAlphaBufferSize(alphaSize); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); // Select EGL config based on requested window format m_eglConfig = q_configFromGLFormat(ms_eglDisplay, format); if (m_eglConfig == 0) qFatal("QQnxGLContext: failed to find EGL config"); QQnxGLContext *glShareContext = static_cast<QQnxGLContext*>(m_glContext->shareHandle()); m_eglShareContext = glShareContext ? glShareContext->m_eglContext : EGL_NO_CONTEXT; m_eglContext = eglCreateContext(ms_eglDisplay, m_eglConfig, m_eglShareContext, contextAttrs(format)); if (m_eglContext == EGL_NO_CONTEXT) { checkEGLError("eglCreateContext"); qFatal("QQnxGLContext: failed to create EGL context, err=%d", eglGetError()); } // Query/cache window format of selected EGL config m_windowFormat = q_glFormatFromConfig(ms_eglDisplay, m_eglConfig); }