Skip to content

Helpers for using vitaGL and the gl crate in rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

captifi/vita_gl_helpers

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

vitaGL Helpers

CI Crates.io Documentation License

Safe, ergonomic Rust helpers for vitaGL development on PlayStation Vita.

Features

  • πŸ›‘οΈ 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! and uniform_table! reduce shader boilerplate
  • πŸ—οΈ Builder Patterns - Fluent APIs for configuration
  • πŸ“š Comprehensive Documentation - All public APIs documented with examples

Quick Start

Add to your Cargo.toml:

[dependencies]
vita_gl_helpers = "0.2"
gl = "0.14"

Basic Example

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

Using Attribute Tables

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

Using Uniform Tables

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

Modules

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 Flags

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"] }

Migration from v0.1

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.

Prerequisites

Contributing

Contributions are welcome! Please see the docs/PRD_IMPROVEMENTS.md and docs/ARD_IMPROVEMENTS.md for the roadmap.

License

Licensed under either of:

at your option.

Acknowledgments

About

Helpers for using vitaGL and the gl crate in rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 100.0%