Skip to content

Commit eb02143

Browse files
committed
Replaced WebGLUtils.convert with toGL
1 parent 2637dc5 commit eb02143

File tree

5 files changed

+193
-132
lines changed

5 files changed

+193
-132
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';
3131
import { WebGLClipping } from './webgl/WebGLClipping';
3232
import { Frustum } from '../math/Frustum';
3333
import { Vector4 } from '../math/Vector4';
34-
import { WebGLUtils } from './webgl/WebGLUtils';
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 );
@@ -2451,14 +2447,14 @@ function WebGLRenderer( parameters ) {
24512447
var textureFormat = texture.format;
24522448
var textureType = texture.type;
24532449

2454-
if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
2450+
if ( textureFormat !== RGBAFormat && toGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
24552451

24562452
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
24572453
return;
24582454

24592455
}
24602456

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

@@ -2473,7 +2469,7 @@ function WebGLRenderer( parameters ) {
24732469

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

2476-
_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
2472+
_gl.readPixels( x, y, width, height, toGL( textureFormat ), toGL( textureType ), buffer );
24772473

24782474
}
24792475

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants';
66
import { Vector4 } from '../../math/Vector4';
7+
import { toGL } from './WebGLUtils';
78

8-
function WebGLState( gl, extensions, utils ) {
9+
function WebGLState( gl, extensions ) {
910

1011
function ColorBuffer() {
1112

@@ -621,7 +622,7 @@ function WebGLState( gl, extensions, utils ) {
621622

622623
if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
623624

624-
gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
625+
gl.blendEquationSeparate( toGL( blendEquation ), toGL( blendEquationAlpha ) );
625626

626627
currentBlendEquation = blendEquation;
627628
currentBlendEquationAlpha = blendEquationAlpha;
@@ -630,7 +631,7 @@ function WebGLState( gl, extensions, utils ) {
630631

631632
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
632633

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

635636
currentBlendSrc = blendSrc;
636637
currentBlendDst = blendDst;

src/renderers/webgl/WebGLTextures.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
66
import { _Math } from '../../math/Math';
7+
import { toGL } from './WebGLUtils';
78

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

1011
var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
1112

@@ -264,8 +265,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
264265

265266
var image = cubeImage[ 0 ],
266267
isPowerOfTwoImage = isPowerOfTwo( image ),
267-
glFormat = utils.convert( texture.format ),
268-
glType = utils.convert( texture.type );
268+
glFormat = toGL( texture.format ),
269+
glType = toGL( texture.type );
269270

270271
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
271272

@@ -349,11 +350,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
349350

350351
if ( isPowerOfTwoImage ) {
351352

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

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

358359
} else {
359360

@@ -425,8 +426,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
425426
}
426427

427428
var isPowerOfTwoImage = isPowerOfTwo( image ),
428-
glFormat = utils.convert( texture.format ),
429-
glType = utils.convert( texture.type );
429+
glFormat = toGL( texture.format ),
430+
glType = toGL( texture.type );
430431

431432
setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
432433

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

462463
texture.type = UnsignedShortType;
463-
glType = utils.convert( texture.type );
464+
glType = toGL( texture.type );
464465

465466
}
466467

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

482483
texture.type = UnsignedInt248Type;
483-
glType = utils.convert( texture.type );
484+
glType = toGL( texture.type );
484485

485486
}
486487

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

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

0 commit comments

Comments
 (0)