Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global graphic contexts. Fix windows for js backend. #482

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

quantimnot
Copy link
Contributor

@quantimnot quantimnot commented Jun 4, 2021

I've been trying to get nimxapp and nimxedit to fully function for the js 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 and fonts.FontContext.
I then set the context to the window and ensured all views had their parent window initialized in their init 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 where View.window was being evaluated so I changed my approach.
I instead created a View.gfx property that was initialized early on each view. The graphics context is then passed into each func/proc/... where it is needed.

State:

  • example layout windows now work
  • some deserialization bugs

TODO:

  • debug editor deserialization (why aren't button faces rendered in the editor after my changes?)
  • debug why nothing created inside editor workspace on js backend
  • cleanup changes

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:

  • if this is a reasonable solution
  • concerns
  • suggestions

@quantimnot
Copy link
Contributor Author

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.

@yglukhov
Copy link
Owner

yglukhov commented Oct 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants