Heya everyone :)

I decided to make my own lightweight DLL to grant me access to certain OpenGL extension functions (such as glBindBuffer).
Attached is source, binary and lib.

This LIB / DLL provides "transparent" access to certain OpenGL extension functions, such that your sourcecode can invoke them without any changes (it doesn't need to know that these functions are not normally available).

The DLL exports some stub functions which call the OpenGL extension function of the same name for you.
The idea is that by linking to my Lib in your sourcecode, you can invoke these 'missing' functions via their regular names.

BUILDTIME: To use this in builds, just the GLADD .inc and .lib in your sourcecode, along with your usual opengl includes.
RUNTIME: After you have obtained a valid OpenGL Render Context (hRC), call my "Thanks_Homer" function to initialize the GLADD module. If you fail to do this, your code will crash when you try to call the other exported functions (ie the function pointers will be NULL until you pay homage to me ;)).

The DLL will have to be present at runtime for your executable to work, but hey its open sourced, rip/modify it to suit yourself and rename it whatever you want.

Only a handful of functions have been implemented, but more can be added.



Attachments:
Posted on 2010-06-25 03:30:25 by Homer
That's nice. Don't think I've seen an extension library aimed at assembly programmers before.
One idea I have though:
What if you make a stub function for each unloaded extension? I think it can be done with a macro.
Something like:
glBindBuffers dd MYSTUB(glBindBuffers)

And the MYSTUB macro then generates something like this code:
call Thanks_Homer
call glBindBuffers
ret

The result is that the first unloaded extension will trigger the loading of all extensions automatically. After that, the stub pointers are overwritten with the direct proc address, so Thanks_Homer is only called once, no extra cost.
Posted on 2010-06-25 06:04:27 by Scali
The DLL is not truly required - its possible to do what you suggest within the main sourcecode.
I tried a few macros without much success - I'm not great with MASM macros.
So I got lazy and wrote the DLL.
And the DLL is pretty crappy too.
The function stubs should have the prolog/epilog disabled and so the PUSHES can be removed for all stubs.
Perhaps if people begin using this thing I'll make improvements to it, but I was impatient, I wanted instant gratification.

Posted on 2010-06-25 08:51:33 by Homer
Yea, I suppose alternatively you could also do something like this:
glBindBuffers dd MYSTUB("glBindBuffers")

So that the macro generates the proper code to wglGetProcAddress() for that particular function, and replace that one function pointer with the function address on the furst call.

I've found that gluX does some pretty nifty stuff to automate all this. There's a set of scripts which scrape the extension information and function names from the online OpenGL extension registry, and then automatically generate all the sourcecode. So it can auto-generate itself, basically, and remain up-to-date.
Posted on 2010-06-25 09:50:55 by Scali