|
@@ -23,6 +23,7 @@ import { Vector4 } from '../math/Vector4.js';
|
|
import { WebGLAnimation } from './webgl/WebGLAnimation.js';
|
|
import { WebGLAnimation } from './webgl/WebGLAnimation.js';
|
|
import { WebGLAttributes } from './webgl/WebGLAttributes.js';
|
|
import { WebGLAttributes } from './webgl/WebGLAttributes.js';
|
|
import { WebGLBackground } from './webgl/WebGLBackground.js';
|
|
import { WebGLBackground } from './webgl/WebGLBackground.js';
|
|
|
|
+import { WebGLBindingStates } from './webgl/WebGLBindingStates.js';
|
|
import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
|
|
import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
|
|
import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
|
|
import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
|
|
import { WebGLClipping } from './webgl/WebGLClipping.js';
|
|
import { WebGLClipping } from './webgl/WebGLClipping.js';
|
|
@@ -138,14 +139,6 @@ function WebGLRenderer( parameters ) {
|
|
_currentFramebuffer = null,
|
|
_currentFramebuffer = null,
|
|
_currentMaterialId = - 1,
|
|
_currentMaterialId = - 1,
|
|
|
|
|
|
- // geometry and program caching
|
|
|
|
-
|
|
|
|
- _currentGeometryProgram = {
|
|
|
|
- geometry: null,
|
|
|
|
- program: null,
|
|
|
|
- wireframe: false
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
_currentCamera = null,
|
|
_currentCamera = null,
|
|
_currentArrayCamera = null,
|
|
_currentArrayCamera = null,
|
|
|
|
|
|
@@ -248,7 +241,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
var background, morphtargets, bufferRenderer, indexedBufferRenderer;
|
|
var background, morphtargets, bufferRenderer, indexedBufferRenderer;
|
|
|
|
|
|
- var utils;
|
|
|
|
|
|
+ var utils, bindingStates;
|
|
|
|
|
|
function initGLContext() {
|
|
function initGLContext() {
|
|
|
|
|
|
@@ -264,6 +257,7 @@ function WebGLRenderer( parameters ) {
|
|
extensions.get( 'OES_texture_half_float_linear' );
|
|
extensions.get( 'OES_texture_half_float_linear' );
|
|
extensions.get( 'OES_standard_derivatives' );
|
|
extensions.get( 'OES_standard_derivatives' );
|
|
extensions.get( 'OES_element_index_uint' );
|
|
extensions.get( 'OES_element_index_uint' );
|
|
|
|
+ extensions.get( 'OES_vertex_array_object' );
|
|
extensions.get( 'ANGLE_instanced_arrays' );
|
|
extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -272,7 +266,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
utils = new WebGLUtils( _gl, extensions, capabilities );
|
|
utils = new WebGLUtils( _gl, extensions, capabilities );
|
|
|
|
|
|
- state = new WebGLState( _gl, extensions, utils, capabilities );
|
|
|
|
|
|
+ state = new WebGLState( _gl, extensions, utils );
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
|
|
|
@@ -280,10 +274,11 @@ function WebGLRenderer( parameters ) {
|
|
properties = new WebGLProperties();
|
|
properties = new WebGLProperties();
|
|
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
|
|
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
|
|
attributes = new WebGLAttributes( _gl );
|
|
attributes = new WebGLAttributes( _gl );
|
|
- geometries = new WebGLGeometries( _gl, attributes, info );
|
|
|
|
|
|
+ bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
|
|
|
|
+ geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
|
|
objects = new WebGLObjects( geometries, info );
|
|
objects = new WebGLObjects( geometries, info );
|
|
morphtargets = new WebGLMorphtargets( _gl );
|
|
morphtargets = new WebGLMorphtargets( _gl );
|
|
- programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
|
|
|
|
|
|
+ programCache = new WebGLPrograms( _this, extensions, capabilities, textures, bindingStates );
|
|
renderLists = new WebGLRenderLists();
|
|
renderLists = new WebGLRenderLists();
|
|
renderStates = new WebGLRenderStates();
|
|
renderStates = new WebGLRenderStates();
|
|
|
|
|
|
@@ -567,6 +562,7 @@ function WebGLRenderer( parameters ) {
|
|
renderStates.dispose();
|
|
renderStates.dispose();
|
|
properties.dispose();
|
|
properties.dispose();
|
|
objects.dispose();
|
|
objects.dispose();
|
|
|
|
+ bindingStates.dispose();
|
|
|
|
|
|
vr.dispose();
|
|
vr.dispose();
|
|
|
|
|
|
@@ -645,7 +641,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
this.renderBufferImmediate = function ( object, program ) {
|
|
this.renderBufferImmediate = function ( object, program ) {
|
|
|
|
|
|
- state.initAttributes();
|
|
|
|
|
|
+ bindingStates.initAttributes();
|
|
|
|
|
|
var buffers = properties.get( object );
|
|
var buffers = properties.get( object );
|
|
|
|
|
|
@@ -661,7 +657,7 @@ function WebGLRenderer( parameters ) {
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
|
|
|
|
|
|
- state.enableAttribute( programAttributes.position );
|
|
|
|
|
|
+ bindingStates.enableAttribute( programAttributes.position );
|
|
_gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
|
|
_gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -671,7 +667,7 @@ function WebGLRenderer( parameters ) {
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
|
|
|
|
|
|
- state.enableAttribute( programAttributes.normal );
|
|
|
|
|
|
+ bindingStates.enableAttribute( programAttributes.normal );
|
|
_gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
|
|
_gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -681,7 +677,7 @@ function WebGLRenderer( parameters ) {
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
|
|
|
|
|
|
- state.enableAttribute( programAttributes.uv );
|
|
|
|
|
|
+ bindingStates.enableAttribute( programAttributes.uv );
|
|
_gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
|
|
_gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -691,12 +687,12 @@ function WebGLRenderer( parameters ) {
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
|
|
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
|
|
_gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
|
|
|
|
|
|
- state.enableAttribute( programAttributes.color );
|
|
|
|
|
|
+ bindingStates.enableAttribute( programAttributes.color );
|
|
_gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
|
|
_gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- state.disableUnusedAttributes();
|
|
|
|
|
|
+ bindingStates.disableUnusedAttributes();
|
|
|
|
|
|
_gl.drawArrays( _gl.TRIANGLES, 0, object.count );
|
|
_gl.drawArrays( _gl.TRIANGLES, 0, object.count );
|
|
|
|
|
|
@@ -712,27 +708,6 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
var program = setProgram( camera, fog, material, object );
|
|
var program = setProgram( camera, fog, material, object );
|
|
|
|
|
|
- var updateBuffers = false;
|
|
|
|
-
|
|
|
|
- if ( _currentGeometryProgram.geometry !== geometry.id ||
|
|
|
|
- _currentGeometryProgram.program !== program.id ||
|
|
|
|
- _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
|
|
|
|
-
|
|
|
|
- _currentGeometryProgram.geometry = geometry.id;
|
|
|
|
- _currentGeometryProgram.program = program.id;
|
|
|
|
- _currentGeometryProgram.wireframe = material.wireframe === true;
|
|
|
|
- updateBuffers = true;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( object.morphTargetInfluences ) {
|
|
|
|
-
|
|
|
|
- morphtargets.update( object, geometry, material, program );
|
|
|
|
-
|
|
|
|
- updateBuffers = true;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
|
|
|
|
var index = geometry.index;
|
|
var index = geometry.index;
|
|
@@ -746,6 +721,14 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if ( object.morphTargetInfluences ) {
|
|
|
|
+
|
|
|
|
+ morphtargets.update( object, geometry, material, program );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bindingStates.setup( material, program, geometry, index );
|
|
|
|
+
|
|
var attribute;
|
|
var attribute;
|
|
var renderer = bufferRenderer;
|
|
var renderer = bufferRenderer;
|
|
|
|
|
|
@@ -758,18 +741,6 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( updateBuffers ) {
|
|
|
|
-
|
|
|
|
- setupVertexAttributes( material, program, geometry );
|
|
|
|
-
|
|
|
|
- if ( index !== null ) {
|
|
|
|
-
|
|
|
|
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
|
|
|
|
var dataCount = Infinity;
|
|
var dataCount = Infinity;
|
|
@@ -875,135 +846,6 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- function setupVertexAttributes( material, program, geometry ) {
|
|
|
|
-
|
|
|
|
- if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
|
|
|
|
-
|
|
|
|
- if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
|
|
|
|
-
|
|
|
|
- console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- state.initAttributes();
|
|
|
|
-
|
|
|
|
- var geometryAttributes = geometry.attributes;
|
|
|
|
-
|
|
|
|
- var programAttributes = program.getAttributes();
|
|
|
|
-
|
|
|
|
- var materialDefaultAttributeValues = material.defaultAttributeValues;
|
|
|
|
-
|
|
|
|
- for ( var name in programAttributes ) {
|
|
|
|
-
|
|
|
|
- var programAttribute = programAttributes[ name ];
|
|
|
|
-
|
|
|
|
- if ( programAttribute >= 0 ) {
|
|
|
|
-
|
|
|
|
- var geometryAttribute = geometryAttributes[ name ];
|
|
|
|
-
|
|
|
|
- if ( geometryAttribute !== undefined ) {
|
|
|
|
-
|
|
|
|
- var normalized = geometryAttribute.normalized;
|
|
|
|
- var size = geometryAttribute.itemSize;
|
|
|
|
-
|
|
|
|
- var attribute = attributes.get( geometryAttribute );
|
|
|
|
-
|
|
|
|
- // TODO Attribute may not be available on context restore
|
|
|
|
-
|
|
|
|
- if ( attribute === undefined ) continue;
|
|
|
|
-
|
|
|
|
- var buffer = attribute.buffer;
|
|
|
|
- var type = attribute.type;
|
|
|
|
- var bytesPerElement = attribute.bytesPerElement;
|
|
|
|
-
|
|
|
|
- if ( geometryAttribute.isInterleavedBufferAttribute ) {
|
|
|
|
-
|
|
|
|
- var data = geometryAttribute.data;
|
|
|
|
- var stride = data.stride;
|
|
|
|
- var offset = geometryAttribute.offset;
|
|
|
|
-
|
|
|
|
- if ( data && data.isInstancedInterleavedBuffer ) {
|
|
|
|
-
|
|
|
|
- state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
|
|
|
|
-
|
|
|
|
- if ( geometry.maxInstancedCount === undefined ) {
|
|
|
|
-
|
|
|
|
- geometry.maxInstancedCount = data.meshPerAttribute * data.count;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- state.enableAttribute( programAttribute );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
|
|
|
|
- _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- if ( geometryAttribute.isInstancedBufferAttribute ) {
|
|
|
|
-
|
|
|
|
- state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
|
|
|
|
-
|
|
|
|
- if ( geometry.maxInstancedCount === undefined ) {
|
|
|
|
-
|
|
|
|
- geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- state.enableAttribute( programAttribute );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
|
|
|
|
- _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else if ( materialDefaultAttributeValues !== undefined ) {
|
|
|
|
-
|
|
|
|
- var value = materialDefaultAttributeValues[ name ];
|
|
|
|
-
|
|
|
|
- if ( value !== undefined ) {
|
|
|
|
-
|
|
|
|
- switch ( value.length ) {
|
|
|
|
-
|
|
|
|
- case 2:
|
|
|
|
- _gl.vertexAttrib2fv( programAttribute, value );
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 3:
|
|
|
|
- _gl.vertexAttrib3fv( programAttribute, value );
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 4:
|
|
|
|
- _gl.vertexAttrib4fv( programAttribute, value );
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- default:
|
|
|
|
- _gl.vertexAttrib1fv( programAttribute, value );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- state.disableUnusedAttributes();
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// Compile
|
|
// Compile
|
|
|
|
|
|
this.compile = function ( scene, camera ) {
|
|
this.compile = function ( scene, camera ) {
|
|
@@ -1109,9 +951,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
// reset caching for this frame
|
|
// reset caching for this frame
|
|
|
|
|
|
- _currentGeometryProgram.geometry = null;
|
|
|
|
- _currentGeometryProgram.program = null;
|
|
|
|
- _currentGeometryProgram.wireframe = false;
|
|
|
|
|
|
+ bindingStates.resetDefaultState();
|
|
_currentMaterialId = - 1;
|
|
_currentMaterialId = - 1;
|
|
_currentCamera = null;
|
|
_currentCamera = null;
|
|
|
|
|
|
@@ -1430,9 +1270,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
var program = setProgram( camera, scene.fog, material, object );
|
|
var program = setProgram( camera, scene.fog, material, object );
|
|
|
|
|
|
- _currentGeometryProgram.geometry = null;
|
|
|
|
- _currentGeometryProgram.program = null;
|
|
|
|
- _currentGeometryProgram.wireframe = false;
|
|
|
|
|
|
+ bindingStates.reset();
|
|
|
|
|
|
renderObjectImmediate( object, program );
|
|
renderObjectImmediate( object, program );
|
|
|
|
|