XQuartz: GL: Provide code for getting the capabilities of the underlying system's CGL.
Add a setVisualConfigs that is called before the fbScreenInit, to setup the __GLXvisualConfigs. (cherry picked from commit fc86f9e4482043eca76d9d7a96e166be1aabf674)
This commit is contained in:
parent
2998e48be3
commit
a8f5d422c9
|
@ -0,0 +1,86 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <OpenGL/glext.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#include "capabilities.h"
|
||||
|
||||
//#define DIAGNOSTIC 0
|
||||
|
||||
static void handleBufferModes(struct glCapabilities *cap, GLint bufferModes) {
|
||||
if(bufferModes & kCGLStereoscopicBit) {
|
||||
cap->stereo = true;
|
||||
}
|
||||
|
||||
if(bufferModes & kCGLDoubleBufferBit) {
|
||||
cap->buffers = 2;
|
||||
} else {
|
||||
cap->buffers = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void initCapabilities(struct glCapabilities *cap) {
|
||||
cap->stereo = cap->buffers = cap->aux_buffers = 0;
|
||||
}
|
||||
|
||||
enum {
|
||||
MAX_DISPLAYS = 32
|
||||
};
|
||||
|
||||
/*Return true if an error occured. */
|
||||
bool getGlCapabilities(struct glCapabilities *cap) {
|
||||
CGDirectDisplayID dspys[MAX_DISPLAYS];
|
||||
CGDisplayErr err;
|
||||
CGOpenGLDisplayMask displayMask;
|
||||
CGDisplayCount i, displayCount = 0;
|
||||
|
||||
initCapabilities(cap);
|
||||
|
||||
err = CGGetActiveDisplayList(MAX_DISPLAYS, dspys, &displayCount);
|
||||
if(err) {
|
||||
#ifdef DIAGNOSTIC
|
||||
fprintf(stderr, "CGGetActiveDisplayList %s\n", CGLErrorString (err));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
for(i = 0; i < displayCount; ++i) {
|
||||
displayMask = CGDisplayIDToOpenGLDisplayMask(dspys[i]);
|
||||
|
||||
CGLRendererInfoObj info;
|
||||
GLint numRenderers = 0, r, accelerated = 0, flags = 0, aux = 0;
|
||||
|
||||
err = CGLQueryRendererInfo (displayMask, &info, &numRenderers);
|
||||
if(!err) {
|
||||
CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers);
|
||||
for(r = 0; r < numRenderers; ++r) {
|
||||
// find accelerated renderer (assume only one)
|
||||
CGLDescribeRenderer (info, r, kCGLRPAccelerated, &accelerated);
|
||||
if(accelerated) {
|
||||
err = CGLDescribeRenderer(info, r, kCGLRPBufferModes, &flags);
|
||||
if(err) {
|
||||
CGLDestroyRendererInfo(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
handleBufferModes(cap, flags);
|
||||
|
||||
err = CGLDescribeRenderer(info, r, kCGLRPMaxAuxBuffers, &aux);
|
||||
if(err) {
|
||||
CGLDestroyRendererInfo(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
cap->aux_buffers = aux;
|
||||
}
|
||||
}
|
||||
CGLDestroyRendererInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
/* No error occured. We are done. */
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef CAPABILITIES_H
|
||||
#define CAPABILITIES_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct glCapabilities {
|
||||
int stereo;
|
||||
int aux_buffers;
|
||||
int buffers;
|
||||
/*TODO handle STENCIL and ACCUM*/
|
||||
};
|
||||
|
||||
bool getGlCapabilities(struct glCapabilities *cap);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,118 @@
|
|||
#ifdef HAVE_DIX_CONFIG_H
|
||||
#include <dix-config.h>
|
||||
#endif
|
||||
|
||||
#include "dri.h"
|
||||
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/CGLContext.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glxproto.h>
|
||||
#include <windowstr.h>
|
||||
#include <resource.h>
|
||||
#include <GL/glxint.h>
|
||||
#include <GL/glxtokens.h>
|
||||
#include <scrnintstr.h>
|
||||
#include <glxserver.h>
|
||||
#include <glxscreens.h>
|
||||
#include <glxdrawable.h>
|
||||
#include <glxcontext.h>
|
||||
#include <glxext.h>
|
||||
#include <glxutil.h>
|
||||
#include <glxscreens.h>
|
||||
#include <GL/internal/glcore.h>
|
||||
|
||||
#include "capabilities.h"
|
||||
#include "visualConfigs.h"
|
||||
|
||||
extern BOOL enable_stereo;
|
||||
|
||||
void setVisualConfigs(void) {
|
||||
int numConfigs = 0;
|
||||
__GLXvisualConfig *visualConfigs = NULL;
|
||||
void **visualPrivates = NULL;
|
||||
struct glCapabilities caps[1];
|
||||
int stereo, depth, aux, buffers, stencil, accum;
|
||||
int i = 0;
|
||||
|
||||
if(getGlCapabilities(caps)) {
|
||||
ErrorF("error from getGlCapabilities()!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* count num configs:
|
||||
2 stereo (on, off) (optional)
|
||||
2 Z buffer (0, 24 bit)
|
||||
2 AUX buffer (0, 2)
|
||||
2 buffers (single, double)
|
||||
2 stencil (0, 8 bit)
|
||||
2 accum (0, 64 bit)
|
||||
= 64 configs with stereo, or 32 without */
|
||||
|
||||
numConfigs = ((enable_stereo && caps->stereo) ? 2 : 1) * 2 *
|
||||
(caps->aux_buffers ? 2 : 1) * (caps->buffers) * 2 * 2;
|
||||
|
||||
visualConfigs = xcalloc(sizeof(*visualConfigs), numConfigs);
|
||||
visualPrivates = xcalloc(sizeof(void *), numConfigs);
|
||||
|
||||
if (NULL != visualConfigs) {
|
||||
i = 0; /* current buffer */
|
||||
for (stereo = 0; stereo < ((enable_stereo && caps->stereo) ? 2 : 1); ++stereo) {
|
||||
for (depth = 0; depth < 2; ++depth) {
|
||||
for (aux = 0; aux < (caps->aux_buffers ? 2 : 1); ++aux) {
|
||||
for (buffers = 0; buffers < caps->buffers; ++buffers) {
|
||||
for (stencil = 0; stencil < 2; ++stencil) {
|
||||
for (accum = 0; accum < 2; ++accum) {
|
||||
visualConfigs[i].vid = -1;
|
||||
visualConfigs[i].class = -1;
|
||||
visualConfigs[i].rgba = TRUE;
|
||||
visualConfigs[i].redSize = -1;
|
||||
visualConfigs[i].greenSize = -1;
|
||||
visualConfigs[i].blueSize = -1;
|
||||
visualConfigs[i].redMask = -1;
|
||||
visualConfigs[i].greenMask = -1;
|
||||
visualConfigs[i].blueMask = -1;
|
||||
visualConfigs[i].alphaMask = 0;
|
||||
if (accum) {
|
||||
visualConfigs[i].accumRedSize = 16;
|
||||
visualConfigs[i].accumGreenSize = 16;
|
||||
visualConfigs[i].accumBlueSize = 16;
|
||||
visualConfigs[i].accumAlphaSize = 16;
|
||||
} else {
|
||||
visualConfigs[i].accumRedSize = 0;
|
||||
visualConfigs[i].accumGreenSize = 0;
|
||||
visualConfigs[i].accumBlueSize = 0;
|
||||
visualConfigs[i].accumAlphaSize = 0;
|
||||
}
|
||||
visualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
|
||||
visualConfigs[i].stereo = stereo ? TRUE : FALSE;
|
||||
visualConfigs[i].bufferSize = -1;
|
||||
|
||||
visualConfigs[i].depthSize = depth? 24 : 0;
|
||||
visualConfigs[i].stencilSize = stencil ? 8 : 0;
|
||||
visualConfigs[i].auxBuffers = aux ? caps->aux_buffers : 0;
|
||||
visualConfigs[i].level = 0;
|
||||
visualConfigs[i].visualRating = GLX_NONE_EXT;
|
||||
visualConfigs[i].transparentPixel = 0;
|
||||
visualConfigs[i].transparentRed = 0;
|
||||
visualConfigs[i].transparentGreen = 0;
|
||||
visualConfigs[i].transparentBlue = 0;
|
||||
visualConfigs[i].transparentAlpha = 0;
|
||||
visualConfigs[i].transparentIndex = 0;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i != numConfigs) {
|
||||
ErrorF("numConfigs calculation error in setVisualConfigs!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
GlxSetVisualConfigs(numConfigs, visualConfigs, visualPrivates);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef VISUAL_CONFIGS_H
|
||||
#define VISUAL_CONFIGS_H
|
||||
|
||||
void setVisualConfigs(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue