super-three 0.172.0 → 0.173.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 +439 -380
- package/build/three.core.js +413 -41
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +28 -344
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +11 -3
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +7550 -1798
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +7551 -1798
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/animation/CCDIKSolver.js +6 -5
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +23 -21
- package/examples/jsm/exporters/GLTFExporter.js +26 -25
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/loaders/GCodeLoader.js +3 -1
- package/examples/jsm/loaders/GLTFLoader.js +0 -2
- package/examples/jsm/loaders/TDSLoader.js +0 -1
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +4 -3
- package/examples/jsm/misc/Volume.js +7 -5
- package/examples/jsm/misc/VolumeSlice.js +5 -3
- package/examples/jsm/objects/WaterMesh.js +25 -20
- package/examples/jsm/physics/JoltPhysics.js +7 -7
- package/examples/jsm/physics/RapierPhysics.js +4 -4
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/shaders/OutputShader.js +5 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +2 -0
- package/package.json +1 -1
- package/src/Three.Core.js +2 -0
- package/src/Three.TSL.js +9 -1
- package/src/cameras/ArrayCamera.js +1 -0
- package/src/constants.js +6 -1
- package/src/core/BufferAttribute.js +4 -0
- package/src/core/EventDispatcher.js +8 -6
- package/src/extras/ImageUtils.js +1 -11
- package/src/loaders/nodes/NodeObjectLoader.js +1 -1
- package/src/materials/nodes/MeshBasicNodeMaterial.js +1 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +1 -1
- package/src/materials/nodes/NodeMaterial.js +5 -5
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +109 -7
- package/src/materials/nodes/SpriteNodeMaterial.js +1 -1
- package/src/materials/nodes/VolumeNodeMaterial.js +3 -3
- package/src/materials/nodes/manager/NodeMaterialObserver.js +8 -0
- package/src/nodes/Nodes.js +4 -0
- package/src/nodes/TSL.js +4 -0
- package/src/nodes/accessors/Arrays.js +30 -8
- package/src/nodes/accessors/BatchNode.js +3 -3
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/Camera.js +64 -3
- package/src/nodes/accessors/InstanceNode.js +1 -1
- package/src/nodes/accessors/MaterialNode.js +9 -9
- package/src/nodes/accessors/ModelViewProjectionNode.js +1 -1
- package/src/nodes/accessors/Normal.js +6 -2
- package/src/nodes/accessors/Object3DNode.js +0 -1
- package/src/nodes/accessors/Position.js +6 -6
- package/src/nodes/accessors/ReferenceBaseNode.js +2 -4
- package/src/nodes/accessors/ReferenceNode.js +2 -3
- package/src/nodes/accessors/StorageBufferNode.js +42 -5
- package/src/nodes/accessors/Tangent.js +2 -2
- package/src/nodes/accessors/Texture3DNode.js +1 -1
- package/src/nodes/accessors/TextureNode.js +12 -5
- package/src/nodes/accessors/UniformArrayNode.js +9 -3
- package/src/nodes/accessors/VelocityNode.js +0 -2
- package/src/nodes/code/ScriptableNode.js +3 -3
- package/src/nodes/core/ArrayNode.js +125 -0
- package/src/nodes/core/ConstNode.js +8 -0
- package/src/nodes/core/Node.js +14 -1
- package/src/nodes/core/NodeBuilder.js +229 -19
- package/src/nodes/core/NodeUtils.js +11 -1
- package/src/nodes/core/NodeVar.js +17 -1
- package/src/nodes/core/OutputStructNode.js +19 -9
- package/src/nodes/core/StackNode.js +20 -1
- package/src/nodes/core/StructNode.js +121 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +82 -21
- package/src/nodes/core/TempNode.js +1 -1
- package/src/nodes/core/VarNode.js +94 -7
- package/src/nodes/core/VaryingNode.js +19 -3
- package/src/nodes/display/BlendModes.js +88 -1
- package/src/nodes/display/BumpMapNode.js +6 -6
- package/src/nodes/display/NormalMapNode.js +6 -6
- package/src/nodes/display/PassNode.js +3 -1
- package/src/nodes/display/ScreenNode.js +9 -0
- package/src/nodes/fog/Fog.js +17 -0
- package/src/nodes/gpgpu/AtomicFunctionNode.js +20 -4
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +8 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
- package/src/nodes/lighting/ShadowNode.js +1 -1
- package/src/nodes/math/ConditionalNode.js +8 -1
- package/src/nodes/math/MathNode.js +14 -1
- package/src/nodes/math/OperatorNode.js +96 -18
- package/src/nodes/pmrem/PMREMUtils.js +1 -1
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +1 -0
- package/src/nodes/tsl/TSLCore.js +22 -2
- package/src/nodes/utils/ArrayElementNode.js +1 -1
- package/src/nodes/utils/LoopNode.js +8 -1
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/StorageArrayElementNode.js +14 -0
- package/src/nodes/utils/Timer.js +21 -0
- package/src/objects/BatchedMesh.js +1 -1
- package/src/objects/Line.js +6 -6
- package/src/renderers/WebGLRenderer.js +7 -0
- package/src/renderers/common/Animation.js +23 -1
- package/src/renderers/common/Backend.js +58 -15
- package/src/renderers/common/Background.js +14 -0
- package/src/renderers/common/Binding.js +1 -1
- package/src/renderers/common/BufferUtils.js +1 -1
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +9 -7
- package/src/renderers/common/ClippingContext.js +1 -1
- package/src/renderers/common/Color4.js +7 -3
- package/src/renderers/common/Geometries.js +2 -23
- package/src/renderers/common/Info.js +1 -45
- package/src/renderers/common/Lighting.js +8 -6
- package/src/renderers/common/Pipelines.js +3 -3
- package/src/renderers/common/PostProcessing.js +24 -8
- package/src/renderers/common/QuadMesh.js +1 -1
- package/src/renderers/common/RenderBundles.js +9 -3
- package/src/renderers/common/RenderContext.js +37 -3
- package/src/renderers/common/RenderContexts.js +30 -17
- package/src/renderers/common/RenderList.js +2 -2
- package/src/renderers/common/RenderLists.js +9 -3
- package/src/renderers/common/RenderObject.js +76 -17
- package/src/renderers/common/RenderObjects.js +9 -7
- package/src/renderers/common/Renderer.js +86 -67
- package/src/renderers/common/SampledTexture.js +0 -1
- package/src/renderers/common/StorageBufferAttribute.js +1 -1
- package/src/renderers/common/StorageInstancedBufferAttribute.js +1 -1
- package/src/renderers/common/StorageTexture.js +1 -1
- package/src/renderers/common/Textures.js +14 -7
- package/src/renderers/common/TimestampQueryPool.js +39 -0
- package/src/renderers/common/Uniform.js +37 -1
- package/src/renderers/common/UniformsGroup.js +2 -0
- package/src/renderers/common/XRManager.js +1193 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +53 -8
- package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -1
- package/src/renderers/common/nodes/NodeUniform.js +54 -2
- package/src/renderers/common/nodes/Nodes.js +25 -18
- package/src/renderers/webgl/WebGLBackground.js +4 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +295 -110
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -17
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +57 -0
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +167 -21
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +132 -149
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +6 -4
- package/src/renderers/webgpu/WebGPURenderer.js +5 -4
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +615 -41
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +85 -6
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +85 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +257 -9
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +86 -4
- package/src/renderers/webxr/WebXRManager.js +13 -2
- package/src/textures/VideoFrameTexture.js +35 -0
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
- package/examples/jsm/objects/InstancedPoints.js +0 -19
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -209
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -37
|
@@ -6,17 +6,47 @@ import {
|
|
|
6
6
|
OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
|
|
7
7
|
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
|
|
8
8
|
} from '../../../constants.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import { Vector4 } from '../../../math/Vector4.js';
|
|
10
|
+
|
|
11
|
+
let equationToGL, factorToGL;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A WebGL 2 backend utility module for managing the WebGL state.
|
|
15
|
+
*
|
|
16
|
+
* The major goal of this module is to reduce the number of state changes
|
|
17
|
+
* by caching the WEbGL state with a series of variables. In this way, the
|
|
18
|
+
* renderer only executes state change commands when necessary which
|
|
19
|
+
* improves the overall performance.
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
12
23
|
class WebGLState {
|
|
13
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new utility object.
|
|
27
|
+
*
|
|
28
|
+
* @param {WebGLBackend} backend - The WebGL 2 backend.
|
|
29
|
+
*/
|
|
14
30
|
constructor( backend ) {
|
|
15
31
|
|
|
32
|
+
/**
|
|
33
|
+
* A reference to the WebGL 2 backend.
|
|
34
|
+
*
|
|
35
|
+
* @type {WebGLBackend}
|
|
36
|
+
*/
|
|
16
37
|
this.backend = backend;
|
|
17
38
|
|
|
39
|
+
/**
|
|
40
|
+
* A reference to the rendering context.
|
|
41
|
+
*
|
|
42
|
+
* @type {WebGL2RenderingContext}
|
|
43
|
+
*/
|
|
18
44
|
this.gl = this.backend.gl;
|
|
19
45
|
|
|
46
|
+
// Below properties are intended to cache
|
|
47
|
+
// the WebGL state and are not explicitly
|
|
48
|
+
// documented for convenience reasons.
|
|
49
|
+
|
|
20
50
|
this.enabled = {};
|
|
21
51
|
this.currentFlipSided = null;
|
|
22
52
|
this.currentCullFace = null;
|
|
@@ -51,17 +81,19 @@ class WebGLState {
|
|
|
51
81
|
this.currentBoundTextures = {};
|
|
52
82
|
this.currentBoundBufferBases = {};
|
|
53
83
|
|
|
54
|
-
if ( initialized === false ) {
|
|
55
84
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
initialized = true;
|
|
59
|
-
|
|
60
|
-
}
|
|
85
|
+
this._init();
|
|
61
86
|
|
|
62
87
|
}
|
|
63
88
|
|
|
64
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Inits the state of the utility.
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
_init() {
|
|
95
|
+
|
|
96
|
+
const gl = this.gl;
|
|
65
97
|
|
|
66
98
|
// Store only WebGL constants here.
|
|
67
99
|
|
|
@@ -85,8 +117,24 @@ class WebGLState {
|
|
|
85
117
|
[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
|
|
86
118
|
};
|
|
87
119
|
|
|
120
|
+
const scissorParam = gl.getParameter( gl.SCISSOR_BOX );
|
|
121
|
+
const viewportParam = gl.getParameter( gl.VIEWPORT );
|
|
122
|
+
|
|
123
|
+
this.currentScissor = new Vector4().fromArray( scissorParam );
|
|
124
|
+
this.currentViewport = new Vector4().fromArray( viewportParam );
|
|
125
|
+
|
|
126
|
+
this._tempVec4 = new Vector4();
|
|
127
|
+
|
|
88
128
|
}
|
|
89
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Enables the given WebGL capability.
|
|
132
|
+
*
|
|
133
|
+
* This method caches the capability state so
|
|
134
|
+
* `gl.enable()` is only called when necessary.
|
|
135
|
+
*
|
|
136
|
+
* @param {GLenum} id - The capability to enable.
|
|
137
|
+
*/
|
|
90
138
|
enable( id ) {
|
|
91
139
|
|
|
92
140
|
const { enabled } = this;
|
|
@@ -100,6 +148,14 @@ class WebGLState {
|
|
|
100
148
|
|
|
101
149
|
}
|
|
102
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Disables the given WebGL capability.
|
|
153
|
+
*
|
|
154
|
+
* This method caches the capability state so
|
|
155
|
+
* `gl.disable()` is only called when necessary.
|
|
156
|
+
*
|
|
157
|
+
* @param {GLenum} id - The capability to enable.
|
|
158
|
+
*/
|
|
103
159
|
disable( id ) {
|
|
104
160
|
|
|
105
161
|
const { enabled } = this;
|
|
@@ -113,6 +169,15 @@ class WebGLState {
|
|
|
113
169
|
|
|
114
170
|
}
|
|
115
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Specifies whether polygons are front- or back-facing
|
|
174
|
+
* by setting the winding orientation.
|
|
175
|
+
*
|
|
176
|
+
* This method caches the state so `gl.frontFace()` is only
|
|
177
|
+
* called when necessary.
|
|
178
|
+
*
|
|
179
|
+
* @param {Boolean} flipSided - Whether triangles flipped their sides or not.
|
|
180
|
+
*/
|
|
116
181
|
setFlipSided( flipSided ) {
|
|
117
182
|
|
|
118
183
|
if ( this.currentFlipSided !== flipSided ) {
|
|
@@ -135,6 +200,15 @@ class WebGLState {
|
|
|
135
200
|
|
|
136
201
|
}
|
|
137
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Specifies whether or not front- and/or back-facing
|
|
205
|
+
* polygons can be culled.
|
|
206
|
+
*
|
|
207
|
+
* This method caches the state so `gl.cullFace()` is only
|
|
208
|
+
* called when necessary.
|
|
209
|
+
*
|
|
210
|
+
* @param {Number} cullFace - Defines which polygons are candidates for culling.
|
|
211
|
+
*/
|
|
138
212
|
setCullFace( cullFace ) {
|
|
139
213
|
|
|
140
214
|
const { gl } = this;
|
|
@@ -171,6 +245,14 @@ class WebGLState {
|
|
|
171
245
|
|
|
172
246
|
}
|
|
173
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Specifies the width of line primitives.
|
|
250
|
+
*
|
|
251
|
+
* This method caches the state so `gl.lineWidth()` is only
|
|
252
|
+
* called when necessary.
|
|
253
|
+
*
|
|
254
|
+
* @param {Number} width - The line width.
|
|
255
|
+
*/
|
|
174
256
|
setLineWidth( width ) {
|
|
175
257
|
|
|
176
258
|
const { currentLineWidth, gl } = this;
|
|
@@ -185,7 +267,21 @@ class WebGLState {
|
|
|
185
267
|
|
|
186
268
|
}
|
|
187
269
|
|
|
188
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Defines the blending.
|
|
272
|
+
*
|
|
273
|
+
* This method caches the state so `gl.blendEquation()`, `gl.blendEquationSeparate()`,
|
|
274
|
+
* `gl.blendFunc()` and `gl.blendFuncSeparate()` are only called when necessary.
|
|
275
|
+
*
|
|
276
|
+
* @param {Number} blending - The blending type.
|
|
277
|
+
* @param {Number} blendEquation - The blending equation.
|
|
278
|
+
* @param {Number} blendSrc - Only relevant for custom blending. The RGB source blending factor.
|
|
279
|
+
* @param {Number} blendDst - Only relevant for custom blending. The RGB destination blending factor.
|
|
280
|
+
* @param {Number} blendEquationAlpha - Only relevant for custom blending. The blending equation for alpha.
|
|
281
|
+
* @param {Number} blendSrcAlpha - Only relevant for custom blending. The alpha source blending factor.
|
|
282
|
+
* @param {Number} blendDstAlpha - Only relevant for custom blending. The alpha destination blending factor.
|
|
283
|
+
* @param {Boolean} premultipliedAlpha - Whether premultiplied alpha is enabled or not.
|
|
284
|
+
*/
|
|
189
285
|
setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
190
286
|
|
|
191
287
|
const { gl } = this;
|
|
@@ -322,6 +418,15 @@ class WebGLState {
|
|
|
322
418
|
|
|
323
419
|
}
|
|
324
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Specifies whether colors can be written when rendering
|
|
423
|
+
* into a framebuffer or not.
|
|
424
|
+
*
|
|
425
|
+
* This method caches the state so `gl.colorMask()` is only
|
|
426
|
+
* called when necessary.
|
|
427
|
+
*
|
|
428
|
+
* @param {Boolean} colorMask - The color mask.
|
|
429
|
+
*/
|
|
325
430
|
setColorMask( colorMask ) {
|
|
326
431
|
|
|
327
432
|
if ( this.currentColorMask !== colorMask ) {
|
|
@@ -333,6 +438,11 @@ class WebGLState {
|
|
|
333
438
|
|
|
334
439
|
}
|
|
335
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Specifies whether the depth test is enabled or not.
|
|
443
|
+
*
|
|
444
|
+
* @param {Boolean} depthTest - Whether the depth test is enabled or not.
|
|
445
|
+
*/
|
|
336
446
|
setDepthTest( depthTest ) {
|
|
337
447
|
|
|
338
448
|
const { gl } = this;
|
|
@@ -349,6 +459,15 @@ class WebGLState {
|
|
|
349
459
|
|
|
350
460
|
}
|
|
351
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Specifies whether depth values can be written when rendering
|
|
464
|
+
* into a framebuffer or not.
|
|
465
|
+
*
|
|
466
|
+
* This method caches the state so `gl.depthMask()` is only
|
|
467
|
+
* called when necessary.
|
|
468
|
+
*
|
|
469
|
+
* @param {Boolean} depthMask - The depth mask.
|
|
470
|
+
*/
|
|
352
471
|
setDepthMask( depthMask ) {
|
|
353
472
|
|
|
354
473
|
if ( this.currentDepthMask !== depthMask ) {
|
|
@@ -360,6 +479,14 @@ class WebGLState {
|
|
|
360
479
|
|
|
361
480
|
}
|
|
362
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Specifies the depth compare function.
|
|
484
|
+
*
|
|
485
|
+
* This method caches the state so `gl.depthFunc()` is only
|
|
486
|
+
* called when necessary.
|
|
487
|
+
*
|
|
488
|
+
* @param {Number} depthFunc - The depth compare function.
|
|
489
|
+
*/
|
|
363
490
|
setDepthFunc( depthFunc ) {
|
|
364
491
|
|
|
365
492
|
if ( this.currentDepthFunc !== depthFunc ) {
|
|
@@ -420,6 +547,80 @@ class WebGLState {
|
|
|
420
547
|
|
|
421
548
|
}
|
|
422
549
|
|
|
550
|
+
/**
|
|
551
|
+
* Specifies the viewport.
|
|
552
|
+
*
|
|
553
|
+
* @param {Number} x - The x-coordinate of the lower left corner of the viewport.
|
|
554
|
+
* @param {Number} y - The y-coordinate of the lower left corner of the viewport.
|
|
555
|
+
* @param {Number} width - The width of the viewport.
|
|
556
|
+
* @param {Number} height - The height of the viewport.
|
|
557
|
+
*
|
|
558
|
+
*/
|
|
559
|
+
scissor( x, y, width, height ) {
|
|
560
|
+
|
|
561
|
+
const scissor = this._tempVec4.set( x, y, width, height );
|
|
562
|
+
|
|
563
|
+
if ( this.currentScissor.equals( scissor ) === false ) {
|
|
564
|
+
|
|
565
|
+
const { gl } = this;
|
|
566
|
+
|
|
567
|
+
gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
|
|
568
|
+
this.currentScissor.copy( scissor );
|
|
569
|
+
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Specifies the viewport.
|
|
576
|
+
*
|
|
577
|
+
* @param {Number} x - The x-coordinate of the lower left corner of the viewport.
|
|
578
|
+
* @param {Number} y - The y-coordinate of the lower left corner of the viewport.
|
|
579
|
+
* @param {Number} width - The width of the viewport.
|
|
580
|
+
* @param {Number} height - The height of the viewport.
|
|
581
|
+
*
|
|
582
|
+
*/
|
|
583
|
+
viewport( x, y, width, height ) {
|
|
584
|
+
|
|
585
|
+
const viewport = this._tempVec4.set( x, y, width, height );
|
|
586
|
+
|
|
587
|
+
if ( this.currentViewport.equals( viewport ) === false ) {
|
|
588
|
+
|
|
589
|
+
const { gl } = this;
|
|
590
|
+
|
|
591
|
+
gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
|
|
592
|
+
this.currentViewport.copy( viewport );
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Defines the scissor test.
|
|
600
|
+
*
|
|
601
|
+
* @param {Boolean} boolean - Whether the scissor test should be enabled or not.
|
|
602
|
+
*/
|
|
603
|
+
setScissorTest( boolean ) {
|
|
604
|
+
|
|
605
|
+
const gl = this.gl;
|
|
606
|
+
|
|
607
|
+
if ( boolean ) {
|
|
608
|
+
|
|
609
|
+
gl.enable( gl.SCISSOR_TEST );
|
|
610
|
+
|
|
611
|
+
} else {
|
|
612
|
+
|
|
613
|
+
gl.disable( gl.SCISSOR_TEST );
|
|
614
|
+
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Specifies whether the stencil test is enabled or not.
|
|
621
|
+
*
|
|
622
|
+
* @param {Boolean} stencilTest - Whether the stencil test is enabled or not.
|
|
623
|
+
*/
|
|
423
624
|
setStencilTest( stencilTest ) {
|
|
424
625
|
|
|
425
626
|
const { gl } = this;
|
|
@@ -436,6 +637,15 @@ class WebGLState {
|
|
|
436
637
|
|
|
437
638
|
}
|
|
438
639
|
|
|
640
|
+
/**
|
|
641
|
+
* Specifies whether stencil values can be written when rendering
|
|
642
|
+
* into a framebuffer or not.
|
|
643
|
+
*
|
|
644
|
+
* This method caches the state so `gl.stencilMask()` is only
|
|
645
|
+
* called when necessary.
|
|
646
|
+
*
|
|
647
|
+
* @param {Boolean} stencilMask - The stencil mask.
|
|
648
|
+
*/
|
|
439
649
|
setStencilMask( stencilMask ) {
|
|
440
650
|
|
|
441
651
|
if ( this.currentStencilMask !== stencilMask ) {
|
|
@@ -447,6 +657,16 @@ class WebGLState {
|
|
|
447
657
|
|
|
448
658
|
}
|
|
449
659
|
|
|
660
|
+
/**
|
|
661
|
+
* Specifies whether the stencil test functions.
|
|
662
|
+
*
|
|
663
|
+
* This method caches the state so `gl.stencilFunc()` is only
|
|
664
|
+
* called when necessary.
|
|
665
|
+
*
|
|
666
|
+
* @param {Number} stencilFunc - The stencil compare function.
|
|
667
|
+
* @param {Number} stencilRef - The reference value for the stencil test.
|
|
668
|
+
* @param {Number} stencilMask - A bit-wise mask that is used to AND the reference value and the stored stencil value when the test is done.
|
|
669
|
+
*/
|
|
450
670
|
setStencilFunc( stencilFunc, stencilRef, stencilMask ) {
|
|
451
671
|
|
|
452
672
|
if ( this.currentStencilFunc !== stencilFunc ||
|
|
@@ -463,6 +683,17 @@ class WebGLState {
|
|
|
463
683
|
|
|
464
684
|
}
|
|
465
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Specifies whether the stencil test operation.
|
|
688
|
+
*
|
|
689
|
+
* This method caches the state so `gl.stencilOp()` is only
|
|
690
|
+
* called when necessary.
|
|
691
|
+
*
|
|
692
|
+
* @param {Number} stencilFail - The function to use when the stencil test fails.
|
|
693
|
+
* @param {Number} stencilZFail - The function to use when the stencil test passes, but the depth test fail.
|
|
694
|
+
* @param {Number} stencilZPass - The function to use when both the stencil test and the depth test pass,
|
|
695
|
+
* or when the stencil test passes and there is no depth buffer or depth testing is disabled.
|
|
696
|
+
*/
|
|
466
697
|
setStencilOp( stencilFail, stencilZFail, stencilZPass ) {
|
|
467
698
|
|
|
468
699
|
if ( this.currentStencilFail !== stencilFail ||
|
|
@@ -479,6 +710,13 @@ class WebGLState {
|
|
|
479
710
|
|
|
480
711
|
}
|
|
481
712
|
|
|
713
|
+
/**
|
|
714
|
+
* Configures the WebGL state for the given material.
|
|
715
|
+
*
|
|
716
|
+
* @param {Material} material - The material to configure the state for.
|
|
717
|
+
* @param {Number} frontFaceCW - Whether the front faces are counter-clockwise or not.
|
|
718
|
+
* @param {Number} hardwareClippingPlanes - The number of hardware clipping planes.
|
|
719
|
+
*/
|
|
482
720
|
setMaterial( material, frontFaceCW, hardwareClippingPlanes ) {
|
|
483
721
|
|
|
484
722
|
const { gl } = this;
|
|
@@ -543,6 +781,16 @@ class WebGLState {
|
|
|
543
781
|
|
|
544
782
|
}
|
|
545
783
|
|
|
784
|
+
/**
|
|
785
|
+
* Specifies the polygon offset.
|
|
786
|
+
*
|
|
787
|
+
* This method caches the state so `gl.polygonOffset()` is only
|
|
788
|
+
* called when necessary.
|
|
789
|
+
*
|
|
790
|
+
* @param {Boolean} polygonOffset - Whether polygon offset is enabled or not.
|
|
791
|
+
* @param {Number} factor - The scale factor for the variable depth offset for each polygon.
|
|
792
|
+
* @param {Number} units - The multiplier by which an implementation-specific value is multiplied with to create a constant depth offset.
|
|
793
|
+
*/
|
|
546
794
|
setPolygonOffset( polygonOffset, factor, units ) {
|
|
547
795
|
|
|
548
796
|
const { gl } = this;
|
|
@@ -568,6 +816,15 @@ class WebGLState {
|
|
|
568
816
|
|
|
569
817
|
}
|
|
570
818
|
|
|
819
|
+
/**
|
|
820
|
+
* Defines the usage of the given WebGL program.
|
|
821
|
+
*
|
|
822
|
+
* This method caches the state so `gl.useProgram()` is only
|
|
823
|
+
* called when necessary.
|
|
824
|
+
*
|
|
825
|
+
* @param {WebGLProgram} program - The WebGL program to use.
|
|
826
|
+
* @return {Boolean} Whether a program change has been executed or not.
|
|
827
|
+
*/
|
|
571
828
|
useProgram( program ) {
|
|
572
829
|
|
|
573
830
|
if ( this.currentProgram !== program ) {
|
|
@@ -587,6 +844,16 @@ class WebGLState {
|
|
|
587
844
|
// framebuffer
|
|
588
845
|
|
|
589
846
|
|
|
847
|
+
/**
|
|
848
|
+
* Binds the given framebuffer.
|
|
849
|
+
*
|
|
850
|
+
* This method caches the state so `gl.bindFramebuffer()` is only
|
|
851
|
+
* called when necessary.
|
|
852
|
+
*
|
|
853
|
+
* @param {Number} target - The binding point (target).
|
|
854
|
+
* @param {WebGLFramebuffer} framebuffer - The WebGL framebuffer to bind.
|
|
855
|
+
* @return {Boolean} Whether a bind has been executed or not.
|
|
856
|
+
*/
|
|
590
857
|
bindFramebuffer( target, framebuffer ) {
|
|
591
858
|
|
|
592
859
|
const { gl, currentBoundFramebuffers } = this;
|
|
@@ -619,6 +886,16 @@ class WebGLState {
|
|
|
619
886
|
|
|
620
887
|
}
|
|
621
888
|
|
|
889
|
+
/**
|
|
890
|
+
* Defines draw buffers to which fragment colors are written into.
|
|
891
|
+
* Configures the MRT setup of custom framebuffers.
|
|
892
|
+
*
|
|
893
|
+
* This method caches the state so `gl.drawBuffers()` is only
|
|
894
|
+
* called when necessary.
|
|
895
|
+
*
|
|
896
|
+
* @param {RenderContext} renderContext - The render context.
|
|
897
|
+
* @param {WebGLFramebuffer} framebuffer - The WebGL framebuffer.
|
|
898
|
+
*/
|
|
622
899
|
drawBuffers( renderContext, framebuffer ) {
|
|
623
900
|
|
|
624
901
|
const { gl } = this;
|
|
@@ -679,6 +956,14 @@ class WebGLState {
|
|
|
679
956
|
|
|
680
957
|
// texture
|
|
681
958
|
|
|
959
|
+
/**
|
|
960
|
+
* Makes the given texture unit active.
|
|
961
|
+
*
|
|
962
|
+
* This method caches the state so `gl.activeTexture()` is only
|
|
963
|
+
* called when necessary.
|
|
964
|
+
*
|
|
965
|
+
* @param {Number} webglSlot - The texture unit to make active.
|
|
966
|
+
*/
|
|
682
967
|
activeTexture( webglSlot ) {
|
|
683
968
|
|
|
684
969
|
const { gl, currentTextureSlot, maxTextures } = this;
|
|
@@ -694,6 +979,16 @@ class WebGLState {
|
|
|
694
979
|
|
|
695
980
|
}
|
|
696
981
|
|
|
982
|
+
/**
|
|
983
|
+
* Binds the given WebGL texture to a target.
|
|
984
|
+
*
|
|
985
|
+
* This method caches the state so `gl.bindTexture()` is only
|
|
986
|
+
* called when necessary.
|
|
987
|
+
*
|
|
988
|
+
* @param {Number} webglType - The binding point (target).
|
|
989
|
+
* @param {WebGLTexture} webglTexture - The WebGL texture to bind.
|
|
990
|
+
* @param {Number} webglSlot - The texture.
|
|
991
|
+
*/
|
|
697
992
|
bindTexture( webglType, webglTexture, webglSlot ) {
|
|
698
993
|
|
|
699
994
|
const { gl, currentTextureSlot, currentBoundTextures, maxTextures } = this;
|
|
@@ -739,6 +1034,17 @@ class WebGLState {
|
|
|
739
1034
|
|
|
740
1035
|
}
|
|
741
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* Binds a given WebGL buffer to a given binding point (target) at a given index.
|
|
1039
|
+
*
|
|
1040
|
+
* This method caches the state so `gl.bindBufferBase()` is only
|
|
1041
|
+
* called when necessary.
|
|
1042
|
+
*
|
|
1043
|
+
* @param {Number} target - The target for the bind operation.
|
|
1044
|
+
* @param {Number} index - The index of the target.
|
|
1045
|
+
* @param {WebGLBuffer} buffer - The WebGL buffer.
|
|
1046
|
+
* @return {Boolean} Whether a bind has been executed or not.
|
|
1047
|
+
*/
|
|
742
1048
|
bindBufferBase( target, index, buffer ) {
|
|
743
1049
|
|
|
744
1050
|
const { gl } = this;
|
|
@@ -759,6 +1065,12 @@ class WebGLState {
|
|
|
759
1065
|
}
|
|
760
1066
|
|
|
761
1067
|
|
|
1068
|
+
/**
|
|
1069
|
+
* Unbinds the current bound texture.
|
|
1070
|
+
*
|
|
1071
|
+
* This method caches the state so `gl.bindTexture()` is only
|
|
1072
|
+
* called when necessary.
|
|
1073
|
+
*/
|
|
762
1074
|
unbindTexture() {
|
|
763
1075
|
|
|
764
1076
|
const { gl, currentTextureSlot, currentBoundTextures } = this;
|