Asynchronous texture creation for smoother render loop
Reported by lindsay.kay (at xeolabs) | May 14th, 2010 @ 12:55 AM | in V0.7.5
Problem
Texture creations happen in batches within scene traversal, stalling the renderer.
Reason
In V0.7.4, image load is asynchronous, while texture creation is done within scene traversal. This was deemed necessary for accurate monitoring of processes in scene graphs between traversals, which is no longer considered important.
In V0.7.4, texture creation a two-step process: when first visited, a SceneJS.Texture is in INITIAL state and so starts it's asynchronous image load and enters IMAGE_LOADING state. When that completes, which may or may not be within a traversal, the node enters IMAGE_LOADED. Then on a subsequent traversal SceneJS finds the node in IMAGE_LOADED and immediately begins creating it's texture right then, stalling the scene traversal while that happens, then the node enters TEXTURE_CREATED. Then on another subsequent traversal, SceneJS finds the node in that state and applies its texture. Node is in ERROR state as soon as image load or texture creation fails.
The effect is that bigs scenes freeze while textures are created - after all their images have loaded, more or less simultaneously, their texture creations have effectively queued up to be done mostly within the same scene traversal.
Solution
Collapse node's states to four: INITIAL, LOADING, LOADED, ERROR. Node starts in INITIAL, from there starting image load and entering LOADING. When image load completes, it immediately creates it's texture within the Image.onload callback, which is asynchronous with regard to scene traversal, then enters LOADED. When a scene traversal finds the node in LOADED, it then applies the texture.
Result
The result is scenes that appear piece-by-piece while textures load.
Comments and changes to this ticket
-
lindsay.kay (at xeolabs) May 14th, 2010 @ 02:25 AM
- Tag set to scenejs.texture
- State changed from new to resolved
There is still some clunkiness because the fastest strategy turned out to be to ensure that the complete set of layers are loaded before applying any of them. There would be a huge performance penalty if we were to apply the incomplete set as layers are still loading - SceneJS would then have to generate a new shader for each new layer loaded, which would become redundant as soon as the next layer is loaded.
The latter gave some smoothness but at the cost of at least 2X slower overall time taken before scene graph stabilised into final state with all geometries and shaders created and loaded.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
SceneJS provides easy access to WebGL through a simple and declarative JavaScript API. The SceneJS API is functional, which enables its scene definitions to be really compact and expressive, while hooking into other JavaScript code just that little bit more smoothly.