Skip to content

Commit

Permalink
Add standard extensions code with cmake options to disable each one
Browse files Browse the repository at this point in the history
  • Loading branch information
1runeberg committed Oct 21, 2024
1 parent 53857ca commit f3829ce
Show file tree
Hide file tree
Showing 24 changed files with 1,879 additions and 236 deletions.
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(XRLIB_INCLUDE "${XRLIB_ROOT}/include")
set(XRLIB_BIN_OUT "${XRLIB_ROOT}/bin")
set(XRLIB_LIB_OUT "${XRLIB_ROOT}/lib")
set(THIRD_PARTY "${XRLIB_ROOT}/third_party")
set(XRLIB_EXT_INCLUDE "${XRLIB_INCLUDE}/${XRLIB}/ext")
set(XRLIB_EXT_SRC "${XRLIB_SRC}/${XRLIB}/ext")

set(XRVK_INCLUDE "${XRLIB_INCLUDE}/xrvk")
set(XRVK_SRC "${XRLIB_SRC}/xrvk")
Expand Down Expand Up @@ -74,6 +76,47 @@ file(GLOB_RECURSE XRVK_SOURCE
"${XRVK_SRC}/*.c*"
)

# Exclude extensions (option)
option(EXCLUDE_KHR_VISIBILITY_MASK "EXCLUDE_KHR_VISIBILITY_MASK" OFF)
set(FILES_KHR_VISIBILITY_MASK "KHR/visibility_mask")

option(EXCLUDE_EXT_HAND_TRACKING "EXCLUDE_EXT_HAND_TRACKING" OFF)
set (FILES_EXT_HAND_TRACKING "EXT/hand_tracking" )

option(EXCLUDE_FB_DISPLAY_REFRESH "EXCLUDE_FB_DISPLAY_REFRESH" OFF)
set (FILES_FB_DISPLAY_REFRESH "FB/display_refresh_rate" )

option(EXCLUDE_FB_PASSTHROUGH "EXCLUDE_FB_PASSTHROUGH" OFF)
set (FILES_FB_PASSTHROUGH "FB/passthrough" "FB/triangle_mesh")

if (${EXCLUDE_KHR_VISIBILITY_MASK} STREQUAL "ON")
foreach( f IN ITEMS ${FILES_KHR_VISIBILITY_MASK} )
list(REMOVE_ITEM XRLIB_HEADERS "${XRLIB_EXT_INCLUDE}/${f}.hpp" )
list(REMOVE_ITEM XRLIB_SOURCE "${XRLIB_EXT_SRC}/${f}.cpp" )
endforeach()
endif()

if (${EXCLUDE_EXT_HAND_TRACKING})
foreach(f IN ITEMS ${FILE_EXT_HAND_TRACKING})
list(REMOVE_ITEM XRLIB_HEADERS "${XRLIB_EXT_INCLUDE}/${f}.hpp")
list(REMOVE_ITEM XRLIB_SOURCE "${XRLIB_EXT_SRC}/${f}.cpp")
endforeach()
endif()

if (${EXCLUDE_FB_DISPLAY_REFRESH})
foreach(f IN ITEMS ${FILES_FB_DISPLAY_REFRESH} )
list(REMOVE_ITEM XRLIB_HEADERS "${XRLIB_EXT_INCLUDE}/${f}.hpp")
list(REMOVE_ITEM XRLIB_SOURCE "${XRLIB_EXT_SRC}/${f}.cpp")
endforeach()
endif()

if (${EXCLUDE_FB_PASSTHROUGH})
foreach(f IN ITEMS ${FILES_FB_PASSTHROUGH} )
list(REMOVE_ITEM XRLIB_HEADERS "${XRLIB_EXT_INCLUDE}/${f}.hpp")
list(REMOVE_ITEM XRLIB_SOURCE "${XRLIB_EXT_SRC}/${f}.cpp")
endforeach()
endif()

