Skip to content

Commit

Permalink
Hydrogent: moved USD stage loading to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 21, 2023
1 parent e31577b commit a6940d9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 42 deletions.
67 changes: 37 additions & 30 deletions Hydrogent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,72 @@ set_common_target_properties(Diligent-Hydrogent)

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

add_library(USD_LIBS INTERFACE)

if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
# Boost version depends on Visual Studio version. Since we can't use wildcards in
# generator expressions, we have to find boost directory for each configuration
file(GLOB BOOST_INCLUDE_DEBUG "${DILIGENT_USD_PATH}/Debug/include/boost-*")
file(GLOB BOOST_INCLUDE_RELEASE "${DILIGENT_USD_PATH}/Release/include/boost-*")
file(GLOB BOOST_INCLUDE_RELWITHDEBINFO "${DILIGENT_USD_PATH}/RelWithDebInfo/include/boost-*")

target_include_directories(Diligent-Hydrogent
PRIVATE
target_include_directories(USD_LIBS
INTERFACE
${DILIGENT_USD_PATH}/$<CONFIG>/include
$<$<CONFIG:DEBUG>:${BOOST_INCLUDE_DEBUG}>
$<$<CONFIG:RELEASE>:${BOOST_INCLUDE_RELEASE}>
$<$<CONFIG:RELWITHDEBINFO>:${BOOST_INCLUDE_RELWITHDEBINFO}>
)

target_link_directories(Diligent-Hydrogent
PUBLIC
target_link_directories(USD_LIBS
INTERFACE
${DILIGENT_USD_PATH}/$<CONFIG>/lib
)
else()
file(GLOB BOOST_INCLUDE_DEBUG "${DILIGENT_USD_PATH}/Debug/boost-*")
target_include_directories(Diligent-Hydrogent
PRIVATE
target_include_directories(USD_LIBS
INTERFACE
${DILIGENT_USD_PATH}/include
${BOOST_INCLUDE_DEBUG}
)

target_link_directories(Diligent-Hydrogent
PUBLIC
target_link_directories(USD_LIBS
INTERFACE
${DILIGENT_USD_PATH}/lib
)
endif()

target_include_directories(USD_LIBS
INTERFACE
${Python3_INCLUDE_DIRS}
)

if(MSVC)
target_compile_definitions(USD_LIBS INTERFACE NOMINMAX)
target_compile_options(USD_LIBS INTERFACE /wd4244 /wd4305 /wd4127 /wd4267)
endif()

target_link_libraries(USD_LIBS
INTERFACE
usd_gf
usd_ar
usd_sdf
usd_tf
usd_usd
usd_plug
usd_hd
usd_usdImaging
usd_vt
usd_hio
usd_sdr
usd_ndr
)

target_include_directories(Diligent-Hydrogent
PUBLIC
interface
PRIVATE
include
${Python3_INCLUDE_DIRS}
)

target_link_directories(Diligent-Hydrogent
Expand All @@ -88,20 +115,8 @@ add_library(EnableRTTI INTERFACE)
target_compile_options(EnableRTTI INTERFACE /GR)

target_link_libraries(Diligent-Hydrogent
PUBLIC
usd_gf
usd_ar
usd_sdf
usd_tf
usd_usd
usd_plug
usd_hd
usd_usdImaging
usd_vt
usd_hio
usd_sdr
usd_ndr
PRIVATE
USD_LIBS
NO_WERROR
EnableRTTI # USD requires RTTI
Diligent-GraphicsEngine
Expand All @@ -112,14 +127,6 @@ PRIVATE
DiligentFX
)

if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
target_compile_definitions(Diligent-Hydrogent PRIVATE NOMINMAX)
endif()

if(MSVC)
target_compile_options(Diligent-Hydrogent PRIVATE /wd4244 /wd4305 /wd4127 /wd4267)
endif()

set_target_properties(Diligent-Hydrogent PROPERTIES
FOLDER DiligentFX
)
Expand Down
5 changes: 3 additions & 2 deletions Hydrogent/include/HnRendererImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>

IMPLEMENT_QUERY_INTERFACE2_IN_PLACE(IID_HnRenderer, IID_Impl, TBase)

virtual void LoadUSDStage(const char* FileName) override final;
virtual void LoadUSDStage(pxr::UsdStageRefPtr& Stage) override final;
virtual void Update() override final;
virtual void Draw(IDeviceContext* pCtx, const HnDrawAttribs& Attribs) override final;
virtual void SetEnvironmentMap(IDeviceContext* pCtx, ITextureView* pEnvironmentMapSRV) override final;

private:
RenderDeviceWithCache_N m_Device;
RenderDeviceWithCache_N m_Device;
RefCntAutoPtr<IDeviceContext> m_Context;

RefCntAutoPtr<IBuffer> m_CameraAttribsCB;
RefCntAutoPtr<IBuffer> m_LightAttribsCB;
Expand Down
4 changes: 3 additions & 1 deletion Hydrogent/interface/HnRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "../../../Graphics/GraphicsEngine/interface/DeviceContext.h"
#include "../../../Common/interface/BasicMath.hpp"

#include "pxr/usd/usd/stage.h"

namespace Diligent
{

Expand Down Expand Up @@ -87,7 +89,7 @@ struct HnDrawAttribs
class IHnRenderer : public IObject
{
public:
virtual void LoadUSDStage(const char* FileName) = 0;
virtual void LoadUSDStage(pxr::UsdStageRefPtr& Stage) = 0;

virtual void Update() = 0;

Expand Down
15 changes: 6 additions & 9 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters,
const HnRendererCreateInfo& CI) :
TBase{pRefCounters},
m_Device{pDevice},
m_Context{pContext},
m_CameraAttribsCB{CI.pCameraAttribsCB},
m_LightAttribsCB{CI.pLightAttribsCB},
m_USDRenderer{
Expand Down Expand Up @@ -119,8 +120,7 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters,
EnvMapRndrCI.ConvertOutputToSRGB = CI.ConvertOutputToSRGB;

return EnvMapRndrCI;
}(CI, pDevice))},
m_RenderDelegate{HnRenderDelegate::Create({pDevice, pContext, m_CameraAttribsCB, m_LightAttribsCB, m_USDRenderer})}
}(CI, pDevice))}
{
}

Expand All @@ -130,14 +130,11 @@ HnRendererImpl::~HnRendererImpl()
delete m_RenderIndex;
}

void HnRendererImpl::LoadUSDStage(const char* FileName)
void HnRendererImpl::LoadUSDStage(pxr::UsdStageRefPtr& Stage)
{
m_Stage = pxr::UsdStage::Open(FileName);
if (!m_Stage)
{
LOG_ERROR_MESSAGE("Failed to open USD stage '", FileName, "'");
return;
}
m_Stage = Stage;

m_RenderDelegate = HnRenderDelegate::Create({m_Device, m_Context, m_CameraAttribsCB, m_LightAttribsCB, m_USDRenderer});

m_RenderIndex = pxr::HdRenderIndex::New(m_RenderDelegate.get(), pxr::HdDriverVector{});
m_ImagingDelegate = new pxr::UsdImagingDelegate(m_RenderIndex, pxr::SdfPath::AbsoluteRootPath());
Expand Down

0 comments on commit a6940d9

Please sign in to comment.