Blender V5.0
opensubdiv_evaluator.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 *
5 * Author: Sergey Sharybin. */
6
7#ifndef OPENSUBDIV_EVALUATOR_IMPL_H_
8#define OPENSUBDIV_EVALUATOR_IMPL_H_
9
10#ifdef _MSC_VER
11# include <iso646.h>
12#endif
13
14#include <opensubdiv/far/patchMap.h>
15#include <opensubdiv/far/patchTable.h>
16
18
19#include "GPU_storage_buffer.hh"
20
24namespace blender::gpu {
25class VertBuf;
26}
27namespace blender::opensubdiv {
28
30class PatchMap;
31
32// Wrapper around implementation, which defines API which we are capable to
33// provide over the implementation.
35 public:
36 // Anonymous forward declaration of actual evaluator implementation.
37 class EvalOutput;
38
39 // NOTE: PatchMap is not owned, only referenced.
40 EvalOutputAPI(EvalOutput *implementation, PatchMap *patch_map);
41
43
44 // Set settings for data buffers.
45 void setSettings(const OpenSubdiv_EvaluatorSettings *settings);
46
47 // Set coarse positions from a continuous array of coordinates.
48 void setCoarsePositions(const float *positions,
49 const int start_vertex_index,
50 const int num_vertices);
51 // Set vertex data from a continuous array of data.
52 void setVertexData(const float *data, const int start_vertex_index, const int num_vertices);
53 // Set varying data from a continuous array of data.
54 void setVaryingData(const float *varying_data,
55 const int start_vertex_index,
56 const int num_vertices);
57 // Set face varying data from a continuous array of data.
58 //
59 // TODO(sergey): Find a better name for vertex here. It is not the vertex of
60 // geometry, but a vertex of UV map.
61 void setFaceVaryingData(const int face_varying_channel,
62 const float *varying_data,
63 const int start_vertex_index,
64 const int num_vertices);
65
66 // Set coarse vertex position from a continuous memory buffer where
67 // first coordinate starts at offset of `start_offset` and there is `stride`
68 // bytes between adjacent vertex coordinates.
69 void setCoarsePositionsFromBuffer(const void *buffer,
70 const int start_offset,
71 const int stride,
72 const int start_vertex_index,
73 const int num_vertices);
74 // Set varying data from a continuous memory buffer where
75 // first coordinate starts at offset of `start_offset` and there is `stride`
76 // bytes between adjacent vertex coordinates.
77 void setVaryingDataFromBuffer(const void *buffer,
78 const int start_offset,
79 const int stride,
80 const int start_vertex_index,
81 const int num_vertices);
82 // Set face varying data 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 //
86 // TODO(sergey): Find a better name for vertex here. It is not the vertex of
87 // geometry, but a vertex of UV map.
88 void setFaceVaryingDataFromBuffer(const int face_varying_channel,
89 const void *buffer,
90 const int start_offset,
91 const int stride,
92 const int start_vertex_index,
93 const int num_vertices);
94
95 // Refine after coarse positions update.
96 void refine();
97
98 // Evaluate given ptex face at given bilinear coordinate.
99 // If derivatives are NULL, they will not be evaluated.
100 void evaluateLimit(const int ptex_face_index,
101 float face_u,
102 float face_v,
103 float P[3],
104 float dPdu[3],
105 float dPdv[3]);
106
107 // Evaluate varying data at a given bilinear coordinate of given ptex face.
108 void evaluateVertexData(const int ptex_face_index, float face_u, float face_v, float data[]);
109
110 // Evaluate varying data at a given bilinear coordinate of given ptex face.
111 void evaluateVarying(const int ptex_face_index, float face_u, float face_v, float varying[3]);
112
113 // Evaluate facee-varying data at a given bilinear coordinate of given
114 // ptex face.
115 void evaluateFaceVarying(const int face_varying_channel,
116 const int ptex_face_index,
117 float face_u,
118 float face_v,
119 float face_varying[2]);
120
121 // Batched evaluation of multiple input coordinates.
122
123 // Evaluate given ptex face at given bilinear coordinate.
124 // If derivatives are NULL, they will not be evaluated.
125 //
126 // NOTE: Output arrays must point to a memory of size float[3]*num_patch_coords.
127 void evaluatePatchesLimit(const OpenSubdiv_PatchCoord *patch_coords,
128 const int num_patch_coords,
129 float *P,
130 float *dPdu,
131 float *dPdv);
132
133 // Fill the output buffers and variables with data from the PatchMap.
134 void getPatchMap(blender::gpu::VertBuf *patch_map_handles,
135 blender::gpu::VertBuf *patch_map_quadtree,
136 int *min_patch_face,
137 int *max_patch_face,
138 int *max_depth,
139 int *patches_are_triangular);
140
141 // Copy the patch arrays buffer used by OpenSubDiv for the source data to the given buffer.
143
144 // Wrap the patch index buffer used by OpenSubDiv for the source data with the given buffer.
146
147 // Wrap the patch param buffer used by OpenSubDiv for the source data with the given buffer.
149
150 // Wrap the buffer used by OpenSubDiv for the source data with the given buffer.
152
153 // Wrap the buffer used by OpenSubDiv for the extra source data with the given buffer.
155
156 // Copy the patch arrays buffer used by OpenSubDiv for the face varying channel with the given
157 // buffer.
158 gpu::StorageBuf *create_face_varying_patch_array_buf(const int face_varying_channel);
159
160 // Wrap the patch index buffer used by OpenSubDiv for the face varying channel with the given
161 // buffer.
162 gpu::StorageBuf *get_face_varying_patch_index_buf(const int face_varying_channel);
163
164 // Wrap the patch param buffer used by OpenSubDiv for the face varying channel with the given
165 // buffer.
166 gpu::StorageBuf *get_face_varying_patch_param_buf(const int face_varying_channel);
167
168 // Wrap thebuffer used by OpenSubDiv for the face varying channel with the given buffer.
169 gpu::VertBuf *get_face_varying_source_buf(const int face_varying_channel);
171 int get_face_varying_source_offset(const int face_varying_channel) const;
172
173 // Return true if source vertex data has been set.
174 bool hasVertexData() const;
175
176 protected:
179};
180
181} // namespace blender::opensubdiv
182
193
196 eOpenSubdivEvaluator evaluator_type,
197 OpenSubdiv_EvaluatorCache *evaluator_cache_descr);
198
199#endif // OPENSUBDIV_EVALUATOR_IMPL_H_
BMesh const char void * data
gpu::VertBuf * get_face_varying_source_buf(const int face_varying_channel)
gpu::StorageBuf * get_face_varying_patch_index_buf(const int face_varying_channel)
void setVaryingData(const float *varying_data, const int start_vertex_index, const int num_vertices)
void evaluatePatchesLimit(const OpenSubdiv_PatchCoord *patch_coords, const int num_patch_coords, float *P, float *dPdu, float *dPdv)
gpu::StorageBuf * create_patch_arrays_buf()
void setSettings(const OpenSubdiv_EvaluatorSettings *settings)
void evaluateVarying(const int ptex_face_index, float face_u, float face_v, float varying[3])
void evaluateLimit(const int ptex_face_index, float face_u, float face_v, float P[3], float dPdu[3], float dPdv[3])
void setFaceVaryingData(const int face_varying_channel, const float *varying_data, const int start_vertex_index, const int num_vertices)
gpu::StorageBuf * create_face_varying_patch_array_buf(const int face_varying_channel)
void evaluateVertexData(const int ptex_face_index, float face_u, float face_v, float data[])
void evaluateFaceVarying(const int face_varying_channel, const int ptex_face_index, float face_u, float face_v, float face_varying[2])
int get_face_varying_source_offset(const int face_varying_channel) const
void setCoarsePositionsFromBuffer(const void *buffer, const int start_offset, const int stride, const int start_vertex_index, const int num_vertices)
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)
gpu::StorageBuf * get_face_varying_patch_param_buf(const int face_varying_channel)
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 getPatchMap(blender::gpu::VertBuf *patch_map_handles, blender::gpu::VertBuf *patch_map_quadtree, int *min_patch_face, int *max_patch_face, int *max_depth, int *patches_are_triangular)
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:25
eOpenSubdivEvaluator
OpenSubdiv_Evaluator * openSubdiv_createEvaluatorFromTopologyRefiner(blender::opensubdiv::TopologyRefinerImpl *topology_refiner, eOpenSubdivEvaluator evaluator_type, OpenSubdiv_EvaluatorCache *evaluator_cache_descr)
const OpenSubdiv::Far::PatchTable * patch_table
blender::opensubdiv::EvalOutputAPI * eval_output
const blender::opensubdiv::PatchMap * patch_map
eOpenSubdivEvaluator type