Cleanup: fix compiler warnings.
[blender.git] / intern / opensubdiv / opensubdiv_utils_capi.cc
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 #include "opensubdiv_capi.h"
21
22 #include <cstring>
23 #include <GL/glew.h>
24
25 #ifdef _MSC_VER
26 #  include "iso646.h"
27 #endif
28
29 #ifdef OPENSUBDIV_HAS_OPENCL
30 #  include "opensubdiv_device_context_opencl.h"
31 #endif  /* OPENSUBDIV_HAS_OPENCL */
32
33 #ifdef OPENSUBDIV_HAS_CUDA
34 #  include "opensubdiv_device_context_cuda.h"
35 #endif  /* OPENSUBDIV_HAS_CUDA */
36
37 static bool gpu_legacy_support_global = false;
38
39 int openSubdiv_getAvailableEvaluators(void)
40 {
41         if (!openSubdiv_supportGPUDisplay()) {
42                 return 0;
43         }
44
45         int flags = OPENSUBDIV_EVALUATOR_CPU;
46
47 #ifdef OPENSUBDIV_HAS_OPENMP
48         flags |= OPENSUBDIV_EVALUATOR_OPENMP;
49 #endif  /* OPENSUBDIV_HAS_OPENMP */
50
51 #ifdef OPENSUBDIV_HAS_OPENCL
52         if (CLDeviceContext::HAS_CL_VERSION_1_1()) {
53                 flags |= OPENSUBDIV_EVALUATOR_OPENCL;
54         }
55 #endif  /* OPENSUBDIV_HAS_OPENCL */
56
57 #ifdef OPENSUBDIV_HAS_CUDA
58         if (CudaDeviceContext::HAS_CUDA_VERSION_4_0()) {
59                 flags |= OPENSUBDIV_EVALUATOR_CUDA;
60         }
61 #endif  /* OPENSUBDIV_HAS_OPENCL */
62
63 #ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
64         if (GLEW_VERSION_4_1) {
65                 flags |= OPENSUBDIV_EVALUATOR_GLSL_TRANSFORM_FEEDBACK;
66         }
67 #endif  /* OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK */
68
69 #ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
70         if (GLEW_VERSION_4_3 || GLEW_ARB_compute_shader) {
71                 flags |= OPENSUBDIV_EVALUATOR_GLSL_COMPUTE;
72         }
73 #endif  /* OPENSUBDIV_HAS_GLSL_COMPUTE */
74
75         return flags;
76 }
77
78 void openSubdiv_init(bool gpu_legacy_support)
79 {
80         /* Ensure all OpenGL strings are cached. */
81         (void)openSubdiv_getAvailableEvaluators();
82         gpu_legacy_support_global = gpu_legacy_support;
83 }
84
85 void openSubdiv_cleanup(void)
86 {
87         openSubdiv_osdGLDisplayDeinit();
88 }
89
90 bool openSubdiv_gpu_legacy_support(void)
91 {
92         return gpu_legacy_support_global;
93 }