NYXGFX/README.md

102 lines
2.7 KiB
Markdown
Raw Normal View History

2026-08-11 21:06:28 +01:00
# NYXGFX
Low cortisol crossplatform RHI (Rendering Hardware Interface)
## Backends
2026-08-11 21:11:00 +01:00
- [x] Vulkan
- [ ] OpenGL
- [ ] DX12
2026-08-11 21:06:28 +01:00
## Features
- Fire and forget
- Dead simple + Performance + Flexible
- Handles
2026-08-12 14:52:27 +01:00
- Auto managed
2026-08-11 21:26:15 +01:00
2026-08-12 02:11:57 +01:00
## Architecture
```text
examples/simple/simple.zig
src/gfx.zig
└─ Selected Backend
src/rhi/root.zig
└─ Common / Handles / Configs
src/rhi/vulkan/vulkan.zig
└─ Vulkan Backend / RHI
src/rhi/vulkan/resource.zig
└─ Adapter / Device / Shader
```
2026-08-12 14:52:27 +01:00
| Function | Description |
| ------------------- | ----------------------------------------------------------------- |
| `makeX(...)` | Creates an RHI resource and returns its handle |
| `deleteX(handle)` | Releases the resource and removes it from the resource pool |
| `releaseX(handle)` | Releases the resource without removing it from the resource pool |
2026-08-12 20:31:05 +01:00
| `getXInfo(handle)` | Returns backend-independent information about the resource |
2026-08-12 14:52:27 +01:00
| `getRawVkX(handle)` | Returns the backend-specific raw Vulkan GPU handle |
## Example
### Core
```zig
const adapter = try gfx.makeAdapter(.{});
const surface = try gfx.makeSurface();
const device = try gfx.makeDevice(adapter, surface);
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
```
### Buffers
```zig
const vbuf = try gfx.makeBuffer(vertices, .vertex, adapter, device);
const ibuf = try gfx.makeBuffer(indices, .index, adapter, device);
```
### Shaders
```zig
const simple_vert = try gfx.makeShader("examples/assets/shaders/compiled/simple.vert.spv", device);
const simple_frag = try gfx.makeShader("examples/assets/shaders/compiled/simple.frag.spv", device);
```
### Pipelines
```zig
const pipeline = try gfx.makePipeline(.{
.vertex_attributes = &.{
.{ .location = 0, .format = .vec2, .offset = @offsetOf(Vertex, "pos") },
.{ .location = 1, .format = .vec2, .offset = @offsetOf(Vertex, "normal") },
.{ .location = 2, .format = .vec2, .offset = @offsetOf(Vertex, "uv") },
},
.vertex_binding = .{ .stride = @sizeOf(Vertex) },
.uniforms = &.{
.{ .name = "material", .offset = 0, .size = @sizeOf(UnlitMaterial) },
},
.textures = &.{texture},
.blend_mode = .alpha,
.vert_shader = simple_vert,
.frag_shader = simple_frag,
.device = device,
.swapchain = swapchain,
});
```
### Render Pass
```zig
if (gfx.beginPass(swapchain, .{
.clear_color = .{ 0.01, 0.01, 0.01, 1.0 },
})) |pass| {
defer pass.end();
try vbuf.bind();
try ibuf.bind();
try pipeline.setUniform("material", material);
try pipeline.bind();
pass.drawIndexed(indices.len, 1, 0, 0, 0);
}
```
2026-08-12 02:11:57 +01:00
## Examples
2026-08-11 21:26:15 +01:00
- ```zig build run-simple```
2026-08-12 20:56:56 +01:00
- ```zig build run-3D```