b40505b197d074326432f2ef42a85f383f93ff50
[blender.git] / intern / opensubdiv / opensubdiv_capi.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Sergey Sharybin
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 #ifndef __OPENSUBDIV_CAPI_H__
27 #define __OPENSUBDIV_CAPI_H__
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 // Types declaration.
34 struct OpenSubdiv_GLMesh;
35 struct OpenSubdiv_TopologyRefinerDescr;
36
37 typedef struct OpenSubdiv_GLMesh OpenSubdiv_GLMesh;
38
39 #ifdef __cplusplus
40 struct OpenSubdiv_GLMeshDescr;
41 typedef struct OpenSubdiv_GLMesh {
42         int evaluator_type;
43         OpenSubdiv_GLMeshDescr *descriptor;
44         OpenSubdiv_TopologyRefinerDescr *topology_refiner;
45 } OpenSubdiv_GLMesh;
46 #endif
47
48 // Keep this a bitmask os it's possible to pass available
49 // evaluators to Blender.
50 enum {
51         OPENSUBDIV_EVALUATOR_CPU                      = (1 << 0),
52         OPENSUBDIV_EVALUATOR_OPENMP                   = (1 << 1),
53         OPENSUBDIV_EVALUATOR_OPENCL                   = (1 << 2),
54         OPENSUBDIV_EVALUATOR_CUDA                     = (1 << 3),
55         OPENSUBDIV_EVALUATOR_GLSL_TRANSFORM_FEEDBACK  = (1 << 4),
56         OPENSUBDIV_EVALUATOR_GLSL_COMPUTE             = (1 << 5),
57 };
58
59 enum {
60         OPENSUBDIV_SCHEME_CATMARK,
61         OPENSUBDIV_SCHEME_BILINEAR,
62         OPENSUBDIV_SCHEME_LOOP,
63 };
64
65 /* TODO(sergey): Re-name and avoid bad level data access. */
66 OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromTopologyRefiner(
67         struct OpenSubdiv_TopologyRefinerDescr *topology_refiner,
68         int evaluator_type,
69         int level,
70         int subdivide_uvs);
71
72 void openSubdiv_deleteOsdGLMesh(OpenSubdiv_GLMesh *gl_mesh);
73 unsigned int openSubdiv_getOsdGLMeshPatchIndexBuffer(
74         OpenSubdiv_GLMesh *gl_mesh);
75 unsigned int openSubdiv_getOsdGLMeshVertexBuffer(OpenSubdiv_GLMesh *gl_mesh);
76 void openSubdiv_osdGLMeshUpdateVertexBuffer(OpenSubdiv_GLMesh *gl_mesh,
77                                             const float *vertex_data,
78                                             int start_vertex,
79                                             int num_verts);
80 void openSubdiv_osdGLMeshRefine(OpenSubdiv_GLMesh *gl_mesh);
81 void openSubdiv_osdGLMeshSynchronize(OpenSubdiv_GLMesh *gl_mesh);
82 void openSubdiv_osdGLMeshBindVertexBuffer(OpenSubdiv_GLMesh *gl_mesh);
83
84 const struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_getGLMeshTopologyRefiner(
85         OpenSubdiv_GLMesh *gl_mesh);
86
87 /* ** Initialize/Deinitialize global OpenGL drawing buffers/GLSL programs ** */
88 bool openSubdiv_osdGLDisplayInit(void);
89 void openSubdiv_osdGLDisplayDeinit(void);
90
91 /* ** Evaluator API ** */
92
93 struct OpenSubdiv_EvaluatorDescr;
94 typedef struct OpenSubdiv_EvaluatorDescr OpenSubdiv_EvaluatorDescr;
95
96 /* TODO(sergey): Avoid bad-level data access, */
97 OpenSubdiv_EvaluatorDescr *openSubdiv_createEvaluatorDescr(
98         struct OpenSubdiv_TopologyRefinerDescr *topology_refiner,
99         int subsurf_level);
100
101 void openSubdiv_deleteEvaluatorDescr(OpenSubdiv_EvaluatorDescr *evaluator_descr);
102
103 void openSubdiv_setEvaluatorCoarsePositions(OpenSubdiv_EvaluatorDescr *evaluator_descr,
104                                             float *positions,
105                                             int start_vert,
106                                             int num_vert);
107
108 void openSubdiv_setEvaluatorVaryingData(OpenSubdiv_EvaluatorDescr *evaluator_descr,
109                                         float *varying_data,
110                                         int start_vert,
111                                         int num_vert);
112
113 void openSubdiv_evaluateLimit(OpenSubdiv_EvaluatorDescr *evaluator_descr,
114                               int osd_face_index,
115                               float face_u, float face_v,
116                               float P[3],
117                               float dPdu[3],
118                               float dPdv[3]);
119
120 void openSubdiv_evaluateVarying(OpenSubdiv_EvaluatorDescr *evaluator_descr,
121                                int osd_face_index,
122                                float face_u, float face_v,
123                                float varying[3]);
124
125 /* ** Actual drawing ** */
126
127 /* Initialize all the invariants which stays the same for every single path,
128  * for example lighting model stays untouched for the whole mesh.
129  *
130  * TODO(sergey): Some of the stuff could be initialized once for all meshes.
131  */
132 void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl,
133                                         int active_uv_index);
134
135 /* Draw specified patches. */
136 void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh,
137                                  int fill_quads,
138                                  int start_patch,
139                                  int num_patches);
140
141 /* ** Utility functions ** */
142 int openSubdiv_supportGPUDisplay(void);
143 int openSubdiv_getAvailableEvaluators(void);
144 void openSubdiv_init(bool gpu_legacy_support);
145 void openSubdiv_cleanup(void);
146 bool openSubdiv_gpu_legacy_support(void);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif  // __OPENSUBDIV_CAPI_H__