make GlowEffect support DependencyManager

This commit is contained in:
ZappoMan 2014-12-15 17:29:48 -08:00
parent 79bc5e0507
commit e53833b306
17 changed files with 64 additions and 32 deletions

View file

@ -90,6 +90,8 @@
#include "gpu/Batch.h"
#include "gpu/GLBackend.h"
#include "renderer/GlowEffect.h"
#include "scripting/AccountScriptingInterface.h"
#include "scripting/AudioDeviceScriptingInterface.h"
#include "scripting/ClipboardScriptingInterface.h"
@ -702,7 +704,7 @@ void Application::paintGL() {
TV3DManager::display(*whichCamera);
} else {
_glowEffect.prepare();
DependencyManager::get<GlowEffect>()->prepare();
// Viewport is assigned to the size of the framebuffer
QSize size = DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->size();
@ -721,7 +723,7 @@ void Application::paintGL() {
renderRearViewMirror(_mirrorViewRect);
}
_glowEffect.render();
DependencyManager::get<GlowEffect>()->render();
{
PerformanceTimer perfTimer("renderOverlay");
@ -1913,7 +1915,6 @@ void Application::init() {
_environment.init();
_deferredLightingEffect.init();
_glowEffect.init();
_ambientOcclusionEffect.init();
// TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
@ -2036,6 +2037,9 @@ void Application::init() {
// make sure our texture cache knows about window size changes
DependencyManager::get<TextureCache>()->associateWithWidget(getGLWidget());
// initialize the GlowEffect with our widget
DependencyManager::get<GlowEffect>()->init(getGLWidget());
}
void Application::closeMirrorView() {

View file

@ -63,7 +63,6 @@
#include "entities/EntityTreeRenderer.h"
#include "renderer/AmbientOcclusionEffect.h"
#include "renderer/DeferredLightingEffect.h"
#include "renderer/GlowEffect.h"
#include "scripting/ControllerScriptingInterface.h"
#include "ui/BandwidthDialog.h"
#include "ui/BandwidthMeter.h"
@ -252,7 +251,6 @@ public:
AnimationCache* getAnimationCache() { return &_animationCache; }
DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; }
GlowEffect* getGlowEffect() { return &_glowEffect; }
ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; }
AvatarManager& getAvatarManager() { return _avatarManager; }
@ -571,7 +569,6 @@ private:
AnimationCache _animationCache;
DeferredLightingEffect _deferredLightingEffect;
GlowEffect _glowEffect;
AmbientOcclusionEffect _ambientOcclusionEffect;
Audio _audio;

View file

@ -40,6 +40,7 @@
#include "Recorder.h"
#include "world.h"
#include "devices/OculusManager.h"
#include "renderer/GlowEffect.h"
#include "ui/TextRenderer.h"
using namespace std;

View file

@ -21,10 +21,11 @@
#include "Application.h"
#include "Avatar.h"
#include "AvatarManager.h"
#include "Menu.h"
#include "MyAvatar.h"
#include "AvatarManager.h"
#include "renderer/GlowEffect.h"
// We add _myAvatar into the hash with all the other AvatarData, and we use the default NULL QUid as the key.
const QUuid MY_AVATAR_KEY; // NULL key

View file

@ -22,6 +22,7 @@
#include "Menu.h"
#include "Util.h"
#include "devices/OculusManager.h"
#include "renderer/GlowEffect.h"
using namespace std;
@ -331,7 +332,7 @@ void Head::addLeanDeltas(float sideways, float forward) {
void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) {
Application::getInstance()->getGlowEffect()->begin();
DependencyManager::get<GlowEffect>()->begin();
glLineWidth(2.0);
glBegin(GL_LINES);
@ -345,7 +346,7 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi
glVertex3f(lookatPosition.x, lookatPosition.y, lookatPosition.z);
glEnd();
Application::getInstance()->getGlowEffect()->end();
DependencyManager::get<GlowEffect>()->end();
}

View file

@ -26,6 +26,7 @@
#include <UserActivityLogger.h>
#include "Application.h"
#include "renderer/GlowEffect.h"
#ifdef HAVE_LIBOVR
@ -448,7 +449,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p
//Bind our framebuffer object. If we are rendering the glow effect, we let the glow effect shader take care of it
if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) {
Application::getInstance()->getGlowEffect()->prepare();
DependencyManager::get<GlowEffect>()->prepare();
} else {
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -553,7 +554,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p
//Bind the output texture from the glow shader. If glow effect is disabled, we just grab the texture
if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) {
QOpenGLFramebufferObject* fbo = Application::getInstance()->getGlowEffect()->render(true);
QOpenGLFramebufferObject* fbo = DependencyManager::get<GlowEffect>()->render(true);
glBindTexture(GL_TEXTURE_2D, fbo->texture());
} else {
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->release();

View file

@ -19,6 +19,7 @@
#include "TV3DManager.h"
#include "Menu.h"
#include "renderer/GlowEffect.h"
int TV3DManager::_screenWidth = 1;
int TV3DManager::_screenHeight = 1;
@ -103,7 +104,7 @@ void TV3DManager::display(Camera& whichCamera) {
applicationOverlay.renderOverlay(true);
const bool displayOverlays = Menu::getInstance()->isOptionChecked(MenuOption::UserInterface);
Application::getInstance()->getGlowEffect()->prepare();
DependencyManager::get<GlowEffect>()->prepare();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -169,7 +170,7 @@ void TV3DManager::display(Camera& whichCamera) {
// reset the viewport to how we started
glViewport(0, 0, deviceSize.width(), deviceSize.height());
Application::getInstance()->getGlowEffect()->render();
DependencyManager::get<GlowEffect>()->render();
}
void TV3DManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,

View file

@ -36,6 +36,8 @@
#include "RenderableSphereEntityItem.h"
#include "RenderableTextEntityItem.h"
#include "renderer/GlowEffect.h"
QThread* EntityTreeRenderer::getMainThread() {
return Application::getInstance()->getEntities()->thread();

View file

@ -24,6 +24,7 @@
#include "RenderUtil.h"
#include "AmbientOcclusionEffect.h"
#include "renderer/GlowEffect.h"
const int ROTATION_WIDTH = 4;
const int ROTATION_HEIGHT = 4;
@ -105,7 +106,7 @@ void AmbientOcclusionEffect::render() {
glBindTexture(GL_TEXTURE_2D, _rotationTextureID);
// render with the occlusion shader to the secondary/tertiary buffer
QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject();
QOpenGLFramebufferObject* freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebufferObject();
freeFBO->bind();
float left, right, bottom, top, nearVal, farVal;

View file

@ -19,6 +19,7 @@
#include "Application.h"
#include "DeferredLightingEffect.h"
#include "RenderUtil.h"
#include "renderer/GlowEffect.h"
void DeferredLightingEffect::init() {
_simpleProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/simple.vert");
@ -41,7 +42,7 @@ void DeferredLightingEffect::init() {
void DeferredLightingEffect::bindSimpleProgram() {
DependencyManager::get<TextureCache>()->setPrimaryDrawBuffers(true, true, true);
_simpleProgram.bind();
_simpleProgram.setUniformValue(_glowIntensityLocation, Application::getInstance()->getGlowEffect()->getIntensity());
_simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get<GlowEffect>()->getIntensity());
glDisable(GL_BLEND);
}
@ -146,7 +147,7 @@ void DeferredLightingEffect::render() {
QOpenGLFramebufferObject* primaryFBO = textureCache->getPrimaryFramebufferObject();
primaryFBO->release();
QOpenGLFramebufferObject* freeFBO = Application::getInstance()->getGlowEffect()->getFreeFramebufferObject();
QOpenGLFramebufferObject* freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebufferObject();
freeFBO->bind();
glClear(GL_COLOR_BUFFER_BIT);

View file

@ -13,6 +13,7 @@
#include "InterfaceConfig.h"
#include <QOpenGLFramebufferObject>
#include <QWindow>
#include <PathUtils.h>
#include <PerfStat.h>
@ -58,7 +59,7 @@ static ProgramObject* createProgram(const QString& name) {
return program;
}
void GlowEffect::init() {
void GlowEffect::init(QGLWidget* widget) {
if (_initialized) {
qDebug("[ERROR] GlowEffeect is already initialized.");
return;
@ -86,8 +87,18 @@ void GlowEffect::init() {
_diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale");
_initialized = true;
_widget = widget;
}
int GlowEffect::getDeviceWidth() const {
return _widget->width() * (_widget->windowHandle() ? _widget->windowHandle()->devicePixelRatio() : 1.0f);
}
int GlowEffect::getDeviceHeight() const {
return _widget->height() * (_widget->windowHandle() ? _widget->windowHandle()->devicePixelRatio() : 1.0f);
}
void GlowEffect::prepare() {
DependencyManager::get<TextureCache>()->getPrimaryFramebufferObject()->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -148,8 +159,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
} else {
maybeBind(destFBO);
if (!destFBO) {
glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(),
Application::getInstance()->getGLWidget()->getDeviceHeight());
glViewport(0, 0, getDeviceWidth(), getDeviceHeight());
}
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
@ -196,9 +206,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
}
maybeBind(destFBO);
if (!destFBO) {
glViewport(0, 0,
Application::getInstance()->getGLWidget()->getDeviceWidth(),
Application::getInstance()->getGLWidget()->getDeviceHeight());
glViewport(0, 0, getDeviceWidth(), getDeviceHeight());
}
_addSeparateProgram->bind();
renderFullscreenQuad();
@ -226,10 +234,10 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
}
Glower::Glower(float amount) {
Application::getInstance()->getGlowEffect()->begin(amount);
DependencyManager::get<GlowEffect>()->begin(amount);
}
Glower::~Glower() {
Application::getInstance()->getGlowEffect()->end();
DependencyManager::get<GlowEffect>()->end();
}

View file

@ -15,23 +15,23 @@
#include <QObject>
#include <QStack>
#include <DependencyManager.h>
class QOpenGLFramebufferObject;
class ProgramObject;
/// A generic full screen glow effect.
class GlowEffect : public QObject {
class GlowEffect : public QObject, public DependencyManager::Dependency {
Q_OBJECT
public:
GlowEffect();
~GlowEffect();
/// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state
/// (either the secondary or the tertiary).
QOpenGLFramebufferObject* getFreeFramebufferObject() const;
void init();
void init(QGLWidget* widget);
/// Prepares the glow effect for rendering the current frame. To be called before rendering the scene.
void prepare();
@ -52,6 +52,12 @@ public:
QOpenGLFramebufferObject* render(bool toTexture = false);
private:
GlowEffect();
virtual ~GlowEffect();
friend class DependencyManager;
int getDeviceWidth() const;
int getDeviceHeight() const;
bool _initialized;
@ -69,6 +75,7 @@ private:
float _intensity;
QStack<float> _intensityStack;
QGLWidget* _widget;
};
/// RAII-style glow handler. Applies glow when in scope.

View file

@ -33,6 +33,8 @@
#define GLBATCH( call ) batch._##call
//#define GLBATCH( call ) call
#include "renderer/GlowEffect.h"
using namespace std;
static int modelPointerTypeId = qRegisterMetaType<QPointer<Model> >();
@ -2327,6 +2329,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches);
TextureCache* textureCache = DependencyManager::get<TextureCache>();
GlowEffect* glowEffect = DependencyManager::get<GlowEffect>();
QString lastMaterialID;
int meshPartsRendered = 0;
updateVisibleJointStates();
@ -2431,7 +2434,7 @@ int Model::renderMeshesFromList(QVector<int>& list, gpu::Batch& batch, RenderMod
glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity);
if (!(translucent && alphaThreshold == 0.0f)) {
GLBATCH(glAlphaFunc)(GL_EQUAL, diffuse.a = Application::getInstance()->getGlowEffect()->getIntensity());
GLBATCH(glAlphaFunc)(GL_EQUAL, diffuse.a = glowEffect->getIntensity());
}
glm::vec4 specular = glm::vec4(part.specularColor, 1.0f);
GLBATCH(glMaterialfv)(GL_FRONT, GL_AMBIENT, (const float*)&diffuse);

View file

@ -12,6 +12,7 @@
#include "Application.h"
#include "LocalModelsOverlay.h"
#include "renderer/GlowEffect.h"
LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) :
Volume3DOverlay(),

View file

@ -18,6 +18,7 @@
#include <Application.h>
#include "LocalVoxelsOverlay.h"
#include "renderer/GlowEffect.h"
#include "voxels/VoxelSystem.h"
QMap<QString, WeakVoxelSystemPointer> LocalVoxelsOverlay::_voxelSystemMap;

View file

@ -11,6 +11,7 @@
#include "../../Menu.h"
#include "ModelOverlay.h"
#include "renderer/GlowEffect.h"
ModelOverlay::ModelOverlay()
: _model(),

View file

@ -15,6 +15,7 @@
#include "Application.h"
#include "VoxelFade.h"
#include "renderer/GlowEffect.h"
const float VoxelFade::FADE_OUT_START = 0.5f;
const float VoxelFade::FADE_OUT_END = 0.05f;
@ -36,7 +37,7 @@ VoxelFade::VoxelFade(FadeDirection direction, float red, float green, float blue
}
void VoxelFade::render() {
Application::getInstance()->getGlowEffect()->begin();
DependencyManager::get<GlowEffect>()->begin();
glDisable(GL_LIGHTING);
glPushMatrix();
@ -52,7 +53,7 @@ void VoxelFade::render() {
glEnable(GL_LIGHTING);
Application::getInstance()->getGlowEffect()->end();
DependencyManager::get<GlowEffect>()->end();
opacity *= (direction == FADE_OUT) ? FADE_OUT_STEP : FADE_IN_STEP;
}