Skip to content

Commit dfc27bf

Browse files
authored
Merge pull request #17782 from mrdoob/webglutils
WebGLUtils: Moved relevant code to WebGLState and WebGLTextures
2 parents 4156fce + 65ecf7a commit dfc27bf

File tree

3 files changed

+49
-62
lines changed

3 files changed

+49
-62
lines changed

src/renderers/webgl/WebGLState.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, AddEquation, DoubleSide, BackSide } from '../../constants.js';
5+
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 } from '../../constants.js';
66
import { Vector4 } from '../../math/Vector4.js';
77

88
function WebGLState( gl, extensions, utils, capabilities ) {
@@ -529,6 +529,28 @@ function WebGLState( gl, extensions, utils, capabilities ) {
529529

530530
}
531531

532+
var equationToGL = {
533+
[ AddEquation ]: gl.FUNC_ADD,
534+
[ SubtractEquation ]: gl.FUNC_SUBTRACT,
535+
[ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT,
536+
[ MinEquation ]: isWebGL2 ? gl.MIN : extensions.get( 'EXT_blend_minmax' ).MIN_EXT,
537+
[ MaxEquation ]: isWebGL2 ? gl.MAX : extensions.get( 'EXT_blend_minmax' ).MAX_EXT
538+
};
539+
540+
var factorToGL = {
541+
[ ZeroFactor ]: gl.ZERO,
542+
[ OneFactor ]: gl.ONE,
543+
[ SrcColorFactor ]: gl.SRC_COLOR,
544+
[ SrcAlphaFactor ]: gl.SRC_ALPHA,
545+
[ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE,
546+
[ DstColorFactor ]: gl.DST_COLOR,
547+
[ DstAlphaFactor ]: gl.DST_ALPHA,
548+
[ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR,
549+
[ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA,
550+
[ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR,
551+
[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
552+
};
553+
532554
function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
533555

534556
if ( blending === NoBlending ) {
@@ -640,7 +662,7 @@ function WebGLState( gl, extensions, utils, capabilities ) {
640662

641663
if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
642664

643-
gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
665+
gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
644666

645667
currentBlendEquation = blendEquation;
646668
currentBlendEquationAlpha = blendEquationAlpha;
@@ -649,7 +671,7 @@ function WebGLState( gl, extensions, utils, capabilities ) {
649671

650672
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
651673

652-
gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
674+
gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
653675

654676
currentBlendSrc = blendSrc;
655677
currentBlendDst = blendDst;

src/renderers/webgl/WebGLTextures.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipmapLinearFilter, NearestMipmapNearestFilter } from '../../constants.js';
5+
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping } from '../../constants.js';
66
import { _Math } from '../../math/Math.js';
77

88
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
@@ -522,23 +522,37 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
522522

523523
}
524524

525-
function setTextureParameters( textureType, texture, supportsMips ) {
525+
var wrappingToGL = {
526+
[ RepeatWrapping ]: _gl.REPEAT,
527+
[ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE,
528+
[ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT
529+
};
530+
531+
var filterToGL = {
532+
[ NearestFilter ]: _gl.NEAREST,
533+
[ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST,
534+
[ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR,
526535

527-
var extension;
536+
[ LinearFilter ]: _gl.LINEAR,
537+
[ LinearMipmapNearestFilter ]: _gl.LINEAR_MIPMAP_NEAREST,
538+
[ LinearMipmapLinearFilter ]: _gl.LINEAR_MIPMAP_LINEAR
539+
};
540+
541+
function setTextureParameters( textureType, texture, supportsMips ) {
528542

529543
if ( supportsMips ) {
530544

531-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
532-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
545+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
546+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
533547

534548
if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
535549

536-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, utils.convert( texture.wrapR ) );
550+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );
537551

538552
}
539553

540-
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
541-
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
554+
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );
555+
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );
542556

543557
} else {
544558

@@ -568,7 +582,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
568582

569583
}
570584

571-
extension = extensions.get( 'EXT_texture_filter_anisotropic' );
585+
var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
572586

573587
if ( extension ) {
574588

src/renderers/webgl/WebGLUtils.js

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @author thespite / http://www.twitter.com/thespite
33
*/
44

5-
import { MaxEquation, MinEquation, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, SrcAlphaSaturateFactor, OneMinusDstColorFactor, DstColorFactor, OneMinusDstAlphaFactor, DstAlphaFactor, OneMinusSrcAlphaFactor, SrcAlphaFactor, OneMinusSrcColorFactor, SrcColorFactor, OneFactor, ZeroFactor, ReverseSubtractEquation, SubtractEquation, AddEquation, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, RGBFormat, AlphaFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort565Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NearestFilter, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping } from '../../constants.js';
5+
import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, RGBFormat, AlphaFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort565Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType } from '../../constants.js';
66

77
function WebGLUtils( gl, extensions, capabilities ) {
88

@@ -12,18 +12,6 @@ function WebGLUtils( gl, extensions, capabilities ) {
1212

1313
var extension;
1414

15-
if ( p === RepeatWrapping ) return gl.REPEAT;
16-
if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
17-
if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
18-
19-
if ( p === NearestFilter ) return gl.NEAREST;
20-
if ( p === NearestMipmapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
21-
if ( p === NearestMipmapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
22-
23-
if ( p === LinearFilter ) return gl.LINEAR;
24-
if ( p === LinearMipmapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
25-
if ( p === LinearMipmapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
26-
2715
if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
2816
if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
2917
if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
@@ -55,23 +43,6 @@ function WebGLUtils( gl, extensions, capabilities ) {
5543
if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
5644
if ( p === RedFormat ) return gl.RED;
5745

58-
if ( p === AddEquation ) return gl.FUNC_ADD;
59-
if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
60-
if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
61-
62-
if ( p === ZeroFactor ) return gl.ZERO;
63-
if ( p === OneFactor ) return gl.ONE;
64-
if ( p === SrcColorFactor ) return gl.SRC_COLOR;
65-
if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
66-
if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
67-
if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
68-
if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
69-
if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
70-
71-
if ( p === DstColorFactor ) return gl.DST_COLOR;
72-
if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
73-
if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
74-
7546
if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
7647
p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
7748

@@ -128,26 +99,6 @@ function WebGLUtils( gl, extensions, capabilities ) {
12899

129100
}
130101

131-
if ( p === MinEquation || p === MaxEquation ) {
132-
133-
if ( isWebGL2 ) {
134-
135-
if ( p === MinEquation ) return gl.MIN;
136-
if ( p === MaxEquation ) return gl.MAX;
137-
138-
}
139-
140-
extension = extensions.get( 'EXT_blend_minmax' );
141-
142-
if ( extension !== null ) {
143-
144-
if ( p === MinEquation ) return extension.MIN_EXT;
145-
if ( p === MaxEquation ) return extension.MAX_EXT;
146-
147-
}
148-
149-
}
150-
151102
if ( p === UnsignedInt248Type ) {
152103

153104
if ( isWebGL2 ) return gl.UNSIGNED_INT_24_8;

0 commit comments

Comments
 (0)