Skip to content

Commit 7ab6098

Browse files
committed
Use Frame struct to represent FrameBegin and FrameEnd calls
1 parent 991f46a commit 7ab6098

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

citro3d/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,9 @@ impl Instance {
123123
&'istance mut self,
124124
f: impl FnOnce(RenderPass<'frame>) -> RenderPass<'frame>,
125125
) {
126-
unsafe {
127-
citro3d_sys::C3D_FrameBegin(
128-
// TODO: begin + end flags should be configurable
129-
citro3d_sys::C3D_FRAME_SYNCDRAW,
130-
);
131-
}
132-
133126
let pass = f(RenderPass::new(self));
134127

135-
unsafe {
136-
citro3d_sys::C3D_FrameEnd(0);
137-
}
138-
139-
// Explicit drop after FrameEnd (when the GPU command buffer is flushed).
128+
// Explicit drop for FrameEnd (when the GPU command buffer is flushed).
140129
drop(pass);
141130
}
142131
}

citro3d/src/render.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ pub struct Target<'screen> {
8080
_queue: Rc<RenderQueue>,
8181
}
8282

83+
struct Frame;
84+
8385
#[non_exhaustive]
8486
#[must_use]
8587
pub struct RenderPass<'pass> {
8688
texenvs: [OnceCell<TexEnv>; texenv::TEXENV_COUNT],
89+
_active_frame: Frame,
8790
_phantom: PhantomData<&'pass mut Instance>,
8891
}
8992

@@ -99,6 +102,7 @@ impl<'pass> RenderPass<'pass> {
99102
OnceCell::new(),
100103
OnceCell::new(),
101104
],
105+
_active_frame: Frame::new(),
102106
_phantom: PhantomData,
103107
}
104108
}
@@ -334,6 +338,27 @@ impl<'screen> Target<'screen> {
334338
}
335339
}
336340

341+
impl Frame {
342+
fn new() -> Self {
343+
unsafe {
344+
citro3d_sys::C3D_FrameBegin(
345+
// TODO: begin + end flags should be configurable
346+
citro3d_sys::C3D_FRAME_SYNCDRAW,
347+
)
348+
};
349+
350+
Self {}
351+
}
352+
}
353+
354+
impl Drop for Frame {
355+
fn drop(&mut self) {
356+
unsafe {
357+
citro3d_sys::C3D_FrameEnd(0);
358+
}
359+
}
360+
}
361+
337362
impl Drop for Target<'_> {
338363
#[doc(alias = "C3D_RenderTargetDelete")]
339364
fn drop(&mut self) {

0 commit comments

Comments
 (0)