Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/renderers/webgl/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/

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

function WebGLState( gl, extensions, utils, capabilities ) {
Expand Down Expand Up @@ -529,6 +529,28 @@ function WebGLState( gl, extensions, utils, capabilities ) {

}

var equationToGL = {
[ AddEquation ]: gl.FUNC_ADD,
[ SubtractEquation ]: gl.FUNC_SUBTRACT,
[ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT,
[ MinEquation ]: isWebGL2 ? gl.MIN : extensions.get( 'EXT_blend_minmax' ).MIN_EXT,
[ MaxEquation ]: isWebGL2 ? gl.MAX : extensions.get( 'EXT_blend_minmax' ).MAX_EXT
};

var factorToGL = {
[ ZeroFactor ]: gl.ZERO,
[ OneFactor ]: gl.ONE,
[ SrcColorFactor ]: gl.SRC_COLOR,
[ SrcAlphaFactor ]: gl.SRC_ALPHA,
[ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE,
[ DstColorFactor ]: gl.DST_COLOR,
[ DstAlphaFactor ]: gl.DST_ALPHA,
[ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR,
[ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA,
[ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR,
[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
};

function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {

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

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

gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );

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

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( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );

currentBlendSrc = blendSrc;
currentBlendDst = blendDst;
Expand Down
32 changes: 23 additions & 9 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/

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

function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
Expand Down Expand Up @@ -522,23 +522,37 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

function setTextureParameters( textureType, texture, supportsMips ) {
var wrappingToGL = {
[ RepeatWrapping ]: _gl.REPEAT,
[ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE,
[ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT
};

var filterToGL = {
[ NearestFilter ]: _gl.NEAREST,
[ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST,
[ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR,

var extension;
[ LinearFilter ]: _gl.LINEAR,
[ LinearMipmapNearestFilter ]: _gl.LINEAR_MIPMAP_NEAREST,
[ LinearMipmapLinearFilter ]: _gl.LINEAR_MIPMAP_LINEAR
};

function setTextureParameters( textureType, texture, supportsMips ) {

if ( supportsMips ) {

_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, wrappingToGL[ texture.wrapS ] );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );

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

_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, utils.convert( texture.wrapR ) );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );

}

_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, filterToGL[ texture.magFilter ] );
_gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );

} else {

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

}

extension = extensions.get( 'EXT_texture_filter_anisotropic' );
var extension = extensions.get( 'EXT_texture_filter_anisotropic' );

if ( extension ) {

Expand Down
51 changes: 1 addition & 50 deletions src/renderers/webgl/WebGLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author thespite / http://www.twitter.com/thespite
*/

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';
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';

function WebGLUtils( gl, extensions, capabilities ) {

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

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;
Expand Down Expand Up @@ -55,23 +43,6 @@ function WebGLUtils( gl, extensions, capabilities ) {
if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
if ( p === RedFormat ) return gl.RED;

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 ) {

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

}

if ( p === MinEquation || p === MaxEquation ) {

if ( isWebGL2 ) {

if ( p === MinEquation ) return gl.MIN;
if ( p === MaxEquation ) return gl.MAX;

}

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 ) {

if ( isWebGL2 ) return gl.UNSIGNED_INT_24_8;
Expand Down