Open quantimnot opened 3 years ago
Hey @yglukhov, I got side-tracked coming up with a CI for testing each target platform. I would like to contribute more to your project. Do you have any feedback about the core of this PR? I don't want to spend time on it if you're not interested. The core of this PR is to stop using global variables. I can refactor Rod too.
Hey @quantimnot, thanks for your interest in this. Your PR made me spend some time on researching the topic, and sadly this is a problem indeed. Unfortunately I don't see a good solution to this. Not only does it make the API more complex, but it introduces lots of additional questions e.g. resource management. Take a nimx.Image
for instance. It implicitly and lazily manages a texture, created in the default (and single one) context. What if we want to draw an Image
(or vertex buffer or any other resource) in the context it wasn't created in? Such ability would require to either (a) redesign image api from the ground up, so that the user is always aware of the Image's context, or (b) to add more logic for the image to have ability to belong to multiple contexts under the hood, which sounds pretty involved.
So my biggest concern is that a lot of effort has to be taken, likely a lot of API broken, for the possibility to support multiple webgl contexts, which feels like little gain to me. Maybe it's better for nimx to support only one webgl context, I think it would be a more reasonable limitation.
I've been trying to get
nimxapp
andnimxedit
to fully function for thejs
backend. While debugging the layout examples I learned the graphics context was globally shared and that is not supported by the webgl spec.This pull request is a possible solution.
I consolidated relative global variables into
context.GraphicsContext
andfonts.FontContext
. I then set the context to the window and ensured all views had their parent window initialized in theirinit
method. But then I learned that the initialization state of a view's window property was being used elsewhere and my changes broke that. I didn't understand the code well enough to alter whereView.window
was being evaluated so I changed my approach. I instead created aView.gfx
property that was initialized early on each view. The graphics context is then passed into each func/proc/... where it is needed.State:
TODO:
I've only been testing the js and sdl backends. The others may not currently work.
Please give it a try and let me know: