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

WebGL mode refactor #7355

Merged
merged 9 commits into from
Nov 4, 2024
Merged

WebGL mode refactor #7355

merged 9 commits into from
Nov 4, 2024

Conversation

davepagurek
Copy link
Contributor

@davepagurek davepagurek commented Nov 3, 2024

Resolves #7030

My plan here is to refactor how WebGL mode is structured to make it more understandable to contributors and to reduce duplication. At a high level:

  • All RendererGL methods should be in one file. Things split out into different files should be self-contained pieces, similar to the existing GeometryBuilder class
  • Consolidate immediate/retained mode as much as possible. Already, both draw using p5.Geometry, they just have different methods for creating and storing geometry, so those systems should be factored out, leaving common rendering code
  • Have shader and geometry properties' locations more clearly defined. Right now it could be in one of a number of locations, depending on what the renderer is doing.

Specific changes and progress so far:

  • Consolidate logic for drawing a p5.Geometry into one spot; currently it has a lot of duplication between immediate and retained mode
  • Factor shape building out of immediate mode and into a contained ShapeBuilder class
  • Factor out retained more into a geometry cache manager
  • Clean up buffer cache management:
    • Use a single set of buffers for retained/immediate modes
    • Rename retainedMode.geometry to be more descriptive: this is what stores the WebGL buffer references, not the geometry itself
    • Clean up storage locations for WebGL buffers: for retained mode it goes on retainedMode.geometry[gid]; for immediate mode it just gets dumped right on the immediate mode's p5.Geometry. These should be handled the same way
    • Make consistent the usage of cached buffer lengths vs accessing data array lengths
  • Clean up shader management: currently, half the uniforms are set via p5.Shader, and half are set via p5.RendererGL
  • Pass around p5.Geometry everywhere instead of accessing the cache directly via the gid property
    • Refactor most internal functions to accept geometry
    • Update 3D primitives to pass in geometry instead of accessing cache

@davepagurek
Copy link
Contributor Author

One other side thing I want to do: now that tests are run in a browser window, I'd really like it if the tests didn't download files 😅

@davepagurek davepagurek marked this pull request as ready for review November 3, 2024 18:09
@davepagurek
Copy link
Contributor Author

Ok, done all the refactors I wanted!

This is definitely going to make rebasing webgl changes from main very annoying, but I think this structure for the code makes more sense and will help with the 2D filter runner.

@limzykenneth
Copy link
Member

Looks good to me, feel free to merge whenever.

@davepagurek davepagurek merged commit 8909e1b into dev-2.0 Nov 4, 2024
2 checks passed
@davepagurek davepagurek deleted the webgl-refactor branch November 4, 2024 18:20
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