Browse Source

WebGLRenderer helpers are exposed to public API

Filipp Keks 5 years ago
parent
commit
511b249746
4 changed files with 73 additions and 19 deletions
  1. 8 0
      src/Three.d.ts
  2. 12 0
      src/Three.js
  3. 34 0
      src/renderers/WebGLRenderer.d.ts
  4. 19 19
      src/renderers/WebGLRenderer.js

+ 8 - 0
src/Three.d.ts

@@ -170,6 +170,14 @@ export * from './renderers/webgl/WebGLShadowMap';
 export * from './renderers/webgl/WebGLState';
 export * from './renderers/webgl/WebGLTextures';
 export * from './renderers/webgl/WebGLUniforms';
+export * from './renderers/webgl/WebGLUtils';
+export * from './renderers/webgl/WebGLMaterials';
+export * from './renderers/webgl/WebGLGeometries';
+export * from './renderers/webgl/WebGLAttributes';
+export * from './renderers/webgl/WebGLRenderStates';
+export * from './renderers/webgl/WebGLBackground';
+export * from './renderers/webgl/WebGLAnimation';
+export * from './renderers/webgl/WebGLMorphtargets';
 export * from './constants';
 export * from './Three.Legacy';
 

+ 12 - 0
src/Three.js

@@ -154,6 +154,18 @@ export { ImageUtils } from './extras/ImageUtils.js';
 export { ShapeUtils } from './extras/ShapeUtils.js';
 export { PMREMGenerator } from './extras/PMREMGenerator.js';
 export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
+export { WebGLMaterials } from './renderers/webgl/WebGLMaterials.js';
+export { WebGLPrograms } from './renderers/webgl/WebGLPrograms.js';
+export { WebGLObjects } from './renderers/webgl/WebGLObjects.js';
+export { WebGLGeometries } from './renderers/webgl/WebGLGeometries.js';
+export { WebGLAttributes } from './renderers/webgl/WebGLAttributes.js';
+export { WebGLTextures } from './renderers/webgl/WebGLTextures.js';
+export { WebGLRenderStates } from './renderers/webgl/WebGLRenderStates.js';
+export { WebGLBackground } from './renderers/webgl/WebGLBackground.js';
+export { WebGLBufferRenderer } from './renderers/webgl/WebGLBufferRenderer.js';
+export { WebGLIndexedBufferRenderer } from './renderers/webgl/WebGLIndexedBufferRenderer.js';
+export { WebGLAnimation } from './renderers/webgl/WebGLAnimation.js';
+export { WebGLMorphtargets } from './renderers/webgl/WebGLMorphtargets.js';
 export * from './constants.js';
 export * from './Three.Legacy.js';
 

+ 34 - 0
src/renderers/WebGLRenderer.d.ts

@@ -20,6 +20,19 @@ import { RenderTarget } from './webgl/WebGLRenderLists';
 import { Geometry } from './../core/Geometry';
 import { BufferGeometry } from './../core/BufferGeometry';
 import { Texture } from '../textures/Texture';
