Expand description
§siftgl
A memory-safe, ergonomic, zero-dependency, security-hardened OpenGL 3.3–4.6 Core frontend for Rust.
siftgl brings the safety and ergonomics philosophy of siftx12 and siftvulkan to OpenGL:
- Zero Third-Party Dependencies: Directly loads
opengl32.dll(Windows),libGL.so.1(Linux), orOpenGL.framework(macOS) using native OS dynamic linking, or binds to any windowing library viaGlContext::from_loader. Includes built-in headless WGL Core Profile context creation (GlContext::new_offscreen) on Windows. - Compile-Time Thread Affinity:
GlContextand all OpenGL resources are!Send + !Sync, preventing cross-thread OpenGL context misuse at compile time. - FFI Encapsulation & Explicit Safety Invariants: Every
unsafeFFI call is encapsulated behind validated Rust types with explicit// SAFETY:comments and#![forbid(unsafe_op_in_unsafe_fn)]. - Zero Panicking Unwraps: All fallible operations return
Result<T>(GlError), with clippy denies onunwrap_used,expect_used,panic,todo, andunimplemented. - RAII Resource Lifecycle & Teardown Ordering: Every GPU object (
Buffer,Shader,Program,VertexArray,Texture,Sampler,Framebuffer,Renderbuffer,SyncFence,Query,DebugGuard) is deterministically destroyed onDrop, keeping the dispatch table and native context alive until the last object drops. - Security & Bounds Hardening: Checked integer arithmetic on all byte ranges, pixel buffer
length validation on texture uploads and
read_pixels, double-map prevention onBuffer, WGL sentinel pointer filtering (0/1/2/3/-1), interior-NUL string rejection, and panic-safecatch_unwindC FFI trampolines forKHR_debugcallbacks.
§Quick Start
use siftgl::{Buffer, BufferDesc, ContextDesc, GlContext};
fn main() -> siftgl::Result<()> {
#[cfg(windows)]
{
let gl = GlContext::new_offscreen(&ContextDesc::default())?;
let vbo = Buffer::new(&gl, &BufferDesc::vertex(256))?;
vbo.write_bytes(0, b"hello opengl!")?;
gl.check_error()?;
}
Ok(())
}Re-exports§
pub use buffer::Buffer;pub use buffer::BufferDesc;pub use buffer::MappedBuffer;pub use buffer::MappedBufferMut;pub use context::ContextDesc;pub use context::GlContext;pub use debug::DebugGuard;pub use debug::DebugMessage;pub use error::GlError;pub use error::GlErrorCode;pub use error::Result;pub use framebuffer::Framebuffer;pub use framebuffer::Renderbuffer;pub use framebuffer::RenderbufferDesc;pub use shader::ActiveAttribute;pub use shader::ActiveUniform;pub use shader::Program;pub use shader::Shader;pub use sync::Query;pub use sync::QueryTarget;pub use sync::SyncFence;pub use sync::SyncWaitResult;pub use texture::Sampler;pub use texture::SamplerDesc;pub use texture::Texture;pub use texture::Texture2DDesc;pub use types::AttribLocation;pub use types::BlendEquation;pub use types::BlendFactor;pub use types::BufferStorageFlags;pub use types::BufferTarget;pub use types::BufferUsage;pub use types::Capability;pub use types::ClearColor;pub use types::ClearMask;pub use types::CompareFunc;pub use types::ContextInfo;pub use types::CullFace;pub use types::DataType;pub use types::DebugSeverity;pub use types::DebugSource;pub use types::DebugType;pub use types::FramebufferAttachment;pub use types::FramebufferStatus;pub use types::FramebufferTarget;pub use types::FrontFace;pub use types::GlProfile;pub use types::GlVersion;pub use types::IndexType;pub use types::InternalFormat;pub use types::MemoryBarrierFlags;pub use types::PixelFormat;pub use types::PixelType;pub use types::PolygonMode;pub use types::PrimitiveMode;pub use types::ScissorRect;pub use types::ShaderStage;pub use types::TextureFilter;pub use types::TextureTarget;pub use types::TextureWrap;pub use types::UniformLocation;pub use types::Viewport;pub use vao::VertexArray;pub use vao::VertexAttribDesc;
Modules§
- buffer
- Bounds-checked GPU buffers and RAII mapped memory guards.
- context
- Thread-bound OpenGL 3.3–4.6 Core context, pipeline state, draw/compute commands, and zero-dependency offscreen WGL context creation on Windows.
- debug
- Panic-safe OpenGL 4.3 /
KHR_debugcallback registration with RAII cleanup. - error
- Error types and
Resultalias forsiftgl. - framebuffer
- Framebuffer objects (FBOs) and Renderbuffer objects (RBOs) for offscreen rendering.
- loader
- Zero-dependency OpenGL shared library loader and function dispatch table.
- shader
- GLSL shader compilation, program linking, uniform setters, and reflection.
- sync
- GPU fence synchronization (
GLsync) and hardware performance/occlusion queries. - texture
- Bounds-checked OpenGL textures and sampler objects.
- types
- Strongly-typed OpenGL 3.3–4.6 Core value types, enums, and bitflags.
- vao
- Vertex Array Objects (VAOs) and validated vertex attribute layout descriptors.