Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Asynchronous texture creation for smoother render loop

#76

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.

Reported by lindsay.kay (at xeolabs) · May 14th, 2010 @ 12:55 AM

State: resolved
Milestone: V0.7.5

Activity

  1. lindsay.kay (at xeolabs)
    lindsay.kay (at xeolabs)
    • 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.

    May 14th, 2010 @ 02:25 AM

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.