Add support for drawing 3d overlays on the Application Overlay

This commit is contained in:
Ryan Huffman 2014-12-17 16:25:25 -08:00
parent f987f77094
commit 9bd7912f9f
4 changed files with 49 additions and 5 deletions

View file

@ -177,8 +177,10 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
}
glPushMatrix(); {
const float NEAR_CLIP = -10000;
const float FAR_CLIP = 10000;
glLoadIdentity();
gluOrtho2D(0, glWidget->width(), glWidget->height(), 0);
glOrtho(0, glWidget->width(), glWidget->height(), 0, NEAR_CLIP, FAR_CLIP);
renderAudioMeter();
@ -1081,7 +1083,7 @@ void ApplicationOverlay::TexturedHemisphere::buildFramebufferObject() {
delete _framebufferObject;
}
_framebufferObject = new QOpenGLFramebufferObject(size);
_framebufferObject = new QOpenGLFramebufferObject(size, QOpenGLFramebufferObject::Depth);
bindTexture();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

View file

@ -28,7 +28,8 @@ Base3DOverlay::Base3DOverlay() :
_isSolid(DEFAULT_IS_SOLID),
_isDashedLine(DEFAULT_IS_DASHED_LINE),
_ignoreRayIntersection(false),
_drawInFront(false)
_drawInFront(false),
_drawOnApplicationOverlay(false)
{
}
@ -162,6 +163,9 @@ QScriptValue Base3DOverlay::getProperty(const QString& property) {
if (property == "drawInFront") {
return _drawInFront;
}
if (property == "drawOnApplicationOverlay") {
return _drawOnApplicationOverlay;
}
return Overlay::getProperty(property);
}

View file

@ -37,6 +37,7 @@ public:
const glm::quat& getRotation() const { return _rotation; }
bool getIgnoreRayIntersection() const { return _ignoreRayIntersection; }
bool getDrawInFront() const { return _drawInFront; }
bool getDrawOnApplicationOverlay() const { return _drawOnApplicationOverlay; }
// setters
void setPosition(const glm::vec3& position) { _position = position; }
@ -46,6 +47,7 @@ public:
void setRotation(const glm::quat& value) { _rotation = value; }
void setIgnoreRayIntersection(bool value) { _ignoreRayIntersection = value; }
void setDrawInFront(bool value) { _drawInFront = value; }
void setDrawOnApplicationOverlay(bool value) { _drawOnApplicationOverlay = value; }
virtual void setProperties(const QScriptValue& properties);
virtual QScriptValue getProperty(const QString& property);
@ -67,6 +69,7 @@ protected:
bool _isDashedLine;
bool _ignoreRayIntersection;
bool _drawInFront;
bool _drawOnApplicationOverlay;
};
#endif // hifi_Base3DOverlay_h

View file

@ -92,6 +92,17 @@ void Overlays::render2D() {
foreach(Overlay* thisOverlay, _overlays2D) {
thisOverlay->render(&args);
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
foreach(Overlay* thisOverlay, _overlays3D) {
Base3DOverlay* overlay3D = static_cast<Base3DOverlay*>(thisOverlay);
if (overlay3D->getDrawOnApplicationOverlay()) {
thisOverlay->render(&args);
}
}
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
}
void Overlays::render3D(bool drawFront, RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) {
@ -114,7 +125,7 @@ void Overlays::render3D(bool drawFront, RenderArgs::RenderMode renderMode, Rende
foreach(Overlay* thisOverlay, _overlays3D) {
Base3DOverlay* overlay3D = static_cast<Base3DOverlay*>(thisOverlay);
if (overlay3D->getDrawInFront() != drawFront) {
if (overlay3D->getDrawInFront() != drawFront || overlay3D->getDrawOnApplicationOverlay()) {
continue;
}
glPushMatrix();
@ -251,7 +262,27 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
}
QReadLocker lock(&_lock);
QMapIterator<unsigned int, Overlay*> i(_overlays2D);
QMapIterator<unsigned int, Overlay*> i(_overlays3D);
i.toBack();
const float LARGE_NEGATIVE_FLOAT = -9999999;
glm::vec3 origin(pointCopy.x, pointCopy.y, LARGE_NEGATIVE_FLOAT);
glm::vec3 direction(0, 0, 1);
BoxFace thisFace;
float distance;
while (i.hasPrevious()) {
i.previous();
unsigned int thisID = i.key();
Base3DOverlay* thisOverlay = static_cast<Base3DOverlay*>(i.value());
if (thisOverlay->getDrawOnApplicationOverlay() && !thisOverlay->getIgnoreRayIntersection()) {
if (thisOverlay->findRayIntersection(origin, direction, distance, thisFace)) {
return thisID;
}
}
}
i = QMapIterator<unsigned int, Overlay*>(_overlays2D);
i.toBack();
while (i.hasPrevious()) {
i.previous();
@ -262,6 +293,7 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
return thisID;
}
}
return 0; // not found
}
@ -320,6 +352,9 @@ RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray)
i.previous();
unsigned int thisID = i.key();
Base3DOverlay* thisOverlay = static_cast<Base3DOverlay*>(i.value());
if (thisOverlay->getDrawOnApplicationOverlay()) {
continue;
}
if (thisOverlay->getVisible() && !thisOverlay->getIgnoreRayIntersection() && thisOverlay->isLoaded()) {
float thisDistance;
BoxFace thisFace;