From c17794849d76fdb171b575448be12a4f60bfd9ae Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 12:58:15 -0700 Subject: [PATCH] more GlowEctomy --- interface/src/Application.cpp | 3 - .../src/DeferredLightingEffect.cpp | 5 +- libraries/render-utils/src/GlowEffect.cpp | 225 ------------------ libraries/render-utils/src/GlowEffect.h | 97 -------- 4 files changed, 2 insertions(+), 328 deletions(-) delete mode 100644 libraries/render-utils/src/GlowEffect.cpp delete mode 100644 libraries/render-utils/src/GlowEffect.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 373610087b..b85297c3cf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -98,8 +98,6 @@ #include #include -#include // FIXME - #include "Application.h" #include "AudioClient.h" #include "DiscoverabilityManager.h" @@ -270,7 +268,6 @@ bool setupEssentials(int& argc, char** argv) { auto geometryCache = DependencyManager::set(); auto scriptCache = DependencyManager::set(); auto soundCache = DependencyManager::set(); - auto glowEffect = DependencyManager::set(); // FIXME auto faceshift = DependencyManager::set(); auto audio = DependencyManager::set(); auto audioScope = DependencyManager::set(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b2db089bbe..4737929cf6 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -18,7 +18,6 @@ #include "AbstractViewStateInterface.h" #include "DeferredLightingEffect.h" #include "GeometryCache.h" -#include "GlowEffect.h" #include "RenderUtil.h" #include "TextureCache.h" @@ -238,7 +237,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = textureCache->getFrameBufferSize(); // binding the first framebuffer - auto freeFBO = DependencyManager::get()->getFreeFramebuffer(); + auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); batch.setFramebuffer(freeFBO); batch.clearColorFramebuffer(freeFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); @@ -547,7 +546,7 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { auto textureCache = DependencyManager::get(); QSize framebufferSize = textureCache->getFrameBufferSize(); - auto freeFBO = DependencyManager::get()->getFreeFramebuffer(); + auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); batch.setFramebuffer(textureCache->getPrimaryFramebuffer()); batch.setPipeline(_blitLightBuffer); diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp deleted file mode 100644 index 2e8b58c6c2..0000000000 --- a/libraries/render-utils/src/GlowEffect.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// -// GlowEffect.cpp -// interface/src/renderer -// -// Created by Andrzej Kapolka on 8/7/13. -// Copyright 2013 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 this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include - -#include -#include - -#include -#include - -#include "GlowEffect.h" -#include "ProgramObject.h" -#include "RenderUtil.h" -#include "TextureCache.h" -#include "RenderUtilsLogging.h" - -#include "gpu/GLBackend.h" - -GlowEffect::GlowEffect() - : _initialized(false), - _isOddFrame(false), - _isFirstFrame(true), - _intensity(0.0f), - _enabled(false) { -} - -GlowEffect::~GlowEffect() { - if (_initialized) { - delete _addProgram; - delete _horizontalBlurProgram; - delete _verticalBlurAddProgram; - delete _verticalBlurProgram; - delete _addSeparateProgram; - delete _diffuseProgram; - } -} - -gpu::FramebufferPointer GlowEffect::getFreeFramebuffer() const { - return (_isOddFrame ? - DependencyManager::get()->getSecondaryFramebuffer(): - DependencyManager::get()->getTertiaryFramebuffer()); -} - -static ProgramObject* createProgram(const QString& name) { - ProgramObject* program = new ProgramObject(); - program->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/" + name + ".frag"); - program->link(); - - program->bind(); - program->setUniformValue("originalTexture", 0); - program->release(); - - return program; -} - -void GlowEffect::init(bool enabled) { - if (_initialized) { - qCDebug(renderutils, "[ERROR] GlowEffeect is already initialized."); - return; - } - - _addProgram = createProgram("glow_add"); - _horizontalBlurProgram = createProgram("horizontal_blur"); - _verticalBlurAddProgram = createProgram("vertical_blur_add"); - _verticalBlurProgram = createProgram("vertical_blur"); - _addSeparateProgram = createProgram("glow_add_separate"); - _diffuseProgram = createProgram("diffuse"); - - _verticalBlurAddProgram->bind(); - _verticalBlurAddProgram->setUniformValue("horizontallyBlurredTexture", 1); - _verticalBlurAddProgram->release(); - - _addSeparateProgram->bind(); - _addSeparateProgram->setUniformValue("blurredTexture", 1); - _addSeparateProgram->release(); - - _diffuseProgram->bind(); - _diffuseProgram->setUniformValue("diffusedTexture", 1); - _diffuseProgram->release(); - - _diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale"); - - _initialized = true; - _enabled = enabled; -} - -void GlowEffect::prepare(RenderArgs* renderArgs) { - auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); - GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - _isEmpty = true; - _isOddFrame = !_isOddFrame; -} - -void GlowEffect::begin(RenderArgs* renderArgs, float intensity) { - // store the current intensity and add the new amount - _intensityStack.push(_intensity); - glBlendColor(0.0f, 0.0f, 0.0f, _intensity += intensity); - _isEmpty &= (_intensity == 0.0f); -} - -void GlowEffect::end(RenderArgs* renderArgs) { - // restore the saved intensity - glBlendColor(0.0f, 0.0f, 0.0f, _intensity = _intensityStack.pop()); -} - -gpu::FramebufferPointer GlowEffect::render(RenderArgs* renderArgs) { - PerformanceTimer perfTimer("glowEffect"); - - auto textureCache = DependencyManager::get(); - - auto primaryFBO = gpu::GLBackend::getFramebufferID(textureCache->getPrimaryFramebuffer()); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - glBindTexture(GL_TEXTURE_2D, textureCache->getPrimaryColorTextureID()); - auto framebufferSize = textureCache->getFrameBufferSize(); - - glPushMatrix(); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); - - gpu::FramebufferPointer destFBO = textureCache->getSecondaryFramebuffer(); - if (!_enabled || _isEmpty) { - // copy the primary to the screen - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); - glBindFramebuffer(GL_READ_FRAMEBUFFER, primaryFBO); - glBlitFramebuffer( - 0, 0, framebufferSize.width(), framebufferSize.height(), - 0, 0, framebufferSize.width(), framebufferSize.height(), - GL_COLOR_BUFFER_BIT, GL_NEAREST); - } else { - // diffuse into the secondary/tertiary (alternating between frames) - auto oldDiffusedFBO = - textureCache->getSecondaryFramebuffer(); - auto newDiffusedFBO = - textureCache->getTertiaryFramebuffer(); - if (_isOddFrame) { - qSwap(oldDiffusedFBO, newDiffusedFBO); - } - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(newDiffusedFBO)); - - if (_isFirstFrame) { - glClear(GL_COLOR_BUFFER_BIT); - - } else { - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(oldDiffusedFBO->getRenderBuffer(0))); - - _diffuseProgram->bind(); - - _diffuseProgram->setUniformValue(_diffusionScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height()); - - renderFullscreenQuad(); - - _diffuseProgram->release(); - } - - destFBO = oldDiffusedFBO; - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - // add diffused texture to the primary - glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(newDiffusedFBO->getRenderBuffer(0))); - - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); - glViewport(0, 0, framebufferSize.width(), framebufferSize.height()); - _addSeparateProgram->bind(); - renderFullscreenQuad(); - _addSeparateProgram->release(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - } - - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glEnable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); - glBindTexture(GL_TEXTURE_2D, 0); - - _isFirstFrame = false; - - return destFBO; -} - -void GlowEffect::toggleGlowEffect(bool enabled) { - _enabled = enabled; -} - -Glower::Glower(float amount) { - RenderArgs renderArgs; - DependencyManager::get()->begin(&renderArgs, amount); -} -Glower::Glower(RenderArgs* renderArgs, float amount) : _renderArgs(renderArgs) { - DependencyManager::get()->begin(_renderArgs, amount); -} - -Glower::~Glower() { - DependencyManager::get()->end(_renderArgs); -} - diff --git a/libraries/render-utils/src/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h deleted file mode 100644 index 23a21a9575..0000000000 --- a/libraries/render-utils/src/GlowEffect.h +++ /dev/null @@ -1,97 +0,0 @@ -// -// GlowEffect.h -// interface/src/renderer -// -// Created by Andrzej Kapolka on 8/7/13. -// Copyright 2013 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_GlowEffect_h -#define hifi_GlowEffect_h - -#include -#include - -#include "RenderArgs.h" - -#include -#include -#include - -#include - -class ProgramObject; - -/// A generic full screen glow effect. -class GlowEffect : public QObject, public Dependency { - Q_OBJECT - SINGLETON_DEPENDENCY - -public: - - /// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state - /// (either the secondary or the tertiary). - gpu::FramebufferPointer getFreeFramebuffer() const; - - void init(bool enabled); - - /// Prepares the glow effect for rendering the current frame. To be called before rendering the scene. - void prepare(RenderArgs* renderArgs); - - /// Starts using the glow effect. - /// \param intensity the desired glow intensity, from zero to one - void begin(RenderArgs* renderArgs, float intensity = 1.0f); - - /// Stops using the glow effect. - void end(RenderArgs* renderArgs); - - /// Returns the current glow intensity. - float getIntensity() const { return _intensity; } - - /// Renders the glow effect. To be called after rendering the scene. - /// \param toTexture whether to render to a texture, rather than to the frame buffer - /// \return the framebuffer object to which we rendered, or NULL if to the frame buffer - gpu::FramebufferPointer render(RenderArgs* renderArgs); - -public slots: - void toggleGlowEffect(bool enabled); - -private: - GlowEffect(); - virtual ~GlowEffect(); - - bool _initialized; - - ProgramObject* _addProgram; - ProgramObject* _horizontalBlurProgram; - ProgramObject* _verticalBlurAddProgram; - ProgramObject* _verticalBlurProgram; - ProgramObject* _addSeparateProgram; - ProgramObject* _diffuseProgram; - int _diffusionScaleLocation; - - bool _isEmpty; ///< set when nothing in the scene is currently glowing - bool _isOddFrame; ///< controls the alternation between texture targets in diffuse add mode - bool _isFirstFrame; ///< for persistent modes, notes whether this is the first frame rendered - - float _intensity; - QStack _intensityStack; - bool _enabled; -}; - -/// RAII-style glow handler. Applies glow when in scope. -class Glower { -public: - - Glower(float amount = 1.0f); - Glower(RenderArgs* renderArgs, float amount = 1.0f); - ~Glower(); - -private: - RenderArgs* _renderArgs; -}; - -#endif // hifi_GlowEffect_h