// 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 "StateAttribute.hpp" #include "held_ptr.hpp" using namespace boost::python; namespace { osg::Texture3D * asTexture3D(osg::StateAttribute * self) { return dynamic_cast(self); } class SubloadCallback3D : public osg::Texture3D::SubloadCallback { public: SubloadCallback3D(PyObject * p) : _self(p) {} ~SubloadCallback3D() {} virtual void load(const osg::Texture3D& 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::Texture3D& 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::Texture3D * self, PyObject * cb) { bool is_callback = extract(cb).check(); Py_XINCREF(cb); if (is_callback) { extract callback(cb); self->setSubloadCallback(callback); } else { SubloadCallback3D * callback = new SubloadCallback3D(cb); self->setSubloadCallback(callback); } } } namespace PyOSG { void init_Texture3D() { register_castStateAttribute("asTexture3D", &asTexture3D); class_, bases > texture3d("Texture3D", no_init); scope texture3d_scope(texture3d); texture3d .def(init<>()) .def("setImage", (void (osg::Texture3D::*)(osg::Image *)) &osg::Texture3D::setImage) .def("getImage", (osg::Image *(osg::Texture3D::*)()) &osg::Texture3D::getImage, return_value_policy()) .def("setTextureSize", &osg::Texture3D::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("getTextureSize", &osg::Texture3D::getTextureSize, "Get the texture subload width.") .def("setNumMipmapLevels", &osg::Texture3D::setNumMipmapLevels, "Set the number of mip map levels the the texture has been created with,\n" "should only be called within an osg::Texuture::apply() and custom texture load.") .def("getNumMipmapLevels", &osg::Texture3D::getNumMipmapLevels, "Get the number of mip map levels the the texture has been created with.") .def("copyTexSubImage3D", &osg::Texture3D::copyTexSubImage3D, "Copy a two-dimensional texture subimage. As per glCopyTexSubImage2D.\n" "Updates portion of an existing OpenGL texture object from the current OpenGL background\n" "framebuffer contents at pos \a x, \a y with width \a width and\n" "height \a height.") .def("setSubloadCallback", &setSubloadCallback) .def("getExtensions", &osg::Texture3D::getExtensions, return_value_policy()) .staticmethod("getExtensions") ; class_, bases, boost::noncopyable > extensions("Extensions", no_init); extensions .def(init()) .def("setTexture3DSupported", &osg::Texture3D::Extensions::setTexture3DSupported) .def("isTexture3DSupported", &osg::Texture3D::Extensions::isTexture3DSupported) .def("setTexture3DFast", &osg::Texture3D::Extensions::setTexture3DFast) .def("isTexture3DFast", &osg::Texture3D::Extensions::isTexture3DFast) .def("setMaxTexture3DSize", &osg::Texture3D::Extensions::setMaxTexture3DSize) .def("maxTexture3DSize", &osg::Texture3D::Extensions::maxTexture3DSize) /*** .def("setTexImage3DProc", &osg::Texture3D::Extensions::setTexImage3DProc) .def("glTexImage3D", &osg::Texture3D::Extensions::glTexImage3D) .def("setTexSubImage3DProc", &osg::Texture3D::Extensions::setTexSubImage3DProc) .def("glTexSubImage3D", &osg::Texture3D::Extensions::glTexSubImage3D) .def("setCopyTexSubImage3DProc", &osg::Texture3D::Extensions::setCopyTexSubImage3DProc) .def("glCopyTexSubImage3D", &osg::Texture3D::Extensions::glCopyTexSubImage3D) ***/ ; class_, bases, boost::noncopyable>("SubloadCallback", no_init) .def(init<>()) ; } } // namespace PyOSG