Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | 1x 1x | import macro from 'vtk.js/Sources/macros'; import vtkWebGPUSampler from 'vtk.js/Sources/Rendering/WebGPU/Sampler'; import vtkWebGPUTypes from 'vtk.js/Sources/Rendering/WebGPU/Types'; // ---------------------------------------------------------------------------- // vtkWebGPUTextureView methods // ---------------------------------------------------------------------------- /* eslint-disable no-bitwise */ function vtkWebGPUTextureView(publicAPI, model) { // Set our className model.classHierarchy.push('vtkWebGPUTextureView'); publicAPI.create = (texture, options) => { model.texture = texture; model.options = options; model.options.dimension = model.options.dimension || '2d'; model.options.label = model.label; model.textureHandle = texture.getHandle(); model.handle = model.textureHandle.createView(model.options); model.bindGroupLayoutEntry.texture.viewDimension = model.options.dimension; const tDetails = vtkWebGPUTypes.getDetailsFromTextureFormat( model.texture.getFormat() ); model.bindGroupLayoutEntry.texture.sampleType = tDetails.sampleType; }; publicAPI.createFromTextureHandle = (textureHandle, options) => { model.texture = null; model.options = options; model.options.dimension = model.options.dimension || '2d'; model.options.label = model.label; model.textureHandle = textureHandle; model.handle = model.textureHandle.createView(model.options); model.bindGroupLayoutEntry.texture.viewDimension = model.options.dimension; const tDetails = vtkWebGPUTypes.getDetailsFromTextureFormat(options.format); model.bindGroupLayoutEntry.texture.sampleType = tDetails.sampleType; model.bindGroupTime.modified(); }; publicAPI.getBindGroupEntry = () => { const foo = { resource: publicAPI.getHandle(), }; return foo; }; publicAPI.getShaderCode = (binding, group) => { let ttype = 'f32'; if (model.bindGroupLayoutEntry.texture.sampleType === 'sint') { ttype = 'i32'; } else if (model.bindGroupLayoutEntry.texture.sampleType === 'uint') { ttype = 'u32'; } let result = `@binding(${binding}) @group(${group}) var ${model.label}: texture_${model.options.dimension}<${ttype}>;`; if (model.bindGroupLayoutEntry.texture.sampleType === 'depth') { result = `@binding(${binding}) @group(${group}) var ${model.label}: texture_depth_${model.options.dimension};`; } return result; }; publicAPI.addSampler = (device, options) => { const newSamp = vtkWebGPUSampler.newInstance({ label: `${model.label}Sampler`, }); newSamp.create(device, options); publicAPI.setSampler(newSamp); }; publicAPI.getBindGroupTime = () => { // check if the handle changed if (model.texture && model.texture.getHandle() !== model.textureHandle) { model.textureHandle = model.texture.getHandle(); model.handle = model.textureHandle.createView(model.options); model.bindGroupTime.modified(); } return model.bindGroupTime; }; // if the texture has changed then get a new view publicAPI.getHandle = () => { if (model.texture && model.texture.getHandle() !== model.textureHandle) { model.textureHandle = model.texture.getHandle(); model.handle = model.textureHandle.createView(model.options); model.bindGroupTime.modified(); } return model.handle; }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { texture: null, handle: null, sampler: null, label: null, }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); // Object methods macro.obj(publicAPI, model); model.bindGroupLayoutEntry = { /* eslint-disable no-undef */ visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT, /* eslint-enable no-undef */ texture: { sampleType: 'float', viewDimension: '2d', // multisampled: false, }, }; model.bindGroupTime = {}; macro.obj(model.bindGroupTime, { mtime: 0 }); macro.get(publicAPI, model, ['bindGroupTime', 'texture']); macro.setGet(publicAPI, model, ['bindGroupLayoutEntry', 'label', 'sampler']); vtkWebGPUTextureView(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |