Skip to content

Commit c488fb9

Browse files
committed
Lots of cross-platform polish
* Temporary hacks for rust-lang/rust-bindgen#1244 * Implement WindowHandle trait * Add rudimentary EGL support (see renderdoc/issues#853) * Fix compilation bugs with Windows and winapi * Modernize triangle example * Change replay wrapper filenames to snake case
1 parent e9c1d31 commit c488fb9

29 files changed

+449
-203
lines changed

Cargo.toml

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

1212
[features]
13-
default = ["app", "replay", "glutin"]
13+
default = ["app", "glutin", "replay"]
1414
app = ["renderdoc_sys/app"]
1515
replay = ["renderdoc_sys/replay"]
1616

@@ -22,7 +22,7 @@ renderdoc_sys = { version = "0.1", path = "renderdoc_sys" }
2222
shared_library = "0.1.8"
2323

2424
[target.'cfg(windows)'.dependencies]
25-
winapi = "~0.2.8"
25+
winapi = { version = "~0.3", features = ["d3d11", "d3d12", "guiddef"] }
2626
wio = "~0.1.2"
2727

2828
[dev-dependencies]

examples/shader/triangle_300_es.glslf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#version 300 es
2+
precision mediump float;
3+
4+
in vec4 v_Color;
5+
out vec4 Target0;
6+
7+
void main() {
8+
Target0 = v_Color;
9+
}

examples/shader/triangle_300_es.glslv

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#version 300 es
2+
3+
in vec2 a_Pos;
4+
in vec3 a_Color;
5+
out vec4 v_Color;
6+
7+
void main() {
8+
v_Color = vec4(a_Color, 1.0);
9+
gl_Position = vec4(a_Pos, 0.0, 1.0);
10+
}

examples/triangle.rs

+44-25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
#![cfg_attr(target_os = "emscripten", allow(unused_mut))] // this is annoying...
1415

