[SDL] SDL 1.3 on Mac OS X speed hit

Sam Lantinga slouken at devolution.com
Tue Aug 14 21:09:48 PDT 2007


> > Performance notes coming shortly.

> - Every call to SDL_SelectRenderer() appears to result in a MakeCurrent 
> call, even if we haven't changed GL contexts, and even if there's only 
> one GL context total. The high-level SDL call should cache the last 
> selected renderer and return immediately if the new selection matches 
> the old one. There are platforms where making a GL context current is 
> extremely expensive, probably even if it's already current. 
> MoveSprites() in testsprite2.c is doing this when there's only one window.

Okay, this is implemented.

> - Never never call a glGet*() entry point if you can avoid it, including 
> glGetError(). In the new multithreaded GL on Mac OS X 10.5 (and some 
> existing 10.4-based hardware), this will force all threads to 
> synchronize, basically nullifying the multithreading boost, even if you 
> just call glGetError() once a frame. glGetError() is mostly good for 
> detecting programming errors and not runtime states, so you can live 
> without it in production code (#ifdef _DEBUG those sections), state you 
> set yourself should be shadowed in local variables instead of retrieved 
> from glGetInteger(), etc, or queried once at startup for things like the 
> max texture size.

I'll switch this over once the VBO/PBO stuff is done.

> - Turn on the multithreaded GL.   :)   Here's the code:

All set, pending VBO/PBO changes to take advantage of it.

> - Don't use glBegin()/glEnd() to put polygons to the screen. Apple 
> engineers implied that just having a vertex_buffer_object with one 
> rectangle in it will be faster, since there's all sorts of state that 
> has to be built, coordinated, pushed to the hardware, and immediately 
> discarded every time in a glBegin/glEnd pair.

I did a test on Windows OpenGL last year, and it was a wash.  I opted to
leave it as glBegin and glEnd for simplicity, but since it's much better
on Mac OS X, yes let's use a VBO.

> - Keep track of state you've set, only set it when it changes (if 
> texture X is already bound to target Y, calling glBindTexture(Y, X) is a 
> waste of time). Not all GL implementations are smart enough to make 
> these into no-ops. This is probably a small win overall, though.

Once the VBO/PBO stuff is done I'll go through and clean this up.  I'll
wait until then since I'm not sure how much code will change between now
and then.

Thanks!
	-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment



More information about the SDL mailing list