Cleanup: fix compiler warnings.
[blender.git] / intern / opensubdiv / opensubdiv_capi.h
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 #ifndef __OPENSUBDIV_CAPI_H__
21 #define __OPENSUBDIV_CAPI_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 // Types declaration.
28 struct OpenSubdiv_GLMesh;
29 struct OpenSubdiv_GLMeshFVarData;
30 struct OpenSubdiv_TopologyRefinerDescr;
31
32 typedef struct OpenSubdiv_GLMesh OpenSubdiv_GLMesh;
33
34 #ifdef __cplusplus
35 struct OpenSubdiv_GLMeshDescr;
36
37 typedef struct OpenSubdiv_GLMesh {
38         int evaluator_type;
39         OpenSubdiv_GLMeshDescr *descriptor;
40         OpenSubdiv_TopologyRefinerDescr *topology_refiner;
41         OpenSubdiv_GLMeshFVarData *fvar_data;
42 } OpenSubdiv_GLMesh;
43 #endif
44
45 // Keep this a bitmask os it's possible to pass available
46 // evaluators to Blender.
47 enum {
48         OPENSUBDIV_EVALUATOR_CPU                      = (1 << 0),
49         OPENSUBDIV_EVALUATOR_OPENMP                   = (1 << 1),
50         OPENSUBDIV_EVALUATOR_OPENCL                   = (1 << 2),
51         OPENSUBDIV_EVALUATOR_CUDA                     = (1 << 3),
52         OPENSUBDIV_EVALUATOR_GLSL_TRANSFORM_FEEDBACK  = (1 << 4),
53         OPENSUBDIV_EVALUATOR_GLSL_COMPUTE             = (1 << 5),
54 };
55
56 enum {
57         OPENSUBDIV_SCHEME_CATMARK,
58         OPENSUBDIV_SCHEME_BILINEAR,
59         OPENSUBDIV_SCHEME_LOOP,
60 };
61
62 /* TODO(sergey): Re-name and avoid bad level data access. */
63 OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
64         struct OpenSubdiv_TopologyRefinerDescr *topology_refiner,
65         int evaluator_type,
66         int level);
67
68 void openSubdiv_deleteOsdGLMesh(OpenSubdiv_GLMesh *gl_mesh);
69 unsigned int openSubdiv_getOsdGLMeshPatchIndexBuffer(
70         OpenSubdiv_GLMesh *gl_mesh);
71 unsigned int openSubdiv_getOsdGLMeshVertexBuffer(OpenSubdiv_GLMesh *gl_mesh);
72 void openSubdiv_osdGLMeshUpdateVertexBuffer(OpenSubdiv_GLMesh *gl_mesh,
73                                             const float *vertex_data,
74                                             int start_vertex,
75                                             int num_verts);
76 void openSubdiv_osdGLMeshRefine(OpenSubdiv_GLMesh *gl_mesh);
77 void openSubdiv_osdGLMeshSynchronize(OpenSubdiv_GLMesh *gl_mesh);
78 void openSubdiv_osdGLMeshBindVertexBuffer(OpenSubdiv_GLMesh *gl_mesh);
79
80 const struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_getGLMeshTopologyRefiner(
81         OpenSubdiv_GLMesh *gl_mesh);
82
83 /* ** Initialize/Deinitialize global OpenGL drawing buffers/GLSL programs ** */
84 bool openSubdiv_osdGLDisplayInit(void);
85 void openSubdiv_osdGLDisplayDeinit(void);
86
87 /* ** Evaluator API ** */
88
89 struct OpenSubdiv_EvaluatorDescr;
90 typedef struct OpenSubdiv_EvaluatorDescr OpenSubdiv_EvaluatorDescr;
91
92 /* TODO(sergey): Avoid bad-level data access, */
93 OpenSubdiv_EvaluatorDescr *openSubdiv_createEvaluatorDescr(
94         struct OpenSubdiv_TopologyRefinerDescr *topology_refiner,
95         int subsurf_level);
96
97 void openSubdiv_deleteEvaluatorDescr(OpenSubdiv_EvaluatorDescr *evaluator_descr);
98
99 void openSubdiv_setEvaluatorCoarsePositions(OpenSubdiv_EvaluatorDescr *evaluator_descr,
100                                             float *positions,
101                                             int start_vert,
102                                             int num_vert);
103
104 void openSubdiv_setEvaluatorVaryingData(OpenSubdiv_EvaluatorDescr *evaluator_descr,
105                                         float *varying_data,
106                                         int start_vert,
107                                         int num_vert);
108
109 void openSubdiv_evaluateLimit(OpenSubdiv_EvaluatorDescr *evaluator_descr,
110                               int osd_face_index,
111                               float face_u, float face_v,
112                               float P[3],
113                               float dPdu[3],
114                               float dPdv[3]);
115
116 void openSubdiv_evaluateVarying(OpenSubdiv_EvaluatorDescr *evaluator_descr,
117                                int osd_face_index,
118                                float face_u, float face_v,
119                                float varying[3]);
120
121 /* ** Actual drawing ** */
122
123 /* Initialize all the invariants which stays the same for every single path,
124  * for example lighting model stays untouched for the whole mesh.
125  *
126  * TODO(sergey): Some of the stuff could be initialized once for all meshes.
127  */
128 void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl,
129                                         int active_uv_index);
130
131 /* Draw specified patches. */
132 void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh,
133                                  int fill_quads,
134                                  int start_patch,
135                                  int num_patches);
136
137 void openSubdiv_osdGLAllocFVar(struct OpenSubdiv_TopologyRefinerDescr *topology_refiner,
138                                OpenSubdiv_GLMesh *gl_mesh,
139                                const float *fvar_data);
140 void openSubdiv_osdGLDestroyFVar(OpenSubdiv_GLMesh *gl_mesh);
141
142 /* ** Utility functions ** */
143 int openSubdiv_supportGPUDisplay(void);
144 int openSubdiv_getAvailableEvaluators(void);
145 void openSubdiv_init(bool gpu_legacy_support);
146 void openSubdiv_cleanup(void);
147 bool openSubdiv_gpu_legacy_support(void);
148
149 int openSubdiv_getVersionHex(void);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif  // __OPENSUBDIV_CAPI_H__