Blender  V3.3
evaluator_impl.h
Go to the documentation of this file.
1 // Copyright 2018 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 //
17 // Author: Sergey Sharybin
18 
19 #ifndef OPENSUBDIV_EVALUATOR_IMPL_H_
20 #define OPENSUBDIV_EVALUATOR_IMPL_H_
21 
22 #ifdef _MSC_VER
23 # include <iso646.h>
24 #endif
25 
26 #include <opensubdiv/far/patchMap.h>
27 #include <opensubdiv/far/patchTable.h>
28 
29 #include "internal/base/memory.h"
30 
31 #include "opensubdiv_capi_type.h"
32 
33 struct OpenSubdiv_Buffer;
38 
39 namespace blender {
40 namespace opensubdiv {
41 
42 class PatchMap;
43 
44 // Wrapper around implementation, which defines API which we are capable to
45 // provide over the implementation.
46 //
47 // TODO(sergey): It is almost the same as C-API object, so ideally need to
48 // merge them somehow, but how to do this and keep files with all the templates
49 // and such separate?
51  public:
52  // Anonymous forward declaration of actual evaluator implementation.
53  class EvalOutput;
54 
55  // NOTE: PatchMap is not owned, only referenced.
56  EvalOutputAPI(EvalOutput *implementation, PatchMap *patch_map);
57 
59 
60  // Set settings for data buffers.
61  void setSettings(const OpenSubdiv_EvaluatorSettings *settings);
62 
63  // Set coarse positions from a continuous array of coordinates.
64  void setCoarsePositions(const float *positions,
65  const int start_vertex_index,
66  const int num_vertices);
67  // Set vertex data from a continuous array of data.
68  void setVertexData(const float *data, const int start_vertex_index, const int num_vertices);
69  // Set varying data from a continuous array of data.
70  void setVaryingData(const float *varying_data,
71  const int start_vertex_index,
72  const int num_vertices);
73  // Set face varying data from a continuous array of data.
74  //
75  // TODO(sergey): Find a better name for vertex here. It is not the vertex of
76  // geometry, but a vertex of UV map.
77  void setFaceVaryingData(const int face_varying_channel,
78  const float *varying_data,
79  const int start_vertex_index,
80  const int num_vertices);
81 
82  // Set coarse vertex position from a continuous memory buffer where
83  // first coordinate starts at offset of `start_offset` and there is `stride`
84  // bytes between adjacent vertex coordinates.
85  void setCoarsePositionsFromBuffer(const void *buffer,
86  const int start_offset,
87  const int stride,
88  const int start_vertex_index,
89  const int num_vertices);
90  // Set varying data from a continuous memory buffer where
91  // first coordinate starts at offset of `start_offset` and there is `stride`
92  // bytes between adjacent vertex coordinates.
93  void setVaryingDataFromBuffer(const void *buffer,
94  const int start_offset,
95  const int stride,
96  const int start_vertex_index,
97  const int num_vertices);
98  // Set face varying data from a continuous memory buffer where
99  // first coordinate starts at offset of `start_offset` and there is `stride`
100  // bytes between adjacent vertex coordinates.
101  //
102  // TODO(sergey): Find a better name for vertex here. It is not the vertex of
103  // geometry, but a vertex of UV map.
104  void setFaceVaryingDataFromBuffer(const int face_varying_channel,
105  const void *buffer,
106  const int start_offset,
107  const int stride,
108  const int start_vertex_index,
109  const int num_vertices);
110 
111  // Refine after coarse positions update.
112  void refine();
113 
114  // Evaluate given ptex face at given bilinear coordinate.
115  // If derivatives are NULL, they will not be evaluated.
116  void evaluateLimit(const int ptex_face_index,
117  float face_u,
118  float face_v,
119  float P[3],
120  float dPdu[3],
121  float dPdv[3]);
122 
123  // Evaluate varying data at a given bilinear coordinate of given ptex face.
124  void evaluateVertexData(const int ptes_face_index, float face_u, float face_v, float data[]);
125 
126  // Evaluate varying data at a given bilinear coordinate of given ptex face.
127  void evaluateVarying(const int ptes_face_index, float face_u, float face_v, float varying[3]);
128 
129  // Evaluate facee-varying data at a given bilinear coordinate of given
130  // ptex face.
131  void evaluateFaceVarying(const int face_varying_channel,
132  const int ptes_face_index,
133  float face_u,
134  float face_v,
135  float face_varying[2]);
136 
137  // Batched evaluation of multiple input coordinates.
138 
139  // Evaluate given ptex face at given bilinear coordinate.
140  // If derivatives are NULL, they will not be evaluated.
141  //
142  // NOTE: Output arrays must point to a memory of size float[3]*num_patch_coords.
143  void evaluatePatchesLimit(const OpenSubdiv_PatchCoord *patch_coords,
144  const int num_patch_coords,
145  float *P,
146  float *dPdu,
147  float *dPdv);
148 
149  // Fill the output buffers and variables with data from the PatchMap.
150  void getPatchMap(OpenSubdiv_Buffer *patch_map_handles,
151  OpenSubdiv_Buffer *patch_map_quadtree,
152  int *min_patch_face,
153  int *max_patch_face,
154  int *max_depth,
155  int *patches_are_triangular);
156 
157  // Copy the patch arrays buffer used by OpenSubDiv for the source data to the given buffer.
158  void fillPatchArraysBuffer(OpenSubdiv_Buffer *patch_arrays_buffer);
159 
160  // Wrap the patch index buffer used by OpenSubDiv for the source data with the given buffer.
161  void wrapPatchIndexBuffer(OpenSubdiv_Buffer *patch_index_buffer);
162 
163  // Wrap the patch param buffer used by OpenSubDiv for the source data with the given buffer.
164  void wrapPatchParamBuffer(OpenSubdiv_Buffer *patch_param_buffer);
165 
166  // Wrap the buffer used by OpenSubDiv for the source data with the given buffer.
167  void wrapSrcBuffer(OpenSubdiv_Buffer *src_buffer);
168 
169  // Wrap the buffer used by OpenSubDiv for the extra source data with the given buffer.
170  void wrapSrcVertexDataBuffer(OpenSubdiv_Buffer *src_buffer);
171 
172  // Copy the patch arrays buffer used by OpenSubDiv for the face varying channel with the given
173  // buffer.
174  void fillFVarPatchArraysBuffer(const int face_varying_channel,
175  OpenSubdiv_Buffer *patch_arrays_buffer);
176 
177  // Wrap the patch index buffer used by OpenSubDiv for the face varying channel with the given
178  // buffer.
179  void wrapFVarPatchIndexBuffer(const int face_varying_channel,
180  OpenSubdiv_Buffer *patch_index_buffer);
181 
182  // Wrap the patch param buffer used by OpenSubDiv for the face varying channel with the given
183  // buffer.
184  void wrapFVarPatchParamBuffer(const int face_varying_channel,
185  OpenSubdiv_Buffer *patch_param_buffer);
186 
187  // Wrap thebuffer used by OpenSubDiv for the face varying channel with the given buffer.
188  void wrapFVarSrcBuffer(const int face_varying_channel, OpenSubdiv_Buffer *src_buffer);
189 
190  // Return true if source vertex data has been set.
191  bool hasVertexData() const;
192 
193  protected:
196 };
197 
198 } // namespace opensubdiv
199 } // namespace blender
200 
202  public:
205 
208  const OpenSubdiv::Far::PatchTable *patch_table;
209 
210  MEM_CXX_CLASS_ALLOC_FUNCS("OpenSubdiv_EvaluatorImpl");
211 };
212 
214  struct OpenSubdiv_TopologyRefiner *topology_refiner,
215  eOpenSubdivEvaluator evaluator_type,
216  OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr);
217 
219 
220 #endif // OPENSUBDIV_EVALUATOR_IMPL_H_
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
void setVaryingData(const float *varying_data, const int start_vertex_index, const int num_vertices)
void wrapSrcBuffer(OpenSubdiv_Buffer *src_buffer)
void wrapFVarSrcBuffer(const int face_varying_channel, OpenSubdiv_Buffer *src_buffer)
void evaluatePatchesLimit(const OpenSubdiv_PatchCoord *patch_coords, const int num_patch_coords, float *P, float *dPdu, float *dPdv)
void wrapPatchIndexBuffer(OpenSubdiv_Buffer *patch_index_buffer)
void fillPatchArraysBuffer(OpenSubdiv_Buffer *patch_arrays_buffer)
void setSettings(const OpenSubdiv_EvaluatorSettings *settings)
void wrapPatchParamBuffer(OpenSubdiv_Buffer *patch_param_buffer)
void evaluateLimit(const int ptex_face_index, float face_u, float face_v, float P[3], float dPdu[3], float dPdv[3])
void evaluateFaceVarying(const int face_varying_channel, const int ptes_face_index, float face_u, float face_v, float face_varying[2])
void setFaceVaryingData(const int face_varying_channel, const float *varying_data, const int start_vertex_index, const int num_vertices)
void getPatchMap(OpenSubdiv_Buffer *patch_map_handles, OpenSubdiv_Buffer *patch_map_quadtree, int *min_patch_face, int *max_patch_face, int *max_depth, int *patches_are_triangular)
void wrapFVarPatchIndexBuffer(const int face_varying_channel, OpenSubdiv_Buffer *patch_index_buffer)
void fillFVarPatchArraysBuffer(const int face_varying_channel, OpenSubdiv_Buffer *patch_arrays_buffer)
void wrapSrcVertexDataBuffer(OpenSubdiv_Buffer *src_buffer)
void evaluateVertexData(const int ptes_face_index, float face_u, float face_v, float data[])
void setCoarsePositionsFromBuffer(const void *buffer, const int start_offset, const int stride, const int start_vertex_index, const int num_vertices)
void wrapFVarPatchParamBuffer(const int face_varying_channel, OpenSubdiv_Buffer *patch_param_buffer)
void setVaryingDataFromBuffer(const void *buffer, const int start_offset, const int stride, const int start_vertex_index, const int num_vertices)
EvalOutputAPI(EvalOutput *implementation, PatchMap *patch_map)
void evaluateVarying(const int ptes_face_index, float face_u, float face_v, float varying[3])
void setFaceVaryingDataFromBuffer(const int face_varying_channel, const void *buffer, const int start_offset, const int stride, const int start_vertex_index, const int num_vertices)
void setVertexData(const float *data, const int start_vertex_index, const int num_vertices)
void setCoarsePositions(const float *positions, const int start_vertex_index, const int num_vertices)
An quadtree-based map connecting coarse faces to their sub-patches.
Definition: patch_map.h:43
void openSubdiv_deleteEvaluatorInternal(OpenSubdiv_EvaluatorImpl *evaluator)
OpenSubdiv_EvaluatorImpl * openSubdiv_createEvaluatorInternal(struct OpenSubdiv_TopologyRefiner *topology_refiner, eOpenSubdivEvaluator evaluator_type, OpenSubdiv_EvaluatorCacheImpl *evaluator_cache_descr)
ccl_global float * buffer
static float P(float k)
Definition: math_interp.c:25
MutableSpan< float3 > positions
eOpenSubdivEvaluator
const blender::opensubdiv::PatchMap * patch_map
blender::opensubdiv::EvalOutputAPI * eval_output
const OpenSubdiv::Far::PatchTable * patch_table
MEM_CXX_CLASS_ALLOC_FUNCS("OpenSubdiv_EvaluatorImpl")