Skip to content

Commit

Permalink
Merge pull request #191 from OGRECave/swig
Browse files Browse the repository at this point in the history
Python Bindings
  • Loading branch information
paroj committed May 15, 2016
2 parents 15b6a3e + 908d588 commit 1d86810
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ addons:
- libboost-all-dev
- libcppunit-dev
- libgles2-mesa-dev
- python3-dev
before_script:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" && sudo apt-get update -qq && sudo apt-get install -qq nvidia-cg-dev ; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" && sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-backports universe" && sudo apt-get update -qq && sudo apt-get install -qq nvidia-cg-dev swig3.0 ; fi
# we start compilation afterwards anyway, so no need to sleep
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start ; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install freetype libzzip sdl2 cppunit cmake ; fi
Expand Down Expand Up @@ -47,8 +48,12 @@ script:
- BUILD_CMD="cmake --build ."
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then BUILD_CMD="set -o pipefail && $BUILD_CMD | xcpretty" ; fi
- echo $BUILD_CMD && eval $BUILD_CMD
# run unit tests
- if [ $TEST ]; then bin/Test_Ogre ; fi
# run visual tests
- if [ $TEST ]; then cd bin && ./TestContext ; fi
# verify that the python modules are loadable
- if [ $TEST ]; then cd ../lib && python3 -c "import _Ogre; import _OgreRTShader" ; fi
os:
- linux
- osx
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ cmake_dependent_option(OGRE_BUILD_COMPONENT_PROPERTY "Build Property component"
cmake_dependent_option(OGRE_BUILD_PLUGIN_CG "Build Cg plugin" TRUE "Cg_FOUND;NOT APPLE_IOS;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" FALSE)
cmake_dependent_option(OGRE_BUILD_COMPONENT_OVERLAY "Build Overlay component" TRUE "FREETYPE_FOUND" FALSE)
option(OGRE_BUILD_COMPONENT_HLMS "Build HLMS component" TRUE)
option(OGRE_BUILD_COMPONENT_PYTHON "Build Python bindings" TRUE)
option(OGRE_BUILD_COMPONENT_RTSHADERSYSTEM "Build RTShader System component" TRUE)
cmake_dependent_option(OGRE_BUILD_RTSHADERSYSTEM_CORE_SHADERS "Build RTShader System FFP core shaders" TRUE "OGRE_BUILD_COMPONENT_RTSHADERSYSTEM" FALSE)
cmake_dependent_option(OGRE_BUILD_RTSHADERSYSTEM_EXT_SHADERS "Build RTShader System extensions shaders" TRUE "OGRE_BUILD_COMPONENT_RTSHADERSYSTEM" FALSE)
Expand Down
6 changes: 5 additions & 1 deletion Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ endif ()

if (OGRE_BUILD_COMPONENT_HLMS)
add_subdirectory(HLMS)
endif ()
endif ()

if (OGRE_BUILD_COMPONENT_PYTHON)
add_subdirectory(Python)
endif()
32 changes: 32 additions & 0 deletions Components/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
find_package(SWIG)
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})
find_package(PythonInterp)

if(NOT PYTHONLIBS_FOUND OR NOT SWIG_FOUND)
return()
endif()

include(${SWIG_USE_FILE})

set(PYTHON_SITE_PACKAGES lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/dist-packages/)

set(CMAKE_SWIG_FLAGS "-w401,314")

add_definitions(-Wno-cast-qual -Wno-shadow -Wno-maybe-uninitialized)
set_source_files_properties(../../OgreMain/include/Ogre.i PROPERTIES CPLUSPLUS ON)
swig_add_module(Ogre python ../../OgreMain/include/Ogre.i)
swig_link_libraries(Ogre OgreMain ${PYTHON_LIBRARIES})
set_target_properties(${SWIG_MODULE_Ogre_REAL_NAME} PROPERTIES DEBUG_POSTFIX "")
install(TARGETS ${SWIG_MODULE_Ogre_REAL_NAME} LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_BINARY_DIR}/Components/Python/Ogre.py DESTINATION ${PYTHON_SITE_PACKAGES})

