summaryrefslogtreecommitdiff
path: root/hw/xquartz/GL
diff options
context:
space:
mode:
authorGeorge Staplin <georgestaplin@george-staplins-mac-pro.local>2008-10-06 18:01:23 -0600
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-10-08 18:44:21 -0700
commita8f5d422c9c0a39f55e80bbd180439b6ec3a805c (patch)
tree82a67a2265fdf0a9feed279583d20ea8b619c792 /hw/xquartz/GL
parent2998e48be343ab2a11d6d328fc961ab5b8eb9292 (diff)
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)
Diffstat (limited to 'hw/xquartz/GL')
-rw-r--r--hw/xquartz/GL/capabilities.c86
-rw-r--r--hw/xquartz/GL/capabilities.h15
-rw-r--r--hw/xquartz/GL/visualConfigs.c118
-rw-r--r--hw/xquartz/GL/visualConfigs.h6
4 files changed, 225 insertions, 0 deletions
diff --git a/hw/xquartz/GL/capabilities.c b/hw/xquartz/GL/capabilities.c
new file mode 100644
index 000000000..3a540258b
--- /dev/null
+++ b/hw/xquartz/GL/capabilities.c
@@ -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;
+}
diff --git a/hw/xquartz/GL/capabilities.h b/hw/xquartz/GL/capabilities.h
new file mode 100644
index 000000000..74487be89
--- /dev/null
+++ b/hw/xquartz/GL/capabilities.h
@@ -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
diff --git a/hw/xquartz/GL/visualConfigs.c b/hw/xquartz/GL/visualConfigs.c
new file mode 100644
index 000000000..05dfa19b1
--- /dev/null
+++ b/hw/xquartz/GL/visualConfigs.c
@@ -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);
+}
diff --git a/hw/xquartz/GL/visualConfigs.h b/hw/xquartz/GL/visualConfigs.h
new file mode 100644
index 000000000..f9cd8861b
--- /dev/null
+++ b/hw/xquartz/GL/visualConfigs.h
@@ -0,0 +1,6 @@
+#ifndef VISUAL_CONFIGS_H
+#define VISUAL_CONFIGS_H
+
+void setVisualConfigs(void);
+
+#endif