yog-gfx 0.4.0

Yog graphics subsystem — low-level GPU pipeline access for mods.
Documentation
  • Coverage
  • 67.57%
    50 out of 74 items documented0 out of 46 items with examples
  • Size
  • Source code size: 19.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 858.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • F000NKKK

Yog graphics — low-level GPU pipeline access for mods.

Provides ergonomic wrappers around YogGfxApi, the stable C ABI table for GPU operations (VAO/VBO, GLSL shaders, textures, draw calls, render state).

Render contexts

Mods receive a [GfxContext] in two places:

  • on_hud_render(|ctx| { ... }) — called every frame after the HUD is drawn. ctx.view_proj() is zeroed; ctx.draw2d() works.
  • on_world_render(|ctx| { ... }) — called after world geometry. ctx.view_proj() holds the camera view-projection matrix in camera-relative space; ctx.camera_pos() is the world-space camera position.

GPU resource lifetime

GPU handles (u32) must be created and destroyed on the render thread. Store handles between frames; pass ctx on every render call.

use yog_gfx::{GfxContext, gl::{Buffer, ShaderProgram, VertexArray}};

struct MyRenderer {
    vbo: Option<Buffer>,
    vao: Option<VertexArray>,
    prog: Option<ShaderProgram>,
}

impl MyRenderer {
    fn ensure_init(&mut self, ctx: &GfxContext) {
        if self.vbo.is_some() { return; }
        let vbo = ctx.create_buffer();
        vbo.upload(ctx, &MY_VERTICES, false);
        let prog = ctx.create_shader(VERT_SRC, FRAG_SRC).unwrap();
        let vao = ctx.create_vao();
        vao.attrib(ctx, &vbo, 0, 3, yog_gfx::core::DataType::F32, false, 24, 0);
        self.vbo = Some(vbo);
        self.vao = Some(vao);
        self.prog = Some(prog);
    }

    fn render(&mut self, ctx: &GfxContext) {
        self.ensure_init(ctx);
        let vao = self.vao.as_ref().unwrap();
        let prog = self.prog.as_ref().unwrap();
        prog.uniform_mat4(ctx, "uViewProj", &ctx.view_proj());
        ctx.draw_arrays(vao, prog, yog_gfx::core::DrawMode::Triangles, 0, 3);
    }
}