浏览代码

Refactored WebGLRendererDebug into a separate object

Took 30 minutes
Alex Goldring 6 年之前
父节点
当前提交
b2790d5263

+ 2 - 6
docs/api/en/renderers/WebGLRenderer.html

@@ -92,13 +92,9 @@
 			Default is *true*.
 		</p>
 
-		<h3>[property:Boolean programCheckEnabled]</h3>
+		<h3>[property:WebGLRendererDebug debug]</h3>
 		<p>
-			If [page:.programCheckEnabled programCheckEnabled] is true, defines whether material shader programs are checked
-			for errors during compilation and linkage process. It may be useful to disable this check in production for performance gain.
-			It is strongly recommended to keep these checks enabled during development.
-			If the shader does not compile and link - it will not work and associated material will not render.
-			Default is *true*.
+			Contains debug configuration of the renderer
 		</p>
 
 		<h3>[property:Object capabilities]</h3>

+ 33 - 0
docs/api/en/renderers/WebGLRendererDebug.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8"/>
+		<base href="../../../"/>
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css"/>
+	</head>
+	<body>
+		<h1>[name]</h1>
+
+		<p class="desc">
+			The debug configuration container for WebGLRenderer
+		</p>
+
+
+		<h2>Properties</h2>
+
+		<h3>[property:Boolean checkShaderErrors]</h3>
+		<p>
+			If [page:.checkShaderErrors checkShaderErrors] is true, defines whether material shader programs are checked
+			for errors during compilation and linkage process. It may be useful to disable this check in production for performance gain.
+			It is strongly recommended to keep these checks enabled during development.
+			If the shader does not compile and link - it will not work and associated material will not render.
+			Default is *true*.
+		</p>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 2 - 6
docs/api/zh/renderers/WebGLRenderer.html

@@ -79,13 +79,9 @@
 			默认是*true*
 		</p>
 
-		<h3>[property:Boolean programCheckEnabled]</h3>
+		<h3>[property:WebGLRendererDebug debug]</h3>
 		<p>
-			如果[page:.programCheckEnabled programCheckEnabled]为true,定义是否检查材质着色器程序
-			编译和链接过程中的错误。 禁用此检查生产以获得性能增益可能很有用。
-			强烈建议在开发期间保持启用这些检查。
-			如果着色器没有编译和链接 - 它将无法工作,并且相关材料将不会呈现。
-			默认是*true*
+			包含渲染器的调试配置。
 		</p>
 
 		<h3>[property:Object capabilities]</h3>

+ 34 - 0
docs/api/zh/renderers/WebGLRendererDebug.html

@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8"/>
+		<base href="../../../"/>
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css"/>
+	</head>
+	<body>
+		<h1>[name]</h1>
+
+		<p class="desc">
+			The debug configuration container for WebGLRenderer
+		</p>
+
+
+		<h2>Properties</h2>
+
+		<h3>[property:Boolean checkShaderErrors]</h3>
+		<p>
+
+			如果[page:.checkShaderErrors checkShaderErrors]为true,定义是否检查材质着色器程序
+			编译和链接过程中的错误。 禁用此检查生产以获得性能增益可能很有用。
+			强烈建议在开发期间保持启用这些检查。
+			如果着色器没有编译和链接 - 它将无法工作,并且相关材料将不会呈现。
+			默认是*true*
+		</p>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 2 - 5
src/renderers/WebGLRenderer.js

@@ -36,6 +36,7 @@ import { WebGLPrograms } from './webgl/WebGLPrograms.js';
 import { WebGLProperties } from './webgl/WebGLProperties.js';
 import { WebGLRenderLists } from './webgl/WebGLRenderLists.js';
 import { WebGLRenderStates } from './webgl/WebGLRenderStates.js';
+import { WebGLRendererDebug } from "./WebGLRendererDebug.js";
 import { WebGLShadowMap } from './webgl/WebGLShadowMap.js';
 import { WebGLState } from './webgl/WebGLState.js';
 import { WebGLTextures } from './webgl/WebGLTextures.js';
@@ -77,11 +78,7 @@ function WebGLRenderer( parameters ) {
 	this.domElement = _canvas;
 	this.context = null;
 
-	/**
-	 * Enables error checking and reporting when shader programs are being compiled
-	 * @type {boolean}
-	 */
-	this.programCheckEnabled = true;
+	this.debug = new WebGLRendererDebug();
 
 	// clearing
 

+ 15 - 0
src/renderers/WebGLRendererDebug.js

@@ -0,0 +1,15 @@
+/**
+ * @author Alex Goldring | https://github.com/Usnul
+ */
+
+function WebGLRendererDebug() {
+
+	/**
+	 * Enables error checking and reporting when shader programs are being compiled
+	 * @type {boolean}
+	 */
+	this.checkShaderErrors = true;
+
+}
+
+export { WebGLRendererDebug };

+ 4 - 4
src/renderers/webgl/WebGLProgram.js

@@ -583,8 +583,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 	// console.log( '*VERTEX*', vertexGlsl );
 	// console.log( '*FRAGMENT*', fragmentGlsl );
 
-	var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl, renderer.programCheckEnabled );
-	var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl, renderer.programCheckEnabled );
+	var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl, renderer.debug.checkShaderErrors );
+	var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl, renderer.debug.checkShaderErrors );
 
 	gl.attachShader( program, glVertexShader );
 	gl.attachShader( program, glFragmentShader );
@@ -604,8 +604,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
 
 	gl.linkProgram( program );
 
-	if ( renderer.programCheckEnabled ){
-		// check for link errors
+	// check for link errors
+	if ( renderer.debug.checkShaderErrors ) {
 
 		var programLog = gl.getProgramInfoLog( program ).trim();
 		var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();

+ 1 - 1
src/renderers/webgl/WebGLShader.d.ts

@@ -1,3 +1,3 @@
 export class WebGLShader {
-  constructor(gl: any, type: string, string: string, checkProgram: boolean);
+  constructor(gl: any, type: string, string: string, debug: boolean);
 }

+ 2 - 2
src/renderers/webgl/WebGLShader.js

@@ -16,14 +16,14 @@ function addLineNumbers( string ) {
 
 }
 
-function WebGLShader( gl, type, string, checkProgram ) {
+function WebGLShader( gl, type, string, debug ) {
 
 	var shader = gl.createShader( type );
 
 	gl.shaderSource( shader, string );
 	gl.compileShader( shader );
 
-	if ( checkProgram === true ) {
+	if ( debug === true ) {
 
 		if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {