From a1f0a650578b71fddae9db05435715338b15ba35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Fri, 6 Aug 2010 07:53:28 +0200 Subject: Make the GLX integration give more correct format Also create a correct window for the format. --- src/gui/kernel/qplatformwindowformat_qpa.cpp | 24 ++++ src/gui/kernel/qplatformwindowformat_qpa.h | 7 + src/opengl/qgl_qpa.cpp | 3 +- src/plugins/platforms/testlite/qglxintegration.cpp | 159 ++++++++++++--------- src/plugins/platforms/testlite/qglxintegration.h | 7 +- src/plugins/platforms/testlite/qtestlitewindow.cpp | 25 ++-- 6 files changed, 138 insertions(+), 87 deletions(-) diff --git a/src/gui/kernel/qplatformwindowformat_qpa.cpp b/src/gui/kernel/qplatformwindowformat_qpa.cpp index 1112ba9..d497e85 100644 --- a/src/gui/kernel/qplatformwindowformat_qpa.cpp +++ b/src/gui/kernel/qplatformwindowformat_qpa.cpp @@ -41,6 +41,8 @@ #include "qplatformwindowformat_qpa.h" +#include + Q_GLOBAL_STATIC(QPlatformWindowFormat, q_platformwindow_default_format); class QPlatformWindowFormatPrivate @@ -986,3 +988,25 @@ bool operator!=(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) { return !(a == b); } + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QPlatformWindowFormat &f) +{ + const QPlatformWindowFormatPrivate * const d = f.d; + + dbg.nospace() << "QGLFormat(" + << "options " << d->opts + << ", depthBufferSize " << d->depthSize + << ", accumBufferSize " << d->accumSize + << ", stencilBufferSize " << d->stencilSize + << ", redBufferSize " << d->redSize + << ", greenBufferSize " << d->greenSize + << ", blueBufferSize " << d->blueSize + << ", alphaBufferSize " << d->alphaSize + << ", samples " << d->numSamples + << ", swapInterval " << d->swapInterval + << ')'; + + return dbg.space(); +} +#endif diff --git a/src/gui/kernel/qplatformwindowformat_qpa.h b/src/gui/kernel/qplatformwindowformat_qpa.h index 37e628d..075e796 100644 --- a/src/gui/kernel/qplatformwindowformat_qpa.h +++ b/src/gui/kernel/qplatformwindowformat_qpa.h @@ -163,11 +163,18 @@ private: friend Q_GUI_EXPORT bool operator==(const QPlatformWindowFormat&, const QPlatformWindowFormat&); friend Q_GUI_EXPORT bool operator!=(const QPlatformWindowFormat&, const QPlatformWindowFormat&); +#ifndef QT_NO_DEBUG_STREAM + friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QPlatformWindowFormat &); +#endif }; Q_GUI_EXPORT bool operator==(const QPlatformWindowFormat&, const QPlatformWindowFormat&); Q_GUI_EXPORT bool operator!=(const QPlatformWindowFormat&, const QPlatformWindowFormat&); +#ifndef QT_NO_DEBUG_STREAM +Q_OPENGL_EXPORT QDebug operator<<(QDebug, const QPlatformWindowFormat &); +#endif + Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformWindowFormat::FormatOptions) inline bool QPlatformWindowFormat::doubleBuffer() const diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index 3d5b74f..5f0bca3 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -105,7 +105,8 @@ static QPlatformWindowFormat qt_glformat_to_platformwindowformat(const QGLFormat retFormat.setRedBufferSize(format.redBufferSize()); retFormat.setRgba(format.rgba()); retFormat.setSampleBuffers(format.sampleBuffers()); - retFormat.setSamples(format.sampleBuffers()); + if (format.samples() >= 0) + retFormat.setSamples(format.samples()); retFormat.setStencil(format.stencil()); if (format.stencilBufferSize() >= 0) retFormat.setStencilBufferSize(format.stencilBufferSize()); diff --git a/src/plugins/platforms/testlite/qglxintegration.cpp b/src/plugins/platforms/testlite/qglxintegration.cpp index 57f9de4..47a4f5a 100644 --- a/src/plugins/platforms/testlite/qglxintegration.cpp +++ b/src/plugins/platforms/testlite/qglxintegration.cpp @@ -63,69 +63,94 @@ QVector QGLXGLContext::buildSpec(const QPlatformWindowFormat &format) { QVector spec(48); int i = 0; - int depthSize = 0; - int stencilSize = 0; - int sampleSize = 0; - - if (format.depth()) - depthSize = (format.depthBufferSize() == -1) ? 1 : format.depthBufferSize(); - if (format.stencil()) - stencilSize = (format.stencilBufferSize() == -1) ? 1 : format.stencilBufferSize(); - if (format.sampleBuffers()) - sampleSize = (format.samples() == -1) ? 1 : format.samples(); + spec[i++] = GLX_LEVEL; + spec[i++] = 0; spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_WINDOW_BIT; - spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_RGBA_BIT; + + if (format.rgba()) { + spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_RGBA_BIT; + spec[i++] = GLX_RED_SIZE; spec[i++] = (format.redBufferSize() == -1) ? 1 : format.redBufferSize(); + spec[i++] = GLX_GREEN_SIZE; spec[i++] = (format.greenBufferSize() == -1) ? 1 : format.greenBufferSize(); + spec[i++] = GLX_BLUE_SIZE; spec[i++] = (format.blueBufferSize() == -1) ? 1 : format.blueBufferSize(); + if (format.alpha()) { + spec[i++] = GLX_ALPHA_SIZE; spec[i++] = (format.alphaBufferSize() == -1) ? 1 : format.alphaBufferSize(); + } + + spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + + if (format.alpha()) { + spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 1 : format.accumBufferSize(); + } + + } else { + spec[i++] = GLX_RENDER_TYPE; spec[i++] = GLX_COLOR_INDEX_BIT; //I'm really not sure if this works.... + spec[i++] = GLX_BUFFER_SIZE; spec[i++] = 8; + } + spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.doubleBuffer() ? True : False; spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False; - spec[i++] = GLX_DEPTH_SIZE; spec[i++] = depthSize; - spec[i++] = GLX_STENCIL_SIZE; spec[i++] = stencilSize; - spec[i++] = GLX_SAMPLE_BUFFERS_ARB; spec[i++] = sampleSize; + if (format.depth()) { + spec[i++] = GLX_DEPTH_SIZE; spec[i++] = (format.depthBufferSize() == -1) ? 1 : format.depthBufferSize(); + } - spec[i++] = GLX_RED_SIZE; spec[i++] = (format.redBufferSize() == -1) ? 1 : format.redBufferSize(); - spec[i++] = GLX_GREEN_SIZE; spec[i++] = (format.greenBufferSize() == -1) ? 1 : format.greenBufferSize(); - spec[i++] = GLX_BLUE_SIZE; spec[i++] = (format.blueBufferSize() == -1) ? 1 : format.blueBufferSize(); - spec[i++] = GLX_ALPHA_SIZE; spec[i++] = (format.alphaBufferSize() == -1) ? 0 : format.alphaBufferSize(); + if (format.stencil()) { + spec[i++] = GLX_STENCIL_SIZE; spec[i++] = (format.stencilBufferSize() == -1) ? 1 : format.stencilBufferSize(); + } + if (format.sampleBuffers()) { + spec[i++] = GLX_SAMPLE_BUFFERS_ARB; + spec[i++] = 1; + spec[i++] = GLX_SAMPLES_ARB; + spec[i++] = format.samples() == -1 ? 4 : format.samples(); + } - spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 0 : format.accumBufferSize(); - spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 0 : format.accumBufferSize(); - spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 0 : format.accumBufferSize(); - spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = (format.accumBufferSize() == -1) ? 0 : format.accumBufferSize(); spec[i++] = XNone; return spec; } -GLXFBConfig QGLXGLContext::findConfig(const GLXFBConfig *configs, int configCount, const QPlatformWindowFormat &format, const MyDisplay *xd) +GLXFBConfig QGLXGLContext::findConfig(const MyDisplay *xd, const QPlatformWindowFormat &format) { - if (!configs) - return 0; - + QVector spec = buildSpec(format); + int confcount = 0; + GLXFBConfig *configs; GLXFBConfig chosenConfig = 0; - for (int i = 0; i < configCount; ++i) { - chosenConfig = configs[i]; + configs = glXChooseFBConfig(xd->display,xd->screen,spec.constData(),&confcount); + if (confcount) + { + for (int i = 0; i < confcount; i++) { + chosenConfig = configs[i]; + + // Make sure we try to get an ARGB visual if the format asked for an alpha: + if (format.alpha()) { + int alphaSize; + glXGetFBConfigAttrib(xd->display,configs[i],GLX_ALPHA_SIZE,&alphaSize); + if (alphaSize > 0) + break; + } else { + break; // Just choose the first in the list if there's no alpha requested + } + } - // Make sure we try to get an ARGB visual if the format asked for an alpha: - if (format.alpha()) { - XVisualInfo* vi; - vi = glXGetVisualFromFBConfig(xd->display, configs[i]); - if (!vi) - continue; + XFree(configs); + } - XRenderPictFormat *pictFormat = XRenderFindVisualFormat(xd->display, vi->visual); - XFree(vi); + if (!chosenConfig) + qFatal("Warning no context created"); - if (pictFormat && (pictFormat->type == PictTypeDirect) && pictFormat->direct.alphaMask) { - // The pict format for the visual matching the FBConfig indicates ARGB - break; - } - } else - break; // Just choose the first in the list if there's no alpha requested - } return chosenConfig; } -QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config) +XVisualInfo *QGLXGLContext::findVisualInfo(const MyDisplay *xd, const QPlatformWindowFormat &format) +{ + GLXFBConfig config = QGLXGLContext::findConfig(xd,format); + XVisualInfo *visualInfo = glXGetVisualFromFBConfig(xd->display,config); + return visualInfo; +} + +QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext ctx) { QPlatformWindowFormat format; int redSize = 0; @@ -134,6 +159,7 @@ QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *disp int alphaSize = 0; int depthSize = 0; int stencilSize = 0; + int sampleBuffers = 0; int sampleCount = 0; int level = 0; int rgba = 0; @@ -143,15 +169,17 @@ QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *disp int accumSizeG = 0; int accumSizeB = 0; + XVisualInfo *vi = glXGetVisualFromFBConfig(display,config); + glXGetConfig(display,vi,GLX_RGBA,&rgba); + 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, &sampleCount); + glXGetFBConfigAttrib(display, config, GLX_SAMPLES, &sampleBuffers); glXGetFBConfigAttrib(display, config, GLX_LEVEL, &level); - glXGetFBConfigAttrib(display, config, GLX_RGBA, &rgba); glXGetFBConfigAttrib(display, config, GLX_STEREO, &stereo); glXGetFBConfigAttrib(display, config, GLX_ACCUM_ALPHA_SIZE, &accumSizeA); glXGetFBConfigAttrib(display, config, GLX_ACCUM_RED_SIZE, &accumSizeR); @@ -164,11 +192,16 @@ QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *disp format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); - format.setSamples(sampleCount); - format.setDirectRendering(true); // We don't support anything else for now. + format.setSampleBuffers(sampleBuffers); + if (format.sampleBuffers()) { + glXGetFBConfigAttrib(display, config, GLX_SAMPLES_ARB, &sampleCount); + format.setSamples(sampleCount); + } + + format.setDirectRendering(glXIsDirect(display, ctx)); format.setRgba(rgba); format.setStereo(stereo); - format.setAccumBufferSize(accumSizeA + accumSizeB + accumSizeG + accumSizeR); + format.setAccumBufferSize(accumSizeB); return format; } @@ -199,19 +232,9 @@ QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindow if (sharePlatformContext) shareGlxContext = static_cast(sharePlatformContext)->glxContext(); - QVector spec = buildSpec(format); - int confcount = 0; - GLXFBConfig *configs; - configs = glXChooseFBConfig(xd->display,xd->screen,spec.constData(),&confcount); - if (confcount) - { - GLXFBConfig config = findConfig(configs,confcount,format,xd); - m_context = glXCreateNewContext(xd->display,config,GLX_RGBA_TYPE,shareGlxContext,TRUE); - m_windowFormat = QGLXGLContext::platformWindowFromGLXFBConfig(xd->display,config); - XFree(configs); - } else { - qFatal("Warning no context created"); - } + GLXFBConfig config = findConfig(xd,format); + m_context = glXCreateNewContext(xd->display,config,GLX_RGBA_TYPE,shareGlxContext,TRUE); + m_windowFormat = QGLXGLContext::platformWindowFromGLXFBConfig(xd->display,config,m_context); #ifdef MYX11_DEBUG qDebug() << "QGLXGLContext::create context" << m_context; @@ -243,16 +266,10 @@ void QGLXGLContext::createDefaultSharedContex(MyDisplay *xd) x, y, w, h, 0 /*border_width*/, xd->blackPixel(), xd->whitePixel()); GLXContext context; - QPlatformWindowFormat format; - QVector spec = buildSpec(format); - int confcount = 0; - GLXFBConfig *configs; - configs = glXChooseFBConfig(xd->display,xd->screen,spec.constData(),&confcount); - if (confcount) - { - GLXFBConfig config = findConfig(configs,confcount,format,xd); + QPlatformWindowFormat format = QPlatformWindowFormat::defaultFormat(); + GLXFBConfig config = findConfig(xd,format); + if (config) { context = glXCreateNewContext(xd->display,config,GLX_RGBA_TYPE,0,TRUE); - XFree(configs); QPlatformGLContext *sharedContext = new QGLXGLContext(xd,sharedWindow,context); QPlatformGLContext::setDefaultSharedContext(sharedContext); } else { diff --git a/src/plugins/platforms/testlite/qglxintegration.h b/src/plugins/platforms/testlite/qglxintegration.h index 5a98e25..2f7c70e 100644 --- a/src/plugins/platforms/testlite/qglxintegration.h +++ b/src/plugins/platforms/testlite/qglxintegration.h @@ -69,10 +69,13 @@ public: GLXContext glxContext() {return m_context;} QPlatformWindowFormat platformWindowFormat() const; + + static XVisualInfo *findVisualInfo(const MyDisplay *xd, const QPlatformWindowFormat &format); private: + static GLXFBConfig findConfig(const MyDisplay *xd,const QPlatformWindowFormat &format); static QVector buildSpec(const QPlatformWindowFormat &format); - static GLXFBConfig findConfig(const GLXFBConfig *configs,int configCount, const QPlatformWindowFormat &format, const MyDisplay *xd); - static QPlatformWindowFormat platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config); + static QPlatformWindowFormat platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context); + MyDisplay *m_xd; Drawable m_drawable; diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp index fd02bc4..39b2cc0 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.cpp +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -56,7 +56,6 @@ #include #include -#include #include "qglxintegration.h" #include @@ -158,21 +157,21 @@ QTestLiteWindow::QTestLiteWindow(const QTestLiteIntegration *platformIntegration int w = window->width(); int h = window->height(); -// int n, i; -// if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL) { -// x_visualInfo = QGLXGLContext::findVisual(window->platformWindowFormat(),xd); - -// XSetWindowAttributes a; -// a.background_pixel = xd->whitePixel(); -// a.border_pixel = xd->blackPixel(); -// x_window = XCreateWindow(xd->display, xd->rootWindow(),x, y, w, h, -// 0, visualInfo()->depth, InputOutput, visualInfo()->visual, -// CWBackPixel|CWBorderPixel, &a); -// } else { + if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL) { + + XVisualInfo *visualInfo = QGLXGLContext::findVisualInfo(xd,window->platformWindowFormat()); + Colormap cmap = XCreateColormap(xd->display,xd->rootWindow(),visualInfo->visual,AllocNone); + + XSetWindowAttributes a; + a.colormap = cmap; + x_window = XCreateWindow(xd->display, xd->rootWindow(),x, y, w, h, + 0, visualInfo->depth, InputOutput, visualInfo->visual, + CWColormap, &a); + } else { x_window = XCreateSimpleWindow(xd->display, xd->rootWindow(), x, y, w, h, 0 /*border_width*/, xd->blackPixel(), xd->whitePixel()); -// } + } #ifdef MYX11_DEBUG qDebug() << "QTestLiteWindow::QTestLiteWindow creating" << hex << x_window << window; -- cgit v0.12