
Test if extension is available
Posted Tuesday, 1 April, 2008 - 15:26 by teichgraf inHello,
I am asking me right now, if OpenTK has a helper method, which tests if a certain OpenGL extension is available?
Something like:
public static bool IsExtAvailable(string ext) { return GL.GetString(StringName.Extensions).Contains(ext); }
Or is there another way to test for extensions at runtime?


Comments
Re: Test if extension is available
This can be simplified using the Enum.GetValues()-method:
Only problem is the GL.Extension.Last-value.
Re: Test if extension is available
I think
GL.Extension.Lastshould be removed from theGL.Extensionenum.GL.Extension.Lastor something likeGL.Extension.Countvalues are a relict from pre managed times, when one needed such values for iteration or array initialization.By the way,
Enum.GetValuesreturnsArray, so it's no problem to get theLength.Re: Test if extension is available
Thanks for the pointer, I'm going to remove 'Last' from this enum, as well as from mouse and keyboard button/keys.
GetValues is actually very inefficient (slow and allocates memory), but its return value can be cached so it won't be a problem.
Re: Test if extension is available
Just out of curiosity, how slow is it..?
Re: Test if extension is available
1024 calls take 8ms on my machine and allocate ~250KB of memory, on an enum with 26 values (the alphabet).
Re: Test if extension is available
Well I don't think it matters much which of the options, it's not the normal use case iterating through all extensions.
What might be interesting is adding custom extensions DIRECTX_9, DIRECTX_10 which returns true if the set of extensions (which represent the functionality) are available. Might be a bad idea though, since Geforce 5, 6 & 7 are all DX9 cards but vary in functionality and performance quite a bit.
Re: Test if extension is available
Definitely a bad idea, even DX9 hardware differs wildly in capabilities. Testing for specific opengl extensions is the way to go.
What would make sense is automatic detection of Shader Model (2, 3, 4). Here is a good reference, in case someone is interested in implementing this.
Re: Test if extension is available
The idea was more like the iterate-through-all-extensions for debug purposes. An OpenGL app should indeed rather check for the required extensions than relying on DIRECTX_10, etc. You're right, it's probably not a good idea.
GL.SupportsShadermodel
The problem with testing for a single extension is that it works for Nvidia and Ati cards, but will fail for others although they might support SM3. I'd be interested in such a function, but the torusknot test has proven that you spend way more time kicking your "testers" in the butt to run the test and forward it to you or teaching how to navigate directories and what c&p is. Don't have the nerve to do this again so soon tbh.
Just compiling the SM3 one and fall back to a SM2 one (or fixed-func) is the way to go, unless there's alot of motivated people supporting the testing. It might be best to add this with the the benchmark/diagnostics app, which requires alot of testing anyways.