Skip to content

Commit dfa4a23

Browse files
committed
Reach feature parity with old implementation, fix example code
1 parent 91c17a4 commit dfa4a23

File tree

7 files changed

+220
-26
lines changed

7 files changed

+220
-26
lines changed

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ readme = "README.md"
1010
keywords = ["graphics", "profile", "renderdoc", "trace"]
1111

1212
[features]
13-
default = ["glutin"]
13+
default = ["app", "replay", "glutin"]
14+
app = ["renderdoc_sys/app"]
15+
replay = ["renderdoc_sys/replay"]
1416

1517
[dependencies]
1618
bitflags = "~1.0"

examples/triangle.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ extern crate renderdoc;
2121
use gfx::traits::FactoryExt;
2222
use gfx::Device;
2323
use glutin::GlContext;
24-
use renderdoc::app::{OverlayBits, RenderDoc, V100};
25-
use renderdoc::app::api::RenderDocV100;
24+
use renderdoc::app::{RenderDoc, V110};
25+
use renderdoc::app::prelude::*;
2626

2727
pub type ColorFormat = gfx::format::Rgba8;
2828
pub type DepthFormat = gfx::format::DepthStencil;
@@ -57,7 +57,7 @@ const TRIANGLE: [Vertex; 3] = [
5757
const CLEAR_COLOR: [f32; 4] = [0.1, 0.2, 0.3, 1.0];
5858

5959
pub fn main() {
60-
let mut rd: RenderDoc<V100> = RenderDoc::new().unwrap();
60+
let mut rd: RenderDoc<V110> = RenderDoc::new().unwrap();
6161

6262
let mut events_loop = glutin::EventsLoop::new();
6363
let window_config = glutin::WindowBuilder::new()
@@ -89,18 +89,18 @@ pub fn main() {
8989
events_loop.poll_events(|event| {
9090
if let glutin::Event::WindowEvent { event, .. } = event {
9191
match event {
92-
// glutin::WindowEvent::KeyboardInput {
93-
// input:
94-
// glutin::KeyboardInput {
95-
// virtual_keycode: Some(glutin::VirtualKeyCode::R),
96-
// state: glutin::ElementState::Pressed,
97-
// ..
98-
// },
99-
// ..
100-
// } => match rd.launch_replay_ui(None) {
101-
// Ok(pid) => println!("Launched replay UI ({}).", pid),
102-
// Err(err) => println!("{:?}", err),
103-
// },
92+
glutin::WindowEvent::KeyboardInput {
93+
input:
94+
glutin::KeyboardInput {
95+
virtual_keycode: Some(glutin::VirtualKeyCode::R),
96+
state: glutin::ElementState::Pressed,
97+
..
98+
},
99+
..
100+
} => match rd.launch_replay_ui(None) {
101+
Ok(pid) => println!("Launched replay UI ({}).", pid),
102+
Err(err) => println!("{:?}", err),
103+
},
104104
glutin::WindowEvent::KeyboardInput {
105105
input:
106106
glutin::KeyboardInput {

src/app/api.rs

+194-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub trait RenderDocV100: Sized {
2121
/// # Examples
2222
///
2323
/// ```rust
24-
/// # use renderdoc::{RenderDoc, V100};
25-
/// # use renderdoc::prelude::*;
24+
/// # use renderdoc::app::{RenderDoc, V100};
25+
/// # use renderdoc::app::prelude::*;
2626
/// # fn init() -> Result<(), String> {
2727
/// # let renderdoc: RenderDoc<V100> = RenderDoc::new()?;
2828
/// let (major, minor, patch) = renderdoc.get_api_version();
@@ -39,6 +39,46 @@ pub trait RenderDocV100: Sized {
3939
}
4040
}
4141

42+
/// Sets the specified `CaptureOption` to the given `f32` value.
43+
///
44+
/// # Panics
45+
///
46+
/// This method will panic if the option and/or the value are invalid.
47+
fn set_capture_option_f32(&mut self, opt: CaptureOption, val: f32) {
48+
let raw = opt as u32;
49+
let err = unsafe { (self.entry_v100().SetCaptureOptionF32.unwrap())(raw, val) };
50+
assert_eq!(err, 1);
51+
}
52+
53+
/// Sets the specified `CaptureOption` to the given `u32` value.
54+
///
55+
/// # Panics
56+
///
57+
/// This method will panic if the option and/or the value are invalid.
58+
fn set_capture_option_u32(&mut self, opt: CaptureOption, val: u32) {
59+
let raw = opt as u32;
60+
let err = unsafe { (self.entry_v100().SetCaptureOptionU32.unwrap())(raw, val) };
61+
assert_eq!(err, 1);
62+
}
63+
64+
#[allow(missing_docs)]
65+
fn get_capture_option_f32(&self, opt: CaptureOption) -> f32 {
66+
use std::f32::MAX;
67+
let raw = opt as u32;
68+
let val = unsafe { (self.entry_v100().GetCaptureOptionF32.unwrap())(raw) };
69+
assert_ne!(val, -MAX);
70+
val
71+
}
72+
73+
#[allow(missing_docs)]
74+
fn get_capture_option_u32(&self, opt: CaptureOption) -> u32 {
75+
use std::u32::MAX;
76+
let raw = opt as u32;
77+
let val = unsafe { (self.entry_v100().GetCaptureOptionU32.unwrap())(raw) };
78+
assert_ne!(val, MAX);
79+
val
80+
}
81+
4282
/// Changes the key bindings in-application for triggering a capture on the
4383
/// current window.
4484
fn set_capture_keys<I: Into<InputButton> + Clone>(&mut self, keys: &[I]) {
@@ -49,7 +89,7 @@ pub trait RenderDocV100: Sized {
4989
}
5090

5191
/// Changes the key bindings in-application for changing the focused window.
52-
fn set_focus_toggle_keys<K, I: Into<InputButton> + Clone>(&mut self, keys: &[I]) {
92+
fn set_focus_toggle_keys<I: Into<InputButton> + Clone>(&mut self, keys: &[I]) {
5393
unsafe {
5494
let mut k: Vec<_> = keys.iter().cloned().map(|k| k.into() as u32).collect();
5595
(self.entry_v100().SetFocusToggleKeys.unwrap())(k.as_mut_ptr(), k.len() as i32)
@@ -69,13 +109,161 @@ pub trait RenderDocV100: Sized {
69109
}
70110

71111
#[allow(missing_docs)]
72-
fn set_active_window<D: DevicePointer, W: WindowHandle>(&mut self, dev: D, win: W) {
112+
fn unload_crash_handler(&mut self) {
113+
unsafe {
114+
(self.entry_v100().UnloadCrashHandler.unwrap())();
115+
}
116+
}
117+
118+
#[allow(missing_docs)]
119+
fn get_overlay_bits(&self) -> OverlayBits {
120+
let bits = unsafe { (self.entry_v100().GetOverlayBits.unwrap())() };
121+
OverlayBits::from_bits_truncate(bits)
122+
}
123+
124+
#[allow(missing_docs)]
125+
fn mask_overlay_bits(&mut self, and: OverlayBits, or: OverlayBits) {
126+
unsafe {
127+
(self.entry_v100().MaskOverlayBits.unwrap())(and.bits(), or.bits());
128+
}
129+
}
130+
131+
#[allow(missing_docs)]
132+
fn get_log_file_path_template(&self) -> &str {
133+
unsafe {
134+
let raw = (self.entry_v100().GetLogFilePathTemplate.unwrap())();
135+
CStr::from_ptr(raw).to_str().unwrap()
136+
}
137+
}
138+
139+
#[allow(missing_docs)]
140+
fn set_log_file_path_template<P: AsRef<Path>>(&mut self, path_template: P) {
141+
unsafe {
142+
let bytes = mem::transmute(path_template.as_ref().as_os_str());
143+
let cstr = CStr::from_bytes_with_nul_unchecked(bytes);
144+
(self.entry_v100().SetLogFilePathTemplate.unwrap())(cstr.as_ptr());
145+
}
146+
}
147+
148+
#[allow(missing_docs)]
149+
fn get_num_captures(&self) -> u32 {
150+
unsafe { (self.entry_v100().GetNumCaptures.unwrap())() }
151+
}
152+
153+
#[allow(missing_docs)]
154+
fn get_capture(&self, index: u32) -> Option<(String, u64)> {
155+
unsafe {
156+
let mut len = self.get_log_file_path_template().len() as u32 + 128;
157+
let mut path = Vec::with_capacity(len as usize);
158+
let mut time = 0u64;
159+
160+
if (self.entry_v100().GetCapture.unwrap())(index, path.as_mut_ptr(), &mut len, &mut time) == 1 {
161+
let raw_path = CString::from_raw(path.as_mut_ptr());
162+
let mut path = raw_path.into_string().unwrap();
163+
path.shrink_to_fit();
164+
165+
Some((path, time))
166+
} else {
167+
None
168+
}
169+
}
170+
}
171+
172+
/// Captures the next frame from the currently active window and API device.
173+
///
174+
/// Data is saved to a capture log file at the location specified via
175+
/// `set_log_file_path_template()`.
176+
fn trigger_capture(&mut self) {
177+
unsafe {
178+
(self.entry_v100().TriggerCapture.unwrap())();
179+
}
180+
}
181+
182+
#[allow(missing_docs)]
183+
fn is_target_control_connected(&self) -> bool {
184+
unsafe { (self.entry_v100().IsRemoteAccessConnected.unwrap())() == 1 }
185+
}
186+
187+
#[allow(missing_docs)]
188+
fn launch_replay_ui<C>(&self, cmd_line: C) -> Result<u32, ()>
189+
where
190+
C: Into<Option<&'static str>>,
191+
{
192+
unsafe {
193+
let with_cmd = cmd_line.into();
194+
let (enabled, text) = if let Some(ref cmd) = with_cmd {
195+
let bytes = cmd.as_bytes();
196+
(1, CStr::from_bytes_with_nul_unchecked(bytes))
197+
} else {
198+
(0, Default::default())
199+
};
200+
201+
match (self.entry_v100().LaunchReplayUI.unwrap())(enabled, text.as_ptr()) {
202+
0 => Err(()),
203+
pid => Ok(pid),
204+
}
205+
}
206+
}
207+
208+
#[allow(missing_docs)]
209+
fn set_active_window<D, W>(&mut self, device: D, window: W)
210+
where
211+
D: DevicePointer,
212+
W: WindowHandle
213+
{
73214
unsafe {
74-
let device = dev.as_device_ptr();
75-
let window = win.as_window_handle();
215+
let device = device.as_device_ptr();
216+
let window = window.as_window_handle();
76217
(self.entry_v100().SetActiveWindow.unwrap())(device, window);
77218
}
78219
}
220+
221+
#[allow(missing_docs)]
222+
fn start_frame_capture<D, W>(&mut self, device: D, window: W)
223+
where
224+
D: DevicePointer,
225+
W: WindowHandle
226+
{
227+
unsafe {
228+
let device = device.as_device_ptr();
229+
let window = window.as_window_handle();
230+
(self.entry_v100().StartFrameCapture.unwrap())(device, window);
231+
}
232+
}
233+
234+
/// Returns whether or not a frame capture is currently ongoing anywhere.
235+
///
236+
/// # Examples
237+
///
238+
/// ```rust
239+
/// # use renderdoc::app::{RenderDoc, V100};
240+
/// # use renderdoc::app::prelude::*;
241+
/// # fn init() -> Result<(), String> {
242+
/// # let renderdoc: RenderDoc<V100> = RenderDoc::new()?;
243+
/// if renderdoc.is_frame_capturing() {
244+
/// println!("Frames are being captured.");
245+
/// } else {
246+
/// println!("No frame capture is occurring.");
247+
/// }
248+
/// # Ok(())
249+
/// # }
250+
/// ```
251+
fn is_frame_capturing(&self) -> bool {
252+
unsafe { (self.entry_v100().IsFrameCapturing.unwrap())() == 1 }
253+
}
254+
255+
#[allow(missing_docs)]
256+
fn end_frame_capture<D, W>(&mut self, device: D, window: W)
257+
where
258+
D: DevicePointer,
259+
W: WindowHandle
260+
{
261+
unsafe {
262+
let device = device.as_device_ptr();
263+
let window = window.as_window_handle();
264+
(self.entry_v100().EndFrameCapture.unwrap())(device, window);
265+
}
266+
}
79267
}
80268

81269
/// Additional features for API version 1.1.0.

src/app/ffi.rs

-3
This file was deleted.

src/app/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
pub use self::types::{CaptureOption, DevicePointer, InputButton, OverlayBits, WindowHandle};
44
pub use self::version::{Version, V100, V110};
5+
pub use renderdoc_sys::app as ffi;
56

67
pub mod api;
7-
pub mod ffi;
88
pub mod prelude;
99
pub mod version;
1010

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ extern crate winapi;
1919
#[cfg(target_os = "windows")]
2020
extern crate wio;
2121

22+
#[cfg(feature = "app")]
2223
pub mod app;
24+
25+
#[cfg(feature = "replay")]
26+
pub mod replay;

src/replay/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Replay API bindings.
2+
3+
pub use renderdoc_sys::replay as ffi;

0 commit comments

Comments
 (0)