Skip to content
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

Several fixes #16

Merged
merged 14 commits into from
Dec 18, 2022
Merged
Changes from all commits
Commits
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
65 changes: 55 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
cmake_minimum_required(VERSION 3.14)

project(VSGVR)
project(vsgvr
VERSION 0.4.0
DESCRIPTION "VulkanSceneGraph based virtual reality viewer"
LANGUAGES CXX
)

include(FetchContent)
set(VSGVR_SOVERSION 0)

if( NOT CMAKE_BUILD_TYPE AND NOT MSVC )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "MinSizeRel" "RelWithDebInfo" )
endif()
include(FetchContent)

# Compiler/Tool requirements
set( CMAKE_CXX_STANDARD 17 )
@@ -17,17 +18,61 @@ set(OpenGL_GL_PREFERENCE GLVND)
find_package(vsg 1.0.0 NO_CMAKE_FIND_ROOT_PATH)
find_package(Vulkan REQUIRED)

add_subdirectory( deps/openxr )
vsg_setup_dir_vars()
vsg_setup_build_vars()

vsg_add_target_clang_format(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
)
vsg_add_target_cppcheck(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include/vsgvr/*.h
${PROJECT_SOURCE_DIR}/vsgvr/srv/vsgvr/*.cpp
)
vsg_add_target_clobber()
vsg_add_target_docs(
FILES
${PROJECT_SOURCE_DIR}/vsgvr/include
)
vsg_add_target_uninstall()

find_package(OpenXR QUIET)
if(OpenXR_FOUND)
set(OpenXR_LIBRARY OpenXR::openxr_loader)
elseif(IS_DIRECTORY deps/openxr)
message(STATUS "Using embedded OpenXR development kit")
add_subdirectory(deps/openxr)
set(OpenXR_LIBRARY openxr_loader)
else()
message(FATAL_ERROR "Could not find OpenXR development kit")
endif()

add_subdirectory( vsgvr )

# setup relative data install path
file(RELATIVE_PATH VSGVR_REL_DATADIR ${CMAKE_INSTALL_FULL_BINDIR} ${CMAKE_INSTALL_FULL_DATADIR}/vsgvr)
add_definitions(-DVSGVR_REL_DATADIR=\"${VSGVR_REL_DATADIR}\")

add_executable( example_vr example_vr.cpp )
target_link_libraries( example_vr vsg::vsg vsgvr )
target_include_directories( example_vr PRIVATE
${OPENVR_ROOT}/headers
vsgvr/include )
set_target_properties(example_vr PROPERTIES OUTPUT_NAME vsgopenxrviewer)
install(TARGETS example_vr)

# Copy models into the build dir
configure_file(models/world/world.vsgt ${CMAKE_CURRENT_BINARY_DIR}/world.vsgt COPYONLY)
configure_file(models/controller/controller.vsgt ${CMAKE_CURRENT_BINARY_DIR}/controller.vsgt COPYONLY)
configure_file(models/controller/controller2.vsgt ${CMAKE_CURRENT_BINARY_DIR}/controller2.vsgt COPYONLY)
configure_file(models/world/world.vsgt ${CMAKE_CURRENT_BINARY_DIR}/share/vsgvr/world.vsgt COPYONLY)
configure_file(models/controller/controller.vsgt ${CMAKE_CURRENT_BINARY_DIR}/share/vsgvr/controller.vsgt COPYONLY)
configure_file(models/controller/controller2.vsgt ${CMAKE_CURRENT_BINARY_DIR}/share/vsgvr/controller2.vsgt COPYONLY)

install(FILES
models/world/world.vsgt
models/controller/controller.vsgt
models/controller/controller2.vsgt
DESTINATION ${CMAKE_INSTALL_DATADIR}/vsgvr
)

vsg_add_feature_summary()
18 changes: 13 additions & 5 deletions example_vr.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
#include <iostream>
#include <algorithm>

#include <iostream>

int main(int argc, char **argv) {
try
{
@@ -21,6 +23,10 @@ int main(int argc, char **argv) {
auto options = vsg::Options::create();
arguments.read(options);

// add relative data path based on binary dir
vsg::Path dataPath = vsg::filePath(vsg::executableFilePath());
dataPath.append(VSGVR_REL_DATADIR);
options->paths.push_back(dataPath);
vsg::Path filename = "world.vsgt";
if (argc > 1)
filename = arguments[1];
@@ -30,15 +36,17 @@ int main(int argc, char **argv) {
// load the scene graph
vsg::ref_ptr<vsg::Group> vsg_scene =
vsg::read_cast<vsg::Group>(filename, options);
if (!vsg_scene)
return 0;
if (!vsg_scene) {
std::cerr << "Could not read the scene graph" << std::endl;
return EXIT_FAILURE;
}

auto controllerNodeLeft = vsg::MatrixTransform::create();
controllerNodeLeft->addChild(vsg::read_cast<vsg::Node>("controller.vsgt"));
controllerNodeLeft->addChild(vsg::read_cast<vsg::Node>("controller.vsgt", options));
vsg_scene->addChild(controllerNodeLeft);

auto controllerNodeRight = vsg::MatrixTransform::create();
controllerNodeRight->addChild(vsg::read_cast<vsg::Node>("controller2.vsgt"));
controllerNodeRight->addChild(vsg::read_cast<vsg::Node>("controller2.vsgt", options));
vsg_scene->addChild(controllerNodeRight);

// Initialise OpenXR
@@ -280,7 +288,7 @@ int main(int argc, char **argv) {
}
catch( const vsg::Exception& e )
{
std::cout << "VSG Exception: " << e.message << std::endl;
std::cerr << "VSG Exception: " << e.message << std::endl;
return EXIT_FAILURE;
}
}
54 changes: 31 additions & 23 deletions vsgvr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@

file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/vsgvr/*.h )
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/vsgvr/*/*.h )

