Skip to main content

wayrs_egl/
lib.rs

1//! Brings OpneGL-(ES) to `wayrs`.
2//!
3//! Requires EGL 1.4 with the following extensions:
4//! - [`EGL_KHR_platform_gbm`][1]
5//! - [`EGL_KHR_no_config_context`][2]
6//! - [`EGL_KHR_surfaceless_context`][3]
7//! - [`EGL_EXT_image_dma_buf_import_modifiers`][4]
8//! - [`GL_OES_EGL_image`][5]
9//!
10//! [1]: https://registry.khronos.org/EGL/extensions/KHR/EGL_KHR_platform_gbm.txt
11//! [2]: https://registry.khronos.org/EGL/extensions/KHR/EGL_KHR_no_config_context.txt
12//! [3]: https://registry.khronos.org/EGL/extensions/KHR/EGL_KHR_surfaceless_context.txt
13//! [4]: https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_image_dma_buf_import_modifiers.txt
14//! [5]: https://registry.khronos.org/OpenGL/extensions/OES/OES_EGL_image.txt
15//!
16//! # Usage
17//!
18//! 1. Subscribe to `zwp_linux_dmabuf_feedback_v1` (for example, using `wayrs_utils::dmabuf_feedback::DmabufFeedback`).
19//! 1. When feedback is received, get the render node path using [`DrmDevice`] and create [`EglDisplay`] for the given path.
20//! 1. Select buffer formats that where advertised by dmabuf feedback and are supported by [`EglDisplay`]. From these formats choose the one you will use.
21//! 1. Create [`EglContext`] using [`EglContextBuilder`] and make it current.
22//! 1. Load graphics API functons using [`egl_ffi::eglGetProcAddress`].
23//! 1. Assert that `GL_OES_EGL_image` is supported.
24//! 1. Setup a framebuffer and a renderbuffer objects.
25//! 1. Create a [`BufferPool`] with the desired number of buffers. Three may be a good choice. This step is optional, you may manually manage your buffers.
26//!
27//! Before rendering, select a free [`Buffer`] and link it to your renderbuffer object using
28//! [`Buffer::set_as_gl_renderbuffer_storage`]. After rendering, attach and commit
29//! [`Buffer::wl_buffer`].
30//!
31//! See an example in [`examples/triangle.rs`](https://github.com/MaxVerevkin/wayrs/blob/main/wayrs-egl/examples/triangle.rs).
32
33#![deny(unsafe_op_in_unsafe_fn)]
34
35use std::fmt;
36
37mod buffer;
38mod drm;
39mod egl;
40mod errors;
41mod gbm;
42mod xf86drm_ffi;
43
44pub mod egl_ffi;
45pub use buffer::{Buffer, BufferPool};
46pub use drm::DrmDevice;
47pub use egl::{EglContext, EglContextBuilder, EglDisplay, EglExtensions};
48pub use errors::*;
49
50#[derive(Debug, Clone, Copy)]
51pub enum GraphicsApi {
52    OpenGl,
53    OpenGlEs,
54    OpenVg,
55}
56
57/// A DRM fourcc format wrapper with nice `Debug` formatting
58#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
59pub struct Fourcc(pub u32);
60
61impl fmt::Debug for Fourcc {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        let [a, b, c, d] = self.0.to_le_bytes();
64        write!(
65            f,
66            "{}{}{}{}",
67            a.escape_ascii(),
68            b.escape_ascii(),
69            c.escape_ascii(),
70            d.escape_ascii()
71        )
72    }
73}
74
75const DRM_FORMAT_MOD_INVALID: u64 = 72057594037927935;