Skip to content

Commit

Permalink
Move detection of display-p3 capabilility to WebGL.js
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Aug 31, 2023
1 parent bb4ab88 commit 062373c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
17 changes: 17 additions & 0 deletions examples/jsm/capabilities/WebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ class WebGL {

}

static isColorSpaceAvailable( colorSpace ) {

try {

const canvas = document.createElement( 'canvas' );
const ctx = window.WebGL2RenderingContext && canvas.getContext( 'webgl2' );
ctx.drawingBufferColorSpace = colorSpace;
return ctx.drawingBufferColorSpace === colorSpace; // deepscan-disable-line SAME_OPERAND_VALUE

} catch ( e ) {

return false;

}

}

static getWebGLErrorMessage() {

return this.getErrorMessage( 1 );
Expand Down
4 changes: 3 additions & 1 deletion examples/webgl_test_wide_gamut.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@

import * as THREE from 'three';

import WebGL from 'three/addons/capabilities/WebGL.js';

let container, camera, renderer, loader;
let sceneL, sceneR, textureL, textureR;

let sliderPos = window.innerWidth / 2;

const isP3Context = THREE.ColorManagement.isDrawingBufferColorSpaceSupported( THREE.DisplayP3ColorSpace );
const isP3Context = WebGL.isColorSpaceAvailable( THREE.DisplayP3ColorSpace );

if ( isP3Context ) {

Expand Down
17 changes: 0 additions & 17 deletions src/math/ColorManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,6 @@ export const ColorManagement = {

},

isDrawingBufferColorSpaceSupported: function ( colorSpace ) {

try {

const canvas = document.createElement( 'canvas' );
const ctx = window.WebGL2RenderingContext && canvas.getContext( 'webgl2' );
ctx.drawingBufferColorSpace = colorSpace;
return ctx.drawingBufferColorSpace === colorSpace; // deepscan-disable-line SAME_OPERAND_VALUE

} catch ( e ) {

return false;

}

}

};


Expand Down

0 comments on commit 062373c

Please sign in to comment.