QT_BEGIN_NAMESPACE QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format) { QGLFormat retFormat; retFormat.setAccum(format.accum()); if (format.accumBufferSize() >= 0) retFormat.setAccumBufferSize(format.accumBufferSize()); retFormat.setAlpha(format.alpha()); if (format.alphaBufferSize() >= 0) retFormat.setAlphaBufferSize(format.alphaBufferSize()); if (format.blueBufferSize() >= 0) retFormat.setBlueBufferSize(format.blueBufferSize()); retFormat.setDepth(format.depth()); if (format.depthBufferSize() >= 0) retFormat.setDepthBufferSize(format.depthBufferSize()); retFormat.setDirectRendering(format.directRendering()); retFormat.setDoubleBuffer(format.doubleBuffer()); if (format.greenBufferSize() >= 0) retFormat.setGreenBufferSize(format.greenBufferSize()); if (format.redBufferSize() >= 0) retFormat.setRedBufferSize(format.redBufferSize()); retFormat.setRgba(format.rgba()); retFormat.setSampleBuffers(format.sampleBuffers()); retFormat.setSamples(format.sampleBuffers()); retFormat.setStencil(format.stencil()); if (format.stencilBufferSize() >= 0) retFormat.setStencilBufferSize(format.stencilBufferSize()); retFormat.setStereo(format.stereo()); retFormat.setSwapInterval(format.swapInterval()); return retFormat; }
QT_BEGIN_NAMESPACE /*! Returns an OpenGL format for the window format specified by \a format. */ QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format) { QGLFormat retFormat; if (format.alphaBufferSize() >= 0) retFormat.setAlphaBufferSize(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.depthBufferSize() >= 0) retFormat.setDepthBufferSize(format.depthBufferSize()); if (format.samples() > 1) { retFormat.setSampleBuffers(format.samples()); retFormat.setSamples(true); } if (format.stencilBufferSize() > 0) { retFormat.setStencil(true); retFormat.setStencilBufferSize(format.stencilBufferSize()); } retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer); retFormat.setStereo(format.stereo()); return retFormat; }
const QGLFormat GLFormat::asQGLFormat() const { QGLFormat format; format.setVersion(m_majorVersion, m_minorVersion); switch(m_profile) { default: case NoProfile: format.setProfile(QGLFormat::NoProfile); break; case CoreProfile: format.setProfile(QGLFormat::CoreProfile); break; case CompatibilityProfile: format.setProfile(QGLFormat::CompatibilityProfile); break; }; format.setRedBufferSize (m_redBufferSize); format.setGreenBufferSize (m_greenBufferSize); format.setBlueBufferSize (m_blueBufferSize); format.setAlphaBufferSize (m_alphaBufferSize); format.setDepthBufferSize (m_depthBufferSize); format.setStencilBufferSize(m_stencilBufferSize); format.setDoubleBuffer (m_doubleBuffer); format.setStereo (m_stereo); format.setSampleBuffers (m_sampleBuffers); format.setSamples (m_samples); format.setSwapInterval (m_swapInterval); return format; }
// Updates "format" with the parameters of the selected configuration. void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config) { EGLint redSize = 0; EGLint greenSize = 0; EGLint blueSize = 0; EGLint alphaSize = 0; EGLint depthSize = 0; EGLint stencilSize = 0; EGLint sampleCount = 0; EGLint level = 0; EGLDisplay display = QEgl::display(); 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_LEVEL, &level); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); format.setSamples(sampleCount); format.setPlane(level); format.setDirectRendering(true); // All EGL contexts are direct-rendered format.setRgba(true); // EGL doesn't support colour index rendering format.setStereo(false); // EGL doesn't support stereo buffers format.setAccumBufferSize(0); // EGL doesn't support accululation buffers format.setDoubleBuffer(true); // We don't support single buffered EGL contexts // 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(); }
QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL) : QGraphicsSystem(), m_useX11GL(useX11GL) { #if defined(Q_WS_X11) && !defined(QT_OPENGL_ES) // only override the system defaults if the user hasn't already // picked a visual if (X11->visual == 0 && X11->visual_id == -1 && X11->visual_class == -1) { // find a double buffered, RGBA visual that supports OpenGL // and set that as the default visual for windows in Qt int i = 0; int spec[16]; spec[i++] = GLX_RGBA; spec[i++] = GLX_DOUBLEBUFFER; if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) { spec[i++] = GLX_DEPTH_SIZE; spec[i++] = 8; spec[i++] = GLX_STENCIL_SIZE; spec[i++] = 8; spec[i++] = GLX_SAMPLE_BUFFERS_ARB; spec[i++] = 1; spec[i++] = GLX_SAMPLES_ARB; spec[i++] = 4; } spec[i++] = XNone; XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec); if (vi) { X11->visual_id = vi->visualid; X11->visual_class = vi->c_class; QGLFormat format; int res; glXGetConfig(X11->display, vi, GLX_LEVEL, &res); format.setPlane(res); glXGetConfig(X11->display, vi, GLX_DOUBLEBUFFER, &res); format.setDoubleBuffer(res); glXGetConfig(X11->display, vi, GLX_DEPTH_SIZE, &res); format.setDepth(res); if (format.depth()) format.setDepthBufferSize(res); glXGetConfig(X11->display, vi, GLX_RGBA, &res); format.setRgba(res); glXGetConfig(X11->display, vi, GLX_RED_SIZE, &res); format.setRedBufferSize(res); glXGetConfig(X11->display, vi, GLX_GREEN_SIZE, &res); format.setGreenBufferSize(res); glXGetConfig(X11->display, vi, GLX_BLUE_SIZE, &res); format.setBlueBufferSize(res); glXGetConfig(X11->display, vi, GLX_ALPHA_SIZE, &res); format.setAlpha(res); if (format.alpha()) format.setAlphaBufferSize(res); glXGetConfig(X11->display, vi, GLX_ACCUM_RED_SIZE, &res); format.setAccum(res); if (format.accum()) format.setAccumBufferSize(res); glXGetConfig(X11->display, vi, GLX_STENCIL_SIZE, &res); format.setStencil(res); if (format.stencil()) format.setStencilBufferSize(res); glXGetConfig(X11->display, vi, GLX_STEREO, &res); format.setStereo(res); glXGetConfig(X11->display, vi, GLX_SAMPLE_BUFFERS_ARB, &res); format.setSampleBuffers(res); if (format.sampleBuffers()) { glXGetConfig(X11->display, vi, GLX_SAMPLES_ARB, &res); format.setSamples(res); } QGLWindowSurface::surfaceFormat = format; XFree(vi); printf("using visual class %x, id %x\n", X11->visual_class, X11->visual_id); } } #elif defined(Q_WS_WIN) QGLWindowSurface::surfaceFormat.setDoubleBuffer(true); qt_win_owndc_required = true; #endif }