Skip to content

Commit 53ae84b

Browse files
authored
Core: Add ReversedDepthFuncs dictionary. (mrdoob#32983)
1 parent 1547577 commit 53ae84b

File tree

4 files changed

+28
-43
lines changed

4 files changed

+28
-43
lines changed

src/renderers/webgl-fallback/utils/WebGLState.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,10 @@ import {
88
MaterialBlending
99
} from '../../../constants.js';
1010
import { Vector4 } from '../../../math/Vector4.js';
11-
import { error, warnOnce } from '../../../utils.js';
11+
import { error, ReversedDepthFuncs, warnOnce } from '../../../utils.js';
1212

1313
let equationToGL, factorToGL;
1414

15-
const reversedFuncs = {
16-
[ NeverDepth ]: AlwaysDepth,
17-
[ LessDepth ]: GreaterDepth,
18-
[ EqualDepth ]: NotEqualDepth,
19-
[ LessEqualDepth ]: GreaterEqualDepth,
20-
21-
[ AlwaysDepth ]: NeverDepth,
22-
[ GreaterDepth ]: LessDepth,
23-
[ NotEqualDepth ]: EqualDepth,
24-
[ GreaterEqualDepth ]: LessEqualDepth,
25-
};
26-
2715
/**
2816
* A WebGL 2 backend utility module for managing the WebGL state.
2917
*
@@ -679,7 +667,7 @@ class WebGLState {
679667
*/
680668
setDepthFunc( depthFunc ) {
681669

682-
if ( this.currentDepthReversed ) depthFunc = reversedFuncs[ depthFunc ];
670+
if ( this.currentDepthReversed ) depthFunc = ReversedDepthFuncs[ depthFunc ];
683671

684672
if ( this.currentDepthFunc !== depthFunc ) {
685673

src/renderers/webgl/WebGLState.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, DoubleSide, BackSide, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor, OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor } from '../../constants.js';
22
import { Color } from '../../math/Color.js';
33
import { Vector4 } from '../../math/Vector4.js';
4-
import { error } from '../../utils.js';
5-
6-
const reversedFuncs = {
7-
[ NeverDepth ]: AlwaysDepth,
8-
[ LessDepth ]: GreaterDepth,
9-
[ EqualDepth ]: NotEqualDepth,
10-
[ LessEqualDepth ]: GreaterEqualDepth,
11-
12-
[ AlwaysDepth ]: NeverDepth,
13-
[ GreaterDepth ]: LessDepth,
14-
[ NotEqualDepth ]: EqualDepth,
15-
[ GreaterEqualDepth ]: LessEqualDepth,
16-
};
4+
import { error, ReversedDepthFuncs } from '../../utils.js';
175

186
function WebGLState( gl, extensions ) {
197

@@ -146,7 +134,7 @@ function WebGLState( gl, extensions ) {
146134

147135
setFunc: function ( depthFunc ) {
148136

149-
if ( currentReversed ) depthFunc = reversedFuncs[ depthFunc ];
137+
if ( currentReversed ) depthFunc = ReversedDepthFuncs[ depthFunc ];
150138

151139
if ( currentDepthFunc !== depthFunc ) {
152140

src/renderers/webgpu/utils/WebGPUPipelineUtils.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ import {
1515
NeverStencilFunc, AlwaysStencilFunc, LessStencilFunc, LessEqualStencilFunc, EqualStencilFunc, GreaterEqualStencilFunc, GreaterStencilFunc, NotEqualStencilFunc
1616
} from '../../../constants.js';
1717

18-
import { error, warnOnce } from '../../../utils.js';
19-
20-
const reversedFuncs = {
21-
[ NeverDepth ]: AlwaysDepth,
22-
[ LessDepth ]: GreaterDepth,
23-
[ EqualDepth ]: NotEqualDepth,
24-
[ LessEqualDepth ]: GreaterEqualDepth,
25-
26-
[ AlwaysDepth ]: NeverDepth,
27-
[ GreaterDepth ]: LessDepth,
28-
[ NotEqualDepth ]: EqualDepth,
29-
[ GreaterEqualDepth ]: LessEqualDepth,
30-
};
18+
import { error, ReversedDepthFuncs, warnOnce } from '../../../utils.js';
3119

3220
/**
3321
* A WebGPU backend utility module for managing pipelines.
@@ -806,7 +794,7 @@ class WebGPUPipelineUtils {
806794

807795
} else {
808796

809-
const depthFunc = ( this.backend.parameters.reversedDepthBuffer ) ? reversedFuncs[ material.depthFunc ] : material.depthFunc;
797+
const depthFunc = ( this.backend.parameters.reversedDepthBuffer ) ? ReversedDepthFuncs[ material.depthFunc ] : material.depthFunc;
810798

811799
switch ( depthFunc ) {
812800

src/utils.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AlwaysDepth, EqualDepth, GreaterDepth, GreaterEqualDepth, LessDepth, LessEqualDepth, NeverDepth, NotEqualDepth } from './constants.js';
2+
13
/**
24
* Finds the minimum value in an array.
35
*
@@ -447,4 +449,23 @@ function toReversedProjectionMatrix( projectionMatrix ) {
447449

448450
}
449451

450-
export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, setConsoleFunction, getConsoleFunction, log, warn, error, warnOnce, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, isTypedArray };
452+
/**
453+
* Used to select the correct depth functions
454+
* when reversed depth buffer is used.
455+
*
456+
* @private
457+
* @type {Object}
458+
*/
459+
const ReversedDepthFuncs = {
460+
[ NeverDepth ]: AlwaysDepth,
461+
[ LessDepth ]: GreaterDepth,
462+
[ EqualDepth ]: NotEqualDepth,
463+
[ LessEqualDepth ]: GreaterEqualDepth,
464+
465+
[ AlwaysDepth ]: NeverDepth,
466+
[ GreaterDepth ]: LessDepth,
467+
[ NotEqualDepth ]: EqualDepth,
468+
[ GreaterEqualDepth ]: LessEqualDepth,
469+
};
470+
471+
export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, setConsoleFunction, getConsoleFunction, log, warn, error, warnOnce, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, isTypedArray, ReversedDepthFuncs };

0 commit comments

Comments
 (0)