Skip to content

Commit

Permalink
Fix a bug in which the rex elevation texture was not getting applied …
Browse files Browse the repository at this point in the history
…for subsequent layers
  • Loading branch information
gwaldron committed Nov 12, 2018
1 parent f0250ab commit 70cdc3e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/osgEarthDrivers/engine_rex/DrawTileCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ DrawTileCommand::draw(osg::RenderInfo& ri, DrawState& dsMaster, osg::Referenced*

if (sampler._texture.valid() && !samplerState._texture.isSetTo(sampler._texture.get()))
{
state.applyTextureAttribute((*dsMaster._bindings)[s].unit(), sampler._texture.get());
state.setActiveTextureUnit((*dsMaster._bindings)[s].unit());
sampler._texture->apply(state);
samplerState._texture = sampler._texture.get();
}

Expand Down Expand Up @@ -109,7 +110,8 @@ DrawTileCommand::draw(osg::RenderInfo& ri, DrawState& dsMaster, osg::Referenced*

if (sampler._texture.valid() && !samplerState._texture.isSetTo(sampler._texture.get()))
{
state.applyTextureAttribute((*dsMaster._bindings)[s].unit(), sampler._texture.get());
state.setActiveTextureUnit((*dsMaster._bindings)[s].unit());
sampler._texture->apply(state);
samplerState._texture = sampler._texture.get();
}

Expand Down
34 changes: 34 additions & 0 deletions src/osgEarthDrivers/engine_rex/LayerDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ LayerDrawable::~LayerDrawable()
setStateSet(0L);
}

namespace
{
// Hack State so we can dirty the texture attrs without dirtying the other
// attributes (as dirtyAllAttributes() would do.
struct StateEx : public osg::State
{
void dirtyAllTextureAttributes()
{
// dirtyAllTextureAttributes. (Don't call state->dirtyAllAttributes because that
// will mess up positional state attributes like light sources)
for (TextureAttributeMapList::iterator tamItr = _textureAttributeMapList.begin();
tamItr != _textureAttributeMapList.end();
++tamItr)
{
osg::State::AttributeMap& attributeMap = *tamItr;
for (osg::State::AttributeMap::iterator aitr = attributeMap.begin();
aitr != attributeMap.end();
++aitr)
{
osg::State::AttributeStack& as = aitr->second;
as.last_applied_attribute = 0;
as.changed = true;
}
}
}
};
}


void
LayerDrawable::drawImplementation(osg::RenderInfo& ri) const
{
Expand Down Expand Up @@ -76,6 +105,11 @@ LayerDrawable::drawImplementation(osg::RenderInfo& ri) const
// necessary when doing custom OpenGL within a Drawable.
if (_clearOsgState)
{
// Dirty the texture attributes so OSG can properly reset them
// NOTE: cannot call state.dirtyAllAttributes, because that would invalidate
// positional state like light sources!
reinterpret_cast<StateEx*>(ri.getState())->dirtyAllTextureAttributes();

// NOTE: this is a NOOP in OSG 3.5.x, but not in 3.4.x ... Later we will need to
// revisit whether to call disableAllVertexArrays() in 3.5.x instead.
ri.getState()->dirtyAllVertexArrays();
Expand Down

0 comments on commit 70cdc3e

Please sign in to comment.