aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java
blob: abbc9a51144389afd28da59d965a781b8d5a9678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/*
 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * - Redistribution of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * You acknowledge that this software is not designed or intended for use
 * in the design, construction, operation or maintenance of any nuclear
 * facility.
 * 
 * Sun gratefully acknowledges that this software was originally authored
 * and developed by Kenneth Bradley Russell and Christopher John Kline.
 */

package com.sun.opengl.impl.windows;

import java.awt.Component;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;

import javax.media.opengl.*;
import com.sun.opengl.impl.*;

public abstract class WindowsGLDrawable extends GLDrawableImpl {
  protected static final boolean DEBUG = Debug.debug("WindowsGLDrawable");

  protected long hdc;
  protected Component component;
  protected GLCapabilities capabilities;
  protected GLCapabilitiesChooser chooser;
  protected boolean pixelFormatChosen;

  protected static final int MAX_PFORMATS = 256;
  protected static final int MAX_ATTRIBS  = 256;

  public WindowsGLDrawable(Component component,
                           GLCapabilities capabilities,
                           GLCapabilitiesChooser chooser) {
    this.component = component;
    this.capabilities = (GLCapabilities) capabilities.clone();
    this.chooser = chooser;
  }

  public void setRealized(boolean val) {
    throw new GLException("Should not call this (should only be called for onscreen GLDrawables)");
  }

  public void destroy() {
    throw new GLException("Should not call this (should only be called for offscreen GLDrawables)");
  }

  public void swapBuffers() throws GLException {
  }

  public long getHDC() {
    return hdc;
  }

