Skip to content

Commit

Permalink
Wind Waker: Fix some render inst template leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jan 4, 2025
1 parent 7e0d8a3 commit 7ca9dfe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/Common/JSYSTEM/J2Dv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ export class J2DPicture extends J2DPane {
if (this.tex === null || this.sdraw === null)
return;

renderInstManager.pushTemplate();
const renderInst = renderInstManager.newRenderInst();

ctx2D.setOnRenderInst(renderInst);
Expand All @@ -452,7 +451,6 @@ export class J2DPicture extends J2DPane {
this.materialHelper.allocateDrawParamsDataOnInst(renderInst, drawParams);

renderInstManager.submitRenderInst(renderInst);
renderInstManager.popTemplate();
}

public override destroy(device: GfxDevice): void {
Expand Down
18 changes: 10 additions & 8 deletions src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, group);
}

// From mDoGph_Painter(). Draw the 2D particle groups with different view/proj matrices.
// From mDoGph_Painter(). Draw the 2D particle groups with different view/proj matrices.
{
const orthoCtx = this.globals.scnPlay.currentGrafPort;
const template = renderInstManager.pushTemplate();
Expand All @@ -424,14 +424,16 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
const viewMtx = scratchMatrix;
computeModelMatrixT(viewMtx, orthoCtx.aspectRatioCorrection * 320, 240, 0);
globals.particleCtrl.setDrawInfo(viewMtx, orthoCtx.sceneParams.u_Projection, null, null);

renderInstManager.setCurrentList(dlst.particle2DBack);
globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDback);
globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDmenuBack);

renderInstManager.setCurrentList(dlst.particle2DFore);
globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDfore);
globals.particleCtrl.draw(device, this.renderHelper.renderInstManager, ParticleGroup.TwoDmenuFore);

renderInstManager.popTemplate();
}
}

Expand All @@ -452,7 +454,7 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
const dlst = this.globals.dlst;
dlst.peekZ.beginFrame(device);

// From mDoGph_Painter,
// From mDoGph_Painter,
this.globals.scnPlay.currentGrafPort.setOrtho(-9.0, -21.0, 650.0, 503.0, 100000.0, -100000.0);
this.globals.scnPlay.currentGrafPort.setPort(viewerInput.backbufferWidth, viewerInput.backbufferHeight);

Expand Down Expand Up @@ -902,8 +904,8 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc {
super(stageDir, name, roomList);
assert(this.roomList.length === 1);

// Use a distinct ID for demos so that we don't conflict with the non-demo version of this stage.
// Without this, going to a scene like Outset Island and reloading will select the first Outset Island demo.
// Use a distinct ID for demos so that we don't conflict with the non-demo version of this stage.
// Without this, going to a scene like Outset Island and reloading will select the first Outset Island demo.
this.id = this.stbFilename.slice(0, -4);
}

