Skip to content

Commit

Permalink
Fix InstanceBuilder problems pre OSG 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
timoore committed Apr 23, 2020
1 parent fba7c23 commit 1fabae0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/osgEarth/InstanceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using namespace osgEarth;

// OSG in GLCORE mode doesn't set the vertex attribute divisor
// correctly, so here's a big old hack to get around that.

#if OSG_VERSION_GREATER_OR_EQUAL(3,6,0)
class InstancedGeometry : public osg::Geometry
{
public:
Expand Down Expand Up @@ -67,6 +67,7 @@ class InstancedGeometry : public osg::Geometry
protected:
std::vector<unsigned int> _divisors;
};
#endif

namespace
{
Expand Down Expand Up @@ -131,11 +132,13 @@ namespace
if (perVertex)
{
geom->setVertexAttribArray(index, perVertex, osg::Array::BIND_PER_VERTEX);
#if OSG_VERSION_GREATER_OR_EQUAL(3,6,0)
InstancedGeometry* instancedGeom = dynamic_cast<InstancedGeometry*>(geom);
if (instancedGeom && instancedGeom->getUseVertexArrayObject())
{
instancedGeom->setVertexAttribDivisor(index, 1);
}
#endif
else
{
osg::StateSet* ss = geom->getOrCreateStateSet();
Expand All @@ -149,6 +152,7 @@ namespace
}
}

#if OSG_VERSION_GREATER_OR_EQUAL(3,6,0)
InstancedGeometry::InstancedGeometry()
{
setUseVertexArrayObject(osgEarth::Registry::capabilities().supportsVertexArrayObjects());
Expand Down Expand Up @@ -185,6 +189,7 @@ void InstancedGeometry::compileGLObjects(osg::RenderInfo& renderInfo) const
state.unbindVertexArrayObject();
}
}
#endif

InstanceBuilder::InstanceBuilder()
{
Expand All @@ -199,7 +204,11 @@ InstanceBuilder::InstanceBuilder()

osg::Geometry* InstanceBuilder::createGeometry()
{
#if OSG_VERSION_GREATER_OR_EQUAL(3,6,0)
return new InstancedGeometry;
#else
return new osg::Geometry;
#endif
}

void InstanceBuilder::installInstancing(osg::Geometry* geometry) const
Expand Down

0 comments on commit 1fabae0

Please sign in to comment.