All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cpuEvalLimitController.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef OSD_CPU_EVAL_LIMIT_CONTROLLER_H
26 #define OSD_CPU_EVAL_LIMIT_CONTROLLER_H
27 
28 #include "../version.h"
29 
30 #include "../osd/cpuEvalLimitContext.h"
31 #include "../osd/vertexDescriptor.h"
32 
33 namespace OpenSubdiv {
34 namespace OPENSUBDIV_VERSION {
35 
36 namespace Osd {
37 
61 
62 public:
65 
68 
83  template<class INPUT_BUFFER, class OUTPUT_BUFFER>
84  void BindVertexBuffers( VertexBufferDescriptor const & iDesc, INPUT_BUFFER *inQ,
85  VertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ,
86  OUTPUT_BUFFER *outdQu=0,
87  OUTPUT_BUFFER *outdQv=0 ) {
88  _currentBindState.vertexData.inDesc = iDesc;
89  _currentBindState.vertexData.in = inQ ? inQ->BindCpuBuffer() : 0;
90 
91  _currentBindState.vertexData.outDesc = oDesc;
92  _currentBindState.vertexData.out = outQ ? outQ->BindCpuBuffer() : 0;
93  _currentBindState.vertexData.outDu = outdQu ? outdQu->BindCpuBuffer() : 0;
94  _currentBindState.vertexData.outDv = outdQv ? outdQv->BindCpuBuffer() : 0;
95  }
96 
107  template<class INPUT_BUFFER, class OUTPUT_BUFFER>
108  void BindVaryingBuffers( VertexBufferDescriptor const & iDesc, INPUT_BUFFER *inQ,
109  VertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ ) {
110  _currentBindState.varyingData.inDesc = iDesc;
111  _currentBindState.varyingData.in = inQ ? inQ->BindCpuBuffer() : 0;
112 
113  _currentBindState.varyingData.outDesc = oDesc;
114  _currentBindState.varyingData.out = outQ ? outQ->BindCpuBuffer() : 0;
115  }
116 
130  template<class OUTPUT_BUFFER>
132  VertexBufferDescriptor const & oDesc, OUTPUT_BUFFER *outQ ) {
133  _currentBindState.facevaryingData.inDesc = iDesc;
134 
135  _currentBindState.facevaryingData.outDesc = oDesc;
136  _currentBindState.facevaryingData.out = outQ ? outQ->BindCpuBuffer() : 0;
137  }
138 
161  int EvalLimitSample( EvalCoords const & coord,
162  CpuEvalLimitContext * context,
163  VertexBufferDescriptor const & outDesc,
164  float * outQ,
165  float * outDQU,
166  float * outDQV ) const;
167 
182  int EvalLimitSample( EvalCoords const & coords,
183  CpuEvalLimitContext * context,
184  unsigned int index ) const {
185  if (not context)
186  return 0;
187 
188  int n = _EvalLimitSample( coords, context, index );
189 
190  return n;
191  }
192 
193  void Unbind() {
194  _currentBindState.Reset();
195  }
196 
197 protected:
198 
199 
200  // Vertex interpolated streams
201  struct VertexData {
202 
203  VertexData() : in(0), out(0), outDu(0), outDv(0) { }
204 
205 
206  void Reset() {
207  in = out = outDu = outDv = NULL;
208  inDesc.Reset();
209  outDesc.Reset();
210  }
211 
213  outDesc;
214  float * in,
215  * out,
216  * outDu,
217  * outDv;
218  };
219 
220  // Varying interpolated streams
221  struct VaryingData {
222 
223  VaryingData() : in(0), out(0) { }
224 
225 
226  void Reset() {
227  in = out = NULL;
228  inDesc.Reset();
229  outDesc.Reset();
230  }
231 
233  outDesc;
234  float * in,
235  * out;
236  };
237 
238  // Facevarying interpolated streams
240 
241  FacevaryingData() : out(0) { }
242 
243  void Reset() {
244  out = NULL;
245  inDesc.Reset();
246  outDesc.Reset();
247  }
248 
250  outDesc;
251  float * out;
252  };
253 
254 
255 private:
256 
257  int _EvalLimitSample( EvalCoords const & coords,
258  CpuEvalLimitContext * context,
259  unsigned int index ) const;
260 
261  // Bind state is a transitional state during refinement.
262  // It doesn't take an ownership of vertex buffers.
263  struct BindState {
264 
265  BindState() { }
266 
267  void Reset() {
268  vertexData.Reset();
269  varyingData.Reset();
270  facevaryingData.Reset();
271  }
272 
273  VertexData vertexData; // vertex interpolated data descriptor
274  VaryingData varyingData; // varying interpolated data descriptor
275  FacevaryingData facevaryingData; // face-varying interpolated data descriptor
276  };
277 
278  BindState _currentBindState;
279 };
280 
281 } // end namespace Osd
282 
283 } // end namespace OPENSUBDIV_VERSION
284 using namespace OPENSUBDIV_VERSION;
285 
286 } // end namespace OpenSubdiv
287 
288 #endif /* OSD_CPU_EVAL_LIMIT_CONTROLLER_H */
289 
void BindVaryingBuffers(VertexBufferDescriptor const &iDesc, INPUT_BUFFER *inQ, VertexBufferDescriptor const &oDesc, OUTPUT_BUFFER *outQ)
Binds the varying-interpolated data streams.
int EvalLimitSample(EvalCoords const &coords, CpuEvalLimitContext *context, unsigned int index) const
Vertex interpolation of samples at the limit.
Describes vertex elements in interleaved data buffers.
void Reset()
Resets the descriptor to default.
Coordinates set on a limit surface.
void BindFacevaryingBuffers(VertexBufferDescriptor const &iDesc, VertexBufferDescriptor const &oDesc, OUTPUT_BUFFER *outQ)
Binds the face-varying-interpolated data streams.
int EvalLimitSample(EvalCoords const &coord, CpuEvalLimitContext *context, VertexBufferDescriptor const &outDesc, float *outQ, float *outDQU, float *outDQV) const
Vertex interpolation of a single sample at the limit.
void BindVertexBuffers(VertexBufferDescriptor const &iDesc, INPUT_BUFFER *inQ, VertexBufferDescriptor const &oDesc, OUTPUT_BUFFER *outQ, OUTPUT_BUFFER *outdQu=0, OUTPUT_BUFFER *outdQv=0)
Binds control vertex data buffer.