luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.
MIT License
570 stars 109 forks source link

Restrict API to a particular version #39

Closed vinodkhare closed 7 years ago

vinodkhare commented 7 years ago

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?

luca-piccioni commented 7 years ago

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

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?

luca-piccioni commented 7 years ago

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

vinodkhare commented 7 years ago

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.

luca-piccioni commented 7 years ago

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.

luca-piccioni commented 7 years ago

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

wolfgangmauer commented 7 years ago

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?

luca-piccioni commented 7 years ago

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

wolfgangmauer commented 7 years ago

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?!

luca-piccioni commented 7 years ago

I run samples on RPi and Android. It shoild detect EGL automatically. Try to set Egl.IsRequired to true, and it will work.

Il lun 24 apr 2017, 14:16 wolfgangmauer notifications@github.com ha scritto:

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?!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/luca-piccioni/OpenGL.Net/issues/39#issuecomment-296643310, or mute the thread https://github.com/notifications/unsubscribe-auth/AEe6CW843uDgoTlE7TvffGwqKQoA5eerks5rzJKKgaJpZM4M9_r8 .

wolfgangmauer commented 7 years ago

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)); } }

luca-piccioni commented 7 years ago

I'll check this tonight. In the meanwhile, you should undestand that there are two kind of loaders: OS and GL.

OS loaders are used for loading platform pointers (and on linux it means using dlsym). This kind of loaders are returned by GetProcAddressOS.

GL procedures are loaded using a separate API, returned with GetProcAddressGL. This kind of loader depends on the platform API.

Indeed, you need dlsym for loading EGL procedures, and eglProcAddress for loading GL procedures.

Il lun 24 apr 2017, 14:31 wolfgangmauer notifications@github.com ha scritto:

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)); } }

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/luca-piccioni/OpenGL.Net/issues/39#issuecomment-296648962, or mute the thread https://github.com/notifications/unsubscribe-auth/AEe6CUa1A5GA69mEuZHEISv-dEiwlZIwks5rzJYMgaJpZM4M9_r8 .

luca-piccioni commented 7 years ago

FYI you should read the static constructor of Egl class, since probably the EGL library is cannot be found by the code.

Il lun 24 apr 2017, 14:44 Luca Piccioni luca.piccioni@gmail.com ha scritto:

I'll check this tonight. In the meanwhile, you should undestand that there are two kind of loaders: OS and GL.

OS loaders are used for loading platform pointers (and on linux it means using dlsym). This kind of loaders are returned by GetProcAddressOS.

GL procedures are loaded using a separate API, returned with GetProcAddressGL. This kind of loader depends on the platform API.

Indeed, you need dlsym for loading EGL procedures, and eglProcAddress for loading GL procedures.

Il lun 24 apr 2017, 14:31 wolfgangmauer notifications@github.com ha scritto:

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)); } }

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/luca-piccioni/OpenGL.Net/issues/39#issuecomment-296648962, or mute the thread https://github.com/notifications/unsubscribe-auth/AEe6CUa1A5GA69mEuZHEISv-dEiwlZIwks5rzJYMgaJpZM4M9_r8 .

wolfgangmauer commented 7 years ago

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.

luca-piccioni commented 7 years ago

Evidently, since I've run on Linuxes having GL.so I always been able to run without issues (my Rpi has X11 installed).

The solution would be to avoid loading GL.so, or masking the exception if reasonable. I wonder where and why it's tryong to use GL.so even once it has found EGL platform. 😤

Il lun 24 apr 2017, 15:51 wolfgangmauer notifications@github.com ha scritto:

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.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/luca-piccioni/OpenGL.Net/issues/39#issuecomment-296674696, or mute the thread https://github.com/notifications/unsubscribe-auth/AEe6CU6NOv6eSnDa7OinwIBtJ-_tLs8kks5rzKjTgaJpZM4M9_r8 .

wolfgangmauer commented 7 years ago

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

luca-piccioni commented 7 years ago

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