EmbreeScene.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. //
  21. #include <xmmintrin.h>
  22. #include <pmmintrin.h>
  23. #include <cmath>
  24. #include <cfloat>
  25. #include "Embree.h"
  26. #include <Atomic/IO/Log.h>
  27. #include "BakeMesh.h"
  28. #include "EmbreeScene.h"
  29. // TODO: Configurable for fast/final bakes?
  30. /*
  31. enum RTCSceneFlags
  32. {
  33. // dynamic type flags
  34. RTC_SCENE_STATIC = (0 << 0), //!< specifies static scene
  35. RTC_SCENE_DYNAMIC = (1 << 0), //!< specifies dynamic scene
  36. // acceleration structure flags
  37. RTC_SCENE_COMPACT = (1 << 8), //!< use memory conservative data structures
  38. RTC_SCENE_COHERENT = (1 << 9), //!< optimize data structures for coherent rays
  39. RTC_SCENE_INCOHERENT = (1 << 10), //!< optimize data structures for in-coherent rays (enabled by default)
  40. RTC_SCENE_HIGH_QUALITY = (1 << 11), //!< create higher quality data structures
  41. // traversal algorithm flags
  42. RTC_SCENE_ROBUST = (1 << 16) //!< use more robust traversal algorithms
  43. };
  44. */
  45. namespace AtomicGlow
  46. {
  47. static void RTCErrorCallback(const RTCError code, const char* str)
  48. {
  49. ATOMIC_LOGERRORF("RTC Error %d: %s", code, str);
  50. }
  51. EmbreeScene::EmbreeScene(Context* context) : Object(context),
  52. rtcDevice_(0),
  53. rtcScene_(0)
  54. {
  55. // Intel says to do this, so we're doing it.
  56. _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
  57. _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
  58. // Create the embree device and scene.
  59. rtcDevice_ = rtcNewDevice(NULL);
  60. rtcDeviceSetErrorFunction(rtcDevice_, RTCErrorCallback);
  61. rtcScene_ = rtcDeviceNewScene(rtcDevice_, RTC_SCENE_STATIC, RTC_INTERSECT1);
  62. }
  63. EmbreeScene::~EmbreeScene()
  64. {
  65. }
  66. void EmbreeScene::Commit()
  67. {
  68. rtcCommit(rtcScene_);
  69. }
  70. }