File size: 1,687 Bytes
b797337 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import { WebGLLights } from './WebGLLights.js';
function WebGLRenderState( extensions, capabilities ) {
const lights = new WebGLLights( extensions, capabilities );
const lightsArray = [];
const shadowsArray = [];
function init() {
lightsArray.length = 0;
shadowsArray.length = 0;
}
function pushLight( light ) {
lightsArray.push( light );
}
function pushShadow( shadowLight ) {
shadowsArray.push( shadowLight );
}
function setupLights( useLegacyLights ) {
lights.setup( lightsArray, useLegacyLights );
}
function setupLightsView( camera ) {
lights.setupView( lightsArray, camera );
}
const state = {
lightsArray: lightsArray,
shadowsArray: shadowsArray,
lights: lights
};
return {
init: init,
state: state,
setupLights: setupLights,
setupLightsView: setupLightsView,
pushLight: pushLight,
pushShadow: pushShadow
};
}
function WebGLRenderStates( extensions, capabilities ) {
let renderStates = new WeakMap();
function get( scene, renderCallDepth = 0 ) {
const renderStateArray = renderStates.get( scene );
let renderState;
if ( renderStateArray === undefined ) {
renderState = new WebGLRenderState( extensions, capabilities );
renderStates.set( scene, [ renderState ] );
} else {
if ( renderCallDepth >= renderStateArray.length ) {
renderState = new WebGLRenderState( extensions, capabilities );
renderStateArray.push( renderState );
} else {
renderState = renderStateArray[ renderCallDepth ];
}
}
return renderState;
}
function dispose() {
renderStates = new WeakMap();
}
return {
get: get,
dispose: dispose
};
}
export { WebGLRenderStates };
|