Feature/openvr (#180)

* Updated SGCT to latest commit, to include OpenVR convenience functions.

* Made OpenSpace application support OpenVR. Check CMake option "OPENSPACE_OPENVR_SUPPORT" to enable this functionality.

* Merged latest SGCT to remove ogl_header dependency in SGCTOpenVR header

* Merged latest SGCT with minor Mac gl/glew include fix for including SGCTOpenVR as it relies on inclusion of gl headers.

* CMake fix in OpenSpace app for resetting variables after unchecking OPENVR_SUPPORT.

* Created separate SGCT config files for Oculus Rift and HTC Vive HMD

* Update Ghoul to enable experimental GLM features

* Update SGCT repository

* Updated to latest SGCT version for latest fixes.
This commit is contained in:
eriksunden
2017-02-25 02:41:40 +01:00
committed by Alexander Bock
parent 5db26ad44b
commit 87f5654bf8
7 changed files with 140 additions and 6 deletions

View File

@@ -29,15 +29,51 @@ if (WIN32)
set(RESOURCE_FILE ${OPENSPACE_APPS_DIR}/OpenSpace/openspace.rc)
endif ()
##OpenVR section start####################
option(OPENSPACE_OPENVR_SUPPORT "Build OpenSpace application with OpenVR support" OFF)
if(OPENSPACE_OPENVR_SUPPORT)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OPENSPACE_EXT_DIR}/sgct/cmake/modules/")
find_package(OpenVR REQUIRED)
set(SGCT_OPENVR_DEFINITIONS OPENVR_SUPPORT)
if(NOT SGCT_OPENVR_INCLUDE_DIRECTORY)
if( WIN32 )
find_path(SGCT_OPENVR_INCLUDE_DIRECTORY
NAMES SGCTOpenVR.h
PATHS $ENV{SGCT_ROOT_DIR}/additional_includes/openvr ${OPENSPACE_EXT_DIR}/sgct/additional_includes/openvr NO_DEFAULT_PATH
REQUIRED)
else()
find_path(SGCT_OPENVR_INCLUDE_DIRECTORY
NAMES SGCTOpenVR.h
PATH_SUFFIXES SGCTOpenVR
PATHS $ENV{SGCT_ROOT_DIR}/additional_includes/openvr ${OPENSPACE_EXT_DIR}/sgct/additional_includes/openvr
REQUIRED)
endif()
else()
set(SGCT_OPENVR_FILES ${SGCT_OPENVR_INCLUDE_DIRECTORY}/SGCTOpenVR.h ${SGCT_OPENVR_INCLUDE_DIRECTORY}/SGCTOpenVR.cpp)
endif()
else()
set(OPENVR_INCLUDE_DIRS "")
set(SGCT_OPENVR_INCLUDE_DIRECTORY "")
set(OPENVR_LIBRARY "")
set(SGCT_OPENVR_DEFINITIONS "")
endif()
##OpenVR section end####################
add_executable(${APPLICATION_NAME}
${SGCT_OPENVR_FILES}
${OPENSPACE_APPS_DIR}/OpenSpace/main.cpp
${RESOURCE_FILE}
)
target_include_directories(${APPLICATION_NAME} PUBLIC ${OPENSPACE_BASE_DIR}/include)
target_link_libraries(${APPLICATION_NAME} libOpenSpace)
target_include_directories(${APPLICATION_NAME} PUBLIC ${OPENSPACE_BASE_DIR}/include ${OPENVR_INCLUDE_DIRS} ${SGCT_OPENVR_INCLUDE_DIRECTORY})
target_link_libraries(${APPLICATION_NAME} libOpenSpace ${OPENVR_LIBRARY})
target_compile_definitions(${APPLICATION_NAME} PUBLIC ${SGCT_OPENVR_DEFINITIONS})
if (MSVC)
set_target_properties(${APPLICATION_NAME} PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib"
)
endif ()
endif()

View File

