Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/display_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,37 @@ export abstract class RenderedPanel extends RefCounted {
gl.scissor(canvasRelativeClippedLeft, glBottom, width, height);
}

setSubdividedGLClippedViewport(cellIndex: number, totalCells: number) {
const {
gl,
canvasRelativeClippedTop,
canvasRelativeClippedLeft,
renderViewport: { width, height },
} = this;

const numCols = Math.ceil(Math.sqrt(totalCells));
const numRows = Math.ceil(totalCells / numCols);

const col = cellIndex % numCols;
const row = Math.floor(cellIndex / numCols);

const cellWidth = width / numCols;
const cellHeight = height / numRows;

const left = canvasRelativeClippedLeft + col * cellWidth;
const top = canvasRelativeClippedTop + row * cellHeight;
const bottom = top + cellHeight;

const glLeft = Math.floor(left);
const glBottom = Math.floor(this.context.canvas.height - bottom);
const glWidth = Math.ceil(cellWidth);
const glHeight = Math.ceil(cellHeight);

gl.enable(WebGL2RenderingContext.SCISSOR_TEST);
gl.viewport(glLeft, glBottom, glWidth, glHeight);
gl.scissor(glLeft, glBottom, glWidth, glHeight);
}

// Sets the viewport to the logical viewport, using the scissor test to constrain drawing to the
// clipped viewport. Drawing does not need to take `visible{Left,Top,Width,Height}Fraction` into
// account.
Expand Down
17 changes: 17 additions & 0 deletions src/perspective_view/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ import { MultipleScaleBarTextures } from "#src/widget/scale_bar.js";
import type { RPC } from "#src/worker_rpc.js";
import { SharedObject } from "#src/worker_rpc.js";

// Turn on to see each of the offscreen textures
// render order is from top left to bottom right
// picking will not work as expected in a subdivision
// of the full panel, pretend you are picking from the full panel
const DEBUG_OFFSCREEN_TEXTURES = false;

export interface PerspectiveViewerState extends RenderedDataViewerState {
wireFrame: WatchableValueInterface<boolean>;
enableAdaptiveDownsampling: WatchableValueInterface<boolean>;
Expand Down Expand Up @@ -1419,6 +1425,17 @@ export class PerspectivePanel extends RenderedDataPanel {
}
this.offscreenFramebuffer.unbind();

if (DEBUG_OFFSCREEN_TEXTURES) {
const numTextures = OffscreenTextures.NUM_TEXTURES;
for (let i = 0; i < numTextures; i++) {
const texture = this.offscreenFramebuffer.colorBuffers[i].texture;
if (texture) {
this.setSubdividedGLClippedViewport(i, numTextures);
this.offscreenCopyHelper.draw(texture);
}
}
return true;
}
// Draw the texture over the whole viewport.
this.setGLClippedViewport();
this.offscreenCopyHelper.draw(
Expand Down
18 changes: 17 additions & 1 deletion src/sliceview/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ import type { ShaderBuilder } from "#src/webgl/shader.js";
import type { TrackableScaleBarOptions } from "#src/widget/scale_bar.js";
import { MultipleScaleBarTextures } from "#src/widget/scale_bar.js";

// Turn on to see each of the offscreen textures
// render order is from top left to bottom right
// picking will not work as expected in a subdivision
// of the full panel, pretend you are picking from the full panel
const DEBUG_OFFSCREEN_TEXTURES = false;

export interface SliceViewerState extends RenderedDataViewerState {
showScaleBar: TrackableBoolean;
wireFrame: TrackableBoolean;
Expand Down Expand Up @@ -431,9 +437,19 @@ export class SliceViewPanel extends RenderedDataPanel {
gl.disable(WebGL2RenderingContext.BLEND);
}
}

this.offscreenFramebuffer.unbind();

if (DEBUG_OFFSCREEN_TEXTURES) {
const numTextures = OffscreenTextures.NUM_TEXTURES;
for (let i = 0; i < numTextures; i++) {
const texture = this.offscreenFramebuffer.colorBuffers[i].texture;
if (texture) {
this.setSubdividedGLClippedViewport(i, numTextures);
this.offscreenCopyHelper.draw(texture);
}
}
return true;
}
// Draw the texture over the whole viewport.
this.setGLClippedViewport();
this.offscreenCopyHelper.draw(
Expand Down
Loading