A FogCoordinateSource set/get methods to osg::Fog which correspond to the
FogCoord support added to osg::Geometry. Added suppot for these new parameters to the .osg plugin.
This commit is contained in:
@@ -9,6 +9,13 @@
|
||||
#include <osg/Types>
|
||||
#include <osg/Vec4>
|
||||
|
||||
#ifndef GL_FOG_COORDINATE
|
||||
#define GL_FOG_COORDINATE 0x8451
|
||||
#endif
|
||||
#ifndef GL_FRAGMENT_DEPTH
|
||||
#define GL_FRAGMENT_DEPTH 0x8452
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
@@ -26,7 +33,8 @@ class SG_EXPORT Fog : public StateAttribute
|
||||
_density(fog._density),
|
||||
_start(fog._start),
|
||||
_end(fog._end),
|
||||
_color(fog._color) {}
|
||||
_color(fog._color),
|
||||
_fogCoordinateSource(fog._fogCoordinateSource) {}
|
||||
|
||||
META_StateAttribute(osg, Fog,FOG);
|
||||
|
||||
@@ -43,6 +51,7 @@ class SG_EXPORT Fog : public StateAttribute
|
||||
COMPARE_StateAttribute_Parameter(_start)
|
||||
COMPARE_StateAttribute_Parameter(_end)
|
||||
COMPARE_StateAttribute_Parameter(_color)
|
||||
COMPARE_StateAttribute_Parameter(_fogCoordinateSource)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
@@ -72,6 +81,15 @@ class SG_EXPORT Fog : public StateAttribute
|
||||
|
||||
inline void setColor( const Vec4 &color ) { _color = color; }
|
||||
inline const Vec4& getColor() const { return _color; }
|
||||
|
||||
enum FogCoordinateSource
|
||||
{
|
||||
FOG_COORDINATE = GL_FOG_COORDINATE,
|
||||
FRAGMENT_DEPTH = GL_FRAGMENT_DEPTH
|
||||
};
|
||||
|
||||
inline void setFogCoordinateSource(GLint source) { _fogCoordinateSource = source; }
|
||||
inline GLint getFogCoordinateSource() const { return _fogCoordinateSource; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
@@ -79,11 +97,12 @@ class SG_EXPORT Fog : public StateAttribute
|
||||
|
||||
virtual ~Fog();
|
||||
|
||||
Mode _mode;
|
||||
float _density;
|
||||
float _start;
|
||||
float _end;
|
||||
Vec4 _color;
|
||||
Mode _mode;
|
||||
float _density;
|
||||
float _start;
|
||||
float _end;
|
||||
Vec4 _color;
|
||||
GLint _fogCoordinateSource;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <osg/Fog>
|
||||
#include <osg/GLExtensions>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
@@ -9,6 +10,7 @@ Fog::Fog()
|
||||
_start = 0.0f;
|
||||
_end = 1.0f;
|
||||
_color.set( 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
_fogCoordinateSource = FRAGMENT_DEPTH;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,4 +25,10 @@ void Fog::apply(State&) const
|
||||
glFogf( GL_FOG_START, _start );
|
||||
glFogf( GL_FOG_END, _end );
|
||||
glFogfv( GL_FOG_COLOR, (GLfloat*)_color.ptr() );
|
||||
|
||||
static bool fogCoordExtensionSuppoted = osg::isGLExtensionSupported("GL_EXT_fog_coord");
|
||||
if (fogCoordExtensionSuppoted)
|
||||
{
|
||||
glFogi(GL_FOG_COORDINATE_SOURCE_EXT,_fogCoordinateSource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,21 @@ bool Fog_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("fogCoordinateSource"))
|
||||
{
|
||||
if (fr[1].matchWord("FOG_COORDINATE"))
|
||||
{
|
||||
fog.setFogCoordinateSource(osg::Fog::FOG_COORDINATE);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
} else if (fr[1].matchWord("FRAGMENT_DEPTH"))
|
||||
{
|
||||
fog.setFogCoordinateSource(osg::Fog::FRAGMENT_DEPTH);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -89,6 +104,18 @@ bool Fog_writeLocalData(const Object& obj,Output& fw)
|
||||
fw.indent() << "start " << fog.getStart() << std::endl;
|
||||
fw.indent() << "end " << fog.getEnd() << std::endl;
|
||||
fw.indent() << "color " << fog.getColor() << std::endl;
|
||||
switch(fog.getFogCoordinateSource())
|
||||
{
|
||||
case(Fog::FOG_COORDINATE):
|
||||
fw.indent() << "fogCoordinateSource FOG_COORDINATE" << std::endl;
|
||||
break;
|
||||
case(Fog::FRAGMENT_DEPTH):
|
||||
fw.indent() << "fogCoordinateSource FRAGMENT_DEPTH" << std::endl;
|
||||
break;
|
||||
default:
|
||||
// unrecognized source type.
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,67 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
}
|
||||
|
||||
Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
|
||||
{
|
||||
geom.setSecondaryColorBinding(secondaryColorBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("SecondaryColorArray %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
Array* colors = Array_readLocalData(fr);
|
||||
if (colors)
|
||||
{
|
||||
geom.setSecondaryColorArray(colors);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))
|
||||
{
|
||||
geom.setFogCoordBinding(fogCoordBinding);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("FogCoordArray %i {"))
|
||||
{
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
|
||||
int capacity;
|
||||
fr[1].getInt(capacity);
|
||||
|
||||
FloatArray* fogcoords = osgNew FloatArray;
|
||||
fogcoords->reserve(capacity);
|
||||
|
||||
fr += 3;
|
||||
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||||
{
|
||||
float fc;
|
||||
if (fr[0].getFloat(fc))
|
||||
{
|
||||
++fr;
|
||||
fogcoords->push_back(fc);
|
||||
}
|
||||
else
|
||||
{
|
||||
++fr;
|
||||
}
|
||||
}
|
||||
|
||||
geom.setFogCoordArray(fogcoords);
|
||||
|
||||
iteratorAdvanced = true;
|
||||
++fr;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("TexCoordArray %i %w %i {"))
|
||||
{
|
||||
int unit=0;
|
||||
@@ -750,6 +811,23 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
|
||||
Array_writeLocalData(*geom.getColorArray(),fw);
|
||||
}
|
||||
|
||||
if (geom.getSecondaryColorArray())
|
||||
{
|
||||
fw.indent()<<"SecondaryColorBinding "<<Geometry_getBindingTypeStr(geom.getSecondaryColorBinding())<<std::endl;
|
||||
fw.indent()<<"SecondaryColorArray ";
|
||||
Array_writeLocalData(*geom.getSecondaryColorArray(),fw);
|
||||
}
|
||||
|
||||
if (geom.getFogCoordArray())
|
||||
{
|
||||
fw.indent()<<"FogCoordBinding "<<Geometry_getBindingTypeStr(geom.getFogCoordBinding())<<std::endl;
|
||||
|
||||
const FloatArray& fogcoords = *geom.getFogCoordArray();
|
||||
fw.indent()<<"FogCoordArray "<<fogcoords.size()<<std::endl;
|
||||
|
||||
Array_writeLocalData(fw,fogcoords.begin(),fogcoords.end());
|
||||
}
|
||||
|
||||
const Geometry::TexCoordArrayList& tcal=geom.getTexCoordArrayList();
|
||||
for(unsigned int i=0;i<tcal.size();++i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user