giawa / opengl4csharp

OpenGL 4 Bindings (partially based on OpenTK) for C#
Other
234 stars 61 forks source link

Detect if platform is not supported #2

Closed WardBenjamin closed 7 years ago

WardBenjamin commented 8 years ago

Hey Giawa,

I've been working on a game development framework using SDL and your OpenGL bindings, and was wondering if you had any input on detecting if any OpenGL features are not supported on a device. Essentially, is there a way to detect if any of the dll references that you do here fail, without crashing? I'm asking this because I want to support GL3 as well as GL4, so some of the methods here in my case would be allowed to not exist.

giawa commented 8 years ago

Hi WardBenjamin,

Thanks for the comment, and I'm glad the OpenGL bindings have been useful :D

You can currently check to see if a function exists by calling Gl.GetAddress("glFunctionName") with the function name and checking if a null pointer is returned (IntPtr.Zero). You can also verify the OpenGL version via Gl.Version() or via Gl.GetString(StringName.Version) (which will return something like "4.4.13084 Compatibility Profile Context 14.301.1001.0").

Hopefully this helps! If you have further suggestions as to how to gracefully handle missing dll references please let me know and we could work towards incorporating them into the opengl4csharp library.

Giawa

WardBenjamin commented 8 years ago

Hey Giawa,

Thanks for the help!

As far as gracefully handling references, I almost think it would be better to load each reference manually, an example of which is here. Essentially by doing this you could check for individual ARB or GL version requirements, like FNA does in that example.

If you'd like that to be added to this library, it's definitely an option that I could work towards. This could perhaps be done in a static constructor of one of the classes, so that it wouldn't have to be called manually by the user but would still definitely be called.

By the way, you can always join me in chat on gitter.im, which integrates with Github's account system. Just log in, and you can either message me or you can drop by the Flare.Framework room.

Thanks, Benjamin Ward

giawa commented 8 years ago

Hi Benjamin,

I'm not 100% sure how building something into the library will be useful. I'm not sure if there is a minimum subset of OpenGL functionality that would appeal to common users. It would definitely be possible to add something like FNA, but in their case they are targeting older OpenGL frameworks.

I would imagine several users would just end up re-writing their OpenGL checks to verify their application specific requirements. Let me know what you think though. I'm open to adding something, just not quite sure what that will be yet.

Giawa

WardBenjamin commented 8 years ago

Hey Giawa,

I would imagine several users would just end up re-writing their OpenGL checks to verify their application specific requirements.

That's exactly what I wanted to facilitate. Essentially, what would be implemented would be something like the following case, if you wanted to make sure the platform supported the 4.1 standard, for example.

Gl.CheckVersionAvailability(4, 1); // int major, int minor

or

Gl.CheckARBAvailability(ARB.VertexShader); // ARB enum

for checking for GL_ARB_vertex_shader being available.

This would completely prevent having to check for each function being available individually, and is probably a better solution than the one that I mentioned above. Also, this would be fantastic for developer use, since it enables them to do easily supported custom checks for versions, ARBs, etc. pre-game, before any obscure (to the end user) crashes happen due to functions not loading or being available.

For many of these, I envision something as simple as wrapping around Gl.GetVersion and similar functionality.

Benjamin Ward

giawa commented 8 years ago

Hey Benjamin,

I haven't forgotten about this request. I'm looking into a few different ways we can tackle it. It is tough, because this library is only dealing with OpenGL 4, so should we really verify any of the older functions exist? We can definitely add a:

Gl.CheckVersionAvailability(4, 1); // int major, int minor

but I'm trying to decide on how to best implement an ARB availability equivalent. If you have any thoughts on it definitely feel free to let me know. For now I am browsing the OpenGL man pages for a better understanding of how different functions are required by different ARB features.

Giawa

giawa commented 7 years ago

I've just committed some code that gets partway to detecting things like extensions. You can now query for extensions, with all of the extensions on the OpenGL manpages built-in for easy query. Here are two examples:

if (Gl.Extensions.TextureFilterAnisotropic_EXT)
{
   // initialize the texture manually with Anisotropy
}
if (Gl.IsExtensionSupported(Extension.GL_EXT_texture_filter_anisotropic))
{
   // initialize the texture manually with Anisotropy
}

Not 100% what you were looking for, but I think it's a step in the right direction. Let me know what you think.

giawa commented 7 years ago

Going to close this issue as I haven't received any feedback. I think detecting extensions is probably what WardBenjamin was looking for.