DeferredRenderer 1.0

GLWindow Class Reference

The GLWidget for updating the drawing of our scene. More...

#include <GLWindow.h>

Collaboration diagram for GLWindow:

List of all members.

Public Slots

void toggleWireframe (bool _mode)
 a slot to toggle wireframe mode
void toggleShadowMap (bool _mode)
 a slot to toggle showing shadowmap
void toggleDebug (bool _mode)
 set the debug display
void setKa (double _value)
 set the ambient coefficient for the scene
void setKd (double _value)
 set the diffuse coefficient for the scene
void setDVecX (double _value)
 set the global directional light for the scene
void setDVecY (double _value)
 set the global directional light for the scene
void setDVecZ (double _value)
 set the global directional light for the scene
void setAmbientColourR (double _value)
 set the global ambient light col for the scene
void setAmbientColourG (double _value)
 set the global ambient light col for the scene
void setAmbientColourB (double _value)
 set the global ambient light col for the scene
void setDColourR (double _value)
 set the global directional light col for the scene
void setDColourG (double _value)
 set the global directional light col for the scene
void setDColourB (double _value)
 set the global directional light col for the scene
void changeNormWeight (double _value)
 alter the normal weighting on AA
void changeDepthWeight (double _value)
 alter the depth weighting on AA
void changeNormBarrier (double _value)
 alter the normal barrier on AA
void changeDepthBarrier (double _value)
 alter the depth barrier on AA
void changeKernel (double _value)
 set the global directional light col for the scene
void setMainDisplay (int _displayMode)
 the mode for the main screen quad, binds our render targets to it

Public Member Functions

 GLWindow (QWidget *_parent)
 Constructor for GLWindow.
void processKeyPress (QKeyEvent *_event)
 GL key events processing.

Protected Member Functions

void genShader (const std::string &_name, const std::string &_VSname, const std::string &_FSname, const std::vector< std::string > &_attributes)
 a helper function for generating ngl shaders
void initializeGL ()
 called upon creating GLWindow, setup for Glew and other scene elements
void resizeGL (const int _w, const int _h)
 Re-size method, disabled in this application.
void paintGL ()
 this is the main gl drawing routine
void timerEvent (QTimerEvent *_event)
 timer event for updating the demo scene
void createScreenQuad ()
 construct the geometry once for our screen quad

Protected Attributes

float m_AAbarrierNorm
 anti aliasing kernel variables
float m_AAbarrierDepth
float m_AAweightNorm
float m_AAweightDepth
float m_AAkernel
int m_currentDisplay
 the current main display texture
int m_spinXFace
 used to store the x rotation mouse value
int m_spinYFace
 used to store the y rotation mouse value
bool m_rotate
 flag to indicate if the mouse button is pressed when dragging
int m_origX
 the previous x mouse value
int m_origY
 the previous y mouse value
ngl::TransformStack m_transformStack
 the transformation stack

Private Member Functions

void mouseMoveEvent (QMouseEvent *_event)
 this method is called every time a mouse is moved
void mousePressEvent (QMouseEvent *_event)
 this method is called everytime the mouse button is pressed
void mouseReleaseEvent (QMouseEvent *_event)
 this method is called everytime the mouse button is released
void setupShaders ()
 setup our application shaders
void setupTextures ()
 setup our applictaion textures
void lightAccumulation ()
 accumulate light onto our pixels
void shadowPass ()
 shadow pass for our shadowspot
void geometryPass ()
 geometry for main gbuffer
void debugPass ()
 debug pass for drawing our debug quads
void postProcess ()
 run the post processing chain
void postProcessUniforms ()
 setup shader uniforms for post process
void postProcessSetup ()
 setup the post processor chain
void addStandardEffect (const std::string &_effectName, const std::string &_outputName, const std::string &_shaderName, const std::string &_sourceName)
 stub for common setup of effect

Private Attributes

TextureManager m_textureManager
 controls our applications texture
LightingManager m_lightingManager
 controls out applications lights
int m_updatetimer
 update timer for demo scene
float m_time
 current time variable
float m_timeStep
 the increment for out time variable
float m_Ka
 the ambient coefficient of the gpass
float m_Kd
 the diffuse coefficient of the gpass
bool m_wireframe
 wireframe mode on/off
bool m_debug
 debug mode on/off
ScreenQuad m_viewportQuad
 our main viewport quad
Frustum m_frustum
 out camera frustum
FrameBufferObject m_fbo
 maine fbo for gpass
FrameBufferObject m_shadowBuffer
 shadow fbo for shadowpass
ngl::Camera m_cam
 our ngl camera
unsigned int m_pointLightVAO
 out point light vao id
std::string m_spotLightName
 spotlight name for ngl vboprimitives
unsigned int m_screenQuadVAO
 our screen quad vao id
ScreenQuad m_debugQuad1
 debug quad bottom left
ScreenQuad m_debugQuad2
 debug quad bottom middle-left
ScreenQuad m_debugQuad3
 debug quad bottom middle-right
ScreenQuad m_debugQuad4
 debug quad bottom right
ScreenQuad m_debugQuad5
 debug quad top left
ScreenQuad m_debugQuad6
 debug quad top right
ngl::Vector m_directionalVec
 the global directional vector
ngl::Vector m_ambientColour
 the global directional vector
ngl::Vector m_directionalColour
 the global directional vector
bool m_showShadowMap
 check whether to display our shadowmap
PostProcessor m_postProcessor
 our post processor
ngl::Obj * obj
 a demo obj
int m_windoWidth
int m_windowHeight

Detailed Description

The GLWidget for updating the drawing of our scene.

Definition at line 27 of file GLWindow.h.


Constructor & Destructor Documentation

GLWindow::GLWindow ( QWidget *  _parent)

