X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FOSGUtils.hxx;h=557339d0ae9d73039425ca3b630fc59130c36bea;hb=08ad449774b0b80dc19b7a55d82dc25a71ce1415;hp=21c5d698bbce3b1bc00f643cfc49917dba6220b4;hpb=98cecfe940dd9245672b32a01e027aca3d04c02f;p=simgear.git diff --git a/simgear/structure/OSGUtils.hxx b/simgear/structure/OSGUtils.hxx index 21c5d698..557339d0 100644 --- a/simgear/structure/OSGUtils.hxx +++ b/simgear/structure/OSGUtils.hxx @@ -20,8 +20,9 @@ #ifndef SIMGEAR_OSGUTILS_HXX #define SIMGEAR_OSGUTILS_HXX 1 -#include #include +#include +#include namespace simgear { @@ -99,59 +100,280 @@ T* clone_ref(const osg::ref_ptr& object, return static_cast(object->clone(copyop)); } -template -class BackRefInsertIterator - : public boost::iterator_facade, - BackRefInsertIterator, - boost::incrementable_traversal_tag - > +} + +namespace osg { -public: - typedef typename Container::value_type::element_type* PtrType; - BackRefInsertIterator() : _container(0) {} - explicit BackRefInsertIterator(Container& container) - : _container(&container) - { - } +class AlphaFunc; +class BlendColor; +class BlendEquation; +class BlendFunc; +class ClampColor; +class ColorMask; +class ColorMatrix; +class CullFace; +class Depth; +class Fog; +class FragmentProgram; +class FrontFace; +class LightModel; +class LineStipple; +class LineWidth; +class LogicOp; +class Material; +class Multisample; +class Point; +class PointSprite; +class PolygonMode; +class PolygonOffset; +class PolygonStipple; +class Program; +class Scissor; +class ShadeModel; +class Stencil; +class StencilTwoSided; +class TexEnv; +class TexEnvCombine; +class TexEnvFilter; +class TexGen; +class TexMat; +class Texture1D; +class Texture2D; +class Texture2DArray; +class Texture3D; +class TextureCubeMap; +class TextureRectangle; +class VertexProgram; +class Viewport; +} - BackRefInsertIterator& - operator=(const PtrType ptr) - { - _container->push_back(ptr); - return *this; - } - -private: - friend class boost::iterator_core_access; +namespace simgear +{ +namespace osgutils +{ +using namespace osg; - void increment() - { - } - - BackRefInsertIterator& dereference() - { - return *this; - } +template +struct TypeHolder +{ + static const StateAttribute::Type type = T; +}; - BackRefInsertIterator& dereference() const - { - return const_cast(*this); - } +template struct AttributeType; +template struct TexAttributeType; - bool equal(const BackRefInsertIterator& rhs) - { - return _container == rhs._container; - } - - Container* _container; -}; +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + + +template<> +struct AttributeType // Conflicts with Xlib + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; +template<> +struct AttributeType + : public TypeHolder +{}; -template -inline BackRefInsertIterator -backRefInsertIterator(Container& container) +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +// TexEnvCombine is not a subclass of TexEnv, so we can't do a +// typesafe access of the attribute. +#if 0 +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct TexAttributeType + : public TypeHolder +{}; +#endif + +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct TexAttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; + +template<> +struct AttributeType + : public TypeHolder +{}; +} // namespace osgutils + +template +inline AT* getStateAttribute(osg::StateSet* ss) { - return BackRefInsertIterator(container); + return static_cast(ss->getAttribute(osgutils::AttributeType::type)); } + +template +inline const AT* getStateAttribute(const osg::StateSet* ss) +{ + return static_cast(ss->getAttribute(osgutils::AttributeType::type)); +} + +template +inline AT* getStateAttribute(unsigned int unit, osg::StateSet* ss) +{ + return static_cast(ss->getTextureAttribute(unit, osgutils::TexAttributeType + ::type)); } + +template +inline const AT* getStateAttribute(unsigned int unit, const osg::StateSet* ss) +{ + return static_cast(ss->getTextureAttribute(unit, + osgutils::TexAttributeType + ::type)); +} +} // namespace simgear + #endif