浏览代码

Merge pull request #17747 from elalish/dev

fixed copyFramebufferToTexture
Mr.doob 5 年之前
父节点
当前提交
33ebb86aca
共有 2 个文件被更改,包括 27 次插入3 次删除
  1. 21 0
      src/renderers/WebGLRenderer.d.ts
  2. 6 3
      src/renderers/WebGLRenderer.js

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

@@ -19,6 +19,7 @@ import { WebVRManager } from '../renderers/webvr/WebVRManager';
 import { RenderTarget } from './webgl/WebGLRenderLists';
 import { Geometry } from './../core/Geometry';
 import { BufferGeometry } from './../core/BufferGeometry';
+import { Texture } from '../textures/Texture';
 
 export interface Renderer {
 	domElement: HTMLCanvasElement;
@@ -396,6 +397,26 @@ export class WebGLRenderer implements Renderer {
 		activeCubeFaceIndex?: number
 	): void;
 
+	/**
+	 * Copies a region of the currently bound framebuffer into the selected mipmap level of the selected texture.
+	 * This region is defined by the size of the destination texture's mip level, offset by the input position.
+	 *
+	 * @param position Specifies the pixel offset from which to copy out of the framebuffer.
+	 * @param texture Specifies the destination texture.
+	 * @param level Specifies the destination mipmap level of the texture.
+	 */
+	copyFramebufferToTexture( position: Vector2, texture: Texture, level?: number ): void;
+
+	/**
+	 * Copies srcTexture to the specified level of dstTexture, offset by the input position.
+	 *
+	 * @param position Specifies the pixel offset into the dstTexture where the copy will occur.
+	 * @param srcTexture Specifies the source texture.
+	 * @param dstTexture Specifies the destination texture.
+	 * @param level Specifies the destination mipmap level of the texture.
+	 */
+	copyTextureToTexture( position: Vector2, srcTexture: Texture, dstTexture: Texture, level?: number ): void;
+
 	/**
 	 * @deprecated
 	 */

+ 6 - 3
src/renderers/WebGLRenderer.js

@@ -2719,13 +2719,16 @@ function WebGLRenderer( parameters ) {
 
 	this.copyFramebufferToTexture = function ( position, texture, level ) {
 
-		var width = texture.image.width;
-		var height = texture.image.height;
+		if ( level === undefined ) level = 0;
+
+		var levelScale = Math.pow( 2, - level );
+		var width = Math.floor( texture.image.width * levelScale );
+		var height = Math.floor( texture.image.height * levelScale );
 		var glFormat = utils.convert( texture.format );
 
 		textures.setTexture2D( texture, 0 );
 
-		_gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, glFormat, position.x, position.y, width, height, 0 );
+		_gl.copyTexImage2D( _gl.TEXTURE_2D, level, glFormat, position.x, position.y, width, height, 0 );
 
 	};