// 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 "StateAttribute.hpp" #include "held_ptr.hpp" using namespace boost::python; namespace { osg::TextureRectangle * asTextureRectangle(osg::StateAttribute * self) { return dynamic_cast(self); } class SubloadCallback : public osg::TextureRectangle::SubloadCallback { public: SubloadCallback(PyObject * p) : _self(p) {} ~SubloadCallback() {} virtual void load(const osg::TextureRectangle& texture,osg::State& state) const{ try { call_method(_self, "load", ptr(&texture), ptr(&state)); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); return; } } virtual void subload(const osg::TextureRectangle& texture,osg::State& state) const{ try { call_method(_self, "subload", ptr(&texture), ptr(&state)); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); return; } } private: PyObject * _self; }; void setSubloadCallback(osg::TextureRectangle * self, PyObject * cb) { bool is_callback = extract(cb).check(); Py_XINCREF(cb); if (is_callback) { extract callback(cb); self->setSubloadCallback(callback); } else { SubloadCallback * callback = new SubloadCallback(cb); self->setSubloadCallback(callback); } } } namespace PyOSG { void init_TextureRectangle() { register_castStateAttribute("asTextureRectangle", &asTextureRectangle); class_, bases > map("TextureRectangle", no_init); scope map_scope(map); map.def(init<>()) .def(init()) .def("setImage", (void (osg::TextureRectangle::*)(osg::Image *)) &osg::TextureRectangle::setImage) .def("getImage", (osg::Image *(osg::TextureRectangle::*)())&osg::TextureRectangle::getImage, return_value_policy()) .def("setTextureSize", &osg::TextureRectangle::setTextureSize, "Set the texture width and height. If width or height are zero then\n" "the repsective size value is calculated from the source image sizes.\n") .def("getTextureWidth", &osg::TextureRectangle::getTextureWidth) .def("getTextureHeight", &osg::TextureRectangle::getTextureHeight) ; } } // namespace PyOSG