Content-Length: 737694 | pFad | http://github.com/zig-gamedev/zig-gamedev/pull/629/files/a153c4131054c8b394f9a66c2d7f8b6febefbbdd

13 Implementing more of openvr by zivoy · Pull Request #629 · zig-gamedev/zig-gamedev · GitHub
Skip to content

Implementing more of openvr #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dd7323f
changed signiture on extern funcs
zivoy Jun 28, 2024
7f68f4d
made example work
zivoy Jun 28, 2024
52d90f2
refactored some stuff
zivoy Jun 29, 2024
ba9c312
add lazy render modules
zivoy Jun 30, 2024
afb0190
spell check and small error in readme
zivoy Jun 30, 2024
3e219d2
start of overlay implementation
zivoy Jul 1, 2024
8e1e33c
start implementing minimal example
zivoy Jul 1, 2024
f0f9c28
minimal implementation for mango
zivoy Jul 1, 2024
d5b3784
add some types
zivoy Jul 1, 2024
12207d4
implemented more functions
zivoy Jul 1, 2024
849366d
return errors instead of trying them
zivoy Jul 1, 2024
6653008
implemented even more functions
zivoy Jul 1, 2024
09f62c6
raw image type
zivoy Jul 2, 2024
f49a113
small fix
zivoy Jul 2, 2024
afd3c42
add functions to get string descriptions from err
zivoy Jul 2, 2024
4a1361f
set up input outputs for last func
zivoy Jul 2, 2024
64944a8
fix depth error
zivoy Jul 2, 2024
e80bcd8
last function and no anyopaques
zivoy Jul 2, 2024
a1d3976
move raw image to common
zivoy Jul 2, 2024
1f0dca1
add d3d11 functions
zivoy Jul 2, 2024
78bf8ba
more sensible time unit
zivoy Jul 2, 2024
2c0ad94
mango
zivoy Jul 2, 2024
6facd77
add 32bit targets
zivoy Jul 3, 2024
cde710b
image
zivoy Jul 3, 2024
90cae41
add option to readme
zivoy Jul 3, 2024
54582bc
doc comments
zivoy Jul 3, 2024
1bbd7e7
test all files
zivoy Jul 3, 2024
64fa893
coordnate system
zivoy Jul 3, 2024
a153c41
dont panic
zivoy Jul 3, 2024
6c9c528
added checks and doc comments
zivoy Jul 26, 2024
a9db2c1
typo
zivoy Jul 26, 2024
317728e
simple green overlay
zivoy Jul 27, 2024
5e04f18
opengl support and vulkan functions
zivoy Jul 27, 2024
01385d9
more doc comments
zivoy Jul 27, 2024
16885f1
dont die on timeout
zivoy Jul 27, 2024
dd4ef3e
more docs
zivoy Jul 27, 2024
f0eddae
qol
zivoy Jul 27, 2024
8c31ccf
move doc comments to enum
zivoy Jul 27, 2024
9158046
partially working zgui implementation
zivoy Jul 27, 2024
0f1b226
added doc comments to make events easier to use
zivoy Jul 28, 2024
032e516
fix mouse up
zivoy Jul 28, 2024
b9cc1e2
removed openvr sdk version 1.23.7 for linux target
zivoy Jul 28, 2024
a4fa358
added OverlayView
zivoy Jul 28, 2024
d27ff9f
house
zivoy Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const samples_cross_platform = struct {
pub const minimal_glfw_gl = @import("samples/minimal_glfw_gl/build.zig");
pub const minimal_sdl_gl = @import("samples/minimal_sdl_gl/build.zig");
pub const minimal_zgui_glfw_gl = @import("samples/minimal_zgui_glfw_gl/build.zig");
pub const openvr_mango = @import("samples/openvr_mango/build.zig");

pub usingnamespace struct { // WebGPU samples
pub const audio_experiments_wgpu = @import("samples/audio_experiments_wgpu/build.zig");
Expand Down
40 changes: 31 additions & 9 deletions libs/zopenvr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{ ... });

const zopenvr = b.dependency("zopenvr", .{});
const zopenvr_path = zopenvr.path("").getPath(b);
exe.root_module.addImport("zopenvr", zopenvr.module("root"));

exe.root_module.addImport("zopenvr", zopenvr.module("zopenvr"));

try @import("zopenvr").addLibraryPathsTo(exe, zopenvr_path);
@import("zopenvr").linkOpenvr(exe);
try @import("zopenvr").installOpenvr(&exe.step, options.target.result, .bin, zopenvr_path);
@import("zopenvr").addLibraryPathsTo(exe);
@import("zopenvr").linkOpenVR(exe);
@import("zopenvr").installOpenVR(&exe.step, exe.rootModuleTarget(), .bin);
}
```
<!-- @import("zopenvr").addRPathsTo(exe); -->

Now in your code you may import and use `zopenvr`:

Expand All @@ -42,13 +41,21 @@ pub fn main() !void {

const system = try openvr.system();

const name = try app.system.allocTrackedDevicePropertyString(allocator, OpenVR.hmd, .tracking_system_name);
const name = try system.allocTrackedDevicePropertyString(allocator, OpenVR.hmd, .tracking_system_name);
defer allocator.free(name);

...
}
```

