first cut at getting overlays to toggle again

This commit is contained in:
Brad Hefta-Gaub 2016-03-10 16:07:49 -08:00
parent 1547fc15aa
commit ff30611234
6 changed files with 102 additions and 4 deletions

View file

@ -11,6 +11,7 @@
#include <memory> #include <memory>
#include <math.h> #include <math.h>
#include <QtCore/QTimer>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget> #include <QtWidgets/QDesktopWidget>
@ -414,13 +415,45 @@ void CompositorHelper::updateTooltips() {
} }
static const float FADE_DURATION = 500.0f; static const float FADE_DURATION = 500.0f;
static const float FADE_IN_ALPHA = 1.0f;
static const float FADE_OUT_ALPHA = 0.0f;
void CompositorHelper::startFadeFailsafe(float endValue) {
return;
qDebug() << __FUNCTION__;
_fadeStarted = usecTimestampNow();
_fadeFailsafeEndValue = endValue;
const int SLIGHT_DELAY = 10;
QTimer::singleShot(FADE_DURATION + SLIGHT_DELAY, [this]{
checkFadeFailsafe();
});
}
void CompositorHelper::checkFadeFailsafe() {
return;
qDebug() << __FUNCTION__;
auto elapsedInFade = usecTimestampNow() - _fadeStarted;
if (elapsedInFade > FADE_DURATION) {
setAlpha(_fadeFailsafeEndValue);
}
}
void CompositorHelper::fadeIn() { void CompositorHelper::fadeIn() {
_fadeInAlpha = true; _fadeInAlpha = true;
_alphaPropertyAnimation->setDuration(FADE_DURATION); _alphaPropertyAnimation->setDuration(FADE_DURATION);
_alphaPropertyAnimation->setStartValue(_alpha); _alphaPropertyAnimation->setStartValue(_alpha);
_alphaPropertyAnimation->setEndValue(1.0f); _alphaPropertyAnimation->setEndValue(FADE_IN_ALPHA);
_alphaPropertyAnimation->start(); _alphaPropertyAnimation->start();
// Sometimes, this "QPropertyAnimation" fails to complete the animation, and we end up with a partially faded
// state. So we will also have this fail-safe, where we record the timestamp of the fadeRequest, and the target
// value of the fade, and if after that time we still haven't faded all the way, we will kick it to the final
// fade value
startFadeFailsafe(FADE_IN_ALPHA);
} }
void CompositorHelper::fadeOut() { void CompositorHelper::fadeOut() {
@ -428,8 +461,9 @@ void CompositorHelper::fadeOut() {
_alphaPropertyAnimation->setDuration(FADE_DURATION); _alphaPropertyAnimation->setDuration(FADE_DURATION);
_alphaPropertyAnimation->setStartValue(_alpha); _alphaPropertyAnimation->setStartValue(_alpha);
_alphaPropertyAnimation->setEndValue(0.0f); _alphaPropertyAnimation->setEndValue(FADE_OUT_ALPHA);
_alphaPropertyAnimation->start(); _alphaPropertyAnimation->start();
startFadeFailsafe(FADE_OUT_ALPHA);
} }
void CompositorHelper::toggle() { void CompositorHelper::toggle() {

View file

@ -145,6 +145,11 @@ private:
float _fadeInAlpha { true }; float _fadeInAlpha { true };
float _oculusUIRadius { 1.0f }; float _oculusUIRadius { 1.0f };
quint64 _fadeStarted { 0.0f };
float _fadeFailsafeEndValue { 1.0f };
void checkFadeFailsafe();
void startFadeFailsafe(float endValue);
int _reticleQuad; int _reticleQuad;
int _previousBorderWidth { -1 }; int _previousBorderWidth { -1 };

View file

@ -296,6 +296,9 @@ void OpenGLDisplayPlugin::customizeContext() {
if (uniform.Name() == "mvp") { if (uniform.Name() == "mvp") {
_mvpUniform = uniform.Index(); _mvpUniform = uniform.Index();
} }
if (uniform.Name() == "alpha") {
_alphaUniform = uniform.Index();
}
uniforms.Next(); uniforms.Next();
} }
@ -406,6 +409,20 @@ void OpenGLDisplayPlugin::updateFramerate() {
void OpenGLDisplayPlugin::compositeOverlay() { void OpenGLDisplayPlugin::compositeOverlay() {
using namespace oglplus; using namespace oglplus;
// set the alpha
auto compositorHelper = DependencyManager::get<CompositorHelper>();
auto overlayAlpha = compositorHelper->getAlpha();
qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha;
if (overlayAlpha <= 0.0f) {
//return; // don't render the overlay at all.
qDebug() << "would bail early...";
}
Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
// Overlay draw // Overlay draw
if (isStereo()) { if (isStereo()) {
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4()); Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4());
@ -423,6 +440,17 @@ void OpenGLDisplayPlugin::compositeOverlay() {
void OpenGLDisplayPlugin::compositePointer() { void OpenGLDisplayPlugin::compositePointer() {
using namespace oglplus; using namespace oglplus;
auto compositorHelper = DependencyManager::get<CompositorHelper>(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
// set the alpha
auto overlayAlpha = compositorHelper->getAlpha();
if (overlayAlpha <= 0.0f) {
//return; // don't render the overlay at all.
qDebug() << "would bail early...";
}
qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha;
Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
Uniform<glm::mat4>(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4())); Uniform<glm::mat4>(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4()));
if (isStereo()) { if (isStereo()) {
for_each_eye([&](Eye eye) { for_each_eye([&](Eye eye) {

View file

@ -86,6 +86,7 @@ protected:
ProgramPtr _program; ProgramPtr _program;
int32_t _mvpUniform { -1 }; int32_t _mvpUniform { -1 };
int32_t _alphaUniform { -1 };
ShapeWrapperPtr _plane; ShapeWrapperPtr _plane;
mutable Mutex _mutex; mutable Mutex _mutex;

View file

@ -62,6 +62,20 @@ void HmdDisplayPlugin::uncustomizeContext() {
void HmdDisplayPlugin::compositeOverlay() { void HmdDisplayPlugin::compositeOverlay() {
using namespace oglplus; using namespace oglplus;
// set the alpha
auto compositorHelper = DependencyManager::get<CompositorHelper>();
auto overlayAlpha = compositorHelper->getAlpha();
qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha;
if (overlayAlpha <= 0.0f) {
//return; // don't render the overlay at all.
qDebug() << "would bail early...";
}
Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
_sphereSection->Use(); _sphereSection->Use();
for_each_eye([&](Eye eye) { for_each_eye([&](Eye eye) {
eyeViewport(eye); eyeViewport(eye);
@ -73,13 +87,28 @@ void HmdDisplayPlugin::compositeOverlay() {
} }
void HmdDisplayPlugin::compositePointer() { void HmdDisplayPlugin::compositePointer() {
using namespace oglplus;
//Mouse Pointer //Mouse Pointer
auto compositorHelper = DependencyManager::get<CompositorHelper>(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
// set the alpha
auto overlayAlpha = compositorHelper->getAlpha();
qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha;
if (overlayAlpha <= 0.0f) {
//return; // don't render the overlay at all.
qDebug() << "would bail early...";
}
qDebug() << __FUNCTION__ << "overlayAlpha:" << overlayAlpha;
Uniform<float>(*_program, _alphaUniform).Set(1.0f);
_plane->Use(); _plane->Use();
// Reconstruct the headpose from the eye poses // Reconstruct the headpose from the eye poses
auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f; auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f;
for_each_eye([&](Eye eye) { for_each_eye([&](Eye eye) {
using namespace oglplus;
eyeViewport(eye); eyeViewport(eye);
auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition); auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition);
auto mvp = _eyeProjections[eye] * reticleTransform; auto mvp = _eyeProjections[eye] * reticleTransform;

View file

@ -33,13 +33,14 @@ static const char * SIMPLE_TEXTURED_FS = R"FS(#version 410 core
#pragma line __LINE__ #pragma line __LINE__
uniform sampler2D sampler; uniform sampler2D sampler;
uniform float alpha = 1.0;
in vec2 vTexCoord; in vec2 vTexCoord;
out vec4 FragColor; out vec4 FragColor;
void main() { void main() {
FragColor = texture(sampler, vTexCoord); FragColor = texture(sampler, vTexCoord) * alpha;
} }
)FS"; )FS";