Skip to content

Commit 541cc4c

Browse files
committed
cleanup extension and capability queries
1 parent 1b15ed7 commit 541cc4c

11 files changed

Lines changed: 36 additions & 98 deletions

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
"Fdez",
155155
"Heitz",
156156
"Hejl",
157+
"INSTANCEDMESH",
157158
"Kaufmann",
158159
"Kulla",
159160
"Meshopt",
@@ -189,6 +190,8 @@
189190
"preexisting",
190191
"rgbe",
191192
"rightx",
193+
"sessionend",
194+
"sessionstart",
192195
"skybox",
193196
"unproject",
194197
"vars"

packages/renderers/dist/renderers.esm-bundler.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Vector4, Color, Frustum, Matrix4, Vector2, Vector3, floorPowerOfTwo, ColorManagement } from '@renderlayer/math';
1+
import { Vector4, Color, Frustum, Matrix4, Vector2, Vector3, ColorManagement } from '@renderlayer/math';
22
import { createCanvasElement, SRGBColorSpace, NoToneMapping, HalfFloatType, UnsignedByteType, LinearMipmapLinearFilter, DoubleSide, BackSide, FrontSide, RGBAFormat, FloatType, WebGLCoordinateSystem, DisplayP3ColorSpace, LinearDisplayP3ColorSpace, LinearSRGBColorSpace, RGBAIntegerFormat, RGIntegerFormat, RedIntegerFormat, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedShort4444Type, UnsignedShort5551Type } from '@renderlayer/shared';
33
import { WebGLRenderTarget } from '@renderlayer/targets';
44
import { WebGLAnimation, WebGLUniforms, WebGLExtensions, WebGLCapabilities, WebGLUtils, WebGLState, WebGLInfo, WebGLProperties, WebGLTextures, WebGLCubeMaps, WebGLCubeUVMaps, WebGLAttributes, WebGLBindingStates, WebGLGeometries, WebGLObjects, WebGLMorphtargets, WebGLClipping, WebGLPrograms, WebGLMaterials, WebGLRenderLists, WebGLRenderStates, WebGLBackground, WebGLShadowMap, WebGLUniformsGroups, WebGLBufferRenderer, WebGLIndexedBufferRenderer } from '@renderlayer/webgl';
@@ -745,21 +745,16 @@ class WebGLRenderer {
745745
if (overrideMaterial !== null) {
746746
return;
747747
}
748-
const isWebGL2 = capabilities.isWebGL2;
749748
if (_transmissionRenderTarget === null) {
750749
_transmissionRenderTarget = new WebGLRenderTarget(1, 1, {
751750
generateMipmaps: true,
752751
type: extensions.has("EXT_color_buffer_half_float") ? HalfFloatType : UnsignedByteType,
753752
minFilter: LinearMipmapLinearFilter,
754-
samples: isWebGL2 ? 4 : 0
753+
samples: 4
755754
});
756755
}
757756
_this.getDrawingBufferSize(_vector2);
758-
if (isWebGL2) {
759-
_transmissionRenderTarget.setSize(_vector2.x, _vector2.y);
760-
} else {
761-
_transmissionRenderTarget.setSize(floorPowerOfTwo(_vector2.x), floorPowerOfTwo(_vector2.y));
762-
}
757+
_transmissionRenderTarget.setSize(_vector2.x, _vector2.y);
763758
const currentRenderTarget = _this.getRenderTarget();
764759
_this.setRenderTarget(_transmissionRenderTarget);
765760
_this.getClearColor(_currentClearColor);
@@ -993,7 +988,7 @@ class WebGLRenderer {
993988
needsProgramChange = true;
994989
} else if (materialProperties.toneMapping !== toneMapping) {
995990
needsProgramChange = true;
996-
} else if (capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount) {
991+
} else if (materialProperties.morphTargetsCount !== morphTargetsCount) {
997992
needsProgramChange = true;
998993
}
999994
} else {
@@ -1059,7 +1054,7 @@ class WebGLRenderer {
10591054
}
10601055
}
10611056
const morphAttributes = geometry.morphAttributes;
1062-
if (morphAttributes.position !== void 0 || morphAttributes.normal !== void 0 || morphAttributes.color !== void 0 && capabilities.isWebGL2 === true) {
1057+
if (morphAttributes.position !== void 0 || morphAttributes.normal !== void 0 || morphAttributes.color !== void 0) {
10631058
morphtargets.update(object, geometry, program);
10641059
}
10651060
if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
@@ -1100,13 +1095,9 @@ class WebGLRenderer {
11001095
if (material.isShaderMaterial || material.isRawShaderMaterial) {
11011096
const groups = material.uniformsGroups;
11021097
for (let i = 0, l = groups.length; i < l; i++) {
1103-
if (capabilities.isWebGL2) {
1104-
const group = groups[i];
1105-
uniformsGroups.update(group, program);
1106-
uniformsGroups.bind(group, program);
1107-
} else {
1108-
console.warn("WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.");
1109-
}
1098+
const group = groups[i];
1099+
uniformsGroups.update(group, program);
1100+
uniformsGroups.bind(group, program);
11101101
}
11111102
}
11121103
return program;
@@ -1190,7 +1181,7 @@ class WebGLRenderer {
11901181
framebuffer = __webglFramebuffer[activeCubeFace];
11911182
}
11921183
isCube = true;
1193-
} else if (capabilities.isWebGL2 && renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) {
1184+
} else if (renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) {
11941185
framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
11951186
} else {
11961187
if (Array.isArray(__webglFramebuffer)) {
@@ -1259,9 +1250,9 @@ class WebGLRenderer {
12591250
);
12601251
return;
12611252
}
1262-
const halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has("EXT_color_buffer_half_float") || capabilities.isWebGL2 && extensions.has("EXT_color_buffer_float"));
1253+
const halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has("EXT_color_buffer_half_float") || extensions.has("EXT_color_buffer_float"));
12631254
if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) && // Edge and Chrome Mac < 52 (#9513)
1264-
!(textureType === FloatType && (capabilities.isWebGL2 || extensions.has("OES_texture_float") || extensions.has("WEBGL_color_buffer_float"))) && // Chrome Mac >= 52 and Firefox
1255+
!(textureType === FloatType && true) && // Chrome Mac >= 52 and Firefox
12651256
!halfFloatSupportedByExt) {
12661257
console.error(
12671258
"WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type."

packages/renderers/src/WebGLRenderer.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,14 +1172,12 @@ class WebGLRenderer {
11721172
return;
11731173
}
11741174

1175-
const isWebGL2 = capabilities.isWebGL2;
1176-
11771175
if (_transmissionRenderTarget === null) {
11781176
_transmissionRenderTarget = new WebGLRenderTarget(1, 1, {
11791177
generateMipmaps: true,
11801178
type: extensions.has('EXT_color_buffer_half_float') ? HalfFloatType : UnsignedByteType,
11811179
minFilter: LinearMipmapLinearFilter,
1182-
samples: isWebGL2 ? 4 : 0
1180+
samples: 4
11831181
});
11841182

11851183
// debug
@@ -1195,11 +1193,7 @@ class WebGLRenderer {
11951193

11961194
_this.getDrawingBufferSize(_vector2);
11971195

1198-
if (isWebGL2) {
1199-
_transmissionRenderTarget.setSize(_vector2.x, _vector2.y);
1200-
} else {
1201-
_transmissionRenderTarget.setSize(floorPowerOfTwo(_vector2.x), floorPowerOfTwo(_vector2.y));
1202-
}
1196+
_transmissionRenderTarget.setSize(_vector2.x, _vector2.y);
12031197

12041198
//
12051199

@@ -1556,10 +1550,7 @@ class WebGLRenderer {
15561550
needsProgramChange = true;
15571551
} else if (materialProperties.toneMapping !== toneMapping) {
15581552
needsProgramChange = true;
1559-
} else if (
1560-
capabilities.isWebGL2 === true &&
1561-
materialProperties.morphTargetsCount !== morphTargetsCount
1562-
) {
1553+
} else if (materialProperties.morphTargetsCount !== morphTargetsCount) {
15631554
needsProgramChange = true;
15641555
}
15651556
} else {
@@ -1610,7 +1601,7 @@ class WebGLRenderer {
16101601
p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
16111602
}
16121603

1613-
// consider moving isOrthographic to UniformLib and WebGLMaterials, see #26467# issuecomment-1645185067
1604+
// consider moving isOrthographic to UniformLib and WebGLMaterials, see #26467# issue-comment-1645185067
16141605

16151606
if (
16161607
// material.isMeshPhongMaterial ||
@@ -1663,7 +1654,7 @@ class WebGLRenderer {
16631654
if (
16641655
morphAttributes.position !== undefined ||
16651656
morphAttributes.normal !== undefined ||
1666-
(morphAttributes.color !== undefined && capabilities.isWebGL2 === true)
1657+
morphAttributes.color !== undefined
16671658
) {
16681659
morphtargets.update(object, geometry, program);
16691660
}
@@ -1732,14 +1723,10 @@ class WebGLRenderer {
17321723
const groups = material.uniformsGroups;
17331724

17341725
for (let i = 0, l = groups.length; i < l; i++) {
1735-
if (capabilities.isWebGL2) {
1736-
const group = groups[i];
1726+
const group = groups[i];
17371727

1738-
uniformsGroups.update(group, program);
1739-
uniformsGroups.bind(group, program);
1740-
} else {
1741-
console.warn('WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.');
1742-
}
1728+
uniformsGroups.update(group, program);
1729+
uniformsGroups.bind(group, program);
17431730
}
17441731
}
17451732

@@ -1857,7 +1844,6 @@ class WebGLRenderer {
18571844

18581845
isCube = true;
18591846
} else if (
1860-
capabilities.isWebGL2 &&
18611847
renderTarget.samples > 0 &&
18621848
textures.useMultisampledRTT(renderTarget) === false
18631849
) {
@@ -1956,14 +1942,14 @@ class WebGLRenderer {
19561942
const halfFloatSupportedByExt =
19571943
textureType === HalfFloatType &&
19581944
(extensions.has('EXT_color_buffer_half_float') ||
1959-
(capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float')));
1945+
extensions.has('EXT_color_buffer_float'));
19601946

19611947
if (
19621948
textureType !== UnsignedByteType &&
19631949
utils.convert(textureType) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) && // Edge and Chrome Mac < 52 (#9513)
19641950
!(
19651951
textureType === FloatType &&
1966-
(capabilities.isWebGL2 ||
1952+
(true ||
19671953
extensions.has('OES_texture_float') ||
19681954
extensions.has('WEBGL_color_buffer_float'))
19691955
) && // Chrome Mac >= 52 and Firefox

packages/webgl/dist/webgl.esm-bundler.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,6 @@ function WebGLBindingStates(gl, extensions, attributes, capabilities) {
449449
}
450450
}
451451
function setupVertexAttributes(object, material, program, geometry) {
452-
if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
453-
if (extensions.get("ANGLE_instanced_arrays") === null)
454-
return;
455-
}
456452
initAttributes();
457453
const geometryAttributes = geometry.attributes;
458454
const programAttributes = program.getAttributes();
@@ -476,7 +472,7 @@ function WebGLBindingStates(gl, extensions, attributes, capabilities) {
476472
const buffer = attribute.buffer;
477473
const type = attribute.type;
478474
const bytesPerElement = attribute.bytesPerElement;
479-
const integer = capabilities.isWebGL2 === true && (type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType);
475+
const integer = type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType;
480476
if (geometryAttribute.isInterleavedBufferAttribute) {
481477
const data = geometryAttribute.data;
482478
const stride = data.stride;
@@ -680,7 +676,7 @@ function WebGLCapabilities(gl, extensions, parameters) {
680676
console.warn("WebGLRenderer:", precision, "not supported, using", maxPrecision, "instead.");
681677
precision = maxPrecision;
682678
}
683-
const drawBuffers = isWebGL2 || extensions.has("WEBGL_draw_buffers");
679+
const drawBuffers = true;
684680
const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
685681
const maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
686682
const maxVertexTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
@@ -691,9 +687,9 @@ function WebGLCapabilities(gl, extensions, parameters) {
691687
const maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS);
692688
const maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
693689
const vertexTextures = maxVertexTextures > 0;
694-
const floatFragmentTextures = isWebGL2 || extensions.has("OES_texture_float");
690+
const floatFragmentTextures = true;
695691
const floatVertexTextures = vertexTextures && floatFragmentTextures;
696-
const maxSamples = isWebGL2 ? gl.getParameter(gl.MAX_SAMPLES) : 0;
692+
const maxSamples = gl.getParameter(gl.MAX_SAMPLES);
697693
return {
698694
isWebGL2,
699695
drawBuffers,
@@ -3018,7 +3014,7 @@ function WebGLPrograms(renderer, cubemaps, cubeuvmaps, extensions, capabilities,
30183014
}
30193015
const parameters = {
30203016
isWebGL2: true,
3021-
// EP: always true, optimise
3017+
// EP: optimise
30223018
shaderID,
30233019
shaderType: material.type,
30243020
shaderName: material.name,

packages/webgl/src/WebGLAttributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
function WebGLAttributes(gl, capabilities) {
2-
// const isWebGL2 = capabilities.isWebGL2;
3-
42
const buffers = new WeakMap();
53

64
function createBuffer(attribute, bufferType) {

packages/webgl/src/WebGLBindingStates.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ function WebGLBindingStates(gl, extensions, attributes, capabilities) {
227227
}
228228

229229
function setupVertexAttributes(object, material, program, geometry) {
230-
if (
231-
capabilities.isWebGL2 === false &&
232-
(object.isInstancedMesh || geometry.isInstancedBufferGeometry)
233-
) {
234-
if (extensions.get('ANGLE_instanced_arrays') === null) return;
235-
}
236-
237230
initAttributes();
238231

239232
const geometryAttributes = geometry.attributes;
@@ -272,8 +265,7 @@ function WebGLBindingStates(gl, extensions, attributes, capabilities) {
272265
// check for integer attributes (WebGL 2 only)
273266

274267
const integer =
275-
capabilities.isWebGL2 === true &&
276-
(type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType);
268+
type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType;
277269

278270
if (geometryAttribute.isInterleavedBufferAttribute) {
279271
const data = geometryAttribute.data;

packages/webgl/src/WebGLBufferRenderer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class WebGLBufferRenderer {
22
constructor(gl, extensions, info, capabilities) {
3-
// const isWebGL2 = capabilities.isWebGL2;
43
let mode;
54

65
function setMode(value) {

packages/webgl/src/WebGLCapabilities.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function WebGLCapabilities(gl, extensions, parameters) {
3939
return 'lowp';
4040
}
4141

42-
// EP: Warn here.
4342
const isWebGL2 =
4443
typeof WebGL2RenderingContext !== 'undefined' &&
4544
gl.constructor.name === 'WebGL2RenderingContext';
@@ -52,7 +51,7 @@ function WebGLCapabilities(gl, extensions, parameters) {
5251
precision = maxPrecision;
5352
}
5453

55-
const drawBuffers = isWebGL2 || extensions.has('WEBGL_draw_buffers');
54+
const drawBuffers = true;
5655

5756
const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
5857

@@ -67,10 +66,10 @@ function WebGLCapabilities(gl, extensions, parameters) {
6766
const maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
6867

6968
const vertexTextures = maxVertexTextures > 0;
70-
const floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
69+
const floatFragmentTextures = true;
7170
const floatVertexTextures = vertexTextures && floatFragmentTextures;
7271

73-
const maxSamples = isWebGL2 ? gl.getParameter(gl.MAX_SAMPLES) : 0;
72+
const maxSamples = gl.getParameter(gl.MAX_SAMPLES);
7473

7574
return {
7675
isWebGL2,

packages/webgl/src/WebGLExtensions.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,6 @@ function WebGLExtensions(gl) {
99
let extension;
1010

1111
switch (name) {
12-
// case 'WEBGL_depth_texture':
13-
// extension =
14-
// gl.getExtension('WEBGL_depth_texture') ||
15-
// gl.getExtension('MOZ_WEBGL_depth_texture') ||
16-
// gl.getExtension('WEBKIT_WEBGL_depth_texture');
17-
// break;
18-
19-
// case 'EXT_texture_filter_anisotropic':
20-
// extension =
21-
// gl.getExtension('EXT_texture_filter_anisotropic') ||
22-
// gl.getExtension('MOZ_EXT_texture_filter_anisotropic') ||
23-
// gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
24-
// break;
25-
26-
// case 'WEBGL_compressed_texture_s3tc':
27-
// extension =
28-
// gl.getExtension('WEBGL_compressed_texture_s3tc') ||
29-
// gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') ||
30-
// gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
31-
// break;
32-
3312
case 'WEBGL_compressed_texture_pvrtc':
3413
extension =
3514
gl.getExtension('WEBGL_compressed_texture_pvrtc') ||
@@ -51,6 +30,7 @@ function WebGLExtensions(gl) {
5130
},
5231

5332
init(capabilities) {
33+
// EP: some extensions need to be initialised by a query to function
5434
getExtension('EXT_color_buffer_float');
5535
getExtension('OES_texture_float_linear');
5636
getExtension('EXT_color_buffer_half_float');

packages/webgl/src/WebGLPrograms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function WebGLPrograms(
190190
}
191191

192192
const parameters = {
193-
isWebGL2: true, // EP: always true, optimise
193+
isWebGL2: true, // EP: optimise
194194

195195
shaderID,
196196
shaderType: material.type,

0 commit comments

Comments
 (0)