// 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::Texture * asTexture(osg::StateAttribute * self) { return dynamic_cast(self); } } namespace PyOSG { void init_Texture() { register_castStateAttribute("asTexture", &asTexture); class_, bases, boost::noncopyable > tex("Texture", "Texture base class which encapsulates OpenGl texture functionality which common betweent the various types of OpenGL textures.", no_init); scope tex_scope(tex); tex.def("setWrap", &osg::Texture::setWrap, "Set the texture wrap mode.") .def("getWrap", &osg::Texture::getWrap) .def("setBorderColor", &osg::Texture::setBorderColor, "Sets the border color for this texture. Makes difference only if\n" "wrap mode is CLAMP_TO_BORDER"); tex.def("getBorderColor", &osg::Texture::getBorderColor, return_value_policy()); tex.def("setBorderWidth", &osg::Texture::setBorderWidth, "Set the border width."); tex.def("getBorderWidth", &osg::Texture::getBorderWidth); tex.def("setFilter", &osg::Texture::setFilter, "Set the texture filter mode."); tex.def("getFilter", &osg::Texture::getFilter, "Get the texture filter mode."); tex.def("setMaxAnisotropy", &osg::Texture::setMaxAnisotropy, "Set the maximum anisotropy value, default value is 1.0 for\n" "no anisotropic filtering. If hardware does not support anisotropic\n" "filtering then normal filtering is used, equivilant to a max anisotropy value of 1.0.\n" "valid range is 1.0f upwards. The maximum value depends on the graphics\n" "system being used."); tex.def("getMaxAnisotropy", &osg::Texture::getMaxAnisotropy, "Get the maximum anisotropy value."); tex.def("setUseHardwareMipMapGeneration", &osg::Texture::setUseHardwareMipMapGeneration, "Set the hint of whether to use hardware mip map generation where available.\n"); tex.def("getUseHardwareMipMapGeneration", &osg::Texture::getUseHardwareMipMapGeneration, "Get the hint of whether to use hardware mip map generation where available.\n"); tex.def("setUnRefImageDataAfterApply", &osg::Texture::setUnRefImageDataAfterApply, "Set the automatic unreference of image data after the texture has been set up in apply, on (true) or off (false).\n" "If the image data is only referened by this Texture then the image data will be autoamtically deleted.\n"); tex.def("getUnRefImageDataAfterApply", &osg::Texture::getUnRefImageDataAfterApply, "Get the automatic unreference of image data after the texture has been set up in apply.\n"); tex.def("setClientStorageHint", &osg::Texture::setClientStorageHint, "Sets whether to use client storage for the texture, if supported\n" "by the graphics system. Note: If enabled, and the graphics system\n" "supports it, the osg::Image(s) associated with this texture cannot\n" "be deleted, so the UnRefImageDataAfterApply flag would be ignored.\n"); tex.def("getClientStorageHint", &osg::Texture::getClientStorageHint, "Gets whether to use client storage for the texture.\n"); tex.def("setInternalFormatMode", &osg::Texture::setInternalFormatMode, "Set the internal format mode.\n" "Note, If the mode is set USE_IMAGE_DATA_FORMAT, USE_ARB_COMPRESSION,\n" "USE_S3TC_COMPRESSION the internalFormat is automatically selected,\n" "and will overwrite the previous _internalFormat."); tex.def("getInternalFormatMode", &osg::Texture::getInternalFormatMode, "Get the internal format mode."); tex.def("setInternalFormat", &osg::Texture::setInternalFormat, "Set the internal format to use when creating OpenGL textures.\n" "Also sets the internalFormatMode to USE_USER_DEFINED_FORMAT.\n"); tex.def("getInternalFormat", &osg::Texture::getInternalFormat, "Get the internal format to use when creating OpenGL textures."); tex.def("isCompressedInternalFormat", (bool(osg::Texture::*)(void) const)&osg::Texture::isCompressedInternalFormat); tex.def("setSourceFormat",&osg::Texture::setSourceFormat, "Sets the external source image format, used as a fallback when no osg::Image is attached to provide the source image format."); tex.def("getSourceFormat",&osg::Texture::getSourceFormat, "Gets the external source image format"); tex.def("setSourceType",&osg::Texture::setSourceType, "Sets the external source data type, used as a fallback when no osg::Image is attached to provide the source image format."); tex.def("getSourceType",&osg::Texture::getSourceType, "Gets the external source data type."); tex.def("getTextureObject", &osg::Texture::getTextureObject, "Get the handle to the texture object for the current context.\n", return_value_policy()); tex.def("getTextureObject", &osg::Texture::getTextureObject, return_value_policy()); tex.def("getTextureParameterDirty", &osg::Texture::getTextureParameterDirty, "get the dirty flag for the current contextID.\n", return_value_policy()); tex.def("dirtyTextureObject", &osg::Texture::dirtyTextureObject, "Force a recompile on next apply() of associated OpenGL texture objects."); tex.def("dirtyTextureParameters", &osg::Texture::dirtyTextureParameters, "Force a recompile on next apply() of associated OpenGL texture parameters."); tex.def("setShadowComparison", &osg::Texture::setShadowComparison, "Sets GL_TEXTURE_COMPARE_MODE_ARB to GL_COMPARE_R_TO_TEXTURE_ARB\n" "See http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt.\n"); tex.def("setShadowCompareFunc", &osg::Texture::setShadowCompareFunc, "Sets shadow texture comparison function."); tex.def("getShadowCompareFunc", &osg::Texture::getShadowCompareFunc); tex.def("setShadowTextureMode", &osg::Texture::setShadowTextureMode, "Sets shadow texture mode after comparison."); tex.def("getShadowTextureMode", &osg::Texture::getShadowTextureMode); tex.def("setShadowAmbient", &osg::Texture::setShadowAmbient, "Sets the TEXTURE_COMPARE_FAIL_VALUE_ARB texture parameter. See\n" "http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow_ambient.txt.\n"); tex.def("getShadowAmbient", &osg::Texture::getShadowAmbient); tex.def("setImage",&osg::Texture::setImage, "Sets the texture image for the specified face."); // tex.def("getImage",&osg::Texture::getImage, // "Gets the texture image for the specified face."); tex.def("getNumImages",&osg::Texture::getNumImages, "Gets the number of images that can be assigned to this Texture."); tex.def("getExtensions", &osg::Texture::getExtensions, return_value_policy()); tex.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 > extensions("Extensions", /** Extensions class which encapsulates the querring of extensions and * associated function pointers, and provide convinience wrappers to * check for the extensions or use the associated functions.*/ no_init); extensions .def(init()) .def("setMultiTexturingSupported", &osg::Texture::Extensions::setMultiTexturingSupported) .def("isMultiTexturingSupported", &osg::Texture::Extensions::isMultiTexturingSupported) .def("setTextureFilterAnisotropicSupported", &osg::Texture::Extensions::setTextureFilterAnisotropicSupported) .def("isTextureFilterAnisotropicSupported", &osg::Texture::Extensions::isTextureFilterAnisotropicSupported) .def("setTextureCompressionARBSupported", &osg::Texture::Extensions::setTextureCompressionARBSupported) .def("isTextureCompressionARBSupported", &osg::Texture::Extensions::isTextureCompressionARBSupported) .def("setTextureCompressionS3TCSupported", &osg::Texture::Extensions::setTextureCompressionS3TCSupported) .def("isTextureCompressionS3TCSupported", &osg::Texture::Extensions::isTextureCompressionS3TCSupported) .def("setTextureMirroredRepeatSupported", &osg::Texture::Extensions::setTextureMirroredRepeatSupported) .def("isTextureMirroredRepeatSupported", &osg::Texture::Extensions::isTextureMirroredRepeatSupported) .def("setTextureEdgeClampSupported", &osg::Texture::Extensions::setTextureEdgeClampSupported) .def("isTextureEdgeClampSupported", &osg::Texture::Extensions::isTextureEdgeClampSupported) .def("setTextureBorderClampSupported", &osg::Texture::Extensions::setTextureBorderClampSupported) .def("isTextureBorderClampSupported", &osg::Texture::Extensions::isTextureBorderClampSupported) .def("setGenerateMipMapSupported", &osg::Texture::Extensions::setGenerateMipMapSupported) .def("isGenerateMipMapSupported", &osg::Texture::Extensions::isGenerateMipMapSupported) .def("setMaxTextureSize", &osg::Texture::Extensions::setMaxTextureSize) .def("maxTextureSize", &osg::Texture::Extensions::maxTextureSize) .def("isCompressedTexImage2DSupported", &osg::Texture::Extensions::isCompressedTexImage2DSupported) ; # define OSG_ENUM_WRAP(VALUE) \ (wrap.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ wrap("WrapParameter"); OSG_ENUM_WRAP(WRAP_S); OSG_ENUM_WRAP(WRAP_T); OSG_ENUM_WRAP(WRAP_R); # define OSG_ENUM_WRAPMODE(VALUE) \ (wrapmode.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ wrapmode("WrapMode"); OSG_ENUM_WRAPMODE(CLAMP); OSG_ENUM_WRAPMODE(CLAMP_TO_EDGE); OSG_ENUM_WRAPMODE(CLAMP_TO_BORDER); OSG_ENUM_WRAPMODE(REPEAT); OSG_ENUM_WRAPMODE(MIRROR); # define OSG_ENUM_FILTERPARAM(VALUE) \ (filterparam.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ filterparam("FilterParameter"); OSG_ENUM_FILTERPARAM(MIN_FILTER); OSG_ENUM_FILTERPARAM(MAG_FILTER); # define OSG_ENUM_FILTERMODE(VALUE) \ (filtermode.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ filtermode("FilterMode"); OSG_ENUM_FILTERMODE(LINEAR); OSG_ENUM_FILTERMODE(LINEAR_MIPMAP_LINEAR); OSG_ENUM_FILTERMODE(LINEAR_MIPMAP_NEAREST); OSG_ENUM_FILTERMODE(NEAREST); OSG_ENUM_FILTERMODE(NEAREST_MIPMAP_LINEAR); OSG_ENUM_FILTERMODE(NEAREST_MIPMAP_NEAREST); # define OSG_ENUM_FORMAT(VALUE) \ (format.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ format("InternalFormatMode"); OSG_ENUM_FORMAT(USE_IMAGE_DATA_FORMAT); OSG_ENUM_FORMAT(USE_USER_DEFINED_FORMAT); OSG_ENUM_FORMAT(USE_ARB_COMPRESSION); OSG_ENUM_FORMAT(USE_S3TC_DXT1_COMPRESSION); OSG_ENUM_FORMAT(USE_S3TC_DXT3_COMPRESSION); OSG_ENUM_FORMAT(USE_S3TC_DXT5_COMPRESSION); # define OSG_ENUM_SHADOWCOMPARE(VALUE) \ (scompare.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ scompare("ShadowCompareFunc"); OSG_ENUM_SHADOWCOMPARE(LEQUAL); OSG_ENUM_SHADOWCOMPARE(GEQUAL); # define OSG_ENUM_SHADOWTEX(VALUE) \ (stexmode.value(#VALUE, osg::Texture::VALUE), \ tex.def(#VALUE, object(osg::Texture::VALUE))) enum_ stexmode("ShadowTextureMode"); OSG_ENUM_SHADOWTEX(LUMINANCE); OSG_ENUM_SHADOWTEX(INTENSITY); OSG_ENUM_SHADOWTEX(ALPHA); } } // namespace PyOSG