Browse Source

WebGLRenderer: Introduce resetState().

Mugen87 4 years ago
parent
commit
0486b09e04

+ 3 - 0
docs/api/en/renderers/WebGLRenderer.html

@@ -428,6 +428,9 @@
 		Renders an instance of [page:ImmediateRenderObject]. Gets called by renderObjectImmediate().
 		</p>
 
+		<h3>[method:null resetState]()</h3>
+		<p>Can be used to reset the internal WebGL state. This method is mostly relevant for applications which share a single WebGL context across multiple WebGL libraries.</p>
+
 		<h3>[method:null setAnimationLoop]( [param:Function callback] )</h3>
 		<p>[page:Function callback] — The function will be called every available frame. If `null` is passed it will stop any already ongoing animation.</p>
 		<p>A built in function that can be used instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]. For WebXR projects this function must be used.</p>

+ 3 - 0
docs/api/zh/renderers/WebGLRenderer.html

@@ -385,6 +385,9 @@
 		Renders an instance of [page:ImmediateRenderObject],由renderObjectImmediate对象调用。
 		</p>
 
+		<h3>[method:null resetState]()</h3>
+		<p>Can be used to reset the internal WebGL state. This method is mostly relevant for applications which share a single WebGL context across multiple WebGL libraries.</p>
+
 		<h3>[method:null setAnimationLoop]( [param:Function callback] )</h3>
 		<p>[page:Function callback] — 每个可用帧都会调用的函数。 如果传入‘null’,所有正在进行的动画都会停止。</p>
 		<p>可用来代替[link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]的内置函数. 对于WebXR项目,必须使用此函数。</p>

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

@@ -449,6 +449,11 @@ export class WebGLRenderer implements Renderer {
 	 */
 	initTexture( texture: Texture ): void;
 
+	/**
+	 * Can be used to reset the internal WebGL state.
+	 */
+	resetState(): void;
+
 	/**
 	 * @deprecated
 	 */

+ 7 - 0
src/renderers/WebGLRenderer.js

@@ -1993,6 +1993,13 @@ function WebGLRenderer( parameters ) {
 
 	};
 
+	this.resetState = function () {
+
+		state.reset();
+		bindingStates.reset();
+
+	};
+
 	if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
 
 		__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef