TG: OpenGL cleanup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@28877 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Thomas Gamper 2009-10-25 13:49:19 +00:00
parent 6653ef68cc
commit c0abc9a675
4 changed files with 340 additions and 288 deletions

View file

@ -1,3 +1,11 @@
2009-10-25 Thomas Gamper <icicle@cg.tuwien.ac.at>
* Source/x11/XGGLContext.m
* Source/x11/XGGLFormat.m
* Headers/x11/XGOpenGL.h
Clean up OpenGL stuff, reformat code and add Multisampling
support.
2009-10-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/gsc/GSContext.m,

View file

@ -25,8 +25,8 @@
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_XGOpenGL
#define _GNUstep_H_XGOpenGL
#ifndef _GNUstep_H_XGOpenGL_
#define _GNUstep_H_XGOpenGL_
#include <AppKit/NSOpenGL.h>
@ -42,6 +42,7 @@
@interface XGGLContext : NSOpenGLContext
{
int glxminorversion;
GLXContext glx_context;
GLXWindow glx_drawable;
XGXSubWindow *xSubWindow;
@ -55,33 +56,19 @@
@interface XGGLPixelFormat : NSOpenGLPixelFormat
{
@public
union
{
GLXFBConfig *fbconfig;
XVisualInfo *visualinfo;
} configurations;
Display * display;
long int glxminorversion;
GLXFBConfig *fbconfig;
XVisualInfo *visualinfo;
int configurationCount;
}
- (XVisualInfo *)xvinfo;
- (GLXContext)createGLXContext: (XGGLContext *)share;
+ (int) glxMinorVersion;
- (Display *) display;
- (XVisualInfo *) visualinfo;
- (GLXContext) createGLXContext: (XGGLContext *)share;
- (GLXWindow) drawableForWindow: (Window)xwindowid;
@end
static inline int
GSglxMinorVersion(Display *dpy)
{
int major, minor;
if (False == glXQueryVersion(dpy, &major, &minor))
{
return -1;
}
return minor;
}
#endif

View file

@ -29,6 +29,7 @@
#ifdef HAVE_GLX
#include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#include <Foundation/NSDictionary.h>
#include <GNUstepGUI/GSDisplayServer.h>
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.h>
@ -69,16 +70,21 @@
XSetWindowAttributes window_attributes;
self = [super init];
if (!self)
return nil;
{
return nil;
}
window = [view window];
NSAssert(window, @"request of an X window attachment on a view that is not on a NSWindow");
NSAssert(window, @"Request of an X window attachment on a view that is not\
on a NSWindow");
if ([view isRotatedOrScaledFromBase])
{
[NSException raise: NSInvalidArgumentException
format: @"Cannot attach an Xwindow to a view that is rotated or scaled"];
format: @"Cannot attach an Xwindow to a view that is\
rotated or scaled"];
}
server = (XGServer *)GSServerForWindow(window);
@ -113,11 +119,12 @@
width = NSWidth(rect);
height = NSHeight(rect);
window_attributes.border_pixel = 255;
window_attributes.border_pixel = 0;
window_attributes.background_pixel = 0;
window_attributes.colormap = XCreateColormap(win_info->display,
win_info->ident,
xVisualInfo->visual, AllocNone);
window_attributes.event_mask = StructureNotifyMask
| VisibilityChangeMask
| ExposureMask;
@ -126,8 +133,8 @@
xwindowid = XCreateWindow(win_info->display, win_info->ident,
x, y, width, height, 0,
xVisualInfo->depth, InputOutput, xVisualInfo->visual,
mask, &window_attributes);
xVisualInfo->depth, InputOutput,
xVisualInfo->visual, mask, &window_attributes);
XMapWindow(win_info->display, xwindowid);
@ -208,7 +215,8 @@
- (void) dealloc
{
NSDebugMLLog(@"GLX", @"deallocating");
NSDebugMLLog(@"GLX", @"Deallocating");
[self detach];
[super dealloc];
}
@ -219,30 +227,36 @@
return AUTORELEASE(win);
}
@end
//FIXME:
//should be on per thread basis.
static XGGLContext *currentGLContext;
@implementation XGGLContext
+ (void)clearCurrentContext
{
MAKE_DISPLAY(dpy);
if (GSglxMinorVersion(dpy) >= 3)
if ([XGGLPixelFormat glxMinorVersion] >= 3)
{
if ( !glXMakeContextCurrent(dpy, None, None, NULL) )
NSDebugMLLog( @"GLX", @"Can not clear current GL context - Errror %u",
glGetError() );
{
NSDebugMLLog( @"GLX",
@"Can not clear current GL context - Errror %u",
glGetError() );
}
}
else
{
if ( !glXMakeCurrent(dpy, None, NULL) )
NSDebugMLLog( @"GLX", @"Can not clear current GL context - Errror %u",
glGetError() );
{
NSDebugMLLog( @"GLX",
@"Can not clear current GL context - Errror %u",
glGetError() );
}
}
currentGLContext = nil;
@ -260,12 +274,16 @@ static XGGLContext *currentGLContext;
MAKE_DISPLAY(dpy);
if (currentGLContext == self)
{
{
[XGGLContext clearCurrentContext];
}
// FIXME:
// glXDestroyWindow(dpy, glx_drawable);
glx_drawable = None;
if ( glx_drawable != xSubWindow->xwindowid )
{
glXDestroyWindow(dpy, glx_drawable);
glx_drawable = None;
}
DESTROY(xSubWindow);
}
}
@ -287,17 +305,22 @@ static XGGLContext *currentGLContext;
MAKE_DISPLAY(dpy);
if (context == nil || ![context isKindOfClass: [XGGLContext class]])
[NSException raise: NSInvalidArgumentException
format: @"%@ is an invalid context", context];
{
[NSException raise: NSInvalidArgumentException
format: @"%@ is an invalid context", context];
}
glXCopyContext(dpy, ((XGGLContext *)context)->glx_context,
glx_context, mask);
error = glGetError();
if ( error != GL_NO_ERROR )
NSDebugMLLog( @"GLX", @"Can not copy GL context %@ from context %@ - Errror %u",
self, context, error );
if ( error != GL_NO_ERROR )
{
NSDebugMLLog( @"GLX",
@"Can not copy GL context %@ from context %@ - Error %u",
self, context, error );
}
}
- (void)createTexture:(unsigned long)target
@ -320,66 +343,8 @@ static XGGLContext *currentGLContext;
MAKE_DISPLAY(dpy);
glXSwapBuffers(dpy, glx_drawable);
#if 0
// FIXME Not with Mesa Xlib sofware driver !
// TODO Use EXT_framebuffer_blit if available
if ( _doubleBuffer )
{
if ( _backingStore )
{
GLint rBuf,dBuf;
GLint viewport[4];
GLfloat raster_pos[4];
/* save viewport */
glGetIntegerv(GL_VIEWPORT, viewport);
/* save old raster position */
glGetFloatv(GL_CURRENT_RASTER_POSITION, raster_pos);
/* set raster position */
glRasterPos4f(0.0, 0.0, 0.0, 1.0);
/* save target/source buffers */
glGetIntegerv( GL_READ_BUFFER, &rBuf );
glGetIntegerv( GL_DRAW_BUFFER, &wBuf );
/* set projection matrix */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity() ;
gluOrtho2D(0, viewport[2], 0, viewport[3]);
/* set modelview matrix */
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//FIXME copy depth, stencil?
glReadBuffer (GL_FRONT_LEFT);
glDrawBuffer (GL_BACK_LEFT);
glCopyPixels(0, 0, viewport[2], viewport[3], GL_COLOR);
if ( _stereo )
{
glReadBuffer (GL_FRONT_RIGHT);
glDrawBuffer (GL_BACK_RIGHT);
glCopyPixels(0, 0, viewport[2], viewport[3], GL_COLOR);
}
/* restore target/source buffers */
glReadBuffer (rBuf);
glDrawBuffer (dBuf);
/* restore old raster position */
glRasterPos4fv(raster_pos);
/* restore old matrices */
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
/* restore viewport */
glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
}
}
#endif
}
- (void)getValues:(long *)vals
forParameter:(NSOpenGLContextParameter)param
{
@ -387,19 +352,21 @@ static XGGLContext *currentGLContext;
[self notImplemented: _cmd];
}
- (id)initWithFormat: (NSOpenGLPixelFormat *)_format
shareContext: (NSOpenGLContext *)share
{
self = [super init];
if (!self)
return nil;
{
return nil;
}
glx_context = None;
if (!_format || ![_format isKindOfClass: [XGGLPixelFormat class]])
{
NSDebugMLLog(@"GLX", @"invalid format %@", _format);
NSDebugMLLog(@"GLX", @"Invalid format %@", _format);
RELEASE(self);
return nil;
@ -407,16 +374,15 @@ static XGGLContext *currentGLContext;
ASSIGN(pixelFormat, (XGGLPixelFormat *)_format);
//FIXME: allow index mode and sharing
glx_context = [pixelFormat createGLXContext: (XGGLContext *)share];
return self;
}
- (void) dealloc
{
NSDebugMLLog(@"GLX", @"deallocating");
NSDebugMLLog(@"GLX", @"Deallocating");
[self _detach];
RELEASE(pixelFormat);
@ -434,27 +400,30 @@ static XGGLContext *currentGLContext;
MAKE_DISPLAY(dpy);
if (xSubWindow == nil)
[NSException raise: NSGenericException
format: @"GL Context is not bind, cannot be made current"];
{
[NSException raise: NSGenericException
format: @"GL Context has no view attached, cannot be\
made current"];
}
NSAssert(glx_context != None && glx_drawable != None,
NSInternalInconsistencyException);
if (GSglxMinorVersion(dpy) >= 3)
if ([XGGLPixelFormat glxMinorVersion] >= 3)
{
//NSDebugMLLog(@"GLX", @"before glXMakeContextCurrent");
if ( !glXMakeContextCurrent(dpy, glx_drawable, glx_drawable, glx_context) )
NSDebugMLLog( @"GLX", @"Can not make GL context %@ current - Errror %u",
self, glGetError() );
//NSDebugMLLog(@"GLX", @"after glXMakeContextCurrent");
{
NSDebugMLLog( @"GLX", @"Cannot make GL context %@ current - Error %u",
self, glGetError() );
}
}
else
{
//NSDebugMLLog(@"GLX", @"before glXMakeCurrent");
if ( !glXMakeCurrent(dpy, glx_drawable, glx_context) )
NSDebugMLLog( @"GLX", @"Can not make GL context %@ current - Errror %u",
self, glGetError() );
//NSDebugMLLog(@"GLX", @"after glXMakeCurrent");
{
NSDebugMLLog( @"GLX", @"Cannot make GL context %@ current - Error %u",
self, glGetError() );
}
}
currentGLContext = self;
@ -487,18 +456,24 @@ static XGGLContext *currentGLContext;
- (void)setView:(NSView *)view
{
NSView *current_view;
if (!view)
[NSException raise: NSInvalidArgumentException
format: @"setView called with a nil value"];
{
[NSException raise: NSInvalidArgumentException
format: @"setView called with a nil value"];
}
NSAssert(pixelFormat, NSInternalInconsistencyException);
current_view = [self view];
if ( current_view != nil )
{
[current_view _setIgnoresBacking: saved_ignores_backing];
}
ASSIGN(xSubWindow, [XGXSubWindow subwindowOnView: view
visualinfo: [pixelFormat xvinfo]]);
visualinfo: [pixelFormat visualinfo]]);
glx_drawable = [pixelFormat drawableForWindow: xSubWindow->xwindowid];
saved_ignores_backing = [view _ignoresBacking];
[view _setIgnoresBacking: YES];

View file

@ -26,80 +26,109 @@
*/
#include "config.h"
#ifdef HAVE_GLX
#include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#include <Foundation/NSData.h>
#include <Foundation/NSDictionary.h>
#include <GNUstepGUI/GSDisplayServer.h>
#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)
#include <math.h>
@implementation XGGLPixelFormat
/* FIXME:
we assume that the ABI of NSOpenGLPixelFormatAttribute matches the ABI
of glX. Apparently, this is true for the most useful attributes.
*/
+ (int) glxMinorVersion
{
Display * display = [(XGServer *)GSCurrentServer() xDisplay];
NSDictionary * attributes = [GSCurrentServer() attributes];
NSString * sn = [attributes objectForKey: GSScreenNumber];
// This is due to some OpenGL drivers reporting a lower overall GLX version than they actually implement.
NSString * glxServerVersion = [NSString stringWithFormat:@"%s", glXQueryServerString(display, [sn intValue], GLX_VERSION)];
NSString * glxClientVersion = [NSString stringWithFormat:@"%s", glXGetClientString(display, GLX_VERSION)];
float serverversion = [glxServerVersion floatValue];
float clientversion = [glxClientVersion floatValue];
float serverIntegerPart;
float clientIntegerPart;
float fracServer = modff(serverversion, &serverIntegerPart);
float fracClient = modff(clientversion, &clientIntegerPart);
if ( serverIntegerPart == 1.0f && clientIntegerPart == 1.0f )
{
fracServer = rintf(fracServer * 10.0f);
fracClient = rintf(fracClient * 10.0f);
NSDebugMLLog(@"GLX", @"server %f client %f", fracServer, fracClient );
return (int)MIN(fracServer, fracClient);
}
return -1;
}
// Works for some attributes only
- (void) getValues: (GLint *)vals
forAttribute: (NSOpenGLPixelFormatAttribute)attrib
forVirtualScreen: (GLint)screen
{
GLint error;
MAKE_DISPLAY(dpy);
NSAssert(((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig : (void *)configurations.visualinfo) != NULL
&& configurationCount > 0,
NSAssert((fbconfig != NULL || visualinfo != NULL) && configurationCount > 0,
NSInternalInconsistencyException);
if (GSglxMinorVersion(dpy) >= 3)
int error;
if (glxminorversion >= 3)
{
error = glXGetFBConfigAttrib(dpy, configurations.fbconfig[0], attrib, vals);
error = glXGetFBConfigAttrib(display, fbconfig[0], attrib, vals);
if ( error != 0 )
NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u",
NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Error %u",
self, error );
}
else
{
error = glXGetConfig(dpy, configurations.visualinfo, attrib, vals);
error = glXGetConfig(display, visualinfo, attrib, vals);
if ( error != 0 )
NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u",
self, error );
if ( error != 0 )
NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u",
NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Error %u",
self, error );
}
}
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
- (NSMutableData *) assembleGLXAttributes:(NSOpenGLPixelFormatAttribute *)pixelFormatAttributes
{
int AccumSize;
NSOpenGLPixelFormatAttribute *ptr = attribs;
NSOpenGLPixelFormatAttribute *ptr = pixelFormatAttributes;
NSMutableData *data = [NSMutableData data];
#define append(a, b) \
do \
{ \
int v1 = a; \
int v2 = b; \
[data appendBytes: &v1 length: sizeof(v1)]; \
[data appendBytes: &v2 length: sizeof(v2)]; \
} while (0)
#define append1(a) \
do \
{ \
int v1 = a; \
[data appendBytes: &v1 length: sizeof(v1)]; \
} while (0)
GLint drawable_type = 0;
MAKE_DISPLAY(dpy);
#define append(a, b) do {int v1 = a; int v2 = b; [data appendBytes: &v1 length: sizeof(v1)];\
[data appendBytes: &v2 length: sizeof(v2)];} while (0)
#define append1(a) do {int v1 = a; [data appendBytes: &v1 length: sizeof(v1)];} while (0)
if (GSglxMinorVersion (dpy) < 3)
if (glxminorversion < 3)
{
append1 (GLX_RGBA);
append1(GLX_RGBA);
}
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);
}
while (*ptr)
@ -110,95 +139,139 @@
case NSOpenGLPFASingleRenderer:
case NSOpenGLPFAAllRenderers:
case NSOpenGLPFAAccelerated:
if (GSglxMinorVersion(dpy) < 3)
append(GLX_USE_GL,YES);
break;
if (glxminorversion < 3)
{
append(GLX_USE_GL, YES);
break;
}
case NSOpenGLPFADoubleBuffer:
append(GLX_DOUBLEBUFFER, YES);
break;
{
append(GLX_DOUBLEBUFFER, YES);
break;
}
case NSOpenGLPFAStereo:
append(GLX_STEREO, YES);
break;
{
append(GLX_STEREO, YES);
break;
}
case NSOpenGLPFAAuxBuffers:
ptr++;
append(GLX_AUX_BUFFERS, *ptr);
break;
{
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;
{
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;
{
ptr++;
append(GLX_ALPHA_SIZE, *ptr);
break;
}
case NSOpenGLPFADepthSize:
ptr++;
append(GLX_DEPTH_SIZE, *ptr);
break;
{
ptr++;
append(GLX_DEPTH_SIZE, *ptr);
break;
}
case NSOpenGLPFAStencilSize:
ptr++;
append(GLX_STENCIL_SIZE, *ptr);
break;
{
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;
case NSOpenGLPFAWindow:
drawable_type |= GLX_WINDOW_BIT;
break;
case NSOpenGLPFAPixelBuffer:
drawable_type |= GLX_PBUFFER_BIT;
break;
{
ptr++;
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;
}
case NSOpenGLPFAWindow:
{
drawable_type |= GLX_WINDOW_BIT;
break;
}
case NSOpenGLPFAPixelBuffer:
{
drawable_type |= GLX_PBUFFER_BIT;
break;
}
case NSOpenGLPFAOffScreen:
drawable_type |= GLX_PIXMAP_BIT;
break;
{
drawable_type |= GLX_PIXMAP_BIT;
break;
}
//can not be handle by X11
//can not be handled by X11
case NSOpenGLPFAMinimumPolicy:
break;
// can not be handle by X11
{
break;
}
// can not be handled by X11
case NSOpenGLPFAMaximumPolicy:
break;
//FIXME all of this stuff...
{
break;
}
// Not supported, would be a lot of work to implement.
case NSOpenGLPFAFullScreen:
{
break;
}
case NSOpenGLPFASampleBuffers:
{
if ( glxminorversion >= 4 )
{
ptr++;
append(GLX_SAMPLE_BUFFERS, *ptr);
break;
}
}
case NSOpenGLPFASamples:
{
if ( glxminorversion >= 4 )
{
ptr++;
append(GLX_SAMPLES, *ptr);
break;
}
}
case NSOpenGLPFAAuxDepthStencil:
case NSOpenGLPFARendererID:
case NSOpenGLPFANoRecovery:
@ -210,7 +283,6 @@
case NSOpenGLPFACompliant:
case NSOpenGLPFAScreenMask:
case NSOpenGLPFAVirtualScreenCount:
case NSOpenGLPFAAllowOfflineRenderers:
case NSOpenGLPFAColorFloat:
case NSOpenGLPFAMultisample:
@ -223,34 +295,50 @@
if ( drawable_type )
{
append(GLX_DRAWABLE_TYPE,drawable_type);
append(GLX_DRAWABLE_TYPE, drawable_type);
}
append1(None);
//FIXME, what screen number ?
if (GSglxMinorVersion (dpy) >= 3)
return data;
#undef append
#undef append1
}
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
{
self = [super init];
fbconfig = NULL;
visualinfo = NULL;
display = [(XGServer *)GSCurrentServer() xDisplay];
NSAssert(display != NULL, NSInternalInconsistencyException);
glxminorversion = [XGGLPixelFormat glxMinorVersion];
NSDebugMLLog(@"GLX", @"minor version %d", glxminorversion);
NSMutableData * glxAttributes = [self assembleGLXAttributes:attribs];
NSDictionary * dsattributes = [GSCurrentServer() attributes];
if (glxminorversion >= 3)
{
configurations.fbconfig = glXChooseFBConfig(dpy, DefaultScreen(dpy),
[data mutableBytes],
&configurationCount);
if ( configurations.fbconfig == NULL )
NSDebugMLLog( @"GLX", @"Can not choose FB config for pixel format %@",
self );
fbconfig = glXChooseFBConfig(display,
[[dsattributes objectForKey: GSScreenNumber] intValue],
[glxAttributes mutableBytes],
&configurationCount);
visualinfo = glXGetVisualFromFBConfig(display,fbconfig[0]);
}
else
{
configurations.visualinfo = glXChooseVisual(dpy, DefaultScreen(dpy),
[data mutableBytes]);
if((void *)configurations.visualinfo != NULL)
configurationCount = 1;
else
NSDebugMLLog( @"GLX", @"Can not choose FB config for pixel format %@",
self );
visualinfo = glXChooseVisual(display,
[[dsattributes objectForKey: GSScreenNumber] intValue],
[glxAttributes mutableBytes]);
}
if (((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig :
(void *)configurations.visualinfo) == NULL)
if (fbconfig == NULL && visualinfo == NULL)
{
NSDebugMLLog(@"GLX", @"no pixel format found matching what is required");
RELEASE(self);
@ -265,79 +353,73 @@
}
}
- (XVisualInfo *)xvinfo
- (Display *) display
{
MAKE_DISPLAY(dpy);
return display;
}
if (GSglxMinorVersion(dpy) >= 3)
{
return glXGetVisualFromFBConfig(dpy, configurations.fbconfig[0]);
}
else
{
return configurations.visualinfo;
}
- (XVisualInfo *) visualinfo
{
return visualinfo;
}
- (GLXContext)createGLXContext: (XGGLContext *)share
{
GLXContext context;
MAKE_DISPLAY(dpy);
if (GSglxMinorVersion(dpy) >= 3)
if (glxminorversion >= 3)
{
context = glXCreateNewContext(dpy, configurations.fbconfig[0],
context = glXCreateNewContext(display, fbconfig[0],
GLX_RGBA_TYPE, [share glxcontext], YES);
}
else
{
context = glXCreateContext(dpy, configurations.visualinfo,
context = glXCreateContext(display, visualinfo,
[share glxcontext], GL_TRUE);
}
if ( context == NULL )
NSDebugMLLog( @"GLX", @"Can not create GL context for pixel format %@ - Errror %u",
self, glGetError() );
{
NSDebugMLLog(@"GLX",
@"Can not create GL context for pixel format %@ - Error %u",
self, glGetError());
}
return context;
}
- (GLXWindow) drawableForWindow: (Window)xwindowid
{
GLint error;
GLXWindow win;
MAKE_DISPLAY(dpy);
if (GSglxMinorVersion(dpy) >= 3)
if (glxminorversion >= 3)
{
win = glXCreateWindow(dpy, configurations.fbconfig[0],
xwindowid, NULL);
win = glXCreateWindow(display, fbconfig[0], xwindowid, NULL);
}
else
{
win = xwindowid;
}
error = glGetError();
GLint error = glGetError();
if ( error != GL_NO_ERROR )
NSDebugMLLog( @"GLX", @"Can not create GL window for pixel format %@ - Errror %u",
self, error );
{
NSDebugMLLog(@"GLX",
@"Can not create GL window for pixel format %@ - Error %u",
self, error );
}
return win;
}
- (void) dealloc
{
//FIXME
//are we sure that X Connection is still up here ?
MAKE_DISPLAY(dpy);
if (glxminorversion >= 3)
{
XFree(fbconfig);
}
if (GSglxMinorVersion(dpy) >= 3)
{
XFree(configurations.fbconfig);
}
else
{
XFree(configurations.visualinfo);
}
XFree(visualinfo);
NSDebugMLLog(@"GLX", @"deallocation");
[super dealloc];
@ -346,9 +428,9 @@
- (int)numberOfVirtualScreens
{
//FIXME
//This looks like a reasonable value to return...
return 1;
}
@end
#endif