Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove WebGLMultisampleRenderTarget. #23455

Merged
merged 7 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 45 additions & 73 deletions build/three.cjs

Large diffs are not rendered by default.

118 changes: 45 additions & 73 deletions build/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,7 @@
this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
this.samples = options.samples !== undefined ? options.samples : 0;
}

setTexture(texture) {
Expand Down Expand Up @@ -2550,6 +2551,7 @@
this.depthBuffer = source.depthBuffer;
this.stencilBuffer = source.stencilBuffer;
this.depthTexture = source.depthTexture;
this.samples = source.samples;
return this;
}

Expand Down Expand Up @@ -2617,27 +2619,6 @@

WebGLMultipleRenderTargets.prototype.isWebGLMultipleRenderTargets = true;

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;

class Quaternion {
constructor(x = 0, y = 0, z = 0, w = 1) {
this._x = x;
Expand Down Expand Up @@ -16536,8 +16517,7 @@
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();

Expand Down Expand Up @@ -17353,7 +17333,7 @@

state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);

if (renderTarget.useRenderToTexture) {
if (useMultisampledRenderToTexture(renderTarget)) {
MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, 0, getRenderTargetSamples(renderTarget));
} else {
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
Expand All @@ -17369,7 +17349,7 @@
if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
let glInternalFormat = _gl.DEPTH_COMPONENT16;

if (isMultisample || renderTarget.useRenderToTexture) {
if (isMultisample || useMultisampledRenderToTexture(renderTarget)) {
const depthTexture = renderTarget.depthTexture;

if (depthTexture && depthTexture.isDepthTexture) {
Expand All @@ -17382,7 +17362,7 @@

const samples = getRenderTargetSamples(renderTarget);

if (renderTarget.useRenderToTexture) {
if (useMultisampledRenderToTexture(renderTarget)) {
MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
} else {
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
Expand All @@ -17395,9 +17375,9 @@
} else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
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);
} else {
_gl.renderbufferStorage(_gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height);
Expand All @@ -17412,9 +17392,9 @@
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);
} else {
_gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height);
Expand Down Expand Up @@ -17448,13 +17428,13 @@
const samples = getRenderTargetSamples(renderTarget);

if (renderTarget.depthTexture.format === DepthFormat) {
if (renderTarget.useRenderToTexture) {
if (useMultisampledRenderToTexture(renderTarget)) {
MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples);
} else {
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0);
}
} 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);
} else {
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0);
Expand Down Expand Up @@ -17549,7 +17529,7 @@
} else {
console.warn('THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension.');
}
} else if (renderTarget.useRenderbuffer) {
} else if (renderTarget.samples > 0 && useMultisampledRenderToTexture(renderTarget) === false) {
if (isWebGL2) {
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
Expand All @@ -17576,7 +17556,7 @@

state.bindFramebuffer(_gl.FRAMEBUFFER, null);
} else {
console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
console.warn('THREE.WebGLRenderer: Multisampled render targets can only be used with WebGL 2.');
}
}
} // Setup color buffer
Expand Down Expand Up @@ -17661,8 +17641,8 @@
}

function updateMultisampleRenderTarget(renderTarget) {
if (renderTarget.useRenderbuffer) {
if (isWebGL2) {
if (isWebGL2) {
if (renderTarget.samples > 0 && useMultisampledRenderToTexture(renderTarget) === false) {
const width = renderTarget.width;
const height = renderTarget.height;
let mask = _gl.COLOR_BUFFER_BIT;
Expand All @@ -17673,16 +17653,18 @@
invalidationArray.push(depthStyle);
}

if (!renderTarget.ignoreDepthForMultisampleCopy) {
const renderTargetProperties = properties.get(renderTarget);
const ignoreDepthValues = renderTargetProperties.__ignoreDepthValues !== undefined ? renderTargetProperties.__ignoreDepthValues : true;

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);

if (renderTarget.ignoreDepthForMultisampleCopy) {
if (ignoreDepthValues === true) {
_gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, [depthStyle]);

_gl.invalidateFramebuffer(_gl.DRAW_FRAMEBUFFER, [depthStyle]);
Expand All @@ -17694,14 +17676,19 @@

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.');
}
} else {
console.warn('THREE.WebGLRenderer: Multisampled render targets can only be used with WebGL 2.');
}
}

function getRenderTargetSamples(renderTarget) {
return isWebGL2 && (renderTarget.useRenderbuffer || renderTarget.useRenderToTexture) ? Math.min(maxSamples, renderTarget.samples) : 0;
return Math.min(maxSamples, renderTarget.samples);
}

function useMultisampledRenderToTexture(renderTarget) {
const renderTargetProperties = properties.get(renderTarget);
return renderTarget.samples > 0 && extensions.has('WEBGL_multisampled_render_to_texture') === true && renderTargetProperties.__useRenderToTexture !== false;
}

function updateVideoTexture(texture) {
Expand Down Expand Up @@ -17791,6 +17778,7 @@
this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
this.setupDepthRenderbuffer = setupDepthRenderbuffer;
this.setupFrameBufferTexture = setupFrameBufferTexture;
this.useMultisampledRenderToTexture = useMultisampledRenderToTexture;
this.safeSetTexture2D = safeSetTexture2D;
this.safeSetTextureCube = safeSetTextureCube;
}
Expand Down Expand Up @@ -18238,12 +18226,10 @@
let framebufferScaleFactor = 1.0;
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;
Expand Down Expand Up @@ -18407,7 +18393,6 @@
encoding: renderer.outputEncoding
});
} else {
isMultisample = attributes.antialias;
let depthFormat = null;
let depthType = null;
let glDepthFormat = null;
Expand All @@ -18428,27 +18413,16 @@
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;
}

newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278
Expand Down Expand Up @@ -20018,12 +19992,11 @@
const isWebGL2 = capabilities.isWebGL2;

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: isWebGL2 ? LinearMipmapLinearFilter : LinearFilter,
useRenderToTexture: extensions.has('WEBGL_multisampled_render_to_texture')
samples: isWebGL2 && _antialias === true ? 4 : 0
});
}

Expand Down Expand Up @@ -20421,7 +20394,7 @@
if (!renderTargetProperties.__autoAllocateDepthBuffer) {
// 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;
renderTarget.useRenderbuffer = true;
Expand Down Expand Up @@ -20473,7 +20446,7 @@
if (renderTarget.isWebGLCubeRenderTarget) {
framebuffer = __webglFramebuffer[activeCubeFace];
isCube = true;
} else if (renderTarget.useRenderbuffer) {
} else if (renderTarget.samples > 0 && textures.useMultisampledRenderToTexture(renderTarget) === false) {
framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
} else {
framebuffer = __webglFramebuffer;
Expand Down Expand Up @@ -36942,7 +36915,6 @@
exports.WebGL1Renderer = WebGL1Renderer;
exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
exports.WebGLMultipleRenderTargets = WebGLMultipleRenderTargets;
exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
exports.WebGLRenderTarget = WebGLRenderTarget;
exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
exports.WebGLRenderer = WebGLRenderer;
Expand Down
2 changes: 1 addition & 1 deletion build/three.min.js

Large diffs are not rendered by default.

Loading