@@ -33,6 +33,11 @@
#include <chrono>
#include <thread>
#ifdef OPENVR_SUPPORT
#include <SGCTOpenVR.h>
sgct::SGCTWindow* FirstOpenVRWindow = nullptr;
#endif
sgct::Engine* _sgctEngine;
int main_main(int argc, char** argv);
@@ -212,6 +217,11 @@ int main_main(int argc, char** argv) {
LDEBUG("Destroying SGCT Engine");
delete _sgctEngine;
#ifdef OPENVR_SUPPORT
// Clean up OpenVR
sgct::SGCTOpenVR::shutdown();
#endif
// Exit program
exit(EXIT_SUCCESS);
}
@@ -234,6 +244,21 @@ void mainInitFunc() {
LogMgr.flushLogs();
exit(EXIT_FAILURE);
}
#ifdef OPENVR_SUPPORT
//Find if we have at least one OpenVR window
//Save reference to first OpenVR window, which is the one we will copy to the HMD.
for (size_t i = 0; i < _sgctEngine->getNumberOfWindows(); i++) {
if (_sgctEngine->getWindowPtr(i)->checkIfTagExists("OpenVR")) {
FirstOpenVRWindow = _sgctEngine->getWindowPtr(i);
break;
}
}
//If we have an OpenVRWindow, initialize OpenVR.
if (FirstOpenVRWindow) {
sgct::SGCTOpenVR::initialize(_sgctEngine->getNearClippingPlane(), _sgctEngine->getFarClippingPlane());
}
#endif
// Set the clear color for all non-linear projection viewports
size_t nWindows = _sgctEngine->getNumberOfWindows();
@@ -267,6 +292,14 @@ void mainPostSyncPreDrawFunc() {
// }
LTRACE("main::postSynchronizationPreDraw(begin)");
OsEng.postSynchronizationPreDraw();
#ifdef OPENVR_SUPPORT
if (FirstOpenVRWindow) {
//Update pose matrices for all tracked OpenVR devices once per frame
sgct::SGCTOpenVR::updatePoses();
}
#endif
LTRACE("main::postSynchronizationPreDraw(end)");
}
@@ -285,12 +318,28 @@ void mainRenderFunc() {
viewMatrix = viewMatrix * sceneMatrix;
mat4 projectionMatrix = _sgctEngine->getCurrentProjectionMatrix();
#ifdef OPENVR_SUPPORT
if (sgct::SGCTOpenVR::isHMDActive() &&
(FirstOpenVRWindow == _sgctEngine->getCurrentWindowPtr() || _sgctEngine->getCurrentWindowPtr()->checkIfTagExists("OpenVR"))) {
projectionMatrix = sgct::SGCTOpenVR::getHMDCurrentViewProjectionMatrix(_sgctEngine->getCurrentFrustumMode());
}
#endif
OsEng.render(projectionMatrix, viewMatrix);
LTRACE("main::mainRenderFunc(end)");
}
void mainPostDrawFunc() {
LTRACE("main::mainPostDrawFunc(begin)");
#ifdef OPENVR_SUPPORT
if (FirstOpenVRWindow) {
//Copy the first OpenVR window to the HMD
sgct::SGCTOpenVR::copyWindowToHMD(FirstOpenVRWindow);
}
#endif
OsEng.postDraw();
LTRACE("main::mainPostDrawFunc(end)");

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<Cluster masterAddress="localhost">
<Node address="localhost" port="20401">
<Window tags="OpenVR" fullScreen="false" numberOfSamples="8" name="OpenSpace">
<Stereo type="side_by_side" />
<!-- Res is equal to the Recommend target size -->
<Size x="1332" y="840" />
<Res x="3024" y="1680" />
<Viewport>
<Pos x="0.0" y="0.0" />
<Size x="1.0" y="1.0" />
<Projectionplane>
<!-- Lower left -->
<Pos x="-1.7156" y="-0.965" z="0.0" />
<!-- Upper left -->
<Pos x="-1.7156" y="0.965" z="0.0" />
<!-- Upper right -->
<Pos x="1.7156" y="0.965" z="0.0" />
</Projectionplane>
</Viewport>
</Window>
</Node>
</Cluster>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<Cluster masterAddress="localhost">
<Node address="localhost" port="20401">
<Window tags="OpenVR" fullScreen="false" numberOfSamples="8" name="OpenSpace">
<Stereo type="side_by_side" />
<!-- Res is equal to the Recommend target size -->
<Size x="1332" y="793" />
<Res x="2664" y="1586" />
<Viewport>
<Pos x="0.0" y="0.0" />
<Size x="1.0" y="1.0" />
<Projectionplane>
<!-- Lower left -->
<Pos x="-1.7156" y="-0.965" z="0.0" />
<!-- Upper left -->
<Pos x="-1.7156" y="0.965" z="0.0" />
<!-- Upper right -->
<Pos x="1.7156" y="0.965" z="0.0" />
</Projectionplane>
</Viewport>
</Window>
</Node>
</Cluster>

View File

@@ -5,6 +5,7 @@
return {
-- Determines which SGCT configuration file is loaded, that is, if there rendering
-- occurs in a single window, a fisheye projection, or a dome cluster system
-- A regular 1280x720 window
SGCTConfig = sgct.config.single{},
@@ -14,6 +15,8 @@ return {
-- A 4k fisheye rendering in a 1024x1024 window
-- SGCTConfig = sgct.config.fisheye{1024, 1024, res={4096, 4096}, quality="2k", tilt=27},
--SGCTConfig = "${SGCT}/openvr_oculusRiftCv1.xml",
--SGCTConfig = "${SGCT}/openvr_htcVive.xml",
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
-- of all entities that will be visible during an instance of OpenSpace
@@ -82,4 +85,4 @@ return {
DownloadRequestURL = "http://data.openspaceproject.com/request.cgi",
RenderingMethod = "Framebuffer"
--RenderingMethod = "ABuffer" -- alternative: "Framebuffer"
}
}