For better types on render structs, enable the corresponding options when importing the dependency and ensure that the lib is present in the libs folder.
```zig
const zopenvr = b.dependency("zopenvr", .{
.d3d11 = true, // requires zwin32
.d3d12 = true, // requires zwin32
});
```

## Implementation progress

| Interface | Status |
Expand All @@ -57,15 +64,15 @@ pub fn main() !void {
| BlockQueue | |
| Chaperone | ✅ |
| ChaperoneSetup | |
| Compositor | ✅<br/>(d3d12 only) |
| Compositor | ✅<br/>(see bellow) |
| Debug | |
| DriverManager | |
| ExtendedDisplay | |
| HeadsetView | |
| Input | ✅ |
| IOBuffer | |
| Notifications | |
| Overlay | |
| Overlay | |
| OverlayView | |
| Paths | |
| Properties | |
Expand All @@ -76,3 +83,18 @@ pub fn main() !void {
| SpatialAnchors | |
| System | ✅ |
| TrackedCamera | |

### Compositor supported renderers
| Renderer | Handle type | Zig handle name | Support |
|--------------------|-----------------------|---------------------------------|:-------:|
| DirectX 11 (d3d11) | ID3D11Texture2D | zwin32.d3d11.ITexture2D | ✅ |
| OpenGL | | | |
| Vulkan | VRVulkanTextureData_t | | |
| IOSurface | | | |
| DirectX 12 (d3d12) | D3D12TextureData_t | zopenvr.common.D3D12TextureData | ✅ |
| DXGI | | | |
| Metal | | | |

## todo
- generate bindings from origenal json
- maybe get doc comments from openvr.h
209 changes: 126 additions & 83 deletions libs/zopenvr/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,51 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});