+import { WebGLMaterials } from './webgl/WebGLMaterials';
+import { WebGLPrograms } from './webgl/WebGLPrograms';
+import { WebGLObjects } from './webgl/WebGLObjects';
+import { WebGLGeometries } from './webgl/WebGLGeometries';
+import { WebGLAttributes } from './webgl/WebGLAttributes';
+import { WebGLTextures } from './webgl/WebGLTextures';
+import { WebGLRenderStates } from './webgl/WebGLRenderStates';
+import { WebGLBackground } from './webgl/WebGLBackground';
+import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer';
+import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer';
+import { WebGLUtils } from './webgl/WebGLUtils';
+import { WebGLAnimation } from './webgl/WebGLAnimation';
+import { WebGLMorphtargets } from './webgl/WebGLMorphtargets';
 
 export interface Renderer {
 	domElement: HTMLCanvasElement;
@@ -85,6 +98,27 @@ export interface WebGLRendererParameters {
 	 * default is false.
 	 */
 	logarithmicDepthBuffer?: boolean;
+
+	/**
+	 * Custom WebGLRenderer helpers, all null by default
+	 * Should be used for rendering pipeline customization
+	 */
+	textures?: WebGLTextures;
+	attributes?: WebGLAttributes;
+	geometries?: WebGLGeometries;
+	objects?: WebGLObjects;
+	programCache?: WebGLPrograms;
+	materials?: WebGLMaterials;
+	renderStates?: WebGLRenderStates;
+	background?: WebGLBackground;
+	bufferRenderer?: WebGLBufferRenderer;
+	indexedBufferRenderer?: WebGLIndexedBufferRenderer;
+	utils?: WebGLUtils;
+	renderLists?: WebGLRenderLists;
+	animation?: WebGLAnimation;
+	morphtargets?: WebGLMorphtargets;
+	shadowMap?: WebGLShadowMap;
+	xr?: WebXRManager;
 }
 
 export interface WebGLDebug {

+ 19 - 19
src/renderers/WebGLRenderer.js

@@ -268,28 +268,28 @@ function WebGLRenderer( parameters ) {
 
 		extensions.get( 'OES_texture_float_linear' );
 
-		utils = new WebGLUtils( _gl, extensions, capabilities );
+		utils = parameters.utils !== undefined ? parameters.utils : new WebGLUtils( _gl, extensions, capabilities );
 
-		state = new WebGLState( _gl, extensions, capabilities );
+		state = parameters.state !== undefined ? parameters.state : new WebGLState( _gl, extensions, capabilities );
 		state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
 		state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
 
-		info = new WebGLInfo( _gl );
-		properties = new WebGLProperties();
-		textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
-		attributes = new WebGLAttributes( _gl, capabilities );
-		geometries = new WebGLGeometries( _gl, attributes, info );
-		objects = new WebGLObjects( _gl, geometries, attributes, info );
-		morphtargets = new WebGLMorphtargets( _gl );
-		programCache = new WebGLPrograms( _this, extensions, capabilities );
-		materials = new WebGLMaterials();
-		renderLists = new WebGLRenderLists();
-		renderStates = new WebGLRenderStates();
+		info = parameters.info !== undefined ? parameters.info : new WebGLInfo( _gl );
+		properties = parameters.properties !== undefined ? parameters.properties : new WebGLProperties();
+		textures = parameters.textures !== undefined ? parameters.textures : new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
+		attributes = parameters.attributes !== undefined ? parameters.attributes : new WebGLAttributes( _gl, capabilities );
+		geometries = parameters.geometries !== undefined ? parameters.geometries : new WebGLGeometries( _gl, attributes, info );
+		objects = parameters.objects !== undefined ? parameters.objects : new WebGLObjects( _gl, geometries, attributes, info );
+		morphtargets = parameters.morphtargets !== undefined ? parameters.morphtargets : new WebGLMorphtargets( _gl );
+		programCache = parameters.programCache !== undefined ? parameters.programCache : new WebGLPrograms( _this, extensions, capabilities );
+		materials = parameters.materials !== undefined ? parameters.materials : new WebGLMaterials();
+		renderLists = parameters.renderLists !== undefined ? parameters.renderLists : new WebGLRenderLists();
+		renderStates = parameters.renderStates !== undefined ? parameters.renderStates : new WebGLRenderStates();
 
-		background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
+		background = parameters.background !== undefined ? parameters.background : new WebGLBackground( _this, state, objects, _premultipliedAlpha );
 
-		bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
-		indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
+		bufferRenderer = parameters.bufferRenderer !== undefined ? parameters.bufferRenderer : new WebGLBufferRenderer( _gl, extensions, info, capabilities );
+		indexedBufferRenderer = parameters.indexedBufferRenderer !== undefined ? parameters.indexedBufferRenderer : new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
 
 		info.programs = programCache.programs;
 
@@ -306,13 +306,13 @@ function WebGLRenderer( parameters ) {
 
 	// xr
 
-	var xr = new WebXRManager( _this, _gl );
+	var xr = parameters.xr !== undefined ? parameters.xr : new WebXRManager( _this, _gl );
 
 	this.xr = xr;
 
 	// shadow map
 
-	var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
+	var shadowMap = parameters.shadowMap !== undefined ? parameters.shadowMap : new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
 
 	this.shadowMap = shadowMap;
 
@@ -1100,7 +1100,7 @@ function WebGLRenderer( parameters ) {
 
 	}
 
-	var animation = new WebGLAnimation();
+	var animation = parameters.animation !== undefined ? parameters.animation : new WebGLAnimation();
 	animation.setAnimationLoop( onAnimationFrame );
 
 	if ( typeof window !== 'undefined' ) animation.setContext( window );