2002-11-16 05:00:14 +00:00
|
|
|
/* -*- mode:ObjC -*-
|
|
|
|
XGGLContext - backend implementation of NSOpenGLContext
|
|
|
|
|
|
|
|
Copyright (C) 1998,2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Frederic De Jaeger
|
|
|
|
Date: Nov 2002
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C User Interface Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 23:25:10 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2002-11-16 05:00:14 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:12:46 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 23:25:10 +00:00
|
|
|
|
2002-11-16 05:00:14 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 23:25:10 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2002-11-16 05:00:14 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_GLX
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSData.h>
|
2003-07-31 23:57:11 +00:00
|
|
|
#include <GNUstepGUI/GSDisplayServer.h>
|
2002-11-16 05:00:14 +00:00
|
|
|
#include "x11/XGServer.h"
|
|
|
|
#include "x11/XGOpenGL.h"
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#define MAKE_DISPLAY(dpy) Display *dpy;\
|
|
|
|
dpy = [(XGServer *)GSCurrentServer() xDisplay];\
|
|
|
|
NSAssert(dpy != NULL, NSInternalInconsistencyException)
|
|
|
|
|
|
|
|
|
|
|
|
@implementation XGGLPixelFormat
|
2008-01-21 21:27:58 +00:00
|
|
|
|
|
|
|
/* FIXME:
|
2002-11-16 05:00:14 +00:00
|
|
|
we assume that the ABI of NSOpenGLPixelFormatAttribute matches the ABI
|
2008-01-21 21:27:58 +00:00
|
|
|
of glX. Apparently, this is true for the most useful attributes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void) getValues: (GLint *)vals
|
|
|
|
forAttribute: (NSOpenGLPixelFormatAttribute)attrib
|
|
|
|
forVirtualScreen: (GLint)screen
|
2002-11-16 05:00:14 +00:00
|
|
|
{
|
|
|
|
MAKE_DISPLAY(dpy);
|
2003-07-23 03:40:47 +00:00
|
|
|
|
2008-01-21 21:27:58 +00:00
|
|
|
NSAssert(((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig : (void *)configurations.visualinfo) != NULL
|
|
|
|
&& configurationCount > 0,
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
|
|
|
if (GSglxMinorVersion(dpy) >= 3)
|
|
|
|
{
|
|
|
|
glXGetFBConfigAttrib(dpy, configurations.fbconfig[0], attrib, vals);
|
|
|
|
}
|
2003-07-23 03:40:47 +00:00
|
|
|
else
|
2008-01-21 21:27:58 +00:00
|
|
|
{
|
|
|
|
glXGetConfig(dpy, configurations.visualinfo, attrib, vals);
|
|
|
|
}
|
2002-11-16 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
|
|
|
|
{
|
2003-07-24 03:24:13 +00:00
|
|
|
int AccumSize;
|
2002-11-16 05:00:14 +00:00
|
|
|
NSOpenGLPixelFormatAttribute *ptr = attribs;
|
|
|
|
NSMutableData *data = [NSMutableData data];
|
|
|
|
MAKE_DISPLAY(dpy);
|
|
|
|
|
2008-01-21 21:27:58 +00:00
|
|
|
#define append(a, b) do {int v1 = a; int v2 = b; [data appendBytes: &v1 length: sizeof(v1)];\
|
2004-11-29 00:19:46 +00:00
|
|
|
[data appendBytes: &v2 length: sizeof(v2)];} while (0)
|
2008-01-21 21:27:58 +00:00
|
|
|
|
|
|
|
#define append1(a) do {int v1 = a; [data appendBytes: &v1 length: sizeof(v1)];} while (0)
|
2002-11-16 05:00:14 +00:00
|
|
|
|
2003-07-23 03:40:47 +00:00
|
|
|
if (GSglxMinorVersion (dpy) < 3)
|
2004-11-29 00:19:46 +00:00
|
|
|
{
|
|
|
|
append1 (GLX_RGBA);
|
|
|
|
}
|
2008-01-21 21:27:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
append(GLX_RENDER_TYPE, GLX_RGBA_BIT);
|
|
|
|
append(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT|GLX_PIXMAP_BIT);
|
|
|
|
// append(GLX_X_RENDERABLE,YES);
|
|
|
|
//append(GLX_X_VISUAL_TYPE,GLX_TRUE_COLOR);
|
|
|
|
}
|
2003-07-23 03:40:47 +00:00
|
|
|
|
2005-11-16 11:40:31 +00:00
|
|
|
while (*ptr)
|
2002-11-16 05:00:14 +00:00
|
|
|
{
|
|
|
|
switch(*ptr)
|
2008-01-21 21:27:58 +00:00
|
|
|
{
|
|
|
|
// it means all the same on GLX - there is no diffrent here
|
|
|
|
case NSOpenGLPFASingleRenderer:
|
|
|
|
case NSOpenGLPFAAllRenderers:
|
|
|
|
case NSOpenGLPFAAccelerated:
|
|
|
|
if (GSglxMinorVersion(dpy) < 3)
|
|
|
|
append(GLX_USE_GL,YES);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFADoubleBuffer:
|
|
|
|
append(GLX_DOUBLEBUFFER, YES);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAStereo:
|
|
|
|
append(GLX_STEREO, YES);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAAuxBuffers:
|
|
|
|
ptr++;
|
|
|
|
append(GLX_AUX_BUFFERS, *ptr);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAColorSize:
|
|
|
|
ptr++;
|
|
|
|
append(GLX_RED_SIZE, *ptr);
|
|
|
|
append(GLX_GREEN_SIZE, *ptr);
|
|
|
|
append(GLX_BLUE_SIZE, *ptr);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAAlphaSize:
|
|
|
|
ptr++;
|
|
|
|
append(GLX_ALPHA_SIZE, *ptr);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFADepthSize:
|
|
|
|
ptr++;
|
|
|
|
append(GLX_DEPTH_SIZE, *ptr);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAStencilSize:
|
|
|
|
ptr++;
|
|
|
|
append(GLX_STENCIL_SIZE, *ptr);
|
|
|
|
break;
|
|
|
|
case NSOpenGLPFAAccumSize:
|
|
|
|
ptr++;
|
|
|
|
//has to been tested - I did it in that way....
|
|
|
|
//FIXME? I don't understand...
|
|
|
|
//append(GLX_ACCUM_RED_SIZE, *ptr/3);
|
|
|
|
//append(GLX_ACCUM_GREEN_SIZE, *ptr/3);
|
|
|
|
//append(GLX_ACCUM_BLUE_SIZE, *ptr/3);
|
|
|
|
AccumSize=*ptr;
|
|
|
|
switch (AccumSize)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
append(GLX_ACCUM_RED_SIZE, 3);
|
|
|
|
append(GLX_ACCUM_GREEN_SIZE, 3);
|
|
|
|
append(GLX_ACCUM_BLUE_SIZE, 2);
|
|
|
|
append(GLX_ACCUM_ALPHA_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
append(GLX_ACCUM_RED_SIZE, 5);
|
|
|
|
append(GLX_ACCUM_GREEN_SIZE, 5);
|
|
|
|
append(GLX_ACCUM_BLUE_SIZE, 5);
|
|
|
|
append(GLX_ACCUM_ALPHA_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
append(GLX_ACCUM_RED_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_GREEN_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_BLUE_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_ALPHA_SIZE, 0);
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
append(GLX_ACCUM_RED_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_GREEN_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_BLUE_SIZE, 8);
|
|
|
|
append(GLX_ACCUM_ALPHA_SIZE, 8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//can not be handle by X11
|
|
|
|
case NSOpenGLPFAMinimumPolicy:
|
|
|
|
break;
|
|
|
|
// can not be handle by X11
|
|
|
|
case NSOpenGLPFAMaximumPolicy:
|
|
|
|
break;
|
|
|
|
|
|
|
|
//FIXME all of this stuff...
|
|
|
|
case NSOpenGLPFAOffScreen:
|
|
|
|
case NSOpenGLPFAFullScreen:
|
|
|
|
case NSOpenGLPFASampleBuffers:
|
|
|
|
case NSOpenGLPFASamples:
|
|
|
|
case NSOpenGLPFAAuxDepthStencil:
|
|
|
|
case NSOpenGLPFARendererID:
|
|
|
|
case NSOpenGLPFANoRecovery:
|
|
|
|
case NSOpenGLPFAClosestPolicy:
|
|
|
|
case NSOpenGLPFARobust:
|
|
|
|
case NSOpenGLPFABackingStore:
|
|
|
|
case NSOpenGLPFAMPSafe:
|
|
|
|
case NSOpenGLPFAWindow:
|
|
|
|
case NSOpenGLPFAMultiScreen:
|
|
|
|
case NSOpenGLPFACompliant:
|
|
|
|
case NSOpenGLPFAScreenMask:
|
|
|
|
case NSOpenGLPFAVirtualScreenCount:
|
|
|
|
break;
|
|
|
|
}
|
2002-11-16 05:00:14 +00:00
|
|
|
ptr ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
append1(None);
|
|
|
|
|
|
|
|
//FIXME, what screen number ?
|
2003-07-23 03:40:47 +00:00
|
|
|
if (GSglxMinorVersion (dpy) >= 3)
|
2008-01-21 21:27:58 +00:00
|
|
|
{
|
|
|
|
configurations.fbconfig = glXChooseFBConfig(dpy, DefaultScreen(dpy),
|
|
|
|
[data mutableBytes],
|
|
|
|
&configurationCount);
|
|
|
|
}
|
2003-07-23 03:40:47 +00:00
|
|
|
else
|
2008-01-21 21:27:58 +00:00
|
|
|
{
|
|
|
|
configurations.visualinfo = glXChooseVisual(dpy, DefaultScreen(dpy),
|
|
|
|
[data mutableBytes]);
|
|
|
|
}
|
2003-07-23 03:40:47 +00:00
|
|
|
|
2008-01-21 21:27:58 +00:00
|
|
|
if (((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig :
|
|
|
|
(void *)configurations.visualinfo) == NULL)
|
2002-11-16 05:00:14 +00:00
|
|
|
{
|
|
|
|
NSDebugMLLog(@"GLX", @"no pixel format found matching what is required");
|
|
|
|
RELEASE(self);
|
2008-01-21 21:27:58 +00:00
|
|
|
|
2002-11-16 05:00:14 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-21 21:27:58 +00:00
|
|
|
NSDebugMLLog(@"GLX", @"We found %d pixel formats", configurationCount);
|
2002-11-16 05:00:14 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 21:27:58 +00:00
|
|
|
- (XVisualInfo *)xvinfo
|
|
|
|
{
|
|
|
|
MAKE_DISPLAY(dpy);
|
|
|
|
|
|
|
|
if (GSglxMinorVersion(dpy) >= 3)
|
|
|
|
{
|
|
|
|
return glXGetVisualFromFBConfig(dpy, configurations.fbconfig[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return configurations.visualinfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GLXContext)createGLXContext: (XGGLContext *)share
|
|
|
|
{
|
|
|
|
MAKE_DISPLAY(dpy);
|
|
|
|
|
|
|
|
if (GSglxMinorVersion(dpy) >= 3)
|
|
|
|
{
|
|
|
|
return glXCreateNewContext(dpy, configurations.fbconfig[0],
|
|
|
|
GLX_RGBA_TYPE, [share glxcontext], YES);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return glXCreateContext(dpy, configurations.visualinfo,
|
|
|
|
[share glxcontext], GL_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GLXWindow) drawableForWindow: (Window)xwindowid
|
|
|
|
{
|
|
|
|
MAKE_DISPLAY(dpy);
|
|
|
|
|
|
|
|
if (GSglxMinorVersion(dpy) >= 3)
|
|
|
|
{
|
|
|
|
return glXCreateWindow(dpy, configurations.fbconfig[0],
|
|
|
|
xwindowid, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return xwindowid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-16 05:00:14 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
//are we sure that X Connection is still up here ?
|
2003-07-23 03:40:47 +00:00
|
|
|
MAKE_DISPLAY(dpy);
|
2008-01-21 21:27:58 +00:00
|
|
|
|
|
|
|
if (GSglxMinorVersion(dpy) >= 3)
|
|
|
|
{
|
|
|
|
XFree(configurations.fbconfig);
|
|
|
|
}
|
2003-07-23 03:40:47 +00:00
|
|
|
else
|
2008-01-21 21:27:58 +00:00
|
|
|
{
|
|
|
|
XFree(configurations.visualinfo);
|
|
|
|
}
|
|
|
|
|
2002-11-16 05:00:14 +00:00
|
|
|
NSDebugMLLog(@"GLX", @"deallocation");
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)numberOfVirtualScreens
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
//This looks like a reasonable value to return...
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
#endif
|