瀏覽代碼

WebGLState: Added .scissor() and .viewport().

Mr.doob 9 年之前
父節點
當前提交
4a149fbe35
共有 1 個文件被更改,包括 27 次插入0 次删除
  1. 27 0
      src/renderers/webgl/WebGLState.js

+ 27 - 0
src/renderers/webgl/WebGLState.js

@@ -41,6 +41,9 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 	var currentTextureSlot = undefined;
 	var currentTextureSlot = undefined;
 	var currentBoundTextures = {};
 	var currentBoundTextures = {};
 
 
+	var currentScissor = new THREE.Rectangle();
+	var currentViewport = new THREE.Rectangle();
+
 	this.init = function () {
 	this.init = function () {
 
 
 		gl.clearColor( 0, 0, 0, 1 );
 		gl.clearColor( 0, 0, 0, 1 );
@@ -509,6 +512,30 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
 
 
 	//
 	//
 
 
+	this.scissor = function ( scissor ) {
+
+		if ( currentScissor.equals( scissor ) === false ) {
+
+			gl.scissor( scissor.x, scissor.y, scissor.width, scissor.height );
+			currentScissor.copy( scissor );
+
+		}
+
+	};
+
+	this.viewport = function ( viewport ) {
+
+		if ( currentViewport.equals( viewport ) === false ) {
+
+			gl.viewport( viewport.x, viewport.y, viewport.width, viewport.height );
+			currentViewport.copy( viewport );
+
+		}
+
+	};
+
+	//
+
 	this.reset = function () {
 	this.reset = function () {
 
 
 		for ( var i = 0; i < enabledAttributes.length; i ++ ) {
 		for ( var i = 0; i < enabledAttributes.length; i ++ ) {