Pps.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "Renderer.h"
  2. //======================================================================================================================
  3. // init =
  4. //======================================================================================================================
  5. void Renderer::Pps::init()
  6. {
  7. // create FBO
  8. fbo.create();
  9. fbo.bind();
  10. // inform in what buffers we draw
  11. fbo.setNumOfColorAttachements( 1 );
  12. // create the texes
  13. fai.createEmpty2D( r.width, r.height, GL_RGB, GL_RGB );
  14. // attach
  15. glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fai.getGlId(), 0 );
  16. // test if success
  17. if( !fbo.isGood() )
  18. FATAL( "Cannot create post-processing stage FBO" );
  19. fbo.unbind();
  20. // init the shader and it's vars
  21. string pps = "";
  22. if( ssao.enabled )
  23. {
  24. pps += "#define _SSAO_\n";
  25. }
  26. if( hdr.enabled )
  27. {
  28. pps += "#define _HDR_\n";
  29. }
  30. sProg.customLoad( "shaders/Pps.glsl", pps.c_str() );
  31. sProg.bind();
  32. sProg.uniVars.isFai = sProg.findUniVar( "isFai" );
  33. if( ssao.enabled )
  34. {
  35. ssao.init();
  36. sProg.uniVars.ppsSsaoFai = sProg.findUniVar( "ppsSsaoFai" );
  37. }
  38. if( hdr.enabled )
  39. {
  40. hdr.init();
  41. sProg.uniVars.hdrFai = sProg.findUniVar( "ppsHdrFai" );
  42. }
  43. /// @ todo enable lscatt
  44. /*if( R::Pps::Lscatt::enabled )
  45. {
  46. R::Pps::Lscatt::init();
  47. sProg.uniVars.lscattFai = sProg.findUniVar( "ppsLscattFai" )->getLoc();
  48. }*/
  49. }
  50. //======================================================================================================================
  51. // run =
  52. //======================================================================================================================
  53. void Renderer::Pps::run()
  54. {
  55. if( ssao.enabled )
  56. ssao.run();
  57. if( hdr.enabled )
  58. hdr.run();
  59. fbo.bind();
  60. // set GL
  61. glDisable( GL_DEPTH_TEST );
  62. glDisable( GL_BLEND );
  63. Renderer::setViewport( 0, 0, r.width, r.height );
  64. // set shader
  65. sProg.bind();
  66. sProg.uniVars.isFai->setTexture( r.is.fai, 0 );
  67. if( hdr.enabled )
  68. {
  69. sProg.uniVars.hdrFai->setTexture( hdr.fai, 1 );
  70. }
  71. if( ssao.enabled )
  72. {
  73. sProg.uniVars.ppsSsaoFai->setTexture( ssao.fai, 2 );
  74. }
  75. // draw quad
  76. Renderer::drawQuad( 0 );
  77. // unbind FBO
  78. fbo.unbind();
  79. }