All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cpuSmoothNormalContext.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_SMOOTHNORMAL_CONTEXT_H
26 #define OSD_CPU_SMOOTHNORMAL_CONTEXT_H
27 
28 #include "../version.h"
29 
30 #include "../osd/nonCopyable.h"
31 #include "../osd/vertexDescriptor.h"
32 #include "../osd/vertex.h"
33 
34 #include "../far/patchTables.h"
35 
36 namespace OpenSubdiv {
37 namespace OPENSUBDIV_VERSION {
38 
39 namespace Osd {
40 
41 class CpuSmoothNormalContext : private NonCopyable<CpuSmoothNormalContext> {
42 
43 public:
44 
56  Far::PatchTables const *patchTables, bool resetMemory=false);
57 
70  template<class VERTEX_BUFFER>
71  void Bind(VERTEX_BUFFER * in, int iOfs,
72  VERTEX_BUFFER * out, int oOfs) {
73 
74  assert( ((iOfs+3)<=in->GetNumElements()) and
75  ((oOfs+3)<=out->GetNumElements()) and
76  out->GetNumVertices()>=in->GetNumVertices());
77 
78  _iBuffer = in ? in->BindCpuBuffer() : 0;
79  _oBuffer = out ? out->BindCpuBuffer() : 0;
80 
81  _iDesc = VertexBufferDescriptor( iOfs, 3, in->GetNumElements() );
82  _oDesc = VertexBufferDescriptor( oOfs, 3, out->GetNumElements() );
83 
84  _numVertices = out->GetNumVertices();
85  }
86 
88  void Unbind() {
89 
90  _iBuffer = _oBuffer = 0;
91  _iDesc.Reset();
92  _oDesc.Reset();
93  _numVertices = 0;
94  }
95 
98  return _patchArrays;
99  }
100 
102  const std::vector<unsigned int> & GetControlVertices() const {
103  return _patches;
104  }
105 
107  float const * GetCurrentInputVertexBuffer() const {
108  return _iBuffer;
109  }
110 
113  return _oBuffer;
114  }
115 
118  return _iDesc;
119  }
120 
124  return _oDesc;
125  }
126 
128  int GetNumVertices() const {
129  return _numVertices;
130  }
131 
134  bool GetResetMemory() const {
135  return _resetMemory;
136  }
137 
140  void SetResetMemory(bool resetMemory) {
141  _resetMemory = resetMemory;
142  }
143 
144 protected:
145  // Constructor
146  explicit CpuSmoothNormalContext(
147  Far::PatchTables const *patchTables, bool resetMemory);
148 
149 private:
150 
151  // Topology data for a mesh
152  Far::PatchTables::PatchArrayVector _patchArrays; // patch descriptor for each patch in the mesh
153  Far::PatchTables::PTable _patches; // patch control vertices
154 
155  VertexBufferDescriptor _iDesc,
156  _oDesc;
157 
158  int _numVertices;
159 
160  float * _iBuffer,
161  * _oBuffer;
162 
163  bool _resetMemory; // set to true if the output buffer needs to be reset to 0
164 };
165 
166 
167 } // end namespace Osd
168 
169 } // end namespace OPENSUBDIV_VERSION
170 using namespace OPENSUBDIV_VERSION;
171 
172 } // end namespace OpenSubdiv
173 
174 #endif // OSD_CPU_SMOOTHNORMAL_CONTEXT_H
175 
static CpuSmoothNormalContext * Create(Far::PatchTables const *patchTables, bool resetMemory=false)
void Unbind()
Unbinds any previously bound vertex and varying data buffers.
CpuSmoothNormalContext(Far::PatchTables const *patchTables, bool resetMemory)
Container for patch vertex indices tables.
Definition: patchTables.h:49
const std::vector< unsigned int > & GetControlVertices() const
The ordered array of control vertex indices for all the patches.
int GetNumVertices() const
Returns the number of vertices in output vertex buffer.
Describes vertex elements in interleaved data buffers.
void Reset()
Resets the descriptor to default.
float const * GetCurrentInputVertexBuffer() const
Returns a pointer to the data of the input buffer.
const Far::PatchTables::PatchArrayVector & GetPatchArrayVector() const
Returns the vector of patch arrays.
VertexBufferDescriptor const & GetInputVertexDescriptor() const
Returns an VertexDescriptor for the input vertex data.
float * GetCurrentOutputVertexBuffer()
Returns a pointer to the data of the output buffer.
void Bind(VERTEX_BUFFER *in, int iOfs, VERTEX_BUFFER *out, int oOfs)
VertexBufferDescriptor const & GetOutputVertexDescriptor() const