[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include <qglpixelbuffer.h>
|
---|
| 43 | #include <qgl.h>
|
---|
| 44 | #include <private/qgl_p.h>
|
---|
| 45 |
|
---|
| 46 | #include <private/qglpixelbuffer_p.h>
|
---|
| 47 |
|
---|
| 48 | #include <qimage.h>
|
---|
| 49 | #include <qdebug.h>
|
---|
| 50 |
|
---|
| 51 | QT_BEGIN_NAMESPACE
|
---|
| 52 |
|
---|
| 53 | /* WGL_WGLEXT_PROTOTYPES */
|
---|
| 54 | typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
|
---|
| 55 | typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
|
---|
| 56 | typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer);
|
---|
| 57 | typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC);
|
---|
| 58 | typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer);
|
---|
| 59 | typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
|
---|
| 60 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
|
---|
| 61 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
|
---|
| 62 | typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
---|
| 63 | typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
---|
| 64 | typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
---|
| 65 | typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int * piAttribList);
|
---|
| 66 |
|
---|
| 67 | #ifndef WGL_ARB_pbuffer
|
---|
| 68 | #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
|
---|
| 69 | #define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
|
---|
| 70 | #define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
|
---|
| 71 | #define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
|
---|
| 72 | #define WGL_PBUFFER_LARGEST_ARB 0x2033
|
---|
| 73 | #define WGL_PBUFFER_WIDTH_ARB 0x2034
|
---|
| 74 | #define WGL_PBUFFER_HEIGHT_ARB 0x2035
|
---|
| 75 | #define WGL_PBUFFER_LOST_ARB 0x2036
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
| 78 | #ifndef WGL_ARB_pixel_format
|
---|
| 79 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
|
---|
| 80 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001
|
---|
| 81 | #define WGL_DRAW_TO_BITMAP_ARB 0x2002
|
---|
| 82 | #define WGL_ACCELERATION_ARB 0x2003
|
---|
| 83 | #define WGL_NEED_PALETTE_ARB 0x2004
|
---|
| 84 | #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
|
---|
| 85 | #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
|
---|
| 86 | #define WGL_SWAP_METHOD_ARB 0x2007
|
---|
| 87 | #define WGL_NUMBER_OVERLAYS_ARB 0x2008
|
---|
| 88 | #define WGL_NUMBER_UNDERLAYS_ARB 0x2009
|
---|
| 89 | #define WGL_TRANSPARENT_ARB 0x200A
|
---|
| 90 | #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
|
---|
| 91 | #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
|
---|
| 92 | #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
|
---|
| 93 | #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
|
---|
| 94 | #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
|
---|
| 95 | #define WGL_SHARE_DEPTH_ARB 0x200C
|
---|
| 96 | #define WGL_SHARE_STENCIL_ARB 0x200D
|
---|
| 97 | #define WGL_SHARE_ACCUM_ARB 0x200E
|
---|
| 98 | #define WGL_SUPPORT_GDI_ARB 0x200F
|
---|
| 99 | #define WGL_SUPPORT_OPENGL_ARB 0x2010
|
---|
| 100 | #define WGL_DOUBLE_BUFFER_ARB 0x2011
|
---|
| 101 | #define WGL_STEREO_ARB 0x2012
|
---|
| 102 | #define WGL_PIXEL_TYPE_ARB 0x2013
|
---|
| 103 | #define WGL_COLOR_BITS_ARB 0x2014
|
---|
| 104 | #define WGL_RED_BITS_ARB 0x2015
|
---|
| 105 | #define WGL_RED_SHIFT_ARB 0x2016
|
---|
| 106 | #define WGL_GREEN_BITS_ARB 0x2017
|
---|
| 107 | #define WGL_GREEN_SHIFT_ARB 0x2018
|
---|
| 108 | #define WGL_BLUE_BITS_ARB 0x2019
|
---|
| 109 | #define WGL_BLUE_SHIFT_ARB 0x201A
|
---|
| 110 | #define WGL_ALPHA_BITS_ARB 0x201B
|
---|
| 111 | #define WGL_ALPHA_SHIFT_ARB 0x201C
|
---|
| 112 | #define WGL_ACCUM_BITS_ARB 0x201D
|
---|
| 113 | #define WGL_ACCUM_RED_BITS_ARB 0x201E
|
---|
| 114 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
|
---|
| 115 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
|
---|
| 116 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
|
---|
| 117 | #define WGL_DEPTH_BITS_ARB 0x2022
|
---|
| 118 | #define WGL_STENCIL_BITS_ARB 0x2023
|
---|
| 119 | #define WGL_AUX_BUFFERS_ARB 0x2024
|
---|
| 120 | #define WGL_NO_ACCELERATION_ARB 0x2025
|
---|
| 121 | #define WGL_GENERIC_ACCELERATION_ARB 0x2026
|
---|
| 122 | #define WGL_FULL_ACCELERATION_ARB 0x2027
|
---|
| 123 | #define WGL_SWAP_EXCHANGE_ARB 0x2028
|
---|
| 124 | #define WGL_SWAP_COPY_ARB 0x2029
|
---|
| 125 | #define WGL_SWAP_UNDEFINED_ARB 0x202A
|
---|
| 126 | #define WGL_TYPE_RGBA_ARB 0x202B
|
---|
| 127 | #define WGL_TYPE_COLORINDEX_ARB 0x202C
|
---|
| 128 | #endif
|
---|
| 129 |
|
---|
| 130 | #ifndef WGL_ARB_render_texture
|
---|
| 131 | #define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070
|
---|
| 132 | #define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071
|
---|
| 133 | #define WGL_TEXTURE_FORMAT_ARB 0x2072
|
---|
| 134 | #define WGL_TEXTURE_TARGET_ARB 0x2073
|
---|
| 135 | #define WGL_MIPMAP_TEXTURE_ARB 0x2074
|
---|
| 136 | #define WGL_TEXTURE_RGB_ARB 0x2075
|
---|
| 137 | #define WGL_TEXTURE_RGBA_ARB 0x2076
|
---|
| 138 | #define WGL_NO_TEXTURE_ARB 0x2077
|
---|
| 139 | #define WGL_TEXTURE_CUBE_MAP_ARB 0x2078
|
---|
| 140 | #define WGL_TEXTURE_1D_ARB 0x2079
|
---|
| 141 | #define WGL_TEXTURE_2D_ARB 0x207A
|
---|
| 142 | #define WGL_MIPMAP_LEVEL_ARB 0x207B
|
---|
| 143 | #define WGL_CUBE_MAP_FACE_ARB 0x207C
|
---|
| 144 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
|
---|
| 145 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
|
---|
| 146 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
|
---|
| 147 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
|
---|
| 148 | #define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
|
---|
| 149 | #define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
|
---|
| 150 | #define WGL_FRONT_LEFT_ARB 0x2083
|
---|
| 151 | #define WGL_FRONT_RIGHT_ARB 0x2084
|
---|
| 152 | #define WGL_BACK_LEFT_ARB 0x2085
|
---|
| 153 | #define WGL_BACK_RIGHT_ARB 0x2086
|
---|
| 154 | #define WGL_AUX0_ARB 0x2087
|
---|
| 155 | #define WGL_AUX1_ARB 0x2088
|
---|
| 156 | #define WGL_AUX2_ARB 0x2089
|
---|
| 157 | #define WGL_AUX3_ARB 0x208A
|
---|
| 158 | #define WGL_AUX4_ARB 0x208B
|
---|
| 159 | #define WGL_AUX5_ARB 0x208C
|
---|
| 160 | #define WGL_AUX6_ARB 0x208D
|
---|
| 161 | #define WGL_AUX7_ARB 0x208E
|
---|
| 162 | #define WGL_AUX8_ARB 0x208F
|
---|
| 163 | #define WGL_AUX9_ARB 0x2090
|
---|
| 164 | #endif
|
---|
| 165 |
|
---|
| 166 | #ifndef WGL_FLOAT_COMPONENTS_NV
|
---|
| 167 | #define WGL_FLOAT_COMPONENTS_NV 0x20B0
|
---|
| 168 | #endif
|
---|
| 169 |
|
---|
[846] | 170 | #ifndef WGL_ARB_multisample
|
---|
| 171 | #define WGL_SAMPLE_BUFFERS_ARB 0x2041
|
---|
| 172 | #define WGL_SAMPLES_ARB 0x2042
|
---|
| 173 | #endif
|
---|
| 174 |
|
---|
| 175 | #ifndef GL_SAMPLES_ARB
|
---|
| 176 | #define GL_SAMPLES_ARB 0x80A9
|
---|
| 177 | #endif
|
---|
| 178 |
|
---|
[2] | 179 | QGLFormat pfiToQGLFormat(HDC hdc, int pfi);
|
---|
| 180 |
|
---|
| 181 | static void qt_format_to_attrib_list(bool has_render_texture, const QGLFormat &f, int attribs[])
|
---|
| 182 | {
|
---|
| 183 | int i = 0;
|
---|
| 184 | attribs[i++] = WGL_SUPPORT_OPENGL_ARB;
|
---|
| 185 | attribs[i++] = TRUE;
|
---|
| 186 | attribs[i++] = WGL_DRAW_TO_PBUFFER_ARB;
|
---|
| 187 | attribs[i++] = TRUE;
|
---|
| 188 |
|
---|
| 189 | if (has_render_texture) {
|
---|
| 190 | attribs[i++] = WGL_BIND_TO_TEXTURE_RGBA_ARB;
|
---|
| 191 | attribs[i++] = TRUE;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | attribs[i++] = WGL_COLOR_BITS_ARB;
|
---|
| 195 | attribs[i++] = 32;
|
---|
| 196 | attribs[i++] = WGL_DOUBLE_BUFFER_ARB;
|
---|
| 197 | attribs[i++] = FALSE;
|
---|
| 198 |
|
---|
| 199 | if (f.stereo()) {
|
---|
| 200 | attribs[i++] = WGL_STEREO_ARB;
|
---|
| 201 | attribs[i++] = TRUE;
|
---|
| 202 | }
|
---|
| 203 | if (f.depth()) {
|
---|
| 204 | attribs[i++] = WGL_DEPTH_BITS_ARB;
|
---|
| 205 | attribs[i++] = f.depthBufferSize() == -1 ? 24 : f.depthBufferSize();
|
---|
| 206 | }
|
---|
| 207 | if (f.redBufferSize() != -1) {
|
---|
| 208 | attribs[i++] = WGL_RED_BITS_ARB;
|
---|
| 209 | attribs[i++] = f.redBufferSize();
|
---|
| 210 | }
|
---|
| 211 | if (f.greenBufferSize() != -1) {
|
---|
| 212 | attribs[i++] = WGL_GREEN_BITS_ARB;
|
---|
| 213 | attribs[i++] = f.greenBufferSize();
|
---|
| 214 | }
|
---|
| 215 | if (f.blueBufferSize() != -1) {
|
---|
| 216 | attribs[i++] = WGL_BLUE_BITS_ARB;
|
---|
| 217 | attribs[i++] = f.blueBufferSize();
|
---|
| 218 | }
|
---|
| 219 | if (f.alpha()) {
|
---|
| 220 | attribs[i++] = WGL_ALPHA_BITS_ARB;
|
---|
| 221 | attribs[i++] = f.alphaBufferSize() == -1 ? 8 : f.alphaBufferSize();
|
---|
| 222 | }
|
---|
| 223 | if (f.accum()) {
|
---|
| 224 | attribs[i++] = WGL_ACCUM_BITS_ARB;
|
---|
| 225 | attribs[i++] = f.accumBufferSize() == -1 ? 16 : f.accumBufferSize();
|
---|
| 226 | }
|
---|
| 227 | if (f.stencil()) {
|
---|
| 228 | attribs[i++] = WGL_STENCIL_BITS_ARB;
|
---|
| 229 | attribs[i++] = f.stencilBufferSize() == -1 ? 8 : f.stencilBufferSize();
|
---|
| 230 | }
|
---|
| 231 | if ((f.redBufferSize() > 8 || f.greenBufferSize() > 8
|
---|
| 232 | || f.blueBufferSize() > 8 || f.alphaBufferSize() > 8)
|
---|
[651] | 233 | && (QGLExtensions::glExtensions() & QGLExtensions::NVFloatBuffer))
|
---|
[2] | 234 | {
|
---|
| 235 | attribs[i++] = WGL_FLOAT_COMPONENTS_NV;
|
---|
| 236 | attribs[i++] = TRUE;
|
---|
| 237 | }
|
---|
[846] | 238 | if (f.sampleBuffers()) {
|
---|
| 239 | attribs[i++] = WGL_SAMPLE_BUFFERS_ARB;
|
---|
| 240 | attribs[i++] = 1;
|
---|
| 241 | attribs[i++] = WGL_SAMPLES_ARB;
|
---|
| 242 | attribs[i++] = f.samples() == -1 ? 16 : f.samples();
|
---|
| 243 | }
|
---|
[2] | 244 | attribs[i] = 0;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidget *shareWidget)
|
---|
| 248 | {
|
---|
[846] | 249 | QGLTemporaryContext tempContext;
|
---|
[2] | 250 |
|
---|
| 251 | PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB =
|
---|
| 252 | (PFNWGLCREATEPBUFFERARBPROC) wglGetProcAddress("wglCreatePbufferARB");
|
---|
| 253 | PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB =
|
---|
| 254 | (PFNWGLGETPBUFFERDCARBPROC) wglGetProcAddress("wglGetPbufferDCARB");
|
---|
| 255 | PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB =
|
---|
| 256 | (PFNWGLQUERYPBUFFERARBPROC) wglGetProcAddress("wglQueryPbufferARB");
|
---|
| 257 | PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB =
|
---|
| 258 | (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
|
---|
| 259 |
|
---|
| 260 | if (!wglCreatePbufferARB) // assumes that if one can be resolved, all of them can
|
---|
| 261 | return false;
|
---|
| 262 |
|
---|
[846] | 263 | dc = wglGetCurrentDC();
|
---|
[2] | 264 | Q_ASSERT(dc);
|
---|
[846] | 265 | has_render_texture = false;
|
---|
[2] | 266 |
|
---|
[846] | 267 | // sample buffers doesn't work in conjunction with the render_texture extension
|
---|
| 268 | if (!f.sampleBuffers()) {
|
---|
| 269 | PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB =
|
---|
| 270 | (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
|
---|
[2] | 271 |
|
---|
[846] | 272 | if (wglGetExtensionsStringARB) {
|
---|
| 273 | QString extensions(QLatin1String(wglGetExtensionsStringARB(dc)));
|
---|
| 274 | has_render_texture = extensions.contains(QLatin1String("WGL_ARB_render_texture"));
|
---|
| 275 | }
|
---|
[2] | 276 | }
|
---|
| 277 |
|
---|
| 278 | int attribs[40];
|
---|
| 279 | qt_format_to_attrib_list(has_render_texture, f, attribs);
|
---|
| 280 |
|
---|
| 281 | // Find pbuffer capable pixel format.
|
---|
| 282 | unsigned int num_formats = 0;
|
---|
| 283 | int pixel_format;
|
---|
| 284 | wglChoosePixelFormatARB(dc, attribs, 0, 1, &pixel_format, &num_formats);
|
---|
| 285 |
|
---|
| 286 | // some GL implementations don't support pbuffers with accum
|
---|
| 287 | // buffers, so try that before we give up
|
---|
| 288 | if (num_formats == 0 && f.accum()) {
|
---|
| 289 | QGLFormat tmp = f;
|
---|
| 290 | tmp.setAccum(false);
|
---|
| 291 | qt_format_to_attrib_list(has_render_texture, tmp, attribs);
|
---|
| 292 | wglChoosePixelFormatARB(dc, attribs, 0, 1, &pixel_format, &num_formats);
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | if (num_formats == 0) {
|
---|
| 296 | qWarning("QGLPixelBuffer: Unable to find a pixel format with pbuffer - giving up.");
|
---|
| 297 | return false;
|
---|
| 298 | }
|
---|
| 299 | format = pfiToQGLFormat(dc, pixel_format);
|
---|
| 300 |
|
---|
| 301 | // NB! The below ONLY works if the width/height are powers of 2.
|
---|
| 302 | // Set some pBuffer attributes so that we can use this pBuffer as
|
---|
| 303 | // a 2D RGBA texture target.
|
---|
| 304 | int pb_attribs[] = {WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
|
---|
| 305 | WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, 0};
|
---|
| 306 |
|
---|
| 307 | pbuf = wglCreatePbufferARB(dc, pixel_format, size.width(), size.height(),
|
---|
| 308 | has_render_texture ? pb_attribs : 0);
|
---|
[846] | 309 | if (!pbuf) {
|
---|
[2] | 310 | // try again without the render_texture extension
|
---|
| 311 | pbuf = wglCreatePbufferARB(dc, pixel_format, size.width(), size.height(), 0);
|
---|
| 312 | has_render_texture = false;
|
---|
| 313 | if (!pbuf) {
|
---|
| 314 | qWarning("QGLPixelBuffer: Unable to create pbuffer [w=%d, h=%d] - giving up.", size.width(), size.height());
|
---|
| 315 | return false;
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | dc = wglGetPbufferDCARB(pbuf);
|
---|
| 320 | ctx = wglCreateContext(dc);
|
---|
| 321 | if (!dc || !ctx) {
|
---|
| 322 | qWarning("QGLPixelBuffer: Unable to create pbuffer context - giving up.");
|
---|
| 323 | return false;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[846] | 326 | // Explicitly disable the render_texture extension if we have a
|
---|
| 327 | // multi-sampled pbuffer context. This seems to be a problem only with
|
---|
| 328 | // ATI cards if multi-sampling is forced globally in the driver.
|
---|
| 329 | wglMakeCurrent(dc, ctx);
|
---|
| 330 | GLint samples = 0;
|
---|
| 331 | glGetIntegerv(GL_SAMPLES_ARB, &samples);
|
---|
| 332 | if (has_render_texture && samples != 0)
|
---|
| 333 | has_render_texture = false;
|
---|
| 334 |
|
---|
[2] | 335 | HGLRC share_ctx = shareWidget ? shareWidget->d_func()->glcx->d_func()->rc : 0;
|
---|
| 336 | if (share_ctx && !wglShareLists(share_ctx, ctx))
|
---|
| 337 | qWarning("QGLPixelBuffer: Unable to share display lists - with share widget.");
|
---|
| 338 |
|
---|
| 339 | int width, height;
|
---|
| 340 | wglQueryPbufferARB(pbuf, WGL_PBUFFER_WIDTH_ARB, &width);
|
---|
| 341 | wglQueryPbufferARB(pbuf, WGL_PBUFFER_HEIGHT_ARB, &height);
|
---|
| 342 | return true;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | bool QGLPixelBufferPrivate::cleanup()
|
---|
| 346 | {
|
---|
| 347 | PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB =
|
---|
| 348 | (PFNWGLRELEASEPBUFFERDCARBPROC) wglGetProcAddress("wglReleasePbufferDCARB");
|
---|
| 349 | PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB =
|
---|
| 350 | (PFNWGLDESTROYPBUFFERARBPROC) wglGetProcAddress("wglDestroyPbufferARB");
|
---|
| 351 | if (!invalid && wglReleasePbufferDCARB && wglDestroyPbufferARB) {
|
---|
| 352 | wglReleasePbufferDCARB(pbuf, dc);
|
---|
| 353 | wglDestroyPbufferARB(pbuf);
|
---|
| 354 | }
|
---|
| 355 | return true;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id)
|
---|
| 359 | {
|
---|
| 360 | Q_D(QGLPixelBuffer);
|
---|
| 361 | if (d->invalid || !d->has_render_texture)
|
---|
| 362 | return false;
|
---|
| 363 | PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB =
|
---|
| 364 | (PFNWGLBINDTEXIMAGEARBPROC) wglGetProcAddress("wglBindTexImageARB");
|
---|
| 365 | if (wglBindTexImageARB) {
|
---|
| 366 | glBindTexture(GL_TEXTURE_2D, texture_id);
|
---|
| 367 | return wglBindTexImageARB(d->pbuf, WGL_FRONT_LEFT_ARB);
|
---|
| 368 | }
|
---|
| 369 | return false;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | void QGLPixelBuffer::releaseFromDynamicTexture()
|
---|
| 373 | {
|
---|
| 374 | Q_D(QGLPixelBuffer);
|
---|
| 375 | if (d->invalid || !d->has_render_texture)
|
---|
| 376 | return;
|
---|
| 377 | PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB =
|
---|
| 378 | (PFNWGLRELEASETEXIMAGEARBPROC) wglGetProcAddress("wglReleaseTexImageARB");
|
---|
| 379 | if (wglReleaseTexImageARB)
|
---|
| 380 | wglReleaseTexImageARB(d->pbuf, WGL_FRONT_LEFT_ARB);
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | bool QGLPixelBuffer::hasOpenGLPbuffers()
|
---|
| 384 | {
|
---|
| 385 | bool ret = false;
|
---|
[651] | 386 | QGLTemporaryContext *tmpContext = 0;
|
---|
| 387 | if (!QGLContext::currentContext())
|
---|
| 388 | tmpContext = new QGLTemporaryContext;
|
---|
[2] | 389 | PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB =
|
---|
| 390 | (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
|
---|
| 391 | if (wglGetExtensionsStringARB) {
|
---|
| 392 | QString extensions(QLatin1String(wglGetExtensionsStringARB(wglGetCurrentDC())));
|
---|
| 393 | if (extensions.contains(QLatin1String("WGL_ARB_pbuffer"))
|
---|
| 394 | && extensions.contains(QLatin1String("WGL_ARB_pixel_format"))) {
|
---|
| 395 | ret = true;
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
[651] | 398 | if (tmpContext)
|
---|
| 399 | delete tmpContext;
|
---|
[2] | 400 | return ret;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | QT_END_NAMESPACE
|
---|