All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
meshSamplers.h
1 //
2 // Copyright 2017 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 #ifndef HDEMBREE_MESH_SAMPLERS_H
25 #define HDEMBREE_MESH_SAMPLERS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdEmbree/sampler.h"
29 #include "pxr/imaging/hd/meshUtil.h"
30 #include "pxr/base/vt/types.h"
31 
32 #include <embree2/rtcore.h>
33 #include <embree2/rtcore_geometry.h>
34 
35 #include <bitset>
36 
37 // Old versions of embree didn't define this, and had 2 hardcoded user buffers.
38 #ifndef RTC_MAX_USER_VERTEX_BUFFERS
39 #define RTC_MAX_USER_VERTEX_BUFFERS 2
40 #endif
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
49 {
50 public:
53  : _bitset(0) {}
54 
58  RTCBufferType Allocate();
59 
62  void Free(RTCBufferType buffer);
63 private:
64  std::bitset<RTC_MAX_USER_VERTEX_BUFFERS> _bitset;
65 };
66 
67 // ----------------------------------------------------------------------
68 // The classes below implement the HdEmbreePrimvarSampler interface for
69 // the different interpolation modes that hydra supports. In some cases,
70 // implementations are broken out by geometry type (e.g. triangles vs
71 // subdiv).
72 
79 public:
84  VtValue const& value)
85  : _buffer(name, value)
86  , _sampler(_buffer) {}
87 
97  virtual bool Sample(unsigned int element, float u, float v, void* value,
98  HdTupleType dataType) const;
99 
100 private:
101  HdVtBufferSource const _buffer;
102  HdEmbreeBufferSampler const _sampler;
103 };
104 
115 public:
122  VtValue const& value,
123  VtIntArray const& primitiveParams)
124  : _buffer(name, value)
125  , _sampler(_buffer)
126  , _primitiveParams(primitiveParams) {}
127 
132  VtValue const& value)
133  : _buffer(name, value)
134  , _sampler(_buffer) {}
135 
147  virtual bool Sample(unsigned int element, float u, float v, void* value,
148  HdTupleType dataType) const;
149 
150 private:
151  HdVtBufferSource const _buffer;
152  HdEmbreeBufferSampler const _sampler;
153  VtIntArray const _primitiveParams;
154 };
155 
165 public:
172  VtValue const& value,
173  VtVec3iArray const& indices)
174  : _buffer(name, value)
175  , _sampler(_buffer)
176  , _indices(indices) {}
177 
190  virtual bool Sample(unsigned int element, float u, float v, void* value,
191  HdTupleType dataType) const;
192 
193 private:
194  HdVtBufferSource const _buffer;
195  HdEmbreeBufferSampler const _sampler;
196  VtVec3iArray const _indices;
197 };
198 
216 public:
223  VtValue const& value,
224  HdMeshUtil &meshUtil)
225  : _buffer(name, _Triangulate(name, value, meshUtil))
226  , _sampler(_buffer) {}
227 
241  virtual bool Sample(unsigned int element, float u, float v, void* value,
242  HdTupleType dataType) const;
243 
244 private:
245  HdVtBufferSource const _buffer;
246  HdEmbreeBufferSampler const _sampler;
247 
248  // Pass the "value" parameter through HdMeshUtils'
249  // ComputeTriangulatedFaceVaryingPrimvar(), which adjusts the primvar
250  // buffer data for the triangulated topology. HdMeshUtil is provided
251  // the source topology at construction time, so this class doesn't need
252  // to provide it.
253  static VtValue _Triangulate(TfToken const& name, VtValue const& value,
254  HdMeshUtil &meshUtil);
255 };
256 
265 public:
277  VtValue const& value,
278  RTCScene meshScene,
279  unsigned meshId,
280  HdEmbreeRTCBufferAllocator *allocator);
281 
284 
295  virtual bool Sample(unsigned int element, float u, float v, void* value,
296  HdTupleType dataType) const;
297 
298 private:
299  RTCBufferType _embreeBufferId;
300  HdVtBufferSource const _buffer;
301  RTCScene _meshScene;
302  unsigned _meshId;
303  HdEmbreeRTCBufferAllocator *_allocator;
304 };
305 
306 PXR_NAMESPACE_CLOSE_SCOPE
307 
308 #endif // HDEMBREE_MESH_SAMPLERS_H
void Free(RTCBufferType buffer)
Free a buffer by clearing its bit.
RTCBufferType Allocate()
Allocate a buffer by finding the first clear bit, using that as the buffer number, and setting the bit to mark it as used.
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value, VtIntArray const &primitiveParams)
Constructor.
Definition: meshSamplers.h:121
HdEmbreeTriangleFaceVaryingSampler(TfToken const &name, VtValue const &value, HdMeshUtil &meshUtil)
Constructor.
Definition: meshSamplers.h:222
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:239
An abstract base class that knows how to sample a primvar signal given a ray hit coordinate: an &lt;elem...
Definition: sampler.h:137
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
HdEmbreeRTCBufferAllocator()
Constructor. By default, set everything to unallocated.
Definition: meshSamplers.h:52
HdEmbreeTriangleVertexSampler(TfToken const &name, VtValue const &value, VtVec3iArray const &indices)
Constructor.
Definition: meshSamplers.h:171
This class implements the HdEmbreePrimvarSampler interface for primvars with &quot;uniform&quot; interpolation ...
Definition: meshSamplers.h:114
HdEmbreeSubdivVertexSampler(TfToken const &name, VtValue const &value, RTCScene meshScene, unsigned meshId, HdEmbreeRTCBufferAllocator *allocator)
Constructor.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Utility class to track which embree user vertex buffers are currently in use.
Definition: meshSamplers.h:48
HdEmbreeConstantSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:83
virtual ~HdEmbreeSubdivVertexSampler()
Destructor. Frees the embree user vertex buffer.
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with &quot;vert...
Definition: meshSamplers.h:164
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with &quot;face...
Definition: meshSamplers.h:215
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
This class implements the HdEmbreePrimvarSampler interface for primvars on subdiv meshes with &quot;vertex...
Definition: meshSamplers.h:264
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:97
This class implements the HdEmbreePrimvarSampler interface for primvars with &quot;constant&quot; interpolation...
Definition: meshSamplers.h:78
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:131
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
A collection of utility algorithms for generating triangulation and quadrangulation of an input topol...
Definition: meshUtil.h:82
An implementation of HdBufferSource where the source data value is a VtValue.