66#include < helium/helium_math.h>
77// tsd_io
88#include " tsd/io/serialization.hpp"
9+ // std
10+ #include < algorithm>
911
1012namespace tsd_device {
1113
12- Frame::Frame (DeviceGlobalState *s) : helium::BaseFrame(s) {}
14+ Frame::Frame (DeviceGlobalState *s) : helium::BaseFrame(s)
15+ {
16+ m_anariFrame = anari::newObject<anari::Frame>(s->device );
17+ }
1318
1419Frame::~Frame ()
1520{
1621 wait ();
22+ anari::release (deviceState ()->device , m_anariFrame);
1723}
1824
1925bool Frame::isValid () const
2026{
21- return m_world && m_world->isValid ();
27+ return m_world && m_world->isValid () && m_renderer && m_camera ;
2228}
2329
2430DeviceGlobalState *Frame::deviceState () const
@@ -49,6 +55,41 @@ void Frame::finalize()
4955 reportMessage (
5056 ANARI_SEVERITY_WARNING, " missing required parameter 'camera' on frame" );
5157 }
58+
59+ if (!(m_world && m_renderer && m_camera))
60+ return ;
61+
62+ auto *state = deviceState ();
63+ auto d = state->device ;
64+ anari::unsetAllParameters (d, m_anariFrame);
65+ std::for_each (params_begin (), params_end (), [&](auto &p) {
66+ if (anari::isObject (p.second .type ())) {
67+ reportMessage (ANARI_SEVERITY_WARNING,
68+ " skip forwarding object parameter '%s' on ANARIFrame" ,
69+ p.first .c_str ());
70+ } else if (p.first == " name" && p.second .type () == ANARI_STRING) {
71+ anari::setParameter (
72+ d, m_anariFrame, p.first .c_str (), p.second .getString ());
73+ } else if (p.second .type () != ANARI_UNKNOWN) {
74+ anari::setParameter (
75+ d, m_anariFrame, p.first .c_str (), p.second .type (), p.second .data ());
76+ } else {
77+ reportMessage (ANARI_SEVERITY_WARNING,
78+ " skip setting parameter '%s' of unknown type on ANARIFrame" ,
79+ p.first .c_str ());
80+ }
81+ });
82+
83+ anari::setParameter (
84+ d, m_anariFrame, " camera" , (anari::Camera)m_camera->anariHandle ());
85+ anari::setParameter (
86+ d, m_anariFrame, " renderer" , (anari::Renderer)m_renderer->anariHandle ());
87+ anari::setParameter (d,
88+ m_anariFrame,
89+ " world" ,
90+ (anari::World)m_world->getRenderIndex ()->world ());
91+
92+ anari::commitParameters (d, m_anariFrame);
5293}
5394
5495bool Frame::getProperty (const std::string_view &name,
@@ -57,7 +98,14 @@ bool Frame::getProperty(const std::string_view &name,
5798 uint64_t size,
5899 uint32_t flags)
59100{
60- return 0 ;
101+ std::string nameStr (name);
102+ return anariGetProperty (deviceState ()->device ,
103+ m_anariFrame,
104+ nameStr.c_str (),
105+ type,
106+ ptr,
107+ size,
108+ flags);
61109}
62110
63111void Frame::renderFrame ()
@@ -67,23 +115,29 @@ void Frame::renderFrame()
67115 reportMessage (
68116 ANARI_SEVERITY_INFO, " exporting scene to 'tsd_device_export.tsd'" );
69117 tsd::io::save_Scene (state->scene , " tsd_device_export.tsd" );
118+ anari::render (state->device , m_anariFrame);
70119}
71120
72121void *Frame::map (std::string_view channel,
73122 uint32_t *width,
74123 uint32_t *height,
75124 ANARIDataType *pixelType)
76125{
77- wait ();
78- *width = 0 ;
79- *height = 0 ;
80- *pixelType = ANARI_UNKNOWN;
81- return nullptr ;
126+ auto *state = deviceState ();
127+ std::string channelStr (channel);
128+ return (void *)anariMapFrame (state->device ,
129+ m_anariFrame,
130+ channelStr.c_str (),
131+ width,
132+ height,
133+ pixelType);
82134}
83135
84136void Frame::unmap (std::string_view channel)
85137{
86- // no-op
138+ auto *state = deviceState ();
139+ std::string channelStr (channel);
140+ anari::unmap (state->device , m_anariFrame, channelStr.c_str ());
87141}
88142
89143int Frame::frameReady (ANARIWaitMask m)
@@ -98,17 +152,17 @@ int Frame::frameReady(ANARIWaitMask m)
98152
99153void Frame::discard ()
100154{
101- // no-op
155+ anari::discard ( deviceState ()-> device , m_anariFrame);
102156}
103157
104158bool Frame::ready () const
105159{
106- return true ;
160+ return anari::isReady ( deviceState ()-> device , m_anariFrame) ;
107161}
108162
109163void Frame::wait () const
110164{
111- // no-op
165+ anari::wait ( deviceState ()-> device , m_anariFrame);
112166}
113167
114168} // namespace tsd_device
0 commit comments