From cff0d96f09419b0eab44904c87ba4e69f15acbb7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 4 Nov 2010 22:56:18 +0100 Subject: [PATCH] applied Edgar's patch (#20) --- SConstruct | 93 ++++++++++++++------------- include/mitsuba/core/atomic.h | 12 ++++ include/mitsuba/core/ref.h | 2 + include/mitsuba/core/stl.h | 13 +++- include/mitsuba/render/records.inl | 6 +- src/integrators/photonmapper/ppm.cpp | 4 +- src/integrators/photonmapper/sppm.cpp | 6 +- src/libhw/wgldevice.cpp | 2 +- src/shapes/ply/ply.cpp | 26 +++++++- src/shapes/ply/ply/ply_parser.hpp | 71 +++++++++++++++++++- 10 files changed, 175 insertions(+), 60 deletions(-) diff --git a/SConstruct b/SConstruct index 278f8954..e4e43dd3 100644 --- a/SConstruct +++ b/SConstruct @@ -22,6 +22,7 @@ vars.Add('CXXFLAGS', 'C++ flags') vars.Add('CCFLAGS', 'C compiler flags') vars.Add('STRIP', 'Program for stripping away unused symbols') vars.Add('SHCXXFLAGS', 'C++ flags (for shared libraries)') +vars.Add('LINK', 'Linker') vars.Add('LINKFLAGS', 'Linker flags') vars.Add('SHLINKFLAGS', 'Linker flags (dynamic libraries)') vars.Add('BASEINCLUDE', 'Base include path') @@ -71,11 +72,11 @@ env.Append(CPPFLAGS=[]) env.Append(LIBPATH=[]) env.Append(LIBS=env['BASELIB']) if env.has_key('BOOSTINCLUDE'): - env.Append(CPPPATH=env['BOOSTINCLUDE']) + env.Prepend(CPPPATH=env['BOOSTINCLUDE']) if env.has_key('BOOSTLIBDIR'): - env.Append(LIBPATH=env['BOOSTLIBDIR']) + env.Prepend(LIBPATH=env['BOOSTLIBDIR']) if env.has_key('BOOSTLIB'): - env.Append(LIBS=env['BOOSTLIB']) + env.Prepend(LIBS=env['BOOSTLIB']) if env.has_key('BASELIBDIR'): env.Append(LIBPATH=env['BASELIBDIR']) @@ -117,31 +118,31 @@ cppFlagsPrevious = SCons.Util.semi_deepcopy(env['CPPFLAGS']) cxxFlagsPrevious = SCons.Util.semi_deepcopy(env['CXXFLAGS']) if env.has_key('PNGINCLUDE'): - env.Append(CPPPATH=env['PNGINCLUDE']) + env.Prepend(CPPPATH=env['PNGINCLUDE']) if env.has_key('PNGLIBDIR'): - env.Append(LIBPATH=env['PNGLIBDIR']) + env.Prepend(LIBPATH=env['PNGLIBDIR']) if env.has_key('JPEGINCLUDE'): - env.Append(CPPPATH=env['JPEGINCLUDE']) + env.Prepend(CPPPATH=env['JPEGINCLUDE']) if env.has_key('JPEGLIBDIR'): - env.Append(LIBPATH=env['JPEGLIBDIR']) + env.Prepend(LIBPATH=env['JPEGLIBDIR']) if env.has_key('OEXRFLAGS'): - env.Append(CPPFLAGS=env['OEXRFLAGS']) + env.Prepend(CPPFLAGS=env['OEXRFLAGS']) if env.has_key('OEXRINCLUDE'): - env.Append(CPPPATH=env['OEXRINCLUDE']) + env.Prepend(CPPPATH=env['OEXRINCLUDE']) if env.has_key('OEXRLIBDIR'): - env.Append(LIBPATH=env['OEXRLIBDIR']) + env.Prepend(LIBPATH=env['OEXRLIBDIR']) if env.has_key('XERCESINCLUDE'): - env.Append(CPPPATH=env['XERCESINCLUDE']) + env.Prepend(CPPPATH=env['XERCESINCLUDE']) if env.has_key('XERCESLIBDIR'): - env.Append(LIBPATH=env['XERCESLIBDIR']) + env.Prepend(LIBPATH=env['XERCESLIBDIR']) if env.has_key('GLINCLUDE'): - env.Append(CPPPATH=env['GLINCLUDE']) + env.Prepend(CPPPATH=env['GLINCLUDE']) if env.has_key('GLFLAGS'): - env.Append(CPPFLAGS=env['GLFLAGS']) + env.Prepend(CPPFLAGS=env['GLFLAGS']) if env.has_key('COLLADAINCLUDE'): - env.Append(CPPPATH=env['COLLADAINCLUDE']) + env.Prepend(CPPPATH=env['COLLADAINCLUDE']) if env.has_key('COLLADALIBDIR'): - env.Append(LIBPATH=env['COLLADALIBDIR']) + env.Prepend(LIBPATH=env['COLLADALIBDIR']) if not conf.CheckCXX(): print 'Could not compile a simple C++ fragment, verify that ' + env['CXX'] + ' is installed!' @@ -245,27 +246,27 @@ except: # Core library coreEnv = env.Clone() if coreEnv.has_key('OEXRLIBDIR'): - coreEnv.Append(LIBPATH=env['OEXRLIBDIR']) + coreEnv.Prepend(LIBPATH=env['OEXRLIBDIR']) if coreEnv.has_key('OEXRINCLUDE'): - coreEnv.Append(CPPPATH=env['OEXRINCLUDE']) + coreEnv.Prepend(CPPPATH=env['OEXRINCLUDE']) if coreEnv.has_key('OEXRFLAGS'): - coreEnv.Append(CPPFLAGS=env['OEXRFLAGS']) + coreEnv.Prepend(CPPFLAGS=env['OEXRFLAGS']) if coreEnv.has_key('OEXRLIB'): - coreEnv.Append(LIBS=env['OEXRLIB']) + coreEnv.Prepend(LIBS=env['OEXRLIB']) if coreEnv.has_key('PNGLIBDIR'): - coreEnv.Append(LIBPATH=env['PNGLIBDIR']) + coreEnv.Prepend(LIBPATH=env['PNGLIBDIR']) if coreEnv.has_key('PNGINCLUDE'): - coreEnv.Append(CPPPATH=env['PNGINCLUDE']) + coreEnv.Prepend(CPPPATH=env['PNGINCLUDE']) if coreEnv.has_key('PNGLIB'): - coreEnv.Append(LIBS=env['PNGLIB']) + coreEnv.Prepend(LIBS=env['PNGLIB']) if coreEnv.has_key('JPEGLIBDIR'): - coreEnv.Append(LIBPATH=env['JPEGLIBDIR']) + coreEnv.Prepend(LIBPATH=env['JPEGLIBDIR']) if coreEnv.has_key('JPEGINCLUDE'): - coreEnv.Append(CPPPATH=env['JPEGINCLUDE']) + coreEnv.Prepend(CPPPATH=env['JPEGINCLUDE']) if coreEnv.has_key('JPEGLIB'): - coreEnv.Append(LIBS=env['JPEGLIB']) + coreEnv.Prepend(LIBS=env['JPEGLIB']) -coreEnv.Append(CPPDEFINES = [['MTS_BUILD_MODULE', 'MTS_MODULE_CORE']]) +coreEnv.Prepend(CPPDEFINES = [['MTS_BUILD_MODULE', 'MTS_MODULE_CORE']]) libcore_objects = [ 'src/libcore/class.cpp', 'src/libcore/object.cpp', 'src/libcore/statistics.cpp', 'src/libcore/thread.cpp', @@ -308,11 +309,11 @@ env.Append(LIBPATH=['src/libcore']) renderEnv = env.Clone() renderEnv.Append(CPPDEFINES = [['MTS_BUILD_MODULE', 'MTS_MODULE_RENDER']] ) if renderEnv.has_key('XERCESINCLUDE'): - renderEnv.Append(CPPPATH=renderEnv['XERCESINCLUDE']) + renderEnv.Prepend(CPPPATH=renderEnv['XERCESINCLUDE']) if renderEnv.has_key('XERCESLIBDIR'): - renderEnv.Append(LIBPATH=renderEnv['XERCESLIBDIR']) + renderEnv.Prepend(LIBPATH=renderEnv['XERCESLIBDIR']) if renderEnv.has_key('XERCESLIB'): - renderEnv.Append(LIBS=renderEnv['XERCESLIB']) + renderEnv.Prepend(LIBS=renderEnv['XERCESLIB']) librender = renderEnv.SharedLibrary('src/librender/mitsuba-render', [ 'src/librender/bsdf.cpp', 'src/librender/camera.cpp', 'src/librender/film.cpp', 'src/librender/integrator.cpp', @@ -362,13 +363,13 @@ elif sys.platform == 'linux2': glEnv = env.Clone() glEnv.Append(CPPDEFINES = [['MTS_BUILD_MODULE', 'MTS_MODULE_HW']] ) if glEnv.has_key('GLLIB'): - glEnv.Append(LIBS=glEnv['GLLIB']) + glEnv.Prepend(LIBS=glEnv['GLLIB']) if glEnv.has_key('GLLIBDIR'): - glEnv.Append(LIBPATH=glEnv['GLLIBDIR']) + glEnv.Prepend(LIBPATH=glEnv['GLLIBDIR']) if glEnv.has_key('GLFLAGS'): - glEnv.Append(CPPFLAGS=glEnv['GLFLAGS']) + glEnv.Prepend(CPPFLAGS=glEnv['GLFLAGS']) if glEnv.has_key('GLINCLUDE'): - glEnv.Append(CPPPATH=glEnv['GLINCLUDE']) + glEnv.Prepend(CPPPATH=glEnv['GLINCLUDE']) if sys.platform == 'darwin': glEnv_osx = glEnv.Clone(); @@ -391,19 +392,19 @@ env['SHLIBPREFIX']='' # Environment with Xerces + wxWidgets mainEnv = env.Clone() if mainEnv.has_key('XERCESINCLUDE'): - mainEnv.Append(CPPPATH=mainEnv['XERCESINCLUDE']) + mainEnv.Prepend(CPPPATH=mainEnv['XERCESINCLUDE']) if mainEnv.has_key('XERCESLIBDIR'): - mainEnv.Append(LIBPATH=mainEnv['XERCESLIBDIR']) + mainEnv.Prepend(LIBPATH=mainEnv['XERCESLIBDIR']) if mainEnv.has_key('XERCESLIB'): - mainEnv.Append(LIBS=mainEnv['XERCESLIB']) + mainEnv.Prepend(LIBS=mainEnv['XERCESLIB']) if mainEnv.has_key('GLLIB'): - mainEnv.Append(LIBS=mainEnv['GLLIB']) + mainEnv.Prepend(LIBS=mainEnv['GLLIB']) if mainEnv.has_key('GLLIBDIR'): - mainEnv.Append(LIBPATH=mainEnv['GLLIBDIR']) + mainEnv.Prepend(LIBPATH=mainEnv['GLLIBDIR']) if mainEnv.has_key('GLFLAGS'): - mainEnv.Append(CXXFLAGS=mainEnv['GLFLAGS']) + mainEnv.Prepend(CXXFLAGS=mainEnv['GLFLAGS']) if mainEnv.has_key('GLINCLUDE'): - mainEnv.Append(CPPPATH=mainEnv['GLINCLUDE']) + mainEnv.Prepend(CPPPATH=mainEnv['GLINCLUDE']) resources = [] darwinStub = [] @@ -436,11 +437,11 @@ if hasCollada: colladaEnv.Append(LIBS=['mitsuba-hw']) colladaEnv.Append(LIBPATH=['src/libhw']) if env.has_key('COLLADAINCLUDE'): - colladaEnv.Append(CPPPATH=env['COLLADAINCLUDE']) + colladaEnv.Prepend(CPPPATH=env['COLLADAINCLUDE']) if env.has_key('COLLADALIBDIR'): - colladaEnv.Append(LIBPATH=env['COLLADALIBDIR']) + colladaEnv.Prepend(LIBPATH=env['COLLADALIBDIR']) if env.has_key('COLLADALIB'): - colladaEnv.Append(LIBS=env['COLLADALIB']) + colladaEnv.Prepend(LIBS=env['COLLADALIB']) converter_objects = [ colladaEnv.StaticObject('src/converter/collada.cpp'), colladaEnv.StaticObject('src/converter/obj.cpp'), @@ -473,9 +474,9 @@ if hasQt: if hasCollada: qtgui_files += converter_objects if env.has_key('COLLADALIBDIR'): - qtEnv.Append(LIBPATH=env['COLLADALIBDIR']) + qtEnv.Prepend(LIBPATH=env['COLLADALIBDIR']) if env.has_key('COLLADALIB'): - qtEnv.Append(LIBS=env['COLLADALIB']) + qtEnv.Prepend(LIBS=env['COLLADALIB']) if sys.platform == 'darwin': qtEnv_osx = qtEnv.Clone(); diff --git a/include/mitsuba/core/atomic.h b/include/mitsuba/core/atomic.h index 4af4d365..d55fe6d0 100644 --- a/include/mitsuba/core/atomic.h +++ b/include/mitsuba/core/atomic.h @@ -32,7 +32,19 @@ template inline bool atomicCompareAndExchangePtr(T **v, T *newValue return InterlockedCompareExchangePointer( reinterpret_cast(v), newValue, oldValue) == oldValue; #else + #if !defined(__clang__) return __sync_bool_compare_and_swap(v, oldValue, newValue); + #else + #if __SIZEOF_POINTER__ == 8 + return __sync_bool_compare_and_swap( + reinterpret_cast(v), reinterpret_cast(oldValue), + reinterpret_cast(newValue)); + #else + return __sync_bool_compare_and_swap( + reinterpret_cast(v), reinterpret_cast(oldValue), + reinterpret_cast(newValue)); + #endif + #endif #endif } diff --git a/include/mitsuba/core/ref.h b/include/mitsuba/core/ref.h index ba2176ec..52b29e7b 100644 --- a/include/mitsuba/core/ref.h +++ b/include/mitsuba/core/ref.h @@ -19,6 +19,8 @@ #if !defined(__REFERENCE_H) #define __REFERENCE_H +#include "util.h" + MTS_NAMESPACE_BEGIN /** diff --git a/include/mitsuba/core/stl.h b/include/mitsuba/core/stl.h index c0335feb..66bf4c44 100644 --- a/include/mitsuba/core/stl.h +++ b/include/mitsuba/core/stl.h @@ -161,17 +161,26 @@ MTS_NAMESPACE_END #if defined(WIN32) inline bool ubi_isnan(float f) { int classification = ::_fpclass(f); - return classification == _FPCLASS_QNAN || classification == _FPCLASS_SNAN; + return classification == _FPCLASS_QNAN + || classification == _FPCLASS_SNAN; } inline bool ubi_isnan(double f) { int classification = ::_fpclass(f); - return classification == _FPCLASS_QNAN || classification == _FPCLASS_SNAN; + return classification == _FPCLASS_QNAN + || classification == _FPCLASS_SNAN; } extern "C" { extern MTS_EXPORT_CORE float nextafterf(float x, float y); }; +#elif defined(__clang__) +inline bool ubi_isnan(float f) { + return std::isnan(f); +} +inline bool ubi_isnan(double f) { + return std::isnan(f); +} #else inline bool ubi_isnan(float f) { return std::fpclassify(f) == FP_NAN; diff --git a/include/mitsuba/render/records.inl b/include/mitsuba/render/records.inl index 0e68dc89..02215b2f 100644 --- a/include/mitsuba/render/records.inl +++ b/include/mitsuba/render/records.inl @@ -16,17 +16,17 @@ inline BSDFQueryRecord::BSDFQueryRecord(const Intersection &its, Point2 sample) inline BSDFQueryRecord::BSDFQueryRecord(RadianceQueryRecord &rRec, const Intersection &its, const Vector &wo) - : rRec(&rRec), its(its), wi(its.wi), wo(wo), sample(sample), quantity(ERadiance), + : rRec(&rRec), its(its), wi(its.wi), wo(wo), quantity(ERadiance), typeMask(0xFFFFFFFF), sampledType(0), component(-1), sampledComponent(-1) { } inline BSDFQueryRecord::BSDFQueryRecord(const Intersection &its, const Vector &wo) - : rRec(NULL), its(its), wi(its.wi), wo(wo), sample(sample), quantity(ERadiance), + : rRec(NULL), its(its), wi(its.wi), wo(wo), quantity(ERadiance), typeMask(0xFFFFFFFF), sampledType(0), component(-1), sampledComponent(-1) { } inline BSDFQueryRecord::BSDFQueryRecord(const Intersection &its, const Vector &wi, const Vector &wo) - : rRec(NULL), its(its), wi(wi), wo(wo), sample(sample), quantity(ERadiance), + : rRec(NULL), its(its), wi(wi), wo(wo), quantity(ERadiance), typeMask(0xFFFFFFFF), sampledType(0), component(-1), sampledComponent(-1) { } diff --git a/src/integrators/photonmapper/ppm.cpp b/src/integrators/photonmapper/ppm.cpp index 4a57c08c..34021687 100644 --- a/src/integrators/photonmapper/ppm.cpp +++ b/src/integrators/photonmapper/ppm.cpp @@ -19,7 +19,7 @@ #include #include #include -#if !defined(__OSX__) +#if !defined(__OSX__) && defined(_OPENMP) #include #endif @@ -124,7 +124,7 @@ public: Vector2i cropSize = film->getCropSize(); Point2i cropOffset = film->getCropOffset(); -#if !defined(__OSX__) +#if !defined(__OSX__) && defined(_OPENMP) omp_set_num_threads(nCores); #endif m_gatherPoints.clear(); diff --git a/src/integrators/photonmapper/sppm.cpp b/src/integrators/photonmapper/sppm.cpp index 38a3988d..378ad3e3 100644 --- a/src/integrators/photonmapper/sppm.cpp +++ b/src/integrators/photonmapper/sppm.cpp @@ -20,7 +20,7 @@ #include #include #include -#if !defined(__OSX__) +#if !defined(__OSX__) && defined(_OPENMP) #include #endif @@ -150,7 +150,7 @@ public: int samplerResID = sched->registerManifoldResource( static_cast &>(samplers)); -#if !defined(__OSX__) +#if !defined(__OSX__) && defined(_OPENMP) omp_set_num_threads(nCores); #endif @@ -178,7 +178,7 @@ public: #pragma omp parallel for schedule(dynamic) for (int i=-1; i<(int) m_gatherBlocks.size(); ++i) { std::vector &gatherPoints = m_gatherBlocks[i]; -#if !defined(__OSX__) +#if !defined(__OSX__) && defined(_OPENMP) Sampler *sampler = static_cast(samplers[omp_get_thread_num()]); #else Sampler *sampler = static_cast(samplers[0]); diff --git a/src/libhw/wgldevice.cpp b/src/libhw/wgldevice.cpp index 36aadd7c..b7c1d212 100644 --- a/src/libhw/wgldevice.cpp +++ b/src/libhw/wgldevice.cpp @@ -289,7 +289,7 @@ void WGLDevice::init(Device *other) { if (!m_hwnd) Log(EError, "Unable to create the window"); - SetWindowLong(m_hwnd, 0, (LONG) this); + SetWindowLongPtr(m_hwnd, 0, (LONG_PTR) this); ShowWindow(m_hwnd, SW_HIDE); /* Switch to fullscreen */ diff --git a/src/shapes/ply/ply.cpp b/src/shapes/ply/ply.cpp index 3de49ebe..7fc4bbb6 100644 --- a/src/shapes/ply/ply.cpp +++ b/src/shapes/ply/ply.cpp @@ -22,11 +22,35 @@ #include #include #include -#if defined(WIN32) + +#if defined(__clang__) +#define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates)) +#else +# if defined(_MSC_VER) && (_MSC_VER < 1600) +# define MTS_USE_BOOST_TR1 1 +# else +# define MTS_USE_BOOST_TR1 0 +# endif +#endif + +#if MTS_USE_BOOST_TR1 +# if defined(Float) +# define MTS_Float +# pragma push_macro("Float") +# undef Float +# endif #include +# if defined(MTS_Float) +# pragma pop_macro("Float") +# undef MTS_Float +# endif +#else +#if defined(_MSC_VER) && (_MSC_VER >= 1600) +#include #else #include #endif +#endif using namespace std::tr1::placeholders; diff --git a/src/shapes/ply/ply/ply_parser.hpp b/src/shapes/ply/ply/ply_parser.hpp index ac443f45..a125d776 100644 --- a/src/shapes/ply/ply/ply_parser.hpp +++ b/src/shapes/ply/ply/ply_parser.hpp @@ -9,14 +9,39 @@ #include #include -#if defined(WIN32) +#if defined(__clang__) +#define MTS_USE_BOOST_TR1 (!__has_feature(cxx_variadic_templates)) +#else +# if defined(_MSC_VER) && (_MSC_VER < 1600) +# define MTS_USE_BOOST_TR1 1 +# else +# define MTS_USE_BOOST_TR1 0 +# endif +#endif + +#if MTS_USE_BOOST_TR1 +# if defined(Float) +# define MTS_Float +# pragma push_macro("Float") +# undef Float +# endif #include #include #include +# if defined(MTS_Float) +# pragma pop_macro("Float") +# undef MTS_Float +# endif +#else +#if defined(_MSC_VER) && (_MSC_VER >= 1600) +#include +#include +#include #else #include #include #endif +#endif #include #include @@ -93,6 +118,7 @@ public: { return static_cast&>(callbacks_).callback; } +#if !defined(__clang__) template friend typename scalar_property_definition_callback_type::type& at(scalar_property_definition_callbacks_type& scalar_property_definition_callbacks) { @@ -103,6 +129,7 @@ public: { return scalar_property_definition_callbacks.get(); } +#endif }; template @@ -183,6 +210,7 @@ public: { return static_cast >&>(callbacks_).callback; } +#if !defined(__clang__) template friend typename list_property_definition_callback_type::type& at(list_property_definition_callbacks_type& list_property_definition_callbacks) { @@ -193,6 +221,7 @@ public: { return list_property_definition_callbacks.get(); } +#endif }; void info_callback(const info_callback_type& info_callback); @@ -374,7 +403,10 @@ inline void ply::ply_parser::parse_list_property_definition(const std::string& p { typedef SizeType size_type; typedef ScalarType scalar_type; - typename list_property_definition_callback_type::type& list_property_definition_callback = list_property_definition_callbacks_.get(); + #if !defined(__INTEL_COMPILER) + typename + #endif + list_property_definition_callback_type::type& list_property_definition_callback = list_property_definition_callbacks_.get(); typedef typename list_property_begin_callback_type::type list_property_begin_callback_type; typedef typename list_property_element_callback_type::type list_property_element_callback_type; typedef typename list_property_end_callback_type::type list_property_end_callback_type; @@ -517,4 +549,39 @@ inline bool ply::ply_parser::parse_list_property(format_type format, std::istrea } } +#if defined(__clang__) +// Horrible workaround for ADT failure as of Clang 2.8 +namespace ply +{ + +template +typename ply_parser::scalar_property_definition_callback_type::type& at +(ply_parser::scalar_property_definition_callbacks_type& scalar_property_definition_callbacks) +{ +return scalar_property_definition_callbacks.get(); +} +template +const typename ply_parser::scalar_property_definition_callback_type::type& at +(const ply_parser::scalar_property_definition_callbacks_type& scalar_property_definition_callbacks) +{ +return scalar_property_definition_callbacks.get(); +} + + +template +typename ply_parser::list_property_definition_callback_type::type& at +(ply_parser::list_property_definition_callbacks_type& list_property_definition_callbacks) +{ +return list_property_definition_callbacks.get(); +} +template +const typename ply_parser::list_property_definition_callback_type::type& at +(const ply_parser::list_property_definition_callbacks_type& list_property_definition_callbacks) +{ +return list_property_definition_callbacks.get(); +} + +} // namespace ply +#endif + #endif // PLY_PLY_PARSER_HPP_INCLUDED