super-three 0.160.1 → 0.161.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/build/three.cjs +379 -108
- package/build/three.module.js +380 -108
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +5 -1
- package/examples/jsm/capabilities/WebGPU.js +13 -9
- package/examples/jsm/controls/OrbitControls.js +102 -13
- package/examples/jsm/curves/NURBSUtils.js +59 -4
- package/examples/jsm/curves/NURBSVolume.js +62 -0
- package/examples/jsm/exporters/USDZExporter.js +8 -7
- package/examples/jsm/helpers/TextureHelper.js +3 -3
- package/examples/jsm/loaders/3DMLoader.js +44 -43
- package/examples/jsm/loaders/DDSLoader.js +1 -0
- package/examples/jsm/loaders/KTX2Loader.js +20 -5
- package/examples/jsm/loaders/LUT3dlLoader.js +78 -46
- package/examples/jsm/loaders/LUTCubeLoader.js +81 -67
- package/examples/jsm/loaders/LUTImageLoader.js +3 -2
- package/examples/jsm/loaders/MaterialXLoader.js +115 -16
- package/examples/jsm/loaders/SVGLoader.js +4 -3
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +144 -0
- package/examples/jsm/misc/Timer.js +13 -4
- package/examples/jsm/nodes/Nodes.js +16 -5
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +5 -3
- package/examples/jsm/nodes/accessors/CameraNode.js +9 -4
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +12 -1
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +27 -0
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +56 -3
- package/examples/jsm/nodes/accessors/VertexColorNode.js +70 -0
- package/examples/jsm/nodes/core/AttributeNode.js +1 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +23 -18
- package/examples/jsm/nodes/core/NodeFrame.js +16 -8
- package/examples/jsm/nodes/core/constants.js +1 -0
- package/examples/jsm/nodes/display/AfterImageNode.js +148 -0
- package/examples/jsm/nodes/display/AnamorphicNode.js +148 -0
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +3 -0
- package/examples/jsm/nodes/display/GaussianBlurNode.js +33 -13
- package/examples/jsm/nodes/display/PassNode.js +3 -2
- package/examples/jsm/nodes/display/ToneMappingNode.js +46 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +1 -4
- package/examples/jsm/nodes/display/ViewportNode.js +0 -2
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +4 -4
- package/examples/jsm/nodes/fog/FogNode.js +2 -1
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +13 -5
- package/examples/jsm/nodes/lighting/LightingContextNode.js +1 -1
- package/examples/jsm/nodes/lighting/LightsNode.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +18 -30
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshSSSNodeMaterial.js +84 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +6 -4
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +1 -7
- package/examples/jsm/nodes/math/MathNode.js +12 -2
- package/examples/jsm/nodes/math/MathUtils.js +15 -0
- package/examples/jsm/nodes/math/OperatorNode.js +13 -5
- package/examples/jsm/nodes/math/TriNoise3D.js +71 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +10 -1
- package/examples/jsm/nodes/utils/ArrayElementNode.js +6 -0
- package/examples/jsm/nodes/utils/JoinNode.js +2 -2
- package/examples/jsm/nodes/utils/LoopNode.js +3 -3
- package/examples/jsm/nodes/utils/ReflectorNode.js +227 -0
- package/examples/jsm/nodes/utils/RotateNode.js +68 -0
- package/examples/jsm/nodes/utils/RotateUVNode.js +1 -9
- package/examples/jsm/nodes/utils/SplitNode.js +4 -4
- package/examples/jsm/objects/GroundedSkybox.js +50 -0
- package/examples/jsm/objects/QuadMesh.js +8 -2
- package/examples/jsm/objects/Water2.js +8 -8
- package/examples/jsm/postprocessing/GTAOPass.js +11 -1
- package/examples/jsm/renderers/common/Backend.js +14 -0
- package/examples/jsm/renderers/common/Bindings.js +1 -1
- package/examples/jsm/renderers/common/DataMap.js +1 -1
- package/examples/jsm/renderers/common/Info.js +25 -1
- package/examples/jsm/renderers/common/Pipelines.js +8 -8
- package/examples/jsm/renderers/common/PostProcessing.js +2 -2
- package/examples/jsm/renderers/common/ProgrammableStage.js +3 -1
- package/examples/jsm/renderers/common/RenderObject.js +2 -0
- package/examples/jsm/renderers/common/Renderer.js +238 -22
- package/examples/jsm/renderers/common/StorageBufferAttribute.js +17 -0
- package/examples/jsm/renderers/common/Textures.js +25 -5
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +2 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +4 -2
- package/examples/jsm/renderers/webgl/WebGLBackend.js +631 -270
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +37 -30
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +89 -8
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +11 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +197 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +377 -11
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +2 -2
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +1 -21
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +289 -102
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +7 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +56 -39
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +9 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +38 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +85 -12
- package/examples/jsm/transpiler/AST.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +23 -27
- package/examples/jsm/utils/SortUtils.js +2 -0
- package/examples/jsm/webxr/ARButton.js +12 -2
- package/examples/jsm/webxr/VRButton.js +12 -2
- package/examples/jsm/webxr/XRButton.js +12 -2
- package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +3 -1
- package/package.json +2 -2
- package/src/audio/Audio.js +1 -3
- package/src/cameras/PerspectiveCamera.js +35 -0
- package/src/constants.js +1 -2
- package/src/core/BufferAttribute.js +2 -1
- package/src/core/InterleavedBuffer.js +2 -1
- package/src/core/InterleavedBufferAttribute.js +20 -0
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/Triangle.js +0 -30
- package/src/objects/BatchedMesh.js +6 -7
- package/src/objects/SkinnedMesh.js +0 -8
- package/src/renderers/WebGLRenderer.js +5 -1
- package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +56 -11
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +15 -7
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -1
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/points.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +1 -1
- package/src/renderers/webgl/WebGLAttributes.js +2 -2
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +30 -3
- package/src/renderers/webgl/WebGLPrograms.js +19 -11
- package/src/renderers/webgl/WebGLTextures.js +90 -16
- package/src/renderers/webxr/WebXRDepthSensing.js +105 -0
- package/src/renderers/webxr/WebXRManager.js +46 -0
- package/src/textures/Source.js +1 -0
- package/build/three.js +0 -54519
- package/build/three.min.js +0 -7
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathNode, GLSLNodeParser, NodeBuilder
|
|
1
|
+
import { MathNode, GLSLNodeParser, NodeBuilder } from '../../../nodes/Nodes.js';
|
|
2
2
|
|
|
3
3
|
import UniformBuffer from '../../common/UniformBuffer.js';
|
|
4
4
|
import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
|
|
@@ -36,6 +36,7 @@ class GLSLNodeBuilder extends NodeBuilder {
|
|
|
36
36
|
super( object, renderer, new GLSLNodeParser(), scene );
|
|
37
37
|
|
|
38
38
|
this.uniformGroups = {};
|
|
39
|
+
this.transforms = [];
|
|
39
40
|
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -99,11 +100,7 @@ ${ flowData.code }
|
|
|
99
100
|
|
|
100
101
|
generateTexture( texture, textureProperty, uvSnippet, depthSnippet ) {
|
|
101
102
|
|
|
102
|
-
if ( texture.
|
|
103
|
-
|
|
104
|
-
return `textureCube( ${ textureProperty }, ${ uvSnippet } )`;
|
|
105
|
-
|
|
106
|
-
} else if ( texture.isDepthTexture ) {
|
|
103
|
+
if ( texture.isDepthTexture ) {
|
|
107
104
|
|
|
108
105
|
return `texture( ${ textureProperty }, ${ uvSnippet } ).x`;
|
|
109
106
|
|
|
@@ -283,7 +280,7 @@ ${ flowData.code }
|
|
|
283
280
|
|
|
284
281
|
let snippet = '';
|
|
285
282
|
|
|
286
|
-
if ( shaderStage === 'vertex' ) {
|
|
283
|
+
if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
|
|
287
284
|
|
|
288
285
|
const attributes = this.getAttributesArray();
|
|
289
286
|
|
|
@@ -350,10 +347,11 @@ ${ flowData.code }
|
|
|
350
347
|
|
|
351
348
|
const varyings = this.varyings;
|
|
352
349
|
|
|
353
|
-
if ( shaderStage === 'vertex' ) {
|
|
350
|
+
if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
|
|
354
351
|
|
|
355
352
|
for ( const varying of varyings ) {
|
|
356
353
|
|
|
354
|
+
if ( shaderStage === 'compute' ) varying.needsInterpolation = true;
|
|
357
355
|
const type = varying.type;
|
|
358
356
|
const flat = type === 'int' || type === 'uint' ? 'flat ' : '';
|
|
359
357
|
|
|
@@ -425,6 +423,32 @@ ${ flowData.code }
|
|
|
425
423
|
|
|
426
424
|
}
|
|
427
425
|
|
|
426
|
+
registerTransform( varyingName, attributeNode ) {
|
|
427
|
+
|
|
428
|
+
this.transforms.push( { varyingName, attributeNode } );
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
getTransforms( /* shaderStage */ ) {
|
|
433
|
+
|
|
434
|
+
const transforms = this.transforms;
|
|
435
|
+
|
|
436
|
+
let snippet = '';
|
|
437
|
+
|
|
438
|
+
for ( let i = 0; i < transforms.length; i ++ ) {
|
|
439
|
+
|
|
440
|
+
const transform = transforms[ i ];
|
|
441
|
+
|
|
442
|
+
const attributeName = this.getPropertyName( transform.attributeNode );
|
|
443
|
+
|
|
444
|
+
snippet += `${ transform.varyingName } = ${ attributeName };\n\t`;
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return snippet;
|
|
449
|
+
|
|
450
|
+
}
|
|
451
|
+
|
|
428
452
|
_getGLSLUniformStruct( name, vars ) {
|
|
429
453
|
|
|
430
454
|
return `
|
|
@@ -460,6 +484,9 @@ void main() {
|
|
|
460
484
|
// vars
|
|
461
485
|
${shaderData.vars}
|
|
462
486
|
|
|
487
|
+
// transforms
|
|
488
|
+
${shaderData.transforms}
|
|
489
|
+
|
|
463
490
|
// flow
|
|
464
491
|
${shaderData.flow}
|
|
465
492
|
|
|
@@ -562,6 +589,7 @@ void main() {
|
|
|
562
589
|
stageData.vars = this.getVars( shaderStage );
|
|
563
590
|
stageData.structs = this.getStructs( shaderStage );
|
|
564
591
|
stageData.codes = this.getCodes( shaderStage );
|
|
592
|
+
stageData.transforms = this.getTransforms( shaderStage );
|
|
565
593
|
stageData.flow = flow;
|
|
566
594
|
|
|
567
595
|
}
|
|
@@ -573,8 +601,7 @@ void main() {
|
|
|
573
601
|
|
|
574
602
|
} else {
|
|
575
603
|
|
|
576
|
-
|
|
577
|
-
//this.computeShader = this._getGLSLComputeCode( shadersData.compute );
|
|
604
|
+
this.computeShader = this._getGLSLVertexCode( shadersData.compute );
|
|
578
605
|
|
|
579
606
|
}
|
|
580
607
|
|
|
@@ -647,26 +674,6 @@ void main() {
|
|
|
647
674
|
|
|
648
675
|
}
|
|
649
676
|
|
|
650
|
-
build() {
|
|
651
|
-
|
|
652
|
-
// @TODO: Move this code to super.build()
|
|
653
|
-
|
|
654
|
-
const { object, material } = this;
|
|
655
|
-
|
|
656
|
-
if ( material !== null ) {
|
|
657
|
-
|
|
658
|
-
NodeMaterial.fromMaterial( material ).build( this );
|
|
659
|
-
|
|
660
|
-
} else {
|
|
661
|
-
|
|
662
|
-
this.addFlow( 'compute', object );
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
return super.build();
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
|
|
670
677
|
}
|
|
671
678
|
|
|
672
679
|
export default GLSLNodeBuilder;
|
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
import { IntType } from 'three';
|
|
2
2
|
|
|
3
|
+
let _id = 0;
|
|
4
|
+
|
|
5
|
+
class DualAttributeData {
|
|
6
|
+
|
|
7
|
+
constructor( attributeData, dualBuffer ) {
|
|
8
|
+
|
|
9
|
+
this.buffers = [ attributeData.bufferGPU, dualBuffer ];
|
|
10
|
+
this.type = attributeData.type;
|
|
11
|
+
this.bytesPerElement = attributeData.BYTES_PER_ELEMENT;
|
|
12
|
+
this.version = attributeData.version;
|
|
13
|
+
this.isInteger = attributeData.isInteger;
|
|
14
|
+
this.activeBufferIndex = 0;
|
|
15
|
+
this.baseId = attributeData.id;
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
get id() {
|
|
21
|
+
|
|
22
|
+
return `${ this.baseId }|${ this.activeBufferIndex }`;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get bufferGPU() {
|
|
27
|
+
|
|
28
|
+
return this.buffers[ this.activeBufferIndex ];
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get transformBuffer() {
|
|
33
|
+
|
|
34
|
+
return this.buffers[ this.activeBufferIndex ^ 1 ];
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switchBuffers() {
|
|
39
|
+
|
|
40
|
+
this.activeBufferIndex ^= 1;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
3
46
|
class WebGLAttributeUtils {
|
|
4
47
|
|
|
5
48
|
constructor( backend ) {
|
|
@@ -23,11 +66,7 @@ class WebGLAttributeUtils {
|
|
|
23
66
|
|
|
24
67
|
if ( bufferGPU === undefined ) {
|
|
25
68
|
|
|
26
|
-
bufferGPU =
|
|
27
|
-
|
|
28
|
-
gl.bindBuffer( bufferType, bufferGPU );
|
|
29
|
-
gl.bufferData( bufferType, array, usage );
|
|
30
|
-
gl.bindBuffer( bufferType, null );
|
|
69
|
+
bufferGPU = this._createBuffer( gl, bufferType, array, usage );
|
|
31
70
|
|
|
32
71
|
bufferData.bufferGPU = bufferGPU;
|
|
33
72
|
bufferData.bufferType = bufferType;
|
|
@@ -85,13 +124,24 @@ class WebGLAttributeUtils {
|
|
|
85
124
|
|
|
86
125
|
}
|
|
87
126
|
|
|
88
|
-
|
|
127
|
+
let attributeData = {
|
|
89
128
|
bufferGPU,
|
|
90
129
|
type,
|
|
91
130
|
bytesPerElement: array.BYTES_PER_ELEMENT,
|
|
92
131
|
version: attribute.version,
|
|
93
|
-
isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType
|
|
94
|
-
|
|
132
|
+
isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType,
|
|
133
|
+
id: _id ++
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
if ( attribute.isStorageBufferAttribute ) {
|
|
137
|
+
|
|
138
|
+
// create buffer for tranform feedback use
|
|
139
|
+
const bufferGPUDual = this._createBuffer( gl, bufferType, array, usage );
|
|
140
|
+
attributeData = new DualAttributeData( attributeData, bufferGPUDual );
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
backend.set( attribute, attributeData );
|
|
95
145
|
|
|
96
146
|
}
|
|
97
147
|
|
|
@@ -134,6 +184,25 @@ class WebGLAttributeUtils {
|
|
|
134
184
|
|
|
135
185
|
}
|
|
136
186
|
|
|
187
|
+
destroyAttribute( attribute ) {
|
|
188
|
+
|
|
189
|
+
const backend = this.backend;
|
|
190
|
+
const { gl } = backend;
|
|
191
|
+
|
|
192
|
+
if ( attribute.isInterleavedBufferAttribute ) {
|
|
193
|
+
|
|
194
|
+
backend.delete( attribute.data );
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const attributeData = backend.get( attribute );
|
|
199
|
+
|
|
200
|
+
gl.deleteBuffer( attributeData.bufferGPU );
|
|
201
|
+
|
|
202
|
+
backend.delete( attribute );
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
137
206
|
async getArrayBufferAsync( attribute ) {
|
|
138
207
|
|
|
139
208
|
const backend = this.backend;
|
|
@@ -166,6 +235,18 @@ class WebGLAttributeUtils {
|
|
|
166
235
|
|
|
167
236
|
}
|
|
168
237
|
|
|
238
|
+
_createBuffer( gl, bufferType, array, usage ) {
|
|
239
|
+
|
|
240
|
+
const bufferGPU = gl.createBuffer();
|
|
241
|
+
|
|
242
|
+
gl.bindBuffer( bufferType, bufferGPU );
|
|
243
|
+
gl.bufferData( bufferType, array, usage );
|
|
244
|
+
gl.bindBuffer( bufferType, null );
|
|
245
|
+
|
|
246
|
+
return bufferGPU;
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
|
|
169
250
|
}
|
|
170
251
|
|
|
171
252
|
export default WebGLAttributeUtils;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const GLFeatureName = {
|
|
2
|
+
|
|
3
|
+
'WEBGL_compressed_texture_astc': 'texture-compression-astc',
|
|
4
|
+
'WEBGL_compressed_texture_etc': 'texture-compression-etc2',
|
|
5
|
+
'WEBGL_compressed_texture_etc1': 'texture-compression-etc1',
|
|
6
|
+
'WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc',
|
|
7
|
+
'WEBKIT_WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc',
|
|
8
|
+
'WEBGL_compressed_texture_s3tc': 'texture-compression-bc',
|
|
9
|
+
'EXT_texture_compression_bptc': 'texture-compression-bptc',
|
|
10
|
+
|
|
11
|
+
};
|
|
@@ -40,6 +40,14 @@ class WebGLState {
|
|
|
40
40
|
this.currentStencilZFail = null;
|
|
41
41
|
this.currentStencilZPass = null;
|
|
42
42
|
this.currentStencilMask = null;
|
|
43
|
+
this.currentLineWidth = null;
|
|
44
|
+
|
|
45
|
+
this.currentBoundFramebuffers = {};
|
|
46
|
+
this.currentDrawbuffers = new WeakMap();
|
|
47
|
+
|
|
48
|
+
this.maxTextures = this.gl.getParameter( this.gl.MAX_TEXTURE_IMAGE_UNITS );
|
|
49
|
+
this.currentTextureSlot = null;
|
|
50
|
+
this.currentBoundTextures = {};
|
|
43
51
|
|
|
44
52
|
if ( initialized === false ) {
|
|
45
53
|
|
|
@@ -161,6 +169,21 @@ class WebGLState {
|
|
|
161
169
|
|
|
162
170
|
}
|
|
163
171
|
|
|
172
|
+
setLineWidth( width ) {
|
|
173
|
+
|
|
174
|
+
const { currentLineWidth, gl } = this;
|
|
175
|
+
|
|
176
|
+
if ( width !== currentLineWidth ) {
|
|
177
|
+
|
|
178
|
+
gl.lineWidth( width );
|
|
179
|
+
|
|
180
|
+
this.currentLineWidth = width;
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
164
187
|
setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
165
188
|
|
|
166
189
|
const { gl } = this;
|
|
@@ -535,6 +558,180 @@ class WebGLState {
|
|
|
535
558
|
|
|
536
559
|
}
|
|
537
560
|
|
|
561
|
+
// framebuffer
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
bindFramebuffer( target, framebuffer ) {
|
|
565
|
+
|
|
566
|
+
const { gl, currentBoundFramebuffers } = this;
|
|
567
|
+
|
|
568
|
+
if ( currentBoundFramebuffers[ target ] !== framebuffer ) {
|
|
569
|
+
|
|
570
|
+
gl.bindFramebuffer( target, framebuffer );
|
|
571
|
+
|
|
572
|
+
currentBoundFramebuffers[ target ] = framebuffer;
|
|
573
|
+
|
|
574
|
+
// gl.DRAW_FRAMEBUFFER is equivalent to gl.FRAMEBUFFER
|
|
575
|
+
|
|
576
|
+
if ( target === gl.DRAW_FRAMEBUFFER ) {
|
|
577
|
+
|
|
578
|
+
currentBoundFramebuffers[ gl.FRAMEBUFFER ] = framebuffer;
|
|
579
|
+
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if ( target === gl.FRAMEBUFFER ) {
|
|
583
|
+
|
|
584
|
+
currentBoundFramebuffers[ gl.DRAW_FRAMEBUFFER ] = framebuffer;
|
|
585
|
+
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return true;
|
|
589
|
+
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return false;
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
drawBuffers( renderContext, framebuffer ) {
|
|
597
|
+
|
|
598
|
+
const { gl } = this;
|
|
599
|
+
|
|
600
|
+
let drawBuffers = [];
|
|
601
|
+
|
|
602
|
+
let needsUpdate = false;
|
|
603
|
+
|
|
604
|
+
if ( renderContext.textures !== null ) {
|
|
605
|
+
|
|
606
|
+
drawBuffers = this.currentDrawbuffers.get( framebuffer );
|
|
607
|
+
|
|
608
|
+
if ( drawBuffers === undefined ) {
|
|
609
|
+
|
|
610
|
+
drawBuffers = [];
|
|
611
|
+
this.currentDrawbuffers.set( framebuffer, drawBuffers );
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
const textures = renderContext.textures;
|
|
617
|
+
|
|
618
|
+
if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {
|
|
619
|
+
|
|
620
|
+
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
621
|
+
|
|
622
|
+
drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i;
|
|
623
|
+
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
drawBuffers.length = textures.length;
|
|
627
|
+
|
|
628
|
+
needsUpdate = true;
|
|
629
|
+
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
} else {
|
|
634
|
+
|
|
635
|
+
if ( drawBuffers[ 0 ] !== gl.BACK ) {
|
|
636
|
+
|
|
637
|
+
drawBuffers[ 0 ] = gl.BACK;
|
|
638
|
+
|
|
639
|
+
needsUpdate = true;
|
|
640
|
+
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if ( needsUpdate ) {
|
|
646
|
+
|
|
647
|
+
gl.drawBuffers( drawBuffers );
|
|
648
|
+
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
// texture
|
|
656
|
+
|
|
657
|
+
activeTexture( webglSlot ) {
|
|
658
|
+
|
|
659
|
+
const { gl, currentTextureSlot, maxTextures } = this;
|
|
660
|
+
|
|
661
|
+
if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
|
|
662
|
+
|
|
663
|
+
if ( currentTextureSlot !== webglSlot ) {
|
|
664
|
+
|
|
665
|
+
gl.activeTexture( webglSlot );
|
|
666
|
+
this.currentTextureSlot = webglSlot;
|
|
667
|
+
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
bindTexture( webglType, webglTexture, webglSlot ) {
|
|
673
|
+
|
|
674
|
+
const { gl, currentTextureSlot, currentBoundTextures, maxTextures } = this;
|
|
675
|
+
|
|
676
|
+
if ( webglSlot === undefined ) {
|
|
677
|
+
|
|
678
|
+
if ( currentTextureSlot === null ) {
|
|
679
|
+
|
|
680
|
+
webglSlot = gl.TEXTURE0 + maxTextures - 1;
|
|
681
|
+
|
|
682
|
+
} else {
|
|
683
|
+
|
|
684
|
+
webglSlot = currentTextureSlot;
|
|
685
|
+
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
let boundTexture = currentBoundTextures[ webglSlot ];
|
|
691
|
+
|
|
692
|
+
if ( boundTexture === undefined ) {
|
|
693
|
+
|
|
694
|
+
boundTexture = { type: undefined, texture: undefined };
|
|
695
|
+
currentBoundTextures[ webglSlot ] = boundTexture;
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
|
|
700
|
+
|
|
701
|
+
if ( currentTextureSlot !== webglSlot ) {
|
|
702
|
+
|
|
703
|
+
gl.activeTexture( webglSlot );
|
|
704
|
+
this.currentTextureSlot = webglSlot;
|
|
705
|
+
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
gl.bindTexture( webglType, webglTexture );
|
|
709
|
+
|
|
710
|
+
boundTexture.type = webglType;
|
|
711
|
+
boundTexture.texture = webglTexture;
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
unbindTexture() {
|
|
720
|
+
|
|
721
|
+
const { gl, currentTextureSlot, currentBoundTextures } = this;
|
|
722
|
+
|
|
723
|
+
const boundTexture = currentBoundTextures[ currentTextureSlot ];
|
|
724
|
+
|
|
725
|
+
if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
|
|
726
|
+
|
|
727
|
+
gl.bindTexture( boundTexture.type, null );
|
|
728
|
+
|
|
729
|
+
boundTexture.type = undefined;
|
|
730
|
+
boundTexture.texture = undefined;
|
|
731
|
+
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
}
|
|
538
735
|
|
|
539
736
|
}
|
|
540
737
|
|