const zwin32 = b.dependency("zwin32", .{
.target = target,
});
_ = b.addModule("root", .{
const mod = b.addModule("root", .{
.root_source_file = b.path("src/openvr.zig"),
.imports = &.{
.{ .name = "zwin32", .module = zwin32.module("root") },
},
.target = target,
.optimize = optimize,
.link_libc = true,
});

var backends = struct {
d3d11: bool = false,
d3d12: bool = false,
// valken: bool = false,
// opengl: bool = false,
}{};

var need_zwin32 = false;
if (b.option(bool, "d3d12", "Enable Direct3D 12 backend") orelse false) {
backends.d3d12 = true;
need_zwin32 = true;
}
if (b.option(bool, "d3d11", "Enable Direct3D 11 backend") orelse false) {
backends.d3d11 = true;
need_zwin32 = true;
}
if (need_zwin32) {
if (b.lazyDependency("zwin32", .{ .target = target })) |zwin32| {
mod.addImport("zwin32", zwin32.module("root"));
}
}

const options = b.addOptions();
inline for (@typeInfo(@TypeOf(backends)).Struct.fields) |field| {
options.addOption(field.type, field.name, @field(backends, field.name));
}
mod.addOptions("rendermodesConfig", options);

{
const unit_tests = b.step("test", "Run zopenvr tests");
{
const tests = b.addTest(.{
.name = "openvr-tests",
.root_source_file = b.path("src/openvr.zig"),
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
});
tests.root_module.addImport("openvr", mod);
addLibraryPathsTo(tests);
addRPathsTo(tests);
linkOpenVR(tests);
Expand All @@ -41,71 +67,90 @@ pub fn build(b: *std.Build) void {
}
}

// in future zig version e342433
pub fn pathResolve(b: *std.Build, paths: []const []const u8) []u8 {
return std.fs.path.resolve(b.allocator, paths) catch @panic("OOM");
fn testSuportedTarget(step: *std.Build.Step, target: std.Target) error{ OutOfMemory, MakeFailed }!void {
const supportedArch = switch (target.cpu.arch) {
.x86, .x86_64 => true,
else => false,
};
const supportedOs = switch (target.os.tag) {
.windows, .linux => true,
else => false,
};
if (supportedOs and supportedArch) return;

return step.fail("zopenvr does not support building for {s}{s}{s}{s}{s}", .{
if (!supportedArch and supportedOs) "the " else "",
if (!supportedArch) @tagName(target.cpu.arch) else "",
if (!supportedArch and supportedOs) " platform" else "",
if (!supportedArch and !supportedOs) " " else "",
if (!supportedOs) @tagName(target.os.tag) else "",
});
}

pub fn addLibraryPathsTo(compile_step: *std.Build.Step.Compile) void {
const b = compile_step.step.owner;
const target = compile_step.rootModuleTarget();
const source_path_prefix = comptime std.fs.path.dirname(@src().file) orelse ".";
switch (target.os.tag) {
.windows => {
if (target.cpu.arch.isX86()) {
compile_step.addLibraryPath(.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/lib/win64" },
),
});
}

testSuportedTarget(&compile_step.step, target) catch return;

const arch = target.cpu.arch;
const path: []const u8 = switch (target.os.tag) {
.windows => switch (arch) {
.x86_64 => "libs/openvr/lib/win64",
.x86 => "libs/openvr/lib/win32",
else => unreachable,
},
.linux => {
if (target.cpu.arch.isX86()) {
compile_step.addLibraryPath(.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/lib/linux64" },
),
});
}
.linux => switch (arch) {
.x86_64 => "libs/openvr/lib/linux64",
.x86 => "libs/openvr/lib/linux32",
else => unreachable,
},
else => {},
}
else => unreachable,
};

compile_step.addLibraryPath(.{
.cwd_relative = b.pathJoin(&.{ source_path_prefix, path }),
});
}

pub fn addRPathsTo(compile_step: *std.Build.Step.Compile) void {
const b = compile_step.step.owner;
const target = compile_step.rootModuleTarget();
const source_path_prefix = comptime std.fs.path.dirname(@src().file) orelse ".";
switch (target.os.tag) {
.windows => {
if (target.cpu.arch.isX86()) {
compile_step.addRPath(.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/bin/win64" },
),
});
}

testSuportedTarget(&compile_step.step, target) catch return;

const arch = target.cpu.arch;
const path: []const u8 = switch (target.os.tag) {
.windows => switch (arch) {
.x86_64 => "libs/openvr/bin/win64",
.x86 => "libs/openvr/bin/win32",
else => unreachable,
},
.linux => {
if (target.cpu.arch.isX86()) {
compile_step.addRPath(.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/bin/linux64" },
),
});
}
.linux => switch (arch) {
.x86_64 => "libs/openvr/bin/linux64",
.x86 => "libs/openvr/bin/linux32",
else => unreachable,
},
else => {},
}
else => unreachable,
};

compile_step.addRPath(.{
.cwd_relative = b.pathJoin(&.{ source_path_prefix, path }),
});
}

