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
impl GfxContext
Sourcepub fn screen_size(&self) -> (i32, i32)
pub fn screen_size(&self) -> (i32, i32)
GUI pixel dimensions of the screen for this frame.
Sourcepub fn delta_tick(&self) -> f32
pub fn delta_tick(&self) -> f32
Partial-tick interpolation factor (0.0–1.0).
Sourcepub fn view_proj(&self) -> [f32; 16]
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.
Sourcepub fn camera_pos(&self) -> [f32; 3]
pub fn camera_pos(&self) -> [f32; 3]
Camera world-space position. All zeros during on_hud_render.
Sourcepub fn player_pos(&self) -> [f32; 3]
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.
Sourcepub fn create_buffer(&self) -> Buffer
pub fn create_buffer(&self) -> Buffer
Allocate a new GPU buffer (VBO or EBO). Returns handle 0 on failure.
Sourcepub fn delete_buffer(&self, buf: Buffer)
pub fn delete_buffer(&self, buf: Buffer)
Delete a buffer allocated by create_buffer.
Sourcepub fn create_vao(&self) -> VertexArray
pub fn create_vao(&self) -> VertexArray
Allocate a new vertex array object. Returns handle 0 on failure.
Sourcepub fn delete_vao(&self, vao: VertexArray)
pub fn delete_vao(&self, vao: VertexArray)
Delete a vertex array allocated by create_vao.
Sourcepub fn create_shader(
&self,
vert_src: &str,
frag_src: &str,
) -> Result<ShaderProgram, ()>
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.
Sourcepub fn delete_shader(&self, prog: ShaderProgram)
pub fn delete_shader(&self, prog: ShaderProgram)
Delete a shader program.
Sourcepub fn create_texture_rgba(
&self,
w: u32,
h: u32,
pixels: &[u8],
linear: bool,
) -> Texture
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.
Sourcepub fn texture_from_mc(&self, id: &str) -> Texture
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.
Sourcepub fn delete_texture(&self, tex: Texture)
pub fn delete_texture(&self, tex: Texture)
Delete a texture.
Sourcepub fn bind_texture(&self, unit: u32, tex: &Texture)
pub fn bind_texture(&self, unit: u32, tex: &Texture)
Bind a texture to the given sampler unit (0–7).
Sourcepub fn draw_arrays(
&self,
vao: &VertexArray,
prog: &ShaderProgram,
mode: DrawMode,
first: u32,
count: u32,
)
pub fn draw_arrays( &self, vao: &VertexArray, prog: &ShaderProgram, mode: DrawMode, first: u32, count: u32, )
Draw primitives using a vertex array (no index buffer).
Sourcepub fn draw_elements(
&self,
vao: &VertexArray,
ebo: &Buffer,
prog: &ShaderProgram,
mode: DrawMode,
count: u32,
u32_indices: bool,
)
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.
Sourcepub fn set_blend(&self, enabled: bool, src: u32, dst: u32)
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.
Sourcepub fn set_scissor(&self, x: i32, y: i32, w: i32, h: i32)
pub fn set_scissor(&self, x: i32, y: i32, w: i32, h: i32)
Enable scissor clipping to a GUI-pixel rectangle.
Sourcepub fn clear_scissor(&self)
pub fn clear_scissor(&self)
Disable scissor clipping.
Trait Implementations§
Source§impl Clone for GfxContext
impl Clone for GfxContext
Source§fn clone(&self) -> GfxContext
fn clone(&self) -> GfxContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more