r_ms.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. #include "renderer.hpp"
  3. #include "Scene.h"
  4. //=====================================================================================================================================
  5. // init =
  6. //=====================================================================================================================================
  7. void renderer_t::material_stage_t::init()
  8. {
  9. // create FBO
  10. fbo.create();
  11. fbo.bind();
  12. // inform in what buffers we draw
  13. fbo.setNumOfColorAttachements(3);
  14. // create buffers
  15. const int internal_format = GL_RGBA16F_ARB;
  16. fais.normal.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
  17. fais.diffuse.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
  18. fais.specular.CreateEmpty( renderer.width, renderer.height, internal_format, GL_RGBA );
  19. fais.depth.CreateEmpty( renderer.width, renderer.height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT );
  20. // you could use the above for SSAO but the difference is minimal.
  21. //depthFai.texParameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  22. //depthFai.texParameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  23. // attach the buffers to the FBO
  24. glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fais.normal.getGlId(), 0 );
  25. glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, fais.diffuse.getGlId(), 0 );
  26. glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, fais.specular.getGlId(), 0 );
  27. glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, fais.depth.getGlId(), 0 );
  28. // test if success
  29. if( !fbo.isGood() )
  30. FATAL( "Cannot create deferred shading material pass FBO" );
  31. // unbind
  32. fbo.unbind();
  33. }
  34. //=====================================================================================================================================
  35. // Run =
  36. //=====================================================================================================================================
  37. void renderer_t::material_stage_t::Run() const
  38. {
  39. fbo.bind();
  40. glClear( GL_DEPTH_BUFFER_BIT );
  41. renderer.matrices.view = renderer.camera->getViewMatrix();
  42. renderer.matrices.projection = renderer.camera->getProjectionMatrix();
  43. renderer.setViewport( 0, 0, renderer.width, renderer.height );
  44. //glEnable( GL_DEPTH_TEST );
  45. Scene::skybox.render( renderer.camera->getViewMatrix().getRotationPart() );
  46. //glDepthFunc( GL_LEQUAL );
  47. // render the meshes
  48. for( uint i=0; i<Scene::meshes.size(); i++ )
  49. render<Mesh, false>( Scene::meshes[i] );
  50. // render the smodels
  51. for( uint i=0; i<Scene::smodels.size(); i++ )
  52. render<smodel_t, false>( Scene::smodels[i] );
  53. glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode
  54. fbo.unbind();
  55. }
  56. */