Skip to content

Commit e43e366

Browse files
Jerome Humbertdjeedai
Jerome Humbert
andcommitted
Minor docs edit/add in bevy_render (#3447)
# Objective Docs updates. ## Solution - Detail what `OrthographicCameraBundle::new_2d()` creates. - Fix a few renamed parameters in comments of `TrackedRenderPass`. - Add missing comments for viewport and debug markers. Co-authored-by: Jerome Humbert <[email protected]>
1 parent 50b3f27 commit e43e366

File tree

2 files changed

+70
-14
lines changed

2 files changed

+70
-14
lines changed

crates/bevy_render/src/camera/bundle.rs

+17
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ pub struct OrthographicCameraBundle {
7575
}
7676

7777
impl OrthographicCameraBundle {
78+
/// Create an orthographic projection camera to render 2D content.
79+
///
80+
/// The projection creates a camera space where X points to the right of the screen,
81+
/// Y points to the top of the screen, and Z points out of the screen (backward),
82+
/// forming a right-handed coordinate system. The center of the screen is at `X=0` and
83+
/// `Y=0`.
84+
///
85+
/// The default scaling mode is [`ScalingMode::WindowSize`], resulting in a resolution
86+
/// where 1 unit in X and Y in camera space corresponds to 1 logical pixel on the screen.
87+
/// That is, for a screen of 1920 pixels in width, the X coordinates visible on screen go
88+
/// from `X=-960` to `X=+960` in world space, left to right. This can be changed by changing
89+
/// the [`OrthographicProjection::scaling_mode`] field.
90+
///
91+
/// The camera is placed at `Z=+1000-0.1`, looking toward the world origin `(0,0,0)`.
92+
/// Its orthographic projection extends from `0.0` to `-1000.0` in camera view space,
93+
/// corresponding to `Z=+999.9` (closest to camera) to `Z=-0.1` (furthest away from
94+
/// camera) in world space.
7895
pub fn new_2d() -> Self {
7996
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
8097
// the camera's translation by far and use a right handed coordinate system

crates/bevy_render/src/render_phase/draw_state.rs

+53-14
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ impl<'a> TrackedRenderPass<'a> {
117117
}
118118

119119
/// Sets the active [`BindGroup`] for a given bind group index. The bind group layout in the
120-
/// active pipeline when any `draw()` function is called must match the layout
121-
/// of this `bind group`.
120+
/// active pipeline when any `draw()` function is called must match the layout of this `bind group`.
122121
pub fn set_bind_group(
123122
&mut self,
124123
index: usize,
@@ -149,40 +148,41 @@ impl<'a> TrackedRenderPass<'a> {
149148
/// Assign a vertex buffer to a slot.
150149
///
151150
/// Subsequent calls to [`TrackedRenderPass::draw`] and [`TrackedRenderPass::draw_indexed`]
152-
/// will use the `buffer` as one of the source vertex buffers.
151+
/// will use the buffer referenced by `buffer_slice` as one of the source vertex buffer(s).
153152
///
154-
/// The `slot` refers to the index of the matching descriptor in
153+
/// The `slot_index` refers to the index of the matching descriptor in
155154
/// [`VertexState::buffers`](crate::render_resource::VertexState::buffers).
156-
pub fn set_vertex_buffer(&mut self, index: usize, buffer_slice: BufferSlice<'a>) {
155+
pub fn set_vertex_buffer(&mut self, slot_index: usize, buffer_slice: BufferSlice<'a>) {
157156
let offset = buffer_slice.offset();
158157
if self
159158
.state
160-
.is_vertex_buffer_set(index, buffer_slice.id(), offset)
159+
.is_vertex_buffer_set(slot_index, buffer_slice.id(), offset)
161160
{
162161
debug!(
163162
"set vertex buffer {} (already set): {:?} ({})",
164-
index,
163+
slot_index,
165164
buffer_slice.id(),
166165
offset
167166
);
168167
return;
169168
} else {
170169
debug!(
171170
"set vertex buffer {}: {:?} ({})",
172-
index,
171+
slot_index,
173172
buffer_slice.id(),
174173
offset
175174
);
176175
}
177-
self.pass.set_vertex_buffer(index as u32, *buffer_slice);
176+
self.pass
177+
.set_vertex_buffer(slot_index as u32, *buffer_slice);
178178
self.state
179-
.set_vertex_buffer(index, buffer_slice.id(), offset);
179+
.set_vertex_buffer(slot_index, buffer_slice.id(), offset);
180180
}
181181

182182
/// Sets the active index buffer.
183183
///
184-
/// Subsequent calls to [`TrackedRenderPass::draw_indexed`] will use the `buffer` as
185-
/// the source index buffer.
184+
/// Subsequent calls to [`TrackedRenderPass::draw_indexed`] will use the buffer referenced by
185+
/// `buffer_slice` as the source index buffer.
186186
pub fn set_index_buffer(
187187
&mut self,
188188
buffer_slice: BufferSlice<'a>,
@@ -209,7 +209,7 @@ impl<'a> TrackedRenderPass<'a> {
209209

210210
/// Draws primitives from the active vertex buffer(s).
211211
///
212-
/// The active vertex buffers can be set with [`TrackedRenderPass::set_vertex_buffer`].
212+
/// The active vertex buffer(s) can be set with [`TrackedRenderPass::set_vertex_buffer`].
213213
pub fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>) {
214214
debug!("draw: {:?} {:?}", vertices, instances);
215215
self.pass.draw(vertices, instances);
@@ -218,7 +218,7 @@ impl<'a> TrackedRenderPass<'a> {
218218
/// Draws indexed primitives using the active index buffer and the active vertex buffer(s).
219219
///
220220
/// The active index buffer can be set with [`TrackedRenderPass::set_index_buffer`], while the
221-
/// active vertex buffers can be set with [`TrackedRenderPass::set_vertex_buffer`].
221+
/// active vertex buffer(s) can be set with [`TrackedRenderPass::set_vertex_buffer`].
222222
pub fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>) {
223223
debug!(
224224
"draw indexed: {:?} {} {:?}",
@@ -234,6 +234,7 @@ impl<'a> TrackedRenderPass<'a> {
234234
}
235235

236236
/// Sets the scissor region.
237+
///
237238
/// Subsequent draw calls will discard any fragments that fall outside this region.
238239
pub fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) {
239240
debug!("set_scissor_rect: {} {} {} {}", x, y, width, height);
@@ -253,6 +254,9 @@ impl<'a> TrackedRenderPass<'a> {
253254
self.pass.set_push_constants(stages, offset, data)
254255
}
255256

257+
/// Set the rendering viewport.
258+
///
259+
/// Subsequent draw calls will be projected into that viewport.
256260
pub fn set_viewport(
257261
&mut self,
258262
x: f32,
@@ -270,16 +274,51 @@ impl<'a> TrackedRenderPass<'a> {
270274
.set_viewport(x, y, width, height, min_depth, max_depth)
271275
}
272276

277+
/// Insert a single debug marker.
278+
///
279+
/// This is a GPU debugging feature. This has no effect on the rendering itself.
273280
pub fn insert_debug_marker(&mut self, label: &str) {
274281
debug!("insert debug marker: {}", label);
275282
self.pass.insert_debug_marker(label)
276283
}
277284

285+
/// Start a new debug group.
286+
///
287+
/// Push a new debug group over the internal stack. Subsequent render commands and debug
288+
/// markers are grouped into this new group, until [`pop_debug_group`] is called.
289+
///
290+
/// ```
291+
/// # fn example(mut pass: bevy_render::render_phase::TrackedRenderPass<'static>) {
292+
/// pass.push_debug_group("Render the car");
293+
/// // [setup pipeline etc...]
294+
/// pass.draw(0..64, 0..1);
295+
/// pass.pop_debug_group();
296+
/// # }
297+
/// ```
298+
///
299+
/// Note that [`push_debug_group`] and [`pop_debug_group`] must always be called in pairs.
300+
///
301+
/// This is a GPU debugging feature. This has no effect on the rendering itself.
302+
///
303+
/// [`push_debug_group`]: TrackedRenderPass::push_debug_group
304+
/// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group
278305
pub fn push_debug_group(&mut self, label: &str) {
279306
debug!("push_debug_group marker: {}", label);
280307
self.pass.push_debug_group(label)
281308
}
282309

310+
/// End the current debug group.
311+
///
312+
/// Subsequent render commands and debug markers are not grouped anymore in
313+
/// this group, but in the previous one (if any) or the default top-level one
314+
/// if the debug group was the last one on the stack.
315+
///
316+
/// Note that [`push_debug_group`] and [`pop_debug_group`] must always be called in pairs.
317+
///
318+
/// This is a GPU debugging feature. This has no effect on the rendering itself.
319+
///
320+
/// [`push_debug_group`]: TrackedRenderPass::push_debug_group
321+
/// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group
283322
pub fn pop_debug_group(&mut self) {
284323
debug!("pop_debug_group");
285324
self.pass.pop_debug_group()

0 commit comments

Comments
 (0)