Skip to content

Commit

Permalink
remove WEBGL_multisampled_render_to_texture
Browse files Browse the repository at this point in the history
Used for occulus quest and pico devices.
KhronosGroup/WebGL#3342
  • Loading branch information
epreston committed Nov 28, 2023
1 parent 2ed22f8 commit 707f95a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 220 deletions.
10 changes: 1 addition & 9 deletions packages/renderers/dist/renderers.esm-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,6 @@ class WebGLRenderer {
renderTargetProperties.__hasExternalTextures = true;
if (renderTargetProperties.__hasExternalTextures) {
renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === void 0;
if (!renderTargetProperties.__autoAllocateDepthBuffer) {
if (extensions.has("WEBGL_multisampled_render_to_texture") === true) {
console.warn(
"WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"
);
renderTargetProperties.__useRenderToTexture = false;
}
}
}
};
this.setRenderTargetFramebuffer = (renderTarget, defaultFramebuffer) => {
Expand Down Expand Up @@ -1181,7 +1173,7 @@ class WebGLRenderer {
framebuffer = __webglFramebuffer[activeCubeFace];
}
isCube = true;
} else if (renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) {
} else if (renderTarget.samples > 0) {
framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
} else {
if (Array.isArray(__webglFramebuffer)) {
Expand Down
17 changes: 1 addition & 16 deletions packages/renderers/src/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Vector4,
Color,
Vector2,
floorPowerOfTwo,
ColorManagement
} from '@renderlayer/math';
import {
Expand Down Expand Up @@ -1775,17 +1774,6 @@ class WebGLRenderer {

if (renderTargetProperties.__hasExternalTextures) {
renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;

if (!renderTargetProperties.__autoAllocateDepthBuffer) {
// The multisample_render_to_texture extension doesn't work properly if there
// are mid-frame flushes and an external depth buffer. Disable use of the extension.
if (extensions.has('WEBGL_multisampled_render_to_texture') === true) {
console.warn(
'WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided'
);
renderTargetProperties.__useRenderToTexture = false;
}
}
}
};

Expand Down Expand Up @@ -1843,10 +1831,7 @@ class WebGLRenderer {
}

isCube = true;
} else if (
renderTarget.samples > 0 &&
textures.useMultisampledRTT(renderTarget) === false
) {
} else if (renderTarget.samples > 0) {
framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
} else {
if (Array.isArray(__webglFramebuffer)) {
Expand Down
121 changes: 29 additions & 92 deletions packages/webgl/dist/webgl.esm-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,6 @@ function WebGLExtensions(gl) {
getExtension("EXT_color_buffer_float");
getExtension("OES_texture_float_linear");
getExtension("EXT_color_buffer_half_float");
getExtension("WEBGL_multisampled_render_to_texture");
},
get(name) {
const extension = getExtension(name);
Expand Down Expand Up @@ -4999,7 +4998,7 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
const maxCubemapSize = capabilities.maxCubemapSize;
const maxTextureSize = capabilities.maxTextureSize;
const maxSamples = capabilities.maxSamples;
const multisampledRTTExt = extensions.has("WEBGL_multisampled_render_to_texture") ? extensions.get("WEBGL_multisampled_render_to_texture") : null;
extensions.has("WEBGL_multisampled_render_to_texture") ? extensions.get("WEBGL_multisampled_render_to_texture") : null;
const supportsInvalidateFramebuffer = typeof navigator === "undefined" ? false : /OculusBrowser/g.test(navigator.userAgent);
const _videoTextures = /* @__PURE__ */ new WeakMap();
let _canvas;
Expand Down Expand Up @@ -6141,16 +6140,7 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
}
}
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.framebufferTexture2DMultisampleEXT(
_gl.FRAMEBUFFER,
attachment,
textureTarget,
properties.get(texture).__webglTexture,
0,
getRenderTargetSamples(renderTarget)
);
} else if (textureTarget === _gl.TEXTURE_2D || textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z) {
if (textureTarget === _gl.TEXTURE_2D || textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z) {
_gl.framebufferTexture2D(
_gl.FRAMEBUFFER,
attachment,
Expand All @@ -6165,7 +6155,7 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
_gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer);
if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
let glInternalFormat = _gl.DEPTH_COMPONENT32F;
if (isMultisample || useMultisampledRTT(renderTarget)) {
if (isMultisample) {
const depthTexture = renderTarget.depthTexture;
if (depthTexture && depthTexture.isDepthTexture) {
if (depthTexture.type === FloatType) {
Expand All @@ -6175,23 +6165,13 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
}
}
const samples = getRenderTargetSamples(renderTarget);
if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.renderbufferStorageMultisampleEXT(
_gl.RENDERBUFFER,
samples,
glInternalFormat,
renderTarget.width,
renderTarget.height
);
} else {
_gl.renderbufferStorageMultisample(
_gl.RENDERBUFFER,
samples,
glInternalFormat,
renderTarget.width,
renderTarget.height
);
}
_gl.renderbufferStorageMultisample(
_gl.RENDERBUFFER,
samples,
glInternalFormat,
renderTarget.width,
renderTarget.height
);
} else {
_gl.renderbufferStorage(
_gl.RENDERBUFFER,
Expand All @@ -6208,22 +6188,14 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
);
} else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
const samples = getRenderTargetSamples(renderTarget);
if (isMultisample && useMultisampledRTT(renderTarget) === false) {
if (isMultisample) {
_gl.renderbufferStorageMultisample(
_gl.RENDERBUFFER,
samples,
_gl.DEPTH24_STENCIL8,
renderTarget.width,
renderTarget.height
);
} else if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.renderbufferStorageMultisampleEXT(
_gl.RENDERBUFFER,
samples,
_gl.DEPTH24_STENCIL8,
renderTarget.width,
renderTarget.height
);
} else {
_gl.renderbufferStorage(
_gl.RENDERBUFFER,
Expand All @@ -6250,22 +6222,14 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
texture.colorSpace
);
const samples = getRenderTargetSamples(renderTarget);
if (isMultisample && useMultisampledRTT(renderTarget) === false) {
if (isMultisample) {
_gl.renderbufferStorageMultisample(
_gl.RENDERBUFFER,
samples,
glInternalFormat,
renderTarget.width,
renderTarget.height
);
} else if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.renderbufferStorageMultisampleEXT(
_gl.RENDERBUFFER,
samples,
glInternalFormat,
renderTarget.width,
renderTarget.height
);
} else {
_gl.renderbufferStorage(
_gl.RENDERBUFFER,
Expand Down Expand Up @@ -6293,45 +6257,23 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
}
setTexture2D(renderTarget.depthTexture, 0);
const webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
const samples = getRenderTargetSamples(renderTarget);
getRenderTargetSamples(renderTarget);
if (renderTarget.depthTexture.format === DepthFormat) {
if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.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
);
}
_gl.framebufferTexture2D(
_gl.FRAMEBUFFER,
_gl.DEPTH_ATTACHMENT,
_gl.TEXTURE_2D,
webglDepthTexture,
0
);
} else if (renderTarget.depthTexture.format === DepthStencilFormat) {
if (useMultisampledRTT(renderTarget)) {
multisampledRTTExt.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
);
}
_gl.framebufferTexture2D(
_gl.FRAMEBUFFER,
_gl.DEPTH_STENCIL_ATTACHMENT,
_gl.TEXTURE_2D,
webglDepthTexture,
0
);
} else {
throw new Error("Unknown depthTexture format");
}
Expand Down Expand Up @@ -6431,7 +6373,7 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
);
}
}
if (renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) {
if (renderTarget.samples > 0) {
const textures = isMultipleRenderTargets ? texture : [texture];
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
renderTargetProperties.__webglColorRenderbuffer = [];
Expand Down Expand Up @@ -6584,7 +6526,7 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
}
}
function updateMultisampleRenderTarget(renderTarget) {
if (renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) {
if (renderTarget.samples > 0) {
const textures = renderTarget.isWebGLMultipleRenderTargets ? renderTarget.texture : [renderTarget.texture];
const width = renderTarget.width;
const height = renderTarget.height;
Expand Down Expand Up @@ -6693,10 +6635,6 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
function getRenderTargetSamples(renderTarget) {
return Math.min(maxSamples, renderTarget.samples);
}
function useMultisampledRTT(renderTarget) {
const renderTargetProperties = properties.get(renderTarget);
return renderTarget.samples > 0 && extensions.has("WEBGL_multisampled_render_to_texture") === true && renderTargetProperties.__useRenderToTexture !== false;
}
function updateVideoTexture(texture) {
const frame = info.render.frame;
if (_videoTextures.get(texture) !== frame) {
Expand Down Expand Up @@ -6735,7 +6673,6 @@ function WebGLTextures(_gl, extensions, state, properties, capabilities, utils,
this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
this.setupDepthRenderbuffer = setupDepthRenderbuffer;
this.setupFrameBufferTexture = setupFrameBufferTexture;
this.useMultisampledRTT = useMultisampledRTT;
}

function WebGLUniformsGroups(gl, info, capabilities, state) {
Expand Down
8 changes: 4 additions & 4 deletions packages/webgl/src/WebGLExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function WebGLExtensions(gl) {

init(capabilities) {
// EP: some extensions need to be initialised by a query to function
getExtension('EXT_color_buffer_float');
getExtension('OES_texture_float_linear');
getExtension('EXT_color_buffer_half_float');
getExtension('WEBGL_multisampled_render_to_texture');
// Browser support percentages sourced from https://web3dsurvey.com/webgl2
getExtension('EXT_color_buffer_float'); // 99.8%
getExtension('OES_texture_float_linear'); // 86.31%
getExtension('EXT_color_buffer_half_float'); // 92.2%
},

get(name) {
Expand Down
Loading

0 comments on commit 707f95a

Please sign in to comment.