-
Notifications
You must be signed in to change notification settings - Fork 0
Code Design
There are a few general choices that serve as guidelines throughout the code
A shader doesn't need to be switched if it's already active. A uniform doesn't need to be set if it's the same value for the same shader. A vertex array object doesn't need to be activated if it is already.
By using local caches and maps to store references and value lookups, many WebGL calls can be avoided. The assumption is that it's cheaper to make these very fast lookups and comparisons every time, rather than sometimes upload to the GPU unnecessarily.
There are 3 very different kinds of data, and these are intentionally separated as much as possible in the pipeline.
- Assets.
This is loaded all at once, before anything else begins. The idea is to spend more time upfront parsing the files and loading network files, so that a preliminary loading screen can be shown before any processing begins.
- Render data.
Textures, attributes, and other render data is held in its own structure with maps and lambdas created as needed. This is created completely before the scene begins, so that everything is ready on the GPU.
- Scene data.
Scene data is fully serializable and lightweight. The concept is that it can be used in workers, wasm, or an immutable JS pipeline such as FRP without needing to be worried about cloning issues or dangling references. Typically, this is derived via the Bridge on startup, and then immutably updated from there on in.