More efficiency for glow effect.

This commit is contained in:
Andrzej Kapolka 2013-08-09 16:16:02 -07:00
parent 9189a206b8
commit a3cee5d052
4 changed files with 43 additions and 35 deletions

View file

@ -22,6 +22,9 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/vector_angle.hpp>
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QActionGroup>
#include <QBoxLayout>
#include <QColorDialog>
@ -59,7 +62,6 @@
#include <VoxelSceneStats.h>
#include "Application.h"
#include "InterfaceConfig.h"
#include "LogDisplay.h"
#include "LeapManager.h"
#include "OculusManager.h"
@ -92,6 +94,10 @@ const int STARTUP_JITTER_SAMPLES = PACKET_LENGTH_SAMPLES_PER_CHANNEL / 2;
// customized canvas that simply forwards requests/events to the singleton application
class GLCanvas : public QGLWidget {
public:
GLCanvas();
protected:
virtual void initializeGL();
@ -110,6 +116,9 @@ protected:
virtual void wheelEvent(QWheelEvent* event);
};
GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::AlphaChannel)) {
}
void GLCanvas::initializeGL() {
Application::getInstance()->initializeGL();
setAttribute(Qt::WA_AcceptTouchEvents);
@ -2199,8 +2208,8 @@ void Application::runTests() {
void Application::initDisplay() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel (GL_SMOOTH);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
@ -3001,6 +3010,9 @@ void Application::displaySide(Camera& whichCamera) {
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
setupWorldLight(whichCamera);
// prepare the glow effect
_glowEffect.prepare();
if (_renderStarsOn->isChecked()) {
if (!_stars.getFileLoaded()) {
_stars.readInput(STAR_FILE, STAR_CACHE_FILE, 0);
@ -3033,9 +3045,6 @@ void Application::displaySide(Camera& whichCamera) {
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
// prepare the glow effect
_glowEffect.prepare();
// Enable to show line from me to the voxel I am touching
//renderLineToTouchedVoxel();
//renderThrustAtVoxel(_voxelThrust);
@ -3131,13 +3140,9 @@ void Application::displaySide(Camera& whichCamera) {
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
_myAvatar.getHead().setLookAtPosition(_myCamera.getPosition());
}
_glowEffect.begin();
_myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
_glowEffect.bind();
_myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
_glowEffect.release();
_myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked());
_glowEffect.end();
_myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());

View file

@ -695,8 +695,7 @@ void VoxelSystem::render(bool texture) {
applyScaleAndBindProgram(texture);
// for performance, disable blending and enable backface culling
glDisable(GL_BLEND);
// for performance, enable backface culling
glEnable(GL_CULL_FACE);
// draw the number of voxels we have
@ -704,7 +703,6 @@ void VoxelSystem::render(bool texture) {
glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
removeScaleAndReleaseProgram(texture);

View file

@ -5,11 +5,13 @@
// Created by Andrzej Kapolka on 8/7/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QOpenGLFramebufferObject>
#include "Application.h"
#include "GlowEffect.h"
#include "InterfaceConfig.h"
#include "ProgramObject.h"
static ProgramObject* createBlurProgram(const QString& direction) {
@ -31,17 +33,16 @@ void GlowEffect::init() {
}
void GlowEffect::prepare() {
bind();
glClear(GL_COLOR_BUFFER_BIT);
release();
_isEmpty = true;
}
void GlowEffect::bind() {
Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject()->bind();
void GlowEffect::begin(float amount) {
glBlendColor(0.0f, 0.0f, 0.0f, amount);
_isEmpty = false;
}
void GlowEffect::release() {
Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject()->release();
void GlowEffect::end() {
glBlendColor(0.0f, 0.0f, 0.0f, 0.0f);
}
static void renderFullscreenQuad() {
@ -58,10 +59,15 @@ static void renderFullscreenQuad() {
}
void GlowEffect::render() {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject()->texture());
glDisable(GL_LIGHTING);
if (_isEmpty) {
return; // nothing glowing
}
QOpenGLFramebufferObject* primaryFBO = Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject();
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
QSize size = primaryFBO->size();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.width(), size.height());
glPushMatrix();
glLoadIdentity();
@ -85,7 +91,7 @@ void GlowEffect::render() {
glBindTexture(GL_TEXTURE_2D, secondaryFBO->texture());
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_CONSTANT_ALPHA, GL_ONE);
_verticalBlurProgram->bind();
renderFullscreenQuad();
@ -98,8 +104,5 @@ void GlowEffect::render() {
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
}

View file

@ -18,15 +18,17 @@ public:
void prepare();
void bind();
void release();
void begin(float amount = 1.0f);
void end();
void render();
private:
ProgramObject* _horizontalBlurProgram;
ProgramObject* _verticalBlurProgram;
ProgramObject* _verticalBlurProgram;
bool _isEmpty;
};
#endif /* defined(__interface__GlowEffect__) */