// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #include #include #include #include #include #include #include #include #include #include #include "StateAttribute.hpp" #include "held_ptr.hpp" using namespace boost::python; namespace { osg::TexGen * asTexGen(osg::StateAttribute * self) { return dynamic_cast(self); } class TexGenBase : public osg::TexGen { public: TexGenBase() : osg::TexGen() {} }; class TexGenBase_imp : public TexGenBase { public: TexGenBase_imp() : _self(NULL), _hasApply(-1) {} TexGenBase_imp(PyObject * self): _self(self), _hasApply(-1){} virtual ~TexGenBase_imp() { } virtual void apply(osg::State& state) const { if (_hasApply == -1) { _hasApply = PyObject_HasAttrString(_self, "apply"); } if (_hasApply) { try { call_method(_self, "apply", ptr(&state)); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); } } else { osg::TexGen::apply(state); } } virtual void apply_impl(osg::State& state) const { osg::TexGen::apply(state); } private: PyObject * _self; mutable int _hasApply; }; void setPlane(osg::TexGen& self, osg::TexGen::Coord which, const osg::Vec4& plane) { self.setPlane(which, plane); } } // namespace namespace PyOSG { void init_TexGen() { register_castStateAttribute("asTexGen", &asTexGen); class_, bases, boost::noncopyable > texgen("TexGen", "TexGen - encapsulates the OpenGL glTexGen (texture coordinate generation) state.", no_init); { scope texgen_scope(texgen); texgen.def(init<>()) .def("setMode", &osg::TexGen::setMode) .def("getMode", &osg::TexGen::getMode) .def("setPlane", &osg::TexGen::setPlane) .def("setPlane", &setPlane) .def("getPlane", (const osg::Plane& (osg::TexGen::*)(osg::TexGen::Coord) const) &osg::TexGen::getPlane, return_value_policy()) .def("setPlanesFromMatrix", &osg::TexGen::setPlanesFromMatrix, "Set the tex gen planes from specified matrix.\n" "Typical usage would be to pass in a projection\n" "matrix to set up projective texturing.\n") ; # define OSG_ENUM_MODE(VALUE) \ (mode.value(#VALUE, osg::TexGen::VALUE), \ texgen.def(#VALUE, object(osg::TexGen::VALUE))) enum_ mode("Mode"); OSG_ENUM_MODE(OBJECT_LINEAR); OSG_ENUM_MODE(EYE_LINEAR); OSG_ENUM_MODE(SPHERE_MAP); OSG_ENUM_MODE(NORMAL_MAP); OSG_ENUM_MODE(REFLECTION_MAP); # define OSG_ENUM_COORD(VALUE) \ (coord.value(#VALUE, osg::TexGen::VALUE), \ texgen.def(#VALUE, object(osg::TexGen::VALUE))) enum_ coord("Coord"); OSG_ENUM_COORD(S); OSG_ENUM_COORD(T); OSG_ENUM_COORD(R); OSG_ENUM_COORD(Q); } { class_, bases, boost::noncopyable > texgen_base("TexGen_base", "TexGen - encapsulates the OpenGL glTexGen (texture coordinate generation) state.", no_init); texgen_base .def(init<>()) .def("apply", &TexGenBase_imp::apply_impl) ; } } } // namespace PyOSG