Skip to content

Commit

Permalink
fixed: hdr stage size problems (active par used before init, fixed re…
Browse files Browse the repository at this point in the history
…sizing)
  • Loading branch information
vossg committed May 14, 2012
1 parent 978756b commit ef01d37
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 103 deletions.
120 changes: 103 additions & 17 deletions Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.cpp
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);


Expand All @@ -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;

Expand All @@ -764,6 +811,9 @@ void HDRStage::postProcess(DrawEnv *pEnv)
}
glEnd();

#if !OVERSHADER
pData->getVBlurShader()->deactivate(pEnv);
#endif

pBlurTarget->deactivate(pEnv);

Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.h
Expand Up @@ -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);

/*! \} */
/*---------------------------------------------------------------------*/
Expand Down
6 changes: 4 additions & 2 deletions Source/System/NodeCores/Groups/Effects/HDR/testHDRStage.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit ef01d37

Please sign in to comment.