How to dynamically check for SDL_GL_SWAP_INTERVAL support

Hi, I’m wondering how to check (at runtime) if I can use the GL command:

SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );

This only works on SDL > 1.2.10, I think. The problem is, how do I
check this at runtime, since the SDL lib will be dynamically linked?
And just because it’s available at compile-time doesn’t mean it will be
at run-time (and vice-versa).

Basically, I need to determine at run-time if the
enum ‘SDL_GL_SWAP_CONTROL’ is actually defined. Does anyone have any
advice? I know I could just define that variable to whatever SDL
1.2.10 uses and just always call the function, but that seems a hacky
way of doing things.

Thanks for any info,
Steve

even though you are dynamically linking to the sdl lib, you still “statically link” to sdl.h and other sdl related headers which is where the enum is actually defined.

---- Stephen Anthony wrote:> Hi, I’m wondering how to check (at runtime) if I can use the GL command:

SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );

This only works on SDL > 1.2.10, I think. The problem is, how do I
check this at runtime, since the SDL lib will be dynamically linked?
And just because it’s available at compile-time doesn’t mean it will be
at run-time (and vice-versa).

Basically, I need to determine at run-time if the
enum ‘SDL_GL_SWAP_CONTROL’ is actually defined. Does anyone have any
advice? I know I could just define that variable to whatever SDL
1.2.10 uses and just always call the function, but that seems a hacky
way of doing things.

Thanks for any info,
Steve


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hello Stephen,

Monday, December 4, 2006, 5:47:00 PM, you wrote:

Hi, I’m wondering how to check (at runtime) if I can use the GL command:

SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );

This only works on SDL > 1.2.10, I think. The problem is, how do I
check this at runtime, since the SDL lib will be dynamically linked?
And just because it’s available at compile-time doesn’t mean it will be
at run-time (and vice-versa).

The “enum” is just a value that gets compiled into your program. Older
versions of SDL which don’t recognise it should just do nothing
(they might generate an error through SDL_GetError()).

If this is a Linux program, the best thing to do is a) explicitly say
you need 1.2.10 or greater, b) if it’s a closed source binary app,
distribute your own libSDL.so with your executable.–
Best regards,
Peter mailto:@Peter_Mulholland

Hello Stephen,

Monday, December 4, 2006, 5:47:00 PM, you wrote:

Hi, I’m wondering how to check (at runtime) if I can use the GL
command:

SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );

This only works on SDL > 1.2.10, I think. The problem is, how do I
check this at runtime, since the SDL lib will be dynamically
linked? And just because it’s available at compile-time doesn’t
mean it will be at run-time (and vice-versa).

The “enum” is just a value that gets compiled into your program.
Older versions of SDL which don’t recognise it should just do nothing
(they might generate an error through SDL_GetError()).

On another guys advice, I actually did a little experimentation, and
looked at the source code for SDL in this area. I tried passing in a
nonsensical enum value, and it still worked fine (it just ignored the
setting).

If this is a Linux program, the best thing to do is a) explicitly say
you need 1.2.10 or greater, b) if it’s a closed source binary app,
distribute your own libSDL.so with your executable.

OSX and Win32 get distributed with their own SDL lib, so it’s not a
problem there. My only concern was what happens when the lib doesn’t
support the functionality, and that #define’ing the enum values seemed
a bit hacky. But it does work, so hacky it is :slight_smile:

SteveOn Monday 04 December 2006 15:08, Peter Mulholland wrote:

Stephen Anthony wrote:

I know I could just define that variable to whatever SDL
1.2.10 uses and just always call the function, but that seems a hacky
way of doing things.

That’s what I do. To even allow compilation of my app with an older SDL,
I do

#if ! SDL_VERSION_ATLEAST(1, 2, 10)
#define SDL_GL_SWAP_CONTROL 16
#endif
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

This is safe because SDL_GL_SetAttribute quietly returns -1 without
doing any harm if you give it an unknown attribute. (It’s not explicitly
documented to do that, but it’s obvious if you look at the code, and
it’s the only sensible thing to do.)

-Christian