Permalink
Browse files

fixed: hdr stage size problems (active par used before init, fixed re…

…sizing)
  • Loading branch information...
1 parent 978756b commit ef01d377ffef02416307540f874ffbca13cb19b6 @vossg committed May 14, 2012
@@ -135,6 +135,9 @@ Action::ResultE HDRStage::renderEnter(Action *action)
a->disableDefaultPartition();
+ Int32 iVPWidth = a->getActivePartition()->getViewportWidth ();
+ Int32 iVPHeight = a->getActivePartition()->getViewportHeight();
+
this->beginPartitionGroup(a);
{
this->pushPartition(a);
@@ -147,10 +150,14 @@ Action::ResultE HDRStage::renderEnter(Action *action)
if(pTarget == NULL)
{
- this->initData(a);
+ this->initData(a, iVPWidth, iVPHeight);
pTarget = this->getRenderTarget();
}
+ else
+ {
+ this->updateData(a, iVPWidth, iVPHeight);
+ }
pPart->setRenderTarget(pTarget);
@@ -586,8 +593,45 @@ void HDRStage::resizeStageData(HDRStageData *pData,
Int32 iPixelWidth,
Int32 iPixelHeight)
{
- FWARNING(("HDRStage resize not implemented ==> wrong results\n"));
-}
+ FrameBufferObject *pSceneFBO = this->getRenderTarget();
+
+ pSceneFBO->resizeAll(iPixelWidth, iPixelHeight);
+
+
+ FrameBufferObject *pShrinkFBO = pData->getShrinkRenderTarget();
+
+ pShrinkFBO->resizeAll(iPixelWidth / 2, iPixelHeight / 2);
+
+
+ FrameBufferObject *pBlurFBO = pData->getBlurRenderTarget();
+
+ pBlurFBO->resizeAll(iPixelWidth / 4,
+ iPixelHeight / 4);
+
+
+ SimpleSHLChunk *pHBlurShader = pData->getHBlurShader();
+
+ std::string szNewFragProg =
+ generate1DConvolutionFilterFPString(getBlurWidth(),
+ false,
+ true,
+ iPixelWidth / 2,
+ iPixelHeight / 2);
+
+ pHBlurShader->setFragmentProgram(szNewFragProg);
+
+ szNewFragProg = generate1DConvolutionFilterFPString(getBlurWidth(),
+ true,
+ true,
+ iPixelWidth / 2,
+ iPixelHeight / 2);
+
+ SimpleSHLChunkUnrecPtr pVBlurShader = pData->getVBlurShader();
+
+ pVBlurShader->setFragmentProgram(szNewFragProg);
+
+ commitChanges();
+}
void HDRStage::postProcess(DrawEnv *pEnv)
{
@@ -618,15 +662,6 @@ void HDRStage::postProcess(DrawEnv *pEnv)
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();
@@ -703,16 +738,22 @@ void HDRStage::postProcess(DrawEnv *pEnv)
// HBlur
- StateOverride oOverride;
-
GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT1_EXT };
+#define OVERSHADER 1
+
+#if OVERSHADER
+ StateOverride oOverride;
+
oOverride.addOverride(pData->getHBlurShader()->getClassId(),
pData->getHBlurShader());
pEnv->activateState(pBlurState, &oOverride);
-
+#else
+ pData->getHBlurShader()->activate(pEnv);
+#endif
+
osgGlDrawBuffers(1, aDrawBuffers);
@@ -732,17 +773,23 @@ void HDRStage::postProcess(DrawEnv *pEnv)
}
glEnd();
-
+#if !OVERSHADER
+ pData->getHBlurShader()->deactivate(pEnv);
+#endif
// VBlur
+#if OVERSHADER
StateOverride oOverride1;
oOverride1.addOverride(pData->getVBlurShader()->getClassId(),
pData->getVBlurShader());
pEnv->activateState(pBlurState, &oOverride1);
+#else
+ pData->getVBlurShader()->activate(pEnv);
+#endif
aDrawBuffers[0] = GL_COLOR_ATTACHMENT0_EXT;
@@ -764,6 +811,9 @@ void HDRStage::postProcess(DrawEnv *pEnv)
}
glEnd();
+#if !OVERSHADER
+ pData->getVBlurShader()->deactivate(pEnv);
+#endif
pBlurTarget->deactivate(pEnv);
@@ -808,7 +858,9 @@ void HDRStage::postProcess(DrawEnv *pEnv)
glPopMatrix();
}
-void HDRStage::initData(RenderAction *pAction)
+void HDRStage::initData(RenderAction *pAction,
+ Int32 iVPWidth,
+ Int32 iVPHeight)
{
HDRStageDataUnrecPtr pData = pAction->getData<HDRStageData *>(_iDataSlotId);
@@ -822,17 +874,51 @@ void HDRStage::initData(RenderAction *pAction)
pData->setHeight(pViewport->getPixelHeight());
#endif
+ fprintf(stderr, "use pixe size %d %d\n",
+ pAction->getActivePartition()->getViewportWidth (),
+ pAction->getActivePartition()->getViewportHeight());
+
+#if 0
pData = setupStageData(
pAction->getActivePartition()->getViewportWidth (),
pAction->getActivePartition()->getViewportHeight());
pData->setWidth (pAction->getActivePartition()->getViewportWidth ());
pData->setHeight(pAction->getActivePartition()->getViewportHeight());
+#endif
+
+ pData = setupStageData(iVPWidth,
+ iVPHeight);
+
+ pData->setWidth (iVPWidth );
+ pData->setHeight(iVPHeight);
this->setData(pData, _iDataSlotId, pAction);
}
}
+void HDRStage::updateData(RenderAction *pAction,
+ Int32 iVPWidth,
+ Int32 iVPHeight)
+{
+ HDRStageDataUnrecPtr pData = pAction->getData<HDRStageData *>(_iDataSlotId);
+
+ if(pData == NULL)
+ {
+ initData(pAction, iVPWidth, iVPHeight);
+ }
+ else if((pData->getWidth () != iVPWidth ) ||
+ (pData->getHeight() != iVPHeight) )
+ {
+ resizeStageData(pData,
+ iVPWidth,
+ iVPHeight);
+
+ pData->setWidth (iVPWidth );
+ pData->setHeight(iVPHeight);
+ }
+}
+
#define OSGHDRL << std::endl
SimpleSHLChunkTransitPtr HDRStage::generateHDRFragmentProgram(void)
@@ -88,7 +88,13 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStage : public HDRStageBase
/*! \name Dump */
/*! \{ */
- void initData(RenderAction *pAction);
+ void initData (RenderAction *pAction,
+ Int32 iVPWidth,
+ Int32 iVPHeight);
+
+ void updateData(RenderAction *pAction,
+ Int32 iVPWidth,
+ Int32 iVPHeight);
/*! \} */
/*---------------------------------------------------------------------*/
@@ -556,8 +556,10 @@ int doMain (int argc, char **argv)
OSG::TextureObjChunkUnrecPtr pBackTex = OSG::TextureObjChunk::create();
- pBackTex->setImage(pBackImg);
- pBackTex->setInternalFormat(GL_RGB32F_ARB);
+ pBackTex->setImage (pBackImg );
+ pBackTex->setInternalFormat(GL_RGB32F_ARB );
+ pBackTex->setWrapS (GL_CLAMP_TO_EDGE);
+ pBackTex->setWrapT (GL_CLAMP_TO_EDGE);
bkgnd->setBackTexture (pBackTex);
bkgnd->setFrontTexture (pBackTex);
Oops, something went wrong.

0 comments on commit ef01d37

Please sign in to comment.