Constructor for GLWindow.

Parameters:
[in]_parentthe parent window to create the GL context in

Definition at line 22 of file GLWindow.cpp.

References HEIGHT, m_AAbarrierDepth, m_AAbarrierNorm, m_AAkernel, m_AAweightDepth, m_AAweightNorm, m_ambientColour, m_currentDisplay, m_debug, m_directionalColour, m_directionalVec, m_Ka, m_Kd, m_rotate, m_showShadowMap, m_spinXFace, m_spinYFace, m_time, m_timeStep, m_wireframe, and WIDTH.

                    :
                    QGLWidget(_parent),
                    m_viewportQuad(0.0f, 0.0f, 0.5f, 1.0f),
                    m_fbo(WIDTH, HEIGHT),
                    m_shadowBuffer(512, 512),
                    m_cam(ngl::Vector(0,6,10),ngl::Vector(0,0,4),ngl::Vector(0,1,0), ngl::PERSPECTIVE),
                    m_debugQuad1(-0.75,-0.8,0.0,0.2),
                    m_debugQuad2(-0.25,-0.8,0.0,0.2),
                    m_debugQuad3(0.25,-0.8,0.0,0.2),
                    m_debugQuad4(0.75,-0.8,0.0,0.2),
                    m_debugQuad5(-0.75,0.75,0.0,0.2)
{

  // set this widget to have the initial keyboard focus
  setFocus();
  // re-size the widget to that of the parent (in this case the GLFrame passed in on construction)
  this->resize(WIDTH,HEIGHT);

  m_rotate=false;
  // mouse rotation values set to 0
  m_spinXFace=0;
  m_spinYFace=0;

  m_wireframe = false;
  m_debug = true;
  m_showShadowMap = false;
  m_currentDisplay = 0;
  m_Ka = 0.5;
  m_Kd = 0.7;

  m_directionalVec = ngl::Vector(1,0,0);
  m_ambientColour = ngl::Vector(1,1,1);
  m_directionalColour = ngl::Vector(1,1,1);

  //win32
  m_AAbarrierDepth = 0.5;
  m_AAbarrierNorm = 0.6;
  m_AAweightNorm = 0.15;
  m_AAweightDepth = 0.15;
  m_AAkernel = 0.4;

  m_time = 0.0;
  m_timeStep = 1.0;

}

Member Function Documentation

void GLWindow::addStandardEffect ( const std::string &  _effectName,
const std::string &  _outputName,
const std::string &  _shaderName,
const std::string &  _sourceName 
) [private]

stub for common setup of effect

Definition at line 325 of file GLWindow.cpp.

References PostProcessor::addEffect(), Effect::addSourceTexture(), TextureManager::getTextureId(), m_postProcessor, and m_textureManager.