set( SOURCES
include/vsgvr/xr/OpenXRCommon.h
include/vsgvr/xr/OpenXRInstance.h
src/vsgvr/xr/OpenXRInstance.cpp
include/vsgvr/xr/OpenXREventHandler.h
src/vsgvr/xr/OpenXREventHandler.cpp
include/vsgvr/xr/OpenXRTraits.h
src/vsgvr/xr/OpenXRTraits.cpp
include/vsgvr/app/OpenXRViewer.h
src/vsgvr/actions/OpenXRAction.cpp
src/vsgvr/actions/OpenXRActionPoseBinding.cpp
src/vsgvr/actions/OpenXRActionSet.cpp
src/vsgvr/app/OpenXRViewer.cpp
include/vsgvr/xr/OpenXRGraphicsBindingVulkan.h
src/vsgvr/xr/OpenXREventHandler.cpp
src/vsgvr/xr/OpenXRGraphicsBindingVulkan.cpp
include/vsgvr/xr/OpenXRSession.h
src/vsgvr/xr/OpenXRInstance.cpp
src/vsgvr/xr/OpenXRSession.cpp
include/vsgvr/xr/OpenXRSwapchain.h
src/vsgvr/xr/OpenXRSwapchain.cpp
include/vsgvr/xr/OpenXRViewMatrix.h
include/vsgvr/xr/OpenXRProjectionMatrix.h

include/vsgvr/actions/OpenXRAction.h
src/vsgvr/actions/OpenXRAction.cpp
include/vsgvr/actions/OpenXRActionSet.h
src/vsgvr/actions/OpenXRActionSet.cpp
include/vsgvr/actions/OpenXRActionPoseBinding.h
src/vsgvr/actions/OpenXRActionPoseBinding.cpp
src/vsgvr/xr/OpenXRTraits.cpp
)

add_library( vsgvr STATIC ${SOURCES} ${HEADERS} )
add_library( vsgvr ${SOURCES} ${HEADERS} )

target_include_directories(
vsgvr PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries( vsgvr PUBLIC vsg::vsg )
target_link_libraries( vsgvr PUBLIC openxr_loader )
target_link_libraries( vsgvr PUBLIC ${OpenXR_LIBRARY})
if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_options(vsgvr PRIVATE "-DVSGVR_DECLSPEC=__declspec(dllexport)")
target_compile_options(vsgvr INTERFACE "-DVSGVR_DECLSPEC=__declspec(dllimport)")
else()
target_compile_options(vsgvr PUBLIC -DVSGVR_DECLSPEC=)
endif()
set_target_properties(vsgvr PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
SOVERSION ${VSGVR_SOVERSION}
)
if(WIN32)
set_target_properties(vsgvr PROPERTIES
RUNTIME_OUTPUT_NAME vsgvr-${VSGVR_SOVERSION}
)
endif()

install(TARGETS vsgvr ${INSTALL_TARGETS_DEFAULT_FLAGS})
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vsgvr)

