2323#include < QPixmap>
2424#include < QPlainTextEdit>
2525#include < QPushButton>
26+ #include < QRadioButton>
2627#include < QScrollArea>
2728#include < QSlider>
2829#include < QSpinBox>
@@ -721,6 +722,11 @@ OSLToyMainWindow::OSLToyMainWindow(OSLToyRenderer* rend, int xr, int yr)
721722 connect (maintimer, &QTimer::timeout, this ,
722723 &OSLToyMainWindow::timed_rerender_trigger);
723724 maintimer->start ();
725+
726+ // Provide the callback to the renderer
727+ m_renderer->set_output_getter ([this ]() {
728+ return this ->selected_output (); // Return the selected output
729+ });
724730}
725731
726732
@@ -1249,6 +1255,25 @@ OSLToyMainWindow::build_shader_group()
12491255 }
12501256 renderer ()->set_shadergroup (group);
12511257
1258+ // Doing OSLQuery here before the getattribute calls to
1259+ // set first output param in param list as renderer output if none selected
1260+ if (m_selectedoutput.empty ()) {
1261+ OSLQuery oslquery = ss->oslquery (
1262+ *group, 0 ); // can I assume that there is only ever one group?
1263+ for (size_t p = 0 ; p < oslquery.nparams (); ++p) {
1264+ auto param = oslquery.getparam (p);
1265+ // Has to be output and vec3, so we can display as color
1266+ if (param->isoutput && param->type .is_vec3 ()) {
1267+ m_selectedoutput = param->name ;
1268+ break ;
1269+ }
1270+ }
1271+ }
1272+
1273+ ustring outputs[] = { m_selectedoutput };
1274+ ss->attribute (group.get (), " renderer_outputs" ,
1275+ TypeDesc (TypeDesc::STRING, 1 ), &outputs);
1276+
12521277 m_shader_uses_time = false ;
12531278 int num_globals_needed = 0 ;
12541279 const ustring* globals_needed = nullptr ;
@@ -1305,7 +1330,6 @@ OSLToyMainWindow::make_param_adjustment_row(ParamRec* param,
13051330 connect (diddleCheckbox, &QCheckBox::stateChanged, this ,
13061331 [&](int state) { set_param_diddle (param, state); });
13071332#endif
1308- layout->addWidget (diddleCheckbox, row, 0 );
13091333
13101334 std::string typetext (param->type .c_str ());
13111335 if (param->isclosure )
@@ -1314,8 +1338,38 @@ OSLToyMainWindow::make_param_adjustment_row(ParamRec* param,
13141338 typetext = OSL::fmtformat (" struct {}" , param->structname );
13151339 if (param->isoutput )
13161340 typetext = OSL::fmtformat (" output {}" , typetext);
1341+
1342+ if ((param->isoutput ) && (param->type .is_vec3 ())) {
1343+ // Create a radio button for the output parameter
1344+ auto outputRadioButton = new QRadioButton (this );
1345+ layout->addWidget (outputRadioButton, row, 0 );
1346+
1347+ // Label for the output parameter
1348+ auto nameLabel = new QLabel (
1349+ OSL::fmtformat (" <i>{}</i> <b>{}</b>" , typetext, param->name )
1350+ .c_str ());
1351+ nameLabel->setTextFormat (Qt::RichText);
1352+ layout->addWidget (nameLabel, row, 1 );
1353+
1354+ // Connect the radio button to save the selected output and rerender
1355+ connect (outputRadioButton, &QRadioButton::toggled, this ,
1356+ [this , param](bool checked) {
1357+ if (checked) {
1358+ // Save the selected output parameter
1359+ m_selectedoutput = param->name ;
1360+ }
1361+ });
1362+
1363+ // Check the radio button if this parameter is the currently selected output
1364+ if (m_selectedoutput == param->name )
1365+ outputRadioButton->setChecked (true );
1366+
1367+ return ; // Skip the rest of the function for output parameters
1368+ }
13171369 // auto typeLabel = QtUtils::mtmt{}<i>{}</i>", typetext);
13181370 // layout->addWidget (typeLabel, row, 1);
1371+ layout->addWidget (diddleCheckbox, row, 0 );
1372+
13191373 auto nameLabel = new QLabel (
13201374 OSL::fmtformat (" <i>{}</i> <b>{}</b>" , typetext, param->name )
13211375 .c_str ());
0 commit comments