Skip to content

Commit b799891

Browse files
authored
Resize fixes (#102)
1 parent 7e75e52 commit b799891

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: try-slang.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function withRenderLock(setupFn: { (): Promise<void>; }, renderFn: { (timeMS: nu
212212
}
213213
}
214214

215-
function startRendering() {
215+
function handleResize() {
216216
// This is a lighter-weight setup function that doesn't need to re-compile the shader code.
217217
const setupRenderer = async () => {
218218
if (!computePipeline || !passThroughPipeline)
@@ -221,8 +221,7 @@ function startRendering() {
221221
if (!currentWindowSize || currentWindowSize[0] < 2 || currentWindowSize[1] < 2)
222222
throw new NotReadyError("window not ready");
223223

224-
allocatedResources = await processResourceCommands(computePipeline, resourceBindings, resourceCommands);
225-
224+
safeSet(allocatedResources, "outputTexture", createOutputTexture(device, currentWindowSize[0], currentWindowSize[1], 'rgba8unorm'));
226225
computePipeline.createBindGroup(allocatedResources);
227226

228227
passThroughPipeline.inputTexture = (allocatedResources.get("outputTexture") as GPUTexture);
@@ -240,7 +239,7 @@ function startRendering() {
240239
function resizeCanvasHandler(entries: ResizeObserverEntry[]) {
241240
let needResize = resizeCanvas(entries);
242241
if (needResize) {
243-
startRendering();
242+
handleResize();
244243
}
245244
}
246245

@@ -617,7 +616,7 @@ async function processResourceCommands(pipeline: ComputePipeline | GraphicsPipel
617616
throw new Error(`Failed to create texture from image: ${error}`);
618617
}
619618
} else if (parsedCommand.type === "RAND") {
620-
const elementSize = 4; // Assuming 4 bytes per element (e.g., float) TODO: infer from type.
619+
const elementSize = 4; // RAND is only valid for floats
621620
const bindingInfo = resourceBindings.get(resourceName);
622621
if (!bindingInfo) {
623622
throw new Error(`Resource ${resourceName} is not defined in the bindings.`);

Diff for: ui.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function prepareForResize() {
144144
if (codeEditor.style.display == "none")
145145
continue;
146146
codeEditor.style.overflow = "hidden";
147+
codeEditor.style.height = "100%";
147148
}
148149
workspaceDiv.style.overflow = "hidden";
149150
leftContainer.style.overflowX = "hidden";
@@ -166,7 +167,13 @@ function finishResizing() {
166167
let parentNode = codeEditor.parentNode;
167168
if (codeEditor.clientHeight < 30 && parentNode instanceof HTMLElement)
168169
parentNode.style.overflow = "hidden";
169-
codeEditor.style.overflow = "visible";
170+
171+
if (codeEditor.clientHeight == 0) {
172+
codeEditor.style.height = "0px";
173+
codeEditor.style.overflow = "hidden";
174+
} else {
175+
codeEditor.style.overflow = "visible";
176+
}
170177
}
171178
reflectionTab.style.maxWidth = assertGetElementById("rightContainerDiv").clientWidth + "px";
172179

0 commit comments

Comments
 (0)