From d4f66a4a3d213608db71e2aec7c9947f9323ad77 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 27 May 2014 11:19:45 -0700 Subject: [PATCH 1/6] Added OverlayRenderer class and moved displayOverlay from Application to OverlayRenderer. --- interface/src/Application.cpp | 193 +-------------- interface/src/Application.h | 17 +- interface/src/renderer/GlowEffect.cpp | 3 +- interface/src/ui/overlays/OverlayRenderer.cpp | 231 ++++++++++++++++++ interface/src/ui/overlays/OverlayRenderer.h | 28 +++ 5 files changed, 281 insertions(+), 191 deletions(-) create mode 100644 interface/src/ui/overlays/OverlayRenderer.cpp create mode 100644 interface/src/ui/overlays/OverlayRenderer.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 07309fab85..28a8d83906 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -102,15 +102,6 @@ const int STARTUP_JITTER_SAMPLES = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL / 2 // Startup optimistically with small jitter buffer that // will start playback on the second received audio packet. -const int MIRROR_VIEW_TOP_PADDING = 5; -const int MIRROR_VIEW_LEFT_PADDING = 10; -const int MIRROR_VIEW_WIDTH = 265; -const int MIRROR_VIEW_HEIGHT = 215; -const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; -const float MIRROR_REARVIEW_DISTANCE = 0.65f; -const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; -const float MIRROR_FIELD_OF_VIEW = 30.0f; - const QString CHECK_VERSION_URL = "https://highfidelity.io/latestVersion.xml"; const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion"; @@ -172,7 +163,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _nodeBoundsDisplay(this), _previousScriptLocation(), _runningScriptsWidget(new RunningScriptsWidget(_window)), - _runningScriptsWidgetWasVisible(false) + _runningScriptsWidgetWasVisible(false), + _overlayRenderer() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -627,10 +619,12 @@ void Application::paintGL() { if (OculusManager::isConnected()) { OculusManager::display(whichCamera); + } else if (TV3DManager::isConnected()) { _glowEffect.prepare(); TV3DManager::display(whichCamera); _glowEffect.render(); + } else { _glowEffect.prepare(); @@ -649,7 +643,7 @@ void Application::paintGL() { _rearMirrorTools->render(true); } - displayOverlay(); + _overlayRenderer.displayOverlay(&_overlays); } _frameCount++; @@ -2578,183 +2572,6 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); } -const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; - -void Application::displayOverlay() { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displayOverlay()"); - - // Render 2D overlay: I/O level bar graphs and text - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - glLoadIdentity(); - gluOrtho2D(0, _glWidget->width(), _glWidget->height(), 0); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - - // Display a single screen-size quad to create an alpha blended 'collision' flash - if (_audio.getCollisionFlashesScreen()) { - float collisionSoundMagnitude = _audio.getCollisionSoundMagnitude(); - const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; - if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { - renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude()); - } - } - - // Audio VU Meter and Mute Icon - const int MUTE_ICON_SIZE = 24; - const int AUDIO_METER_INSET = 2; - const int MUTE_ICON_PADDING = 10; - const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - AUDIO_METER_INSET - MUTE_ICON_PADDING; - const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 * AUDIO_METER_INSET; - const int AUDIO_METER_HEIGHT = 8; - const int AUDIO_METER_GAP = 5; - const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_INSET + AUDIO_METER_GAP; - - int audioMeterY; - if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { - audioMeterY = MIRROR_VIEW_HEIGHT + AUDIO_METER_GAP + MUTE_ICON_PADDING; - } else { - audioMeterY = AUDIO_METER_GAP + MUTE_ICON_PADDING; - } - - const float AUDIO_METER_BLUE[] = {0.0, 0.0, 1.0}; - const float AUDIO_METER_GREEN[] = {0.0, 1.0, 0.0}; - const float AUDIO_METER_RED[] = {1.0, 0.0, 0.0}; - const float AUDIO_GREEN_START = 0.25 * AUDIO_METER_SCALE_WIDTH; - const float AUDIO_RED_START = 0.80 * AUDIO_METER_SCALE_WIDTH; - const float CLIPPING_INDICATOR_TIME = 1.0f; - const float AUDIO_METER_AVERAGING = 0.5; - const float LOG2 = log(2.f); - const float METER_LOUDNESS_SCALE = 2.8f / 5.f; - const float LOG2_LOUDNESS_FLOOR = 11.f; - float audioLevel = 0.f; - float loudness = _audio.getLastInputLoudness() + 1.f; - - _trailingAudioLoudness = AUDIO_METER_AVERAGING * _trailingAudioLoudness + (1.f - AUDIO_METER_AVERAGING) * loudness; - float log2loudness = log(_trailingAudioLoudness) / LOG2; - - if (log2loudness <= LOG2_LOUDNESS_FLOOR) { - audioLevel = (log2loudness / LOG2_LOUDNESS_FLOOR) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH; - } else { - audioLevel = (log2loudness - (LOG2_LOUDNESS_FLOOR - 1.f)) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH; - } - if (audioLevel > AUDIO_METER_SCALE_WIDTH) { - audioLevel = AUDIO_METER_SCALE_WIDTH; - } - bool isClipping = ((_audio.getTimeSinceLastClip() > 0.f) && (_audio.getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)); - - if ((_audio.getTimeSinceLastClip() > 0.f) && (_audio.getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) { - const float MAX_MAGNITUDE = 0.7f; - float magnitude = MAX_MAGNITUDE * (1 - _audio.getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME); - renderCollisionOverlay(_glWidget->width(), _glWidget->height(), magnitude, 1.0f); - } - - _audio.renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, - audioMeterY, - Menu::getInstance()->isOptionChecked(MenuOption::Mirror)); - - _audio.renderScope(_glWidget->width(), _glWidget->height()); - - glBegin(GL_QUADS); - if (isClipping) { - glColor3f(1, 0, 0); - } else { - glColor3f(0.475f, 0.475f, 0.475f); - } - - audioMeterY += AUDIO_METER_HEIGHT; - - glColor3f(0, 0, 0); - // Draw audio meter background Quad - glVertex2i(AUDIO_METER_X, audioMeterY); - glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY); - glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY + AUDIO_METER_HEIGHT); - glVertex2i(AUDIO_METER_X, audioMeterY + AUDIO_METER_HEIGHT); - - - if (audioLevel > AUDIO_RED_START) { - if (!isClipping) { - glColor3fv(AUDIO_METER_RED); - } else { - glColor3f(1, 1, 1); - } - // Draw Red Quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - audioLevel = AUDIO_RED_START; - } - if (audioLevel > AUDIO_GREEN_START) { - if (!isClipping) { - glColor3fv(AUDIO_METER_GREEN); - } else { - glColor3f(1, 1, 1); - } - // Draw Green Quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - audioLevel = AUDIO_GREEN_START; - } - // Draw Blue Quad - if (!isClipping) { - glColor3fv(AUDIO_METER_BLUE); - } else { - glColor3f(1, 1, 1); - } - // Draw Blue (low level) quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glEnd(); - - - if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - _myAvatar->renderHeadMouse(_glWidget->width(), _glWidget->height()); - } - - // Display stats and log text onscreen - glLineWidth(1.0f); - glPointSize(1.0f); - - if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { - // let's set horizontal offset to give stats some margin to mirror - int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2; - int voxelPacketsToProcess = _voxelProcessor.packetsToProcessCount(); - // Onscreen text about position, servers, etc - Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, _fps, _packetsPerSecond, _bytesPerSecond, voxelPacketsToProcess); - // Bandwidth meter - if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) { - Stats::drawBackground(0x33333399, _glWidget->width() - 296, _glWidget->height() - 68, 296, 68); - _bandwidthMeter.render(_glWidget->width(), _glWidget->height()); - } - } - - // Show on-screen msec timer - if (Menu::getInstance()->isOptionChecked(MenuOption::FrameTimer)) { - char frameTimer[10]; - quint64 mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); - sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000)); - int timerBottom = - (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && - Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) - ? 80 : 20; - drawText(_glWidget->width() - 100, _glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); - } - _nodeBoundsDisplay.drawOverlay(); - - // give external parties a change to hook in - emit renderingOverlay(); - - _overlays.render2D(); - - glPopMatrix(); -} - glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { float horizontalScale = _glWidget->width() / 2.0f; float verticalScale = _glWidget->height() / 2.0f; diff --git a/interface/src/Application.h b/interface/src/Application.h index 1968ef4fee..4004cfc93a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -82,6 +82,7 @@ #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" #include "ui/overlays/Overlays.h" +#include "ui/overlays/OverlayRenderer.h" #include "ui/RunningScriptsWidget.h" #include "voxels/VoxelFade.h" #include "voxels/VoxelHideShowThread.h" @@ -115,6 +116,15 @@ static const QString CUSTOM_URL_SCHEME = "hifi:"; static const float BILLBOARD_FIELD_OF_VIEW = 30.0f; // degrees static const float BILLBOARD_DISTANCE = 5.0f; // meters +static const int MIRROR_VIEW_TOP_PADDING = 5; +static const int MIRROR_VIEW_LEFT_PADDING = 10; +static const int MIRROR_VIEW_WIDTH = 265; +static const int MIRROR_VIEW_HEIGHT = 215; +static const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; +static const float MIRROR_REARVIEW_DISTANCE = 0.65f; +static const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f; +static const float MIRROR_FIELD_OF_VIEW = 30.0f; + class Application : public QApplication { Q_OBJECT @@ -181,6 +191,7 @@ public: ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } VoxelSystem* getVoxels() { return &_voxels; } VoxelTree* getVoxelTree() { return _voxels.getTree(); } + const VoxelPacketProcessor& getVoxelPacketProcessor() const { return _voxelProcessor; } ParticleTreeRenderer* getParticles() { return &_particles; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; } ModelTreeRenderer* getModels() { return &_models; } @@ -204,6 +215,10 @@ public: BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } QUndoStack* getUndoStack() { return &_undoStack; } + float getFps() const { return _fps; } + float getPacketsPerSecond() const { return _packetsPerSecond; } + float getBytesPerSecond() const { return _bytesPerSecond; } + /// if you need to access the application settings, use lockSettings()/unlockSettings() QSettings* lockSettings() { _settingsMutex.lock(); return _settings; } void unlockSettings() { _settingsMutex.unlock(); } @@ -375,7 +390,6 @@ private: glm::vec3 getSunDirection(); void updateShadowMap(); - void displayOverlay(); void renderRearViewMirror(const QRect& region, bool billboard = false); void renderViewFrustum(ViewFrustum& viewFrustum); @@ -549,6 +563,7 @@ private: TouchEvent _lastTouchEvent; Overlays _overlays; + OverlayRenderer _overlayRenderer; AudioReflector _audioReflector; RunningScriptsWidget* _runningScriptsWidget; diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index b52e8d8531..1eceb71752 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -139,8 +139,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { if (_isEmpty && _renderMode != DIFFUSE_ADD_MODE) { // copy the primary to the screen if (QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { - QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); - + QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); } else { maybeBind(destFBO); glEnable(GL_TEXTURE_2D); diff --git a/interface/src/ui/overlays/OverlayRenderer.cpp b/interface/src/ui/overlays/OverlayRenderer.cpp new file mode 100644 index 0000000000..ba901960e9 --- /dev/null +++ b/interface/src/ui/overlays/OverlayRenderer.cpp @@ -0,0 +1,231 @@ +// +// OverlayRenderer.cpp +// interface/src/ui/overlays +// +// Created by Benjamin Arnold on 5/27/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "OverlayRenderer.h" + + +#include "InterfaceVersion.h" +#include "Menu.h" +#include "ModelUploader.h" +#include "Util.h" +#include "devices/OculusManager.h" +#include "devices/TV3DManager.h" +#include "renderer/ProgramObject.h" + +#include "scripting/AudioDeviceScriptingInterface.h" +#include "scripting/ClipboardScriptingInterface.h" +#include "scripting/MenuScriptingInterface.h" +#include "scripting/SettingsScriptingInterface.h" +#include "scripting/WindowScriptingInterface.h" +#include "scripting/LocationScriptingInterface.h" + +#include "ui/InfoView.h" +#include "ui/OAuthWebViewHandler.h" +#include "ui/Snapshot.h" +#include "ui/Stats.h" +#include "ui/TextRenderer.h" + + + +OverlayRenderer::OverlayRenderer() { + +} + +OverlayRenderer::~OverlayRenderer() { + +} + +const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; + +void OverlayRenderer::displayOverlay(Overlays* overlays) { + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "OverlayRenderer::displayOverlay()"); + + Application* application = Application::getInstance(); + + QGLWidget* glWidget = application->getGLWidget(); + MyAvatar* myAvatar = application->getAvatar(); + Audio* audio = application->getAudio(); + const VoxelPacketProcessor& voxelPacketProcessor = application->getVoxelPacketProcessor(); + BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); + NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); + // Render 2D overlay: I/O level bar graphs and text + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + // Display a single screen-size quad to create an alpha blended 'collision' flash + if (audio->getCollisionFlashesScreen()) { + float collisionSoundMagnitude = audio->getCollisionSoundMagnitude(); + const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; + if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { + renderCollisionOverlay(glWidget->width(), glWidget->height(), audio->getCollisionSoundMagnitude()); + } + } + + // Audio VU Meter and Mute Icon + const int MUTE_ICON_SIZE = 24; + const int AUDIO_METER_INSET = 2; + const int MUTE_ICON_PADDING = 10; + const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - AUDIO_METER_INSET - MUTE_ICON_PADDING; + const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 * AUDIO_METER_INSET; + const int AUDIO_METER_HEIGHT = 8; + const int AUDIO_METER_GAP = 5; + const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_INSET + AUDIO_METER_GAP; + + int audioMeterY; + if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + audioMeterY = MIRROR_VIEW_HEIGHT + AUDIO_METER_GAP + MUTE_ICON_PADDING; + } else { + audioMeterY = AUDIO_METER_GAP + MUTE_ICON_PADDING; + } + + const float AUDIO_METER_BLUE[] = { 0.0, 0.0, 1.0 }; + const float AUDIO_METER_GREEN[] = { 0.0, 1.0, 0.0 }; + const float AUDIO_METER_RED[] = { 1.0, 0.0, 0.0 }; + const float AUDIO_GREEN_START = 0.25 * AUDIO_METER_SCALE_WIDTH; + const float AUDIO_RED_START = 0.80 * AUDIO_METER_SCALE_WIDTH; + const float CLIPPING_INDICATOR_TIME = 1.0f; + const float AUDIO_METER_AVERAGING = 0.5; + const float LOG2 = log(2.f); + const float METER_LOUDNESS_SCALE = 2.8f / 5.f; + const float LOG2_LOUDNESS_FLOOR = 11.f; + float audioLevel = 0.f; + float loudness = audio->getLastInputLoudness() + 1.f; + + _trailingAudioLoudness = AUDIO_METER_AVERAGING * _trailingAudioLoudness + (1.f - AUDIO_METER_AVERAGING) * loudness; + float log2loudness = log(_trailingAudioLoudness) / LOG2; + + if (log2loudness <= LOG2_LOUDNESS_FLOOR) { + audioLevel = (log2loudness / LOG2_LOUDNESS_FLOOR) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH; + } else { + audioLevel = (log2loudness - (LOG2_LOUDNESS_FLOOR - 1.f)) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH; + } + if (audioLevel > AUDIO_METER_SCALE_WIDTH) { + audioLevel = AUDIO_METER_SCALE_WIDTH; + } + bool isClipping = ((audio->getTimeSinceLastClip() > 0.f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)); + + if ((audio->getTimeSinceLastClip() > 0.f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) { + const float MAX_MAGNITUDE = 0.7f; + float magnitude = MAX_MAGNITUDE * (1 - audio->getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME); + renderCollisionOverlay(glWidget->width(), glWidget->height(), magnitude, 1.0f); + } + + audio->renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, + audioMeterY, + Menu::getInstance()->isOptionChecked(MenuOption::Mirror)); + + audio->renderScope(glWidget->width(), glWidget->height()); + + glBegin(GL_QUADS); + if (isClipping) { + glColor3f(1, 0, 0); + } else { + glColor3f(0.475f, 0.475f, 0.475f); + } + + audioMeterY += AUDIO_METER_HEIGHT; + + glColor3f(0, 0, 0); + // Draw audio meter background Quad + glVertex2i(AUDIO_METER_X, audioMeterY); + glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY); + glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY + AUDIO_METER_HEIGHT); + glVertex2i(AUDIO_METER_X, audioMeterY + AUDIO_METER_HEIGHT); + + + if (audioLevel > AUDIO_RED_START) { + if (!isClipping) { + glColor3fv(AUDIO_METER_RED); + } else { + glColor3f(1, 1, 1); + } + // Draw Red Quad + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + audioLevel = AUDIO_RED_START; + } + if (audioLevel > AUDIO_GREEN_START) { + if (!isClipping) { + glColor3fv(AUDIO_METER_GREEN); + } else { + glColor3f(1, 1, 1); + } + // Draw Green Quad + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + audioLevel = AUDIO_GREEN_START; + } + // Draw Blue Quad + if (!isClipping) { + glColor3fv(AUDIO_METER_BLUE); + } else { + glColor3f(1, 1, 1); + } + // Draw Blue (low level) quad + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + glEnd(); + + + if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { + myAvatar->renderHeadMouse(glWidget->width(), glWidget->height()); + } + + // Display stats and log text onscreen + glLineWidth(1.0f); + glPointSize(1.0f); + + if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { + // let's set horizontal offset to give stats some margin to mirror + int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2; + int voxelPacketsToProcess = voxelPacketProcessor.packetsToProcessCount(); + // Onscreen text about position, servers, etc + Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); + // Bandwidth meter + if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) { + Stats::drawBackground(0x33333399, glWidget->width() - 296, glWidget->height() - 68, 296, 68); + bandwidthMeter->render(glWidget->width(), glWidget->height()); + } + } + + // Show on-screen msec timer + if (Menu::getInstance()->isOptionChecked(MenuOption::FrameTimer)) { + char frameTimer[10]; + quint64 mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); + sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000)); + int timerBottom = + (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && + Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) + ? 80 : 20; + drawText(glWidget->width() - 100, glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); + } + nodeBoundsDisplay.drawOverlay(); + + // give external parties a change to hook in + emit application->renderingOverlay(); + + overlays->render2D(); + + glPopMatrix(); +} \ No newline at end of file diff --git a/interface/src/ui/overlays/OverlayRenderer.h b/interface/src/ui/overlays/OverlayRenderer.h new file mode 100644 index 0000000000..aa9b5685ab --- /dev/null +++ b/interface/src/ui/overlays/OverlayRenderer.h @@ -0,0 +1,28 @@ +// +// OverlayRenderer.h +// interface/src/ui/overlays +// +// Created by Benjamin Arnold on 5/27/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_OverlayRenderer_h +#define hifi_OverlayRenderer_h + +// Handles the drawing of the overlays to the scree +class OverlayRenderer { +public: + + OverlayRenderer(); + ~OverlayRenderer(); + void displayOverlay(class Overlays* overlays); + +private: + + float _trailingAudioLoudness; +}; + +#endif // hifi_OverlayRenderer_h \ No newline at end of file From 75580cfd0fc209d572be7eba4f7cf46abbb6b3ae Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 27 May 2014 16:13:56 -0700 Subject: [PATCH 2/6] Made Overlay appear as flat image in front of camera in Oculus Rift. It needs to be a curved surface instead. --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 3 + interface/src/devices/OculusManager.cpp | 10 +- interface/src/ui/overlays/OverlayRenderer.cpp | 171 +++++++++++++++--- interface/src/ui/overlays/OverlayRenderer.h | 12 +- 5 files changed, 166 insertions(+), 32 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9e0cb0e61b..c9c09b7a8f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -643,7 +643,7 @@ void Application::paintGL() { _rearMirrorTools->render(true); } - _overlayRenderer.displayOverlay(&_overlays); + _overlayRenderer.renderOverlay(); } _frameCount++; diff --git a/interface/src/Application.h b/interface/src/Application.h index 628fc24627..aef67bd6e7 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -214,10 +214,13 @@ public: JoystickManager* getJoystickManager() { return &_joystickManager; } BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } QUndoStack* getUndoStack() { return &_undoStack; } + OverlayRenderer& getOverlayRenderer() { return _overlayRenderer; } + Overlays& getOverlays() { return _overlays; } float getFps() const { return _fps; } float getPacketsPerSecond() const { return _packetsPerSecond; } float getBytesPerSecond() const { return _bytesPerSecond; } + const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } /// if you need to access the application settings, use lockSettings()/unlockSettings() QSettings* lockSettings() { _settingsMutex.lock(); return _settings; } diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 854b19236d..f7a61c2034 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -81,7 +81,11 @@ void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenH void OculusManager::display(Camera& whichCamera) { #ifdef HAVE_LIBOVR - Application::getInstance()->getGlowEffect()->prepare(); + OverlayRenderer& overlayRenderer = Application::getInstance()->getOverlayRenderer(); + // We only need to render the overlays to a texture once, then we just render the texture as a quad + overlayRenderer.renderOverlay(true); + + Application::getInstance()->getGlowEffect()->prepare(); // render the left eye view to the left side of the screen const StereoEyeParams& leftEyeParams = _stereoConfig.GetEyeRenderParams(StereoEye_Left); @@ -100,6 +104,8 @@ void OculusManager::display(Camera& whichCamera) { Application::getInstance()->displaySide(whichCamera); + overlayRenderer.displayOverlayTextureOculus(whichCamera); + // and the right eye to the right side const StereoEyeParams& rightEyeParams = _stereoConfig.GetEyeRenderParams(StereoEye_Right); glMatrixMode(GL_PROJECTION); @@ -115,6 +121,8 @@ void OculusManager::display(Camera& whichCamera) { Application::getInstance()->displaySide(whichCamera); + overlayRenderer.displayOverlayTextureOculus(whichCamera); + glPopMatrix(); // restore our normal viewport diff --git a/interface/src/ui/overlays/OverlayRenderer.cpp b/interface/src/ui/overlays/OverlayRenderer.cpp index ba901960e9..199b755c42 100644 --- a/interface/src/ui/overlays/OverlayRenderer.cpp +++ b/interface/src/ui/overlays/OverlayRenderer.cpp @@ -9,56 +9,50 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "InterfaceConfig.h" + +#include #include +#include "Application.h" #include "OverlayRenderer.h" - -#include "InterfaceVersion.h" -#include "Menu.h" -#include "ModelUploader.h" -#include "Util.h" -#include "devices/OculusManager.h" -#include "devices/TV3DManager.h" -#include "renderer/ProgramObject.h" - -#include "scripting/AudioDeviceScriptingInterface.h" -#include "scripting/ClipboardScriptingInterface.h" -#include "scripting/MenuScriptingInterface.h" -#include "scripting/SettingsScriptingInterface.h" -#include "scripting/WindowScriptingInterface.h" -#include "scripting/LocationScriptingInterface.h" - -#include "ui/InfoView.h" -#include "ui/OAuthWebViewHandler.h" -#include "ui/Snapshot.h" #include "ui/Stats.h" -#include "ui/TextRenderer.h" - - -OverlayRenderer::OverlayRenderer() { +OverlayRenderer::OverlayRenderer() : _framebufferObject(NULL) { } OverlayRenderer::~OverlayRenderer() { - + if (_framebufferObject != NULL) { + delete _framebufferObject; + } } const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; -void OverlayRenderer::displayOverlay(Overlays* overlays) { +// Renders the overlays either to a texture or to the screen +void OverlayRenderer::renderOverlay(bool renderToTexture) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "OverlayRenderer::displayOverlay()"); Application* application = Application::getInstance(); + Overlays& overlays = application->getOverlays(); QGLWidget* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); Audio* audio = application->getAudio(); const VoxelPacketProcessor& voxelPacketProcessor = application->getVoxelPacketProcessor(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); - // Render 2D overlay: I/O level bar graphs and text + + if (renderToTexture) { + getFramebufferObject()->bind(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // Render 2D overlay: I/O level bar graphs and text glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -147,7 +141,6 @@ void OverlayRenderer::displayOverlay(Overlays* overlays) { glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY + AUDIO_METER_HEIGHT); glVertex2i(AUDIO_METER_X, audioMeterY + AUDIO_METER_HEIGHT); - if (audioLevel > AUDIO_RED_START) { if (!isClipping) { glColor3fv(AUDIO_METER_RED); @@ -225,7 +218,127 @@ void OverlayRenderer::displayOverlay(Overlays* overlays) { // give external parties a change to hook in emit application->renderingOverlay(); - overlays->render2D(); + overlays.render2D(); glPopMatrix(); -} \ No newline at end of file + + glMatrixMode(GL_MODELVIEW); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); + // glDisable(GL_BLEND); + + + if (renderToTexture) { + getFramebufferObject()->release(); + } +} + +// Draws the FBO texture for the screen +void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) +{ + Application* application = Application::getInstance(); + QGLWidget* glWidget = application->getGLWidget(); + + glEnable(GL_TEXTURE_2D); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture()); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(0, glWidget->height()); + glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height()); + glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0); + glTexCoord2f(0, 1); glVertex2i(0, 0); + glEnd(); + + glPopMatrix(); + glDisable(GL_TEXTURE_2D); +} + +// Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane. +void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) +{ + + Application* application = Application::getInstance(); + + QGLWidget* glWidget = application->getGLWidget(); + MyAvatar* myAvatar = application->getAvatar(); + const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation(); + + const float overlayFov = whichCamera.getFieldOfView() * PI / 180.0f; + const float overlayDistance = 1; + const float overlayAspectRatio = glWidget->width() / (float)glWidget->height(); + const float overlayHeight = overlayDistance * tan(overlayFov); + const float overlayWidth = overlayHeight * overlayAspectRatio; + const float halfOverlayWidth = overlayWidth / 2; + const float halfOverlayHeight = overlayHeight / 2; + + glActiveTexture(GL_TEXTURE0); + + glDepthMask(GL_FALSE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBindTexture(GL_TEXTURE_2D, getFramebufferObject()->texture()); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + glLoadIdentity(); + //transform to world space + glm::quat rotation = whichCamera.getRotation(); + glm::vec3 axis2 = glm::axis(rotation); + glRotatef(-glm::degrees(glm::angle(rotation)), axis2.x, axis2.y, axis2.z); + glTranslatef(viewMatrixTranslation.x, viewMatrixTranslation.y, viewMatrixTranslation.z); + + glm::vec3 pos = whichCamera.getPosition(); + glm::quat rot = myAvatar->getOrientation(); + glm::vec3 axis = glm::axis(rot); + pos += rot * glm::vec3(0.0, 0.0, -overlayDistance); + + glTranslatef(pos.x, pos.y, pos.z); + glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z); + glDisable(GL_DEPTH_TEST); + + glBegin(GL_QUADS); + glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0); + glTexCoord2f(0, 0); glVertex3f(halfOverlayWidth, halfOverlayHeight, 0); + glTexCoord2f(0, 1); glVertex3f(halfOverlayWidth, -halfOverlayHeight, 0); + glTexCoord2f(1, 1); glVertex3f(-halfOverlayWidth, -halfOverlayHeight, 0); + glEnd(); + + glPopMatrix(); + + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); + glEnable(GL_LIGHTING); + +} + +QOpenGLFramebufferObject* OverlayRenderer::getFramebufferObject() { + if (!_framebufferObject) { + _framebufferObject = new QOpenGLFramebufferObject(Application::getInstance()->getGLWidget()->size()); + + glBindTexture(GL_TEXTURE_2D, _framebufferObject->texture()); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); + } + return _framebufferObject; +} + diff --git a/interface/src/ui/overlays/OverlayRenderer.h b/interface/src/ui/overlays/OverlayRenderer.h index aa9b5685ab..b09626fbfa 100644 --- a/interface/src/ui/overlays/OverlayRenderer.h +++ b/interface/src/ui/overlays/OverlayRenderer.h @@ -12,16 +12,26 @@ #ifndef hifi_OverlayRenderer_h #define hifi_OverlayRenderer_h +class Overlays; +class QOpenGLFramebufferObject; + // Handles the drawing of the overlays to the scree class OverlayRenderer { public: OverlayRenderer(); ~OverlayRenderer(); - void displayOverlay(class Overlays* overlays); + + void renderOverlay(bool renderToTexture = false); + void displayOverlayTexture(Camera& whichCamera); + void displayOverlayTextureOculus(Camera& whichCamera); + + // Getters + QOpenGLFramebufferObject* getFramebufferObject(); private: + QOpenGLFramebufferObject* _framebufferObject; float _trailingAudioLoudness; }; From 2570c552411c6bca7b22f99d5e5e68fa959a40ec Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 27 May 2014 16:21:34 -0700 Subject: [PATCH 3/6] Touched up comments --- interface/src/ui/overlays/OverlayRenderer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/overlays/OverlayRenderer.cpp b/interface/src/ui/overlays/OverlayRenderer.cpp index 199b755c42..6dc095c3f9 100644 --- a/interface/src/ui/overlays/OverlayRenderer.cpp +++ b/interface/src/ui/overlays/OverlayRenderer.cpp @@ -226,7 +226,6 @@ void OverlayRenderer::renderOverlay(bool renderToTexture) { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); - // glDisable(GL_BLEND); if (renderToTexture) { @@ -273,6 +272,7 @@ void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) MyAvatar* myAvatar = application->getAvatar(); const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation(); + // Calculates the world space width and height of the texture based on a desired FOV const float overlayFov = whichCamera.getFieldOfView() * PI / 180.0f; const float overlayDistance = 1; const float overlayAspectRatio = glWidget->width() / (float)glWidget->height(); @@ -296,12 +296,13 @@ void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) glPushMatrix(); glLoadIdentity(); - //transform to world space + // Transform to world space glm::quat rotation = whichCamera.getRotation(); glm::vec3 axis2 = glm::axis(rotation); glRotatef(-glm::degrees(glm::angle(rotation)), axis2.x, axis2.y, axis2.z); glTranslatef(viewMatrixTranslation.x, viewMatrixTranslation.y, viewMatrixTranslation.z); + // Translate to the front of the camera glm::vec3 pos = whichCamera.getPosition(); glm::quat rot = myAvatar->getOrientation(); glm::vec3 axis = glm::axis(rot); @@ -309,7 +310,6 @@ void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) glTranslatef(pos.x, pos.y, pos.z); glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z); - glDisable(GL_DEPTH_TEST); glBegin(GL_QUADS); glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0); From 216a73cf60a9386e5c146565ce5c2b78ed917b5c Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 27 May 2014 16:40:51 -0700 Subject: [PATCH 4/6] Fixed coding standard issues --- interface/src/ui/overlays/OverlayRenderer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/src/ui/overlays/OverlayRenderer.cpp b/interface/src/ui/overlays/OverlayRenderer.cpp index 6dc095c3f9..c8fdc4972f 100644 --- a/interface/src/ui/overlays/OverlayRenderer.cpp +++ b/interface/src/ui/overlays/OverlayRenderer.cpp @@ -234,8 +234,8 @@ void OverlayRenderer::renderOverlay(bool renderToTexture) { } // Draws the FBO texture for the screen -void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) -{ +void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) { + Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -263,8 +263,7 @@ void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) } // Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane. -void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) -{ +void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) { Application* application = Application::getInstance(); From 21fb18a92ee982fd7b9507e6a89f146692fce794 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Wed, 28 May 2014 10:24:50 -0700 Subject: [PATCH 5/6] Fixed SkeletonModel compilation errors with PrioVR --- interface/src/devices/PrioVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index 3e19f1800e..ab29fc004b 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -79,7 +79,7 @@ static void setPalm(float deltaTime, int index) { glm::vec3 position; glm::quat rotation; - Model* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel(); + SkeletonModel* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel(); int jointIndex; glm::quat inverseRotation = glm::inverse(Application::getInstance()->getAvatar()->getOrientation()); if (index == LEFT_HAND_INDEX) { From ebfb11c1ce601c15499d5178ea30fdb8ba89ad5a Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Wed, 28 May 2014 10:46:46 -0700 Subject: [PATCH 6/6] Renamed OverlayRenderer to ApplicationOverlay and moved it up a directory --- interface/src/Application.cpp | 4 +- interface/src/Application.h | 6 +-- interface/src/devices/OculusManager.cpp | 8 ++-- ...layRenderer.cpp => ApplicationOverlay.cpp} | 40 +++++++++---------- ...OverlayRenderer.h => ApplicationOverlay.h} | 16 ++++---- 5 files changed, 37 insertions(+), 37 deletions(-) rename interface/src/ui/{overlays/OverlayRenderer.cpp => ApplicationOverlay.cpp} (92%) rename interface/src/ui/{overlays/OverlayRenderer.h => ApplicationOverlay.h} (71%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e8fc1b0d34..fac0ef154f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -165,7 +165,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _runningScriptsWidget(new RunningScriptsWidget(_window)), _runningScriptsWidgetWasVisible(false), _trayIcon(new QSystemTrayIcon(_window)), - _overlayRenderer() + _applicationOverlay() { // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -646,7 +646,7 @@ void Application::paintGL() { _rearMirrorTools->render(true); } - _overlayRenderer.renderOverlay(); + _applicationOverlay.renderOverlay(); } _frameCount++; diff --git a/interface/src/Application.h b/interface/src/Application.h index 8b40ad522e..0065944611 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -83,7 +83,7 @@ #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" #include "ui/overlays/Overlays.h" -#include "ui/overlays/OverlayRenderer.h" +#include "ui/ApplicationOverlay.h" #include "ui/RunningScriptsWidget.h" #include "voxels/VoxelFade.h" #include "voxels/VoxelHideShowThread.h" @@ -216,7 +216,7 @@ public: BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } QUndoStack* getUndoStack() { return &_undoStack; } QSystemTrayIcon* getTrayIcon() { return _trayIcon; } - OverlayRenderer& getOverlayRenderer() { return _overlayRenderer; } + ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; } Overlays& getOverlays() { return _overlays; } float getFps() const { return _fps; } @@ -569,7 +569,7 @@ private: TouchEvent _lastTouchEvent; Overlays _overlays; - OverlayRenderer _overlayRenderer; + ApplicationOverlay _applicationOverlay; AudioReflector _audioReflector; RunningScriptsWidget* _runningScriptsWidget; diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index f7a61c2034..8f71d38bdb 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -81,9 +81,9 @@ void OculusManager::configureCamera(Camera& camera, int screenWidth, int screenH void OculusManager::display(Camera& whichCamera) { #ifdef HAVE_LIBOVR - OverlayRenderer& overlayRenderer = Application::getInstance()->getOverlayRenderer(); + ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); // We only need to render the overlays to a texture once, then we just render the texture as a quad - overlayRenderer.renderOverlay(true); + applicationOverlay.renderOverlay(true); Application::getInstance()->getGlowEffect()->prepare(); @@ -104,7 +104,7 @@ void OculusManager::display(Camera& whichCamera) { Application::getInstance()->displaySide(whichCamera); - overlayRenderer.displayOverlayTextureOculus(whichCamera); + applicationOverlay.displayOverlayTextureOculus(whichCamera); // and the right eye to the right side const StereoEyeParams& rightEyeParams = _stereoConfig.GetEyeRenderParams(StereoEye_Right); @@ -121,7 +121,7 @@ void OculusManager::display(Camera& whichCamera) { Application::getInstance()->displaySide(whichCamera); - overlayRenderer.displayOverlayTextureOculus(whichCamera); + applicationOverlay.displayOverlayTextureOculus(whichCamera); glPopMatrix(); diff --git a/interface/src/ui/overlays/OverlayRenderer.cpp b/interface/src/ui/ApplicationOverlay.cpp similarity index 92% rename from interface/src/ui/overlays/OverlayRenderer.cpp rename to interface/src/ui/ApplicationOverlay.cpp index c8fdc4972f..740b310ff2 100644 --- a/interface/src/ui/overlays/OverlayRenderer.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -1,5 +1,5 @@ // -// OverlayRenderer.cpp +// ApplicationOverlay.cpp // interface/src/ui/overlays // // Created by Benjamin Arnold on 5/27/14. @@ -15,15 +15,15 @@ #include #include "Application.h" -#include "OverlayRenderer.h" +#include "ApplicationOverlay.h" #include "ui/Stats.h" -OverlayRenderer::OverlayRenderer() : _framebufferObject(NULL) { +ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL) { } -OverlayRenderer::~OverlayRenderer() { +ApplicationOverlay::~ApplicationOverlay() { if (_framebufferObject != NULL) { delete _framebufferObject; } @@ -32,8 +32,8 @@ OverlayRenderer::~OverlayRenderer() { const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; // Renders the overlays either to a texture or to the screen -void OverlayRenderer::renderOverlay(bool renderToTexture) { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "OverlayRenderer::displayOverlay()"); +void ApplicationOverlay::renderOverlay(bool renderToTexture) { + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); Application* application = Application::getInstance(); @@ -226,7 +226,7 @@ void OverlayRenderer::renderOverlay(bool renderToTexture) { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); - + if (renderToTexture) { getFramebufferObject()->release(); @@ -234,7 +234,7 @@ void OverlayRenderer::renderOverlay(bool renderToTexture) { } // Draws the FBO texture for the screen -void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) { +void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) { Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -252,10 +252,10 @@ void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) { glDisable(GL_LIGHTING); glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2i(0, glWidget->height()); - glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height()); - glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0); - glTexCoord2f(0, 1); glVertex2i(0, 0); + glTexCoord2f(0, 0); glVertex2i(0, glWidget->height()); + glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height()); + glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0); + glTexCoord2f(0, 1); glVertex2i(0, 0); glEnd(); glPopMatrix(); @@ -263,7 +263,7 @@ void OverlayRenderer::displayOverlayTexture(Camera& whichCamera) { } // Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane. -void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) { +void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { Application* application = Application::getInstance(); @@ -311,10 +311,10 @@ void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) { glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z); glBegin(GL_QUADS); - glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0); - glTexCoord2f(0, 0); glVertex3f(halfOverlayWidth, halfOverlayHeight, 0); - glTexCoord2f(0, 1); glVertex3f(halfOverlayWidth, -halfOverlayHeight, 0); - glTexCoord2f(1, 1); glVertex3f(-halfOverlayWidth, -halfOverlayHeight, 0); + glTexCoord2f(1, 0); glVertex3f(-halfOverlayWidth, halfOverlayHeight, 0); + glTexCoord2f(0, 0); glVertex3f(halfOverlayWidth, halfOverlayHeight, 0); + glTexCoord2f(0, 1); glVertex3f(halfOverlayWidth, -halfOverlayHeight, 0); + glTexCoord2f(1, 1); glVertex3f(-halfOverlayWidth, -halfOverlayHeight, 0); glEnd(); glPopMatrix(); @@ -326,13 +326,13 @@ void OverlayRenderer::displayOverlayTextureOculus(Camera& whichCamera) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); glEnable(GL_LIGHTING); - + } -QOpenGLFramebufferObject* OverlayRenderer::getFramebufferObject() { +QOpenGLFramebufferObject* ApplicationOverlay::getFramebufferObject() { if (!_framebufferObject) { _framebufferObject = new QOpenGLFramebufferObject(Application::getInstance()->getGLWidget()->size()); - + glBindTexture(GL_TEXTURE_2D, _framebufferObject->texture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/interface/src/ui/overlays/OverlayRenderer.h b/interface/src/ui/ApplicationOverlay.h similarity index 71% rename from interface/src/ui/overlays/OverlayRenderer.h rename to interface/src/ui/ApplicationOverlay.h index b09626fbfa..cdc4065f45 100644 --- a/interface/src/ui/overlays/OverlayRenderer.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -1,5 +1,5 @@ // -// OverlayRenderer.h +// ApplicationOverlay.h // interface/src/ui/overlays // // Created by Benjamin Arnold on 5/27/14. @@ -9,25 +9,25 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_OverlayRenderer_h -#define hifi_OverlayRenderer_h +#ifndef hifi_ApplicationOverlay_h +#define hifi_ApplicationOverlay_h class Overlays; class QOpenGLFramebufferObject; // Handles the drawing of the overlays to the scree -class OverlayRenderer { +class ApplicationOverlay { public: - OverlayRenderer(); - ~OverlayRenderer(); + ApplicationOverlay(); + ~ApplicationOverlay(); void renderOverlay(bool renderToTexture = false); void displayOverlayTexture(Camera& whichCamera); void displayOverlayTextureOculus(Camera& whichCamera); // Getters - QOpenGLFramebufferObject* getFramebufferObject(); + QOpenGLFramebufferObject* getFramebufferObject(); private: @@ -35,4 +35,4 @@ private: float _trailingAudioLoudness; }; -#endif // hifi_OverlayRenderer_h \ No newline at end of file +#endif // hifi_ApplicationOverlay_h \ No newline at end of file