Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/gpu/opengl"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
ascii |
core/ascii |
opengl.dodo |
backend |
std/gpu/opengl/native |
opengl.dodo |
common |
std/gpu/opengl/common |
opengl.dodo |
gl |
std/gpu/opengl/gl |
opengl.dodo |
handle |
std/window/handle |
opengl.dodo |
mem |
core/mem |
opengl.dodo |
ptr |
core/ptr |
opengl.dodo |
Error
Type alias · Source
pub type Error = common.Error
error_name
Function · Source
pub fn error_name(error: Error) -> &str from(static)
Options
Struct · Source
Which context to create. Versions 3.2 and later use the core profile, the one std/gpu/opengl/gl binds; earlier versions get a legacy context.
pub struct Options {
pub major: u32
pub minor: u32
// Ask for a debug context, which reports errors through
// gl.debug_message_callback. Not every system offers one; macOS ignores it.
pub debug: bool
}
Options.new
Function · Source
OpenGL
major.minorwithout debugging.
pub fn new(major: u32, minor: u32) -> Options
Options.default
Function · Source
OpenGL 3.3 core, which every desktop driver from the last decade and macOS offer.
pub fn default() -> Options
Context
Struct · Source
An OpenGL context, offscreen or for a window. Dropping it destroys the context and, when it was current, clears the gl package’s entry points.
pub struct Context {
// Private implementation fields omitted.
}
Context.create
Function · Source
Create a context, make it current on the calling thread and load the gl package. Fails with InvalidInput for a version OpenGL does not define, NoLibrary or NoDisplay when the system has no usable OpenGL, and Unsupported when the driver’s version is older than requested. The driver may provide a newer compatible version than requested; version() reports it.
pub fn create(options: Options) -> Context!Error
Context.create_for_window
Function · Source
Create a context that draws into a window, make it current on the calling thread and load the gl package.
nativecomes from std/window’s Window.native_handle(); a window opened with window.Options.gpu() has no pixel buffer to waste. Framebuffer 0 is then the window’s drawing area, double buffered with 8-bit color, a 24-bit depth and an 8-bit stencil buffer, in pixels: the size win.size() reports, which on a high-density display is larger than the size the window was opened with. swap_buffers() shows each frame.Linux uses EGL on the window’s libxcb connection (or an Xlib one when the driver lacks EGL_EXT_platform_xcb), macOS an NSOpenGLContext on the window’s view, which must be used from the main thread, and Windows WGL on the window’s device context. Fails with InvalidInput for a handle of another window system, besides the errors of create(). The window must stay open until the context is dropped.
pub fn create_for_window(native: &handle.NativeHandle, options: Options) -> Context!Error
Context.swap_buffers
Function · Source
Show the frame drawn into a window context’s framebuffer 0, waiting for the display’s refresh as set_swap_interval() says. The context must be current. Fails with Unsupported for a context without a window, and System when the window is gone.
pub fn swap_buffers(&self) -> void!Error
Context.set_swap_interval
Function · Source
How many display refreshes each swap_buffers() waits for: 1, the usual default, ties frames to the display, 0 swaps at once. Fails with Unsupported for a context without a window or a driver that cannot change it.
pub fn set_swap_interval(&self, interval: i32) -> void!Error
Context.update_surface
Function · Source
Tell a window context that the window was resized, so its framebuffer takes the new size; call it on every window.Event.Resize. Only macOS needs it, but it costs nothing elsewhere.
pub fn update_surface(&self)
Context.make_current
Function · Source
Make this context current on the calling thread and point the gl package’s commands at it.
pub fn make_current(&self) -> void!Error
Context.is_current
Function · Source
Whether this context is current on the calling thread.
pub fn is_current(&self) -> bool
Context.major
Function · Source
The version the driver provides, at least the requested one.
pub fn major(&self) -> u32
Context.minor
Function · Source
pub fn minor(&self) -> u32
Context.renderer
Function · Source
The driver’s name for the GPU or renderer, such as “llvmpipe” or “Apple M2”, and the full version and vendor text the driver reports. The context must be current.
pub fn renderer(&self) -> &str from(self)
Context.version
Function · Source
pub fn version(&self) -> &str from(self)
Context.vendor
Function · Source
pub fn vendor(&self) -> &str from(self)
Context.proc_address
Function · Source
The address of the command or extension function with this NUL-terminated name, or 0, for functions the gl package does not bind.
pub fn proc_address(&self, name: *const u8) -> usize
Target
Struct · Source
An offscreen framebuffer to draw into: 8-bit RGBA color with a 24-bit depth and 8-bit stencil buffer. Create it while its context is current; dropping it deletes its OpenGL objects in the current context.
pub struct Target {
// Private implementation fields omitted.
}
Target.new
Function · Source
A target of
widthbyheightpixels, bound for drawing with the viewport covering it. Fails with InvalidInput for a zero size or one above the driver’s renderbuffer limit, and Unsupported before OpenGL 3.0 or when the driver cannot render to it.
pub fn new(width: u32, height: u32) -> Target!Error
Target.width
Function · Source
pub fn width(&self) -> u32
Target.height
Function · Source
pub fn height(&self) -> u32
Target.framebuffer
Function · Source
The framebuffer object’s name, for gl commands that take one.
pub fn framebuffer(&self) -> u32
Target.bind
Function · Source
Draw into this target from now on, with the viewport covering it.
pub fn bind(&self)
Target.bytes_needed
Function · Source
How many bytes read_rgba and read_bgra write: width * height * 4.
pub fn bytes_needed(&self) -> usize
Target.read_rgba
Function · Source
Copy the pixels into
pixels, four bytes each in the order red, green, blue, alpha, with rows top to bottom as std/graphics stores them (OpenGL’s own rows run bottom to top). Waits for drawing to finish. Fails with InvalidInput whenpixelsis shorter than bytes_needed().
pub fn read_rgba(&self, pixels: &mut[u8]) -> void!Error
Target.read_bgra
Function · Source
The same in the order blue, green, red, alpha: graphics.PixelFormat Bgra8888, the layout of a std/window canvas.
pub fn read_bgra(&self, pixels: &mut[u8]) -> void!Error