Skip to content

Commit f7cd331

Browse files
committed
Replaced WebGLUtils.convert with toGL
1 parent 314b181 commit f7cd331

File tree

5 files changed

+207
-131
lines changed

5 files changed

+207
-131
lines changed

src/renderers/WebGLRenderer.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Vector3 } from '../math/Vector3.js';
3131
import { WebGLClipping } from './webgl/WebGLClipping.js';
3232
import { Frustum } from '../math/Frustum.js';
3333
import { Vector4 } from '../math/Vector4.js';
34-
import { WebGLUtils } from './webgl/WebGLUtils.js';
34+
import { toGL } from './webgl/WebGLUtils';
3535

3636
/**
3737
* @author supereggbert / http://www.paulbrunt.co.uk/
@@ -248,8 +248,6 @@ function WebGLRenderer( parameters ) {
248248
var background, morphtargets, bufferRenderer, indexedBufferRenderer;
249249
var flareRenderer, spriteRenderer;
250250

251-
var utils;
252-
253251
function initGLContext() {
254252

255253
extensions = new WebGLExtensions( _gl );
@@ -267,16 +265,14 @@ function WebGLRenderer( parameters ) {
267265

268266
}
269267

270-
utils = new WebGLUtils( _gl, extensions );
271-
272268
capabilities = new WebGLCapabilities( _gl, extensions, parameters );
273269

274-
state = new WebGLState( _gl, extensions, utils );
270+
state = new WebGLState( _gl, extensions );
275271
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
276272
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
277273

278274
properties = new WebGLProperties();
279-
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
275+
textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, _infoMemory );
280276
attributes = new WebGLAttributes( _gl );
281277
geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
282278
objects = new WebGLObjects( geometries, _infoRender );
@@ -2463,14 +2459,14 @@ function WebGLRenderer( parameters ) {
24632459
var textureFormat = texture.format;
24642460
var textureType = texture.type;
24652461

2466-
if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
2462+
if ( textureFormat !== RGBAFormat && toGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
24672463

24682464
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
24692465
return;
24702466

24712467
}
24722468

2473-
if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
2469+
if ( textureType !== UnsignedByteType && toGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
24742470
! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
24752471
! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
24762472

@@ -2485,7 +2481,7 @@ function WebGLRenderer( parameters ) {
24852481

24862482
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
24872483

2488-
_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
2484+
_gl.readPixels( x, y, width, height, toGL( textureFormat ), toGL( textureType ), buffer );
24892485

24902486
}
24912487

src/renderers/webgl/WebGLConstants.js

+68-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ var WebGLConstants = {
3737
INT: 0x1404,
3838
UNSIGNED_INT: 0x1405,
3939
FLOAT: 0x1406,
40+
DEPTH_COMPONENT: 0x1902,
41+
DEPTH_STENCIL: 0x84F9,
42+
43+
// Pixel types
44+
UNSIGNED_SHORT_5_5_5_1: 32820,
45+
UNSIGNED_SHORT_4_4_4_4: 32819,
46+
UNSIGNED_SHORT_5_6_5: 33635,
47+
48+
// Pixel formats
49+
DEPTH_COMPONENT: 0x1902,
50+
ALPHA: 0x1906,
51+
RGB: 0x1907,
52+
RGBA: 0x1908,
53+
LUMINANCE: 0x1909,
54+
LUMINANCE_ALPHA: 0x190A,
55+
56+
// Blending equations
57+
FUNC_ADD: 0x8006,
58+
FUNC_SUBSTRACT: 0x800A,
59+
FUNC_REVERSE_SUBTRACT: 0x800B,
60+
61+
// Blending modes
62+
ZERO: 0,
63+
ONE: 1,
64+
SRC_COLOR: 0x0300,
65+
ONE_MINUS_SRC_COLOR: 0x0301,
66+
SRC_ALPHA: 0x0302,
67+
ONE_MINUS_SRC_ALPHA: 0x0303,
68+
DST_ALPHA: 0x0304,
69+
ONE_MINUS_DST_ALPHA: 0x0305,
70+
DST_COLOR: 0x0306,
71+
ONE_MINUS_DST_COLOR: 0x0307,
72+
SRC_ALPHA_SATURATE: 0x0308,
73+
CONSTANT_COLOR: 0x8001,
74+
ONE_MINUS_CONSTANT_COLOR: 0x8002,
75+
CONSTANT_ALPHA: 0x8003,
76+
ONE_MINUS_CONSTANT_ALPHA: 0x8004,
4077

4178
// Buffers
4279
ARRAY_BUFFER: 0x8892,
@@ -51,7 +88,37 @@ var WebGLConstants = {
5188
LINEAR_MIPMAP_LINEAR: 0x2703,
5289
REPEAT: 0x2901,
5390
CLAMP_TO_EDGE: 0x812F,
54-
MIRRORED_REPEAT: 0x8370
91+
MIRRORED_REPEAT: 0x8370,
92+
93+
// ---------------------------------------------------------------------------
94+
// EXTENSIONS
95+
// ---------------------------------------------------------------------------
96+
97+
// WEBGL_depth_texture
98+
UNSIGNED_INT_24_8_WEBGL: 0x84FA,
99+
100+
// EXT_blend_minmax
101+
MIN_EXT: 0x8007,
102+
MAX_EXT: 0x8008,
103+
104+
// OES_texture_half_float
105+
HALF_FLOAT_OES: 0x8D61,
106+
107+
// WEBGL_compressed_texture_s3tc
108+
COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83F0,
109+
COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83F1,
110+
COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83F2,
111+
COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83F3,
112+
113+
// WEBGL_compressed_texture_pvrtc
114+
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8C00,
115+
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8C01,
116+
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8C02,
117+
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8C03,
118+
119+
// WEBGL_compressed_texture_etc1
120+
COMPRESSED_RGB_ETC1_WEBGL: 0x8D64
121+
55122
};
56123

57124
export { WebGLConstants };

src/renderers/webgl/WebGLState.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5+
<<<<<<< HEAD
56
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants.js';
67
import { Vector4 } from '../../math/Vector4.js';
8+
=======
9+
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants';
10+
import { Vector4 } from '../../math/Vector4';
11+
import { toGL } from './WebGLUtils';
12+
>>>>>>> Replaced WebGLUtils.convert with toGL
713

8-
function WebGLState( gl, extensions, utils ) {
14+
function WebGLState( gl, extensions ) {
915

1016
function ColorBuffer() {
1117

@@ -621,7 +627,7 @@ function WebGLState( gl, extensions, utils ) {
621627

622628
if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
623629

624-
gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
630+
gl.blendEquationSeparate( toGL( blendEquation ), toGL( blendEquationAlpha ) );
625631

626632
currentBlendEquation = blendEquation;
627633
currentBlendEquationAlpha = blendEquationAlpha;
@@ -630,7 +636,7 @@ function WebGLState( gl, extensions, utils ) {
630636

631637
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
632638

633-
gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
639+
gl.blendFuncSeparate( toGL( blendSrc ), toGL( blendDst ), toGL( blendSrcAlpha ), toGL( blendDstAlpha ) );
634640

635641
currentBlendSrc = blendSrc;
636642
currentBlendDst = blendDst;

src/renderers/webgl/WebGLTextures.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5+
<<<<<<< HEAD
56
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants.js';
67
import { _Math } from '../../math/Math.js';
8+
=======
9+
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
10+
import { _Math } from '../../math/Math';
11+
import { toGL } from './WebGLUtils';
12+
>>>>>>> Replaced WebGLUtils.convert with toGL
713

8-
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
14+
function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMemory ) {
915

1016
var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
1117

@@ -264,8 +270,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
264270

265271
var image = cubeImage[ 0 ],
266272
isPowerOfTwoImage = isPowerOfTwo( image ),
267-
glFormat = utils.convert( texture.format ),
268-
glType = utils.convert( texture.type );
273+
glFormat = toGL( texture.format ),
274+
glType = toGL( texture.type );
269275

270276
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
271277

@@ -349,11 +355,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
349355

350356
if ( isPowerOfTwoImage ) {
351357

352-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
353-
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
358+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, toGL( texture.wrapS ) );
359+
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, toGL( texture.wrapT ) );
354360

355-
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
356-
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
361+
_gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, toGL( texture.magFilter ) );
362+
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, toGL( texture.minFilter ) );
357363

358364
} else {
359365

@@ -425,8 +431,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
425431
}
426432

427433
var isPowerOfTwoImage = isPowerOfTwo( image ),
428-
glFormat = utils.convert( texture.format ),
429-
glType = utils.convert( texture.type );
434+
glFormat = toGL( texture.format ),
435+
glType = toGL( texture.type );
430436

431437
setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
432438

@@ -460,7 +466,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
460466
console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
461467

462468
texture.type = UnsignedShortType;
463-
glType = utils.convert( texture.type );
469+
glType = toGL( texture.type );
464470

465471
}
466472

@@ -480,7 +486,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
480486
console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
481487

482488
texture.type = UnsignedInt248Type;
483-
glType = utils.convert( texture.type );
489+
glType = toGL( texture.type );
484490

485491
}
486492

@@ -577,8 +583,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
577583
// Setup storage for target texture and bind it to correct framebuffer
578584
function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
579585

580-
var glFormat = utils.convert( renderTarget.texture.format );
581-
var glType = utils.convert( renderTarget.texture.type );
586+
var glFormat = toGL( renderTarget.texture.format );
587+
var glType = toGL( renderTarget.texture.type );
582588
state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
583589
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
584590
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );

0 commit comments

Comments
 (0)