예제 #1
0
void Renderer::render()
{

    for(auto cameraIter = activeCameras.begin(); cameraIter < activeCameras.end(); cameraIter++){
        (*cameraIter)->update();

    // Geometry pass
    renderGeometryPass( **cameraIter );
    // light pass
    renderLightPass( **cameraIter );
    
    }
}
예제 #2
0
파일: NGLDraw.cpp 프로젝트: NCCA/webgl
void NGLDraw::draw()
{
  glBindFramebuffer (GL_FRAMEBUFFER, m_gbuffer);
  /*************************************************************************************************/
  // Geo Pass
  /*************************************************************************************************/

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1,GL_COLOR_ATTACHMENT2,GL_COLOR_ATTACHMENT3};
  glDrawBuffers (4, drawBuffers);

  drawScene("Pass1");
  /*************************************************************************************************/
  // now do the light pass
  /*************************************************************************************************/
  glBindFramebuffer (GL_FRAMEBUFFER, m_lightBuffer);
  GLenum lightBuffers[] = { GL_COLOR_ATTACHMENT0};
  glDrawBuffers (1, lightBuffers);

  glClear (GL_COLOR_BUFFER_BIT);

  // map the texture buffers so light pass can read them
 glActiveTexture (GL_TEXTURE0);
 glBindTexture (GL_TEXTURE_2D, m_pointTexID);
 glActiveTexture (GL_TEXTURE1);
 glBindTexture (GL_TEXTURE_2D, m_normalTexID);
 glActiveTexture (GL_TEXTURE2);
 glBindTexture (GL_TEXTURE_2D, m_colourTexID);
 glActiveTexture (GL_TEXTURE3);
 glBindTexture (GL_TEXTURE_2D, m_shadingTexID);
 glActiveTexture (GL_TEXTURE4);
 glBindTexture (GL_TEXTURE_2D, m_lightPassTexID);



 glGenerateMipmap(GL_TEXTURE_2D);

 glClear(GL_COLOR_BUFFER_BIT);

 renderLightPass("Lighting");

  glActiveTexture (GL_TEXTURE0);
  glBindTexture (GL_TEXTURE_2D, m_pointTexID);
  glActiveTexture (GL_TEXTURE1);
  glBindTexture (GL_TEXTURE_2D, m_normalTexID);
  glActiveTexture (GL_TEXTURE2);
  glBindTexture (GL_TEXTURE_2D, m_colourTexID);
  glActiveTexture (GL_TEXTURE3);
  glBindTexture (GL_TEXTURE_2D, m_shadingTexID);
  glActiveTexture (GL_TEXTURE4);
  glBindTexture (GL_TEXTURE_2D, m_lightPassTexID);



  // now blit

//  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//  glBindFramebuffer(GL_READ_FRAMEBUFFER, m_lightBuffer);

//  glReadBuffer(GL_COLOR_ATTACHMENT0+m_debugMode);
//  int w=width()*devicePixelRatio();
//  int h=height()*devicePixelRatio();

//  glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);

  if(m_debug==true)
  {
    glBindFramebuffer (GL_FRAMEBUFFER, 0);
    glActiveTexture (GL_TEXTURE0);
    glBindTexture (GL_TEXTURE_2D, m_pointTexID);
    glActiveTexture (GL_TEXTURE1);
    glBindTexture (GL_TEXTURE_2D, m_normalTexID);
    glActiveTexture (GL_TEXTURE2);
    glBindTexture (GL_TEXTURE_2D, m_colourTexID);
    glActiveTexture (GL_TEXTURE3);
    glBindTexture (GL_TEXTURE_2D, m_shadingTexID);
    glActiveTexture (GL_TEXTURE4);
    glBindTexture (GL_TEXTURE_2D, m_lightPassTexID);

    glGenerateMipmap(GL_TEXTURE_2D);

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    ngl::ShaderLib *shader = ngl::ShaderLib::instance();

    shader->use("Debug");
    //shader->setUniform("cam",m_cam->getEye().toVec3());
    shader->setShaderParam1i("mode",m_debugMode);
    m_screenQuad->draw();

  }

  // calculate and draw FPS
  glBindFramebuffer (GL_FRAMEBUFFER, 0);

  ++m_frames;
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  m_text->setColour(1,1,0);
 // QString text=QString("%1 fps using %2 to draw").arg(m_fps).arg(m_debug ? "ScreenQuad" : "glBlitFramebuffer");
 // m_text->renderText(10,20,text);

}