|
@@ -273,17 +273,25 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let _seed = 1234567;
|
|
|
|
+ const DEG2RAD = Math.PI / 180;
|
|
|
|
+ const RAD2DEG = 180 / Math.PI; //
|
|
|
|
+
|
|
const _lut = [];
|
|
const _lut = [];
|
|
|
|
|
|
for (let i = 0; i < 256; i++) {
|
|
for (let i = 0; i < 256; i++) {
|
|
_lut[i] = (i < 16 ? '0' : '') + i.toString(16);
|
|
_lut[i] = (i < 16 ? '0' : '') + i.toString(16);
|
|
}
|
|
}
|
|
|
|
|
|
- let _seed = 1234567;
|
|
|
|
- const DEG2RAD = Math.PI / 180;
|
|
|
|
- const RAD2DEG = 180 / Math.PI; // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
|
|
|
|
|
|
+ const hasRandomUUID = typeof crypto !== 'undefined' && 'randomUUID' in crypto;
|
|
|
|
|
|
function generateUUID() {
|
|
function generateUUID() {
|
|
|
|
+ if (hasRandomUUID) {
|
|
|
|
+ return crypto.randomUUID().toUpperCase();
|
|
|
|
+ } // TODO Remove this code when crypto.randomUUID() is available everywhere
|
|
|
|
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
|
|
|
|
+
|
|
|
|
+
|
|
const d0 = Math.random() * 0xffffffff | 0;
|
|
const d0 = Math.random() * 0xffffffff | 0;
|
|
const d1 = Math.random() * 0xffffffff | 0;
|
|
const d1 = Math.random() * 0xffffffff | 0;
|
|
const d2 = Math.random() * 0xffffffff | 0;
|
|
const d2 = Math.random() * 0xffffffff | 0;
|
|
@@ -9027,7 +9035,6 @@
|
|
constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
|
|
constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
|
|
images = images !== undefined ? images : [];
|
|
images = images !== undefined ? images : [];
|
|
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
|
|
mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
|
|
- format = format !== undefined ? format : RGBFormat;
|
|
|
|
super(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
|
|
super(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
|
|
this.flipY = false;
|
|
this.flipY = false;
|
|
}
|
|
}
|
|
@@ -11769,6 +11776,14 @@
|
|
scene.background = background;
|
|
scene.background = background;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ _setEncoding(uniform, texture) {
|
|
|
|
+ if (this._renderer.capabilities.isWebGL2 === true && texture.format === RGBAFormat && texture.type === UnsignedByteType && texture.encoding === sRGBEncoding) {
|
|
|
|
+ uniform.value = ENCODINGS[LinearEncoding];
|
|
|
|
+ } else {
|
|
|
|
+ uniform.value = ENCODINGS[texture.encoding];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
_textureToCubeUV(texture, cubeUVRenderTarget) {
|
|
_textureToCubeUV(texture, cubeUVRenderTarget) {
|
|
const renderer = this._renderer;
|
|
const renderer = this._renderer;
|
|
|
|
|
|
@@ -11791,8 +11806,9 @@
|
|
uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
|
|
uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
|
|
}
|
|
}
|
|
|
|
|
|
- uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
|
|
|
|
- uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
|
|
|
|
|
|
+ this._setEncoding(uniforms['inputEncoding'], texture);
|
|
|
|
+
|
|
|
|
+ this._setEncoding(uniforms['outputEncoding'], cubeUVRenderTarget.texture);
|
|
|
|
|
|
_setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
|
|
_setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
|
|
|
|
|
|
@@ -11882,8 +11898,11 @@
|
|
|
|
|
|
blurUniforms['dTheta'].value = radiansPerPixel;
|
|
blurUniforms['dTheta'].value = radiansPerPixel;
|
|
blurUniforms['mipInt'].value = LOD_MAX - lodIn;
|
|
blurUniforms['mipInt'].value = LOD_MAX - lodIn;
|
|
- blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
|
|
|
|
- blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
|
|
|
|
|
|
+
|
|
|
|
+ this._setEncoding(blurUniforms['inputEncoding'], targetIn.texture);
|
|
|
|
+
|
|
|
|
+ this._setEncoding(blurUniforms['outputEncoding'], targetIn.texture);
|
|
|
|
+
|
|
const outputSize = _sizeLods[lodOut];
|
|
const outputSize = _sizeLods[lodOut];
|
|
const x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
|
|
const x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
|
|
const y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
|
|
const y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
|
|
@@ -12478,6 +12497,7 @@
|
|
|
|
|
|
getExtension('OES_texture_float_linear');
|
|
getExtension('OES_texture_float_linear');
|
|
getExtension('EXT_color_buffer_half_float');
|
|
getExtension('EXT_color_buffer_half_float');
|
|
|
|
+ getExtension('EXT_multisampled_render_to_texture');
|
|
},
|
|
},
|
|
get: function (name) {
|
|
get: function (name) {
|
|
const extension = getExtension(name);
|
|
const extension = getExtension(name);
|
|
@@ -14273,6 +14293,10 @@
|
|
encoding = LinearEncoding;
|
|
encoding = LinearEncoding;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding) {
|
|
|
|
+ encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
|
|
|
|
+ }
|
|
|
|
+
|
|
return encoding;
|
|
return encoding;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -16338,7 +16362,7 @@
|
|
textureProperties.__maxMipLevel = Math.log2(Math.max(width, height, depth));
|
|
textureProperties.__maxMipLevel = Math.log2(Math.max(width, height, depth));
|
|
}
|
|
}
|
|
|
|
|
|
- function getInternalFormat(internalFormatName, glFormat, glType) {
|
|
|
|
|
|
+ function getInternalFormat(internalFormatName, glFormat, glType, encoding) {
|
|
if (isWebGL2 === false) return glFormat;
|
|
if (isWebGL2 === false) return glFormat;
|
|
|
|
|
|
if (internalFormatName !== null) {
|
|
if (internalFormatName !== null) {
|
|
@@ -16363,7 +16387,7 @@
|
|
if (glFormat === _gl.RGBA) {
|
|
if (glFormat === _gl.RGBA) {
|
|
if (glType === _gl.FLOAT) internalFormat = _gl.RGBA32F;
|
|
if (glType === _gl.FLOAT) internalFormat = _gl.RGBA32F;
|
|
if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RGBA16F;
|
|
if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RGBA16F;
|
|
- if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.RGBA8;
|
|
|
|
|
|
+ if (glType === _gl.UNSIGNED_BYTE) internalFormat = encoding === sRGBEncoding ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
|
|
}
|
|
}
|
|
|
|
|
|
if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) {
|
|
if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) {
|
|
@@ -16629,7 +16653,7 @@
|
|
const supportsMips = isPowerOfTwo$1(image) || isWebGL2,
|
|
const supportsMips = isPowerOfTwo$1(image) || isWebGL2,
|
|
glFormat = utils.convert(texture.format);
|
|
glFormat = utils.convert(texture.format);
|
|
let glType = utils.convert(texture.type),
|
|
let glType = utils.convert(texture.type),
|
|
- glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
|
|
|
+ glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
|
|
setTextureParameters(textureType, texture, supportsMips);
|
|
setTextureParameters(textureType, texture, supportsMips);
|
|
let mipmap;
|
|
let mipmap;
|
|
const mipmaps = texture.mipmaps;
|
|
const mipmaps = texture.mipmaps;
|
|
@@ -16777,7 +16801,7 @@
|
|
supportsMips = isPowerOfTwo$1(image) || isWebGL2,
|
|
supportsMips = isPowerOfTwo$1(image) || isWebGL2,
|
|
glFormat = utils.convert(texture.format),
|
|
glFormat = utils.convert(texture.format),
|
|
glType = utils.convert(texture.type),
|
|
glType = utils.convert(texture.type),
|
|
- glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
|
|
|
+ glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
|
|
setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips);
|
|
setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips);
|
|
let mipmaps;
|
|
let mipmaps;
|
|
|
|
|
|
@@ -16840,7 +16864,7 @@
|
|
function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget) {
|
|
function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget) {
|
|
const glFormat = utils.convert(texture.format);
|
|
const glFormat = utils.convert(texture.format);
|
|
const glType = utils.convert(texture.type);
|
|
const glType = utils.convert(texture.type);
|
|
- const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
|
|
|
+ const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
|
|
|
|
|
|
if (textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY) {
|
|
if (textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY) {
|
|
state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
|
|
state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
|
|
@@ -16896,7 +16920,7 @@
|
|
const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[0] : renderTarget.texture;
|
|
const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[0] : renderTarget.texture;
|
|
const glFormat = utils.convert(texture.format);
|
|
const glFormat = utils.convert(texture.format);
|
|
const glType = utils.convert(texture.type);
|
|
const glType = utils.convert(texture.type);
|
|
- const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
|
|
|
+ const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
|
|
|
|
|
|
if (isMultisample) {
|
|
if (isMultisample) {
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
@@ -17025,7 +17049,7 @@
|
|
|
|
|
|
const glFormat = utils.convert(texture.format);
|
|
const glFormat = utils.convert(texture.format);
|
|
const glType = utils.convert(texture.type);
|
|
const glType = utils.convert(texture.type);
|
|
- const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
|
|
|
|
|
|
+ const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding);
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
const samples = getRenderTargetSamples(renderTarget);
|
|
|
|
|
|
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
_gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height);
|
|
@@ -17592,6 +17616,8 @@
|
|
let xrFrame = null;
|
|
let xrFrame = null;
|
|
let depthStyle = null;
|
|
let depthStyle = null;
|
|
let clearStyle = null;
|
|
let clearStyle = null;
|
|
|
|
+ const msaartcSupported = renderer.extensions.has('EXT_multisampled_render_to_texture');
|
|
|
|
+ let msaaExt = null;
|
|
const controllers = [];
|
|
const controllers = [];
|
|
const inputSourcesMap = new Map(); //
|
|
const inputSourcesMap = new Map(); //
|
|
|
|
|
|
@@ -17790,7 +17816,9 @@
|
|
layers: [glProjLayer]
|
|
layers: [glProjLayer]
|
|
});
|
|
});
|
|
|
|
|
|
- if (isMultisample) {
|
|
|
|
|
|
+ if (isMultisample && msaartcSupported) {
|
|
|
|
+ msaaExt = renderer.extensions.get('EXT_multisampled_render_to_texture');
|
|
|
|
+ } else if (isMultisample) {
|
|
glMultisampledFramebuffer = gl.createFramebuffer();
|
|
glMultisampledFramebuffer = gl.createFramebuffer();
|
|
glColorRenderbuffer = gl.createRenderbuffer();
|
|
glColorRenderbuffer = gl.createRenderbuffer();
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, glColorRenderbuffer);
|
|
gl.bindRenderbuffer(gl.RENDERBUFFER, glColorRenderbuffer);
|
|
@@ -18019,11 +18047,20 @@
|
|
const glSubImage = glBinding.getViewSubImage(glProjLayer, view);
|
|
const glSubImage = glBinding.getViewSubImage(glProjLayer, view);
|
|
state.bindXRFramebuffer(glFramebuffer);
|
|
state.bindXRFramebuffer(glFramebuffer);
|
|
|
|
|
|
- if (glSubImage.depthStencilTexture !== undefined) {
|
|
|
|
- gl.framebufferTexture2D(gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0);
|
|
|
|
|
|
+ if (isMultisample && msaartcSupported) {
|
|
|
|
+ if (glSubImage.depthStencilTexture !== undefined) {
|
|
|
|
+ msaaExt.framebufferTexture2DMultisampleEXT(gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0, 4);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msaaExt.framebufferTexture2DMultisampleEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0, 4);
|
|
|
|
+ } else {
|
|
|
|
+ if (glSubImage.depthStencilTexture !== undefined) {
|
|
|
|
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0);
|
|
|
|
viewport = glSubImage.viewport;
|
|
viewport = glSubImage.viewport;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -18041,7 +18078,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (isMultisample) {
|
|
|
|
|
|
+ if (isMultisample && !msaartcSupported) {
|
|
state.bindXRFramebuffer(glMultisampledFramebuffer);
|
|
state.bindXRFramebuffer(glMultisampledFramebuffer);
|
|
if (clearStyle !== null) gl.clear(clearStyle);
|
|
if (clearStyle !== null) gl.clear(clearStyle);
|
|
}
|
|
}
|
|
@@ -18058,7 +18095,7 @@
|
|
|
|
|
|
if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
|
|
if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
|
|
|
|
|
|
- if (isMultisample) {
|
|
|
|
|
|
+ if (isMultisample && !msaartcSupported) {
|
|
const width = glProjLayer.textureWidth;
|
|
const width = glProjLayer.textureWidth;
|
|
const height = glProjLayer.textureHeight;
|
|
const height = glProjLayer.textureHeight;
|
|
state.bindFramebuffer(gl.READ_FRAMEBUFFER, glMultisampledFramebuffer);
|
|
state.bindFramebuffer(gl.READ_FRAMEBUFFER, glMultisampledFramebuffer);
|
|
@@ -28636,10 +28673,7 @@
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
loader.setCrossOrigin(this.crossOrigin);
|
|
loader.setPath(this.path);
|
|
loader.setPath(this.path);
|
|
loader.load(url, function (image) {
|
|
loader.load(url, function (image) {
|
|
- texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
|
|
|
|
-
|
|
|
|
- const isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
|
|
|
|
- texture.format = isJPEG ? RGBFormat : RGBAFormat;
|
|
|
|
|
|
+ texture.image = image;
|
|
texture.needsUpdate = true;
|
|
texture.needsUpdate = true;
|
|
|
|
|
|
if (onLoad !== undefined) {
|
|
if (onLoad !== undefined) {
|