Merge branch 'plugins2' into plugins

Conflicts:
	interface/src/Application.cpp
	interface/src/plugins/Plugin.h
	interface/src/plugins/render/OculusBaseRenderPlugin.cpp
	interface/src/plugins/render/OculusBaseRenderPlugin.h
	interface/src/plugins/render/RenderPlugin.h
	interface/src/plugins/render/Tv3dRenderPlugin.cpp
	interface/src/plugins/render/Tv3dRenderPlugin.h
	interface/src/ui/ApplicationOverlay.cpp
	interface/src/ui/ApplicationOverlay.h
This commit is contained in:
Brad Davis 2015-04-30 11:04:06 -07:00
commit 2fa92af4ab
9 changed files with 214 additions and 111 deletions

View file

@ -795,19 +795,20 @@ void Application::paintGL() {
primaryFbo->release();
QOpenGLFramebufferObject * finalFbo = DependencyManager::get<GlowEffect>()->render();
// This might not be needed *right now*. We want to ensure that the FBO rendering
// has completed before we start trying to read from it in another context. However
// once we have multi-threaded rendering, this will almost certainly be critical,
// but may be better handled with a fence object
glFinish();
#if 0
finalFbo->bind();
{
PerformanceTimer perfTimer("renderOverlay");
_applicationOverlay.renderOverlay();
_applicationOverlay.displayOverlayTexture();
}
#endif
finalFbo->release();
// This might not be needed *right now*. We want to ensure that the FBO rendering
// has completed before we start trying to read from it in another context. However
// once we have multi-threaded rendering, this will almost certainly be critical,
// but may be better handled with a fence object
glFinish();
_offscreenContext->doneCurrent();
Q_ASSERT(!QOpenGLContext::currentContext());
@ -3161,16 +3162,9 @@ void Application::getProjectionMatrix(glm::dmat4* projectionMatrix) {
void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
// allow 3DTV/Oculus to override parameters from camera
_displayViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
#if 0
if (OculusManager::isConnected()) {
OculusManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
} else if (TV3DManager::isConnected()) {
TV3DManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
}
#endif
// allow 3DTV/Oculus to override parameters from camera
getActiveRenderPlugin()->overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
}
bool Application::getShadowsEnabled() {
@ -3263,10 +3257,6 @@ void Application::resetSensors() {
DependencyManager::get<DdeFaceTracker>()->reset();
getActiveRenderPlugin()->resetSensors();
#if 0
OculusManager::reset();
#endif
//_leapmotion.reset();
#if 0

View file

@ -4,8 +4,6 @@
#include <QObject>
class Plugin : public QObject {
private:
bool _active{ false };
public:
virtual const QString & getName() = 0;
virtual bool isSupported() { return true; }

View file

@ -8,3 +8,97 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "OculusBaseRenderPlugin.h"
#include <OVR_CAPI.h>
bool OculusBaseRenderPlugin::sdkInitialized = false;
bool OculusBaseRenderPlugin::enableSdk() {
sdkInitialized = ovr_Initialize();
return sdkInitialized;
}
void OculusBaseRenderPlugin::disableSdk() {
ovr_Shutdown();
sdkInitialized = false;
}
void OculusBaseRenderPlugin::withSdkActive(std::function<void()> f) {
bool activateSdk = !sdkInitialized;
if (activateSdk && !enableSdk()) {
return;
}
f();
if (activateSdk) {
disableSdk();
}
}
bool OculusBaseRenderPlugin::isSupported() {
bool attached = false;
withSdkActive([&] {
attached = ovrHmd_Detect();
});
return attached;
}
void OculusBaseRenderPlugin::activate() {
enableSdk();
}
void OculusBaseRenderPlugin::deactivate() {
disableSdk();
}
#if 0
// Set the desired FBO texture size. If it hasn't changed, this does nothing.
// Otherwise, it must rebuild the FBOs
if (OculusManager::isConnected()) {
DependencyManager::get<TextureCache>()->setFrameBufferSize(OculusManager::getRenderTargetSize());
} else {
#endif
#if 0
// Update camera position
if (!OculusManager::isConnected()) {
_myCamera.update(1.0f / _fps);
}
#endif
#if 0
if (OculusManager::isConnected()) {
//When in mirror mode, use camera rotation. Otherwise, use body rotation
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera);
} else {
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera);
}
_myCamera.update(1.0f / _fps);
#endif
#if 0
OculusManager::abandonCalibration();
#endif
#if 0
if (OculusManager::isConnected()) {
return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
}
#endif
#if 0
if (OculusManager::isConnected()) {
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
return pos.x;
}
#endif
#if 0
if (OculusManager::isConnected()) {
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
return pos.y;
}
#endif

View file

@ -10,68 +10,31 @@
#pragma once
#include "HmdRenderPlugin.h"
#include <functional>
class OculusRenderPluginBase : public HmdRenderPlugin {
class OculusBaseRenderPlugin : public HmdRenderPlugin {
public:
virtual bool isSupported();
virtual void init();
virtual void deinit();
virtual void activate();
virtual void deactivate();
virtual void overrideOffAxisFrustum(
float& left, float& right, float& bottom, float& top,
float& nearVal, float& farVal,
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
protected:
virtual bool isRiftPresent();
virtual bool isDirectMode();
static bool sdkInitialized;
static void withSdkActive(std::function<void()> f);
static bool enableSdk();
static void disableSdk();
};
#if 0
// Set the desired FBO texture size. If it hasn't changed, this does nothing.
// Otherwise, it must rebuild the FBOs
if (OculusManager::isConnected()) {
DependencyManager::get<TextureCache>()->setFrameBufferSize(OculusManager::getRenderTargetSize());
} else {
#endif
#if 0
// Update camera position
if (!OculusManager::isConnected()) {
_myCamera.update(1.0f / _fps);
}
#endif
#if 0
if (OculusManager::isConnected()) {
//When in mirror mode, use camera rotation. Otherwise, use body rotation
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera);
} else {
OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera);
}
_myCamera.update(1.0f / _fps);
} else if (TV3DManager::isConnected()) {
TV3DManager::display(_myCamera);
} else {
#endif
#if 0
OculusManager::abandonCalibration();
#endif
#if 0
if (OculusManager::isConnected()) {
return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
}
#endif
#if 0
if (OculusManager::isConnected()) {
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
return pos.x;
}
#endif
#if 0
if (OculusManager::isConnected()) {
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
return pos.y;
}
#endif

View file

@ -30,13 +30,31 @@ public:
virtual void postRender() {};
// Pointer support
// Does the rendering surface have current focus?
virtual bool hasFocus() const = 0;
// The size of the rendering surface
virtual QSize getRecommendedFramebufferSize() const = 0;
// The size of the window (differs from the framebuffers size in instances like Retina macs)
virtual glm::ivec2 getCanvasSize() const = 0;
virtual glm::ivec2 getUiMousePosition() const = 0;
// The mouse position relative to the window (or proxy window) surface
virtual glm::ivec2 getTrueMousePosition() const = 0;
// The mouse position relative to the UI elements
virtual glm::ivec2 getUiMousePosition() const {
return trueMouseToUiMouse(getTrueMousePosition());
}
// Convert from screen mouse coordinates to UI mouse coordinates
virtual glm::ivec2 trueMouseToUiMouse(const glm::ivec2 & position) const { return position; };
virtual PickRay computePickRay(const glm::vec2 & pos) const = 0;
virtual bool isMouseOnScreen() const;
virtual void overrideOffAxisFrustum(
float& left, float& right, float& bottom, float& top,
float& nearVal, float& farVal,
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { }
// HMD specific methods
// TODO move these into another class

View file

@ -9,3 +9,35 @@
//
#include "Tv3dRenderPlugin.h"
const QString Tv3dRenderPlugin::NAME("Tv3dRenderPlugin");
const QString & Tv3dRenderPlugin::getName() {
return NAME;
}
void Tv3dRenderPlugin::overrideOffAxisFrustum(
float& left, float& right, float& bottom, float& top,
float& nearVal, float& farVal,
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
#if 0
if (_activeEye) {
left = _activeEye->left;
right = _activeEye->right;
bottom = _activeEye->bottom;
top = _activeEye->top;
}
#endif
}
#if 0
} else if (TV3DManager::isConnected()) {
TV3DManager::display(_myCamera);
} else {
#endif

View file

@ -11,3 +11,16 @@
#pragma once
#include "StereoRenderPlugin.h"
class Tv3dRenderPlugin : public StereoRenderPlugin {
Q_OBJECT
public:
static const QString NAME;
virtual const QString & getName();
virtual void overrideOffAxisFrustum(
float& left, float& right, float& bottom, float& top,
float& nearVal, float& farVal,
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
};

View file

@ -133,7 +133,7 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) {
}
ApplicationOverlay::ApplicationOverlay() :
_textureFov(glm::radians(DEFAULT_OCULUS_UI_ANGULAR_SIZE)),
_textureFov(glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE)),
_textureAspectRatio(1.0f),
_lastMouseMove(0),
_magnifier(true),
@ -172,7 +172,7 @@ void ApplicationOverlay::renderOverlay() {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()");
Overlays& overlays = qApp->getOverlays();
_textureFov = glm::radians(_oculusUIAngularSize);
_textureFov = glm::radians(_hmdUIAngularSize);
glm::vec2 canvasSize = Application::getInstance()->getCanvasSize();
_textureAspectRatio = canvasSize.x / canvasSize.y;;
@ -187,7 +187,7 @@ void ApplicationOverlay::renderOverlay() {
_overlays.buildFramebufferObject();
_overlays.bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); {
const float NEAR_CLIP = -10000;
const float FAR_CLIP = 10000;
@ -450,9 +450,7 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const {
glm::vec3 tipPos = invOrientation * (tip - eyePos);
QPoint rv;
#if 0
if (OculusManager::isConnected()) {
auto glCanvas = Application::getInstance()->getGLWidget();
if (qApp->getActiveRenderPlugin()->isHmd()) {
float t;
//We back the ray up by dir to ensure that it will not start inside the UI.
@ -470,9 +468,10 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const {
float u = asin(collisionPos.x) / (_textureFov)+0.5f;
float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f);
auto size = qApp->getActiveRenderPlugin()->getCanvasSize();
rv.setX(u * glCanvas->width());
rv.setY(v * glCanvas->height());
rv.setX(u * size.x);
rv.setY(v * size.y);
}
} else {
//if they did not click on the overlay, just set the coords to INT_MAX
@ -480,7 +479,6 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const {
rv.setY(INT_MAX);
}
} else {
#endif
glm::dmat4 projection;
qApp->getProjectionMatrix(&projection);
@ -493,9 +491,7 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const {
glm::ivec2 canvasSize = Application::getInstance()->getCanvasSize();
rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * canvasSize.x);
rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * canvasSize.y);
#if 0
}
#endif
return rv;
}
@ -528,20 +524,20 @@ void ApplicationOverlay::renderPointers() {
glActiveTexture(GL_TEXTURE0);
_crosshairTexture->bind();
#if 0
if (OculusManager::isConnected() && !qApp->getLastMouseMoveWasSimulated() && !qApp->isMouseHidden()) {
auto glCanvas = Application::getInstance()->getGLWidget();
if (qApp->getActiveRenderPlugin()->isHmd() && !qApp->getLastMouseMoveWasSimulated() && !qApp->isMouseHidden()) {
glm::ivec2 trueMouse = qApp->getActiveRenderPlugin()->getTrueMousePosition();
//If we are in oculus, render reticle later
if (_lastMouseMove == 0) {
_lastMouseMove = usecTimestampNow();
}
QPoint position = QPoint(qApp->getTrueMouseX(), qApp->getTrueMouseY());
QPoint position(trueMouse.x, trueMouse.y);
static const int MAX_IDLE_TIME = 3;
if (_reticlePosition[MOUSE] != position) {
_lastMouseMove = usecTimestampNow();
} else if (usecTimestampNow() - _lastMouseMove > MAX_IDLE_TIME * USECS_PER_SECOND) {
#if 0
float pitch = 0.0f, yaw = 0.0f, roll = 0.0f; // radians
OculusManager::getEulerAngles(yaw, pitch, roll);
glm::quat orientation(glm::vec3(pitch, yaw, roll));
@ -559,6 +555,7 @@ void ApplicationOverlay::renderPointers() {
} else {
qDebug() << "No collision point";
}
#endif
}
_reticlePosition[MOUSE] = position;
@ -566,9 +563,7 @@ void ApplicationOverlay::renderPointers() {
_magActive[MOUSE] = _magnifier;
_reticleActive[LEFT_CONTROLLER] = false;
_reticleActive[RIGHT_CONTROLLER] = false;
} else
#endif
if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
} else if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
_lastMouseMove = 0;
//only render controller pointer if we aren't already rendering a mouse pointer
_reticleActive[MOUSE] = false;
@ -916,7 +911,6 @@ void ApplicationOverlay::renderStatsAndLogs() {
Application* application = Application::getInstance();
QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
auto glCanvas = Application::getInstance()->getGLWidget();
const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor();
NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
@ -944,7 +938,10 @@ void ApplicationOverlay::renderStatsAndLogs() {
int timerBottom =
(Menu::getInstance()->isOptionChecked(MenuOption::Stats))
? 80 : 20;
drawText(glCanvas->width() - 100, glCanvas->height() - timerBottom,
auto size = qApp->getActiveRenderPlugin()->getCanvasSize();
// auto glCanvas = Application::getInstance()->getGLWidget();
drawText(size.x - 100, size.y - timerBottom,
0.30f, 0.0f, 0, frameTimer.toUtf8().constData(), WHITE_TEXT);
}
nodeBoundsDisplay.drawOverlay();

View file

@ -21,7 +21,7 @@ const float MAGNIFY_WIDTH = 220.0f;
const float MAGNIFY_HEIGHT = 100.0f;
const float MAGNIFY_MULT = 2.0f;
const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f;
const float DEFAULT_HMD_UI_ANGULAR_SIZE = 72.0f;
// Handles the drawing of the overlays to the screen
class ApplicationOverlay {
@ -44,10 +44,8 @@ public:
bool hasMagnifier() const { return _magnifier; }
void toggleMagnifier() { _magnifier = !_magnifier; }
#if 0
float getOculusUIAngularSize() const { return _oculusUIAngularSize; }
void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; }
#endif
float getHmdUIAngularSize() const { return _hmdUIAngularSize; }
void setHmdUIAngularSize(float hmdUIAngularSize) { _hmdUIAngularSize = hmdUIAngularSize; }
// Converter from one frame of reference to another.
// Frame of reference:
@ -97,7 +95,7 @@ private:
VerticesIndices _vbo;
};
float _oculusUIAngularSize = DEFAULT_OCULUS_UI_ANGULAR_SIZE;
float _hmdUIAngularSize = DEFAULT_HMD_UI_ANGULAR_SIZE;
void renderReticle(glm::quat orientation, float alpha);
void renderPointers();;