Safe, ergonomic Rust helpers for vitaGL development on PlayStation Vita.
- π‘οΈ RAII Resource Management - GPU resources (buffers, shaders, textures) are automatically cleaned up when dropped
- π Type-Safe APIs - Prevents common OpenGL mistakes at compile time
- π Declarative Macros -
attribute_table!anduniform_table!reduce shader boilerplate - ποΈ Builder Patterns - Fluent APIs for configuration
- π Comprehensive Documentation - All public APIs documented with examples
Add to your Cargo.toml:
[dependencies]
vita_gl_helpers = "0.2"
gl = "0.14"use vita_gl_helpers::prelude::*;
fn main() {
// Initialize vitaGL with builder pattern
let ctx = VitaGlBuilder::new()
.msaa(4)
.build()
.expect("Failed to initialize vitaGL");
// Compile shaders - automatically deleted when dropped
let vert = Shader::compile(r#"
void main(float2 aPos, float4 out gl_Position : POSITION) {
gl_Position = float4(aPos, 0.0, 1.0);
}
"#, ShaderType::Vertex).unwrap();
let frag = Shader::compile(r#"
float4 main() {
return float4(1.0, 0.0, 0.0, 1.0);
}
"#, ShaderType::Fragment).unwrap();
// Link program - automatically deleted when dropped
let program = Program::link(&vert, &frag).unwrap();
// Create buffer - automatically deleted when dropped
let buffer = Buffer::new();
let vertices: [f32; 6] = [0.0, 0.5, 0.5, -0.5, -0.5, -0.5];
buffer.data(gl::ARRAY_BUFFER, &vertices, gl::STATIC_DRAW);
unsafe {
gl::ClearColor(0.2, 0.3, 0.3, 1.0);
}
loop {
unsafe { gl::Clear(gl::COLOR_BUFFER_BIT); }
program.use_program();
// ... draw ...
ctx.swap_buffers();
}
}use vita_gl_helpers::prelude::*;
// Define attribute table for your shader
attribute_table!(MyAttributes,
pos => "aPosition",
color => "aColor"
);
fn setup(program: &Program) {
// Get attribute locations
let attrs = program.get_attribute_table::<MyAttributes>().unwrap();
// Enable all attributes
attrs.enable_all();
// Configure attribute pointers
let pos_format = AttributeFormat::FLOAT2;
let color_format = AttributeFormat::UBYTE4_NORM;
pos_buffer.bind_to(attrs.pos, pos_format, 0, 0);
color_buffer.bind_to(attrs.color, color_format, 0, 0);
}use vita_gl_helpers::prelude::*;
// Define uniform table for your shader
uniform_table!(MyUniforms,
mvp: UniformMatrix4fv => "uMVP",
color: Uniform4fv => "uColor",
time: Uniform1fv => "uTime"
);
fn render(program: &Program, uniforms: &MyUniforms) {
program.use_program();
// Set uniforms
uniforms.mvp.set(matrix_data, false);
uniforms.color.set([1.0, 0.5, 0.0, 1.0]);
uniforms.time.set(elapsed);
}| Module | Description |
|---|---|
buffer |
GPU buffer management with RAII |
shader |
Shader compilation with RAII |
program |
Shader program linking with RAII |
texture |
Texture management with RAII |
attribute |
Vertex attribute configuration |
uniforms |
Uniform variable management |
draw |
Draw call helpers |
errors |
GL error handling |
handle |
Generic RAII handle wrapper |
| Feature | Description |
|---|---|
debug-gl |
Enable GL error checking after operations |
logging |
Enable debug logging via log crate |
[dependencies]
vita_gl_helpers = { version = "0.2", features = ["debug-gl", "logging"] }Version 0.2 introduces breaking changes for RAII support:
| v0.1 | v0.2 | Notes |
|---|---|---|
load_shader() |
Shader::compile() |
Shaders auto-delete |
link_program() |
Program::link() |
Programs auto-delete |
buffers.gen_buffers() |
Buffer::new() |
Buffers auto-delete |
shader.delete() |
(removed) | Automatic cleanup |
initialise_default() |
VitaGlBuilder::new().build() |
Builder pattern |
Legacy APIs are available but deprecated.
Contributions are welcome! Please see the docs/PRD_IMPROVEMENTS.md and docs/ARD_IMPROVEMENTS.md for the roadmap.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.