diff --git a/docs/api/en/renderers/WebGLMultisampleRenderTarget.html b/docs/api/en/renderers/WebGLMultisampleRenderTarget.html
deleted file mode 100644
index c7274dfce60bff..00000000000000
--- a/docs/api/en/renderers/WebGLMultisampleRenderTarget.html
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
- [page:WebGLRenderTarget] →
-
- [name]
-
-
- A special render target that can be used to utilize multi-sampled renderbuffers.
- Heads up: [name] can only be used with a WebGL 2 rendering context.
-
-
- Examples
-
-
- [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ]
-
-
- Constructor
-
-
- [name]([param:Number width], [param:Number height], [param:Object options])
-
-
- [page:Float width] - The width of the render target.
- [page:Float height] - The height of the render target.
- [page:Object options] - (optional) object that holds texture parameters for an auto-generated target
- texture and depthBuffer/stencilBuffer booleans.
-
-
- Properties
-
- [property:number samples]
-
- Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported
- size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*.
-
-
- [page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.
-
- Methods
-
- [page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.
-
- Source
-
-
- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
-
-
-
diff --git a/docs/api/en/renderers/WebGLRenderTarget.html b/docs/api/en/renderers/WebGLRenderTarget.html
index 7f264688672929..823721c8e183c6 100644
--- a/docs/api/en/renderers/WebGLRenderTarget.html
+++ b/docs/api/en/renderers/WebGLRenderTarget.html
@@ -93,6 +93,10 @@ [property:DepthTexture depthTexture]
If set, the scene depth will be rendered to this texture. Default is null.
+ [property:Number samples]
+
+ Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*.
+
Methods
diff --git a/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html b/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html
deleted file mode 100644
index 974ced3690800e..00000000000000
--- a/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
- [page:WebGLRenderTarget] →
-
- [name]
-
-
- A special render target that can be used to utilize multi-sampled renderbuffers.
- Heads up: [name] can only be used with a WebGL 2 rendering context.
-
-
- Examples
-
-
- [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ]
-
-
- Constructor
-
-
- [name]([param:Number width], [param:Number height], [param:Object options])
-
-
- [page:Float width] - The width of the render target.
- [page:Float height] - The height of the render target.
- [page:Object options] - (optional) object that holds texture parameters for an auto-generated target
- texture and depthBuffer/stencilBuffer booleans.
-
-
- Properties
-
- [property:number samples]
-
- Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported
- size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*.
-
-
- [page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.
-
- Methods
-
- [page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.
-
- Source
-
-
- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
-
-
-
diff --git a/docs/api/zh/renderers/WebGLRenderTarget.html b/docs/api/zh/renderers/WebGLRenderTarget.html
index 072a5efe405acb..d124d812ffd65a 100644
--- a/docs/api/zh/renderers/WebGLRenderTarget.html
+++ b/docs/api/zh/renderers/WebGLRenderTarget.html
@@ -89,6 +89,10 @@ [property:DepthTexture depthTexture]
如果设置,那么场景的深度将会被渲染到此纹理上。默认为null
+ [property:Number samples]
+
+ Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*.
+
方法
diff --git a/docs/list.json b/docs/list.json
index f799758761f637..78eb448f68d5f4 100644
--- a/docs/list.json
+++ b/docs/list.json
@@ -283,7 +283,6 @@
"Renderers": {
"WebGLMultipleRenderTargets": "api/en/renderers/WebGLMultipleRenderTargets",
- "WebGLMultisampleRenderTarget": "api/en/renderers/WebGLMultisampleRenderTarget",
"WebGLRenderer": "api/en/renderers/WebGLRenderer",
"WebGL1Renderer": "api/en/renderers/WebGL1Renderer",
"WebGLRenderTarget": "api/en/renderers/WebGLRenderTarget",
@@ -783,7 +782,6 @@
"渲染器": {
"WebGLMultipleRenderTargets": "api/zh/renderers/WebGLMultipleRenderTargets",
- "WebGLMultisampleRenderTarget": "api/zh/renderers/WebGLMultisampleRenderTarget",
"WebGLRenderer": "api/zh/renderers/WebGLRenderer",
"WebGL1Renderer": "api/zh/renderers/WebGL1Renderer",
"WebGLRenderTarget": "api/zh/renderers/WebGLRenderTarget",
diff --git a/examples/jsm/objects/Reflector.js b/examples/jsm/objects/Reflector.js
index b11d7dd3536fc1..0f4a918754a3d8 100644
--- a/examples/jsm/objects/Reflector.js
+++ b/examples/jsm/objects/Reflector.js
@@ -8,8 +8,7 @@ import {
UniformsUtils,
Vector3,
Vector4,
- WebGLRenderTarget,
- WebGLMultisampleRenderTarget
+ WebGLRenderTarget
} from 'three';
class Reflector extends Mesh {
@@ -27,7 +26,7 @@ class Reflector extends Mesh {
const textureHeight = options.textureHeight || 512;
const clipBias = options.clipBias || 0;
const shader = options.shader || Reflector.ReflectorShader;
- const multisample = options.multisample || 4;
+ const multisample = ( options.multisample !== undefined ) ? options.multisample : 4;
//
@@ -46,18 +45,7 @@ class Reflector extends Mesh {
const textureMatrix = new Matrix4();
const virtualCamera = new PerspectiveCamera();
- let renderTarget;
-
- if ( multisample > 0 ) {
-
- renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight );
- renderTarget.samples = multisample;
-
- } else {
-
- renderTarget = new WebGLRenderTarget( textureWidth, textureHeight );
-
- }
+ const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } );
const material = new ShaderMaterial( {
uniforms: UniformsUtils.clone( shader.uniforms ),
diff --git a/examples/jsm/objects/Refractor.js b/examples/jsm/objects/Refractor.js
index 3c10d84caec905..edb0d1606247a4 100644
--- a/examples/jsm/objects/Refractor.js
+++ b/examples/jsm/objects/Refractor.js
@@ -9,8 +9,7 @@ import {
UniformsUtils,
Vector3,
Vector4,
- WebGLRenderTarget,
- WebGLMultisampleRenderTarget
+ WebGLRenderTarget
} from 'three';
class Refractor extends Mesh {
@@ -28,7 +27,7 @@ class Refractor extends Mesh {
const textureHeight = options.textureHeight || 512;
const clipBias = options.clipBias || 0;
const shader = options.shader || Refractor.RefractorShader;
- const multisample = options.multisample || 4;
+ const multisample = ( options.multisample !== undefined ) ? options.multisample : 4;
//
@@ -43,18 +42,7 @@ class Refractor extends Mesh {
// render target
- let renderTarget;
-
- if ( multisample > 0 ) {
-
- renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight );
- renderTarget.samples = multisample;
-
- } else {
-
- renderTarget = new WebGLRenderTarget( textureWidth, textureHeight );
-
- }
+ const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } );
// material
diff --git a/examples/webgl2_multisampled_renderbuffers.html b/examples/webgl2_multisampled_renderbuffers.html
index 208c510d99f5b5..698e680a374864 100644
--- a/examples/webgl2_multisampled_renderbuffers.html
+++ b/examples/webgl2_multisampled_renderbuffers.html
@@ -127,7 +127,7 @@
//
const size = renderer.getDrawingBufferSize( new THREE.Vector2() );
- const renderTarget = new THREE.WebGLMultisampleRenderTarget( size.width, size.height );
+ const renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, { samples: 4 } );
const renderPass = new RenderPass( scene, camera );
const copyPass = new ShaderPass( CopyShader );
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js
index 69ea7487eba24d..7786bdfc243214 100644
--- a/src/Three.Legacy.js
+++ b/src/Three.Legacy.js
@@ -1975,3 +1975,12 @@ export function ImmediateRenderObject() {
console.error( 'THREE.ImmediateRenderObject has been removed.' );
}
+
+export function WebGLMultisampleRenderTarget( width, height, options ) {
+
+ console.error( 'THREE.WebGLMultisampleRenderTarget has been removed. Use a normal render target and set the "samples" property to greater 0 to enable multisampling.' );
+ const renderTarget = new WebGLRenderTarget( width, height, options );
+ renderTarget.samples = 4;
+ return renderTarget;
+
+}
diff --git a/src/Three.js b/src/Three.js
index 4f0f85adcfad8d..f173015554ae93 100644
--- a/src/Three.js
+++ b/src/Three.js
@@ -1,7 +1,6 @@
import { REVISION } from './constants.js';
export { WebGLMultipleRenderTargets } from './renderers/WebGLMultipleRenderTargets.js';
-export { WebGLMultisampleRenderTarget } from './renderers/WebGLMultisampleRenderTarget.js';
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
export { WebGLRenderer } from './renderers/WebGLRenderer.js';
diff --git a/src/renderers/WebGLMultisampleRenderTarget.js b/src/renderers/WebGLMultisampleRenderTarget.js
deleted file mode 100644
index 0d08ab6c1945cd..00000000000000
--- a/src/renderers/WebGLMultisampleRenderTarget.js
+++ /dev/null
@@ -1,33 +0,0 @@
-import { WebGLRenderTarget } from './WebGLRenderTarget.js';
-
-class WebGLMultisampleRenderTarget extends WebGLRenderTarget {
-
- constructor( width, height, options = {} ) {
-
- super( width, height, options );
-
- this.samples = 4;
-
- this.ignoreDepthForMultisampleCopy = options.ignoreDepth !== undefined ? options.ignoreDepth : true;
- this.useRenderToTexture = ( options.useRenderToTexture !== undefined ) ? options.useRenderToTexture : false;
- this.useRenderbuffer = this.useRenderToTexture === false;
-
- }
-
- copy( source ) {
-
- super.copy.call( this, source );
-
- this.samples = source.samples;
- this.useRenderToTexture = source.useRenderToTexture;
- this.useRenderbuffer = source.useRenderbuffer;
-
- return this;
-
- }
-
-}
-
-WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
-
-export { WebGLMultisampleRenderTarget };
diff --git a/src/renderers/WebGLRenderTarget.js b/src/renderers/WebGLRenderTarget.js
index 62552e07905ed8..bbd21965b62127 100644
--- a/src/renderers/WebGLRenderTarget.js
+++ b/src/renderers/WebGLRenderTarget.js
@@ -37,6 +37,8 @@ class WebGLRenderTarget extends EventDispatcher {
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
+ this.samples = options.samples !== undefined ? options.samples : 0;
+
}
setTexture( texture ) {
@@ -97,6 +99,8 @@ class WebGLRenderTarget extends EventDispatcher {
if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
+ this.samples = source.samples;
+
return this;
}
diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js
index e3e2ca37734910..7ab8c5284112f9 100644
--- a/src/renderers/WebGLRenderer.js
+++ b/src/renderers/WebGLRenderer.js
@@ -31,7 +31,6 @@ import { WebGLGeometries } from './webgl/WebGLGeometries.js';
import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
import { WebGLInfo } from './webgl/WebGLInfo.js';
import { WebGLMorphtargets } from './webgl/WebGLMorphtargets.js';
-import { WebGLMultisampleRenderTarget } from './WebGLMultisampleRenderTarget.js';
import { WebGLObjects } from './webgl/WebGLObjects.js';
import { WebGLPrograms } from './webgl/WebGLPrograms.js';
import { WebGLProperties } from './webgl/WebGLProperties.js';
@@ -1189,13 +1188,11 @@ function WebGLRenderer( parameters = {} ) {
if ( _transmissionRenderTarget === null ) {
- const renderTargetType = ( isWebGL2 && _antialias === true ) ? WebGLMultisampleRenderTarget : WebGLRenderTarget;
-
- _transmissionRenderTarget = new renderTargetType( 1, 1, {
+ _transmissionRenderTarget = new WebGLRenderTarget( 1, 1, {
generateMipmaps: true,
- type: HalfFloatType,
+ type: utils.convert( HalfFloatType ) !== null ? HalfFloatType : UnsignedByteType,
minFilter: LinearMipmapLinearFilter,
- useRenderToTexture: extensions.has( 'WEBGL_multisampled_render_to_texture' )
+ samples: ( isWebGL2 && _antialias === true ) ? 4 : 0
} );
}
@@ -1797,7 +1794,7 @@ function WebGLRenderer( parameters = {} ) {
// The multisample_render_to_texture extension doesn't work properly if there
// are midframe flushes and an external depth buffer. Disable use of the extension.
- if ( renderTarget.useRenderToTexture ) {
+ if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
renderTarget.useRenderToTexture = false;
@@ -1870,7 +1867,7 @@ function WebGLRenderer( parameters = {} ) {
framebuffer = __webglFramebuffer[ activeCubeFace ];
isCube = true;
- } else if ( renderTarget.useRenderbuffer ) {
+ } else if ( ( capabilities.isWebGL2 && renderTarget.samples > 0 ) && textures.useMultisampledRenderToTexture( renderTarget ) === false ) {
framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
diff --git a/src/renderers/webgl/WebGLTextures.js b/src/renderers/webgl/WebGLTextures.js
index c54fd559d3e062..340428b4b5bc95 100644
--- a/src/renderers/webgl/WebGLTextures.js
+++ b/src/renderers/webgl/WebGLTextures.js
@@ -10,8 +10,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const maxCubemapSize = capabilities.maxCubemapSize;
const maxTextureSize = capabilities.maxTextureSize;
const maxSamples = capabilities.maxSamples;
- const hasMultisampledRenderToTexture = extensions.has( 'WEBGL_multisampled_render_to_texture' );
- const MultisampledRenderToTextureExtension = hasMultisampledRenderToTexture ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : undefined;
+ const MultisampledRenderToTextureExtension = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;
const _videoTextures = new WeakMap();
let _canvas;
@@ -1233,7 +1232,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
- if ( renderTarget.useRenderToTexture ) {
+
+ if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
@@ -1257,7 +1257,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
let glInternalFormat = _gl.DEPTH_COMPONENT16;
- if ( isMultisample || renderTarget.useRenderToTexture ) {
+ if ( isMultisample || useMultisampledRenderToTexture( renderTarget ) ) {
const depthTexture = renderTarget.depthTexture;
@@ -1277,7 +1277,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const samples = getRenderTargetSamples( renderTarget );
- if ( renderTarget.useRenderToTexture ) {
+ if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
@@ -1299,11 +1299,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const samples = getRenderTargetSamples( renderTarget );
- if ( isMultisample && renderTarget.useRenderbuffer ) {
+ if ( isMultisample && useMultisampledRenderToTexture( renderTarget ) === false ) {
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
- } else if ( renderTarget.useRenderToTexture ) {
+ } else if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
@@ -1326,11 +1326,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
const samples = getRenderTargetSamples( renderTarget );
- if ( isMultisample && renderTarget.useRenderbuffer ) {
+ if ( isMultisample && useMultisampledRenderToTexture( renderTarget ) === false ) {
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
- } else if ( renderTarget.useRenderToTexture ) {
+ } else if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
@@ -1378,7 +1378,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( renderTarget.depthTexture.format === DepthFormat ) {
- if ( renderTarget.useRenderToTexture ) {
+ if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
@@ -1390,7 +1390,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
- if ( renderTarget.useRenderToTexture ) {
+ if ( useMultisampledRenderToTexture( renderTarget ) ) {
MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
@@ -1537,41 +1537,32 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
- } else if ( renderTarget.useRenderbuffer ) {
-
- if ( isWebGL2 ) {
-
- renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
- renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
-
- _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
-
- const glFormat = utils.convert( texture.format, texture.encoding );
- const glType = utils.convert( texture.type );
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
- const samples = getRenderTargetSamples( renderTarget );
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
-
- state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
- _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
- _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
+ } else if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRenderToTexture( renderTarget ) === false ) {
- if ( renderTarget.depthBuffer ) {
+ renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
+ renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
- renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
- setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
+ _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
- }
-
- state.bindFramebuffer( _gl.FRAMEBUFFER, null );
+ const glFormat = utils.convert( texture.format, texture.encoding );
+ const glType = utils.convert( texture.type );
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
+ const samples = getRenderTargetSamples( renderTarget );
+ _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
+ state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
+ _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
- } else {
+ if ( renderTarget.depthBuffer ) {
- console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
+ renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
+ setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
}
+ state.bindFramebuffer( _gl.FRAMEBUFFER, null );
+
}
}
@@ -1692,61 +1683,61 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateMultisampleRenderTarget( renderTarget ) {
- if ( renderTarget.useRenderbuffer ) {
-
- if ( isWebGL2 ) {
+ if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRenderToTexture( renderTarget ) === false ) {
- const width = renderTarget.width;
- const height = renderTarget.height;
- let mask = _gl.COLOR_BUFFER_BIT;
- const invalidationArray = [ _gl.COLOR_ATTACHMENT0 ];
- const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
+ const width = renderTarget.width;
+ const height = renderTarget.height;
+ let mask = _gl.COLOR_BUFFER_BIT;
+ const invalidationArray = [ _gl.COLOR_ATTACHMENT0 ];
+ const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
- if ( renderTarget.depthBuffer ) {
+ if ( renderTarget.depthBuffer ) {
- invalidationArray.push( depthStyle );
+ invalidationArray.push( depthStyle );
- }
+ }
- if ( ! renderTarget.ignoreDepthForMultisampleCopy ) {
+ const renderTargetProperties = properties.get( renderTarget );
+ const ignoreDepthValues = ( renderTargetProperties.__ignoreDepthValues !== undefined ) ? renderTargetProperties.__ignoreDepthValues : true;
- if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;
- if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;
+ if ( ignoreDepthValues === false ) {
- }
+ if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;
+ if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;
- const renderTargetProperties = properties.get( renderTarget );
+ }
- state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
- state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
- if ( renderTarget.ignoreDepthForMultisampleCopy ) {
+ if ( ignoreDepthValues === true ) {
- _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, [ depthStyle ] );
- _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] );
+ _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, [ depthStyle ] );
+ _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] );
- }
+ }
- _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST );
- _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArray );
+ _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST );
+ _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArray );
- state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
- state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
- } else {
+ }
- console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
+ }
- }
+ function getRenderTargetSamples( renderTarget ) {
- }
+ return Math.min( maxSamples, renderTarget.samples );
}
- function getRenderTargetSamples( renderTarget ) {
+ function useMultisampledRenderToTexture( renderTarget ) {
+
+ const renderTargetProperties = properties.get( renderTarget );
- return ( isWebGL2 && ( renderTarget.useRenderbuffer || renderTarget.useRenderToTexture ) ) ?
- Math.min( maxSamples, renderTarget.samples ) : 0;
+ return isWebGL2 && renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false;
}
@@ -1883,6 +1874,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
this.setupDepthRenderbuffer = setupDepthRenderbuffer;
this.setupFrameBufferTexture = setupFrameBufferTexture;
+ this.useMultisampledRenderToTexture = useMultisampledRenderToTexture;
this.safeSetTexture2D = safeSetTexture2D;
this.safeSetTextureCube = safeSetTextureCube;
diff --git a/src/renderers/webxr/WebXRManager.js b/src/renderers/webxr/WebXRManager.js
index 53c6ca7d82825a..04df05d6ad443e 100644
--- a/src/renderers/webxr/WebXRManager.js
+++ b/src/renderers/webxr/WebXRManager.js
@@ -7,7 +7,6 @@ import { WebGLAnimation } from '../webgl/WebGLAnimation.js';
import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
import { WebXRController } from './WebXRController.js';
import { DepthTexture } from '../../textures/DepthTexture.js';
-import { WebGLMultisampleRenderTarget } from '../WebGLMultisampleRenderTarget.js';
import {
DepthFormat,
DepthStencilFormat,
@@ -31,13 +30,11 @@ class WebXRManager extends EventDispatcher {
let referenceSpace = null;
let referenceSpaceType = 'local-floor';
- const hasMultisampledRenderToTexture = renderer.extensions.has( 'WEBGL_multisampled_render_to_texture' );
let pose = null;
let glBinding = null;
let glProjLayer = null;
let glBaseLayer = null;
- let isMultisample = false;
let xrFrame = null;
const attributes = gl.getContextAttributes();
let initialRenderTarget = null;
@@ -267,7 +264,6 @@ class WebXRManager extends EventDispatcher {
} else {
- isMultisample = attributes.antialias;
let depthFormat = null;
let depthType = null;
let glDepthFormat = null;
@@ -292,36 +288,20 @@ class WebXRManager extends EventDispatcher {
session.updateRenderState( { layers: [ glProjLayer ] } );
- if ( isMultisample ) {
-
- newRenderTarget = new WebGLMultisampleRenderTarget(
- glProjLayer.textureWidth,
- glProjLayer.textureHeight,
- {
- format: RGBAFormat,
- type: UnsignedByteType,
- depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
- stencilBuffer: attributes.stencil,
- ignoreDepth: glProjLayer.ignoreDepthValues,
- useRenderToTexture: hasMultisampledRenderToTexture,
- encoding: renderer.outputEncoding
- } );
-
- } else {
-
- newRenderTarget = new WebGLRenderTarget(
- glProjLayer.textureWidth,
- glProjLayer.textureHeight,
- {
- format: RGBAFormat,
- type: UnsignedByteType,
- depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
- stencilBuffer: attributes.stencil,
- ignoreDepth: glProjLayer.ignoreDepthValues,
- encoding: renderer.outputEncoding
- } );
-
- }
+ newRenderTarget = new WebGLRenderTarget(
+ glProjLayer.textureWidth,
+ glProjLayer.textureHeight,
+ {
+ format: RGBAFormat,
+ type: UnsignedByteType,
+ depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
+ stencilBuffer: attributes.stencil,
+ encoding: renderer.outputEncoding,
+ samples: attributes.antialias ? 4 : 0
+ } );
+
+ const renderTargetProperties = renderer.properties.get( newRenderTarget );
+ renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues;
}