1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-19 05:39:41 +00:00

Merge branch 'openxr_vr' into 'openxr_vr'

Fix compile issues on Linux for mwvr

See merge request madsbuvi/openmw!4
This commit is contained in:
Mads Buvik Sandvei 2020-10-30 23:29:24 +00:00
commit 4e20482c0e
12 changed files with 99 additions and 12 deletions

View file

@ -13,7 +13,7 @@ stages:
before_script:
- export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
- apt-get update -yq
- apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-iostreams-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt5opengl5-dev libopenal-dev libopenscenegraph-dev libunshield-dev libtinyxml-dev libmygui-dev libbullet-dev liblz4-dev ccache git clang
- apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake build-essential libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-iostreams-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt5opengl5-dev libopenal-dev libopenscenegraph-dev libunshield-dev libtinyxml-dev libmygui-dev libbullet-dev liblz4-dev ccache git clang libxcb-glx0-dev libx11-dev
stage: build
script:
- export CCACHE_BASEDIR="`pwd`"

View file

@ -276,7 +276,13 @@ if(BUILD_OPENMW_VR)
target_include_directories(openmw_vr PRIVATE ${openxr_SOURCE_DIR}/include)
# Preprocessor variable used to control code paths to vr code
target_compile_options(openmw_vr PUBLIC -DUSE_OPENXR -DXR_USE_GRAPHICS_API_OPENGL -DXR_USE_PLATFORM_WIN32)
if (WIN32)
target_compile_options(openmw_vr PUBLIC -DUSE_OPENXR -DXR_USE_GRAPHICS_API_OPENGL -DXR_USE_PLATFORM_WIN32)
elseif(UNIX)
target_compile_options(openmw_vr PUBLIC -DUSE_OPENXR -DXR_USE_GRAPHICS_API_OPENGL -DXR_USE_PLATFORM_XLIB)
find_package(X11 REQUIRED)
target_link_libraries(openmw_vr ${X11_LIBRARIES})
endif()
target_link_libraries(openmw_vr ${OPENMW_LINK_TARGETS})
if(APPLE)
add_custom_command(TARGET openmw_vr

View file

@ -20,8 +20,8 @@
#include "../mwvr/vrenvironment.hpp"
#include "../mwrender/renderingmanager.hpp"
#include "../mwworld/player.hpp"
#include "../mwmechanics/actorutil.hpp"
#endif
#include "../mwmechanics/actorutil.hpp"
#include "actor.hpp"
#include "collisiontype.hpp"

View file

@ -12,6 +12,11 @@
#include <iostream>
// TODO: should implement actual safe strcpy
#ifdef __linux__
#define strcpy_s(dst, src) int(strcpy(dst, src) != nullptr)
#endif
namespace MWVR
{

View file

@ -3,9 +3,19 @@
#include "vrenvironment.hpp"
// The OpenXR SDK's platform headers assume we've included these windows headers
#ifdef _WIN32
#include <Windows.h>
#include <objbase.h>
#elif __linux__
#include <X11/Xlib.h>
#include <GL/glx.h>
#undef None
#else
#error Unsupported platform
#endif
#include <openxr/openxr_platform.h>
#include <openxr/openxr_platform_defines.h>
#include <openxr/openxr_reflection.h>

View file

@ -16,10 +16,20 @@
#include "../mwworld/player.hpp"
#include "../mwworld/esmstore.hpp"
// The OpenXR SDK's platform headers assume we've included these windows headers
// The OpenXR SDK's platform headers assume we've included platform headers
#ifdef _WIN32
#include <Windows.h>
#include <objbase.h>
#elif __linux__
#include <X11/Xlib.h>
#include <GL/glx.h>
#undef None
#else
#error Unsupported platform
#endif
#include <openxr/openxr_platform.h>
#include <openxr/openxr_platform_defines.h>
#include <openxr/openxr_reflection.h>
@ -111,8 +121,8 @@ namespace MWVR
}
}
#ifdef _WIN32
{ // Create Session
// TODO: Platform dependent
auto DC = wglGetCurrentDC();
auto GLRC = wglGetCurrentContext();
auto XRGLRC = wglCreateContext(DC);
@ -133,6 +143,38 @@ namespace MWVR
CHECK_XRCMD(xrCreateSession(mInstance, &createInfo, &mSession));
assert(mSession);
}
#elif __linux__
{ // Create Session
Display* xDisplay = XOpenDisplay(NULL);
GLXContext glxContext = glXGetCurrentContext();
GLXDrawable glxDrawable = glXGetCurrentDrawable();
// TODO: runtimes don't actually care (yet)
GLXFBConfig glxFBConfig = 0;
uint32_t visualid = 0;
XrGraphicsBindingOpenGLXlibKHR graphicsBindings;
graphicsBindings.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
graphicsBindings.next = nullptr;
graphicsBindings.xDisplay = xDisplay;
graphicsBindings.glxContext = glxContext;
graphicsBindings.glxDrawable = glxDrawable;
graphicsBindings.glxFBConfig = glxFBConfig;
graphicsBindings.visualid = visualid;
if (!graphicsBindings.glxContext)
Log(Debug::Warning) << "Missing glxContext";
if (!graphicsBindings.glxDrawable)
Log(Debug::Warning) << "Missing glxDrawable";
XrSessionCreateInfo createInfo{ XR_TYPE_SESSION_CREATE_INFO };
createInfo.next = &graphicsBindings;
createInfo.systemId = mSystemId;
CHECK_XRCMD(xrCreateSession(mInstance, &createInfo, &mSession));
assert(mSession);
}
#endif
LogInstanceInfo();
LogReferenceSpaces();
@ -187,7 +229,11 @@ namespace MWVR
if (XR_FAILED(res)) {
std::stringstream ss;
#ifdef _WIN32
ss << sourceLocation << ": OpenXR[Error: " << to_string(res) << "][Thread: " << std::this_thread::get_id() << "][DC: " << wglGetCurrentDC() << "][GLRC: " << wglGetCurrentContext() << "]: " << originator;
#elif __linux__
ss << sourceLocation << ": OpenXR[Error: " << to_string(res) << "][Thread: " << std::this_thread::get_id() << "][glxContext: " << glXGetCurrentContext() << "][glxDrawable: " << glXGetCurrentDrawable() << "]: " << originator;
#endif
Log(Debug::Error) << ss.str();
if (res == XR_ERROR_TIME_INVALID)
Log(Debug::Error) << "Breakpoint";
@ -196,7 +242,11 @@ namespace MWVR
}
else if (res != XR_SUCCESS || sLogAllXrCalls)
{
#ifdef _WIN32
Log(Debug::Verbose) << sourceLocation << ": OpenXR[" << to_string(res) << "][" << std::this_thread::get_id() << "][" << wglGetCurrentDC() << "][" << wglGetCurrentContext() << "]: " << originator;
#elif __linux__
Log(Debug::Verbose) << sourceLocation << ": OpenXR[" << to_string(res) << "][" << std::this_thread::get_id() << "][" << glXGetCurrentContext() << "][" << glXGetCurrentDrawable() << "]: " << originator;
#endif
}
return res;
@ -728,7 +778,7 @@ namespace MWVR
if (result != XR_EVENT_UNAVAILABLE)
CHECK_XRRESULT(result, "xrPollEvent");
return nullptr;
return false;
}
void OpenXRManagerImpl::popEvent()
@ -862,7 +912,7 @@ namespace MWVR
XrQuaternionf toXR(osg::Quat quat)
{
return XrQuaternionf{ quat.x(), quat.z(), -quat.y(), quat.w() };
return XrQuaternionf{ static_cast<float>(quat.x()), static_cast<float>(quat.z()), static_cast<float>(-quat.y()), static_cast<float>(quat.w()) };
}
}

