Skip to content

Commit

Permalink
WebGLCapabilities: add textureTypeReadable() and textureFormatReadable()
Browse files Browse the repository at this point in the history
  • Loading branch information
sguimmara committed Apr 8, 2024
1 parent 1c8dde5 commit 3955116
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {
BackSide,
FrontSide,
DoubleSide,
RGBAFormat,
HalfFloatType,
FloatType,
UnsignedByteType,
NoToneMapping,
LinearMipmapLinearFilter,
Expand Down Expand Up @@ -292,10 +290,10 @@ class WebGLRenderer {
extensions = new WebGLExtensions( _gl );
extensions.init();

capabilities = new WebGLCapabilities( _gl, extensions, parameters );

utils = new WebGLUtils( _gl, extensions );

capabilities = new WebGLCapabilities( _gl, extensions, parameters, utils );

state = new WebGLState( _gl );

info = new WebGLInfo( _gl );
Expand Down Expand Up @@ -2288,17 +2286,14 @@ class WebGLRenderer {
const textureFormat = texture.format;
const textureType = texture.type;

if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
if ( ! capabilities.textureFormatReadable( textureFormat ) ) {

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

}

const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) );

if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // Edge and Chrome Mac < 52 (#9513)
textureType !== FloatType && ! halfFloatSupportedByExt ) {
if ( ! capabilities.textureTypeReadable( textureType ) ) {

console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
return;
Expand Down
34 changes: 33 additions & 1 deletion src/renderers/webgl/WebGLCapabilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function WebGLCapabilities( gl, extensions, parameters ) {
import { FloatType, HalfFloatType, RGBAFormat, UnsignedByteType } from '../../constants.js';

function WebGLCapabilities( gl, extensions, parameters, utils ) {

let maxAnisotropy;

Expand All @@ -22,6 +24,33 @@ function WebGLCapabilities( gl, extensions, parameters ) {

}

function textureFormatReadable( textureFormat ) {

if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {

return false;

}

return true;

}

function textureTypeReadable( textureType ) {

const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) );

if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // Edge and Chrome Mac < 52 (#9513)
textureType !== FloatType && ! halfFloatSupportedByExt ) {

return false;

}

return true;

}

function getMaxPrecision( precision ) {

if ( precision === 'highp' ) {
Expand Down Expand Up @@ -85,6 +114,9 @@ function WebGLCapabilities( gl, extensions, parameters ) {
getMaxAnisotropy: getMaxAnisotropy,
getMaxPrecision: getMaxPrecision,

textureFormatReadable: textureFormatReadable,
textureTypeReadable: textureTypeReadable,

precision: precision,
logarithmicDepthBuffer: logarithmicDepthBuffer,

Expand Down

0 comments on commit 3955116

Please sign in to comment.