# drm-gfx
<a href="https://crates.io/crates/drm-gfx"><img alt="crates.io" src="https://img.shields.io/crates/v/drm-gfx"></a>
<a href="https://github.com/FLimburg/drm-gfx/actions"><img alt="actions" src="https://github.com/FLimburg/drm-gfx/actions/workflows/rust.yml/badge.svg"></a>
A 3D graphics rendering library for the Linux Direct Rendering Manager (DRM). This library provides a lightweight 3D rendering engine that works directly with the DRM interface, without requiring a full graphics stack or window manager.
Or to put it more bluntly:
I stitched together https://github.com/Kezii/embedded-gfx/tree/master with https://github.com/Smithay/drm-rs/tree/develop without any care and threw it into https://github.com/FLimburg/drm-gfx .
## Features
- 3D mesh rendering with multiple render modes (Points, Lines, Solid, Directional Lighting)
- Camera with configurable position, target, and field of view
- Support for transformations and model matrices
- Backface culling
- Simple lighting model
- Direct rendering to DRM framebuffers
- Double buffering support
- Performance counters for optimization
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
drm-gfx = "0.2.1"
```
### features
use feature tokio-thread to use drm-gfx in a tokio based application
### Basic Example
screen resolution will be detected automatically (... it worked on my machine)
`cargo build -r [--features=tokio-threads]`
Run the examples:
`cargo run -r --example triangles`
`cargo run -r --features tokio-threads --example tokio-triangles`
## Supported Render Modes
- **Points**: Renders just the vertices as points
- **Lines**: Renders edges of the mesh as lines
- **Solid**: Renders filled triangles with backface culling
- **SolidLightDir**: Adds directional lighting to solid rendering
## Dependencies
- `embedded-graphics-core`: For pixel color representation
- `nalgebra`: For matrix math and transformations
- `line_drawing`: For line rasterization
- `drm`: For interfacing with the Direct Rendering Manager
## Performance
The library includes performance counters that can be used to measure rendering time and optimize your application.
```rust
use drm_gfx::perfcounter::PerfCounter;
let mut perf = PerfCounter::new();
perf.start();
// Perform rendering
perf.end();
println!("Rendering took {} ms", perf.elapsed_ms());
```
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.
## unit test disclaimer
All unit tests are autogenerated by some ai.