From d1ce80c9f83c5232156cfe4cdfcb240e2bf90297 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Fri, 5 Jan 2018 20:20:33 +0100 Subject: [PATCH] WebGLRenderer: Added .copyFramebufferToTexture() --- build/three.js | 12 ++ docs/api/renderers/WebGLRenderer.html | 5 +- examples/webgl_framebuffer_texture.html | 209 ++++++++++++++++++++++++ src/renderers/WebGLRenderer.js | 12 ++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 examples/webgl_framebuffer_texture.html diff --git a/build/three.js b/build/three.js index 233c93ecc8..e55cda55d2 100644 --- a/build/three.js +++ b/build/three.js @@ -23764,6 +23764,18 @@ }; + this.copyFramebufferToTexture = function ( x, y, texture, level ) { + + var width = texture.image.width; + var height = texture.image.height; + var internalFormat = utils.convert( texture.format ); + + this.setTexture2D( texture, 0 ); + + _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, internalFormat, x, y, width, height, 0 ); + + }; + } /** diff --git a/docs/api/renderers/WebGLRenderer.html b/docs/api/renderers/WebGLRenderer.html index b11c40054a..79ca8770af 100644 --- a/docs/api/renderers/WebGLRenderer.html +++ b/docs/api/renderers/WebGLRenderer.html @@ -52,7 +52,7 @@ [page:Boolean preserveDrawingBuffer] - whether to preserve the buffers until manually cleared or overwritten. Default is *false*.
- + [page:String powerPreference] - Provides a hint to the user agent indicating what configuration of GPU is suitable for this WebGL context. Can be *"high-performance"*, *"low-power"* or *"default"*. Default is *"default"*.
@@ -324,6 +324,9 @@

[method:null compile]( [page:Scene scene], [page:Camera camera] )

Compiles all materials in the scene with the camera. This is useful to precompile shaders before the first rendering.
+

[method:null copyFramebufferToTexture]( [page:Number x], [page:Number y], [page:Texture texture], [page:Number level] )

+
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].
+

[method:null dispose]( )

Dispose of the current rendering context.
diff --git a/examples/webgl_framebuffer_texture.html b/examples/webgl_framebuffer_texture.html new file mode 100644 index 0000000000..4809ef5176 --- /dev/null +++ b/examples/webgl_framebuffer_texture.html @@ -0,0 +1,209 @@ + + + + three.js webgl - framebuffer - texture + + + + + + + + + + + +
+
+ three.js framebuffer to texture
+ The area of the white square is copied from the framebuffer to a texture (shown in the top-left corner). +
+ +
+
+
+
+ + + + + diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 2fcc08e6f2..427f3e6e14 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2559,6 +2559,18 @@ function WebGLRenderer( parameters ) { }; + this.copyFramebufferToTexture = function ( x, y, texture, level ) { + + var width = texture.image.width; + var height = texture.image.height; + var internalFormat = utils.convert( texture.format ); + + this.setTexture2D( texture, 0 ); + + _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, internalFormat, x, y, width, height, 0 ); + + }; + } -- GitLab