c# wglGetProcAdress and OpenGL extensions

Actually it’s not windows specific anymore. There exists C# compilers for linux and even a .NET linux framework. I forget what it’s called and even how they did it , but it’s nice to see that a .NET application can run on more than just windows now.

-SirKnight

Well finally, decided to make a DLL with C to load the NVidia extensions like NV_vertex_array_range2, wglWllocateMemory… perhaps c# is not prepared to manage correctly wglGetProcAddress.

You were fairly close…

First of all, I’m highly suspect of anyone who goes off and starts yet another .NET binding. There’s already way too many and none of them offer anything that hasn’t already been done before. CsGL, while it has some oddities is much further along than the others… The latest instance of CsGL, which is called Tao and is produced and hosted by me corrects the issues that’ve plagued CsGL for a number of versions… It’d be much more productive if people contributed rather than starting anew, but to each his own…

The most simple solution to extensions and the one I’m using is to define a custom attribute that contains the IL to invoke the extension. On the post-process compilation event it’s trivial to have a utility parse out the IL and inject it into your assembly. No need for external assemblies, no need for unmanaged code. I’m already doing the post-processing step to inject cdecl delegate calls as that too is something not supported by c#, but is supported by IL, so to me, this is the most trivial solution. Other options would be to use Reflection.Emit to inject the IL at runtime, but to me that’s extraneous… Obviously you could also use an unmanaged or managed component to do the work.

Anywho, stay tuned for the next release of Tao.

I guess I should reply to the rest of the thread as well… The solution I mentioned is of course IL and not C# and would require a post-processing step to inject the IL into your assembly. I agree it’d be nice if you could do it in C# or using inline IL, but neither is available. This doesn’t mean that it can’t be done in a managed fashion as it is supported by IL. So it’s somewhat of an extraneous step, but it can be completely automated and it won’t affect your deployment (e.g. you can just modify your own assembly). I guess I should give a little example:

[CustomIL IL="
ldarg.1 // push foo
ldarg.0 // push extensionPointer
calli unmanaged stdcall void(float32)
ret
"]
public static void glFogCoordfEXT(IntPtr extensionPointer, Single foo) {}

So your application call would look something like:
glFogCoordfEXT(wglGetProcAddress(“glFogCoordfEXT”), 1.0f);

You’d likely want to cache the extension’s pointer however…

That’s off the top of my head, so please excuse… So, the CustomIL attribute is parsed post-build, the IL is injected into the appropriate method for me automagically using an external utility. It’s the closest thing we’ve got to inline IL with the exception of Reflection.Emit…

I’ve yet to find any need to rely on unmanaged components outside of what’s being wrapped. In CsGL there is an unmanaged component that does a number of things, including invoking extensions. If I recall correctly, Lloyd’s parser parsed the extension headers to write the c# that invoked the unmanaged component. In the case of Tao there are no extraneous unmanaged components, everything’s either in C# using P/Invoke, or in the cases of extensions and cdecl delegates injected IL that’s put in by a post-build utility.

In the Whidbey release, IL will be able to be compiled into your assembly, making this ‘hack’ a non-issue. I don’t believe it’ll be inline IL, but you will be able to combine IL compiled with ILASM into your assembly. Hopefully they’ll add cdecl delegates too and that would completely get rid of my post-build event.

Mono is the main alternative .NET platform. Tao has been reported to run under linux (mono), freebsd (mono), and windows (microsoft and mono) using the same code. In these cases the programs were GLUT based, it would be fairly trivial to add GLX support, but I don’t run either linux or freebsd, so it’s not real high on my priority list.

I think that covers about everything…

[This message has been edited by Ridge (edited 06-12-2003).]

[This message has been edited by Ridge (edited 06-12-2003).]

Oh, thx! i´ll try that.