Skip to content

Commit 5c17a6c

Browse files
committed
files from monorepo @ 14e6258901c6fb47ae598705682837ef6c298e60
0 parents  commit 5c17a6c

File tree

20 files changed

+7991
-0
lines changed

20 files changed

+7991
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.so filter=lfs diff=lfs merge=lfs -text
2+
*.dll filter=lfs diff=lfs merge=lfs -text
3+
*.lib filter=lfs diff=lfs merge=lfs -text
4+
*.a filter=lfs diff=lfs merge=lfs -text
5+
*.dylib filter=lfs diff=lfs merge=lfs -text
6+
*.bin filter=lfs diff=lfs merge=lfs -text
7+
*.exe filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore some special directories
2+
.zig-cache
3+
zig-out
4+
5+
# Ignore some special OS files
6+
*.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 zig-gamedev contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [zopenvr](https://github.com/zig-gamedev/zopenvr)
2+
3+
Zig build package and bindings for [OpenVR](https://github.com/ValveSoftware/openvr) v2.2.3
4+
5+
Work in progress
6+
| Interface | Status |
7+
| --------------- | :-----------------: |
8+
| Applications ||
9+
| BlockQueue | |
10+
| Chaperone ||
11+
| ChaperoneSetup | |
12+
| Compositor | ✅<br/>(d3d12 only) |
13+
| Debug | |
14+
| DriverManager | |
15+
| ExtendedDisplay | |
16+
| HeadsetView | |
17+
| Input ||
18+
| IOBuffer | |
19+
| Notifications | |
20+
| Overlay | |
21+
| OverlayView | |
22+
| Paths | |
23+
| Properties | |
24+
| RenderModels ||
25+
| Resources | |
26+
| Screenshots | |
27+
| Settings | |
28+
| SpatialAnchors | |
29+
| System ||
30+
| TrackedCamera | |
31+
32+
33+
## Getting started
34+
35+
Example `build.zig`:
36+
37+
```zig
38+
pub fn build(b: *std.Build) !void {
39+
const exe = b.addExecutable(.{ ... });
40+
41+
const zopenvr = b.dependency("zopenvr", .{});
42+
43+
exe.root_module.addImport("zopenvr", zopenvr.module("zopenvr"));
44+
45+
try @import("zopenvr").addLibraryPathsTo(zopenvr, exe);
46+
try @import("zopenvr").installOpenVR(zopenvr, &exe.step, target.result, .bin);
47+
@import("zopenvr").linkOpenVR(exe);
48+
}
49+
```
50+
51+
Now in your code you may import and use `zopenvr`:
52+
53+
```zig
54+
const std = @import("std");
55+
const OpenVR = @import("zopenvr");
56+
57+
pub fn main() !void {
58+
...
59+
60+
const openvr = try OpenVR.init(.scene);
61+
defer openvr.deinit();
62+
63+
const system = try openvr.system();
64+
65+
const name = try app.system.allocTrackedDevicePropertyString(allocator, OpenVR.hmd, .tracking_system_name);
66+
defer allocator.free(name);
67+
68+
...
69+
}
70+
```
71+

build.zig

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const zwindows = b.dependency("zwindows", .{
5+
.zxaudio2_debug_layer = b.option(
6+
bool,
7+
"zxaudio2_debug_layer",
8+
"Enable XAudio2 debug layer",
9+
) orelse false,
10+
.zd3d12_debug_layer = b.option(
11+
bool,
12+
"zd3d12_debug_layer",
13+
"Enable DirectX 12 debug layer",
14+
) orelse false,
15+
.zd3d12_gbv = b.option(
16+
bool,
17+
"zd3d12_gbv",
18+
"Enable DirectX 12 GPU-Based Validation (GBV)",
19+
) orelse false,
20+
});
21+
_ = b.addModule("root", .{
22+
.root_source_file = b.path("src/openvr.zig"),
23+
.imports = &.{
24+
.{ .name = "zwindows", .module = zwindows.module("zwindows") },
25+
},
26+
});
27+
}
28+
29+
pub fn addLibraryPathsTo(zopenvr: *std.Build.Dependency, compile_step: *std.Build.Step.Compile) void {
30+
const target = compile_step.rootModuleTarget();
31+
switch (target.os.tag) {
32+
.windows => {
33+
if (target.cpu.arch.isX86()) {
34+
compile_step.addLibraryPath(.{ .dependency = .{
35+
.dependency = zopenvr,
36+
.sub_path = "libs/openvr/lib/win64",
37+
} });
38+
}
39+
},
40+
.linux => {
41+
if (target.cpu.arch.isX86()) {
42+
compile_step.addLibraryPath(.{ .dependency = .{
43+
.dependency = zopenvr,
44+
.sub_path = "libs/openvr/lib/linux64",
45+
} });
46+
}
47+
},
48+
else => {},
49+
}
50+
}
51+
52+
pub fn addRPathsTo(zopenvr: *std.Build.Dependency, compile_step: *std.Build.Step.Compile) void {
53+
const target = compile_step.rootModuleTarget();
54+
switch (target.os.tag) {
55+
.windows => {
56+
if (target.cpu.arch.isX86()) {
57+
compile_step.addRPath(.{ .dependency = .{
58+
.dependency = zopenvr,
59+
.sub_path = "libs/openvr/bin/win64",
60+
} });
61+
}
62+
},
63+
.linux => {
64+
if (target.cpu.arch.isX86()) {
65+
compile_step.addRPath(.{ .dependency = .{
66+
.dependency = zopenvr,
67+
.sub_path = "libs/openvr/bin/linux64",
68+
} });
69+
}
70+
},
71+
else => {},
72+
}
73+
}
74+
75+
pub fn linkOpenVR(compile_step: *std.Build.Step.Compile) void {
76+
switch (compile_step.rootModuleTarget().os.tag) {
77+
.windows, .linux => {
78+
compile_step.linkSystemLibrary("openvr_api");
79+
},
80+
else => {},
81+
}
82+
}
83+
84+
pub fn installOpenVR(
85+
zopenvr: *std.Build.Dependency,
86+
step: *std.Build.Step,
87+
target: std.Target,
88+
install_dir: std.Build.InstallDir,
89+
) void {
90+
const b = step.owner;
91+
switch (target.os.tag) {
92+
.windows => {
93+
if (target.cpu.arch.isX86()) {
94+
step.dependOn(
95+
&b.addInstallFileWithDir(
96+
.{ .dependency = .{
97+
.dependency = zopenvr,
98+
.sub_path = "libs/openvr/bin/win64/openvr_api.dll",
99+
} },
100+
install_dir,
101+
"openvr_api.dll",
102+
).step,
103+
);
104+
}
105+
},
106+
.linux => {
107+
if (target.cpu.arch.isX86()) {
108+
step.dependOn(
109+
&b.addInstallFileWithDir(
110+
.{ .dependency = .{
111+
.dependency = zopenvr,
112+
.sub_path = "libs/openvr/bin/linux64/libopenvr_api.so",
113+
} },
114+
install_dir,
115+
"libopenvr_api.so.0",
116+
).step,
117+
);
118+
}
119+
},
120+
else => {},
121+
}
122+
}

build.zig.zon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.{
2+
.name = "zopenvr",
3+
.version = "0.1.0-dev",
4+
.paths = .{
5+
"build.zig",
6+
"build.zig.zon",
7+
"libs",
8+
"src",
9+
"README.md",
10+
"LICENSE",
11+
},
12+
.dependencies = .{
13+
.zwindows = .{
14+
.url = "https://github.com/zig-gamedev/zwindows/archive/refs/tags/0.1.0.tar.gz",
15+
.hash = "122064d063ba4ba5b767f15879bda76813df85ec973b31460566fbe84c4385f2b387",
16+
},
17+
},
18+
}

libs/openvr/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2015, Valve Corporation
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
14+
3. Neither the name of the copyright holder nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5a450635d90e22a2787dad05a4a26cf6311c7ac61cc3549a7946f4227779a273
3+
size 1752088
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:e5ca2fd8fb753d7bf69d920e72dc7a120b2416b04def194345c3cb01134021bb
3+
size 827712

0 commit comments

Comments
 (0)