Skip to main content

oxihuman_viewer/
render_target_debug_view.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Render target debug view — visualizes attachment formats, resolve, and clear state.
6
7/// Render target debug view configuration.
8#[derive(Debug, Clone)]
9pub struct RenderTargetDebugView {
10    pub enabled: bool,
11    pub attachment_count: u32,
12    pub width: u32,
13    pub height: u32,
14    pub show_depth_attachment: bool,
15}
16
17impl RenderTargetDebugView {
18    pub fn new() -> Self {
19        Self {
20            enabled: false,
21            attachment_count: 1,
22            width: 1920,
23            height: 1080,
24            show_depth_attachment: true,
25        }
26    }
27}
28
29impl Default for RenderTargetDebugView {
30    fn default() -> Self {
31        Self::new()
32    }
33}
34
35/// Create a new render target debug view.
36pub fn new_render_target_debug_view() -> RenderTargetDebugView {
37    RenderTargetDebugView::new()
38}
39
40/// Enable or disable render target debug overlay.
41pub fn rtdv_set_enabled(v: &mut RenderTargetDebugView, enabled: bool) {
42    v.enabled = enabled;
43}
44
45/// Set render target dimensions.
46pub fn rtdv_set_dimensions(v: &mut RenderTargetDebugView, width: u32, height: u32) {
47    v.width = width.max(1);
48    v.height = height.max(1);
49}
50
51/// Set attachment count.
52pub fn rtdv_set_attachment_count(v: &mut RenderTargetDebugView, count: u32) {
53    v.attachment_count = count.clamp(1, 8);
54}
55
56/// Toggle depth attachment display.
57pub fn rtdv_set_show_depth_attachment(v: &mut RenderTargetDebugView, show: bool) {
58    v.show_depth_attachment = show;
59}
60
61/// Compute total pixel count across all color attachments.
62pub fn rtdv_total_pixels(v: &RenderTargetDebugView) -> u64 {
63    v.width as u64 * v.height as u64 * v.attachment_count as u64
64}
65
66/// Serialize to JSON-like string.
67pub fn render_target_debug_view_to_json(v: &RenderTargetDebugView) -> String {
68    format!(
69        r#"{{"enabled":{},"attachment_count":{},"width":{},"height":{},"show_depth_attachment":{}}}"#,
70        v.enabled, v.attachment_count, v.width, v.height, v.show_depth_attachment
71    )
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77
78    #[test]
79    fn test_defaults() {
80        let v = new_render_target_debug_view();
81        assert!(!v.enabled);
82        assert_eq!(v.width, 1920);
83        assert_eq!(v.height, 1080);
84    }
85
86    #[test]
87    fn test_enable() {
88        let mut v = new_render_target_debug_view();
89        rtdv_set_enabled(&mut v, true);
90        assert!(v.enabled);
91    }
92
93    #[test]
94    fn test_set_dimensions() {
95        let mut v = new_render_target_debug_view();
96        rtdv_set_dimensions(&mut v, 2560, 1440);
97        assert_eq!(v.width, 2560);
98        assert_eq!(v.height, 1440);
99    }
100
101    #[test]
102    fn test_dimensions_min() {
103        let mut v = new_render_target_debug_view();
104        rtdv_set_dimensions(&mut v, 0, 0);
105        assert_eq!(v.width, 1);
106        assert_eq!(v.height, 1);
107    }
108
109    #[test]
110    fn test_attachment_count_clamp() {
111        let mut v = new_render_target_debug_view();
112        rtdv_set_attachment_count(&mut v, 20);
113        assert_eq!(v.attachment_count, 8);
114    }
115
116    #[test]
117    fn test_attachment_count_min() {
118        let mut v = new_render_target_debug_view();
119        rtdv_set_attachment_count(&mut v, 0);
120        assert_eq!(v.attachment_count, 1);
121    }
122
123    #[test]
124    fn test_show_depth_toggle() {
125        let mut v = new_render_target_debug_view();
126        rtdv_set_show_depth_attachment(&mut v, false);
127        assert!(!v.show_depth_attachment);
128    }
129
130    #[test]
131    fn test_total_pixels() {
132        let mut v = new_render_target_debug_view();
133        rtdv_set_dimensions(&mut v, 100, 100);
134        rtdv_set_attachment_count(&mut v, 2);
135        assert_eq!(rtdv_total_pixels(&v), 20000);
136    }
137
138    #[test]
139    fn test_json_keys() {
140        let v = new_render_target_debug_view();
141        let s = render_target_debug_view_to_json(&v);
142        assert!(s.contains("attachment_count"));
143    }
144
145    #[test]
146    fn test_clone() {
147        let v = new_render_target_debug_view();
148        let v2 = v.clone();
149        assert_eq!(v2.width, v.width);
150    }
151}