|
@@ -31,6 +31,7 @@ import { Vector3 } from '../math/Vector3';
|
|
import { WebGLClipping } from './webgl/WebGLClipping';
|
|
import { WebGLClipping } from './webgl/WebGLClipping';
|
|
import { Frustum } from '../math/Frustum';
|
|
import { Frustum } from '../math/Frustum';
|
|
import { Vector4 } from '../math/Vector4';
|
|
import { Vector4 } from '../math/Vector4';
|
|
|
|
+import { WebGLUtils } from '../extras/WebGLUtils';
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author supereggbert / http://www.paulbrunt.co.uk/
|
|
* @author supereggbert / http://www.paulbrunt.co.uk/
|
|
@@ -247,6 +248,8 @@ function WebGLRenderer( parameters ) {
|
|
var background, morphtargets, bufferRenderer, indexedBufferRenderer;
|
|
var background, morphtargets, bufferRenderer, indexedBufferRenderer;
|
|
var flareRenderer, spriteRenderer;
|
|
var flareRenderer, spriteRenderer;
|
|
|
|
|
|
|
|
+ var utils;
|
|
|
|
+
|
|
function initGLContext() {
|
|
function initGLContext() {
|
|
|
|
|
|
extensions = new WebGLExtensions( _gl );
|
|
extensions = new WebGLExtensions( _gl );
|
|
@@ -264,14 +267,16 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ utils = new WebGLUtils( _gl, extensions );
|
|
|
|
+
|
|
capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
|
|
|
- state = new WebGLState( _gl, extensions, paramThreeToGL );
|
|
|
|
|
|
+ state = new WebGLState( _gl, extensions, utils );
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
|
|
|
properties = new WebGLProperties();
|
|
properties = new WebGLProperties();
|
|
- textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
|
|
|
|
|
|
+ textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
|
|
attributes = new WebGLAttributes( _gl );
|
|
attributes = new WebGLAttributes( _gl );
|
|
geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
|
|
geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
|
|
objects = new WebGLObjects( geometries, _infoRender );
|
|
objects = new WebGLObjects( geometries, _infoRender );
|
|
@@ -2421,14 +2426,14 @@ function WebGLRenderer( parameters ) {
|
|
var textureFormat = texture.format;
|
|
var textureFormat = texture.format;
|
|
var textureType = texture.type;
|
|
var textureType = texture.type;
|
|
|
|
|
|
- if ( textureFormat !== RGBAFormat && paramThreeToGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
|
|
|
|
|
|
+ if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
|
|
|
|
|
|
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
|
|
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
|
|
return;
|
|
return;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( textureType !== UnsignedByteType && paramThreeToGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
|
|
|
|
|
|
+ if ( textureType !== UnsignedByteType && utils.convert( 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 === 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' ) ) ) {
|
|
! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
|
|
|
|
|
|
@@ -2443,7 +2448,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
|
|
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
|
|
|
|
|
|
- _gl.readPixels( x, y, width, height, paramThreeToGL( textureFormat ), paramThreeToGL( textureType ), buffer );
|
|
|
|
|
|
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2467,134 +2472,6 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
- // Map three.js constants to WebGL constants
|
|
|
|
-
|
|
|
|
- function paramThreeToGL( 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;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|