Commit dfac321a authored by Robert Menzel's avatar Robert Menzel

added initial support for QT

parent 8de5f833
......@@ -45,7 +45,13 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#ifdef ACGL_COMPILE_WITH_GLFW
#include <GLFW/glfw3.h>
#endif
#ifdef ACGL_COMPILE_WITH_QT
#include <qwidget.h>
#endif
#include <OVR_CAPI_GL.h>
namespace ACGL{
......@@ -72,6 +78,11 @@ namespace OVR{
ACGL::OpenGL::ConstSharedTexture2D _rightTexture,
ovrGLTexture _eyeRenderDesc[2]);
// alternative with two (size) identical gl textures:
void generateEyeTextureDescription(GLuint _leftTexture,
GLuint _rightTexture, glm::uvec2 _size,
ovrGLTexture _eyeRenderDesc[2]);
// the Rift SDK needs to know our window, this function hides the window system/OS specifics:
// it's limited to OpenGL / no multisampling back buffers, if more flexibility is needed,
// write your own similar function.
......@@ -79,7 +90,13 @@ namespace OVR{
#ifdef ACGL_COMPILE_WITH_GLFW
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, GLFWwindow *_window);
#endif
#ifdef ACGL_COMPILE_WITH_QT
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, QWidget *_window);
#endif
// assumed that _cfg has already set the OS specific fields!
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, ovrGLConfig _cfg);
// after calling this the warning might still be presented for a few more seconds:
// returns true if the warning is still displayed. Can be called multiple times.
bool deactivateHealthWarning(ovrHmd _hmd);
......
......@@ -227,7 +227,6 @@ ACGL_SMARTPOINTER_TYPEDEFS(SimpleRiftController)
#include <glm/gtc/quaternion.hpp>
#include <ACGL/Scene/OculusRiftCamera.hh>
#include <ACGL/Scene/GenericCamera.hh>
//#include <ACGL/Scene/HMDCamera.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
......@@ -264,13 +263,20 @@ namespace ACGL{
// if _outputViewportSize is 0, use mOutputViewportSize (set previously by setOutputViewportSize() );
void configureRendering(ACGL::OpenGL::ConstSharedTexture2D _leftTexture, ACGL::OpenGL::ConstSharedTexture2D _rightTexture );
void configureRendering(GLuint _leftTexture, GLuint _rightTexture, glm::uvec2 _size );
void renderDistorted();
#ifdef ACGL_COMPILE_WITH_GLFW
void setGLFWWindow(GLFWwindow *_window) { mGLFWWindow = _window; }
#endif
#ifdef ACGL_COMPILE_WITH_QT
void setQWidget( QWidget *_qwidget ) { mQWidget = _qwidget; }
#endif
bool getSuccessfulConnected() { return (mHMD != NULL); }
private:
void configureRendering();
ACGL::Scene::SharedOculusRiftCamera mCamera;
ACGL::Scene::SharedGenericCamera mNormalCamera;
ovrHmd mHMD;
......@@ -278,8 +284,12 @@ namespace ACGL{
bool mRenderingConfigured;
ovrGLTexture mGLTexture[2];
#ifdef ACGL_COMPILE_WITH_GLFW
GLFWwindow *mGLFWWindow;
#endif
#ifdef ACGL_COMPILE_WITH_QT
QWidget *mQWidget;
#endif
int mNextExpectedEyeNumber;
};
......
......@@ -14,6 +14,9 @@
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#endif
#ifdef ACGL_COMPILE_WITH_QT
#include <QMainWindow>
#endif
#include <OVR_CAPI_GL.h>
using namespace std;
......@@ -135,21 +138,28 @@ void generateEyeTextureDescription(ACGL::OpenGL::ConstSharedTexture2D _leftTextu
_eyeRenderDesc[1].OGL.TexId = _rightTexture->getObjectName();
}
void generateEyeTextureDescription(GLuint _leftTexture, GLuint _rightTexture, glm::uvec2 _size, ovrGLTexture _eyeRenderDesc[2])
{
// same for both eyes:
for (int eyeIndex = 0; eyeIndex < 2; ++eyeIndex) {
_eyeRenderDesc[eyeIndex].OGL.Header.API = ovrRenderAPI_OpenGL;
_eyeRenderDesc[eyeIndex].OGL.Header.RenderViewport.Pos.x = 0;
_eyeRenderDesc[eyeIndex].OGL.Header.RenderViewport.Pos.y = 0;
_eyeRenderDesc[eyeIndex].OGL.Header.RenderViewport.Size.w = _size.x;
_eyeRenderDesc[eyeIndex].OGL.Header.RenderViewport.Size.h = _size.y;
_eyeRenderDesc[eyeIndex].OGL.Header.TextureSize.w = _size.x;
_eyeRenderDesc[eyeIndex].OGL.Header.TextureSize.h = _size.y;
}
_eyeRenderDesc[0].OGL.TexId = _leftTexture;
_eyeRenderDesc[1].OGL.TexId = _rightTexture;
}
#ifdef ACGL_COMPILE_WITH_GLFW
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, GLFWwindow *_window)
{
if (!_hmd) return false;
// Update ovr Rendering configuration
ovrGLConfig cfg;
cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
cfg.OGL.Header.RTSize.w = _renderTagetSize.x;
cfg.OGL.Header.RTSize.h = _renderTagetSize.y;
cfg.OGL.Header.Multisample = 0;
#ifdef OVR_OS_WIN32
//debug() << "configure Windows specifics" << std::endl;
cfg.OGL.Window = glfwGetWin32Window(_window);
cfg.OGL.DC = GetDC(cfg.OGL.Window);
#endif
......@@ -159,6 +169,39 @@ bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uv
#ifdef OVR_OS_LINUX
debug() << "configure Linux specifics: TODO" << std::endl;
#endif
return configureRendering(_hmd, _eyeRenderDesc, _renderTagetSize, cfg);
}
#endif
#ifdef ACGL_COMPILE_WITH_QT
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, QWidget *_window)
{
ovrGLConfig cfg;
#ifdef OVR_OS_WIN32
cfg.OGL.Window = (HWND) _window->winId();
cfg.OGL.DC = GetDC(cfg.OGL.Window);
#endif
#ifdef OVR_OS_MAC
debug() << "configure Mac specifics: TODO" << std::endl;
#endif
#ifdef OVR_OS_LINUX
debug() << "configure Linux specifics: TODO" << std::endl;
#endif
return configureRendering(_hmd, _eyeRenderDesc, _renderTagetSize, cfg);
}
#endif
bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uvec2 _renderTagetSize, ovrGLConfig _cfg)
{
if (!_hmd) return false;
// Update ovr Rendering configuration
_cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
_cfg.OGL.Header.RTSize.w = _renderTagetSize.x;
_cfg.OGL.Header.RTSize.h = _renderTagetSize.y;
_cfg.OGL.Header.Multisample = 0;
// OS specifics are already set in _cfg!
//debug() << "call ovrHmd_ConfigureRendering():" << std::endl;
//printDistortionCaps(_hmd->DistortionCaps);
......@@ -167,11 +210,11 @@ bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uv
distortionCaps ^= ovrDistortionCap_SRGB;
#ifdef OVR_OS_WIN32
ovrHmd_AttachToWindow(_hmd, cfg.OGL.Window, nullptr, nullptr);
ovrHmd_AttachToWindow(_hmd, _cfg.OGL.Window, nullptr, nullptr);
#endif
//printDistortionCaps(distortionCaps);
ovrBool ok = ovrHmd_ConfigureRendering(_hmd, (ovrRenderAPIConfig*)&cfg, distortionCaps, _hmd->DefaultEyeFov, _eyeRenderDesc);
ovrBool ok = ovrHmd_ConfigureRendering(_hmd, (ovrRenderAPIConfig*)&_cfg, distortionCaps, _hmd->DefaultEyeFov, _eyeRenderDesc);
if (ok) {
bool riftIsUsingExtendedDesktop = (bool)(_hmd->HmdCaps & ovrHmdCap_ExtendDesktop);
//debug() << "OVR Rendering configured" << std::endl;
......@@ -182,7 +225,7 @@ bool configureRendering(ovrHmd _hmd, ovrEyeRenderDesc _eyeRenderDesc[2], glm::uv
return (bool)ok;
}
#endif
bool deactivateHealthWarning(ovrHmd _hmd)
{
......
......@@ -749,10 +749,12 @@ using namespace ACGL::OpenGL;
using namespace std;
SimpleRiftController::SimpleRiftController(uint32_t _riftnumber) : mRenderingConfigured(false), mGLFWWindow(NULL), mNextExpectedEyeNumber(0) {
SimpleRiftController::SimpleRiftController(uint32_t _riftnumber) : mRenderingConfigured(false), mNextExpectedEyeNumber(0) {
#ifdef ACGL_COMPILE_WITH_GLFW
mGLFWWindow = NULL;
#endif
OVR::initSDK();
mHMD = OVR::createHMD(_riftnumber);
OVR::deactivateHealthWarning(mHMD);
mCamera = SharedOculusRiftCamera(new OculusRiftCamera());
mCamera->connectWithRift(mHMD);
......@@ -768,19 +770,35 @@ SimpleRiftController::~SimpleRiftController() {
OVR::shutdownSDK();
}
void SimpleRiftController::configureRendering(GLuint _leftTexture, GLuint _rightTexture, glm::uvec2 _size ) {
// mGLTexture will be set:
ACGL::HardwareSupport::OVR::generateEyeTextureDescription(_leftTexture, _rightTexture, _size, mGLTexture);
configureRendering();
}
void SimpleRiftController::configureRendering(ACGL::OpenGL::ConstSharedTexture2D _leftTexture, ACGL::OpenGL::ConstSharedTexture2D _rightTexture) {
if (!mHMD) return;
// mGLTexture will be set:
ACGL::HardwareSupport::OVR::generateEyeTextureDescription(_leftTexture, _rightTexture, mGLTexture);
configureRendering();
}
assert(mGLFWWindow && "call setGLFWWindow first!");
void SimpleRiftController::configureRendering() {
if (!mHMD) return;
int width, height;
#ifdef ACGL_COMPILE_WITH_GLFW
assert(mGLFWWindow && "call setGLFWWindow first!");
glfwGetWindowSize(mGLFWWindow, &width, &height);
// mEyeRenderDesc will be set by this:
ACGL::HardwareSupport::OVR::configureRendering(mHMD, mCamera->mEyeRenderDesc, glm::uvec2(width,height), mGLFWWindow);
// mEyeTexture will be set:
ACGL::HardwareSupport::OVR::generateEyeTextureDescription(_leftTexture, _rightTexture, mGLTexture);
#elif ACGL_COMPILE_WITH_QT
assert(mQWidget && "call setQWidget first!");
width = mQWidget->size().width();
height = mQWidget->size().height();
ACGL::HardwareSupport::OVR::configureRendering(mHMD, mCamera->mEyeRenderDesc, glm::uvec2(width,height), mQWidget);
#else
assert(0 && "can't configure SDK rendering as no OS Window is provided!");
#endif
mRenderingConfigured = true;
}
......@@ -796,7 +814,7 @@ void SimpleRiftController::renderDistorted() {
}
glm::uvec2 SimpleRiftController::getPhysicalScreenResolution() {
return glm::uvec2(1920, 1080); // TODO!
return glm::uvec2( mHMD->Resolution.w, mHMD->Resolution.h );
}
GenericCamera::Eye SimpleRiftController::updateCameraEye(int _eyeNumber)
......@@ -811,7 +829,7 @@ GenericCamera::Eye SimpleRiftController::updateCameraEye(int _eyeNumber)
if (_eyeNumber == 0) {
// has to be called at the beginning of the frame, one reason why the eye order is important!
OVR::beginFrame(mHMD);
OVR::deactivateHealthWarning(mHMD);
OVR::deactivateHealthWarning(mHMD); // just quit this asap -> apps should also call this as this might not stay here
}
return mCamera->setPoseForEyeFromRift(_eyeNumber);
......
......@@ -190,26 +190,26 @@ GenericCamera::Eye OculusRiftCamera::setPoseForEyeFromRift(int _eyeNumber)
if (eyeType == ovrEye_Right) eye = GenericCamera::EYE_RIGHT;
// pose:
glm::quat rotation{ eyePose.Orientation.w, eyePose.Orientation.x, eyePose.Orientation.y, eyePose.Orientation.z };
glm::vec3 translation{ eyePose.Position.x, eyePose.Position.y, eyePose.Position.z };
glm::quat rotation( eyePose.Orientation.w, eyePose.Orientation.x, eyePose.Orientation.y, eyePose.Orientation.z );
glm::vec3 translation( eyePose.Position.x, eyePose.Position.y, eyePose.Position.z );
//std::cout << glm::to_string(translation) << std::endl;
// projection:
ovrMatrix4f ovrp = ovrMatrix4f_Projection(mEyeRenderDesc[_eyeNumber].Fov, getNearClippingPlane(), getFarClippingPlane(), true);
glm::mat4 projection{
glm::mat4 projection(
ovrp.M[0][0], ovrp.M[1][0], ovrp.M[2][0], ovrp.M[3][0],
ovrp.M[0][1], ovrp.M[1][1], ovrp.M[2][1], ovrp.M[3][1],
ovrp.M[0][2], ovrp.M[1][2], ovrp.M[2][2], ovrp.M[3][2],
ovrp.M[0][3], ovrp.M[1][3], ovrp.M[2][3], ovrp.M[3][3]
};
);
mProjectionMatrix = projection;
glm::vec3 eyeOffset{ mEyeRenderDesc[_eyeNumber].ViewAdjust.x, mEyeRenderDesc[_eyeNumber].ViewAdjust.y, mEyeRenderDesc[_eyeNumber].ViewAdjust.z };
glm::vec3 eyeOffset( mEyeRenderDesc[_eyeNumber].ViewAdjust.x, mEyeRenderDesc[_eyeNumber].ViewAdjust.y, mEyeRenderDesc[_eyeNumber].ViewAdjust.z );
glm::vec4 basePosition = glm::vec4(MoveableObject::getPosition(), 1.0);
mEyePosition = glm::vec3{ glm::inverse(getViewMatrix()) * basePosition };
mEyePosition = glm::vec3( glm::inverse(getViewMatrix()) * basePosition );
mViewMatrix = glm::translate(eyeOffset) * glm::inverse( glm::translate(translation) * glm::mat4_cast(rotation) ) * MoveableObject::getModelMatrix();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment