Skip to content

Commit 632f9a2

Browse files
authored
Update osltoyrenderer.cpp
auto-detect output variable -- doesn't need to be Cout if there's only one Signed-off-by: lunakhan <91382322+lunakhan@users.noreply.github.com>
1 parent a97387a commit 632f9a2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/osltoy/osltoyrenderer.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,34 @@ OSLToyRenderer::render_image()
129129
m_framebuffer.reset(
130130
OIIO::ImageSpec(m_xres, m_yres, 3, TypeDesc::FLOAT));
131131

132-
static ustring outputs[] = { ustring("Cout") };
132+
std::vector<ustring> output_vars;
133+
134+
// Get the list of output variables from the shader group
135+
shadingsys()->getattribute(shadergroup(), "renderer_outputs", output_vars);
136+
137+
// If no output variables are found, default to Cout
138+
if (output_vars.empty()) {
139+
output_vars.push_back(ustring("Cout"));
140+
}
141+
142+
// If there's only one output variable, automatically use it
143+
const ustring* outputs = &output_vars[0];
144+
if (output_vars.size() == 1) {
145+
outputs = &output_vars[0]; // auto-detect and use the single output
146+
} else {
147+
// If there are multiple outputs, you could implement additional logic here
148+
// to choose between them or provide the user with a choice.
149+
outputs = &output_vars[0]; // default to the first output
150+
}
151+
133152
OIIO::paropt popt(0, OIIO::paropt::SplitDir::Tile, 4096);
134153
shade_image(*shadingsys(), *shadergroup(), &m_shaderglobals_template,
135154
m_framebuffer, outputs, ShadePixelCenters, OIIO::ROI(), popt);
136-
// std::cout << timer() << "\n";
137155
}
138156

139157

140158

159+
141160
int
142161
OSLToyRenderer::supports(string_view /*feature*/) const
143162
{

0 commit comments

Comments
 (0)