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