Fix for impostors bug where image insert were visible, this was down to a double
call to RenderStage::drawPreRenderStage(). The call to it in RenderStage inside the draw() method has been removed, leaving on the call in SceneView.
This commit is contained in:
@@ -143,6 +143,8 @@ class SG_EXPORT ImpostorSprite : public Drawable
|
||||
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||
virtual void accept(PrimitiveFunctor& pf) const;
|
||||
|
||||
// for debugging purposes.
|
||||
Vec4 _color;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ ImpostorSprite::ImpostorSprite()
|
||||
_texture = NULL;
|
||||
_s = 0;
|
||||
_t = 0;
|
||||
|
||||
_color.set(1.0f, 1.0f, 1.0f, 1.0f );
|
||||
}
|
||||
|
||||
ImpostorSprite::~ImpostorSprite()
|
||||
@@ -77,7 +79,8 @@ void ImpostorSprite::drawImplementation(State&) const
|
||||
{
|
||||
// when the tex env is set to REPLACE, and the
|
||||
// texture is set up correctly the color has no effect.
|
||||
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
glColor4fv( _color.ptr() );
|
||||
|
||||
|
||||
glBegin( GL_QUADS );
|
||||
|
||||
@@ -268,6 +271,7 @@ ImpostorSprite* ImpostorSpriteManager::createOrReuseImpostorSprite(int s,int t,i
|
||||
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
|
||||
|
||||
stateset->setRenderingHint( StateSet::TRANSPARENT_BIN );
|
||||
|
||||
stateset->setAttributeAndModes( _alphafunc.get(), StateAttribute::ON );
|
||||
|
||||
|
||||
@@ -629,11 +629,17 @@ void CullVisitor::apply(Impostor& node)
|
||||
// create the impostor sprite.
|
||||
impostorSprite = createImpostorSprite(node);
|
||||
|
||||
//if (impostorSprite) impostorSprite->_color.set(0.0f,0.0f,1.0f,1.0f);
|
||||
|
||||
}
|
||||
//else impostorSprite->_color.set(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
if (impostorSprite)
|
||||
{
|
||||
|
||||
// update frame number to show that impostor is in action.
|
||||
impostorSprite->setLastFrameUsed(getTraversalNumber());
|
||||
|
||||
if (_computeNearFar) updateCalculatedNearFar(matrix,*impostorSprite);
|
||||
|
||||
StateSet* stateset = impostorSprite->getStateSet();
|
||||
@@ -644,8 +650,6 @@ void CullVisitor::apply(Impostor& node)
|
||||
|
||||
if (stateset) popStateSet();
|
||||
|
||||
// update frame number to show that impostor is in action.
|
||||
impostorSprite->setLastFrameUsed(getTraversalNumber());
|
||||
|
||||
}
|
||||
else
|
||||
@@ -886,12 +890,18 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
|
||||
|
||||
dummyState->setAttribute(new_viewport);
|
||||
|
||||
// create the impostor sprite.
|
||||
|
||||
// create the impostor sprite.
|
||||
ImpostorSprite* impostorSprite =
|
||||
_impostorSpriteManager->createOrReuseImpostorSprite(new_s,new_t,getTraversalNumber()-_numFramesToKeepImpostorSprites);
|
||||
|
||||
if (impostorSprite==NULL) return NULL;
|
||||
if (impostorSprite==NULL)
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Warning: unable to create required impostor sprite."<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// update frame number to show that impostor is in action.
|
||||
impostorSprite->setLastFrameUsed(getTraversalNumber());
|
||||
|
||||
// have successfully created an impostor sprite so now need to
|
||||
// add it into the impostor.
|
||||
|
||||
@@ -79,23 +79,33 @@ void RenderStage::addToDependencyList(RenderStage* rs)
|
||||
|
||||
void RenderStage::drawPreRenderStages(osg::State& state,RenderLeaf*& previous)
|
||||
{
|
||||
if (_dependencyList.empty()) return;
|
||||
|
||||
//cout << "Drawing prerendering stages "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
|
||||
for(DependencyList::iterator itr=_dependencyList.begin();
|
||||
itr!=_dependencyList.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->draw(state,previous);
|
||||
}
|
||||
//cout << "Done Drawing prerendering stages "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
|
||||
}
|
||||
|
||||
void RenderStage::draw(osg::State& state,RenderLeaf*& previous)
|
||||
{
|
||||
drawPreRenderStages(state,previous);
|
||||
if (_stageDrawnThisFrame) return;
|
||||
|
||||
_stageDrawnThisFrame = true;
|
||||
|
||||
// note, SceneView does call to drawPreRenderStages explicitly
|
||||
// so there is no need to call it here.
|
||||
//drawPreRenderStages(state,previous);
|
||||
|
||||
RenderBin::draw(state,previous);
|
||||
}
|
||||
|
||||
void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
|
||||
{
|
||||
if (_stageDrawnThisFrame) return;
|
||||
|
||||
if (!_viewport)
|
||||
{
|
||||
@@ -103,7 +113,6 @@ void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
|
||||
return;
|
||||
}
|
||||
|
||||
_stageDrawnThisFrame = true;
|
||||
|
||||
// set up the back buffer.
|
||||
state.applyAttribute(_viewport.get());
|
||||
@@ -111,6 +120,8 @@ void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
|
||||
#define USE_SISSOR_TEST
|
||||
#ifdef USE_SISSOR_TEST
|
||||
glScissor( _viewport->x(), _viewport->y(), _viewport->width(), _viewport->height() );
|
||||
//cout << " clearing "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
|
||||
|
||||
glEnable( GL_SCISSOR_TEST );
|
||||
#endif
|
||||
|
||||
@@ -125,7 +136,10 @@ void RenderStage::drawImplementation(osg::State& state,RenderLeaf*& previous)
|
||||
glClearColor( _clearColor[0], _clearColor[1], _clearColor[2], _clearColor[3]);
|
||||
|
||||
if (_clearMask & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth( _clearDepth);
|
||||
}
|
||||
else
|
||||
|
||||
if (_clearMask & GL_STENCIL_BUFFER_BIT)
|
||||
glClearStencil( _clearStencil);
|
||||
|
||||
@@ -35,12 +35,20 @@ void RenderToTextureStage::reset()
|
||||
|
||||
void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous)
|
||||
{
|
||||
|
||||
if (_stageDrawnThisFrame) return;
|
||||
|
||||
//cout << "begining RTTS draw "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
|
||||
|
||||
RenderStage::draw(state,previous);
|
||||
|
||||
// now copy the rendered image to attached texture.
|
||||
if (_texture.valid())
|
||||
{
|
||||
//cout << " reading "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
|
||||
|
||||
_texture->copyTexImage2D(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height());
|
||||
}
|
||||
|
||||
if (_image.valid())
|
||||
_image->readPixels(_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height(),GL_RGBA,GL_UNSIGNED_BYTE);
|
||||
|
||||
Reference in New Issue
Block a user