# Set openxr
set(OPENXR_ROOT "${THIRD_PARTY}/openxr")
set(OPENXR_INCLUDE "${OPENXR_ROOT}/include")
Expand Down
63 changes: 63 additions & 0 deletions include/xrlib/data_types_bitmasks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2023-24 Beyond Reality Labs Ltd (https://beyondreality.io)
* Copyright 2021-24 Rune Berg (GitHub: https://github.com/1runeberg, YT: https://www.youtube.com/@1RuneBerg, X: https://twitter.com/1runeberg, BSky: https://runeberg.social)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#include <stdint.h>

namespace xrlib
{
struct Flag8
{
uint8_t flag = 0;

// True
void Set( int nflag ) { flag |= nflag; }

// False
void Reset( int nflag ) { flag &= ~nflag; }

// Flip flop flag value
void Flip( int nflag ) { flag ^= nflag; }

// Check flag
bool IsSet( int nflag ) { return ( flag & nflag ) == nflag; }

// Checks for any flag set
bool IsAnySet( int nflags ) { return ( flag & nflags ) != 0; }

};

struct Flag16
{
uint16_t flag = 0;

// True
void Set( int nflag ) { flag |= nflag; }

// False
void Reset( int nflag ) { flag &= ~nflag; }

// Flip flop flag value
void Flip( int nflag ) { flag ^= nflag; }

// Check flag
bool IsSet( int nflag ) { return ( flag & nflag ) == nflag; }

// Checks for any flag set
bool IsAnySet( int nflags ) { return ( flag & nflags ) != 0; }
};
} // namespace xrlib
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
/*
* Copyright 2024 Rune Berg (http://runeberg.io | https://github.com/1runeberg)
* Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <vector>
#include <array>
#include <xrlib/ext/ext_base.hpp>

namespace xrlib::EXT
{
class CHandTracking : public ExtBase
{
public:
CHandTracking( XrInstance xrInstance );
~CHandTracking();

XrResult Init( XrSession xrSession,
XrHandJointSetEXT leftHandJointSet = XR_HAND_JOINT_SET_DEFAULT_EXT,
void *pNextLeft = nullptr,
XrHandJointSetEXT rightHandJointSet = XR_HAND_JOINT_SET_DEFAULT_EXT,
void *pNextRight = nullptr );

struct SJointVelocities
{
XrHandJointVelocitiesEXT left { XR_TYPE_HAND_JOINT_VELOCITIES_EXT };
XrHandJointVelocitiesEXT right { XR_TYPE_HAND_JOINT_VELOCITIES_EXT };

std::array< XrHandJointVelocityEXT, XR_HAND_JOINT_COUNT_EXT > leftVelocities;
std::array< XrHandJointVelocityEXT, XR_HAND_JOINT_COUNT_EXT > rightVelocities;

SJointVelocities( void *pNextLeft = nullptr, void *pNextRight = nullptr );
~SJointVelocities() {};
};

struct SJointLocations
{
XrHandJointLocationsEXT left { XR_TYPE_HAND_JOINT_LOCATIONS_EXT };
XrHandJointLocationsEXT right { XR_TYPE_HAND_JOINT_LOCATIONS_EXT };

std::array< XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT > leftJointLocations;
std::array< XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT > rightJointLocations;

SJointLocations( SJointVelocities &jointVelocities );
SJointLocations( void *pNextLeft = nullptr, void *pNextRight = nullptr );
~SJointLocations() {};
};

XrResult LocateHandJoints( SJointLocations *outHandJointLocations, XrSpace baseSpace, XrTime time, void *pNextLeft = nullptr, void *pNextRight = nullptr );
XrResult LocateHandJoints( XrHandJointLocationsEXT *outHandJointLocations, XrHandEXT hand, XrSpace baseSpace, XrTime time, void *pNext = nullptr );

XrSystemHandTrackingPropertiesEXT GenerateSystemProperties( void *pNext = nullptr );

XrHandTrackerEXT *GetHandTracker( XrHandEXT hand );
std::vector< XrHandTrackerEXT > &GetHandTrackers() { return m_vecHandTrackers; }

private:
XrSession m_xrSession = XR_NULL_HANDLE;
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT = nullptr;
std::vector< XrHandTrackerEXT > m_vecHandTrackers = { XR_NULL_HANDLE, XR_NULL_HANDLE };

};

} // namespace xrlib
/*
* Copyright 2024 Rune Berg (http://runeberg.io | https://github.com/1runeberg)
* Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <vector>
#include <array>
#include <xrlib/ext/ext_base.hpp>

namespace xrlib::EXT
{
class CHandTracking : public ExtBase
{
public:
CHandTracking( XrInstance xrInstance );
~CHandTracking();

XrResult Init( XrSession xrSession,
XrHandJointSetEXT leftHandJointSet = XR_HAND_JOINT_SET_DEFAULT_EXT,
void *pNextLeft = nullptr,
XrHandJointSetEXT rightHandJointSet = XR_HAND_JOINT_SET_DEFAULT_EXT,
void *pNextRight = nullptr );

struct SJointVelocities
{
XrHandJointVelocitiesEXT left { XR_TYPE_HAND_JOINT_VELOCITIES_EXT };
XrHandJointVelocitiesEXT right { XR_TYPE_HAND_JOINT_VELOCITIES_EXT };

std::array< XrHandJointVelocityEXT, XR_HAND_JOINT_COUNT_EXT > leftVelocities;
std::array< XrHandJointVelocityEXT, XR_HAND_JOINT_COUNT_EXT > rightVelocities;

SJointVelocities( void *pNextLeft = nullptr, void *pNextRight = nullptr );
~SJointVelocities() {};
};

struct SJointLocations
{
XrHandJointLocationsEXT left { XR_TYPE_HAND_JOINT_LOCATIONS_EXT };
XrHandJointLocationsEXT right { XR_TYPE_HAND_JOINT_LOCATIONS_EXT };

std::array< XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT > leftJointLocations;
std::array< XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT > rightJointLocations;

SJointLocations( SJointVelocities &jointVelocities );
SJointLocations( void *pNextLeft = nullptr, void *pNextRight = nullptr );
~SJointLocations() {};
};

XrResult LocateHandJoints( SJointLocations *outHandJointLocations, XrSpace baseSpace, XrTime time, void *pNextLeft = nullptr, void *pNextRight = nullptr );
XrResult LocateHandJoints( XrHandJointLocationsEXT *outHandJointLocations, XrHandEXT hand, XrSpace baseSpace, XrTime time, void *pNext = nullptr );

XrSystemHandTrackingPropertiesEXT GenerateSystemProperties( void *pNext = nullptr );

XrHandTrackerEXT *GetHandTracker( XrHandEXT hand );
std::vector< XrHandTrackerEXT > &GetHandTrackers() { return m_vecHandTrackers; }

private:
XrSession m_xrSession = XR_NULL_HANDLE;
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT = nullptr;
std::vector< XrHandTrackerEXT > m_vecHandTrackers = { XR_NULL_HANDLE, XR_NULL_HANDLE };

};

} // namespace xrlib
63 changes: 63 additions & 0 deletions include/xrlib/ext/FB/display_refresh_rate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2023-24 Beyond Reality Labs Ltd (https://beyondreality.io)
* Copyright 2021-24 Rune Berg (GitHub: https://github.com/1runeberg, YT: https://www.youtube.com/@1RuneBerg, X: https://twitter.com/1runeberg, BSky: https://runeberg.social)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <xrlib/ext/ext_base.hpp>

#include <vector>

namespace xrlib::FB
{
class DisplayRefreshRate : public ExtBase
{
public:

DisplayRefreshRate( XrInstance xrInstance );

/// <summary>
/// Retrieve all supported display refresh rates from the openxr runtime that is valid for the running session and hardware
/// </summary>
/// <param name="outSupportedRefreshRates">vector fo floats to put the supported refresh rates in</param>
/// <returns>Result from the openxr runtime of retrieving all supported refresh rates</returns>
XrResult GetSupportedRefreshRates( XrSession xrSession, std::vector< float > &outSupportedRefreshRates );

/// <summary>
/// Retrieves the currently active display refresh rate
/// </summary>
/// <returns>The active display refresh rate, 0.0f if an error is encountered (check logs) - you can also check for event XR_TYPE_EVENT_DATA_DISPLAY_REFRESH_RATE_CHANGED_FB</returns>
float GetCurrentRefreshRate( XrSession xrSession );

/// <summary>
/// Request a refresh rate from the openxr runtime. Provided refresh rate must be a supported refresh rate via GetSupportedRefreshRates()
/// </summary>
/// <param name="fRequestedRefreshRate">The requested refresh rate. This must be a valid refresh rate from GetSupportedRefreshRates(). Use 0.0f to indicate no prefrence and let the runtime
/// choose the most appropriate one for the session.</param>
/// <returns>Result from the openxr runtime of requesting a refresh rate</returns>
XrResult RequestRefreshRate( XrSession xrSession, float fRequestedRefreshRate );

// Below are all the new functions (pointers to them from the runtime) for this spec
// https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_FB_display_refresh_rate
PFN_xrEnumerateDisplayRefreshRatesFB xrEnumerateDisplayRefreshRatesFB = nullptr;
PFN_xrGetDisplayRefreshRateFB xrGetDisplayRefreshRateFB = nullptr;
PFN_xrRequestDisplayRefreshRateFB xrRequestDisplayRefreshRateFB = nullptr;

private:

};

}
Loading

0 comments on commit f3829ce

Please sign in to comment.