Expand All @@ -918,7 +920,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc {

// TODO: Don't render until the camera has been placed for this demo. The cuts are jarring.

// noclip modification: This normally happens on room load. Do it here instead so that we don't waste time
// noclip modification: This normally happens on room load. Do it here instead so that we don't waste time
// loading .arcs for cutscenes that aren't going to be played
const lbnk = globals.roomCtrl.status[this.roomList[0]].data.lbnk;
if (lbnk) {
Expand Down Expand Up @@ -979,7 +981,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc {
// Most of this data comes from the PLAY action of the PACKAGE actor in an event from a Stage's event_list.dat. This
// action has properties for the room and layer that these cutscenes are designed for. HOWEVER, this data is often missing.
// It has been reconstructed by cross-referencing each Room's lbnk section (which points to a Demo*.arc file for each layer),
// the .stb files contained in each of those Objects/Demo*.arc files, and the FileName attribute from the event action.
// the .stb files contained in each of those Objects/Demo*.arc files, and the FileName attribute from the event action.
const demoDescs = [
new DemoDesc("sea", "Pirate Zelda Fly", [44], "kaizoku_zelda_fly.stb", 0, [-200000.0, 0.0, 320000.0], 180.0, 0, 0),
new DemoDesc("sea", "Zola Awakens", [13], "awake_zola.stb", 8, [200000.0, 0.0, -200000.0], 0, 227, 0),
Expand Down Expand Up @@ -1030,7 +1032,7 @@ const demoDescs = [
new DemoDesc("sea_T", "Departure", [0xFF], "departure.stb", 0, [-200000.0, 0.0, 320000.0], 0.0, 0, 0),
new DemoDesc("sea_T", "PirateZeldaFly", [0xFF], "kaizoku_zelda_fly.stb", 0, [-200000.0, 0.0, 320000.0], 180.0, 0, 0),

// The game expects this STB file to be in Stage/Ocean/Stage.arc, but it is not. Must be a leftover.
// The game expects this STB file to be in Stage/Ocean/Stage.arc, but it is not. Must be a leftover.
new DemoDesc("Ocean", "counter.stb", [-1], "counter.stb", 0, [0, 0, 0], 0, 0, 0),
]

Expand Down
8 changes: 3 additions & 5 deletions src/ZeldaWindWaker/d_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6058,11 +6058,9 @@ class d_a_title extends fopAc_ac_c {

this.btkSubtitle.frameCtrl.setFrame(this.btkSubtitle.frameCtrl.endFrame);
this.panes[TitlePane.Nintendo].setAlpha(1.0);
if (this.blinkFrameCounter >= 100) {
this.blinkFrameCounter = 0;
} else {
this.blinkFrameCounter += deltaTimeFrames;
}
this.blinkFrameCounter += deltaTimeFrames;
while (this.blinkFrameCounter >= 100)
this.blinkFrameCounter -= 100;

if (this.blinkFrameCounter >= 50) {
this.panes[TitlePane.PressStart].setAlpha((this.blinkFrameCounter - 50) / 50.0);
Expand Down
16 changes: 9 additions & 7 deletions src/ZeldaWindWaker/d_camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { dGlobals } from "./Main.js";
import { EDemoCamFlags } from "./d_demo.js";
import { projectionMatrixReverseDepth } from "../gfx/helpers/ReversedDepthHelpers.js";
import { projectionMatrixConvertClipSpaceNearZ } from "../gfx/helpers/ProjectionHelpers.js";
import { GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { GfxRenderInst, GfxRenderInstManager } from "../gfx/render/GfxRenderInstManager.js";
import { calcLODBias, fillSceneParamsData, SceneParams, ub_SceneParamsBufferSize } from "../gx/gx_render.js";
import { GX_Program } from "../gx/gx_material.js";
import { ViewerRenderInput } from "../viewer.js";
Expand Down Expand Up @@ -167,16 +167,18 @@ export class dCamera_c extends leafdraw_class {
}
}

// Executes before any other draw in other systems
override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
const template = renderInstManager.pushTemplate();

mat4.copy(sceneParams.u_Projection, globals.camera.clipFromViewMatrix);
public setOnRenderInst(globals: dGlobals, renderInst: GfxRenderInst, viewerInput: ViewerRenderInput): void {
mat4.copy(sceneParams.u_Projection, this.clipFromViewMatrix);
sceneParams.u_SceneTextureLODBias = calcLODBias(viewerInput.backbufferWidth, viewerInput.backbufferHeight);
const d = template.allocateUniformBufferF32(GX_Program.ub_SceneParams, ub_SceneParamsBufferSize);
const d = renderInst.allocateUniformBufferF32(GX_Program.ub_SceneParams, ub_SceneParamsBufferSize);
fillSceneParamsData(d, 0, sceneParams);
}

public override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void {
const template = renderInstManager.getCurrentTemplate();
this.setOnRenderInst(globals, template, viewerInput);
}

public applyScissor(pass: GfxRenderPass) {
if (this.enableLetterboxing) {
pass.setScissor(this.scissor[0], this.scissor[1], this.scissor[2], this.scissor[3]);
Expand Down

0 comments on commit 7ca9dfe

Please sign in to comment.