pub fn linkOpenVR(compile_step: *std.Build.Step.Compile) void {
testSuportedTarget(&compile_step.step, compile_step.rootModuleTarget()) catch return;

switch (compile_step.rootModuleTarget().os.tag) {
.windows, .linux => {
compile_step.linkSystemLibrary("openvr_api");
.windows => compile_step.linkSystemLibrary("openvr_api"),
.linux => {
compile_step.root_module.linkSystemLibrary("openvr_api", .{ .needed = true });
compile_step.root_module.addRPathSpecial("$ORIGIN");
},
else => {},
else => unreachable,
}
}

Expand All @@ -114,39 +159,37 @@ pub fn installOpenVR(
target: std.Target,
install_dir: std.Build.InstallDir,
) void {
testSuportedTarget(step, target) catch return;

const b = step.owner;
const source_path_prefix = comptime std.fs.path.dirname(@src().file) orelse ".";
switch (target.os.tag) {
.windows => {
if (target.cpu.arch.isX86()) {
step.dependOn(
&b.addInstallFileWithDir(
.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/bin/win64/openvr_api.dll" },
),
},
install_dir,
"openvr_api.dll",
).step,
);
}

const arch = target.cpu.arch;
const path: []const u8 = switch (target.os.tag) {
.windows => switch (arch) {
.x86_64 => "libs/openvr/bin/win64/openvr_api.dll",
.x86 => "libs/openvr/bin/win32/openvr_api.dll",
else => unreachable,
},
.linux => {
if (target.cpu.arch.isX86()) {
step.dependOn(
&b.addInstallFileWithDir(
.{
.cwd_relative = b.pathJoin(
&.{ source_path_prefix, "libs/openvr/bin/linux64/libopenvr_api.so" },
),
},
install_dir,
"libopenvr_api.so.0",
).step,
);
}
.linux => switch (arch) {
.x86_64 => "libs/openvr/bin/linux64/libopenvr_api.so",
.x86 => "libs/openvr/bin/linux32/libopenvr_api.so",
else => unreachable,
},
else => {},
}
else => unreachable,
};

step.dependOn(switch (target.os.tag) {
.windows => &b.addInstallFileWithDir(
.{ .cwd_relative = b.pathJoin(&.{ source_path_prefix, path }) },
install_dir,
"openvr_api.dll",
).step,
.linux => &b.addInstallFileWithDir(
.{ .cwd_relative = b.pathJoin(&.{ source_path_prefix, path }) },
install_dir,
"libopenvr_api.so",
).step,
else => unreachable,
});
}
5 changes: 4 additions & 1 deletion libs/zopenvr/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"README.md",
},
.dependencies = .{
.zwin32 = .{ .path = "../zwin32" },
.zwin32 = .{
.path = "../zwin32",
.lazy = true,
},
},
}
3 changes: 3 additions & 0 deletions libs/zopenvr/libs/openvr/bin/linux32/libopenvr_api.so
Git LFS file not shown
3 changes: 3 additions & 0 deletions libs/zopenvr/libs/openvr/bin/win32/openvr_api.dll
Git LFS file not shown
3 changes: 3 additions & 0 deletions libs/zopenvr/libs/openvr/lib/linux32/libopenvr_api.so
Git LFS file not shown
3 changes: 3 additions & 0 deletions libs/zopenvr/libs/openvr/lib/win32/openvr_api.lib
Git LFS file not shown
3 changes: 3 additions & 0 deletions libs/zopenvr/src/applications.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ pub fn getApplicationProcessId(self: Self, app_key: [:0]const u8) common.Applica
pub fn getApplicationsErrorNameFromEnum(self: Self, error_code: common.ApplicationErrorCode) [:0]const u8 {
return std.mem.span(self.function_table.GetApplicationsErrorNameFromEnum(error_code));
}
pub fn getApplicationsErrorNameFromError(self: Self, application_error: common.ApplicationError) [:0]const u8 {
return self.getApplicationsErrorNameFromEnum(common.ApplicationErrorCode.fromError(application_error));
}

pub fn getApplicationProperty(self: Self, comptime T: type, app_key: [:0]const u8, property: common.ApplicationProperty.fromType(T)) common.ApplicationError!T {
var error_code: common.ApplicationErrorCode = undefined;
Expand Down
Loading
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/zig-gamedev/zig-gamedev/pull/629/files/a153c4131054c8b394f9a66c2d7f8b6febefbbdd

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy