Skip to main content

Generating OpenXR / OpenVR Bindings for Odin

Table of Contents

One of my favourite parts about writing VR application code in languages other than C/C++ is the utter joy of parsing an XML or JSON API specification. The task is especially joyous when, at some point, the author has given up and just started writing C declaration syntax sprinkled with a few XML tags here and there.

If you are a normal person, and would prefer not to have to figure out all the special cases required to just get some VR code running, you might consider having a look at my parsers for xr.xml and openvr_api.json. If you’re writing Odin you can just use the generated results, however even if you’re targeting another language, the generators might be a useful reference.

OpenXR Bindings Generator
#

My favourite part about this one is the special case to handle aliased command names, but there is only one: xrGetVulkanGraphicsRequirements2KHR.

cshenton/openxr_odin

OpenXR bindings generator for Odin

Odin
1
0

OpenVR Bindings Generator
#

I think the fact that this is about half the length of the OpenXR one tells you how much more of a joy it was to write. Unlike OpenXR, OpenVR evolved rather than being designed as a strict spec, so my favourite part of this parser is the array of 30 non-standard enum prefixes that I hand wrote to get something more consistent feeling in Odin. Odin has scoped enums so instead of writing OverlayIntersectionPrimitiveType_Rectangle I can simply write .Rectangle, lovely.

cshenton/openvr_odin

Odin bindings generator for OpenVR

Odin
4
0

The OpenVR repo also contains a very minimal application which queries and renders the connected devices using OpenGL. Sadly there is no standardised way to query device render models in OpenXR but that, and much more, is a story for another time.

Happy Virtual Realitying!