DeferredRenderer 1.0
|
00001 #include "PostProcessor.h" 00002 #include "Texture.h" 00003 #include "ngl/ShaderManager.h" 00004 #include "sstream" 00005 00006 PostProcessor::PostProcessor(int _w, int _h, GLuint _vao): 00007 m_screenQuad(0.0f, 0.0f, 0.5f, 1.0f), 00008 m_width(_w), 00009 m_height(_h), 00010 m_fbo(_w,_h), 00011 m_vao(_vao), 00012 m_currentAttachment(0) 00013 { 00014 Texture tmp("tmp"); 00015 tmp.generateEmpty(_w, _h); 00016 m_fbo.create(tmp.id); 00017 } 00018 00019 void PostProcessor::addEffect(const std::string &_effectName, Effect _e) 00020 { 00021 m_effects.insert(std::pair<std::string, Effect>(_effectName, _e)); 00022 } 00023 00024 void PostProcessor::start() 00025 { 00026 m_fbo.bind(); 00027 00028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00029 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00030 } 00031 00032 void PostProcessor::doEffect(const std::string &_effectName) 00033 { 00034 m_fbo.bindTextureSlot(m_currentAttachment, m_effects[_effectName].getOutputId()); 00035 m_fbo.activateTarget(m_currentAttachment); 00036 00037 m_currentAttachment++; 00038 if(m_currentAttachment > 3) 00039 m_currentAttachment = 0; 00040 00041 m_effects[_effectName].prepare(); 00042 00043 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00044 00045 m_screenQuad.draw(m_effects[_effectName].getShaderName(), m_vao); 00046 00047 m_finalComposite = m_effects[_effectName].getOutputId(); 00048 } 00049