Fix low-res depth buffer on OSX

BlitzMax Forums/BlitzMax Module Tweaks/Fix low-res depth buffer on OSX

JoshK(Posted 2012) [#1]
By default, MaxGUI canvases use an extremely low-res depth buffer on OSX. Find this code around line 68 of BRL.GLGraphics/glgraphics.macos.m:
static int _initAttrs( CGLPixelFormatAttribute attrs[16],int flags ){
	int n=0;
	if( flags & FLAGS_BACKBUFFER ) attrs[n++]=kCGLPFADoubleBuffer;
	if( flags & FLAGS_ALPHABUFFER ){ attrs[n++]=kCGLPFAAlphaSize;attrs[n++]=1; }
	if( flags & FLAGS_DEPTHBUFFER ){ attrs[n++]=kCGLPFADepthSize;attrs[n++]=1; }
	if( flags & FLAGS_STENCILBUFFER ){ attrs[n++]=kCGLPFAStencilSize;attrs[n++]=1; }
	if( flags & FLAGS_ACCUMBUFFER ){ attrs[n++]=kCGLPFAAccumSize;attrs[n++]=1; }
	if( flags & FLAGS_FULLSCREEN ){
		attrs[n++]=kCGLPFAFullScreen;
		attrs[n++]=kCGLPFADisplayMask;
		attrs[n++]=CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay );
	}else{
		attrs[n++]=kCGLPFANoRecovery;
	}
	attrs[n]=0;
	return n;
}


Replace this line:
if( flags & FLAGS_DEPTHBUFFER ){ attrs[n++]=kCGLPFADepthSize;attrs[n++]=1; }

With this:
if( flags & FLAGS_DEPTHBUFFER ){ attrs[n++]=kCGLPFADepthSize;attrs[n++]=24; }

Viola, the depth buffer now looks good!


SLotman(Posted 2012) [#2]
I confirm this works - I've done it a long time ago (mainly to improve the depth buffer in minib3d - without it you get some pretty bad sorting errors if your near/far camera values are too far apart)

Too bad the same solution doesn't work on Windows, on those lousy Intel GMA chips - their windows driver (at least on XP) completely ignore the code and forcefully creates a 16bpp depth buffer in opengl =(

Last edited 2012


Sonic(Posted 2013) [#3]
sorry to necro this post, but that OSX fix has really helped my game where i have layered sprites in minib3D. what is the score with the Win version, does it default to a higher res depth buffer anyway? is it just the old GMA cards that have a low-res buffer? i haven't had a chance to test this new version of my game in windows, so i'm curious as to whether it'll only work on my dev Mac!


SLotman(Posted 2013) [#4]
It depends. GMA cards are really bad, and recently I faced some Intel Q35 which won't even initialize an OpenGL window properly. Intel "HD" series seems fine though.