1516
#[macro_use]
1617
extern crate gfx;
@@ -63,16 +64,33 @@ pub fn main() {
6364
let window_config = glutin::WindowBuilder::new()
6465
.with_title("Triangle example".to_string())
6566
.with_dimensions(1024, 768);
66-
let context = glutin::ContextBuilder::new().with_vsync(true);
67+
68+
let (api, version, vs_code, fs_code) = if cfg!(target_os = "emscripten") {
69+
(
70+
glutin::Api::WebGl,
71+
(2, 0),
72+
include_bytes!("shader/triangle_300_es.glslv").to_vec(),
73+
include_bytes!("shader/triangle_300_es.glslf").to_vec(),
74+
)
75+
} else {
76+
(
77+
glutin::Api::OpenGl,
78+
(3, 2),
79+
include_bytes!("shader/triangle_150_core.glslv").to_vec(),
80+
include_bytes!("shader/triangle_150_core.glslf").to_vec(),
81+
)
82+
};
83+
84+
let context = glutin::ContextBuilder::new()
85+
.with_gl(glutin::GlRequest::Specific(api, version))
86+
.with_gl_profile(glutin::GlProfile::Core)
87+
.with_vsync(true);
6788
let (window, mut device, mut factory, main_color, mut main_depth) =
6889
gfx_window_glutin::init::<ColorFormat, DepthFormat>(window_config, context, &events_loop);
69-
let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
90+
let mut encoder = gfx::Encoder::from(factory.create_command_buffer());
91+
7092
let pso = factory
71-
.create_pipeline_simple(
72-
include_bytes!("shader/triangle_150.glslv"),
73-
include_bytes!("shader/triangle_150.glslf"),
74-
pipe::new(),
75-
)
93+
.create_pipeline_simple(&vs_code, &fs_code, pipe::new())
7694
.unwrap();
7795
let (vertex_buffer, slice) = factory.create_vertex_buffer_with_slice(&TRIANGLE, ());
7896
let mut data = pipe::Data {
@@ -87,33 +105,34 @@ pub fn main() {
87105
let mut running = true;
88106
while running {
89107
events_loop.poll_events(|event| {
90-
if let glutin::Event::WindowEvent { event, .. } = event {
108+
use glutin::{Event, KeyboardInput, VirtualKeyCode, WindowEvent};
109+
110+
if let Event::WindowEvent { event, .. } = event {
91111
match event {
92-
glutin::WindowEvent::KeyboardInput {
112+
WindowEvent::Closed
113+
| WindowEvent::KeyboardInput {
93114
input:
94-
glutin::KeyboardInput {
95-
virtual_keycode: Some(glutin::VirtualKeyCode::R),
96-
state: glutin::ElementState::Pressed,
115+
KeyboardInput {
116+
virtual_keycode: Some(VirtualKeyCode::Escape),
97117
..
98118
},
99119
..
100-
} => match rd.launch_replay_ui(None) {
101-
Ok(pid) => println!("Launched replay UI ({}).", pid),
102-
Err(err) => println!("{:?}", err),
103-
},
104-
glutin::WindowEvent::KeyboardInput {
120+
} => running = false,
121+
WindowEvent::Resized(width, height) => {
122+
window.resize(width, height);
123+
gfx_window_glutin::update_views(&window, &mut data.out, &mut main_depth);
124+
}
125+
WindowEvent::KeyboardInput {
105126
input:
106-
glutin::KeyboardInput {
107-
virtual_keycode: Some(glutin::VirtualKeyCode::Escape),
127+
KeyboardInput {
128+
virtual_keycode: Some(VirtualKeyCode::R),
108129
..
109130
},
110131
..
111-
}
112-
| glutin::WindowEvent::Closed => running = false,
113-
glutin::WindowEvent::Resized(width, height) => {
114-
window.resize(width, height);
115-
gfx_window_glutin::update_views(&window, &mut data.out, &mut main_depth);
116-
}
132+
} => match rd.launch_replay_ui(true, None) {
133+
Ok(pid) => println!("Launched replay UI ({}).", pid),
134+
Err(err) => println!("{:?}", err),
135+
},
117136
_ => (),
118137
}
119138
}

renderdoc_sys/build.rs

+44-17
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ fn main() {
99

1010
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
1111

12-
if cfg!(feature = "app") {
13-
gen_app_bindings(&out_path);
14-
}
12+
if cfg!(not(apple)) {
13+
if cfg!(feature = "app") {
14+
gen_app_bindings(&out_path);
15+
}
1516

16-
if cfg!(feature = "replay") {
17-
gen_replay_bindings(&out_path);
17+
if cfg!(feature = "replay") {
18+
gen_replay_bindings(&out_path);
19+
}
1820
}
1921
}
2022

@@ -31,15 +33,21 @@ fn gen_app_bindings<P: AsRef<Path>>(out_path: P) {
3133
}
3234

3335
fn gen_replay_bindings<P: AsRef<Path>>(out_path: P) {
36+
#[cfg(unix)]
37+
let platform_args = ["-DRENDERDOC_PLATFORM_LINUX", "-DRENDERDOC_WINDOWING_XLIB"];
38+
39+
#[cfg(windows)]
40+
let platform_args = ["-DRENDERDOC_PLATFORM_WIN32"];
41+
3442
let replay = bindgen::Builder::default()
3543
.header("replay/wrapper.h")
3644
.clang_args(&[
3745
"-x",
3846
"c++",
3947
"-std=c++11",
40-
"-DRENDERDOC_PLATFORM_LINUX",
41-
"-DRENDERDOC_WINDOWING_XLIB"
48+
"-Irenderdoc"
4249
])
50+
.clang_args(&platform_args)
4351
.opaque_type("std::.*")
4452
.whitelist_function("GetNewUniqueId")
4553
.whitelist_function("RENDERDOC_.*")
@@ -76,19 +84,38 @@ fn gen_replay_bindings<P: AsRef<Path>>(out_path: P) {
7684
.write_to_file(out_path.as_ref().join("replay.rs"))
7785
.expect("Couldn't write replay bindings!");
7886

79-
cc::Build::new()
87+
let mut build = cc::Build::new();
88+
89+
#[cfg(unix)]
90+
build
91+
.define("RENDERDOC_PLATFORM_LINUX", None)
92+
.define("RENDERDOC_WINDOWING_XLIB", None);
93+
94+
#[cfg(windows)]
95+
build.define("RENDERDOC_PLATFORM_WINDOWS", None);
96+
97+
build
8098
.include("replay")
8199
.include("renderdoc")
82-
.file("replay/src/Api.cpp")
83-
.file("replay/src/Camera.cpp")
84-
.file("replay/src/CaptureFile.cpp")
85-
.file("replay/src/RemoteServer.cpp")
86-
.file("replay/src/ReplayController.cpp")
87-
.file("replay/src/ReplayOutput.cpp")
88-
.file("replay/src/TargetControl.cpp")
89-
.define("RENDERDOC_PLATFORM_LINUX", None)
90-
.define("RENDERDOC_WINDOWING_XLIB", None)
100+
.file("replay/src/api.cpp")
101+
.file("replay/src/camera.cpp")
102+
.file("replay/src/capture_file.cpp")
103+
.file("replay/src/remote_server.cpp")
104+
.file("replay/src/replay_controller.cpp")
105+
.file("replay/src/replay_output.cpp")
106+
.file("replay/src/target_control.cpp")
107+
.object(library_path())
91108
.pic(true)
92109
.cpp(true)
93110
.compile("librenderdoc.a");
94111
}
112+
113+
#[cfg(windows)]
114+
fn library_path() -> &'static Path {
115+
Path::new("C:\\Program Files (x64)\\RenderDoc\\renderdoc.dll")
116+
}
117+
118+
#[cfg(unix)]
119+
fn library_path() -> &'static Path {
120+
Path::new("/usr/lib/librenderdoc.so")
121+
}

renderdoc_sys/replay/include/Core.h renamed to renderdoc_sys/replay/include/core.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef uint32_t bool32;
2929
#define RENDERDOC_API __declspec(dllimport)
3030
#endif
3131
#define RENDERDOC_CC __cdecl
32+
3233
#elif defined(RENDERDOC_PLATFORM_LINUX) || defined(RENDERDOC_PLATFORM_APPLE) || \
3334
defined(RENDERDOC_PLATFORM_ANDROID)
3435

renderdoc_sys/replay/src/Api.cpp renamed to renderdoc_sys/replay/src/api.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/Api.h"
4-
5-
#include "../include/Camera.h"
6-
#include "../include/CaptureFile.h"
7-
#include "../include/RemoteServer.h"
8-
#include "../include/ReplayController.h"
9-
#include "../include/ReplayOutput.h"
10-
#include "../include/TargetControl.h"
3+
#include "../include/api.h"
4+
5+
#include "../include/camera.h"
6+
#include "../include/capture_file.h"
7+
#include "../include/remote_server.h"
8+
#include "../include/replay_controller.h"
9+
#include "../include/replay_output.h"
10+
#include "../include/target_control.h"
1111

1212
Camera *RENDERDOC::InitCamera(CameraType type) {
1313
return new Camera(type);

renderdoc_sys/replay/src/Camera.cpp renamed to renderdoc_sys/replay/src/camera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/Camera.h"
3+
#include "../include/camera.h"
44

55
Camera::Camera(CameraType type) {
66
this->inner = RENDERDOC_InitCamera(type);

renderdoc_sys/replay/src/CaptureFile.cpp renamed to renderdoc_sys/replay/src/capture_file.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/CaptureFile.h"
4-
#include "../include/ReplayController.h"
3+
#include "../include/capture_file.h"
4+
#include "../include/replay_controller.h"
55

66
CaptureFile::CaptureFile(ICaptureFile *inner) {
77
this->inner = inner;

renderdoc_sys/replay/src/RemoteServer.cpp renamed to renderdoc_sys/replay/src/remote_server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/RemoteServer.h"
4-
#include "../include/ReplayController.h"
3+
#include "../include/remote_server.h"
4+
#include "../include/replay_controller.h"
55

66
RemoteServer::RemoteServer(IRemoteServer *inner) {
77
this->inner = inner;

renderdoc_sys/replay/src/ReplayController.cpp renamed to renderdoc_sys/replay/src/replay_controller.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/ReplayController.h"
4-
#include "../include/ReplayOutput.h"
3+
#include "../include/replay_controller.h"
4+
#include "../include/replay_output.h"
55

66
APIProperties ReplayController::GetAPIProperties() {
77
return this->inner->GetAPIProperties();

renderdoc_sys/replay/src/ReplayOutput.cpp renamed to renderdoc_sys/replay/src/replay_output.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/ReplayOutput.h"
3+
#include "../include/replay_output.h"
44

55
void ReplayOutput::SetTextureDisplay(const TextureDisplay &o) {
66
this->inner->SetTextureDisplay(o);

renderdoc_sys/replay/src/TargetControl.cpp renamed to renderdoc_sys/replay/src/target_control.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../../renderdoc/renderdoc/api/replay/renderdoc_replay.h"
22

3-
#include "../include/TargetControl.h"
3+
#include "../include/target_control.h"
44

55
TargetControl::TargetControl(ITargetControl *inner) {
66
this->inner = inner;

renderdoc_sys/replay/wrapper.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef WRAPPER_H
22
#define WRAPPER_H
33

4-
#include "include/Core.h"
4+
#include "include/core.h"
55

66
#include "../renderdoc/renderdoc/api/replay/basic_types.h"
77
#include "../renderdoc/renderdoc/api/replay/capture_options.h"
@@ -15,12 +15,12 @@
1515
#include "../renderdoc/renderdoc/api/replay/vk_pipestate.h"
1616
#include "../renderdoc/renderdoc/api/replay/version.h"
1717

18-
#include "include/Api.h"
19-
#include "include/Camera.h"
20-
#include "include/CaptureFile.h"
21-
#include "include/RemoteServer.h"
22-
#include "include/ReplayController.h"
23-
#include "include/ReplayOutput.h"
24-
#include "include/TargetControl.h"
18+
#include "include/api.h"
19+
#include "include/camera.h"
20+
#include "include/capture_file.h"
21+
#include "include/remote_server.h"
22+
#include "include/replay_controller.h"
23+
#include "include/replay_output.h"
24+
#include "include/target_control.h"
2525

2626
#endif // WRAPPER_H

renderdoc_sys/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! Raw FFI bindings to RenderDoc.
1+
//! Raw FFI bindings [RenderDoc], a popular graphics debugger.
2+
//!
3+
//! [RenderDoc]: https://renderdoc.org/
24
35
#![allow(non_upper_case_globals)]
46
#![allow(non_camel_case_types)]

0 commit comments

Comments
 (0)