@@ -7,7 +7,7 @@ import vtkWebGPUHardwareSelector from 'vtk.js/Sources/Rendering/WebGPU/HardwareS
7
7
import vtkWebGPUViewNodeFactory from 'vtk.js/Sources/Rendering/WebGPU/ViewNodeFactory' ;
8
8
import vtkRenderPass from 'vtk.js/Sources/Rendering/SceneGraph/RenderPass' ;
9
9
import vtkRenderWindowViewNode from 'vtk.js/Sources/Rendering/SceneGraph/RenderWindowViewNode' ;
10
- // import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants ';
10
+ import HalfFloat from 'vtk.js/Sources/Common/Core/HalfFloat ' ;
11
11
12
12
const { vtkErrorMacro } = macro ;
13
13
// const IS_CHROME = navigator.userAgent.indexOf('Chrome') !== -1;
@@ -68,15 +68,15 @@ function vtkWebGPURenderWindow(publicAPI, model) {
68
68
publicAPI . recreateSwapChain = ( ) => {
69
69
if ( model . context ) {
70
70
model . context . unconfigure ( ) ;
71
- const presentationFormat = navigator . gpu . getPreferredCanvasFormat (
71
+ model . presentationFormat = navigator . gpu . getPreferredCanvasFormat (
72
72
model . adapter
73
73
) ;
74
74
75
75
/* eslint-disable no-undef */
76
76
/* eslint-disable no-bitwise */
77
77
model . context . configure ( {
78
78
device : model . device . getHandle ( ) ,
79
- format : presentationFormat ,
79
+ format : model . presentationFormat ,
80
80
alphaMode : 'premultiplied' ,
81
81
usage : GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . COPY_DST ,
82
82
width : model . size [ 0 ] ,
@@ -478,9 +478,9 @@ function vtkWebGPURenderWindow(publicAPI, model) {
478
478
height : texture . getHeight ( ) ,
479
479
} ;
480
480
481
- // must be a multiple of 256 bytes, so 64 texels with rgba8
482
- result . colorBufferWidth = 64 * Math . floor ( ( result . width + 63 ) / 64 ) ;
483
- result . colorBufferSizeInBytes = result . colorBufferWidth * result . height * 4 ;
481
+ // must be a multiple of 256 bytes, so 32 texels with rgba16
482
+ result . colorBufferWidth = 32 * Math . floor ( ( result . width + 31 ) / 32 ) ;
483
+ result . colorBufferSizeInBytes = result . colorBufferWidth * result . height * 8 ;
484
484
const colorBuffer = vtkWebGPUBuffer . newInstance ( ) ;
485
485
colorBuffer . setDevice ( device ) ;
486
486
/* eslint-disable no-bitwise */
@@ -499,7 +499,7 @@ function vtkWebGPURenderWindow(publicAPI, model) {
499
499
} ,
500
500
{
501
501
buffer : colorBuffer . getHandle ( ) ,
502
- bytesPerRow : 4 * result . colorBufferWidth ,
502
+ bytesPerRow : 8 * result . colorBufferWidth ,
503
503
rowsPerImage : result . height ,
504
504
} ,
505
505
{
@@ -515,20 +515,22 @@ function vtkWebGPURenderWindow(publicAPI, model) {
515
515
await cLoad ;
516
516
/* eslint-enable no-undef */
517
517
518
- result . colorValues = new Uint8ClampedArray (
519
- colorBuffer . getMappedRange ( ) . slice ( )
520
- ) ;
518
+ result . colorValues = new Uint16Array ( colorBuffer . getMappedRange ( ) . slice ( ) ) ;
521
519
colorBuffer . unmap ( ) ;
522
520
// repack the array
523
521
const tmparray = new Uint8ClampedArray ( result . height * result . width * 4 ) ;
524
522
for ( let y = 0 ; y < result . height ; y ++ ) {
525
523
for ( let x = 0 ; x < result . width ; x ++ ) {
526
524
const doffset = ( y * result . width + x ) * 4 ;
527
525
const soffset = ( y * result . colorBufferWidth + x ) * 4 ;
528
- tmparray [ doffset ] = result . colorValues [ soffset + 2 ] ;
529
- tmparray [ doffset + 1 ] = result . colorValues [ soffset + 1 ] ;
530
- tmparray [ doffset + 2 ] = result . colorValues [ soffset ] ;
531
- tmparray [ doffset + 3 ] = result . colorValues [ soffset + 3 ] ;
526
+ tmparray [ doffset ] =
527
+ 255.0 * HalfFloat . fromHalf ( result . colorValues [ soffset ] ) ;
528
+ tmparray [ doffset + 1 ] =
529
+ 255.0 * HalfFloat . fromHalf ( result . colorValues [ soffset + 1 ] ) ;
530
+ tmparray [ doffset + 2 ] =
531
+ 255.0 * HalfFloat . fromHalf ( result . colorValues [ soffset + 2 ] ) ;
532
+ tmparray [ doffset + 3 ] =
533
+ 255.0 * HalfFloat . fromHalf ( result . colorValues [ soffset + 3 ] ) ;
532
534
}
533
535
}
534
536
result . colorValues = tmparray ;
@@ -564,6 +566,7 @@ const DEFAULT_VALUES = {
564
566
useBackgroundImage : false ,
565
567
nextPropID : 1 ,
566
568
xrSupported : false ,
569
+ presentationFormat : null ,
567
570
} ;
568
571
569
572
// ----------------------------------------------------------------------------
@@ -607,6 +610,7 @@ export function extend(publicAPI, model, initialValues = {}) {
607
610
macro . get ( publicAPI , model , [
608
611
'commandEncoder' ,
609
612
'device' ,
613
+ 'presentationFormat' ,
610
614
'useBackgroundImage' ,
611
615
'xrSupported' ,
612
616
] ) ;
0 commit comments