// 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 // for len(object) #include #include #include #include #include "held_ptr.hpp" using namespace boost::python; namespace { class osgDrawElementsUByte : public osg::DrawElementsUByte { public: osgDrawElementsUByte(GLenum mode) : osg::DrawElementsUByte(mode) {} osgDrawElementsUByte(GLenum mode, tuple &t) : osg::DrawElementsUByte(mode) { for (int i =0 ; i<(int) len(t) ; i++) { unsigned char val = extract(t[i]); push_back(val); } } }; class osgDrawElementsUShort : public osg::DrawElementsUShort { public: osgDrawElementsUShort(GLenum mode) : osg::DrawElementsUShort(mode) {} osgDrawElementsUShort(GLenum mode, unsigned int no) : osg::DrawElementsUShort(mode, no) {} osgDrawElementsUShort(GLenum mode, tuple &t) : osg::DrawElementsUShort(mode) { for (int i =0 ; i<(int) len(t) ; i++) { unsigned short val = extract(t[i]); push_back(val); } } unsigned short getitem(int idx) { if (this->size() <= (unsigned int) idx) { PyErr_SetString(PyExc_IndexError, "assignment index out of range"); throw_error_already_set(); } return (*this)[idx]; } void setitem(int idx, unsigned short val) { if (this->size() <= (unsigned int) idx) { PyErr_SetString(PyExc_IndexError, "list index out of range"); throw_error_already_set(); } else { (*this)[idx] = val; } } }; class osgDrawElementsUInt : public osg::DrawElementsUInt { public: osgDrawElementsUInt(GLenum mode) : osg::DrawElementsUInt(mode) {} osgDrawElementsUInt(GLenum mode, tuple &t) : osg::DrawElementsUInt(mode) { for (int i =0 ; i<(int) len(t) ; i++) { unsigned int val = extract(t[i]); push_back(val); } } }; } // namespace namespace PyOSG { void init_PrimitiveSet() { class_, bases, boost::noncopyable > primitive("PrimitiveSet", no_init); { scope primitive_scope(primitive); primitive .def("getType", &osg::PrimitiveSet::getType) .def("setMode", &osg::PrimitiveSet::setMode) .def("getMode", &osg::PrimitiveSet::getMode) .def("index", &osg::PrimitiveSet::index) .def("getNumIndices", &osg::PrimitiveSet::getNumIndices) .def("offsetIndices", &osg::PrimitiveSet::offsetIndices) .def("getNumPrimitives", &osg::PrimitiveSet::getNumPrimitives) ; # define OSG_ENUM_TYPE(VALUE) \ (type.value(#VALUE, osg::PrimitiveSet::VALUE), \ primitive.def(#VALUE, object(osg::PrimitiveSet::VALUE))) enum_ type("Type"); OSG_ENUM_TYPE( PrimitiveType); OSG_ENUM_TYPE( DrawArraysPrimitiveType); OSG_ENUM_TYPE( DrawArrayLengthsPrimitiveType); OSG_ENUM_TYPE( DrawElementsUBytePrimitiveType); OSG_ENUM_TYPE( DrawElementsUShortPrimitiveType); OSG_ENUM_TYPE( DrawElementsUIntPrimitiveType); # define OSG_ENUM_MODE(VALUE) \ (mode.value(#VALUE, osg::PrimitiveSet::VALUE), \ primitive.def(#VALUE, object(osg::PrimitiveSet::VALUE))) enum_ mode("Mode"); OSG_ENUM_MODE(POINTS); OSG_ENUM_MODE(LINES); OSG_ENUM_MODE(LINE_STRIP); OSG_ENUM_MODE(LINE_LOOP); OSG_ENUM_MODE(TRIANGLES); OSG_ENUM_MODE(TRIANGLE_STRIP); OSG_ENUM_MODE(TRIANGLE_FAN); OSG_ENUM_MODE(QUADS); OSG_ENUM_MODE(QUAD_STRIP); OSG_ENUM_MODE(POLYGON); } class_, bases, boost::noncopyable >("DrawArrays", no_init) .def(init()) ; class_, bases, boost::noncopyable >("DrawArrayLengths", no_init); class_, bases, boost::noncopyable >("DrawElementsUByte", no_init) .def(init()) .def(init()) .def("push_back", &osg::DrawElementsUByte::push_back) .def("reserve", &osg::DrawElementsUByte::reserve) .def("size", &osg::DrawElementsUByte::size) ; class_, bases, boost::noncopyable >("DrawElementsUShort", no_init) .def(init()) .def(init()) // TODO .def(init()) .def(init()) .def("push_back", &osg::DrawElementsUShort::push_back) .def("reserve", &osg::DrawElementsUShort::reserve) .def("size", &osg::DrawElementsUShort::size) .def("__getitem__", &osgDrawElementsUShort::getitem) .def("__setitem__", &osgDrawElementsUShort::setitem) ; class_, bases, boost::noncopyable >("DrawElementsUInt", no_init) .def(init()) .def(init()) .def("push_back", &osg::DrawElementsUInt::push_back) .def("reserve", &osg::DrawElementsUInt::reserve) .def("size", &osg::DrawElementsUInt::size) ; } }