yog-gfx 0.6.0

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

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);
    }
}