if(OGRE_BUILD_COMPONENT_RTSHADERSYSTEM)
ogre_add_component_include_dir(RTShaderSystem)
set_source_files_properties(../RTShaderSystem/include/OgreRTShader.i PROPERTIES CPLUSPLUS ON)
swig_add_module(OgreRTShader python ../RTShaderSystem/include/OgreRTShader.i)
swig_link_libraries(OgreRTShader OgreMain OgreRTShaderSystem ${PYTHON_LIBRARIES})
set_target_properties(${SWIG_MODULE_OgreRTShader_REAL_NAME} PROPERTIES DEBUG_POSTFIX "")
install(TARGETS ${SWIG_MODULE_OgreRTShader_REAL_NAME} LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_BINARY_DIR}/Components/Python/OgreRTShader.py DESTINATION ${PYTHON_SITE_PACKAGES})
endif()
30 changes: 30 additions & 0 deletions Components/RTShaderSystem/include/OgreRTShader.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%module OgreRTShader
%{
/* Includes the header in the wrapper code */
#include "Ogre.h"
#include "OgreRTShaderSystem.h"
%}

%include std_string.i
%include exception.i
%import "Ogre.i"

#define _OgreRTSSExport

%include "OgreShaderPrerequisites.h"
%include "OgreShaderScriptTranslator.h"
%include "OgreShaderSubRenderState.h"
%include "OgreShaderProgramWriter.h"
%include "OgreShaderGenerator.h"
%include "OgreShaderRenderState.h"
%include "OgreShaderFFPTransform.h"
%include "OgreShaderFFPColour.h"
%include "OgreShaderFFPLighting.h"
%include "OgreShaderFFPTexturing.h"
%include "OgreShaderFFPFog.h"
%include "OgreShaderExPerPixelLighting.h"
%include "OgreShaderExNormalMapLighting.h"
%include "OgreShaderExIntegratedPSSM3.h"
%include "OgreShaderExLayeredBlending.h"
%include "OgreShaderExHardwareSkinning.h"
%include "OgreShaderMaterialSerializerListener.h"
254 changes: 254 additions & 0 deletions OgreMain/include/Ogre.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
%module(directors="1") Ogre
%{
/* Includes the header in the wrapper code */
#include "Ogre.h"
#include "OgreArchiveFactory.h"
#include "OgreRectangle2D.h"
#include "OgreWireBoundingBox.h"
#include "OgreVertexBoneAssignment.h"
#include "OgreCodec.h"
#include "OgreZip.h"
#include "OgreParticleIterator.h"
#include "OgreParticleEmitterFactory.h"
#include "OgreParticleAffectorFactory.h"
#include "OgreUnifiedHighLevelGpuProgram.h"
#include "OgreScriptCompiler.h"
%}

%include std_string.i
%include std_pair.i
%include std_map.i
%include std_multimap.i
%include std_vector.i
%include exception.i

/* Parse the header file to generate wrappers */
#define _OgreExport
#define _OgrePrivate
#define OGRE_NORETURN
#define OGRE_STATIC_MUTEX(arg)
#define OGRE_MUTEX(arg)

%feature("autodoc", "1");
%feature("director") *Listener;
%feature("director") *::Listener;
// should be turned on globally if all renames are in place
%feature("flatnested") Ogre::MaterialManager::Listener;

%ignore *::operator=; // needs rename to wrap
%ignore *::operator[]; // needs rename to wrap
%ignore *::setUserAny; // deprecated
%ignore *::getUserAny; // deprecated
%ignore *::getSingletonPtr; // only expose the non ptr variant
%rename(OgreException) Ogre::Exception; // confilcts with Python Exception

// convert c++ exceptions to language native exceptions
%exception {
try {
$action
} catch (const Ogre::Exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
}
}

