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 (!isValid ())
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,33 +98,48 @@ 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 ()
64112{
65113 auto *state = deviceState ();
66114 state->commitBuffer .flush ();
67- reportMessage (
68- ANARI_SEVERITY_INFO, " exporting scene to 'tsd_device_export.tsd'" );
69- tsd::io::save_Scene (state->scene , " tsd_device_export.tsd" );
115+
116+ const char *filename = " live_capture.tsd" ;
117+ reportMessage (ANARI_SEVERITY_INFO, " exporting scene to '%s'" , filename);
118+ tsd::io::save_Scene (state->scene , filename);
119+
120+ anari::render (state->device , m_anariFrame);
70121}
71122
72123void *Frame::map (std::string_view channel,
73124 uint32_t *width,
74125 uint32_t *height,
75126 ANARIDataType *pixelType)
76127{
77- wait ();
78- *width = 0 ;
79- *height = 0 ;
80- *pixelType = ANARI_UNKNOWN;
81- return nullptr ;
128+ auto *state = deviceState ();
129+ std::string channelStr (channel);
130+ return (void *)anariMapFrame (state->device ,
131+ m_anariFrame,
132+ channelStr.c_str (),
133+ width,
134+ height,
135+ pixelType);
82136}
83137
84138void Frame::unmap (std::string_view channel)
85139{
86- // no-op
140+ auto *state = deviceState ();
141+ std::string channelStr (channel);
142+ anari::unmap (state->device , m_anariFrame, channelStr.c_str ());
87143}
88144
89145int Frame::frameReady (ANARIWaitMask m)
@@ -98,17 +154,17 @@ int Frame::frameReady(ANARIWaitMask m)
98154
99155void Frame::discard ()
100156{
101- // no-op
157+ anari::discard ( deviceState ()-> device , m_anariFrame);
102158}
103159
104160bool Frame::ready () const
105161{
106- return true ;
162+ return anari::isReady ( deviceState ()-> device , m_anariFrame) ;
107163}
108164
109165void Frame::wait () const
110166{
111- // no-op
167+ anari::wait ( deviceState ()-> device , m_anariFrame);
112168}
113169
114170} // namespace tsd_device
0 commit comments