rtcore.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "../../include/embree2/rtcore.h"
  18. namespace embree
  19. {
  20. /*! decoding of geometry flags */
  21. __forceinline bool isStatic (RTCSceneFlags flags) { return (flags & 1) == RTC_SCENE_STATIC; }
  22. __forceinline bool isDynamic (RTCSceneFlags flags) { return (flags & 1) == RTC_SCENE_DYNAMIC; }
  23. __forceinline bool isCompact (RTCSceneFlags flags) { return (flags & RTC_SCENE_COMPACT) != 0; }
  24. __forceinline bool isRobust (RTCSceneFlags flags) { return (flags & RTC_SCENE_ROBUST) != 0; }
  25. __forceinline bool isCoherent (RTCSceneFlags flags) { return (flags & RTC_SCENE_COHERENT) != 0; }
  26. __forceinline bool isIncoherent(RTCSceneFlags flags) { return (flags & RTC_SCENE_INCOHERENT) != 0; }
  27. __forceinline bool isHighQuality(RTCSceneFlags flags) { return (flags & RTC_SCENE_HIGH_QUALITY) != 0; }
  28. /*! decoding of algorithm flags */
  29. __forceinline bool isInterpolatable(RTCAlgorithmFlags flags) { return (flags & RTC_INTERPOLATE) != 0; }
  30. __forceinline bool isStreamMode(RTCAlgorithmFlags flags) { return (flags & RTC_INTERSECT_STREAM) != 0; }
  31. __forceinline bool isIntersect1Mode(RTCAlgorithmFlags flags) { return (flags & RTC_INTERSECT1) != 0; }
  32. __forceinline bool isIntersect4Mode(RTCAlgorithmFlags flags) { return (flags & RTC_INTERSECT4) != 0; }
  33. __forceinline bool isIntersect8Mode(RTCAlgorithmFlags flags) { return (flags & RTC_INTERSECT8) != 0; }
  34. __forceinline bool isIntersect16Mode(RTCAlgorithmFlags flags) { return (flags & RTC_INTERSECT16) != 0; }
  35. /*! decoding of intersection flags */
  36. __forceinline bool isCoherent (RTCIntersectFlags flags) { return (flags & RTC_INTERSECT_INCOHERENT) == 0; }
  37. __forceinline bool isIncoherent(RTCIntersectFlags flags) { return (flags & RTC_INTERSECT_INCOHERENT) != 0; }
  38. #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8)
  39. # define USE_TASK_ARENA 1
  40. #else
  41. # define USE_TASK_ARENA 0
  42. #endif
  43. /*! Makros used in the rtcore API implementation */
  44. #define RTCORE_CATCH_BEGIN try {
  45. #define RTCORE_CATCH_END(device) \
  46. } catch (std::bad_alloc&) { \
  47. Device::process_error(device,RTC_OUT_OF_MEMORY,"out of memory"); \
  48. } catch (rtcore_error& e) { \
  49. Device::process_error(device,e.error,e.what()); \
  50. } catch (std::exception& e) { \
  51. Device::process_error(device,RTC_UNKNOWN_ERROR,e.what()); \
  52. } catch (...) { \
  53. Device::process_error(device,RTC_UNKNOWN_ERROR,"unknown exception caught"); \
  54. }
  55. #define RTCORE_VERIFY_HANDLE(handle) \
  56. if (handle == nullptr) { \
  57. throw_RTCError(RTC_INVALID_ARGUMENT,"invalid argument"); \
  58. }
  59. #define RTCORE_VERIFY_GEOMID(id) \
  60. if (id == RTC_INVALID_GEOMETRY_ID) { \
  61. throw_RTCError(RTC_INVALID_ARGUMENT,"invalid argument"); \
  62. }
  63. #if 0 // enable to debug print all API calls
  64. #define RTCORE_TRACE(x) std::cout << #x << std::endl;
  65. #else
  66. #define RTCORE_TRACE(x)
  67. #endif
  68. /*! used to throw embree API errors */
  69. struct rtcore_error : public std::exception
  70. {
  71. __forceinline rtcore_error(RTCError error, const std::string& str)
  72. : error(error), str(str) {}
  73. ~rtcore_error() throw() {}
  74. const char* what () const throw () {
  75. return str.c_str();
  76. }
  77. RTCError error;
  78. std::string str;
  79. };
  80. #if defined(DEBUG) // only report file and line in debug mode
  81. #define throw_RTCError(error,str) \
  82. throw rtcore_error(error,std::string(__FILE__) + " (" + toString(__LINE__) + "): " + std::string(str));
  83. #else
  84. #define throw_RTCError(error,str) \
  85. throw rtcore_error(error,str);
  86. #endif
  87. #define RTC_BUILD_SETTINGS_HAS(settings,member) \
  88. (settings.size > (offsetof(RTCBuildSettings,member)+sizeof(settings.member)))
  89. }