aaronwalsman / splendor-render

MIT License
4 stars 0 forks source link

Added OpenGL import wrapper for Mac support #23

Open fishbotics opened 3 years ago

fishbotics commented 3 years ago

This is just a pass-through wrapper for OpenGL to circumvent some of Apple's OpenGL weirdness. This should be fixed in future versions of Python and then we can maybe ditch this.

fishbotics commented 3 years ago

Oh, yeah that's a good idea. I think it's safe to do import * in this wrapper class as long as we explicitly call it out in other classes.

fishbotics commented 3 years ago

Which solution do you prefer?

aaronwalsman commented 3 years ago

Oooh, I just had an idea, let me test something real quick...

aaronwalsman commented 3 years ago

Ok, nevermind, my test didn't work. I was thinking that if we did the second thing we could still say from opengl_wrapper.OpenGL.GL import * in another script, but that doesn't work because opengl_wrapper isn't a "package"? Python is goofy. Anyway, with that being the case, I kind of like the first version (import ) because it means if everybody eventually gets their act together and makes it so this workaround isn't necessary anymore, it's easy to change things by just changing the imports. But then as soon as I say that I realize the same is true with the other version as well. Also, there is a downside to `import ` in that we might not want to do that for more than one module (do we need to do this for GLUT or EGL or anything else as well?) then we'd have to make separate wrappers for each. So after thinking about that, maybe the second option is better? Just do the wrapper for everything all at once, include them as variables inside the module that other modules can import, and the only downside is that you have to do gl.glWhatever instead of just saying glWhatever... I don't know... what's your take?

fishbotics commented 3 years ago

I think option 2 will be nicer. I'll update.

aaronwalsman commented 3 years ago

sounds good, thanks!

fishbotics commented 3 years ago

@aaronwalsman, you might want to clone this to make sure the EGL files work. I removed all those weird extraneous imports.

fishbotics commented 3 years ago

@aaronwalsman , I finished updating all of these calls. When you have a chance, can you checkout this branch and make sure things run on your desktop? It should just work, but we'll see I guess. I may have missed some imports.

aaronwalsman commented 3 years ago

Hey, sorry it took me a few days to get back to this. Unfortunately this breaks EGL. There are one, maybe two issues with the way it at the moment:

The first is that you can't import EGL until it's been loaded as a plugin (see the load_egl function at the beginning of buffer_manager_egl.py), but when you try to use your opengl_wrapper at the top of buffer_manager_egl (before load_egl has been called), it first tries to import EGL (inside opengl_wrapper) that doesn't work (because the plugin hasn't been loaded), which means EGL doesn't exist in the opengl_wrapper module for importing in buffer_manager_egl after load_egl has been run in buffer_manager_egl.

At first glance, the quick fix solution would be to put the load_egl function inside opengl_wrapper, but when I did this, it broke GLUT. It seems like these two things end up fighting each other for control. It might be possible to make them live side-by-side, but honestly I don't think we need or even want to. Regardless of whether or not it can happen, we never really want to do this. A script using renderpy should always only do one or the other, not both (GLUT if you want an interactive window and some number of off screen frame buffers, EGL if you are on a headless server and only want off screen frame buffers because GLUT breaks on headless servers).

I think the solution is to take GLUT and EGL out of the opengl_wrapper entirely. Then we make two separate things for importing GLUT and EGL separately, possibly as their own wrappers if that's still necessary for mac.

aaronwalsman commented 3 years ago

I have some updates that may help us get this back on track. The context managers (glut and egl) are separate modules now and can both be imported into the same other script. There is still the limitation that you can't actually USE them both at once, but at least you can import them. This is resolved by adding initialize methods that update a stateful module. If you run glut.initialize() it will register glut as being the thing in control, so that if you run egl.initialize after that it will throw an error. Hopefully this setup can get us around some of the issues we experienced here.