Browse Source

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

Mr.doob 9 years ago
parent
commit
4a149fbe35
1 changed files with 27 additions and 0 deletions
  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 currentBoundTextures = {};
 
+	var currentScissor = new THREE.Rectangle();
+	var currentViewport = new THREE.Rectangle();
+
 	this.init = function () {
 
 		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 () {
 
 		for ( var i = 0; i < enabledAttributes.length; i ++ ) {