// Copyleft 2004 Brett Hartshorn (bhartsho@yahoo.com) // // 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::Multisample * asMultisample(osg::StateAttribute * self) { return dynamic_cast(self); } class Multisample : public osg::Multisample { public: Multisample() : _self(NULL), _hasApply(-1) {} Multisample(PyObject * self): _self(self), _hasApply(-1){} 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::Multisample::apply(state); } } virtual void apply_impl(osg::State& state) const { osg::Multisample::apply(state); } virtual ~Multisample() { // std::cerr << "Multisample destructor\n"; } private: PyObject * _self; mutable int _hasApply; }; } namespace PyOSG { void init_Multisample() { register_castStateAttribute("asMultisample", &asMultisample); class_, bases, boost::noncopyable> multisample("Multisample", no_init); { scope multisample_scope(multisample); multisample .def(init<>()) .def("setSampleCoverage", &osg::Multisample::setSampleCoverage) .def("getCoverage", &osg::Multisample::getCoverage) .def("getInvert", &osg::Multisample::getInvert) .def("setHint", &osg::Multisample::setHint) ; enum_ mode("Mode"); # define OSG_ENUM_MS(VALUE) \ (mode.value(#VALUE, osg::Multisample::VALUE), \ multisample.def(#VALUE, object(osg::Multisample::VALUE))) OSG_ENUM_MS(FASTEST); OSG_ENUM_MS(NICEST); OSG_ENUM_MS(DONT_CARE); } class_, bases, boost::noncopyable > multisample_der("MultisampleDer", no_init); multisample_der .def(init<>()) .def("apply", &Multisample::apply_impl) ; } } //namespace PyOSG