diff --git a/examples/js/exporters/GLTFExporter.js b/examples/js/exporters/GLTFExporter.js index e07e41262ee88b..aafa6b13ecba24 100644 --- a/examples/js/exporters/GLTFExporter.js +++ b/examples/js/exporters/GLTFExporter.js @@ -2,43 +2,6 @@ * @author fernandojsg / http://fernandojsg.com */ -//------------------------------------------------------------------------------ -// Constants -//------------------------------------------------------------------------------ -var WEBGL_CONSTANTS = { - POINTS: 0x0000, - LINES: 0x0001, - LINE_LOOP: 0x0002, - LINE_STRIP: 0x0003, - TRIANGLES: 0x0004, - TRIANGLE_STRIP: 0x0005, - TRIANGLE_FAN: 0x0006, - - UNSIGNED_BYTE: 0x1401, - UNSIGNED_SHORT: 0x1403, - FLOAT: 0x1406, - UNSIGNED_INT: 0x1405, - ARRAY_BUFFER: 0x8892, - ELEMENT_ARRAY_BUFFER: 0x8893, - - NEAREST: 0x2600, - LINEAR: 0x2601, - NEAREST_MIPMAP_NEAREST: 0x2700, - LINEAR_MIPMAP_NEAREST: 0x2701, - NEAREST_MIPMAP_LINEAR: 0x2702, - LINEAR_MIPMAP_LINEAR: 0x2703 -}; - -var THREE_TO_WEBGL = { - // @TODO Replace with computed property name [THREE.*] when available on es6 - 1003: WEBGL_CONSTANTS.NEAREST, - 1004: WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST, - 1005: WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR, - 1006: WEBGL_CONSTANTS.LINEAR, - 1007: WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST, - 1008: WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR -}; - //------------------------------------------------------------------------------ // GLTF Exporter //------------------------------------------------------------------------------ @@ -186,7 +149,7 @@ THREE.GLTFExporter.prototype = { } var offset = 0; - var componentSize = componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4; + var componentSize = componentType === THREE.WebGLConstants.UNSIGNED_SHORT ? 2 : 4; // Create a new dataview and dump the attribute's array into it var byteLength = count * attribute.itemSize * componentSize; @@ -199,15 +162,15 @@ THREE.GLTFExporter.prototype = { var value = attribute.array[ i * attribute.itemSize + a ]; - if ( componentType === WEBGL_CONSTANTS.FLOAT ) { + if ( componentType === THREE.WebGLConstants.FLOAT ) { dataView.setFloat32( offset, value, true ); - } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_INT ) { + } else if ( componentType === THREE.WebGLConstants.UNSIGNED_INT ) { dataView.setUint8( offset, value, true ); - } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ) { + } else if ( componentType === THREE.WebGLConstants.UNSIGNED_SHORT ) { dataView.setUint16( offset, value, true ); @@ -234,7 +197,7 @@ THREE.GLTFExporter.prototype = { */ function processBufferView( data, componentType, start, count ) { - var isVertexAttributes = componentType === WEBGL_CONSTANTS.FLOAT; + var isVertexAttributes = componentType === THREE.WebGLConstants.FLOAT; if ( ! outputJSON.bufferViews ) { @@ -242,7 +205,7 @@ THREE.GLTFExporter.prototype = { } - var componentSize = componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ? 2 : 4; + var componentSize = componentType === THREE.WebGLConstants.UNSIGNED_SHORT ? 2 : 4; // Create a new dataview and dump the attribute's array into it var byteLength = count * data.itemSize * componentSize; @@ -253,7 +216,7 @@ THREE.GLTFExporter.prototype = { byteOffset: byteOffset, byteLength: byteLength, byteStride: data.itemSize * componentSize, - target: isVertexAttributes ? WEBGL_CONSTANTS.ARRAY_BUFFER : WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER + target: isVertexAttributes ? THREE.WebGLConstants.ARRAY_BUFFER : THREE.WebGLConstants.ELEMENT_ARRAY_BUFFER }; @@ -300,15 +263,15 @@ THREE.GLTFExporter.prototype = { // Detect the component type of the attribute array (float, uint or ushort) if ( attribute.array.constructor === Float32Array ) { - componentType = WEBGL_CONSTANTS.FLOAT; + componentType = THREE.WebGLConstants.FLOAT; } else if ( attribute.array.constructor === Uint32Array ) { - componentType = WEBGL_CONSTANTS.UNSIGNED_INT; + componentType = THREE.WebGLConstants.UNSIGNED_INT; } else if ( attribute.array.constructor === Uint16Array ) { - componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT; + componentType = THREE.WebGLConstants.UNSIGNED_SHORT; } else { @@ -405,10 +368,10 @@ THREE.GLTFExporter.prototype = { var gltfSampler = { - magFilter: THREE_TO_WEBGL[ map.magFilter ], - minFilter: THREE_TO_WEBGL[ map.minFilter ], - wrapS: THREE_TO_WEBGL[ map.wrapS ], - wrapT: THREE_TO_WEBGL[ map.wrapT ] + magFilter: THREE.WebGLUtils.toGL( map.magFilter ), + minFilter: THREE.WebGLUtils.toGL( map.minFilter ), + wrapS: THREE.WebGLUtils.toGL( map.wrapS ), + wrapT: THREE.WebGLUtils.toGL( map.wrapT) }; @@ -639,19 +602,19 @@ THREE.GLTFExporter.prototype = { // Use the correct mode if ( mesh instanceof THREE.LineSegments ) { - mode = WEBGL_CONSTANTS.LINES; + mode = THREE.WebGLConstants.LINES; } else if ( mesh instanceof THREE.LineLoop ) { - mode = WEBGL_CONSTANTS.LINE_LOOP; + mode = THREE.WebGLConstants.LINE_LOOP; } else if ( mesh instanceof THREE.Line ) { - mode = WEBGL_CONSTANTS.LINE_STRIP; + mode = THREE.WebGLConstants.LINE_STRIP; } else if ( mesh instanceof THREE.Points ) { - mode = WEBGL_CONSTANTS.POINTS; + mode = THREE.WebGLConstants.POINTS; } else { @@ -666,15 +629,15 @@ THREE.GLTFExporter.prototype = { if ( mesh.drawMode === THREE.TriangleFanDrawMode ) { console.warn( 'GLTFExporter: TriangleFanDrawMode and wireframe incompatible.' ); - mode = WEBGL_CONSTANTS.TRIANGLE_FAN; + mode = THREE.WebGLConstants.TRIANGLE_FAN; } else if ( mesh.drawMode === THREE.TriangleStripDrawMode ) { - mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINE_STRIP : WEBGL_CONSTANTS.TRIANGLE_STRIP; + mode = mesh.material.wireframe ? THREE.WebGLConstants.LINE_STRIP : THREE.WebGLConstants.TRIANGLE_STRIP; } else { - mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES; + mode = mesh.material.wireframe ? THREE.WebGLConstants.LINES : THREE.WebGLConstants.TRIANGLES; } diff --git a/examples/js/loaders/GLTFLoader.js b/examples/js/loaders/GLTFLoader.js index 9ccd0d35ee0257..95e70168a71dd8 100644 --- a/examples/js/loaders/GLTFLoader.js +++ b/examples/js/loaders/GLTFLoader.js @@ -836,124 +836,7 @@ THREE.GLTFLoader = ( function () { /*********************************/ /********** INTERNALS ************/ /*********************************/ - - /* CONSTANTS */ - - var WEBGL_CONSTANTS = { - FLOAT: 5126, - //FLOAT_MAT2: 35674, - FLOAT_MAT3: 35675, - FLOAT_MAT4: 35676, - FLOAT_VEC2: 35664, - FLOAT_VEC3: 35665, - FLOAT_VEC4: 35666, - LINEAR: 9729, - REPEAT: 10497, - SAMPLER_2D: 35678, - POINTS: 0, - LINES: 1, - LINE_LOOP: 2, - LINE_STRIP: 3, - TRIANGLES: 4, - TRIANGLE_STRIP: 5, - TRIANGLE_FAN: 6, - UNSIGNED_BYTE: 5121, - UNSIGNED_SHORT: 5123 - }; - - var WEBGL_TYPE = { - 5126: Number, - //35674: THREE.Matrix2, - 35675: THREE.Matrix3, - 35676: THREE.Matrix4, - 35664: THREE.Vector2, - 35665: THREE.Vector3, - 35666: THREE.Vector4, - 35678: THREE.Texture - }; - - var WEBGL_COMPONENT_TYPES = { - 5120: Int8Array, - 5121: Uint8Array, - 5122: Int16Array, - 5123: Uint16Array, - 5125: Uint32Array, - 5126: Float32Array - }; - - var WEBGL_FILTERS = { - 9728: THREE.NearestFilter, - 9729: THREE.LinearFilter, - 9984: THREE.NearestMipMapNearestFilter, - 9985: THREE.LinearMipMapNearestFilter, - 9986: THREE.NearestMipMapLinearFilter, - 9987: THREE.LinearMipMapLinearFilter - }; - - var WEBGL_WRAPPINGS = { - 33071: THREE.ClampToEdgeWrapping, - 33648: THREE.MirroredRepeatWrapping, - 10497: THREE.RepeatWrapping - }; - - var WEBGL_TEXTURE_FORMATS = { - 6406: THREE.AlphaFormat, - 6407: THREE.RGBFormat, - 6408: THREE.RGBAFormat, - 6409: THREE.LuminanceFormat, - 6410: THREE.LuminanceAlphaFormat - }; - - var WEBGL_TEXTURE_DATATYPES = { - 5121: THREE.UnsignedByteType, - 32819: THREE.UnsignedShort4444Type, - 32820: THREE.UnsignedShort5551Type, - 33635: THREE.UnsignedShort565Type - }; - - var WEBGL_SIDES = { - 1028: THREE.BackSide, // Culling front - 1029: THREE.FrontSide // Culling back - //1032: THREE.NoSide // Culling front and back, what to do? - }; - - var WEBGL_DEPTH_FUNCS = { - 512: THREE.NeverDepth, - 513: THREE.LessDepth, - 514: THREE.EqualDepth, - 515: THREE.LessEqualDepth, - 516: THREE.GreaterEqualDepth, - 517: THREE.NotEqualDepth, - 518: THREE.GreaterEqualDepth, - 519: THREE.AlwaysDepth - }; - - var WEBGL_BLEND_EQUATIONS = { - 32774: THREE.AddEquation, - 32778: THREE.SubtractEquation, - 32779: THREE.ReverseSubtractEquation - }; - - var WEBGL_BLEND_FUNCS = { - 0: THREE.ZeroFactor, - 1: THREE.OneFactor, - 768: THREE.SrcColorFactor, - 769: THREE.OneMinusSrcColorFactor, - 770: THREE.SrcAlphaFactor, - 771: THREE.OneMinusSrcAlphaFactor, - 772: THREE.DstAlphaFactor, - 773: THREE.OneMinusDstAlphaFactor, - 774: THREE.DstColorFactor, - 775: THREE.OneMinusDstColorFactor, - 776: THREE.SrcAlphaSaturateFactor - // The followings are not supported by Three.js yet - //32769: CONSTANT_COLOR, - //32770: ONE_MINUS_CONSTANT_COLOR, - //32771: CONSTANT_ALPHA, - //32772: ONE_MINUS_CONSTANT_COLOR - }; - - var WEBGL_TYPE_SIZES = { + var WEBGL_TYPE_SIZES = { 'SCALAR': 1, 'VEC2': 2, 'VEC3': 3, @@ -1467,7 +1350,7 @@ THREE.GLTFLoader = ( function () { return parser.getDependency( 'bufferView', accessor.bufferView ).then( function ( bufferView ) { var itemSize = WEBGL_TYPE_SIZES[ accessor.type ]; - var TypedArray = WEBGL_COMPONENT_TYPES[ accessor.componentType ]; + var TypedArray = THREE.WebGLUtils.fromGL[ accessor.componentType ]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12. var elementBytes = TypedArray.BYTES_PER_ELEMENT; @@ -1561,24 +1444,24 @@ THREE.GLTFLoader = ( function () { if ( textureDef.name !== undefined ) texture.name = textureDef.name; - texture.format = textureDef.format !== undefined ? WEBGL_TEXTURE_FORMATS[ textureDef.format ] : THREE.RGBAFormat; + texture.format = textureDef.format !== undefined ? THREE.WebGLUtils.fromGL[ textureDef.format ] : THREE.RGBAFormat; - if ( textureDef.internalFormat !== undefined && texture.format !== WEBGL_TEXTURE_FORMATS[ textureDef.internalFormat ] ) { + if ( textureDef.internalFormat !== undefined && texture.format !== THREE.WebGLUtils.fromGL[ textureDef.internalFormat ] ) { console.warn( 'THREE.GLTFLoader: Three.js does not support texture internalFormat which is different from texture format. ' + 'internalFormat will be forced to be the same value as format.' ); } - texture.type = textureDef.type !== undefined ? WEBGL_TEXTURE_DATATYPES[ textureDef.type ] : THREE.UnsignedByteType; + texture.type = textureDef.type !== undefined ? THREE.WebGLUtils.fromGL[ textureDef.type ] : THREE.UnsignedByteType; var samplers = json.samplers || {}; var sampler = samplers[ textureDef.sampler ] || {}; - texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter; - texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || THREE.LinearMipMapLinearFilter; - texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || THREE.RepeatWrapping; - texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || THREE.RepeatWrapping; + texture.magFilter = THREE.WebGLUtils.fromGL[ sampler.magFilter ] || THREE.LinearFilter; + texture.minFilter = THREE.WebGLUtils.fromGL[ sampler.minFilter ] || THREE.LinearMipMapLinearFilter; + texture.wrapS = THREE.WebGLUtils.fromGL[ sampler.wrapS ] || THREE.RepeatWrapping; + texture.wrapT = THREE.WebGLUtils.fromGL[ sampler.wrapT ] || THREE.RepeatWrapping; return texture; @@ -1951,33 +1834,33 @@ THREE.GLTFLoader = ( function () { var mesh; - if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === undefined ) { + if ( primitive.mode === THREE.WebGLConstants.TRIANGLES || primitive.mode === undefined ) { mesh = new THREE.Mesh( geometry, material ); - } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) { + } else if ( primitive.mode === THREE.WebGLConstants.TRIANGLE_STRIP ) { mesh = new THREE.Mesh( geometry, material ); mesh.drawMode = THREE.TriangleStripDrawMode; - } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) { + } else if ( primitive.mode === THREE.WebGLConstants.TRIANGLE_FAN ) { mesh = new THREE.Mesh( geometry, material ); mesh.drawMode = THREE.TriangleFanDrawMode; - } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) { + } else if ( primitive.mode === THREE.WebGLConstants.LINES ) { mesh = new THREE.LineSegments( geometry, material ); - } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) { + } else if ( primitive.mode === THREE.WebGLConstants.LINE_STRIP ) { mesh = new THREE.Line( geometry, material ); - } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) { + } else if ( primitive.mode === THREE.WebGLConstants.LINE_LOOP ) { mesh = new THREE.LineLoop( geometry, material ); - } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) { + } else if ( primitive.mode === THREE.WebGLConstants.POINTS ) { mesh = new THREE.Points( geometry, material ); diff --git a/src/Three.js b/src/Three.js index 0d46c4a04e32b2..10c2c18ab604e1 100644 --- a/src/Three.js +++ b/src/Three.js @@ -156,5 +156,6 @@ export { Curve } from './extras/core/Curve.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; export { SceneUtils } from './extras/SceneUtils.js'; export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; +export { WebGLConstants } from './renderers/webgl/WebGLConstants.js'; export * from './constants.js'; export * from './Three.Legacy.js'; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index c833e294d8525a..29182f6300003c 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -246,8 +246,6 @@ function WebGLRenderer( parameters ) { var background, morphtargets, bufferRenderer, indexedBufferRenderer; var flareRenderer, spriteRenderer; - var utils; - function initGLContext() { extensions = new WebGLExtensions( _gl ); @@ -260,16 +258,14 @@ function WebGLRenderer( parameters ) { extensions.get( 'OES_element_index_uint' ); extensions.get( 'ANGLE_instanced_arrays' ); - utils = new WebGLUtils( _gl, extensions ); - capabilities = new WebGLCapabilities( _gl, extensions, parameters ); - state = new WebGLState( _gl, extensions, utils ); + state = new WebGLState( _gl, extensions ); state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) ); state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) ); properties = new WebGLProperties(); - textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory ); + textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, _infoMemory ); attributes = new WebGLAttributes( _gl ); geometries = new WebGLGeometries( _gl, attributes, _infoMemory ); objects = new WebGLObjects( geometries, _infoRender ); @@ -2479,14 +2475,14 @@ function WebGLRenderer( parameters ) { var textureFormat = texture.format; var textureType = texture.type; - if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) { + if ( textureFormat !== RGBAFormat && WebGLUtils.toGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) { console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' ); return; } - if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513) + if ( textureType !== UnsignedByteType && WebGLUtils.toGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513) ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) { @@ -2501,7 +2497,7 @@ function WebGLRenderer( parameters ) { if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) { - _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer ); + _gl.readPixels( x, y, width, height, WebGLUtils.toGL( textureFormat ), WebGLUtils.toGL( textureType ), buffer ); } diff --git a/src/renderers/webgl/WebGLConstants.js b/src/renderers/webgl/WebGLConstants.js new file mode 100644 index 00000000000000..479f91b875907a --- /dev/null +++ b/src/renderers/webgl/WebGLConstants.js @@ -0,0 +1,124 @@ +/** + * @author fernandojsg / http://fernandojsg.com + */ + +var WebGLConstants = { + // Rendering primitives + POINTS: 0x0000, + LINES: 0x0001, + LINE_LOOP: 0x0002, + LINE_STRIP: 0x0003, + TRIANGLES: 0x0004, + TRIANGLE_STRIP: 0x0005, + TRIANGLE_FAN: 0x0006, + + // Uniform types + FLOAT_VEC2: 0x8B50, + FLOAT_VEC3: 0x8B51, + FLOAT_VEC4: 0x8B52, + INT_VEC2: 0x8B53, + INT_VEC3: 0x8B54, + INT_VEC4: 0x8B55, + BOOL: 0x8B56, + BOOL_VEC2: 0x8B57, + BOOL_VEC3: 0x8B58, + BOOL_VEC4: 0x8B59, + FLOAT_MAT2: 0x8B5A, + FLOAT_MAT3: 0x8B5B, + FLOAT_MAT4: 0x8B5C, + SAMPLER_2D: 0x8B5E, + SAMPLER_CUBE: 0x8B60, + + // Data types + BYTE: 0x1400, + UNSIGNED_BYTE: 0x1401, + SHORT: 0x1402, + UNSIGNED_SHORT: 0x1403, + INT: 0x1404, + UNSIGNED_INT: 0x1405, + FLOAT: 0x1406, + DEPTH_COMPONENT: 0x1902, + DEPTH_STENCIL: 0x84F9, + + // Pixel types + UNSIGNED_SHORT_5_5_5_1: 32820, + UNSIGNED_SHORT_4_4_4_4: 32819, + UNSIGNED_SHORT_5_6_5: 33635, + + // Pixel formats + DEPTH_COMPONENT: 0x1902, + ALPHA: 0x1906, + RGB: 0x1907, + RGBA: 0x1908, + LUMINANCE: 0x1909, + LUMINANCE_ALPHA: 0x190A, + + // Blending equations + FUNC_ADD: 0x8006, + FUNC_SUBSTRACT: 0x800A, + FUNC_REVERSE_SUBTRACT: 0x800B, + + // Blending modes + ZERO: 0, + ONE: 1, + SRC_COLOR: 0x0300, + ONE_MINUS_SRC_COLOR: 0x0301, + SRC_ALPHA: 0x0302, + ONE_MINUS_SRC_ALPHA: 0x0303, + DST_ALPHA: 0x0304, + ONE_MINUS_DST_ALPHA: 0x0305, + DST_COLOR: 0x0306, + ONE_MINUS_DST_COLOR: 0x0307, + SRC_ALPHA_SATURATE: 0x0308, + CONSTANT_COLOR: 0x8001, + ONE_MINUS_CONSTANT_COLOR: 0x8002, + CONSTANT_ALPHA: 0x8003, + ONE_MINUS_CONSTANT_ALPHA: 0x8004, + + // Buffers + ARRAY_BUFFER: 0x8892, + ELEMENT_ARRAY_BUFFER: 0x8893, + + // Textures + NEAREST: 0x2600, + LINEAR: 0x2601, + NEAREST_MIPMAP_NEAREST: 0x2700, + LINEAR_MIPMAP_NEAREST: 0x2701, + NEAREST_MIPMAP_LINEAR: 0x2702, + LINEAR_MIPMAP_LINEAR: 0x2703, + REPEAT: 0x2901, + CLAMP_TO_EDGE: 0x812F, + MIRRORED_REPEAT: 0x8370, + + // --------------------------------------------------------------------------- + // EXTENSIONS + // --------------------------------------------------------------------------- + + // WEBGL_depth_texture + UNSIGNED_INT_24_8_WEBGL: 0x84FA, + + // EXT_blend_minmax + MIN_EXT: 0x8007, + MAX_EXT: 0x8008, + + // OES_texture_half_float + HALF_FLOAT_OES: 0x8D61, + + // WEBGL_compressed_texture_s3tc + COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83F0, + COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83F1, + COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83F2, + COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83F3, + + // WEBGL_compressed_texture_pvrtc + COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8C00, + COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8C01, + COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8C02, + COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8C03, + + // WEBGL_compressed_texture_etc1 + COMPRESSED_RGB_ETC1_WEBGL: 0x8D64 + +}; + +export { WebGLConstants }; diff --git a/src/renderers/webgl/WebGLState.js b/src/renderers/webgl/WebGLState.js index 7ab6555f9c1912..83d210ae1f7b2e 100644 --- a/src/renderers/webgl/WebGLState.js +++ b/src/renderers/webgl/WebGLState.js @@ -4,8 +4,9 @@ import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, DoubleSide, BackSide } from '../../constants.js'; import { Vector4 } from '../../math/Vector4.js'; +import { WebGLUtils } from './WebGLUtils'; -function WebGLState( gl, extensions, utils ) { +function WebGLState( gl, extensions ) { function ColorBuffer() { @@ -621,7 +622,7 @@ function WebGLState( gl, extensions, utils ) { if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) { - gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) ); + gl.blendEquationSeparate( WebGLUtils.toGL( blendEquation ), WebGLUtils.toGL( blendEquationAlpha ) ); currentBlendEquation = blendEquation; currentBlendEquationAlpha = blendEquationAlpha; @@ -630,7 +631,7 @@ function WebGLState( gl, extensions, utils ) { if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) { - gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) ); + gl.blendFuncSeparate( WebGLUtils.toGL( blendSrc ), WebGLUtils.toGL( blendDst ), WebGLUtils.toGL( blendSrcAlpha ), WebGLUtils.toGL( blendDstAlpha ) ); currentBlendSrc = blendSrc; currentBlendDst = blendDst; diff --git a/src/renderers/webgl/WebGLTextures.js b/src/renderers/webgl/WebGLTextures.js index f51a1c3443337f..a867e931ef3759 100644 --- a/src/renderers/webgl/WebGLTextures.js +++ b/src/renderers/webgl/WebGLTextures.js @@ -4,8 +4,9 @@ import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants.js'; import { _Math } from '../../math/Math.js'; +import { WebGLUtils } from './WebGLUtils'; -function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) { +function WebGLTextures( _gl, extensions, state, properties, capabilities, infoMemory ) { var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof window.WebGL2RenderingContext ); @@ -263,9 +264,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } var image = cubeImage[ 0 ], - isPowerOfTwoImage = isPowerOfTwo( image ), - glFormat = utils.convert( texture.format ), - glType = utils.convert( texture.type ); + isPowerOfTwoImage = isPowerOfTwo( image ), + glFormat = WebGLUtils.toGL( texture.format ), + glType = WebGLUtils.toGL( texture.type ); setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage ); @@ -349,11 +350,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, if ( isPowerOfTwoImage ) { - _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) ); - _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) ); + _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, WebGLUtils.toGL( texture.wrapS ) ); + _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, WebGLUtils.toGL( texture.wrapT ) ); - _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) ); - _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) ); + _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, WebGLUtils.toGL( texture.magFilter ) ); + _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, WebGLUtils.toGL( texture.minFilter ) ); } else { @@ -425,8 +426,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } var isPowerOfTwoImage = isPowerOfTwo( image ), - glFormat = utils.convert( texture.format ), - glType = utils.convert( texture.type ); + glFormat = WebGLUtils.toGL( texture.format ), + glType = WebGLUtils.toGL( texture.type ); setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage ); @@ -460,7 +461,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' ); texture.type = UnsignedShortType; - glType = utils.convert( texture.type ); + glType = WebGLUtils.toGL( texture.type ); } @@ -480,7 +481,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' ); texture.type = UnsignedInt248Type; - glType = utils.convert( texture.type ); + glType = WebGLUtils.toGL( texture.type ); } @@ -577,8 +578,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, // Setup storage for target texture and bind it to correct framebuffer function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) { - var glFormat = utils.convert( renderTarget.texture.format ); - var glType = utils.convert( renderTarget.texture.type ); + var glFormat = WebGLUtils.toGL( renderTarget.texture.format ); + var glType = WebGLUtils.toGL( renderTarget.texture.type ); state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 ); diff --git a/src/renderers/webgl/WebGLUtils.js b/src/renderers/webgl/WebGLUtils.js index eff600232d6ff4..4b71c29541224a 100644 --- a/src/renderers/webgl/WebGLUtils.js +++ b/src/renderers/webgl/WebGLUtils.js @@ -1,140 +1,212 @@ /** * @author thespite / http://www.twitter.com/thespite + * @author fernandojsg / http://fernandojsg.com */ + /* jshint esversion: 6 */ + +import * as Constants from '../../constants'; +import { WebGLConstants } from './WebGLConstants'; + +//------------------------------------------------------------------------------ +// THREE TO WEBGL +//------------------------------------------------------------------------------ +var THREE_TO_WEBGL = { + + [ Constants.NearestFilter ]: WebGLConstants.NEAREST, + [ Constants.LinearFilter ]: WebGLConstants.LINEAR, + [ Constants.NearestMipMapNearestFilter ]: WebGLConstants.NEAREST_MIPMAP_NEAREST, + [ Constants.LinearMipMapNearestFilter ]: WebGLConstants.LINEAR_MIPMAP_NEAREST, + [ Constants.NearestMipMapLinearFilter ]: WebGLConstants.NEAREST_MIPMAP_LINEAR, + [ Constants.LinearMipMapLinearFilter ]: WebGLConstants.LINEAR_MIPMAP_LINEAR, + + [ Constants.RepeatWrapping ]: WebGLConstants.REPEAT, + [ Constants.ClampToEdgeWrapping ]: WebGLConstants.CLAMP_TO_EDGE, + [ Constants.MirroredRepeatWrapping ]: WebGLConstants.MIRRORED_REPEAT, + + [ Constants.NearestFilter ]: WebGLConstants.NEAREST, + [ Constants.NearestMipMapNearestFilter ]: WebGLConstants.NEAREST_MIPMAP_NEAREST, + [ Constants.NearestMipMapLinearFilter ]: WebGLConstants.NEAREST_MIPMAP_LINEAR, + + [ Constants.LinearFilter ]: WebGLConstants.LINEAR, + [ Constants.LinearMipMapNearestFilter ]: WebGLConstants.LINEAR_MIPMAP_NEAREST, + [ Constants.LinearMipMapLinearFilter ]: WebGLConstants.LINEAR_MIPMAP_LINEAR, + + [ Constants.UnsignedByteType ]: WebGLConstants.UNSIGNED_BYTE, + [ Constants.UnsignedShort4444Type ]: WebGLConstants.UNSIGNED_SHORT_4_4_4_4, + [ Constants.UnsignedShort5551Type ]: WebGLConstants.UNSIGNED_SHORT_5_5_5_1, + [ Constants.UnsignedShort565Type ]: WebGLConstants.UNSIGNED_SHORT_5_6_5, + + [ Constants.ByteType ]: WebGLConstants.BYTE, + [ Constants.ShortType ]: WebGLConstants.SHORT, + [ Constants.UnsignedShortType ]: WebGLConstants.UNSIGNED_SHORT, + [ Constants.IntType ]: WebGLConstants.INT, + [ Constants.UnsignedIntType ]: WebGLConstants.UNSIGNED_INT, + [ Constants.FloatType ]: WebGLConstants.FLOAT, + + [ Constants.AlphaFormat ]: WebGLConstants.ALPHA, + [ Constants.RGBFormat ]: WebGLConstants.RGB, + [ Constants.RGBAFormat ]: WebGLConstants.RGBA, + [ Constants.LuminanceFormat ]: WebGLConstants.LUMINANCE, + [ Constants.LuminanceAlphaFormat ]: WebGLConstants.LUMINANCE_ALPHA, + [ Constants.DepthFormat ]: WebGLConstants.DEPTH_COMPONENT, + [ Constants.DepthStencilFormat ]: WebGLConstants.DEPTH_STENCIL, + + [ Constants.AddEquation ]: WebGLConstants.FUNC_ADD, + [ Constants.SubtractEquation ]: WebGLConstants.FUNC_SUBSTRACT, + [ Constants.ReverseSubtractEquation ]: WebGLConstants.FUNC_REVERSE_SUBTRACT, + + [ Constants.ZeroFactor ]: WebGLConstants.ZERO, + [ Constants.OneFactor ]: WebGLConstants.ONE, + [ Constants.SrcColorFactor ]: WebGLConstants.SRC_COLOR, + [ Constants.OneMinusSrcColorFactor ]: WebGLConstants.ONE_MINUS_SRC_COLOR, + [ Constants.SrcAlphaFactor ]: WebGLConstants.SRC_ALPHA, + [ Constants.OneMinusSrcAlphaFactor ]: WebGLConstants.ONE_MINUS_SRC_ALPHA, + [ Constants.DstAlphaFactor ]: WebGLConstants.DST_ALPHA, + [ Constants.OneMinusDstAlphaFactor ]: WebGLConstants.ONE_MINUS_DST_ALPHA, + + [ Constants.DstColorFactor ]: WebGLConstants.DST_COLOR, + [ Constants.OneMinusDstColorFactor ]: WebGLConstants.ONE_MINUS_DST_COLOR, + [ Constants.SrcAlphaSaturateFactor ]: WebGLConstants.SRC_ALPHA_SATURATE, + + + // Extensions + [ Constants.UnsignedInt248Type ]: WebGLConstants.UNSIGNED_INT_24_8_WEBGL, + + [ Constants.MinEquation ]: WebGLConstants.MIN_EXT, + [ Constants.MaxEquation ]: WebGLConstants.MAX_EXT, + + [ Constants.HalfFloatType ]: WebGLConstants.HALF_FLOAT_OES, + + [ Constants.RGB_S3TC_DXT1_Format ]: WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT, + [ Constants.RGBA_S3TC_DXT1_Format ]: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT, + [ Constants.RGBA_S3TC_DXT3_Format ]: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT, + [ Constants.RGBA_S3TC_DXT5_Format ]: WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT, + + [ Constants.RGB_PVRTC_4BPPV1_Format ]: WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG, + [ Constants.RGB_PVRTC_2BPPV1_Format ]: WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG, + [ Constants.RGBA_PVRTC_4BPPV1_Format ]: WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, + [ Constants.RGBA_PVRTC_2BPPV1_Format ]: WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, + + [ Constants.RGB_ETC1_Format ]: WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL -import { MaxEquation, MinEquation, 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, 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'; - -function WebGLUtils( gl, extensions ) { - - function convert( p ) { - - var extension; - - if ( p === RepeatWrapping ) return gl.REPEAT; - if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE; - if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT; - - if ( p === NearestFilter ) return gl.NEAREST; - if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST; - if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR; - - if ( p === LinearFilter ) return gl.LINEAR; - if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST; - if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR; - - if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE; - if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4; - if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1; - if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5; - - if ( p === ByteType ) return gl.BYTE; - if ( p === ShortType ) return gl.SHORT; - if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT; - if ( p === IntType ) return gl.INT; - if ( p === UnsignedIntType ) return gl.UNSIGNED_INT; - if ( p === FloatType ) return gl.FLOAT; - - if ( p === HalfFloatType ) { - - extension = extensions.get( 'OES_texture_half_float' ); - - if ( extension !== null ) return extension.HALF_FLOAT_OES; - - } - - if ( p === AlphaFormat ) return gl.ALPHA; - if ( p === RGBFormat ) return gl.RGB; - if ( p === RGBAFormat ) return gl.RGBA; - if ( p === LuminanceFormat ) return gl.LUMINANCE; - if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA; - if ( p === DepthFormat ) return gl.DEPTH_COMPONENT; - if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL; - - if ( p === AddEquation ) return gl.FUNC_ADD; - if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT; - if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT; - - if ( p === ZeroFactor ) return gl.ZERO; - if ( p === OneFactor ) return gl.ONE; - if ( p === SrcColorFactor ) return gl.SRC_COLOR; - if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR; - if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA; - if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA; - if ( p === DstAlphaFactor ) return gl.DST_ALPHA; - if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA; - - if ( p === DstColorFactor ) return gl.DST_COLOR; - if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR; - if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE; - - if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || - p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) { - - extension = extensions.get( 'WEBGL_compressed_texture_s3tc' ); - - if ( extension !== null ) { - - if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; - if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; - if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; - if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; - - } - - } - - if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || - p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) { - - extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' ); - - if ( extension !== null ) { - - if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; - if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; - if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - - } - - } - - if ( p === RGB_ETC1_Format ) { - - extension = extensions.get( 'WEBGL_compressed_texture_etc1' ); - - if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL; - - } - - if ( p === MinEquation || p === MaxEquation ) { - - extension = extensions.get( 'EXT_blend_minmax' ); - - if ( extension !== null ) { - - if ( p === MinEquation ) return extension.MIN_EXT; - if ( p === MaxEquation ) return extension.MAX_EXT; - - } - - } - - if ( p === UnsignedInt248Type ) { - - extension = extensions.get( 'WEBGL_depth_texture' ); - - if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL; - - } +} - return 0; +//------------------------------------------------------------------------------ +// WEBGL TO THREE +//------------------------------------------------------------------------------ +var WEBGL_TO_THREE = { + + // Types + 5126: Number, + //35674: THREE.Matrix2, + 35675: THREE.Matrix3, + 35676: THREE.Matrix4, + 35664: THREE.Vector2, + 35665: THREE.Vector3, + 35666: THREE.Vector4, + 35678: THREE.Texture, + + // Component types + 5120: Int8Array, + 5121: Uint8Array, + 5122: Int16Array, + 5123: Uint16Array, + 5125: Uint32Array, + 5126: Float32Array, + + // Filters + 9728: THREE.NearestFilter, // gl.NEAREST + 9729: THREE.LinearFilter, // gl.LINEAR + 9984: THREE.NearestMipMapNearestFilter, // gl.NEAREST_MIPMAP_NEAREST + 9985: THREE.LinearMipMapNearestFilter, // gl.LINEAR_MIPMAP_NEAREST + 9986: THREE.NearestMipMapLinearFilter, // gl.NEAREST_MIPMAP_LINEAR + 9987: THREE.LinearMipMapLinearFilter, // gl.LINEAR_MIPMAP_LINEAR + + // Wrapping + 33071: THREE.ClampToEdgeWrapping, // gl.CLAMP_TO_EDGE + 33648: THREE.MirroredRepeatWrapping, // gl.MIRRORED_REPEAT + 10497: THREE.RepeatWrapping, // gl.REPEAT + + // Texture format + 6406: THREE.AlphaFormat, // gl.ALPHA + 6407: THREE.RGBFormat, // gl.RGB + 6408: THREE.RGBAFormat, // gl.RGBA + 6409: THREE.LuminanceFormat, // gl.LUMINANCE + 6410: THREE.LuminanceAlphaFormat, // gl.LUMINANCE_ALPHA + 6402: THREE.DepthFormat, // gl.DEPTH_COMPONENT + 34041: THREE.DepthStencilFormat, // gl.DEPTH_STENCIL + + // Data types + 5120: THREE.ByteType, // gl.BYTE + 5121: THREE.UnsignedByteType, // gl.UNSIGNED_BYTE + 5122: THREE.ShortType, // gl.SHORT + 5123: THREE.UnsignedShortType, // gl.UNSIGNED_SHORT + 5124: THREE.IntType, // gl.INT + 5125: THREE.UnsignedIntType, // gl.UNSIGNED_INT + 5126: THREE.FloatType, // gl.FLOAT + 32819: THREE.UnsignedShort4444Type, // gl.UNSIGNED_SHORT_4_4_4_4 + 32820: THREE.UnsignedShort5551Type, // gl.UNSIGNED_SHORT_5_5_5_1 + 33635: THREE.UnsignedShort565Type, // gl.UNSIGNED_SHORT_5_6_5 + + // Sides + 1028: THREE.BackSide, + 1029: THREE.FrontSide, + //1032: THREE.NoSide, + + // Depth func + 512: THREE.NeverDepth, + 513: THREE.LessDepth, + 514: THREE.EqualDepth, + 515: THREE.LessEqualDepth, + 516: THREE.GreaterEqualDepth, + 517: THREE.NotEqualDepth, + 518: THREE.GreaterEqualDepth, + 519: THREE.AlwaysDepth, + + // Blend equations + 32774: THREE.AddEquation, // gl.FUNC_ADD + 32778: THREE.SubtractEquation, // gl.FUNC_SUBTRACT + 32779: THREE.ReverseSubtractEquation, // gl.FUNC_REVERSE_SUBTRACT + + + // Blend functions + 0: THREE.ZeroFactor, // gl.ZERO + 1: THREE.OneFactor, // gl.ONE + 768: THREE.SrcColorFactor, // gl.SRC_COLOR + 769: THREE.OneMinusSrcColorFactor, // gl.ONE_MINUS_SRC_COLOR + 770: THREE.SrcAlphaFactor, // gl.SRC_ALPHA + 771: THREE.OneMinusSrcAlphaFactor, // gl.ONE_MINUS_SRC_ALPHA + 772: THREE.DstAlphaFactor, // gl.DST_ALPHA + 773: THREE.OneMinusDstAlphaFactor, // gl.ONE_MINUS_DST_ALPHA + 774: THREE.DstColorFactor, // gl.DST_COLOR + 775: THREE.OneMinusDstColorFactor, // gl.ONE_MINUS_DST_COLOR + 776: THREE.SrcAlphaSaturateFactor // gl.SRC_ALPHA_SATURATE +}; + + +var WebGLUtils = { + + /** + * Convert a WEBGL constant to THREE.js + * @param {Number} webglConstant WebGL constant + * @return {Number} Three.js constant + */ + fromGL: function( webglConstant ) { + + return WEBGL_TO_THREE[ webglConstant ]; + + }, + + /** + * Convert a THREE.js constant to WEBGL + * @param {Number} threeConstant Three.js constant + * @return {Number} WebGL constant + */ + toGL: function( threeConstant ) { + + return THREE_TO_WEBGL[ threeConstant ]; } - - return { convert: convert }; - } - export { WebGLUtils };