// 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 "StateAttribute.hpp" #include "held_ptr.hpp" using namespace boost::python; namespace { osg::PolygonStipple * asPolygonStipple(osg::StateAttribute * self) { return dynamic_cast(self); } } namespace { void setMask(osg::PolygonStipple * self, tuple mask) { GLubyte stipple[128]; int elements = len(mask); if (elements == 32) { for (int i=0; i(mask[i]); self->setMask(stipple); } } else if (elements == 128) { for (int i=0; i(mask[i]); self->setMask(stipple); } } else { PyErr_SetString(PyExc_ValueError, "Length of mask is wrong, should be either 32 or 128"); throw_error_already_set(); } } tuple getMask(osg::PolygonStipple * self) { const GLubyte * stipple = self->getMask(); list mask; for (int i=0 ; i<128; i++) { mask.append(stipple[i]); } return tuple(mask); } } namespace PyOSG { void init_PolygonStipple() { register_castStateAttribute("asPolygonStipple", &asPolygonStipple); class_, bases >("PolygonStipple", no_init) .def(init<>()) .def("setMask", &setMask, "set the mask up, copying 128 bytes (32x32 bitfield) from mask into the local _mask.\n", "The mask can be either a tuple of length 128, or a tuple of length 32") .def("getMask", &getMask, "return the current mask as a tuple of 128 bytes") ; } }