Skip to main content

khora_core/lane/
context_keys.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Domain-agnostic context key types for [`LaneContext`](super::LaneContext).
16//!
17//! These newtypes are inserted into a `LaneContext` by agents and extracted
18//! by lanes. Placing them in `khora-core` avoids a cyclic dependency between
19//! `khora-lanes` and `khora-agents`.
20//!
21//! # Render domain
22//!
23//! | Key                          | Meaning                                      |
24//! |------------------------------|----------------------------------------------|
25//! | [`ColorTarget`]              | Texture view to render colour into            |
26//! | [`DepthTarget`]              | Texture view for depth testing                |
27//! | [`ClearColor`]               | Framebuffer clear colour                      |
28//! | [`ShadowAtlasView`]          | Shadow atlas view written by shadow lanes     |
29//! | [`ShadowComparisonSampler`]  | PCF comparison sampler for shadow sampling    |
30//!
31//! # Physics domain
32//!
33//! | Key                  | Meaning                           |
34//! |----------------------|-----------------------------------|
35//! | [`PhysicsDeltaTime`] | Fixed timestep for the current step |
36//!
37//! # Audio domain
38//!
39//! Audio lanes consume an [`Arc<dyn AudioMixBus>`](crate::audio::AudioMixBus)
40//! injected directly into the [`LaneContext`](super::LaneContext) by the
41//! [`AudioAgent`](../../../khora_agents/audio_agent). The bus carries its
42//! own [`StreamInfo`](crate::audio::StreamInfo), so no separate context
43//! key is needed.
44
45use crate::renderer::api::resource::{SamplerId, TextureViewId};
46
47// ─────────────────────────────────────────────────────────────────────────────
48// Render domain
49// ─────────────────────────────────────────────────────────────────────────────
50
51/// Color render target for the current frame.
52#[derive(Debug, Clone, Copy)]
53pub struct ColorTarget(pub TextureViewId);
54
55/// Depth render target for the current frame.
56#[derive(Debug, Clone, Copy)]
57pub struct DepthTarget(pub TextureViewId);
58
59/// Clear color for the current frame.
60#[derive(Debug, Clone, Copy)]
61pub struct ClearColor(pub crate::math::LinearRgba);
62
63/// 2D shadow atlas texture view (directional / spot lights), written by
64/// shadow lanes after `execute()`.
65#[derive(Debug, Clone, Copy)]
66pub struct ShadowAtlasView(pub TextureViewId);
67
68/// Cube shadow atlas texture view (point lights), bound by lit shaders as
69/// `texture_depth_cube_array`. Written by shadow lanes after `execute()`.
70#[derive(Debug, Clone, Copy)]
71pub struct ShadowAtlasCubeView(pub TextureViewId);
72
73/// Shadow comparison sampler, written by shadow lanes after `execute()`.
74#[derive(Debug, Clone, Copy)]
75pub struct ShadowComparisonSampler(pub SamplerId);
76
77// ─────────────────────────────────────────────────────────────────────────────
78// Physics domain
79// ─────────────────────────────────────────────────────────────────────────────
80
81/// Fixed timestep for the current physics step.
82#[derive(Debug, Clone, Copy)]
83pub struct PhysicsDeltaTime(pub f32);