luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restrict API to a particular version

vinodkhare opened this issue · comments

Is there a way to restrict the API to use a particular OpenGL version? For example, I want to develop using only OpenGL ES 2. How can I make sure that only OpenGL ES 2 functions are available?

I've already considered to solve this issue to reduce the size of the executable. The options that comes in my mind:

  • Separate projects including only the necessary sources for a specific environment? This options requires compatible source code (features shouldn't be mixed in a single source file), but OpenGL ES converges to OpenGL, indeed this option is not practicable.
  • Compile-time checks? The only option I found is the ObsoleteAttribute, but I've already tried it for compatibility profile functions/constants, and I find it quite dirty (just removed al attributes). However, it requires conditional compilation for each configuration (GL, GL ES, GL ES2, GL SC?, GL SC2?). And the sources compiles and executes anyway.
  • Run-time checks? Uhm... just like compiler-time checks, but with performance penalty... No.
  • Separated tool that strip all symbols not required for a specific set of features (even extensions?), using IL generators? Not sure if possible, but I like this path: elegant and efficient. There are all attributes for processing IL; users can customize releases using the original one.

Or maybe all above is over-engineered: Gl.BindApi() should reset the function pointers depending on the current context. However, nobody can grant a GLES2-only implementation: probably the same library contains GLES functions that would be loaded anyway. Indeed a fast & effective solution could be a modified function-loader module that uses field attributes for excluding those function that cannot be implemented by the context; but this is detectable only at run-time, and constants are not excluded.

Indeed? IL generator?

Yes, it seems possible using Mono.Cecil: very useful tool. I'll work on it and I'll let you know.

Hmm, I'm not familiar enough with the project to comment on how it can be achieved from a technical point of view.

From a functional point of view, I was imagining something like this - different OpenGL versions are split into different namespaces. For example, namespace GLES2 contains all the OpenGL ES 2 functions. This would be quite enough for my use case.

This may not be the best way to refactor your library... just brainstorming here.

Sadly, this option would increase the binary size, and make more difficult to have common code for OpenGL and OpenGL ES (which is one of my "requirements").

I've already tested ES2-only library against the HelloTriangle.ANGLE example, and it works pretty well. The only remaining thing is the removal of enumeration fields.

Just uploaded nuget package. Tell me what you think about; feedbacks are welcome.

I have a Linux STB(VuDuo2) only Framebuffer no X11, and i try to use OpenGL.
The Box have a mips BCM7424 CPU, but no OpenSource...
I have libGLES2 but no X11, so the "Initialize" run into "GetProcAddressX11" and like to load "libGL.so.1" and use a "glxGetProcAddress" with are not present.
Is there a way to solve this?

Probably it does not detect any EGL library. Any chance to find a libEGL.so?

Yes the EGL library is present, in source i just change the "glxGetProcAddress" to "eglGetProcAddress"
and the
private const string Library = "libGL.so.1"
to
private const string Library = "libGLESv2.so";
and it seems to work.
So if Linux is not fix assumed to have X11, it will be running on every other non X11/RPI machine?!

I have...
As i described Linux and no X11!
If you take a look....
What i need is (CurrentPlatformId=Linux && GetProcAddress=GetProcAddressEgl)

private static IGetProcAddress CreateOS()
{
switch (Platform.CurrentPlatformId) {
case Platform.Id.WindowsNT:
return new GetProcAddressWindows();
case Platform.Id.Linux:
return new GetProcAddressX11();
case Platform.Id.MacOS:
return new GetProcAddressOSX();
case Platform.Id.Android:
return new GetProcAddressEgl();
default:
throw new NotSupportedException(String.Format("platform {0} not supported", Platform.CurrentPlatformId));
}
}

Sorry, but all GLES2/EGL libraries are found!
The exception is like "cannot find libGL.so.1" and that's right, because i don't have it.

I think i write a libGL.so witch maps the "glxGetProcAddress" to "eglGetProcAddress" ....

Ok, I got it. I'll fix it soon, checking on my RPi. In the meanwhile, your solution is a valid workaround, but to make it correct you should define glXGetProcAddress returning always IntPtr.Zero.

P.s: maybe next time create an issue about