#gpgpu #opengl #opencl #gpu #api-bindings

sys ocl-interop

Creates an OpenCL Context with OpenGL Interop enabled

3 releases

Uses old Rust 2015

0.1.6 Oct 10, 2023
0.1.5 Jan 18, 2019
0.1.4 Jan 11, 2018

#1682 in Concurrency

Download history 66/week @ 2026-01-08 24/week @ 2026-01-15 9/week @ 2026-01-22 49/week @ 2026-01-29 7/week @ 2026-02-05 38/week @ 2026-02-12 18/week @ 2026-02-19 43/week @ 2026-02-26 51/week @ 2026-03-05 37/week @ 2026-03-12 49/week @ 2026-03-19 87/week @ 2026-03-26 49/week @ 2026-04-02 38/week @ 2026-04-09 82/week @ 2026-04-16 61/week @ 2026-04-23

237 downloads per month

MIT/Apache

660KB
12K SLoC

OpenCL + OpenGL Interoperability for Rust

Creates a Context with OpenGL interoperability enabled. DirectX interop is theoretically possible, but not currently implemented. MacOS & OpenGL ES support is untested, but should work.

Usage

Your preferred OpenGL library should be set up and working.

Add the following to your Cargo.toml:

ocl-interop = "0.1"

Add the following to your crate root (lib.rs or main.rs):

extern crate ocl_interop;

Then, when you need the context:

// First, create an OpenGL context and make sure it is active...

// Next, Create an OpenCL context with the interop enabled: (NOTE:
// `::get_context` will return the first available GPU device on your that
// supports OpenGL interop on your system -- you may need to choose a device
// and create the context manually instead if this does not work):
let context = ocl_interop::get_context()?;

// Later, after creating an OpenGL buffer...

// Create an OpenCL buffer from an OpenGL buffer:
let cl_buffer = ocl::Buffer::<f32>::from_gl_buffer(&queue, None, gl_buffer)?;

// Acquire the buffer, making it usable:
cl_buffer.cmd().gl_acquire().enq()?;

// Use the buffer...

// Release the acquisition:
cl_buffer.cmd().gl_release().enq()?;

Dependencies

~1.6–2.2MB
~37K SLoC