vsg_add_cmake_support_files(
CONFIG_TEMPLATE vsgvrConfig.cmake.in
)
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/actions/OpenXRAction.h
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
namespace vsgvr {
class OpenXRInstance;
class OpenXRActionSet;
class VSG_DECLSPEC OpenXRAction : public vsg::Inherit<vsg::Object, OpenXRAction>
class VSGVR_DECLSPEC OpenXRAction : public vsg::Inherit<vsg::Object, OpenXRAction>
{
public:
OpenXRAction(OpenXRActionSet* actionSet, XrActionType actionType, std::string name, std::string localisedName );
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/actions/OpenXRActionPoseBinding.h
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ namespace vsgvr {
* An action of type XR_INPUT_ACTION_TYPE_POSE, and an associated action space
* The space will only be valid while a session is running
*/
class VSG_DECLSPEC OpenXRActionPoseBinding : public vsg::Inherit<OpenXRAction, OpenXRActionPoseBinding>
class VSGVR_DECLSPEC OpenXRActionPoseBinding : public vsg::Inherit<OpenXRAction, OpenXRActionPoseBinding>
{
public:
OpenXRActionPoseBinding(OpenXRActionSet* actionSet, std::string name, std::string localisedName);
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/actions/OpenXRActionSet.h
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace vsgvr {
class OpenXRInstance;
class VSG_DECLSPEC OpenXRActionSet : public vsg::Inherit<vsg::Object, OpenXRActionSet>
class VSGVR_DECLSPEC OpenXRActionSet : public vsg::Inherit<vsg::Object, OpenXRActionSet>
{
public:
OpenXRActionSet(OpenXRInstance* instance, std::string name, std::string localisedName, uint32_t priority = 0);
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/app/OpenXRViewer.h
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ namespace vsgvr {
* * Any elements in vsg which require a vsg::Window cannot work with this viewer (TODO)
* * While some functions are similar, this class does not directly inherit from vsg::Viewer (TODO)
*/
class VSG_DECLSPEC OpenXRViewer : public vsg::Inherit<vsg::Object, OpenXRViewer>
class VSGVR_DECLSPEC OpenXRViewer : public vsg::Inherit<vsg::Object, OpenXRViewer>
{
public:
/**
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXREventHandler.h
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
namespace vsgvr {
class OpenXRInstance;
class OpenXRSession;
class VSG_DECLSPEC OpenXREventHandler : public vsg::Inherit<vsg::Object, OpenXREventHandler>
class VSGVR_DECLSPEC OpenXREventHandler : public vsg::Inherit<vsg::Object, OpenXREventHandler>
{
public:
OpenXREventHandler();
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRGraphicsBindingVulkan.h
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ namespace vsgvr {
VkPhysicalDevice* physicalDevice;
};

class VSG_DECLSPEC OpenXRGraphicsBindingVulkan : public vsg::Inherit<vsg::Object, OpenXRGraphicsBindingVulkan>
class VSGVR_DECLSPEC OpenXRGraphicsBindingVulkan : public vsg::Inherit<vsg::Object, OpenXRGraphicsBindingVulkan>
{
public:
static VulkanRequirements getVulkanRequirements(vsg::ref_ptr<OpenXRInstance> xrInstance);
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRInstance.h
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <vsgvr/actions/OpenXRActionSet.h>

namespace vsgvr {
class VSG_DECLSPEC OpenXRInstance : public vsg::Inherit<vsg::Object, OpenXRInstance>
class VSGVR_DECLSPEC OpenXRInstance : public vsg::Inherit<vsg::Object, OpenXRInstance>
{
public:
OpenXRInstance() = delete;
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRProjectionMatrix.h
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace vsgvr
{
class VSG_DECLSPEC OpenXRProjectionMatrix : public vsg::Inherit<vsg::ProjectionMatrix, OpenXRProjectionMatrix>
class VSGVR_DECLSPEC OpenXRProjectionMatrix : public vsg::Inherit<vsg::ProjectionMatrix, OpenXRProjectionMatrix>
{
public:
OpenXRProjectionMatrix(vsg::dmat4 matrix)
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRSession.h
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <vsg/vk/Framebuffer.h>

namespace vsgvr {
class VSG_DECLSPEC OpenXRSession : public vsg::Inherit<vsg::Object, OpenXRSession>
class VSGVR_DECLSPEC OpenXRSession : public vsg::Inherit<vsg::Object, OpenXRSession>
{
public:
OpenXRSession() = delete;
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRSwapchain.h
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ namespace vsgvr
virtual ~SwapchainImage();
};

class VSG_DECLSPEC OpenXRSwapchain : public vsg::Inherit<vsg::Object, OpenXRSwapchain>
class VSGVR_DECLSPEC OpenXRSwapchain : public vsg::Inherit<vsg::Object, OpenXRSwapchain>
{
public:
OpenXRSwapchain() = delete;
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRTraits.h
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <vector>

namespace vsgvr {
class OpenXrTraits {
class VSGVR_DECLSPEC OpenXrTraits {
public:
OpenXrTraits();
std::vector<std::string> xrExtensions = {
2 changes: 1 addition & 1 deletion vsgvr/include/vsgvr/xr/OpenXRViewMatrix.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <vsgvr/xr/OpenXRCommon.h>

namespace vsgvr {
class VSG_DECLSPEC OpenXRViewMatrix : public vsg::Inherit<vsg::ViewMatrix, OpenXRViewMatrix>
class VSGVR_DECLSPEC OpenXRViewMatrix : public vsg::Inherit<vsg::ViewMatrix, OpenXRViewMatrix>
{
public:
OpenXRViewMatrix(const vsg::dmat4& m) :
6 changes: 4 additions & 2 deletions vsgvr/src/vsgvr/actions/OpenXRActionPoseBinding.cpp
Original file line number Diff line number Diff line change
@@ -61,8 +61,10 @@ namespace vsgvr

void OpenXRActionPoseBinding::destroyActionSpace()
{
xr_check(xrDestroySpace(_space));
_space = 0;
if (_space) {
xr_check(xrDestroySpace(_space));
_space = 0;
}
}

void OpenXRActionPoseBinding::setSpaceLocation(XrSpaceLocation location)
5 changes: 5 additions & 0 deletions vsgvr/vsgvrConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(CMakeFindDependencyMacro)

@FIND_DEPENDENCY_OUT@

include("${CMAKE_CURRENT_LIST_DIR}/vsgvrTargets.cmake")