/* these are ordered by dependancy */
%include "OgreBuildSettings.h"
%include "OgrePrerequisites.h"
%include "OgrePlatform.h"
%include "OgreConfig.h"
%include "OgreMemoryAllocatorConfig.h"
%include "OgreMemorySTLAllocator.h"
%include "OgreCommon.h"
// Basic Data Types
%include "OgreException.h"
%include "OgreAtomicScalar.h"
%include "OgreSharedPtr.h"
%include "OgreAny.h"
%include "OgreIteratorWrapper.h"
//%include "OgreStringVector.h"
// the original definitions confuses SWIG by typedeffing to std inside a struct
namespace Ogre {
typedef std::vector<std::string> StringVector;
typedef Ogre::SharedPtr<StringVector> StringVectorPtr;
}
%template(StringVector) std::vector<Ogre::String>;
%template(StringVectorPtr) Ogre::SharedPtr<std::vector<std::string> >;
// Linear Algebra
%include "OgreVector2.h"
%include "OgreVector3.h"
%include "OgreVector4.h"
%include "OgreMatrix3.h"
%include "OgreMatrix4.h"
%include "OgreQuaternion.h"
%include "OgreSimpleSpline.h"
%include "OgreRotationalSpline.h"
// Geometric Primitives
%include "OgreAxisAlignedBox.h"
%include "OgreSphere.h"
%include "OgrePlane.h"
%include "OgrePlaneBoundedVolume.h"
// I/O
%include "OgreConfigOptionMap.h"
%ignore Ogre::ConfigFile::load; // conflicting overloads
%include "OgreConfigFile.h"
%feature("valuewrapper") Ogre::Log::Stream;
%include "OgreLog.h"
%include "OgreLogManager.h"
%include "OgreDataStream.h"
%include "OgreArchive.h"
%include "OgreFactoryObj.h"
// %template(FactoryObjArchive) Ogre::FactoryObj<Ogre::Archive>;
%include "OgreArchiveFactory.h"
%ignore Ogre::ZipArchiveFactory; // private
%ignore Ogre::ZipDataStream; // private
%include "OgreZip.h"
%include "OgreArchiveManager.h"
%include "OgreCodec.h"
%include "OgreSerializer.h"
%include "OgreScriptLoader.h"
// Listeners
%include "OgreFrameListener.h"
%include "OgreLodListener.h"
%include "OgreRenderObjectListener.h"
%include "OgreRenderQueueListener.h"
%include "OgreRenderTargetListener.h"
// More Data Types
%include "OgreColourValue.h"
%include "OgrePixelFormat.h"
%include "OgreBlendMode.h"
%include "OgreRay.h"
%include "OgreSceneQuery.h"
%include "OgreNameGenerator.h"
%include "OgreController.h"
%include "OgreRenderSystemCapabilities.h"
%include "OgreGpuProgramParams.h"
%include "OgreImage.h"
%include "OgreBillboard.h"
%include "OgreParticle.h"
%include "OgreHardwareOcclusionQuery.h"
%include "OgreHardwareBuffer.h"
%include "OgreParticleIterator.h"
%include "OgreStringInterface.h"
%include "OgreParticleAffector.h"
%include "OgreParticleAffectorFactory.h"
%include "OgreParticleEmitterCommands.h"
%include "OgreParticleEmitter.h"
%include "OgreParticleEmitterFactory.h"
%include "OgreResource.h"
%include "OgreTexture.h"
%include "OgreGpuProgram.h"
%include "OgreHighLevelGpuProgram.h"
%include "OgreScriptCompiler.h"
%include "OgreTextureUnitState.h"
%include "OgreControllerManager.h"
%include "OgreCompositor.h"
%include "OgreCompositionTechnique.h"
%include "OgreCompositionTargetPass.h"
%include "OgreResourceBackgroundQueue.h"
// instantiated in c++ code
// %template(HardwareVertexBufferPtr) Ogre::SharedPtr<Ogre::HardwareVertexBuffer>;
%include "OgreHardwareVertexBuffer.h"
// instantiated in c++ code
// %template(HardwareIndexBufferPtr) Ogre::SharedPtr<Ogre::HardwareIndexBuffer>;
%include "OgreHardwareIndexBuffer.h"
// instantiated in c++ code
// %template(HardwarePixelBufferPtr) Ogre::SharedPtr<Ogre::HardwarePixelBuffer>;
%include "OgreHardwarePixelBuffer.h"
// instantiated in c++ code
// %template(HardwareCounterBufferPtr) Ogre::SharedPtr<Ogre::HardwareCounterBuffer>;
%include "OgreHardwareCounterBuffer.h"
// instantiated in c++ code
// %template(HardwareUniformBufferPtr) Ogre::SharedPtr<Ogre::HardwareUniformBuffer>;
%include "OgreHardwareUniformBuffer.h"
%include "OgreHardwareBufferManager.h"
%include "OgreVertexIndexData.h"
// managers
%include "OgreResourceGroupManager.h"
// overloaded by specfic managers (GpuProgram, Texture)
%ignore Ogre::ResourceManager::getResourceByName;
%ignore Ogre::ResourceManager::createOrRetrieve;
%ignore Ogre::ResourceManager::prepare;
%ignore Ogre::ResourceManager::load;
%include "OgreResourceManager.h"
%include "OgreTextureManager.h"
%include "OgreGpuProgramManager.h"
%include "OgreHighLevelGpuProgramManager.h"
%ignore Ogre::UnifiedHighLevelGpuProgram::setPrioriry;
%include "OgreUnifiedHighLevelGpuProgram.h"
// animations
%include "OgreKeyFrame.h"
%include "OgrePose.h"
%include "OgreAnimationTrack.h"
%include "OgreAnimationState.h"
%include "OgreAnimation.h"
%include "OgreSkeleton.h"
%include "OgreSkeletonInstance.h"
%include "OgreSkeletonManager.h"
%include "OgreRenderQueue.h"
%include "OgreRenderOperation.h"
%include "OgreMaterial.h"
%include "OgreRenderSystem.h"
%include "OgreCompositorManager.h"
%include "OgreCompositorInstance.h"
%include "OgreCompositionPass.h"
%include "OgreMaterialSerializer.h"
%include "OgreUserObjectBindings.h"
%rename(MaterialManager_Listener) Ogre::MaterialManager::Listener;
%include "OgreMaterialManager.h"
%include "OgreRenderable.h"
%include "OgreBillboardChain.h"
%include "OgreRibbonTrail.h"
%include "OgreBillboardSet.h"
%include "OgreShadowCaster.h"
%include "OgreMovableObject.h"
%include "OgreMovablePlane.h"
%include "OgreLight.h"
%include "OgreNode.h"
%include "OgreBone.h"
%include "OgreSceneNode.h"
%include "OgreShadowCameraSetup.h"
%include "OgreShadowCameraSetupFocused.h"
%include "OgreShadowCameraSetupLiSPSM.h"
%include "OgreShadowCameraSetupPlaneOptimal.h"
%include "OgreShadowCameraSetupPSSM.h"
%include "OgreFrustum.h"
%include "OgreCamera.h"
%include "OgreManualObject.h"
%include "OgreEntity.h"
%include "OgreSubEntity.h"
%include "OgreParticleSystem.h"
%include "OgreInstancedEntity.h"
%include "OgreInstanceBatch.h"
%include "OgreSimpleRenderable.h"
%include "OgreRectangle2D.h"
%include "OgreWireBoundingBox.h"
%include "OgreParticleSystemManager.h"
%include "OgreInstanceManager.h"
%include "OgreVertexBoneAssignment.h"
%include "OgreMesh.h"
%include "OgreSubMesh.h"
%include "OgreStaticGeometry.h"
%include "OgrePatchSurface.h"
%include "OgrePatchMesh.h"
%include "OgreMeshManager.h"
%include "OgrePass.h"
%include "OgreTechnique.h"
%include "OgreRenderTarget.h"
%include "OgreRenderWindow.h"
%include "OgreRenderTexture.h"
%include "OgreViewport.h"
%include "OgreCompositorChain.h"
%include "OgreShadowTextureManager.h"
%include "OgreRenderQueueSortingGrouping.h"
%include "OgreRenderQueueInvocation.h"
%include "OgreSceneManager.h"
%include "OgreSceneManagerEnumerator.h"
%include "OgreRoot.h"
// dont wrap: platform specific
// %include "OgreWindowEventUtilities.h"
// %include "OgreTimer.h"
// dont wrap: not useful in high level languages
// %include "OgreRadixSort.h"
// %include "OgreString.h"
// %include "OgreStringConverter.h"
// %include "OgreProfiler.h"
Loading

0 comments on commit 1d86810

Please sign in to comment.