Skip to main content

GameRenderContext

Struct GameRenderContext 

Source
pub struct GameRenderContext<'a> { /* private fields */ }
Expand description

Viewport-local immediate-mode 2D/framebuffer drawing surface passed to GameScene::render.

Implementations§

Source§

impl<'a> GameRenderContext<'a>

Viewport-local drawing primitives for GameRenderContext.

Source

pub fn new(bounds: Rect, display_list: &'a mut DisplayList) -> Self

Creates a GameRenderContext bound to bounds and display_list.

§Arguments
  • Rect - Viewport bounds in root logical coordinates.
  • &'a mut DisplayList - Target display list.
§Returns
  • Self - Constructed viewport render context.
Source

pub fn viewport_size(&self) -> Size

Returns the logical width and height of the game viewport.

§Arguments
  • &Self - Render context reference.
§Returns
  • Size - Viewport size in logical pixels.
Source

pub fn clear(&mut self, color: Color)

Fills the entire game viewport with color.

§Arguments
  • &Self - Mutable render context.
  • Color - Background clear color.
Source

pub fn fill_rect(&mut self, rect: Rect, color: Color)

Draws an axis-aligned solid rectangle in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Rect - Local rectangle bounds.
  • Color - Fill color.
Source

pub fn fill_rounded_rect(&mut self, rect: Rect, color: Color, radius: f32)

Draws a rounded solid rectangle in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Rect - Local rectangle bounds.
  • Color - Fill color.
  • f32 - Corner radius in logical pixels.
Source

pub fn stroke_rect(&mut self, rect: Rect, stroke_width: f32, color: Color)

Draws an outlined rectangle in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Rect - Local rectangle bounds.
  • f32 - Stroke thickness in logical pixels.
  • Color - Stroke color.
Source

pub fn fill_circle(&mut self, center: Point, radius: f32, color: Color)

Draws a filled circle in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Point - Circle center in viewport-local coordinates.
  • f32 - Circle radius in logical pixels.
  • Color - Fill color.
Source

pub fn draw_image(&mut self, rect: Rect, buffer: ImageBuffer)

Draws an RGBA8 ImageBuffer stretched into rect inside this game viewport (ideal for 3D render targets).

§Arguments
  • &Self - Mutable render context.
  • Rect - Local destination rectangle inside the viewport.
  • ImageBuffer - Source RGBA8 pixel buffer.
Source

pub fn draw_line(&mut self, from: Point, to: Point, width: f32, color: Color)

Draws an anti-aliased line segment in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Point - Segment start point.
  • Point - Segment end point.
  • f32 - Line width in logical pixels.
  • Color - Line color.
Source

pub fn draw_text( &mut self, position: Point, text: String, font_size: f32, color: Color, )

Draws HUD or debug text inside the game viewport.

§Arguments
  • &Self - Mutable render context.
  • Point - Top-left local position.
  • String - Text string.
  • f32 - Font size in logical pixels.
  • Color - Text color.
Source

pub fn blit_framebuffer(&mut self, rect: Rect, buffer: ImageBuffer)

Blits an external 2D/3D engine RGBA8 ImageBuffer directly into the viewport.

§Arguments
  • &Self - Mutable render context.
  • Rect - Local destination rectangle.
  • ImageBuffer - External engine rendered frame or sprite sheet.
Source

pub fn fill_triangle(&mut self, p0: Point, p1: Point, p2: Point, color: Color)

Draws a filled triangle in viewport-local coordinates.

§Arguments
  • &Self - Mutable render context.
  • Point - First vertex.
  • Point - Second vertex.
  • Point - Third vertex.
  • Color - Fill color.
Source

pub fn draw_sprite_frame( &mut self, sheet: &SpriteSheet, frame_index: u32, rect: Rect, tint: Color, )

Draws a cropped frame from a SpriteSheet into rect with multiplicative tint.

§Arguments
  • &Self - Mutable render context.
  • &SpriteSheet - Source sprite sheet.
  • u32 - Zero-based animation frame index.
  • Rect - Destination viewport-local rectangle.
  • Color - Multiplicative tint color.
Source

pub fn render_tilemap(&mut self, tilemap: &TileMap, camera: &Camera2D)

Renders all visible tiles of tilemap through camera using O(visible) frustum culling.

§Arguments
  • &Self - Mutable render context.
  • &TileMap - Grid tilemap to draw.
  • &Camera2D - Active 2D world camera.
Source

pub fn render_world(&mut self, world: &GameWorld, camera: &Camera2D) -> usize

Renders all visible sprite entities in world through camera, sorted by z_order with frustum culling.

§Arguments
  • &Self - Mutable render context.
  • &GameWorld - Active ECS world.
  • &Camera2D - Active 2D world camera.
§Returns
  • usize - Number of visible entities drawn after frustum culling.
Source

pub fn render_particles( &mut self, particles: &ParticleSystem, camera: &Camera2D, ) -> usize

Renders all active pooled particles in particles through camera with frustum culling and lifetime interpolation.

§Arguments
  • &Self - Mutable render context.
  • &ParticleSystem - Active particle system.
  • &Camera2D - Active 2D world camera.
§Returns
  • usize - Number of visible particles rendered.
Source

pub fn draw_debug_colliders(&mut self, world: &GameWorld, camera: &Camera2D)

Draws wireframe collider bounds for debugging physics shapes inside world.

§Arguments
  • &Self - Mutable render context.
  • &GameWorld - Active ECS world.
  • &Camera2D - Active 2D world camera.

Trait Implementations§

Source§

impl<'a> Debug for GameRenderContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the struct fields as a debug struct, skipping excluded fields.

§Arguments
  • &mut std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • std::fmt::Result - Success or failure of the formatting operation.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for GameRenderContext<'a>

§

impl<'a> Forget for GameRenderContext<'a>

§

impl<'a> Freeze for GameRenderContext<'a>

§

impl<'a> Move for GameRenderContext<'a>

§

impl<'a> RefUnwindSafe for GameRenderContext<'a>

§

impl<'a> Send for GameRenderContext<'a>

§

impl<'a> Sync for GameRenderContext<'a>

§

impl<'a> Unpin for GameRenderContext<'a>

§

impl<'a> UnsafeUnpin for GameRenderContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.