Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
WebGLRenderer modularization experiment #6782
There has been a lot of talk on breaking up the renderer into smaller components, but I have not seen a lot of details on how to accomplish this refactoring.
Would this PR be a pattern you would consider?
I've only limited myself to transforming four small parts of the renderer. In case you find the diff too unruly, I suggest that you take a look at the more digestible individual commits.
In any case, here is an overview of the approach.
Instead of a monolithic renderer, the logic is broken down into smaller functions. The prototypes of the renderable objects (material, lights, etc) are extended with these functions. Implementation details are pushed into the objects, which become responsible to update the gl state. The renderer is just the orchestrator.
This is similar to how the
One large switch block like this:
is replaced by this single line dispatch:
To clarity, objects are extended with static "pure" functions.
Not data (like the old
No new state is carried by the object.