{
    Effect effect(m_textureManager.getTextureId(_outputName), _shaderName);
    effect.addSourceTexture("u_Sampler", m_textureManager.getTextureId(_sourceName));
    m_postProcessor.addEffect(_effectName, effect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::changeDepthBarrier ( double  _value) [inline, slot]

alter the depth barrier on AA

Parameters:
[in]_valuethe new barrier

Definition at line 183 of file GLWindow.h.

References m_AAbarrierDepth.

  {
      m_AAbarrierDepth = (float)_value;
      updateGL();
  }
void GLWindow::changeDepthWeight ( double  _value) [inline, slot]

alter the depth weighting on AA

Parameters:
[in]_valuethe new weight

Definition at line 167 of file GLWindow.h.

References m_AAweightDepth.

  {
      m_AAweightDepth = (float)_value;
      updateGL();
  }
void GLWindow::changeKernel ( double  _value) [inline, slot]

set the global directional light col for the scene

Parameters:
[in]_valuethe new kernel scale

Definition at line 191 of file GLWindow.h.

References m_AAkernel.

  {
      m_AAkernel = (float)_value;
      updateGL();
  }
void GLWindow::changeNormBarrier ( double  _value) [inline, slot]

alter the normal barrier on AA

Parameters:
[in]_valuethe new barrier

Definition at line 175 of file GLWindow.h.

References m_AAbarrierNorm.

  {
      m_AAbarrierNorm = (float)_value;
      updateGL();
  }
void GLWindow::changeNormWeight ( double  _value) [inline, slot]

alter the normal weighting on AA

Parameters:
[in]_valuethe new weight

Definition at line 159 of file GLWindow.h.

References m_AAweightNorm.

  {
      m_AAweightNorm = (float)_value;
      updateGL();
  }
void GLWindow::createScreenQuad ( ) [protected]

construct the geometry once for our screen quad

Definition at line 574 of file GLWindow.cpp.

References m_screenQuadVAO.

{
    // vertex coords array
   GLfloat vertices[] = {
       -1.0, -1.0, 0.0,
       1.0, -1.0, 0.0,
       1.0, 1.0, 0.0,
       -1.0, 1.0, 0.0  // v0-v1-v2-v3
   };

   GLfloat texture[] = {
       0,0,
       1,0,
       1,1,
       0,1  // v0-v1-v2-v3
   };

     // first we create a vertex array Object
   glGenVertexArrays(1, &m_screenQuadVAO);

     // now bind this to be the currently active one
   glBindVertexArray(m_screenQuadVAO);
     // now we create two VBO's one for each of the objects these are only used here
     // as they will be associated with the vertex array object
   GLuint vboID[2];
   glGenBuffers(2, &vboID[0]);
   // now we will bind an array buffer to the first one and load the data for the verts
   glBindBuffer(GL_ARRAY_BUFFER, vboID[0]);
   glBufferData(GL_ARRAY_BUFFER, 4*3*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
   // now we bind the vertex attribute pointer for this object in this case the
   // vertex data
   ngl::ShaderManager *shader=ngl::ShaderManager::instance();
   (*shader)["ScreenQuad"]->use();
   (*shader)["ScreenQuad"]->vertexAttribPointer("a_VertexPosition",3,GL_FLOAT,0,0);
   (*shader)["ScreenQuad"]->enableAttribArray("a_VertexPosition");

     // now we repeat for the UV data using the second VBO
   glBindBuffer(GL_ARRAY_BUFFER, vboID[1]);
   glBufferData(GL_ARRAY_BUFFER, 4*2*sizeof(GLfloat), texture, GL_STATIC_DRAW);
     // now bind
   (*shader)["ScreenQuad"]->vertexAttribPointer("a_TextureCoord",2,GL_FLOAT,0,0);
   (*shader)["ScreenQuad"]->enableAttribArray("a_TextureCoord");
     // finally switch back to the default so we don't overwrite
   glEnableVertexAttribArray(0);
   glBindVertexArray(0);
}

Here is the caller graph for this function:

void GLWindow::debugPass ( ) [private]

debug pass for drawing our debug quads

Definition at line 186 of file GLWindow.cpp.

References TextureManager::bindTexture(), ScreenQuad::draw(), m_debugQuad1, m_debugQuad2, m_debugQuad3, m_debugQuad4, m_debugQuad5, m_screenQuadVAO, m_showShadowMap, and m_textureManager.

{
    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glActiveTexture(GL_TEXTURE0);

    m_textureManager.bindTexture("constant");
    m_debugQuad1.draw("ScreenQuad", m_screenQuadVAO);
    m_textureManager.bindTexture("normal");
    m_debugQuad2.draw("ScreenQuad",m_screenQuadVAO);
    m_textureManager.bindTexture("albedo");
    m_debugQuad3.draw("ScreenQuad",m_screenQuadVAO);
    m_textureManager.bindTexture("position");
    m_debugQuad4.draw("ScreenQuad",m_screenQuadVAO);

    if(m_showShadowMap)
    {
        m_textureManager.bindTexture("shadow");
        m_debugQuad5.draw("ScreenQuad",m_screenQuadVAO);
    }

    glBindTexture(GL_TEXTURE_2D, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::genShader ( const std::string &  _name,
const std::string &  _VSname,
const std::string &  _FSname,
const std::vector< std::string > &  _attributes 
) [protected]

a helper function for generating ngl shaders

Parameters:
[in]_namethe shaders desired name
[in]_VSnamethe vertex shader name
[in]_FSnamethe frag sjader name
[in]_attributesa vector of strings for the shaders attributes

Definition at line 449 of file GLWindow.cpp.

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();

    shader->createShaderProgram(_name);
    //load shader sources
    shader->attachShader("vertex", ngl::VERTEX);
    shader->attachShader("fragment", ngl::FRAGMENT);
    shader->loadShaderSource("vertex", _VSname);
    shader->loadShaderSource("fragment", _FSname);
    //compile
    shader->compileShader("vertex");
    shader->compileShader("fragment");
    //link
    shader->attachShaderToProgram(_name, "vertex");
    shader->attachShaderToProgram(_name, "fragment");

    for(unsigned int i = 0; i < _attributes.size(); i++)
    {
        shader->bindAttribute(_name, i, _attributes[i]);
    }

    shader->linkProgramObject(_name);
    //use
    (*shader)[_name]->use();

}

Here is the caller graph for this function:

void GLWindow::geometryPass ( ) [private]

geometry for main gbuffer

Definition at line 162 of file GLWindow.cpp.

References FrameBufferObject::activateAllTargets(), FrameBufferObject::bind(), m_fbo, obj, and FrameBufferObject::unbind().

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();

    (*shader)["Gbuffer"]->use();

    ngl::Material m(ngl::GOLD);
    m.use();

    m_fbo.bind();
    {
      m_fbo.activateAllTargets();

      glClearColor(0.f, 0.f, 0.f, 1.0f);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      obj->draw();

    }
    m_fbo.unbind();

        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::initializeGL ( ) [protected]

called upon creating GLWindow, setup for Glew and other scene elements

Definition at line 70 of file GLWindow.cpp.

References LightingManager::addPointLight(), LightingManager::addShadowSpot(), FrameBufferObject::bindTextureSlot(), FrameBufferObject::create(), LightingManager::createLightGeometry(), createScreenQuad(), Frustum::generate(), TextureManager::getTextureId(), HEIGHT, m_cam, m_currentDisplay, m_fbo, m_frustum, m_lightingManager, m_shadowBuffer, m_textureManager, obj, postProcessSetup(), setupShaders(), setupTextures(), and WIDTH.

{
  //init ngl
  ngl::NGLInit *init = ngl::NGLInit::instance();
  #ifdef WIN32
    glewInit();
  #endif
    init->initGlew();
    init->initVBO();

  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  // enable depth testing for drawing
  glEnable(GL_DEPTH_TEST);

  glEnable(GL_MULTISAMPLE);

  for(int i = 0; i < 5; i++)
  {
    glActiveTexture(GL_TEXTURE0+i);
    glEnable(GL_TEXTURE_2D);
  }

  m_cam.setShape(45,float(WIDTH/HEIGHT),0.1,300,ngl::PERSPECTIVE);
  m_frustum.generate(m_cam.getProjection() * m_cam.getModelView());

  //init shaders
  setupShaders();

  //init scene
  //m_scene.init();

  m_lightingManager.createLightGeometry();

  //geometry for unit screen quad
  createScreenQuad();

  setupTextures();

  postProcessSetup();

  //init fbos
  m_fbo.create(m_textureManager.getTextureId("constant"));
  m_shadowBuffer.create(m_textureManager.getTextureId("shadow"));

  m_fbo.bindTextureSlot(1, m_textureManager.getTextureId("normal"));
  m_fbo.bindTextureSlot(2, m_textureManager.getTextureId("albedo"));
  m_fbo.bindTextureSlot(3, m_textureManager.getTextureId("position"));

  m_lightingManager.addPointLight(ngl::Vector(2.0,0.0,4.0),4.0, ngl::Vector(0.7,0.7,0.7));
  m_lightingManager.addPointLight(ngl::Vector(-2.0,0.0,-4.0),4.0, ngl::Vector(1.0,0.7,0.7));
  m_lightingManager.addPointLight(ngl::Vector(2.0,0.0,-4.0),4.0, ngl::Vector(0.7,0.7,1.0));
  m_lightingManager.addPointLight(ngl::Vector(-2.0,0.0,4.0),4.0, ngl::Vector(0.7,0.7,0.0));
  m_lightingManager.addPointLight(ngl::Vector(3.0,0.0,0.0),4.0, ngl::Vector(1.0,0.0,1.0));
  m_lightingManager.addPointLight(ngl::Vector(-3.0,0.0,0.0),4.0, ngl::Vector(0.0,1.0,1.0));

  m_lightingManager.addShadowSpot(ngl::Vector(0,6,10),ngl::Vector(0,0,4),30.0,45.0,ngl::Vector(0.8,0.8,0.4),ngl::Vector(0,1,0));

  obj = new ngl::Obj("models/Troll.obj");
  obj->createVBO(GL_STATIC_DRAW);

  //set current main diaply texturer
  m_currentDisplay = m_textureManager.getTextureId("constant");

  //start update timer for lights
  //m_updatetimer = startTimer(10);
}

Here is the call graph for this function:

void GLWindow::lightAccumulation ( ) [private]

accumulate light onto our pixels

Definition at line 211 of file GLWindow.cpp.

References LightingManager::accumulateLights(), FrameBufferObject::activateTarget(), FrameBufferObject::bind(), Inverse(), m_cam, m_fbo, m_lightingManager, m_spinXFace, m_spinYFace, m_textureManager, and FrameBufferObject::unbind().

{
    m_fbo.bind();
    {
      m_fbo.activateTarget(0);

      ngl::Transformation trans;
      trans.setRotation(m_spinXFace,m_spinYFace,0);

      //get the camera pos in WS
      ngl::Matrix invView = Inverse(m_cam.getModelView() * trans.getMatrix());
      ngl::Vector camPos = invView * ngl::Vector(0,0,0,1);

      m_lightingManager.accumulateLights(m_textureManager, camPos);
    }
    m_fbo.unbind();

}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::mouseMoveEvent ( QMouseEvent *  _event) [private]

this method is called every time a mouse is moved

Parameters:
_eventthe Qt Event structure

Definition at line 621 of file GLWindow.cpp.

References m_origX, m_origY, m_rotate, m_spinXFace, and m_spinYFace.

{
  if(m_rotate && _event->buttons() == Qt::LeftButton)
  {
    m_spinYFace = ( m_spinYFace + (_event->x() - m_origX) ) % 360 ;
    m_spinXFace = ( m_spinXFace + (_event->y() - m_origY) ) % 360 ;
    m_origX = _event->x();
    m_origY = _event->y();
  }

  // re-draw GL
  updateGL();
}
void GLWindow::mousePressEvent ( QMouseEvent *  _event) [private]

this method is called everytime the mouse button is pressed

Parameters:
_eventthe Qt Event structure

Definition at line 639 of file GLWindow.cpp.

References m_origX, m_origY, and m_rotate.

{
  if(_event->button() == Qt::LeftButton)
  {
    m_origX = _event->x();
    m_origY = _event->y();
    m_rotate =true;
  }

}
void GLWindow::mouseReleaseEvent ( QMouseEvent *  _event) [private]

this method is called everytime the mouse button is released

Parameters:
_eventthe Qt Event structure

Definition at line 653 of file GLWindow.cpp.

References m_rotate.

{
  if (_event->button() == Qt::LeftButton)
  {
    m_rotate=false;
  }
}
void GLWindow::paintGL ( ) [protected]

this is the main gl drawing routine

Definition at line 230 of file GLWindow.cpp.

References debugPass(), ScreenQuad::draw(), Frustum::generate(), geometryPass(), ShadowSpot::getProj(), LightingManager::getShadowSpot(), lightAccumulation(), m_ambientColour, m_cam, m_currentDisplay, m_debug, m_directionalColour, m_directionalVec, m_frustum, m_Ka, m_Kd, m_lightingManager, m_screenQuadVAO, ShadowSpot::m_shadowView, m_spinXFace, m_spinYFace, m_viewportQuad, m_wireframe, postProcess(), and postProcessUniforms().

{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  ngl::Transformation trans;
  trans.setRotation(m_spinXFace,m_spinYFace,0);

  ngl::Matrix projView = m_cam.getProjection() * (m_cam.getModelView() * trans.getMatrix());
  ngl::Matrix view = m_cam.getModelView() * trans.getMatrix();

  m_frustum.generate(projView);

  if(m_wireframe)
  {
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }
  else
  {
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }

  ngl::ShaderManager *shader = ngl::ShaderManager::instance();

  /******************
   Shadow pass
   *********************/
  //shadowPass();
  /**************************************/

  /******************
    Gpass
    ********************/
  (*shader)["Gbuffer"]->use();
  shader->setShaderParamFromMatrix("Gbuffer", "u_ViewMatrix", view);
  shader->setShaderParam3f("Gbuffer","u_AmbientLight",m_ambientColour.m_x,m_ambientColour.m_y,m_ambientColour.m_z);
  shader->setShaderParam3f("Gbuffer","u_DirectionalLightVec",m_directionalVec.m_x,m_directionalVec.m_y,m_directionalVec.m_z);
  shader->setShaderParam3f("Gbuffer","u_DirectionalLight",m_directionalColour.m_x,m_directionalColour.m_y,m_directionalColour.m_z);
  shader->setShaderParam3f("Gbuffer", "u_KaKdKs", m_Ka,m_Kd,0.0);
  geometryPass();
  /*************************************/

  /******************
    light accumulation
    *********************/
  (*shader)["PointLight"]->use();
  shader->setShaderParamFromMatrix("PointLight", "u_ViewMatrix", view);

  (*shader)["DemoPL"]->use();
  shader->setShaderParamFromMatrix("DemoPL", "u_ViewMatrix", view);

  (*shader)["SpotLight"]->use();
  shader->setShaderParamFromMatrix("SpotLight", "u_ViewMatrix", view);

  (*shader)["ShadowSpot"]->use();
  shader->setShaderParamFromMatrix("ShadowSpot", "u_ViewMatrix", view);
  shader->setShaderParamFromMatrix("ShadowSpot", "u_LightView", m_lightingManager.getShadowSpot(0).m_shadowView);
  shader->setShaderParamFromMatrix("ShadowSpot", "u_LightProj",m_lightingManager.getShadowSpot(0).getProj());

  lightAccumulation();

  /***************************************/

  /******************
    Post-process
    ********************/
  postProcessUniforms();
  postProcess();
  /***************************************/


  /******************
    debug gpass
    ********************/
  if(m_debug)
  {
      (*shader)["ScreenQuad"]->use();
      debugPass();
  }
  /***************************************/

  /******************
    final
    *********************/

  (*shader)["ScreenQuad"]->use();
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D,  m_currentDisplay);

  m_viewportQuad.draw("ScreenQuad",m_screenQuadVAO);
  glBindTexture(GL_TEXTURE_2D, 0);

  /*************************************/

}

Here is the call graph for this function:

void GLWindow::postProcess ( ) [private]

run the post processing chain

Definition at line 392 of file GLWindow.cpp.

References PostProcessor::doEffect(), PostProcessor::finish(), m_postProcessor, and PostProcessor::start().

{
    m_postProcessor.start();
    {
        //always do AA
        m_postProcessor.doEffect("AntiAlias");

        //grab a blur texture
        m_postProcessor.doEffect("HorizontalBlur");
        m_postProcessor.doEffect("VerticalBlur");

        //do depth of field
        m_postProcessor.doEffect("DoF");

        m_postProcessor.doEffect("BrightPass");
        m_postProcessor.doEffect("BloomHBlur");
        m_postProcessor.doEffect("BloomGaussian");
        m_postProcessor.doEffect("Bloom");

        //m_postProcessor.doEffect("Grayscale");
        //m_postProcessor.doEffect("Sepia");
    }
    m_postProcessor.finish();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::postProcessSetup ( ) [private]

setup the post processor chain

Definition at line 335 of file GLWindow.cpp.

References PostProcessor::addEffect(), Effect::addSourceTexture(), addStandardEffect(), TextureManager::getTextureId(), HEIGHT, m_postProcessor, m_screenQuadVAO, m_textureManager, and WIDTH.

{
    m_postProcessor = PostProcessor(WIDTH, HEIGHT, m_screenQuadVAO);

    Effect antiAlias(m_textureManager.getTextureId("antialias"), "AntiAlias");
    antiAlias.addSourceTexture("u_ColorMap", m_textureManager.getTextureId("constant"));
    antiAlias.addSourceTexture("u_NormalMap", m_textureManager.getTextureId("normal"));
    antiAlias.addSourceTexture("u_PositionMap", m_textureManager.getTextureId("position"));
    m_postProcessor.addEffect("AntiAlias", antiAlias);

    Effect depthOfField(m_textureManager.getTextureId("DoF"), "DoF");
    depthOfField.addSourceTexture("u_ColorMap", m_textureManager.getTextureId("antialias"));
    depthOfField.addSourceTexture("u_BlurMap", m_textureManager.getTextureId("gaussian"));
    depthOfField.addSourceTexture("u_PositionMap", m_textureManager.getTextureId("position"));
    m_postProcessor.addEffect("DoF", depthOfField);

    addStandardEffect("HorizontalBlur", "horizontalBlur", "HorizontalBlur", "antialias");
    addStandardEffect("VerticalBlur", "gaussian", "VerticalBlur", "horizontalBlur");
    addStandardEffect("Grayscale", "grayscale", "Grayscale", "antialias");
    addStandardEffect("Sepia", "sepia", "Sepia", "antialias");

    addStandardEffect("BrightPass", "brightPass", "BrightPass", "antialias");
    addStandardEffect("BloomHBlur", "bloomHBlur", "HorizontalBlur", "brightPass");
    addStandardEffect("BloomGaussian", "bloomGaussian", "VerticalBlur", "bloomHBlur");

    Effect bloom(m_textureManager.getTextureId("bloom"), "Bloom");
    bloom.addSourceTexture("u_BrightMap", m_textureManager.getTextureId("bloomGaussian"));
    bloom.addSourceTexture("u_ColorMap", m_textureManager.getTextureId("antialias"));
    m_postProcessor.addEffect("Bloom", bloom);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::postProcessUniforms ( ) [private]

setup shader uniforms for post process

Definition at line 366 of file GLWindow.cpp.

References m_AAbarrierDepth, m_AAbarrierNorm, m_AAkernel, m_AAweightDepth, m_AAweightNorm, m_cam, m_spinXFace, and m_spinYFace.

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();

    (*shader)["AntiAlias"]->use();

    shader->setShaderParam4f("AntiAlias",
                             "u_barrierWeights",
                             m_AAbarrierNorm,
                             m_AAbarrierDepth,
                             m_AAweightNorm,
                             m_AAweightDepth
                             );

    shader->setShaderParam1f("AntiAlias", "u_kernel", m_AAkernel);

    (*shader)["DoF"]->use();

    shader->setShaderParam1f("DoF", "u_FocalDepth", 0.5);
    ngl::Transformation trans;
    trans.setRotation(m_spinXFace,m_spinYFace,0);

    ngl::Matrix projView = m_cam.getProjection() * (m_cam.getModelView() * trans.getMatrix());
    shader->setShaderParamFromMatrix("DoF", "u_ProjView", projView);
}

Here is the caller graph for this function:

void GLWindow::processKeyPress ( QKeyEvent *  _event)

GL key events processing.

Parameters:
[in]_eventthe event infomation

Definition at line 663 of file GLWindow.cpp.

{
    switch (_event->key())
    {
    default : break;
    }
}

Here is the caller graph for this function:

void GLWindow::resizeGL ( const int  _w,
const int  _h 
) [inline, protected]

Re-size method, disabled in this application.

Definition at line 235 of file GLWindow.h.

References m_windowHeight, and m_windoWidth.

void GLWindow::setAmbientColourB ( double  _value) [inline, slot]

set the global ambient light col for the scene

Parameters:
[in]_valuethe new B ambient light colour

Definition at line 127 of file GLWindow.h.

References m_ambientColour.

  {
      m_ambientColour.m_z = _value;
      updateGL();
  }
void GLWindow::setAmbientColourG ( double  _value) [inline, slot]

set the global ambient light col for the scene

Parameters:
[in]_valuethe new G ambient light colour

Definition at line 119 of file GLWindow.h.

References m_ambientColour.

  {
      m_ambientColour.m_y = _value;
      updateGL();
  }
void GLWindow::setAmbientColourR ( double  _value) [inline, slot]

set the global ambient light col for the scene

Parameters:
[in]_valuethe new R ambient light colour

Definition at line 111 of file GLWindow.h.

References m_ambientColour.

  {
      m_ambientColour.m_x = _value;
      updateGL();
  }
void GLWindow::setDColourB ( double  _value) [inline, slot]

set the global directional light col for the scene

Parameters:
[in]_valuethe new B ambient light colour

Definition at line 151 of file GLWindow.h.

References m_directionalColour.

  {
      m_directionalColour.m_z = _value;
      updateGL();
  }
void GLWindow::setDColourG ( double  _value) [inline, slot]

set the global directional light col for the scene

Parameters:
[in]_valuethe new G ambient light colour

Definition at line 143 of file GLWindow.h.

References m_directionalColour.

  {
      m_directionalColour.m_y = _value;
      updateGL();
  }
void GLWindow::setDColourR ( double  _value) [inline, slot]

set the global directional light col for the scene

Parameters:
[in]_valuethe new R ambient light colour

Definition at line 135 of file GLWindow.h.

References m_directionalColour.

  {
      m_directionalColour.m_x = _value;
      updateGL();
  }
void GLWindow::setDVecX ( double  _value) [inline, slot]

set the global directional light for the scene

Parameters:
[in]_valuethe new directional light vec X dir

Definition at line 87 of file GLWindow.h.

References m_directionalVec.

  {
      m_directionalVec.m_x = _value;
      updateGL();
  }
void GLWindow::setDVecY ( double  _value) [inline, slot]

set the global directional light for the scene

Parameters:
[in]_valuethe new directional light vec Y dir

Definition at line 95 of file GLWindow.h.

References m_directionalVec.

  {
      m_directionalVec.m_y = _value;
      updateGL();
  }
void GLWindow::setDVecZ ( double  _value) [inline, slot]

set the global directional light for the scene

Parameters:
[in]_valuethe new directional light vec Z dir

Definition at line 103 of file GLWindow.h.

References m_directionalVec.

  {
      m_directionalVec.m_z = _value;
      updateGL();
  }
void GLWindow::setKa ( double  _value) [inline, slot]

set the ambient coefficient for the scene

Parameters:
[in]_valuethe new Ka value

Definition at line 71 of file GLWindow.h.

References m_Ka.

  {
      m_Ka = (float)_value;
      updateGL();
  }
void GLWindow::setKd ( double  _value) [inline, slot]

set the diffuse coefficient for the scene

Parameters:
[in]_valuethe new value for Kd

Definition at line 79 of file GLWindow.h.

References m_Kd.

  {
      m_Kd = (float)_value;
      updateGL();
  }
void GLWindow::setMainDisplay ( int  _displayMode) [slot]

the mode for the main screen quad, binds our render targets to it

Parameters:
[in]_displayModethe new mode of display

Definition at line 417 of file GLWindow.cpp.

References PostProcessor::getFinalComposite(), TextureManager::getTextureId(), m_currentDisplay, m_postProcessor, and m_textureManager.

{
    switch(_mode)
    {
    case 0:
        m_currentDisplay =  m_textureManager.getTextureId("constant");
        break;
    case 1:
        m_currentDisplay =  m_textureManager.getTextureId("normal");
        break;
    case 2:
        m_currentDisplay =  m_textureManager.getTextureId("albedo");
        break;
    case 3:
        m_currentDisplay =  m_textureManager.getTextureId("position");
        break;
    case 4:
        m_currentDisplay =  m_textureManager.getTextureId("antialias");
        break;
    case 5:
        m_currentDisplay =  m_textureManager.getTextureId("gaussian");
        break;
    case 6:
        m_currentDisplay =  m_postProcessor.getFinalComposite();
        break;
    default:
        break;
    }

    updateGL();
}

Here is the call graph for this function:

void GLWindow::setupShaders ( ) [private]

setup our application shaders

Definition at line 502 of file GLWindow.cpp.

References genShader(), HEIGHT, m_cam, and WIDTH.

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();

    std::vector<std::string> attrs;
    attrs.push_back("a_VertexPosition");
    attrs.push_back("a_TextureCoord");

    genShader("ScreenQuad", "shaders/ScreenQuad.vs", "shaders/ScreenQuad.fs", attrs);

    genShader("Grayscale", "shaders/ScreenQuad.vs", "shaders/postProcess/Grayscale.fs", attrs);

    genShader("Sepia", "shaders/ScreenQuad.vs", "shaders/postProcess/Sepia.fs", attrs);

    genShader("BrightPass", "shaders/ScreenQuad.vs", "shaders/postProcess/BrightPass.fs", attrs);

    genShader("Bloom", "shaders/ScreenQuad.vs", "shaders/postProcess/Bloom.fs", attrs);

    genShader("HorizontalBlur", "shaders/ScreenQuad.vs", "shaders/postProcess/HorizontalBlur.fs", attrs);
    shader->setShaderParam1f("HorizontalBlur", "u_pixel", 1.0/(float)WIDTH);

    genShader("VerticalBlur", "shaders/ScreenQuad.vs", "shaders/postProcess/VerticalBlur.fs", attrs);
    shader->setShaderParam1f("VerticalBlur", "u_pixel", 1.0/(float)HEIGHT);

    genShader("AntiAlias", "shaders/ScreenQuad.vs", "shaders/postProcess/AntiAlias.fs", attrs);
    shader->setShaderParam2f("AntiAlias", "u_pixel", 1.0/768.0, 1.0/(float)WIDTH);

    genShader("DoF", "shaders/ScreenQuad.vs", "shaders/postProcess/DoF.fs", attrs);

    attrs.clear();

    attrs.push_back("inVert");
    attrs.push_back("inUV");
    attrs.push_back("inNormal");
    attrs.push_back("inTangent");
    attrs.push_back("inBinormal");

    genShader("Gbuffer", "shaders/Gbuffer.vs", "shaders/Gbuffer.fs", attrs);
    shader->setShaderParamFromMatrix("Gbuffer", "u_ProjectionMatrix",m_cam.getProjection());

    attrs.clear();

    genShader("ShadowBuffer", "shaders/SpotShadowPass.vs", "shaders/SpotShadowPass.fs", attrs);

    attrs.push_back("a_VertexPosition");
    genShader("PointLight", "shaders/lights/PointLight.vs", "shaders/lights/PointLight.fs", attrs);
    shader->setShaderParamFromMatrix("PointLight", "u_ProjectionMatrix",m_cam.getProjection());
    shader->setShaderParam1i("PointLight","u_NormalMap",1);
    shader->setShaderParam1i("PointLight","u_AlbedoMap",2);
    shader->setShaderParam1i("PointLight","u_PositionMap",3);

    attrs.clear();
    genShader("SpotLight", "shaders/lights/SpotLight.vs", "shaders/lights/SpotLight.fs", attrs);
    shader->setShaderParamFromMatrix("SpotLight", "u_ProjectionMatrix",m_cam.getProjection());
    shader->setShaderParam1i("SpotLight","u_NormalMap",1);
    shader->setShaderParam1i("SpotLight","u_AlbedoMap",2);
    shader->setShaderParam1i("SpotLight","u_PositionMap",3);

    genShader("ShadowSpot", "shaders/lights/ShadowSpot.vs", "shaders/lights/ShadowSpot.fs", attrs);
    shader->setShaderParamFromMatrix("ShadowSpot", "u_ProjectionMatrix",m_cam.getProjection());
    shader->setShaderParam1i("ShadowSpot","u_NormalMap",1);
    shader->setShaderParam1i("ShadowSpot","u_AlbedoMap",2);
    shader->setShaderParam1i("ShadowSpot","u_PositionMap",3);
    shader->setShaderParam1i("ShadowSpot","u_ShadowMap",4);

    attrs.push_back("a_VertPos");
    genShader("DemoPL", "shaders/VisiblePLDemo.vs", "shaders/VisiblePLDemo.fs", attrs);
    shader->setShaderParamFromMatrix("DemoPL", "u_ProjectionMatrix",m_cam.getProjection());
    attrs.clear();

}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::setupTextures ( ) [private]

setup our applictaion textures

Definition at line 477 of file GLWindow.cpp.

References TextureManager::addEmpty(), TextureManager::addEmptyf(), TextureManager::addTexture(), Texture::generateEmpty(), HEIGHT, m_textureManager, and WIDTH.

Here is the call graph for this function:

Here is the caller graph for this function:

void GLWindow::shadowPass ( ) [private]

shadow pass for our shadowspot

Definition at line 138 of file GLWindow.cpp.

References FrameBufferObject::activateTarget(), FrameBufferObject::bind(), ShadowSpot::getProj(), LightingManager::getShadowSpot(), m_lightingManager, m_shadowBuffer, ShadowSpot::m_shadowView, and FrameBufferObject::unbind().

{
    ngl::ShaderManager *shader = ngl::ShaderManager::instance();
    (*shader)["ShadowBuffer"]->use();

    shader->setShaderParamFromMatrix("ShadowBuffer", "u_LightView", m_lightingManager.getShadowSpot(0).m_shadowView);
    shader->setShaderParamFromMatrix("ShadowBuffer", "u_LightProj", m_lightingManager.getShadowSpot(0).getProj());

    glClearColor(0.f, 0.f, 0.f, 1.0f);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    //bind shadow buffer
    m_shadowBuffer.bind();
    {
        m_shadowBuffer.activateTarget(0);

    }
    m_shadowBuffer.unbind();

    glDisable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
}

Here is the call graph for this function:

void GLWindow::timerEvent ( QTimerEvent *  _event) [protected]

timer event for updating the demo scene

Parameters:
[in]_eventqt event info

Definition at line 671 of file GLWindow.cpp.

References m_time, m_timeStep, and m_updatetimer.

{
  if(_event->timerId() == m_updatetimer)
  {

    m_time += m_timeStep;
    //m_scene.moveLights(m_time);
    updateGL();
  }
}
void GLWindow::toggleDebug ( bool  _mode) [inline, slot]

set the debug display

Parameters:
[in]_modethe mode to set debug diaplsy to

Definition at line 62 of file GLWindow.h.

References m_debug.

  {
      m_debug = _mode;
      updateGL();
  }
void GLWindow::toggleShadowMap ( bool  _mode) [inline, slot]

a slot to toggle showing shadowmap

Parameters:
[in]_modethe mode to set shadow map to

Definition at line 54 of file GLWindow.h.

References m_showShadowMap.

  {
      m_showShadowMap = _mode;
      updateGL();
  }
void GLWindow::toggleWireframe ( bool  _mode) [inline, slot]

a slot to toggle wireframe mode

Parameters:
[in]_modethe mode to wireframe to

Definition at line 46 of file GLWindow.h.

References m_wireframe.

  {
      m_wireframe = _mode;
      updateGL();
  }

Member Data Documentation

float GLWindow::m_AAbarrierDepth [protected]

Definition at line 204 of file GLWindow.h.

float GLWindow::m_AAbarrierNorm [protected]

anti aliasing kernel variables

Definition at line 204 of file GLWindow.h.

float GLWindow::m_AAkernel [protected]

Definition at line 204 of file GLWindow.h.

float GLWindow::m_AAweightDepth [protected]

Definition at line 204 of file GLWindow.h.

float GLWindow::m_AAweightNorm [protected]

Definition at line 204 of file GLWindow.h.

ngl::Vector GLWindow::m_ambientColour [private]

the global directional vector

Definition at line 354 of file GLWindow.h.

ngl::Camera GLWindow::m_cam [private]

our ngl camera

Definition at line 328 of file GLWindow.h.

int GLWindow::m_currentDisplay [protected]

the current main display texture

Definition at line 214 of file GLWindow.h.

bool GLWindow::m_debug [private]

debug mode on/off

Definition at line 317 of file GLWindow.h.

debug quad bottom left

Definition at line 338 of file GLWindow.h.

debug quad bottom middle-left

Definition at line 340 of file GLWindow.h.

debug quad bottom middle-right

Definition at line 342 of file GLWindow.h.

debug quad bottom right

Definition at line 344 of file GLWindow.h.

debug quad top left

Definition at line 346 of file GLWindow.h.

debug quad top right

Definition at line 348 of file GLWindow.h.

ngl::Vector GLWindow::m_directionalColour [private]

the global directional vector

Definition at line 357 of file GLWindow.h.

ngl::Vector GLWindow::m_directionalVec [private]

the global directional vector

Definition at line 351 of file GLWindow.h.

maine fbo for gpass

Definition at line 323 of file GLWindow.h.

out camera frustum

Definition at line 321 of file GLWindow.h.

float GLWindow::m_Ka [private]

the ambient coefficient of the gpass

Definition at line 311 of file GLWindow.h.

float GLWindow::m_Kd [private]

the diffuse coefficient of the gpass

Definition at line 313 of file GLWindow.h.

controls out applications lights

Definition at line 301 of file GLWindow.h.

int GLWindow::m_origX [protected]

the previous x mouse value

Definition at line 226 of file GLWindow.h.

int GLWindow::m_origY [protected]

the previous y mouse value

Definition at line 229 of file GLWindow.h.

unsigned int GLWindow::m_pointLightVAO [private]

out point light vao id

Definition at line 331 of file GLWindow.h.

our post processor

Definition at line 363 of file GLWindow.h.

bool GLWindow::m_rotate [protected]

flag to indicate if the mouse button is pressed when dragging

Definition at line 223 of file GLWindow.h.

unsigned int GLWindow::m_screenQuadVAO [private]

our screen quad vao id

Definition at line 335 of file GLWindow.h.

shadow fbo for shadowpass

Definition at line 325 of file GLWindow.h.

bool GLWindow::m_showShadowMap [private]

check whether to display our shadowmap

Definition at line 360 of file GLWindow.h.

int GLWindow::m_spinXFace [protected]

used to store the x rotation mouse value

Definition at line 217 of file GLWindow.h.

int GLWindow::m_spinYFace [protected]

used to store the y rotation mouse value

Definition at line 220 of file GLWindow.h.

std::string GLWindow::m_spotLightName [private]

spotlight name for ngl vboprimitives

Definition at line 333 of file GLWindow.h.

controls our applications texture

Definition at line 298 of file GLWindow.h.

float GLWindow::m_time [private]

current time variable

Definition at line 307 of file GLWindow.h.

float GLWindow::m_timeStep [private]

the increment for out time variable

Definition at line 309 of file GLWindow.h.

ngl::TransformStack GLWindow::m_transformStack [protected]

the transformation stack

Definition at line 248 of file GLWindow.h.

int GLWindow::m_updatetimer [private]

update timer for demo scene

Definition at line 304 of file GLWindow.h.

our main viewport quad

Definition at line 319 of file GLWindow.h.

int GLWindow::m_windowHeight [private]

Definition at line 368 of file GLWindow.h.

int GLWindow::m_windoWidth [private]

Definition at line 368 of file GLWindow.h.

bool GLWindow::m_wireframe [private]

wireframe mode on/off

Definition at line 315 of file GLWindow.h.

ngl::Obj* GLWindow::obj [private]

a demo obj

Definition at line 366 of file GLWindow.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines