void HDRStage::updateData(RenderAction *pAction, Int32 iVPWidth, Int32 iVPHeight) { HDRStageDataUnrecPtr pData = pAction->getData<HDRStageData *>(_iDataSlotId); if(pData == NULL) { initData(pAction, iVPWidth, iVPHeight); pData = pAction->getData<HDRStageData *>(_iDataSlotId); } else if((pData->getWidth () != iVPWidth ) || (pData->getHeight() != iVPHeight) ) { resizeStageData(pData, iVPWidth, iVPHeight); pData->setWidth (iVPWidth ); pData->setHeight(iVPHeight); } ChunkMaterial* pTonemapMat = pData->getToneMappingMaterial(); BlendChunk* pBlendChunk = static_cast<BlendChunk*>( pTonemapMat->find(BlendChunk::getClassType())); if(pBlendChunk != NULL) pBlendChunk->setIgnore(!getCombineBlend()); }
void PostShaderStage::postProcess(DrawEnv *pEnv) { Window *win = pEnv->getWindow(); if(win->hasExtension(_uiFramebuffer_object_extension) == false || win->hasExtension(_extDepthTexture ) == false) { FNOTICE(("Framebuffer objects not supported on Window %p!\n", win)); return; } GLDrawBuffersEXTProcT glDrawBuffersEXTProc = reinterpret_cast<GLDrawBuffersEXTProcT>( win->getFunction(_uiFuncDrawBuffers)); glColor3f(1.f, 1.f, 1.f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); PostShaderStageData *pData = pEnv->getData<PostShaderStageData *>(_iDataSlotId); if(pData == NULL) { return; } if((pData->getWidth () != pEnv->getPixelWidth() ) || (pData->getHeight() != pEnv->getPixelHeight()) ) { resizeStageData(pData, pEnv->getPixelWidth(), pEnv->getPixelHeight()); } // PostShader pass glDisable(GL_DEPTH_TEST); //Render each pass for(RenderPassVector::iterator PassItor(_PostProcessPasses.begin()) ; PassItor != _PostProcessPasses.end() ; ++PassItor) { (*PassItor)->draw(pEnv, pData); } glEnable(GL_DEPTH_TEST); pEnv->deactivateState(); glPopMatrix(); }
void DepthPeelingStage::updateData(RenderAction *a, Int32 iVPWidth, Int32 iVPHeight) { DepthPeelingStageDataUnrecPtr pData = a->getData<DepthPeelingStageData *>(_iDataSlotId); if(!pData) { initData(a, iVPWidth, iVPHeight); } else if((pData->getWidth () != iVPWidth ) || (pData->getHeight() != iVPHeight) ) { resizeStageData(pData, iVPWidth, iVPHeight); pData->setWidth (iVPWidth ); pData->setHeight(iVPHeight); } }
void HDRStage::postProcess(DrawEnv *pEnv) { Window *win = pEnv->getWindow(); if(win->hasExtension(_uiFramebuffer_object_extension) == false) { FNOTICE(("Framebuffer objects not supported on Window %p!\n", win)); return; } GLDrawBuffersEXTProcT glDrawBuffersEXTProc = reinterpret_cast<GLDrawBuffersEXTProcT>( win->getFunction(_uiFuncDrawBuffers)); glColor3f(1.f, 1.f, 1.f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); HDRStageData *pData = pEnv->getData<HDRStageData *>(_iDataSlotId); if(pData == NULL) { return; } if((pData->getWidth () != pEnv->getPixelWidth() ) || (pData->getHeight() != pEnv->getPixelHeight()) ) { resizeStageData(pData, pEnv->getPixelWidth(), pEnv->getPixelHeight()); } // Shrink to w/2 h/2 FrameBufferObject *pShrinkTarget = pData->getShrinkRenderTarget(); ChunkMaterial *pSHM = pData->getShrinkMaterial(); pShrinkTarget->activate(pEnv); glViewport(0, 0, pEnv->getPixelWidth () / 2, pEnv->getPixelHeight() / 2); State *pShrinkState = pSHM->getState(); pEnv->activateState(pShrinkState, NULL); glBegin(GL_QUADS); { glTexCoord2f(0.00, 0.00); glVertex2f (0.00, 0.00); glTexCoord2f(1.00, 0.00); glVertex2f (1.00, 0.00); glTexCoord2f(1.00, 1.00); glVertex2f (1.00, 1.00); glTexCoord2f(0.00, 1.00); glVertex2f (0.00, 1.00); } glEnd(); pShrinkTarget->deactivate(pEnv); // Shrink to w/4 h/4 FrameBufferObject *pBlurTarget = pData->getBlurRenderTarget(); pBlurTarget->editMFDrawBuffers()->clear(); pBlurTarget->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT); pBlurTarget->activate(pEnv); glViewport(0, 0, pEnv->getPixelWidth () / 4, pEnv->getPixelHeight() / 4); ChunkMaterial *pBLM = pData->getBlurMaterial(); State *pBlurState = pBLM->getState(); pEnv->activateState(pBlurState, NULL); glBegin(GL_QUADS); { glTexCoord2f(0.00, 0.00); glVertex2f (0.00, 0.00); glTexCoord2f(1.00, 0.00); glVertex2f (1.00, 0.00); glTexCoord2f(1.00, 1.00); glVertex2f (1.00, 1.00); glTexCoord2f(0.00, 1.00); glVertex2f (0.00, 1.00); } glEnd(); // HBlur StateOverride oOverride; GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT1_EXT }; oOverride.addOverride(pData->getHBlurShader()->getClassId(), pData->getHBlurShader()); pEnv->activateState(pBlurState, &oOverride); glDrawBuffersEXTProc(1, aDrawBuffers); glBegin(GL_QUADS); { glTexCoord2f(0.00, 0.00); glVertex2f (0.00, 0.00); glTexCoord2f(1.00, 0.00); glVertex2f (1.00, 0.00); glTexCoord2f(1.00, 1.00); glVertex2f (1.00, 1.00); glTexCoord2f(0.00, 1.00); glVertex2f (0.00, 1.00); } glEnd(); // VBlur StateOverride oOverride1; oOverride1.addOverride(pData->getVBlurShader()->getClassId(), pData->getVBlurShader()); pEnv->activateState(pBlurState, &oOverride1); aDrawBuffers[0] = GL_COLOR_ATTACHMENT0_EXT; glDrawBuffersEXTProc(1, aDrawBuffers); glBegin(GL_QUADS); { glTexCoord2f(0.00, 0.00); glVertex2f (0.00, 0.00); glTexCoord2f(1.00, 0.00); glVertex2f (1.00, 0.00); glTexCoord2f(1.00, 1.00); glVertex2f (1.00, 1.00); glTexCoord2f(0.00, 1.00); glVertex2f (0.00, 1.00); } glEnd(); pBlurTarget->deactivate(pEnv); // Tonemap pass glDisable(GL_DEPTH_TEST); glViewport(pEnv->getPixelLeft (), pEnv->getPixelBottom(), pEnv->getPixelWidth (), pEnv->getPixelHeight()); ChunkMaterial *pTCM = pData->getToneMappingMaterial(); State *pTState = pTCM->getState(); pEnv->activateState(pTState, NULL); glBegin(GL_QUADS); { glTexCoord2f(0.00, 0.00); glVertex2f (0.00, 0.00); glTexCoord2f(1.00, 0.00); glVertex2f (1.00, 0.00); glTexCoord2f(1.00, 1.00); glVertex2f (1.00, 1.00); glTexCoord2f(0.00, 1.00); glVertex2f (0.00, 1.00); } glEnd(); glEnable(GL_DEPTH_TEST); pEnv->deactivateState(); glPopMatrix(); }
Action::ResultE DisplayFilterStage::renderEnter(Action *action) { RenderAction *ract = dynamic_cast<RenderAction *>(action); if(ract == NULL) return Action::Continue; DisplayFilterStageDataUnrecPtr pData = ract->getData<DisplayFilterStageData *>(_iDataSlotId); DrawEnv &oEnv = ract->getActivePartition()->getDrawEnv(); bool bFilterActive = false; RenderPartition::Mode partMode = RenderPartition::StateSorting; CalibrationPatternFilter *pCalibFilter = NULL; ResolutionDisplayFilter *pResFilter = NULL; DistortionDisplayFilter *pDistFilter = NULL; ColorDisplayFilter *pColFilter = NULL; bool bDoDraw = true; if(_mfFilterGroups.size() == 0) { pCalibFilter = this->getCalibrationPatternFilter(); pResFilter = this->getResolutionFilter(); pColFilter = this->getColorFilter(); pDistFilter = this->getDistortionFilter(); } else { // Linear search, optimize of needed MFFilterGroupsType::const_iterator gIt = _mfFilterGroups.begin(); MFFilterGroupsType::const_iterator gEnd = _mfFilterGroups.end (); for(; gIt != gEnd; ++gIt) { if((*gIt)->matches(oEnv.getDrawerId(), oEnv.getDrawableId()) == true) { pCalibFilter = (*gIt)->getCalibrationPatternFilter(); pResFilter = (*gIt)->getResolutionFilter(); pColFilter = (*gIt)->getColorFilter(); pDistFilter = (*gIt)->getDistortionFilter(); bDoDraw = ((*gIt)->matches(this->getActiveGroup(), oEnv. getDrawableId ()) == true) || (this->getActiveGroup() == -1 ) ; break; } } } if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true) { if(pData != NULL) pData->setCalibFilter(pCalibFilter); bFilterActive = true; partMode = RenderPartition::SimpleCallback; } else { if(pData != NULL) pData->setCalibFilter(NULL); } if(pColFilter != NULL && pColFilter->getEnabled() == true ) { if(pData != NULL) pData->setColFilter(pColFilter); bFilterActive = true; } else { if(pData != NULL) { pData->setColFilter(NULL); ColorDisplayFilter::deactivate(pData); } } if(pDistFilter != NULL && pDistFilter->getEnabled() == true ) { if(pData != NULL) pData->setDistFilter(pDistFilter); bFilterActive = true; } else { if(pData != NULL) pData->setDistFilter(NULL); } UInt32 uiTargetWidth = oEnv.getPixelWidth (); UInt32 uiTargetHeight = oEnv.getPixelHeight(); Int32 iLeft = oEnv.getPixelLeft (); Int32 iRight = oEnv.getPixelRight (); Int32 iBottom = oEnv.getPixelBottom(); Int32 iTop = oEnv.getPixelTop (); if(pResFilter != NULL && pResFilter->getEnabled() == true ) { bFilterActive = true; uiTargetWidth = UInt32(uiTargetWidth * pResFilter->getDownScale()); uiTargetHeight = UInt32(uiTargetHeight * pResFilter->getDownScale()); iLeft = Int32(iLeft * pResFilter->getDownScale()); iRight = Int32(iRight * pResFilter->getDownScale()); iBottom = Int32(iBottom * pResFilter->getDownScale()); iTop = Int32(iTop * pResFilter->getDownScale()); } if(pData == NULL) { pData = setupStageData(uiTargetWidth, uiTargetHeight); if(pData == NULL) return Action::Continue; this->setData(pData, _iDataSlotId, ract); pData->setColFilter (pColFilter ); pData->setDistFilter (pDistFilter ); pData->setCalibFilter(pCalibFilter); } if((pData->getWidth () != uiTargetWidth ) || (pData->getHeight() != uiTargetHeight) ) { resizeStageData(pData, uiTargetWidth, uiTargetHeight); } if(bFilterActive == false) return Action::Continue; ract->disableDefaultPartition(); this->beginPartitionGroup(ract); { this->pushPartition(ract, 0x0000, partMode); { RenderPartition *pPart = ract ->getActivePartition(); FrameBufferObject *pTarget = pData->getTarget(); Viewarea *pArea = ract ->getViewarea(); Camera *pCam = ract ->getCamera (); Background *pBack = ract ->getBackground(); pPart->setRenderTarget(pTarget); if(pArea != NULL) { pPart->setWindow(ract->getWindow()); if(pTarget != NULL) { pPart->calcViewportDimension(iLeft , iBottom, iRight , iTop , pTarget->getWidth (), pTarget->getHeight ()); } else { pPart->calcViewportDimension( pArea->getLeft (), pArea->getBottom(), pArea->getRight (), pArea->getTop (), ract->getWindow()->getWidth (), ract->getWindow()->getHeight()); } if(pCam != NULL) { Matrix m, t; // set the projection pCam->getProjection (m, pPart->getViewportWidth (), pPart->getViewportHeight()); pCam->getProjectionTranslation(t, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupProjection(m, t); pCam->getViewing(m, pPart->getViewportWidth (), pPart->getViewportHeight()); pPart->setupViewing(m); pPart->setNear (pCam->getNear()); pPart->setFar (pCam->getFar ()); pPart->calcFrustum(); } pPart->setBackground(pBack); } if(pCalibFilter != NULL && pCalibFilter->getEnabled() == true) { RenderPartition::SimpleDrawCallback f; if(bDoDraw == true) { f = boost::bind(&DisplayFilterStage::processCalibActive, this, _1); } else { f = boost::bind(&DisplayFilterStage::processCalibInactive, this, _1); } pPart->dropFunctor(f); } else { MFForegroundsType::const_iterator fIt = this->getMFForegrounds()->begin(); MFForegroundsType::const_iterator fEnd = this->getMFForegrounds()->end (); for(; fIt != fEnd; ++fIt) { pPart->pushToForegrounds(*fIt); } this->recurseFromThis(ract); } } this->popPartition(ract); this->pushPartition(ract, (RenderPartition::CopyWindow | RenderPartition::CopyViewportSize), RenderPartition::SimpleCallback); { RenderPartition *pPart = ract->getActivePartition(); Matrix m, t; m.setIdentity(); t.setIdentity(); MatrixOrthogonal( m, 0.f, 1.f, 0.f, 1.f, -1.f, 1.f); pPart->setupProjection(m, t); RenderPartition::SimpleDrawCallback f; f = boost::bind(&DisplayFilterStage::postProcess, this, _1); pPart->dropFunctor(f); } this->popPartition(ract); } this->endPartitionGroup(ract); return Action::Skip; }