View file

@ -5,9 +5,19 @@
#include <components/debug/debuglog.hpp>
#ifdef _WIN32
#include <Windows.h>
#include <objbase.h>
#elif __linux__
#include <X11/Xlib.h>
#include <GL/glx.h>
#undef None
#else
#error Unsupported platform
#endif
#include <openxr/openxr.h>
#include <openxr/openxr_platform.h>
#include <openxr/openxr_platform_defines.h>
@ -15,7 +25,9 @@
namespace MWVR {
OpenXRSwapchainImpl::OpenXRSwapchainImpl(osg::ref_ptr<osg::State> state, SwapchainConfig config)
: mWidth(config.selectedWidth)
: mSwapchainColorBuffers()
, mSwapchainDepthBuffers()
, mWidth(config.selectedWidth)
, mHeight(config.selectedHeight)
, mSamples(config.selectedSamples)
{

View file

@ -43,8 +43,8 @@ namespace MWVR
private:
XrSwapchain mSwapchain = XR_NULL_HANDLE;
XrSwapchain mSwapchainDepth = XR_NULL_HANDLE;
std::vector<XrSwapchainImageOpenGLKHR> mSwapchainColorBuffers{};
std::vector<XrSwapchainImageOpenGLKHR> mSwapchainDepthBuffers{};
std::vector<XrSwapchainImageOpenGLKHR> mSwapchainColorBuffers;
std::vector<XrSwapchainImageOpenGLKHR> mSwapchainDepthBuffers;
XrSwapchainSubImage mSubImage{};
XrSwapchainSubImage mSubImageDepth{};
int32_t mWidth = -1;

View file

@ -1,5 +1,7 @@
#include "vrgui.hpp"
#include <cmath>
#include "vrenvironment.hpp"
#include "vrsession.hpp"
#include "openxrmanagerimpl.hpp"
@ -50,7 +52,7 @@ namespace MWVR
// When making a circle of a given radius of equally wide planes separated by a given angle, what is the width
static osg::Vec2 radiusAngleWidth(float radius, float angleRadian)
{
const float width = std::fabs(2.f * radius * std::tanf(angleRadian / 2.f));
const float width = std::fabs(2.f * radius * tanf(angleRadian / 2.f));
return osg::Vec2(width, width);
}

View file

@ -7,6 +7,7 @@
#include <chrono>
#include <queue>
#include <thread>
#include <condition_variable>
#include <components/debug/debuglog.hpp>
#include <components/sdlutil/sdlgraphicswindow.hpp>
#include <components/settings/settings.hpp>

View file

@ -36,6 +36,7 @@ namespace MWVR
VRViewer::VRViewer(
osg::ref_ptr<osgViewer::Viewer> viewer)
: mViewer(viewer)
, mViews()
, mPreDraw(new PredrawCallback(this))
, mPostDraw(new PostdrawCallback(this))
, mVrShadow()

View file

@ -87,7 +87,7 @@ namespace MWVR
private:
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
std::map<std::string, osg::ref_ptr<VRView> > mViews{};
std::map<std::string, osg::ref_ptr<VRView> > mViews;
std::map<std::string, osg::ref_ptr<osg::Camera> > mCameras{};
osg::ref_ptr<PredrawCallback> mPreDraw{ nullptr };
osg::ref_ptr<PostdrawCallback> mPostDraw{ nullptr };