Added s/getFactorMultiplier(), s/getUnitMultiplier(), areUnitAndMultipliersSet() and

setFactorAndUnitMultipliersUsingBestGuessForDriver() static methods to
osg::PolygonOffset to help implement workarounds for lack of portablity of
settings between different hardware.
This commit is contained in:
Robert Osfield 2006-07-14 14:08:33 +00:00
parent 618e63a267
commit 4bae225d39
3 changed files with 68 additions and 4 deletions

View File

@ -65,6 +65,19 @@ class OSG_EXPORT PolygonOffset : public StateAttribute
virtual void apply(State& state) const;
static void setFactorMultiplier(float multiplier);
static float getFactorMultiplier();
static void setUnitMultiplier(float multiplier);
static float getUnitMultiplier();
static bool areUnitAndMultipliersSet();
/** Checks with the OpenGL driver to try and pick multiplier approrpriate for the hardware.
note, requires a valid graphics context to be current. */
static void setFactorAndUnitMultipliersUsingBestGuessForDriver();
protected :
virtual ~PolygonOffset();

View File

@ -12,9 +12,49 @@
*/
#include <osg/GL>
#include <osg/PolygonOffset>
#include <osg/Notify>
using namespace osg;
static float s_FactorMultipler = 1.0f;
static float s_UnitMultipler = 1.0f;
static bool s_MultiplerSet = false;
void PolygonOffset::setFactorMultiplier(float multiplier)
{
s_MultiplerSet = true;
s_FactorMultipler = multiplier;
}
float PolygonOffset::getFactorMultiplier()
{
return s_FactorMultipler;
}
void PolygonOffset::setUnitMultiplier(float multiplier)
{
s_MultiplerSet = true;
s_UnitMultipler = multiplier;
}
float PolygonOffset::getUnitMultiplier()
{
return s_UnitMultipler;
}
bool PolygonOffset::areUnitAndMultipliersSet()
{
return s_MultiplerSet;
}
void PolygonOffset::setFactorAndUnitMultipliersUsingBestGuessForDriver()
{
s_MultiplerSet = true;
// osg::notify(osg::NOTICE)<<"PolygonOffset::setFactorAndUnitMultipliersUsingBestGuessForDriver()"<<std::endl;
}
PolygonOffset::PolygonOffset():
_factor(0.0f),
_units(0.0f)
@ -33,5 +73,8 @@ PolygonOffset::~PolygonOffset()
void PolygonOffset::apply(State&) const
{
glPolygonOffset(_factor,_units);
if (!s_MultiplerSet) setFactorAndUnitMultipliersUsingBestGuessForDriver();
glPolygonOffset(_factor * s_FactorMultipler,
_units * s_UnitMultipler);
}

View File

@ -12,13 +12,15 @@
*/
#include <vector>
#include <osgText/Text>
#include <osg/Math>
#include <osg/GL>
#include <osg/Notify>
#include <osg/PolygonOffset>
#include <osgUtil/CullVisitor>
#include <osgDB/ReadFile>
#include "DefaultFont.h"
@ -1446,6 +1448,11 @@ void Text::drawImplementation(osg::State& state) const
if(_backdropType != NONE)
{
if (!osg::PolygonOffset::areUnitAndMultipliersSet())
{
osg::PolygonOffset::setFactorAndUnitMultipliersUsingBestGuessForDriver();
}
// Do I really need to do this for glPolygonOffset?
glPushAttrib(GL_POLYGON_OFFSET_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
@ -1486,12 +1493,13 @@ void Text::drawImplementation(osg::State& state) const
if (!transformedBackdropCoords.empty())
{
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords.front()));
glPolygonOffset(1.0f, 2.0f * (max_backdrop_index-backdrop_index) );
glPolygonOffset(2.0f * osg::PolygonOffset::getFactorMultiplier(),
2.0f * osg::PolygonOffset::getUnitMultiplier() * (max_backdrop_index-backdrop_index) );
glDrawArrays(GL_QUADS,0,transformedBackdropCoords.size());
}
}
glPolygonOffset(0,0);
glPolygonOffset(0.0f,0.0f);
} // end of backdrop text