// 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::TextureCubeMap * asTextureCubeMap(osg::StateAttribute * self) { return dynamic_cast(self); } class SubloadCallbackCM : public osg::TextureCubeMap::SubloadCallback { public: SubloadCallbackCM(PyObject * p) : _self(p) {} ~SubloadCallbackCM() {} virtual void load(const osg::TextureCubeMap& 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::TextureCubeMap& 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::TextureCubeMap * self, PyObject * cb) { bool is_callback = extract(cb).check(); Py_XINCREF(cb); if (is_callback) { extract callback(cb); self->setSubloadCallback(callback); } else { SubloadCallbackCM * callback = new SubloadCallbackCM(cb); self->setSubloadCallback(callback); } } } namespace PyOSG { void init_TextureCubeMap() { register_castStateAttribute("asTextureCubeMap", &asTextureCubeMap); class_, bases > map("TextureCubeMap", no_init); scope map_scope(map); map.def(init<>()) .def("setImage", &osg::TextureCubeMap::setImage) .def("getImage", (osg::Image *(osg::TextureCubeMap::*)(unsigned int)) &osg::TextureCubeMap::getImage, return_value_policy()) .def("setTextureSize", &osg::TextureCubeMap::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("setNumMipmapLevels", &osg::TextureCubeMap::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 OpenGL texture load.") .def("getNumMipmapLevels", &osg::TextureCubeMap::getNumMipmapLevels, "Get the number of mip map levels the the texture has been created with.") .def("setSubloadCallback", &setSubloadCallback) .def("getExtensions", &osg::TextureCubeMap::getExtensions, return_value_policy()) .staticmethod("getExtensions") ; #if 0 tex.def("deleteTextureObject", &osg::Texture::deleteTextureObject, "use deleteTextureObject instead of glDeleteTextures to allow\n" "OpenGL texture objects to cached until they can be deleted\n" "by the OpenGL context in which they were created, specified\n" "by contextID.\n"); tex.def("flushDeletedTextureObject", &osg::Texture::flushDeletedTextureObjects, "flush all the cached display list which need to be deleted\n" "in the OpenGL context related to contextID.\n"); #endif class_, bases, boost::noncopyable>("SubloadCallback", no_init) .def(init<>()) ; class_, bases, boost::noncopyable > extensions("Extensions", no_init); extensions .def(init()) .def("setCubeMapSupported", &osg::TextureCubeMap::Extensions::setCubeMapSupported) .def("isCubeMapSupported", &osg::TextureCubeMap::Extensions::isCubeMapSupported) ; # define OSG_ENUM_FACE(VALUE) \ (face.value(#VALUE, osg::TextureCubeMap::VALUE), \ map.def(#VALUE, object(osg::TextureCubeMap::VALUE))) enum_ face("Face"); OSG_ENUM_FACE(POSITIVE_X); OSG_ENUM_FACE(NEGATIVE_X); OSG_ENUM_FACE(POSITIVE_Y); OSG_ENUM_FACE(NEGATIVE_Y); OSG_ENUM_FACE(POSITIVE_Z); OSG_ENUM_FACE(NEGATIVE_Z); } } // namespace PyOSG