Skip to content

Commit bd28ff1

Browse files
authored
OSLQuery improvements (#821)
* OSLQuery::Parameter -- add copy/move constructors * Make the ShadingSystem side of OSLQuery correctly report default vals.
1 parent 84e9205 commit bd28ff1

4 files changed

Lines changed: 64 additions & 14 deletions

File tree

src/include/OSL/oslquery.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class OSLQUERYPUBLIC OSLQuery {
6161
struct Parameter {
6262
ustring name; ///< name
6363
TypeDesc type; ///< data type
64-
bool isoutput; ///< is it an output param?
65-
bool validdefault; ///< false if there's no default val
66-
bool varlenarray; ///< is it a varying-length array?
67-
bool isstruct; ///< is it a structure?
68-
bool isclosure; ///< is it a closure?
69-
void *data; ///< pointer to data
64+
bool isoutput = false; ///< is it an output param?
65+
bool validdefault = false; ///< false if there's no default val
66+
bool varlenarray = false; ///< is it a varying-length array?
67+
bool isstruct = false; ///< is it a structure?
68+
bool isclosure = false; ///< is it a closure?
69+
void *data = nullptr; ///< pointer to data
7070
std::vector<int> idefault; ///< default int values
7171
std::vector<float> fdefault; ///< default float values
7272
std::vector<ustring> sdefault; ///< default string values
@@ -75,10 +75,10 @@ class OSLQUERYPUBLIC OSLQuery {
7575
std::vector<ustring> fields; ///< Names of this struct's fields
7676
ustring structname; ///< Name of the struct
7777
std::vector<Parameter> metadata; ///< Meta-data about the param
78-
Parameter ()
79-
: isoutput(false), validdefault(false), varlenarray(false),
80-
isstruct(false), isclosure(false), data(NULL)
81-
{ }
78+
79+
Parameter () {}
80+
Parameter (const Parameter& src);
81+
Parameter (Parameter&& src);
8282
};
8383

8484
OSLQuery ();

src/include/osl_pvt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,21 +699,21 @@ class Symbol {
699699
bool is_temp () const { return symtype() == SymTypeTemp; }
700700

701701
// Retrieve the const float value (will ASSERT if not a const float!)
702-
float get_float (int index = 0) {
702+
float get_float (int index = 0) const {
703703
ASSERT (data() && typespec().is_float_based());
704704
return ((const float *)data())[index];
705705
}
706706

707707
// Retrieve the const int value (will ASSERT if not a const int!)
708-
int get_int (int index = 0) {
708+
int get_int (int index = 0) const {
709709
ASSERT (data() && typespec().is_int_based());
710710
return ((const int *)data())[index];
711711
}
712712

713713
// Retrieve the const string value (will ASSERT if not a const string!)
714-
ustring get_string () {
714+
ustring get_string (int index = 0) const {
715715
ASSERT (data() && typespec().is_string());
716-
return ((const ustring *)data())[0];
716+
return ((const ustring *)data())[index];
717717
}
718718

719719
/// Stream output

src/liboslexec/shadingsys.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,19 @@ OSL::OSLQuery::init (const ShaderGroup *group, int layernum)
31023102
p.fdefault.clear();
31033103
p.sdefault.clear();
31043104
p.spacename.clear();
3105+
int n = int (p.type.numelements() * p.type.aggregate);
3106+
if (p.type.basetype == TypeDesc::INT) {
3107+
for (int i = 0; i < n; ++i)
3108+
p.idefault.push_back (sym->get_int(i));
3109+
}
3110+
if (p.type.basetype == TypeDesc::FLOAT) {
3111+
for (int i = 0; i < n; ++i)
3112+
p.fdefault.push_back (sym->get_float(i));
3113+
}
3114+
if (p.type.basetype == TypeDesc::STRING) {
3115+
for (int i = 0; i < n; ++i)
3116+
p.sdefault.push_back (sym->get_string(i));
3117+
}
31053118
p.fields.clear(); // don't bother filling this out
31063119
if (StructSpec *ss = ts.structspec()) {
31073120
p.structname = ss->name().string();

src/liboslquery/oslquery.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,43 @@ OSOReaderQuery::codemarker (const char *name)
267267

268268

269269

270+
OSLQuery::Parameter::Parameter (const Parameter& src)
271+
: name(src.name), type(src.type), isoutput(src.isoutput),
272+
validdefault(src.validdefault), varlenarray(src.varlenarray),
273+
isstruct(src.isstruct), isclosure(src.isclosure),
274+
idefault(src.idefault), fdefault(src.fdefault),
275+
sdefault(src.sdefault), spacename(src.spacename),
276+
fields(src.fields), structname(src.structname),
277+
metadata(src.metadata)
278+
{
279+
if (type.basetype == TypeDesc::INT)
280+
data = idefault.data();
281+
else if (type.basetype == TypeDesc::FLOAT)
282+
data = fdefault.data();
283+
else if (type.basetype == TypeDesc::STRING)
284+
data = sdefault.data();
285+
}
286+
287+
288+
289+
OSLQuery::Parameter::Parameter (Parameter&& src)
290+
: name(src.name), type(src.type), isoutput(src.isoutput),
291+
validdefault(src.validdefault), varlenarray(src.varlenarray),
292+
isstruct(src.isstruct), isclosure(src.isclosure),
293+
idefault(src.idefault), fdefault(src.fdefault),
294+
sdefault(src.sdefault), spacename(src.spacename),
295+
fields(src.fields), structname(src.structname),
296+
metadata(src.metadata)
297+
{
298+
if (type.basetype == TypeDesc::INT)
299+
data = idefault.data();
300+
else if (type.basetype == TypeDesc::FLOAT)
301+
data = fdefault.data();
302+
else if (type.basetype == TypeDesc::STRING)
303+
data = sdefault.data();
304+
}
305+
306+
270307

271308
OSLQuery::OSLQuery ()
272309
{

0 commit comments

Comments
 (0)