Skip to content

Commit e9fcb11

Browse files
bruyeretfinetjul
authored andcommitted
fix: Fix hardware selector high pass
Moving the call to `processPixelBuffers()` at the end of rendering as the processing of the raw pixel buffers needs all the passes to be completed. Moving the call to `updateMaximumPointCellIds()` as it needs a selector that is not always set when the VBO is recomputed.
1 parent bbfd897 commit e9fcb11

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

Sources/Rendering/Core/Mapper/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,11 @@ function vtkMapper(publicAPI, model) {
740740
let inValue = 0;
741741
inValue += rawHighData[pos];
742742
inValue *= 256;
743-
inValue += rawLowData[pos];
743+
inValue += rawLowData[pos + 2];
744744
inValue *= 256;
745745
inValue += rawLowData[pos + 1];
746746
inValue *= 256;
747-
inValue += rawLowData[pos + 2];
747+
inValue += rawLowData[pos];
748748

749749
const outValue = idMap[inValue];
750750
const highData = selector.getPixelBuffer(PassTypes.ID_HIGH24);

Sources/Rendering/OpenGL/HardwareSelector/index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ export function extend(
331331
initialValues?: IOpenGLHardwareSelectorInitialValues
332332
): void;
333333

334+
/**
335+
* The WebGL implementation of the hardware selector renders the id of the VBO
336+
* vertices (gl_VertexID) with an offset to a RGBA texture.
337+
* Only the RGB channels of the RGBA texture are used. This means that a single
338+
* render can only draw 24 bits of information. To reach 32 bits, the hardware
339+
* selector renders a second pass which only writes in the R channel of the
340+
* texture.
341+
*
342+
* Note:
343+
* - With Webgl 2, it is now possible to render directly to a R32 texture and
344+
* even render to multiple render targets.
345+
* - The raw pixel buffers fetched from WebGL are processed in the core mapper
346+
* (see `processSelectorPixelBuffers`) instead of the PolydataMapper.
347+
* - The processing of the raw pixel buffers does not output an UInt32Array as
348+
* we could expect, but one or two textures with the same layout as the RGBA
349+
* textures as input.
350+
*/
334351
export const vtkOpenGLHardwareSelector: {
335352
newInstance: typeof newInstance;
336353
extend: typeof extend;

Sources/Rendering/OpenGL/HardwareSelector/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
482482
const rpasses = model._openGLRenderWindow.getRenderPasses();
483483

484484
publicAPI.beginSelection();
485+
const pixelBufferSavedPasses = [];
485486
for (
486487
model.currentPass = PassTypes.MIN_KNOWN_PASS;
487488
model.currentPass <= PassTypes.MAX_KNOWN_PASS;
@@ -503,9 +504,17 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
503504
publicAPI.postCapturePass(model.currentPass);
504505

505506
publicAPI.savePixelBuffer(model.currentPass);
506-
publicAPI.processPixelBuffers();
507+
pixelBufferSavedPasses.push(model.currentPass);
507508
}
508509
}
510+
511+
// Process pixel buffers
512+
pixelBufferSavedPasses.forEach((pass) => {
513+
model.currentPass = pass;
514+
publicAPI.processPixelBuffers();
515+
});
516+
model.currentPass = PassTypes.MAX_KNOWN_PASS;
517+
509518
publicAPI.endSelection();
510519

511520
// restore original background
@@ -860,9 +869,9 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
860869

861870
//----------------------------------------------------------------------------
862871

863-
publicAPI.attach = (w, r) => {
864-
model._openGLRenderWindow = w;
865-
model._renderer = r;
872+
publicAPI.attach = (openGLRenderWindow, renderer) => {
873+
model._openGLRenderWindow = openGLRenderWindow;
874+
model._renderer = renderer;
866875
};
867876

868877
// override

Sources/Rendering/OpenGL/PolyDataMapper/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
955955
FSSource = vtkShaderProgram.substitute(
956956
FSSource,
957957
'//VTK::Picking::Impl',
958-
' gl_FragData[0] = vec4(float(idx)/255.0, 0.0, 0.0, 1.0);'
958+
' gl_FragData[0] = vec4(float((idx/16777216)%256)/255.0, 0.0, 0.0, 1.0);'
959959
).result;
960960
break;
961961
default:
@@ -1761,6 +1761,8 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
17611761
if (publicAPI.getNeedToRebuildBufferObjects(ren, actor)) {
17621762
publicAPI.buildBufferObjects(ren, actor);
17631763
}
1764+
// Always call this function as the selector can change
1765+
publicAPI.updateMaximumPointCellIds();
17641766
};
17651767

17661768
publicAPI.getNeedToRebuildBufferObjects = (ren, actor) => {
@@ -1948,7 +1950,6 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
19481950
model.renderable.setSelectionWebGLIdsToVTKIds(
19491951
model.selectionWebGLIdsToVTKIds
19501952
);
1951-
publicAPI.updateMaximumPointCellIds();
19521953
}
19531954

19541955
model.VBOBuildString = toString;

0 commit comments

Comments
 (0)