Skip to content

Code Design

David Komer edited this page May 22, 2018 · 2 revisions

There are a few general choices that serve as guidelines throughout the code

Prefer local cache lookups over WebGL calls

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.

GLTF - different kinds of data

There are 3 very different kinds of data, and these are intentionally separated as much as possible in the pipeline.

  1. 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.

  1. 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.

  1. 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.

Clone this wiki locally