Skip to content

Commit

Permalink
Fixing compilation issues with USD 21.02. (#656) (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpalee authored Feb 11, 2021
1 parent cfea903 commit 6d27319
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 5 deletions.
7 changes: 7 additions & 0 deletions render_delegate/basis_curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@ inline bool _RemapVertexPrimvar(

} // namespace

#if PXR_VERSION >= 2102
HdArnoldBasisCurves::HdArnoldBasisCurves(HdArnoldRenderDelegate* delegate, const SdfPath& id)
: HdArnoldRprim<HdBasisCurves>(str::curves, delegate, id), _interpolation(HdTokens->linear)
{
}
#else
HdArnoldBasisCurves::HdArnoldBasisCurves(
HdArnoldRenderDelegate* delegate, const SdfPath& id, const SdfPath& instancerId)
: HdArnoldRprim<HdBasisCurves>(str::curves, delegate, id, instancerId), _interpolation(HdTokens->linear)
{
}
#endif

void HdArnoldBasisCurves::Sync(
HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, const TfToken& reprToken)
Expand Down
14 changes: 14 additions & 0 deletions render_delegate/basis_curves.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ PXR_NAMESPACE_OPEN_SCOPE

class HdArnoldBasisCurves : public HdArnoldRprim<HdBasisCurves> {
public:
#if PXR_VERSION >= 2102
/// Constructor for HdArnoldBasisCurves.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the basis curves.
HDARNOLD_API
HdArnoldBasisCurves(HdArnoldRenderDelegate* delegate, const SdfPath& id);
#else
/// Constructor for HdArnoldBasisCurves.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the basis curves.
/// @param instancerId Path to the Point Instancer for this basis curves.
HDARNOLD_API
HdArnoldBasisCurves(HdArnoldRenderDelegate* delegate, const SdfPath& id, const SdfPath& instancerId = SdfPath());
#endif

/// Destructor for HdArnoldBasisCurves.
///
Expand Down
7 changes: 4 additions & 3 deletions render_delegate/hdarnold.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
#define USD_HAS_NEW_RENDERER_PLUGIN
#endif

#if USED_USD_VERSION_GREATER_EQ(19, 11)
// Integer comparable version exists since 1911.
#if PXR_VERSION >= 1911
/// Hydra has the new renderer plugin base class
#define USD_HAS_UPDATED_TIME_SAMPLE_ARRAY
/// Hydra has the updated render buffer class.
#define USD_HAS_UPDATED_RENDER_BUFFER
#endif

#if USED_USD_VERSION_GREATER_EQ(20, 2)
#if PXR_VERSION >= 2002
/// Depth range in Hydra was changed from -1 .. 1 to 0 .. 1.
#define USD_HAS_ZERO_TO_ONE_DEPTH
#endif

#if USED_USD_VERSION_GREATER_EQ(20, 5)
#if PXR_VERSION >= 2005
/// Not blitting to a hardware buffer anymore, following the example of HdEmbree.
#define USD_DO_NOT_BLIT
#endif
8 changes: 8 additions & 0 deletions render_delegate/instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ inline const VtArray<T>& _LookupInstancePrimvar(const HdArnoldPrimvarMap& primva

} // namespace

#if PXR_VERSION >= 2102
HdArnoldInstancer::HdArnoldInstancer(
HdArnoldRenderDelegate* renderDelegate, HdSceneDelegate* sceneDelegate, const SdfPath& id)
: HdInstancer(sceneDelegate, id)
{
}
#else
HdArnoldInstancer::HdArnoldInstancer(
HdArnoldRenderDelegate* renderDelegate, HdSceneDelegate* sceneDelegate, const SdfPath& id,
const SdfPath& parentInstancerId)
: HdInstancer(sceneDelegate, id, parentInstancerId)
{
}
#endif

void HdArnoldInstancer::_SyncPrimvars()
{
Expand Down
14 changes: 14 additions & 0 deletions render_delegate/instancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,28 @@ PXR_NAMESPACE_OPEN_SCOPE
/// Utility class for the point instancer.
class HdArnoldInstancer : public HdInstancer {
public:
#if PXR_VERSION >= 2102
/// Creates an instance of HdArnoldInstancer.
///
/// @param renderDelegate Pointer to the render delegate creating the
/// instancer.
/// @param sceneDelegate Pointer to Hydra Scene Delegate.
/// @param id Path to the instancer.
HDARNOLD_API
HdArnoldInstancer(HdArnoldRenderDelegate* renderDelegate, HdSceneDelegate* sceneDelegate, const SdfPath& id);
#else
/// Creates an instance of HdArnoldInstancer.
///
/// @param renderDelegate Pointer to the render delegate creating the
/// instancer.
/// @param sceneDelegate Pointer to Hydra Scene Delegate.
/// @param id Path to the instancer.
/// @param parentInstanceId Path to the parent Instancer.
HDARNOLD_API
HdArnoldInstancer(
HdArnoldRenderDelegate* renderDelegate, HdSceneDelegate* sceneDelegate, const SdfPath& id,
const SdfPath& parentInstancerId = SdfPath());
#endif

/// Destructor for HdArnoldInstancer.
~HdArnoldInstancer() override = default;
Expand Down
71 changes: 69 additions & 2 deletions render_delegate/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace {
// clang-format off
TF_DEFINE_PRIVATE_TOKENS(
_tokens,
#if PXR_VERSION < 2102
// Shaping parameters are not part of HdTokens in older USD versions
((shapingFocus, "shaping:focus"))
((shapingFocusTint, "shaping:focusTint"))
Expand All @@ -53,6 +54,8 @@ TF_DEFINE_PRIVATE_TOKENS(
((shapingIesFile, "shaping:ies:file"))
((shapingIesAngleScale, "shaping:ies:angleScale"))
((shapingIesNormalize, "shaping:ies:normalize"))
(treatAsPoint)
#endif
// Barndoor parameters for Houdini
(barndoorbottom)
(barndoorbottomedge)
Expand All @@ -63,7 +66,6 @@ TF_DEFINE_PRIVATE_TOKENS(
(barndoortop)
(barndoortopedge)
(filters)
(treatAsPoint)
((emptyLink, "__arnold_empty_link__"))
);
// clang-format on
Expand All @@ -74,6 +76,28 @@ struct ParamDesc {
TfToken hdName;
};

#if PXR_VERSION >= 2102
std::vector<ParamDesc> genericParams = {
{"intensity", UsdLuxTokens->inputsIntensity}, {"exposure", UsdLuxTokens->inputsExposure},
{"color", UsdLuxTokens->inputsColor}, {"diffuse", UsdLuxTokens->inputsDiffuse},
{"specular", UsdLuxTokens->inputsSpecular}, {"normalize", UsdLuxTokens->inputsNormalize},
{"cast_shadows", UsdLuxTokens->shadowEnable}, {"shadow_color", UsdLuxTokens->shadowColor},
};

std::vector<ParamDesc> pointParams = {{"radius", UsdLuxTokens->inputsRadius}};

std::vector<ParamDesc> spotParams = {
{"radius", UsdLuxTokens->inputsRadius}, {"cosine_power", UsdLuxTokens->shapingFocus}};

std::vector<ParamDesc> photometricParams = {
{"filename", UsdLuxTokens->shapingIesFile}, {"radius", UsdLuxTokens->inputsRadius}};

std::vector<ParamDesc> distantParams = {{"angle", UsdLuxTokens->inputsAngle}};

std::vector<ParamDesc> diskParams = {{"radius", UsdLuxTokens->inputsRadius}};

std::vector<ParamDesc> cylinderParams = {{"radius", UsdLuxTokens->inputsRadius}};
#else
std::vector<ParamDesc> genericParams = {
{"intensity", HdLightTokens->intensity},
{"exposure", HdLightTokens->exposure},
Expand All @@ -96,6 +120,7 @@ std::vector<ParamDesc> distantParams = {{"angle", HdLightTokens->angle}};
std::vector<ParamDesc> diskParams = {{"radius", HdLightTokens->radius}};

std::vector<ParamDesc> cylinderParams = {{"radius", HdLightTokens->radius}};
#endif

void iterateParams(
AtNode* light, const AtNodeEntry* nentry, const SdfPath& id, HdSceneDelegate* delegate,
Expand Down Expand Up @@ -130,7 +155,11 @@ AtString getLightType(HdSceneDelegate* delegate, const SdfPath& id)
return true;
};
auto hasIesFile = [&]() -> bool {
#if PXR_VERSION >= 2102
auto val = delegate->GetLightParamValue(id, UsdLuxTokens->shapingIesFile);
#else
auto val = delegate->GetLightParamValue(id, _tokens->shapingIesFile);
#endif
if (val.IsEmpty()) {
return false;
}
Expand All @@ -144,8 +173,13 @@ AtString getLightType(HdSceneDelegate* delegate, const SdfPath& id)
return false;
};
// If any of the shaping params exists or non-default we have a spot light.
#if PXR_VERSION >= 2102
if (!isDefault(UsdLuxTokens->shapingFocus, 0.0f) || !isDefault(UsdLuxTokens->shapingConeAngle, 180.0f) ||
!isDefault(UsdLuxTokens->shapingConeSoftness, 0.0f)) {
#else
if (!isDefault(_tokens->shapingFocus, 0.0f) || !isDefault(_tokens->shapingConeAngle, 180.0f) ||
!isDefault(_tokens->shapingConeSoftness, 0.0f)) {
#endif
return str::spot_light;
}
return hasIesFile() ? str::photometric_light : str::point_light;
Expand All @@ -154,9 +188,13 @@ AtString getLightType(HdSceneDelegate* delegate, const SdfPath& id)
auto spotLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* nentry, const SdfPath& id,
HdSceneDelegate* delegate) {
iterateParams(light, nentry, id, delegate, spotParams);

#if PXR_VERSION >= 2102
const auto hdAngle = delegate->GetLightParamValue(id, UsdLuxTokens->shapingConeAngle).GetWithDefault(180.0f);
const auto softness = delegate->GetLightParamValue(id, UsdLuxTokens->shapingConeSoftness).GetWithDefault(0.0f);
#else
const auto hdAngle = delegate->GetLightParamValue(id, _tokens->shapingConeAngle).GetWithDefault(180.0f);
const auto softness = delegate->GetLightParamValue(id, _tokens->shapingConeSoftness).GetWithDefault(0.0f);
#endif
const auto arnoldAngle = hdAngle * 2.0f;
const auto penumbra = arnoldAngle * softness;
AiNodeSetFlt(light, str::cone_angle, arnoldAngle);
Expand Down Expand Up @@ -211,7 +249,11 @@ auto spotLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* nentr
auto pointLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* nentry, const SdfPath& id,
HdSceneDelegate* delegate) {
TF_UNUSED(filter);
#if PXR_VERSION >= 2102
const auto treatAsPointValue = delegate->GetLightParamValue(id, UsdLuxTokens->treatAsPoint);
#else
const auto treatAsPointValue = delegate->GetLightParamValue(id, _tokens->treatAsPoint);
#endif
if (treatAsPointValue.IsHolding<bool>() && treatAsPointValue.UncheckedGet<bool>()) {
AiNodeSetFlt(light, str::radius, 0.0f);
AiNodeSetBool(light, str::normalize, true);
Expand Down Expand Up @@ -245,11 +287,19 @@ auto rectLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* nentr
TF_UNUSED(filter);
float width = 1.0f;
float height = 1.0f;
#if PXR_VERSION >= 2102
const auto& widthValue = delegate->GetLightParamValue(id, UsdLuxTokens->inputsWidth);
#else
const auto& widthValue = delegate->GetLightParamValue(id, HdLightTokens->width);
#endif
if (widthValue.IsHolding<float>()) {
width = widthValue.UncheckedGet<float>();
}
#if PXR_VERSION >= 2102
const auto& heightValue = delegate->GetLightParamValue(id, UsdLuxTokens->inputsHeight);
#else
const auto& heightValue = delegate->GetLightParamValue(id, HdLightTokens->height);
#endif
if (heightValue.IsHolding<float>()) {
height = heightValue.UncheckedGet<float>();
}
Expand All @@ -269,7 +319,11 @@ auto cylinderLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* n
TF_UNUSED(filter);
iterateParams(light, nentry, id, delegate, cylinderParams);
float length = 1.0f;
#if PXR_VERSION >= 2102
const auto& lengthValue = delegate->GetLightParamValue(id, UsdLuxTokens->inputsLength);
#else
const auto& lengthValue = delegate->GetLightParamValue(id, UsdLuxTokens->length);
#endif
if (lengthValue.IsHolding<float>()) {
length = lengthValue.UncheckedGet<float>();
}
Expand All @@ -281,7 +335,11 @@ auto cylinderLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* n
auto domeLightSync = [](AtNode* light, AtNode** filter, const AtNodeEntry* nentry, const SdfPath& id,
HdSceneDelegate* delegate) {
TF_UNUSED(filter);
#if PXR_VERSION >= 2102
const auto& formatValue = delegate->GetLightParamValue(id, UsdLuxTokens->inputsTextureFormat);
#else
const auto& formatValue = delegate->GetLightParamValue(id, UsdLuxTokens->textureFormat);
#endif
if (formatValue.IsHolding<TfToken>()) {
const auto& textureFormat = formatValue.UncheckedGet<TfToken>();
if (textureFormat == UsdLuxTokens->latlong) {
Expand Down Expand Up @@ -433,7 +491,11 @@ void HdArnoldGenericLight::Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* r
iterateParams(_light, nentry, id, sceneDelegate, genericParams);
_syncParams(_light, &_filter, nentry, id, sceneDelegate);
if (_supportsTexture) {
#if PXR_VERSION >= 2102
SetupTexture(sceneDelegate->GetLightParamValue(id, UsdLuxTokens->inputsTextureFile));
#else
SetupTexture(sceneDelegate->GetLightParamValue(id, HdLightTokens->textureFile));
#endif
}
for (const auto& primvar : sceneDelegate->GetPrimvarDescriptors(id, HdInterpolation::HdInterpolationConstant)) {
ConvertPrimvarToBuiltinParameter(_light, primvar.name, sceneDelegate->Get(id, primvar.name));
Expand Down Expand Up @@ -488,8 +550,13 @@ void HdArnoldGenericLight::Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* r
}
}
};
#if PXR_VERSION >= 2102
updateLightLinking(_lightLink, UsdLuxTokens->lightLink, false);
updateLightLinking(_shadowLink, UsdLuxTokens->shadowLink, true);
#else
updateLightLinking(_lightLink, HdTokens->lightLink, false);
updateLightLinking(_shadowLink, HdTokens->shadowLink, true);
#endif

*dirtyBits = HdLight::Clean;
}
Expand Down
9 changes: 9 additions & 0 deletions render_delegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,21 @@ inline void _ConvertFaceVaryingPrimvarToBuiltin(

} // namespace

#if PXR_VERSION >= 2102
HdArnoldMesh::HdArnoldMesh(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id)
: HdArnoldRprim<HdMesh>(str::polymesh, renderDelegate, id)
{
// The default value is 1, which won't work well in a Hydra context.
AiNodeSetByte(GetArnoldNode(), str::subdiv_iterations, 0);
}
#else
HdArnoldMesh::HdArnoldMesh(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id, const SdfPath& instancerId)
: HdArnoldRprim<HdMesh>(str::polymesh, renderDelegate, id, instancerId)
{
// The default value is 1, which won't work well in a Hydra context.
AiNodeSetByte(GetArnoldNode(), str::subdiv_iterations, 0);
}
#endif

void HdArnoldMesh::Sync(
HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, const TfToken& reprToken)
Expand Down
9 changes: 9 additions & 0 deletions render_delegate/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ PXR_NAMESPACE_OPEN_SCOPE
/// Utility class for translating Hydra Mesh to Arnold Polymesh.
class HdArnoldMesh : public HdArnoldRprim<HdMesh> {
public:
#if PXR_VERSION >= 2102
/// Constructor for HdArnoldMesh.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the mesh.
HDARNOLD_API
HdArnoldMesh(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id);
#else
/// Constructor for HdArnoldMesh.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the mesh.
/// @param instancerId Path to the Point Instancer for this mesh.
HDARNOLD_API
HdArnoldMesh(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id, const SdfPath& instancerId = SdfPath());
#endif

/// Destructor for HdArnoldMesh.
///
Expand Down
7 changes: 7 additions & 0 deletions render_delegate/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

PXR_NAMESPACE_OPEN_SCOPE

#if PXR_VERSION >= 2102
HdArnoldPoints::HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id)
: HdArnoldRprim<HdPoints>(str::points, renderDelegate, id)
{
}
#else
HdArnoldPoints::HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id, const SdfPath& instancerId)
: HdArnoldRprim<HdPoints>(str::points, renderDelegate, id, instancerId)
{
}
#endif

HdDirtyBits HdArnoldPoints::GetInitialDirtyBitsMask() const
{
Expand Down
9 changes: 9 additions & 0 deletions render_delegate/points.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ PXR_NAMESPACE_OPEN_SCOPE
/// Utility class to handle point primitives.
class HdArnoldPoints : public HdArnoldRprim<HdPoints> {
public:
#if PXR_VERSION >= 2102
/// Constructor for HdArnoldPoints.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the points.
HDARNOLD_API
HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id);
#else
/// Constructor for HdArnoldPoints.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param id Path to the points.
/// @param instancerId Path to the Point Instancer for this points.
HDARNOLD_API
HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id, const SdfPath& instancerId = SdfPath());
#endif

/// Destructor for HdArnoldPoints.
///
Expand Down
Loading

0 comments on commit 6d27319

Please sign in to comment.