2
** License Applicability. Except to the extent portions of this file are
3
** made subject to an alternative license as permitted in the SGI Free
4
** Software License B, Version 1.1 (the "License"), the contents of this
5
** file are subject only to the provisions of the License. You may not use
6
** this file except in compliance with the License. You may obtain a copy
7
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10
** http://oss.sgi.com/projects/FreeB
12
** Note that, as provided in the License, the Software is distributed on an
13
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18
** Original Code. The Original Code is: OpenGL Sample Implementation,
19
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21
** Copyright in any portions created by third parties is as indicated
22
** elsewhere herein. All Rights Reserved.
24
** Additional Notice Provisions: The application programming interfaces
25
** established by SGI in conjunction with the Original Code are The
26
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29
** Window System(R) (Version 1.3), released October 19, 1998. This software
30
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31
** published by SGI, but has not been independently verified as being
32
** compliant with the OpenGL(R) version 1.2.1 Specification.
36
#ifdef HAVE_DMX_CONFIG_H
37
#include <dmx-config.h>
42
#include <GL/glxproto.h>
43
#include <X11/extensions/Xext.h>
44
#include <X11/extensions/extutil.h>
46
#include "dmx_glxvisuals.h"
48
__GLXvisualConfig *GetGLXVisualConfigs(Display *dpy, int screen, int *nconfigs)
50
xGLXGetVisualConfigsReq *req;
51
xGLXGetVisualConfigsReply reply;
52
__GLXvisualConfig *config, *configs;
53
GLint i, j, nvisuals, nprops;
55
int majorOpcode, dummy;
58
if (!XQueryExtension(dpy, "GLX", &majorOpcode, &dummy, &dummy)) {
62
/* Send the glXGetVisualConfigs request */
64
GetReq(GLXGetVisualConfigs,req);
65
req->reqType = majorOpcode;
66
req->glxCode = X_GLXGetVisualConfigs;
68
if (!_XReply(dpy, (xReply*) &reply, 0, False)) {
69
/* Something is busted. Punt. */
75
nvisuals = (int)reply.numVisuals;
77
/* This screen does not support GL rendering */
83
/* Check number of properties per visual */
84
nprops = (int)reply.numProps;
85
if (nprops < __GLX_MIN_CONFIG_PROPS) {
86
/* Huh? Not in protocol defined limits. Punt */
91
props = (INT32*) Xmalloc(nprops * __GLX_SIZE_CARD32);
98
/* Allocate memory for our config structure */
99
config = (__GLXvisualConfig*)
100
Xmalloc(nvisuals * sizeof(__GLXvisualConfig));
107
memset(config, 0, nvisuals * sizeof(__GLXvisualConfig));
109
num_good_visuals = 0;
111
/* Convert config structure into our format */
112
for (i=0; i<nvisuals; i++) {
114
/* Read config structure */
115
_XRead(dpy, (char *)props, (nprops * __GLX_SIZE_CARD32));
117
/* fill in default values */
118
config->visualRating = GLX_NONE_EXT;
119
config->transparentPixel = GLX_NONE_EXT;
121
/* Copy in the first set of properties */
122
config->vid = props[0];
123
config->class = props[1];
125
config->rgba = (Bool) props[2];
127
config->redSize = props[3];
128
config->greenSize = props[4];
129
config->blueSize = props[5];
130
config->alphaSize = props[6];
132
config->accumRedSize = props[7];
133
config->accumGreenSize = props[8];
134
config->accumBlueSize = props[9];
135
config->accumAlphaSize = props[10];
137
config->doubleBuffer = (Bool) props[11];
138
config->stereo = (Bool) props[12];
140
config->bufferSize = props[13];
141
config->depthSize = props[14];
142
config->stencilSize = props[15];
144
config->auxBuffers = props[16];
145
config->level = props[17];
147
/* Process remaining properties */
149
for (j=__GLX_MIN_CONFIG_PROPS; j<nprops; j+=2) {
154
case GLX_SAMPLES_SGIS:
155
config->multiSampleSize = value;
157
case GLX_SAMPLE_BUFFERS_SGIS:
158
config->nMultiSampleBuffers = value;
161
case GLX_TRANSPARENT_TYPE_EXT:
162
config->transparentPixel = value;
164
case GLX_TRANSPARENT_INDEX_VALUE_EXT:
165
config->transparentIndex = value;
167
case GLX_TRANSPARENT_RED_VALUE_EXT:
168
config->transparentRed = value;
170
case GLX_TRANSPARENT_GREEN_VALUE_EXT:
171
config->transparentGreen = value;
173
case GLX_TRANSPARENT_BLUE_VALUE_EXT:
174
config->transparentBlue = value;
176
case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
177
config->transparentAlpha = value;
180
case GLX_VISUAL_CAVEAT_EXT:
181
config->visualRating = value;
184
/* visualSelectGroup is an internal used property */
185
case GLX_VISUAL_SELECT_GROUP_SGIX:
186
config->visualSelectGroup = value;
190
/* Ignore properties we don't recognize */
196
// filter out overlay visuals (dmx does not support overlays)
198
if (config->level == 0) {
207
nvisuals = num_good_visuals;
210
for (i=0; i<nvisuals; i++) {
211
/* XXX hack to fill-in mask info (need a better way to do this) */
213
XVisualInfo *vis, template;
216
template.screen = screen;
217
template.visualid = config->vid;
218
vis = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask,
222
config->redMask = vis->red_mask;
223
config->greenMask = vis->green_mask;
224
config->blueMask = vis->blue_mask;
225
config->alphaMask = 0; /* XXX */
235
*nconfigs = nvisuals;
240
__GLXFBConfig *GetGLXFBConfigs(Display *dpy, int glxMajorOpcode, int *nconfigs)
242
xGLXGetFBConfigsReq *req;
243
xGLXGetFBConfigsReply reply;
244
__GLXFBConfig *config, *fbconfigs;
245
GLint i, j, numFBConfigs, numAttribs;
247
int screen = DefaultScreen( dpy );
248
int numValidConfigs = 0;
250
/* Send the glXGetFBConfigs request */
252
GetReq(GLXGetFBConfigs, req);
253
req->reqType = glxMajorOpcode;
254
req->glxCode = X_GLXGetFBConfigs;
255
req->screen = screen;
259
if (!_XReply(dpy, (xReply*) &reply, 0, False)) {
260
/* Something is busted. Punt. */
266
numFBConfigs = (int)reply.numFBConfigs;
268
/* This screen does not support GL rendering */
274
numAttribs = (int)reply.numAttribs;
281
attrs = (INT32*) Xmalloc(2*numAttribs * __GLX_SIZE_CARD32);
288
/* Allocate memory for our config structure */
289
config = (__GLXFBConfig*)
290
Xmalloc(numFBConfigs * sizeof(__GLXFBConfig));
297
memset(config, 0, numFBConfigs * sizeof(__GLXFBConfig));
300
/* Convert attribute list into our format */
301
for (i=0; i<numFBConfigs; i++) {
303
/* Fill in default properties */
304
config->transparentType = GLX_NONE_EXT;
305
config->visualCaveat = GLX_NONE_EXT;
308
config->minGreen = 0.;
309
config->maxGreen = 1.;
310
config->minBlue = 0.;
311
config->maxBlue = 1.;
312
config->minAlpha = 0.;
313
config->maxAlpha = 1.;
315
/* Read attribute list */
316
_XRead(dpy, (char *)attrs, (2*numAttribs * __GLX_SIZE_CARD32));
319
for (j=0; j<numAttribs; j++) {
320
int attribute = *p++;
324
/* core attributes */
325
case GLX_FBCONFIG_ID:
328
case GLX_BUFFER_SIZE:
329
config->indexBits = value;
332
config->level = value;
334
case GLX_DOUBLEBUFFER:
335
config->doubleBufferMode = value;
338
config->stereoMode = value;
340
case GLX_AUX_BUFFERS:
341
config->maxAuxBuffers = value;
344
config->redBits = value;
347
config->greenBits = value;
350
config->blueBits = value;
353
config->alphaBits = value;
356
config->depthBits = value;
358
case GLX_STENCIL_SIZE:
359
config->stencilBits = value;
361
case GLX_ACCUM_RED_SIZE:
362
config->accumRedBits = value;
364
case GLX_ACCUM_GREEN_SIZE:
365
config->accumGreenBits = value;
367
case GLX_ACCUM_BLUE_SIZE:
368
config->accumBlueBits = value;
370
case GLX_ACCUM_ALPHA_SIZE:
371
config->accumAlphaBits = value;
373
case GLX_RENDER_TYPE:
374
config->renderType = value;
376
case GLX_DRAWABLE_TYPE:
377
config->drawableType = value;
379
case GLX_X_VISUAL_TYPE:
380
config->visualType = value;
382
case GLX_CONFIG_CAVEAT:
383
config->visualCaveat = value;
385
case GLX_TRANSPARENT_TYPE:
386
config->transparentType = value;
388
case GLX_TRANSPARENT_INDEX_VALUE:
389
config->transparentIndex = value;
391
case GLX_TRANSPARENT_RED_VALUE:
392
config->transparentRed = value;
394
case GLX_TRANSPARENT_GREEN_VALUE:
395
config->transparentGreen = value;
397
case GLX_TRANSPARENT_BLUE_VALUE:
398
config->transparentBlue = value;
400
case GLX_TRANSPARENT_ALPHA_VALUE:
401
config->transparentAlpha = value;
403
case GLX_MAX_PBUFFER_WIDTH:
404
config->maxPbufferWidth = value;
406
case GLX_MAX_PBUFFER_HEIGHT:
407
config->maxPbufferHeight = value;
409
case GLX_MAX_PBUFFER_PIXELS:
410
config->maxPbufferPixels = value;
413
config->associatedVisualId = value;
416
/* visualSelectGroup is an internal used property */
417
case GLX_VISUAL_SELECT_GROUP_SGIX:
418
config->visualSelectGroup = value;
421
/* SGIS_multisample attributes */
422
case GLX_SAMPLES_SGIS:
423
config->multiSampleSize = value;
425
case GLX_SAMPLE_BUFFERS_SGIS:
426
config->nMultiSampleBuffers = value;
429
/* SGIX_pbuffer specific attributes */
430
case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
431
config->optimalPbufferWidth = value;
433
case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
434
config->optimalPbufferHeight = value;
438
/* Ignore attributes we don't recognize */
443
/* Fill in derived values */
444
config->screen = screen;
446
config->rgbMode = config->renderType & GLX_RGBA_BIT;
447
config->colorIndexMode = !config->rgbMode;
449
config->haveAccumBuffer =
450
config->accumRedBits > 0 ||
451
config->accumGreenBits > 0 ||
452
config->accumBlueBits > 0;
453
/* Can't have alpha without color */
455
config->haveDepthBuffer = config->depthBits > 0;
456
config->haveStencilBuffer = config->stencilBits > 0;
458
/* overlay visuals are not valid for now */
459
if (!config->level) {
468
for (i=0; i<numValidConfigs; i++) {
470
/* XXX hack to fill-in mask info (need a better way to do this) */
471
if (config->associatedVisualId != 0) {
472
XVisualInfo *vis, template;
475
template.screen = screen;
476
template.visualid = config->associatedVisualId;
477
vis = XGetVisualInfo(dpy, VisualScreenMask|VisualIDMask,
481
config->redMask = (GLuint)vis->red_mask;
482
config->greenMask = (GLuint)vis->green_mask;
483
config->blueMask = (GLuint)vis->blue_mask;
484
config->alphaMask = 0; /* XXX */
495
*nconfigs = numValidConfigs;
500
GetGLXVisualConfigsFromFBConfigs(__GLXFBConfig *fbconfigs, int nfbconfigs,
501
XVisualInfo *visuals, int nvisuals,
502
__GLXvisualConfig *glxConfigs, int nGlxConfigs,
505
__GLXvisualConfig *configs = NULL;
508
if (!fbconfigs || !nfbconfigs || !nconfigs) return(NULL);
511
/* Allocate memory for our config structure */
512
configs = (__GLXvisualConfig*)
513
Xmalloc(nfbconfigs * sizeof(__GLXvisualConfig));
517
memset(configs, 0, nfbconfigs * sizeof(__GLXvisualConfig));
519
for (i=0; i<nfbconfigs; i++) {
520
__GLXFBConfig *fbcfg = &fbconfigs[i];
522
if (fbcfg->associatedVisualId > 0) {
523
__GLXvisualConfig *cfg = configs + (*nconfigs);
525
XVisualInfo *vinfo = NULL;
527
for (j=0; j<nvisuals; j++) {
528
if (visuals[j].visualid == fbcfg->associatedVisualId) {
533
if (!vinfo) continue;
535
/* skip 16 bit colormap visuals */
536
if (vinfo->depth == 16 &&
537
vinfo->class != TrueColor &&
538
vinfo->class != DirectColor ) {
545
* if the same visualid exists in the glx configs,
546
* copy the glx attributes from the glx config
548
for (j=0; j<nGlxConfigs; j++) {
549
if (glxConfigs[j].vid == vinfo->visualid)
552
if (j < nGlxConfigs) {
553
memcpy(cfg, &glxConfigs[j], sizeof(__GLXvisualConfig) );
558
* make glx attributes from the FB config attributes
560
cfg->vid = fbcfg->associatedVisualId;
561
cfg->class = vinfo->class;
562
cfg->rgba = !(fbcfg->renderType & GLX_COLOR_INDEX_BIT_SGIX);
563
cfg->redSize = fbcfg->redBits;
564
cfg->greenSize = fbcfg->greenBits;
565
cfg->blueSize = fbcfg->blueBits;
566
cfg->alphaSize = fbcfg->alphaBits;
567
cfg->redMask = fbcfg->redMask;
568
cfg->greenMask = fbcfg->greenMask;
569
cfg->blueMask = fbcfg->blueMask;
570
cfg->alphaMask = fbcfg->alphaMask;
571
cfg->accumRedSize = fbcfg->accumRedBits;
572
cfg->accumGreenSize = fbcfg->accumGreenBits;
573
cfg->accumBlueSize = fbcfg->accumBlueBits;
574
cfg->accumAlphaSize = fbcfg->accumAlphaBits;
575
cfg->doubleBuffer = fbcfg->doubleBufferMode;
576
cfg->stereo = fbcfg->stereoMode;
577
if (vinfo->class == TrueColor || vinfo->class == DirectColor) {
578
cfg->bufferSize = (fbcfg->rgbMode ? (fbcfg->redBits +
582
: fbcfg->indexBits );
585
cfg->bufferSize = vinfo->depth;
587
cfg->depthSize = fbcfg->depthBits;
588
cfg->stencilSize = fbcfg->stencilBits;
589
cfg->auxBuffers = fbcfg->maxAuxBuffers;
590
cfg->level = fbcfg->level;
591
cfg->visualRating = fbcfg->visualCaveat;
592
cfg->transparentPixel = fbcfg->transparentType;
593
cfg->transparentRed = fbcfg->transparentRed;
594
cfg->transparentGreen = fbcfg->transparentGreen;
595
cfg->transparentBlue = fbcfg->transparentBlue;
596
cfg->transparentAlpha = fbcfg->transparentAlpha;
597
cfg->transparentIndex = fbcfg->transparentIndex;
598
cfg->multiSampleSize = fbcfg->multiSampleSize;
599
cfg->nMultiSampleBuffers = fbcfg->nMultiSampleBuffers;
600
cfg->visualSelectGroup = fbcfg->visualSelectGroup;