opensubdiv.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2013 Blender Foundation. All rights reserved.
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software Foundation,
  15. // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #include "opensubdiv_capi.h"
  17. #ifdef _MSC_VER
  18. # include <iso646.h>
  19. #endif
  20. #include <GL/glew.h>
  21. #include "opensubdiv_device_context_opencl.h"
  22. #include "opensubdiv_device_context_cuda.h"
  23. #include "opensubdiv_gl_mesh_capi.h"
  24. void openSubdiv_init(void)
  25. {
  26. // Ensure all OpenGL strings are cached.
  27. openSubdiv_getAvailableEvaluators();
  28. }
  29. void openSubdiv_cleanup(void)
  30. {
  31. openSubdiv_deinitGLMeshDrawingResources();
  32. }
  33. int openSubdiv_getAvailableEvaluators(void)
  34. {
  35. int flags = OPENSUBDIV_EVALUATOR_CPU;
  36. #ifdef OPENSUBDIV_HAS_OPENMP
  37. flags |= OPENSUBDIV_EVALUATOR_OPENMP;
  38. #endif
  39. #ifdef OPENSUBDIV_HAS_OPENCL
  40. if (CLDeviceContext::HAS_CL_VERSION_1_1()) {
  41. flags |= OPENSUBDIV_EVALUATOR_OPENCL;
  42. }
  43. #endif
  44. #ifdef OPENSUBDIV_HAS_CUDA
  45. if (CudaDeviceContext::HAS_CUDA_VERSION_4_0()) {
  46. flags |= OPENSUBDIV_EVALUATOR_CUDA;
  47. }
  48. #endif
  49. #ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
  50. if (GLEW_VERSION_4_1) {
  51. flags |= OPENSUBDIV_EVALUATOR_GLSL_TRANSFORM_FEEDBACK;
  52. }
  53. #endif
  54. #ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
  55. if (GLEW_VERSION_4_3 || GLEW_ARB_compute_shader) {
  56. flags |= OPENSUBDIV_EVALUATOR_GLSL_COMPUTE;
  57. }
  58. #endif
  59. return flags;
  60. }
  61. int openSubdiv_getVersionHex(void)
  62. {
  63. #if defined(OPENSUBDIV_VERSION_NUMBER)
  64. return OPENSUBDIV_VERSION_NUMBER;
  65. #elif defined(OPENSUBDIV_VERSION_MAJOR)
  66. return OPENSUBDIV_VERSION_MAJOR * 10000 + OPENSUBDIV_VERSION_MINOR * 100 +
  67. OPENSUBDIV_VERSION_PATCH;
  68. #elif defined(OPENSUBDIV_VERSION)
  69. const char *version = STRINGIFY(OPENSUBDIV_VERSION);
  70. if (version[0] == 'v') {
  71. version += 1;
  72. }
  73. int major = 0, minor = 0, patch = 0;
  74. vector<string> tokens;
  75. opensubdiv_capi::stringSplit(&tokens, version, "_", true);
  76. if (tokens.size() == 3) {
  77. major = atoi(tokens[0].c_str());
  78. minor = atoi(tokens[1].c_str());
  79. patch = atoi(tokens[2].c_str());
  80. }
  81. return major * 10000 + minor * 100 + patch;
  82. #else
  83. return 0;
  84. #endif
  85. }