Merge pull request #7316 from ZappoMan/toggleOverlay

Repair Toggle Overlays
This commit is contained in:
Seth Alves 2016-03-11 06:45:06 -08:00
commit 510d96af0e
6 changed files with 118 additions and 39 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,39 @@ 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) {
_fadeStarted = usecTimestampNow();
_fadeFailsafeEndValue = endValue;
const int SLIGHT_DELAY = 10;
QTimer::singleShot(FADE_DURATION + SLIGHT_DELAY, [this]{
checkFadeFailsafe();
});
}
void CompositorHelper::checkFadeFailsafe() {
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 +455,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 };
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,33 +409,53 @@ void OpenGLDisplayPlugin::updateFramerate() {
void OpenGLDisplayPlugin::compositeOverlay() { void OpenGLDisplayPlugin::compositeOverlay() {
using namespace oglplus; using namespace oglplus;
// Overlay draw
if (isStereo()) { auto compositorHelper = DependencyManager::get<CompositorHelper>();
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4());
for_each_eye([&](Eye eye) { // check the alpha
eyeViewport(eye); auto overlayAlpha = compositorHelper->getAlpha();
drawUnitQuad(); if (overlayAlpha > 0.0f) {
}); // set the alpha
} else { Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
// Overlay draw // Overlay draw
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4()); if (isStereo()) {
drawUnitQuad(); Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4());
for_each_eye([&](Eye eye) {
eyeViewport(eye);
drawUnitQuad();
});
} else {
// Overlay draw
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4());
drawUnitQuad();
}
} }
Uniform<float>(*_program, _alphaUniform).Set(1.0);
} }
void OpenGLDisplayPlugin::compositePointer() { void OpenGLDisplayPlugin::compositePointer() {
using namespace oglplus; using namespace oglplus;
auto compositorHelper = DependencyManager::get<CompositorHelper>(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
Uniform<glm::mat4>(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4()));
if (isStereo()) { // check the alpha
for_each_eye([&](Eye eye) { auto overlayAlpha = compositorHelper->getAlpha();
eyeViewport(eye); if (overlayAlpha > 0.0f) {
// set the alpha
Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
Uniform<glm::mat4>(*_program, _mvpUniform).Set(compositorHelper->getReticleTransform(glm::mat4()));
if (isStereo()) {
for_each_eye([&](Eye eye) {
eyeViewport(eye);
drawUnitQuad();
});
} else {
drawUnitQuad(); drawUnitQuad();
}); }
} else {
drawUnitQuad();
} }
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4()); Uniform<glm::mat4>(*_program, _mvpUniform).Set(mat4());
Uniform<float>(*_program, _alphaUniform).Set(1.0);
} }
void OpenGLDisplayPlugin::compositeLayers() { void OpenGLDisplayPlugin::compositeLayers() {

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,30 +62,50 @@ void HmdDisplayPlugin::uncustomizeContext() {
void HmdDisplayPlugin::compositeOverlay() { void HmdDisplayPlugin::compositeOverlay() {
using namespace oglplus; using namespace oglplus;
_sphereSection->Use(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
for_each_eye([&](Eye eye) {
eyeViewport(eye); // check the alpha
auto modelView = glm::inverse(_currentRenderEyePoses[eye]); // *glm::translate(mat4(), vec3(0, 0, -1)); auto overlayAlpha = compositorHelper->getAlpha();
auto mvp = _eyeProjections[eye] * modelView; if (overlayAlpha > 0.0f) {
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mvp); // set the alpha
_sphereSection->Draw(); Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
});
_sphereSection->Use();
for_each_eye([&](Eye eye) {
eyeViewport(eye);
auto modelView = glm::inverse(_currentRenderEyePoses[eye]); // *glm::translate(mat4(), vec3(0, 0, -1));
auto mvp = _eyeProjections[eye] * modelView;
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mvp);
_sphereSection->Draw();
});
}
Uniform<float>(*_program, _alphaUniform).Set(1.0);
} }
void HmdDisplayPlugin::compositePointer() { void HmdDisplayPlugin::compositePointer() {
//Mouse Pointer using namespace oglplus;
auto compositorHelper = DependencyManager::get<CompositorHelper>(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
_plane->Use();
// Reconstruct the headpose from the eye poses // check the alpha
auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f; auto overlayAlpha = compositorHelper->getAlpha();
for_each_eye([&](Eye eye) { if (overlayAlpha > 0.0f) {
using namespace oglplus; // set the alpha
eyeViewport(eye); Uniform<float>(*_program, _alphaUniform).Set(overlayAlpha);
auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition);
auto mvp = _eyeProjections[eye] * reticleTransform; // Mouse pointer
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mvp); _plane->Use();
_plane->Draw(); // Reconstruct the headpose from the eye poses
}); auto headPosition = (vec3(_currentRenderEyePoses[Left][3]) + vec3(_currentRenderEyePoses[Right][3])) / 2.0f;
for_each_eye([&](Eye eye) {
eyeViewport(eye);
auto reticleTransform = compositorHelper->getReticleTransform(_currentRenderEyePoses[eye], headPosition);
auto mvp = _eyeProjections[eye] * reticleTransform;
Uniform<glm::mat4>(*_program, _mvpUniform).Set(mvp);
_plane->Draw();
});
}
Uniform<float>(*_program, _alphaUniform).Set(1.0);
} }
void HmdDisplayPlugin::internalPresent() { void HmdDisplayPlugin::internalPresent() {

View file

@ -33,6 +33,7 @@ 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;
@ -40,6 +41,7 @@ out vec4 FragColor;
void main() { void main() {
FragColor = texture(sampler, vTexCoord); FragColor = texture(sampler, vTexCoord);
FragColor.a *= alpha;
} }
)FS"; )FS";