Răsfoiți Sursa

WebGLRenderer: Simplified copyFramebufferToTexture().

Mr.doob 7 ani în urmă
părinte
comite
67192d4081

+ 1 - 1
docs/api/renderers/WebGLRenderer.html

@@ -315,7 +315,7 @@
 		<h3>[method:null compile]( [page:Scene scene], [page:Camera camera] )</h3>
 		<div>Compiles all materials in the scene with the camera. This is useful to precompile shaders before the first rendering.</div>
 
-		<h3>[method:null copyFramebufferToTexture]( [page:Number x], [page:Number y], [page:Texture texture], [page:Number level] )</h3>
+		<h3>[method:null copyFramebufferToTexture]( [page:Vector2 position], [page:Texture texture], [page:Number level] )</h3>
 		<div>Copies pixels from the current WebGLFramebuffer into a 2D texture. Enables access to [link:https://developer.mozilla.org/de/docs/Web/API/WebGLRenderingContext/copyTexImage2D WebGLRenderingContext.copyTexImage2D].</div>
 
 		<h3>[method:null dispose]( )</h3>

+ 2 - 2
examples/js/objects/LensFlare.js

@@ -84,7 +84,7 @@ THREE.LensFlare = function () {
 
 			// save current RGB to temp texture
 
-			renderer.copyFramebufferToTexture( screenPositionPixels.x, screenPositionPixels.y, tempMap );
+			renderer.copyFramebufferToTexture( screenPositionPixels, tempMap );
 
 			// render pink quad
 
@@ -97,7 +97,7 @@ THREE.LensFlare = function () {
 
 			// copy result to occlusionMap
 
-			renderer.copyFramebufferToTexture( screenPositionPixels.x, screenPositionPixels.y, occlusionMap );
+			renderer.copyFramebufferToTexture( screenPositionPixels, occlusionMap );
 
 			// restore graphics
 

+ 8 - 9
examples/webgl_framebuffer_texture.html

@@ -75,6 +75,7 @@
 			var dpr = window.devicePixelRatio;
 
 			var textureSize = 128 * dpr;
+			var vector = new THREE.Vector2();
 
 			init();
 			animate();
@@ -114,13 +115,11 @@
 
 				//
 
-				var canvas = document.createElement( 'canvas' );
-				canvas.width = textureSize;
-				canvas.height = textureSize;
+				var data = new Uint8Array( textureSize * textureSize * 3 );
 
-				texture = new THREE.CanvasTexture( canvas );
-				texture.format = THREE.RGBFormat;
-				texture.minFilter = texture.magFilter = THREE.NearestFilter;
+				texture = new THREE.DataTexture( data, textureSize, textureSize, THREE.RGBFormat );
+				texture.minFilter = THREE.NearestFilter;
+				texture.magFilter = THREE.NearestFilter;
 				texture.needsUpdate = true;
 
 				//
@@ -196,10 +195,10 @@
 
 				// calculate start position for copying data
 
-				var x = ( window.innerWidth * dpr / 2 ) - ( textureSize / 2 );
-				var y = ( window.innerHeight * dpr / 2 ) - ( textureSize / 2 );
+				vector.x = ( window.innerWidth * dpr / 2 ) - ( textureSize / 2 );
+				vector.y = ( window.innerHeight * dpr / 2 ) - ( textureSize / 2 );
 
-				renderer.copyFramebufferToTexture( x, y, texture );
+				renderer.copyFramebufferToTexture( vector, texture );
 
 				renderer.clearDepth();
 				renderer.render( sceneOrtho, cameraOrtho );

+ 2 - 2
src/renderers/WebGLRenderer.js

@@ -2566,7 +2566,7 @@ function WebGLRenderer( parameters ) {
 
 	};
 
-	this.copyFramebufferToTexture = function ( x, y, texture, level ) {
+	this.copyFramebufferToTexture = function ( position, texture, level ) {
 
 		var width = texture.image.width;
 		var height = texture.image.height;
@@ -2574,7 +2574,7 @@ function WebGLRenderer( parameters ) {
 
 		this.setTexture2D( texture, 0 );
 
-		_gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, internalFormat, x, y, width, height, 0 );
+		_gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, internalFormat, position.x, position.y, width, height, 0 );
 
 	};