Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture: add disableSRGBInternalFormat flag to prevent shader recomplie #133

Open
wants to merge 1 commit into
base: r137-dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ function WebGLRenderer( parameters = {} ) {

}

if ( capabilities.isWebGL2 && Texture.useSrgbTextures && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
if ( capabilities.isWebGL2 && Texture.useSrgbTextures && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding && !map.disableSRGBInternalFormat ) {

encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2

Expand Down
14 changes: 7 additions & 7 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

function getInternalFormat( internalFormatName, glFormat, glType, encoding ) {
function getInternalFormat( internalFormatName, glFormat, glType, encoding, disableSRGBInternalFormat ) {

if ( isWebGL2 === false ) return glFormat;

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

if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( isWebGL2 && Texture.useSrgbTextures && encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( isWebGL2 && Texture.useSrgbTextures && encoding === sRGBEncoding && !disableSRGBInternalFormat ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4;
if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1;

Expand Down Expand Up @@ -562,7 +562,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
glFormat = utils.convert( texture.format, texture.encoding );

let glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.disableSRGBInternalFormat );

setTextureParameters( textureType, texture, supportsMips );

Expand Down Expand Up @@ -921,7 +921,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
supportsMips = isPowerOfTwo( image ) || isWebGL2,
glFormat = utils.convert( texture.format, texture.encoding ),
glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.disableSRGBInternalFormat );

const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true );
const allocateMemory = ( textureProperties.__version === undefined );
Expand Down Expand Up @@ -1086,7 +1086,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.encoding );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.disableSRGBInternalFormat );
const renderTargetProperties = properties.get( renderTarget );

if ( ! renderTargetProperties.__hasExternalTextures ) {
Expand Down Expand Up @@ -1194,7 +1194,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.encoding );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.disableSRGBInternalFormat );
const samples = getRenderTargetSamples( renderTarget );

if ( isMultisample && renderTarget.useRenderbuffer ) {
Expand Down Expand Up @@ -1419,7 +1419,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

const glFormat = utils.convert( texture.format, texture.encoding );
const glType = utils.convert( texture.type );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.disableSRGBInternalFormat );
const samples = getRenderTargetSamples( renderTarget );
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );

Expand Down
2 changes: 1 addition & 1 deletion src/textures/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Texture extends EventDispatcher {

this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
this.needsPMREMUpdate = false; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)

this.disableSRGBInternalFormat = false; // flag for disabling gl-internalFormat of sRGB (relevant for render target textures: prevent unnecessary recompilations of shaders)
}

updateMatrix() {
Expand Down