  public void choosePixelFormat(boolean onscreen) {
    PIXELFORMATDESCRIPTOR pfd = null;
    int pixelFormat = 0;
    if (onscreen) {
      if (WGL.GetPixelFormat(hdc) != 0) {
        // The Java2D/OpenGL pipeline probably already set a pixel
        // format for this canvas.
        if (DEBUG) {
          System.err.println("NOTE: pixel format already chosen (by Java2D/OpenGL pipeline?) for window: " + 
                             WGL.GetPixelFormat(hdc));
        }
        pixelFormatChosen = true;
        return;
      }

      GLCapabilities[] availableCaps = null;
      int numFormats = 0;
      pfd = newPixelFormatDescriptor();
      GraphicsConfiguration config = component.getGraphicsConfiguration();
      GraphicsDevice device = config.getDevice();
      // Produce a recommended pixel format selection for the GLCapabilitiesChooser.
      // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available
      WindowsGLDrawable dummyDrawable = null;
      GLContextImpl     dummyContext  = null;
      WGLExt            dummyWGLExt   = null;
      if (capabilities.getSampleBuffers()) {
        dummyDrawable = new WindowsDummyGLDrawable();
        dummyContext  = (GLContextImpl) dummyDrawable.createContext(null);
        if (dummyContext != null) {
          dummyContext.makeCurrent();
          dummyWGLExt = (WGLExt) dummyContext.getPlatformGLExtensions();
        }
      }      
      int recommendedPixelFormat = -1;
      boolean haveWGLChoosePixelFormatARB = false;
      boolean haveWGLARBMultisample = false;
      boolean gotAvailableCaps = false;
      if (dummyWGLExt != null) {
        haveWGLChoosePixelFormatARB = dummyWGLExt.isExtensionAvailable("WGL_ARB_pixel_format");
        haveWGLARBMultisample       = dummyWGLExt.isExtensionAvailable("WGL_ARB_multisample");

        try {
          if (haveWGLChoosePixelFormatARB) {
            int[]   iattributes = new int  [2 * MAX_ATTRIBS];
            int[]   iresults    = new int  [2 * MAX_ATTRIBS];
            float[] fattributes = new float[2 * MAX_ATTRIBS];
            int niattribs = 0;
            int nfattribs = 0;
            iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
            iattributes[niattribs++] = GL.GL_TRUE;
            iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB;
            iattributes[niattribs++] = GL.GL_TRUE;
            iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
            iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB;
            iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
            if (capabilities.getDoubleBuffered()) {
              iattributes[niattribs++] = GL.GL_TRUE;
            } else {
              iattributes[niattribs++] = GL.GL_FALSE;
            }
            iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
            if (capabilities.getStereo()) {
              iattributes[niattribs++] = GL.GL_TRUE;
            } else {
              iattributes[niattribs++] = GL.GL_FALSE;
            }
            iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
            iattributes[niattribs++] = capabilities.getDepthBits();
            iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
            iattributes[niattribs++] = capabilities.getRedBits();
            iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
            iattributes[niattribs++] = capabilities.getGreenBits();
            iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
            iattributes[niattribs++] = capabilities.getBlueBits();
            iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
            iattributes[niattribs++] = capabilities.getAlphaBits();
            iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
            iattributes[niattribs++] = capabilities.getStencilBits();
            if (capabilities.getAccumRedBits()   > 0 ||
                capabilities.getAccumGreenBits() > 0 ||
                capabilities.getAccumBlueBits()  > 0 ||
                capabilities.getAccumAlphaBits()  > 0) {
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_BITS_ARB;
              iattributes[niattribs++] = (capabilities.getAccumRedBits() +
                                          capabilities.getAccumGreenBits() +
                                          capabilities.getAccumBlueBits() +
                                          capabilities.getAccumAlphaBits());
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
              iattributes[niattribs++] = capabilities.getAccumRedBits();
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
              iattributes[niattribs++] = capabilities.getAccumGreenBits();
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
              iattributes[niattribs++] = capabilities.getAccumBlueBits();
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
              iattributes[niattribs++] = capabilities.getAccumAlphaBits();
            }
            if (haveWGLARBMultisample) {
              if (capabilities.getSampleBuffers()) {
                iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
                iattributes[niattribs++] = GL.GL_TRUE;
                iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
                iattributes[niattribs++] = capabilities.getNumSamples();
              }
            }
          
            int[] pformats = new int[MAX_PFORMATS];
            int[] numFormatsTmp = new int[1];
            if (dummyWGLExt.wglChoosePixelFormatARB(hdc,
                                                    iattributes, 0,
                                                    fattributes, 0,
                                                    MAX_PFORMATS,
                                                    pformats, 0,
                                                    numFormatsTmp, 0)) {
              numFormats = numFormatsTmp[0];
              if (numFormats > 0) {
                // Remove one-basing of pixel format (added on later)
                recommendedPixelFormat = pformats[0] - 1;
                if (DEBUG) {
                  System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat);
                }
              }
            } else {
              if (DEBUG) {
                System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() );
                Thread.dumpStack();
              }
            }
            if (DEBUG) {
              if (recommendedPixelFormat < 0) {
                System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format");
                if (capabilities.getSampleBuffers()) {
                  System.err.print(" for multisampled GLCapabilities");
                }
                System.err.println();
              }
            }

            // Produce a list of GLCapabilities to give to the
            // GLCapabilitiesChooser.
            // Use wglGetPixelFormatAttribivARB instead of
            // DescribePixelFormat to get higher-precision information
            // about the pixel format (should make the GLCapabilities
            // more precise as well...i.e., remove the
            // "HardwareAccelerated" bit, which is basically
            // meaningless, and put in whether it can render to a
            // window, to a pbuffer, or to a pixmap)
            niattribs = 0;
            iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB;
            if (dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) {
              numFormats = iresults[0];
              // Should we be filtering out the pixel formats which aren't
              // applicable, as we are doing here?
              // We don't have enough information in the GLCapabilities to
              // represent those that aren't...
              iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB;
              iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
              iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
              iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
              iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
              iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
              iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
              if (haveWGLARBMultisample) {
                iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
                iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
              }

              availableCaps = new GLCapabilities[numFormats];
              for (int i = 0; i < numFormats; i++) {
                if (!dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) {
                  throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context");
                }
                availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true);
              }
              gotAvailableCaps = true;
            } else {
              int lastErr = WGL.GetLastError();
              // Intel Extreme graphics fails with a zero error code
              if (lastErr != 0) {
                throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError());
              }
            }
          }
        } finally {
          dummyContext.release();
          dummyContext.destroy();
          dummyDrawable.destroy();
        }
      }

      // Fallback path for older cards, in particular Intel Extreme motherboard graphics
      if (!gotAvailableCaps) {
        if (DEBUG) {
          if (!capabilities.getSampleBuffers()) {
            System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested");
          } else {
            System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB");
          }
        }
        pfd = glCapabilities2PFD(capabilities, onscreen);
        // Remove one-basing of pixel format (added on later)
        recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd) - 1;

        numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null);
        if (numFormats == 0) {
          throw new GLException("Unable to enumerate pixel formats of window for GLCapabilitiesChooser");
        }
        availableCaps = new GLCapabilities[numFormats];
        for (int i = 0; i < numFormats; i++) {
          if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) {
            throw new GLException("Error describing pixel format " + (1 + i) + " of device context");
          }
          availableCaps[i] = pfd2GLCapabilities(pfd);
        }
      }

      // Supply information to chooser
      pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat);
      if ((pixelFormat < 0) || (pixelFormat >= numFormats)) {
        throw new GLException("Invalid result " + pixelFormat +
                              " from GLCapabilitiesChooser (should be between 0 and " +
                              (numFormats - 1) + ")");
      }
      if (DEBUG) {
        System.err.println(getThreadName() + ": Chosen pixel format (" + pixelFormat + "):");
        System.err.println(availableCaps[pixelFormat]);
      }
      pixelFormat += 1; // one-base the index
      if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) {
        throw new GLException("Error re-describing the chosen pixel format: " + WGL.GetLastError());
      }
    } else {
      // For now, use ChoosePixelFormat for offscreen surfaces until
      // we figure out how to properly choose an offscreen-
      // compatible pixel format
      pfd = glCapabilities2PFD(capabilities, onscreen);
      pixelFormat = WGL.ChoosePixelFormat(hdc, pfd);
    }
    if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) {
      int lastError = WGL.GetLastError();
      if (DEBUG) {
        System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() +
                           ", current DC = " + WGL.wglGetCurrentDC());
        System.err.println(getThreadName() + ": GetPixelFormat(hdc " + toHexString(hdc) + ") returns " + WGL.GetPixelFormat(hdc));
      }
      throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError);
    }
    pixelFormatChosen = true;
  }

  static PIXELFORMATDESCRIPTOR glCapabilities2PFD(GLCapabilities caps, boolean onscreen) {
    int colorDepth = (caps.getRedBits() +
                      caps.getGreenBits() +
                      caps.getBlueBits());
    if (colorDepth < 15) {
      throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported");
    }
    PIXELFORMATDESCRIPTOR pfd = newPixelFormatDescriptor();
    int pfdFlags = (WGL.PFD_SUPPORT_OPENGL |
                    WGL.PFD_GENERIC_ACCELERATED);
    if (caps.getDoubleBuffered()) {
      pfdFlags |= WGL.PFD_DOUBLEBUFFER;
    }
    if (onscreen) {
      pfdFlags |= WGL.PFD_DRAW_TO_WINDOW;
    } else {
      pfdFlags |= WGL.PFD_DRAW_TO_BITMAP;
    }
    pfd.dwFlags(pfdFlags);
    pfd.iPixelType((byte) WGL.PFD_TYPE_RGBA);
    pfd.cColorBits((byte) colorDepth);
    pfd.cRedBits  ((byte) caps.getRedBits());
    pfd.cGreenBits((byte) caps.getGreenBits());
    pfd.cBlueBits ((byte) caps.getBlueBits());
    pfd.cAlphaBits((byte) caps.getAlphaBits());
    int accumDepth = (caps.getAccumRedBits() +
                      caps.getAccumGreenBits() +
                      caps.getAccumBlueBits());
    pfd.cAccumBits     ((byte) accumDepth);
    pfd.cAccumRedBits  ((byte) caps.getAccumRedBits());
    pfd.cAccumGreenBits((byte) caps.getAccumGreenBits());
    pfd.cAccumBlueBits ((byte) caps.getAccumBlueBits());
    pfd.cAccumAlphaBits((byte) caps.getAccumAlphaBits());
    pfd.cDepthBits((byte) caps.getDepthBits());
    pfd.cStencilBits((byte) caps.getStencilBits());
    pfd.iLayerType((byte) WGL.PFD_MAIN_PLANE);
    return pfd;
  }

  static PIXELFORMATDESCRIPTOR newPixelFormatDescriptor() {
    PIXELFORMATDESCRIPTOR pfd = PIXELFORMATDESCRIPTOR.create();
    pfd.nSize((short) pfd.size());
    pfd.nVersion((short) 1);
    return pfd;
  }

  static GLCapabilities pfd2GLCapabilities(PIXELFORMATDESCRIPTOR pfd) {
    if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) {
      return null;
    }
    GLCapabilities res = new GLCapabilities();
    res.setRedBits       (pfd.cRedBits());
    res.setGreenBits     (pfd.cGreenBits());
    res.setBlueBits      (pfd.cBlueBits());
    res.setAlphaBits     (pfd.cAlphaBits());
    res.setAccumRedBits  (pfd.cAccumRedBits());
    res.setAccumGreenBits(pfd.cAccumGreenBits());
    res.setAccumBlueBits (pfd.cAccumBlueBits());
    res.setAccumAlphaBits(pfd.cAccumAlphaBits());
    res.setDepthBits     (pfd.cDepthBits());
    res.setStencilBits   (pfd.cStencilBits());
    res.setDoubleBuffered((pfd.dwFlags() & WGL.PFD_DOUBLEBUFFER) != 0);
    res.setStereo        ((pfd.dwFlags() & WGL.PFD_STEREO) != 0);
    res.setHardwareAccelerated(((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) ||
			       ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0));
    return res;
  }

  static GLCapabilities iattributes2GLCapabilities(int[] iattribs,
                                                   int[] iresults,
                                                   int   niattribs,
                                                   boolean requireRenderToWindow) {
    GLCapabilities res = new GLCapabilities();
    for (int i = 0; i < niattribs; i++) {
      switch (iattribs[i]) {
        case WGLExt.WGL_DRAW_TO_WINDOW_ARB:
          if (iresults[i] != GL.GL_TRUE)
            return null;
          break;

        case WGLExt.WGL_ACCELERATION_ARB:
          res.setHardwareAccelerated(iresults[i] == WGLExt.WGL_FULL_ACCELERATION_ARB);
          break;

        case WGLExt.WGL_SUPPORT_OPENGL_ARB:
          if (iresults[i] != GL.GL_TRUE)
            return null;
          break;

        case WGLExt.WGL_DEPTH_BITS_ARB:
          res.setDepthBits(iresults[i]);
          break;

        case WGLExt.WGL_STENCIL_BITS_ARB:
          res.setStencilBits(iresults[i]);
          break;

        case WGLExt.WGL_DOUBLE_BUFFER_ARB:
          res.setDoubleBuffered(iresults[i] == GL.GL_TRUE);
          break;

        case WGLExt.WGL_STEREO_ARB:
          res.setStereo(iresults[i] == GL.GL_TRUE);
          break;

        case WGLExt.WGL_PIXEL_TYPE_ARB:
          if (iresults[i] != WGLExt.WGL_TYPE_RGBA_ARB)
            return null;
          break;

        case WGLExt.WGL_RED_BITS_ARB:
          res.setRedBits(iresults[i]);
          break;
          
        case WGLExt.WGL_GREEN_BITS_ARB:
          res.setGreenBits(iresults[i]);
          break;

        case WGLExt.WGL_BLUE_BITS_ARB:
          res.setBlueBits(iresults[i]);
          break;

        case WGLExt.WGL_ALPHA_BITS_ARB:
          res.setAlphaBits(iresults[i]);
          break;

        case WGLExt.WGL_ACCUM_RED_BITS_ARB:
          res.setAccumRedBits(iresults[i]);
          break;

        case WGLExt.WGL_ACCUM_GREEN_BITS_ARB:
          res.setAccumGreenBits(iresults[i]);
          break;

        case WGLExt.WGL_ACCUM_BLUE_BITS_ARB:
          res.setAccumBlueBits(iresults[i]);
          break;

        case WGLExt.WGL_ACCUM_ALPHA_BITS_ARB:
          res.setAccumAlphaBits(iresults[i]);
          break;

        case WGLExt.WGL_SAMPLE_BUFFERS_ARB:
          res.setSampleBuffers(iresults[i] == GL.GL_TRUE);
          break;

        case WGLExt.WGL_SAMPLES_ARB:
          res.setNumSamples(iresults[i]);
          break;

        default:
          throw new GLException("Unknown pixel format attribute " + iattribs[i]);
      }
    }
    return res;
  }

  protected static String getThreadName() {
    return Thread.currentThread().getName();
  }
}