Skip to main content

GfxContext

Struct GfxContext 

Source
pub struct GfxContext(/* private fields */);
Expand description

Handle to the GPU and draw capabilities for a single render frame.

Valid only within an on_hud_render or on_world_render callback. Do not store across frames — store GPU resource handles (u32) instead.

Implementations§

Source§

impl GfxContext

Source

pub fn screen_size(&self) -> (i32, i32)

GUI pixel dimensions of the screen for this frame.

Source

pub fn delta_tick(&self) -> f32

Partial-tick interpolation factor (0.0–1.0).

Source

pub fn view_proj(&self) -> [f32; 16]

View-projection matrix in camera-relative space (column-major, 16 × f32). Zeros during on_hud_render; filled during on_world_render.

Source

pub fn camera_pos(&self) -> [f32; 3]

Camera world-space position. All zeros during on_hud_render.

Source

pub fn player_pos(&self) -> [f32; 3]

Local player world-space position (eye height). All zeros during on_hud_render. Use this to anchor geometry to the player; differs from camera_pos in third-person.

Source

pub fn create_buffer(&self) -> Buffer

Allocate a new GPU buffer (VBO or EBO). Returns handle 0 on failure.

Source

pub fn delete_buffer(&self, buf: Buffer)

Delete a buffer allocated by create_buffer.

Source

pub fn create_vao(&self) -> VertexArray

Allocate a new vertex array object. Returns handle 0 on failure.

Source

pub fn delete_vao(&self, vao: VertexArray)

Delete a vertex array allocated by create_vao.

Source

pub fn create_shader( &self, vert_src: &str, frag_src: &str, ) -> Result<ShaderProgram, ()>

Compile and link a GLSL shader program. Returns Err(()) and logs on compile/link failure.

Source

pub fn delete_shader(&self, prog: ShaderProgram)

Delete a shader program.

Source

pub fn create_texture_rgba( &self, w: u32, h: u32, pixels: &[u8], linear: bool, ) -> Texture

Upload RGBA8 pixel data as a new GPU texture. linear: true = bilinear filter, false = nearest.

Source

pub fn texture_from_mc(&self, id: &str) -> Texture

Get the GL texture handle that Minecraft uses for an identifier (e.g. "minecraft:textures/gui/icons.png"). Returns handle 0 if not found.

Source

pub fn delete_texture(&self, tex: Texture)

Delete a texture.

Source

pub fn bind_texture(&self, unit: u32, tex: &Texture)

Bind a texture to the given sampler unit (0–7).

Source

pub fn draw_arrays( &self, vao: &VertexArray, prog: &ShaderProgram, mode: DrawMode, first: u32, count: u32, )

Draw primitives using a vertex array (no index buffer).

Source

pub fn draw_elements( &self, vao: &VertexArray, ebo: &Buffer, prog: &ShaderProgram, mode: DrawMode, count: u32, u32_indices: bool, )

Draw primitives via an index buffer. u32_indices: true = u32 indices, false = u16 indices.

Source

pub fn set_blend(&self, enabled: bool, src: u32, dst: u32)

Enable or disable alpha blending. src/dst: GL blend factor constants from core::blend.

Source

pub fn set_depth(&self, test: bool, write: bool)

Enable or disable depth testing and writing.

Source

pub fn set_scissor(&self, x: i32, y: i32, w: i32, h: i32)

Enable scissor clipping to a GUI-pixel rectangle.

Source

pub fn clear_scissor(&self)

Disable scissor clipping.

Source

pub fn set_viewport(&self, x: i32, y: i32, w: i32, h: i32)

Set the GL viewport in physical pixels (x, y, width, height).

Source

pub fn draw2d(&self) -> Draw2D<'_>

Access the 2D drawing helpers (text, rectangles, MC textures). These only work during on_hud_render.

Trait Implementations§

Source§

impl Clone for GfxContext

Source§

fn clone(&self) -> GfxContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GfxContext

Source§

impl Send for GfxContext

Source§

impl Sync for GfxContext

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.