OSL_SHADEOP const char * osl_closure_to_string (ShaderGlobals *sg, ClosureColor *c) { // Special case for printing closures std::stringstream stream; print_closure(stream, c, &sg->context->shadingsys()); return ustring(stream.str ()).c_str(); }
static void print_closure (std::ostream &out, const ClosureColor *closure, ShadingSystemImpl *ss, const Color3 &w, bool &first) { if (closure == NULL) return; switch (closure->id) { case ClosureColor::MUL: print_closure(out, closure->as_mul()->closure, ss, closure->as_mul()->weight * w, first); break; case ClosureColor::ADD: print_closure(out, closure->as_add()->closureA, ss, w, first); print_closure(out, closure->as_add()->closureB, ss, w, first); break; default: if (!first) out << "\n\t+ "; print_component (out, closure->as_comp(), ss, w); first = false; break; } }
static void print_closure (std::ostream &out, const ClosureColor *closure, ShadingSystemImpl *ss, const Color3 &w, bool &first) { ClosureComponent *comp; if (closure == NULL) return; switch (closure->type) { case ClosureColor::MUL: print_closure(out, ((ClosureMul *)closure)->closure, ss, ((ClosureMul *)closure)->weight * w, first); break; case ClosureColor::ADD: print_closure(out, ((ClosureAdd *)closure)->closureA, ss, w, first); print_closure(out, ((ClosureAdd *)closure)->closureB, ss, w, first); break; case ClosureColor::COMPONENT: comp = (ClosureComponent *)closure; if (!first) out << "\n\t+ "; print_component (out, comp, ss, w); first = false; break; } }
static void print_component_value(std::ostream &out, ShadingSystemImpl *ss, TypeDesc type, const void *data) { if (type == TypeDesc::TypeInt) out << *(int *)data; else if (type == TypeDesc::TypeFloat) out << *(float *)data; else if (type == TypeDesc::TypeColor) out << "(" << ((Color3 *)data)->x << ", " << ((Color3 *)data)->y << ", " << ((Color3 *)data)->z << ")"; else if (type == TypeDesc::TypeVector) out << "(" << ((Vec3 *)data)->x << ", " << ((Vec3 *)data)->y << ", " << ((Vec3 *)data)->z << ")"; else if (type == TypeDesc::TypeString) out << "\"" << ((ustring *)data)->c_str() << "\""; else if (type == TypeDesc::PTR) // this only happens for closures print_closure (out, *(const ClosureColor **)data, ss); }
void closure(short *nucleus,int n) { int ruleno; unsigned word; unsigned mask; short *csp; unsigned *dsp; unsigned *rsp; int rulesetsize; short *csend; unsigned *rsend; int symbol; int itemno; rulesetsize = WORDSIZE(nrules); rsp = ruleset; rsend = ruleset + rulesetsize; for (rsp = ruleset; rsp < rsend; rsp++) *rsp = 0; csend = nucleus + n; for (csp = nucleus; csp < csend; ++csp) { symbol = ritem[*csp]; if (ISVAR(symbol)) { dsp = first_derives + symbol * rulesetsize; rsp = ruleset; while (rsp < rsend) *rsp++ |= *dsp++; } } ruleno = 0; itemsetend = itemset; csp = nucleus; for (rsp = ruleset; rsp < rsend; ++rsp) { word = *rsp; if (word == 0) ruleno += BITS_PER_WORD; else { mask = 1; while (mask) { if (word & mask) { itemno = rrhs[ruleno]; while (csp < csend && *csp < itemno) *itemsetend++ = *csp++; *itemsetend++ = itemno; while (csp < csend && *csp == itemno) ++csp; } mask <<= 1; ++ruleno; } } } while (csp < csend) *itemsetend++ = *csp++; #ifdef DEBUG print_closure(n); #endif }
void print_value (value v, int pass, hash_table_t *ht) { int size, i, n, ret; unsigned long key; char buf[256]; addr_list_t* entry; if (Is_long(v)) { if (pass == PASS2) printf("%ld ", Long_val(v)); return; } size=Wosize_val(v); switch (Tag_val(v)) { case Closure_tag: print_closure (v, pass, ht); break; case String_tag: print_string(v); break; case Double_tag: if (pass == PASS2) printf("%g ", Double_val(v)); break; case Double_array_tag: if (pass == PASS2) { printf("[| "); n = size/Double_wosize; for (i=0; i<n; i++) { printf("%g", Double_field(v,i)); if (i < (n-1)) printf("; "); else printf(" "); } printf("|]"); } break; case Abstract_tag: if (pass == PASS2) printf("(abstract) "); break; case Custom_tag: if (pass == PASS2) printf("(custom) "); break; default: if (pass == PASS2 && Tag_val(v) >= No_scan_tag) { printf("(unknown) "); break; }; /* For structured values, PASS1 gathers information about addresses and PASS2 prints it. We use MINCYCCNT as a threshold for printing cyclic/shared values. The name of the value is just its stringified address. */ if (pass == PASS1) { key = (unsigned long)v; entry = get(ht, key); if ((entry == NULL) || (entry->count < MINCYCCNT)) { buf[0] = '\0'; sprintf(buf,"var_%lx",key); put(ht, key, strdup(buf)); } for (i=0; i<size; i++) { key = (unsigned long)Field(v,i); entry = get(ht, key); if ((entry == NULL) || (entry->count < MINCYCCNT)) print_value(Field(v,i), pass, ht); } } else if (pass == PASS2) { key = (unsigned long)v; entry = get(ht, key); if ((entry != NULL) && (entry->count >= MINCYCCNT)) { printf("(v=%s) ", entry->val); if (entry->printed == FALSE) { entry->printed = TRUE; printf("( "); for (i=0; i<size; i++) { print_value(Field(v,i), pass, ht); if (i < (size-1)) printf(", "); } printf(") "); } } else { printf("( "); for (i=0; i<size; i++) { print_value(Field(v,i), pass, ht); if (i < (size-1)) printf(", "); } printf(") "); } } } return; }
void closure(Value_t *nucleus, int n) { unsigned ruleno; unsigned word; unsigned i; Value_t *csp; unsigned *dsp; unsigned *rsp; int rulesetsize; Value_t *csend; unsigned *rsend; int symbol; Value_t itemno; rulesetsize = WORDSIZE(nrules); rsend = ruleset + rulesetsize; for (rsp = ruleset; rsp < rsend; rsp++) *rsp = 0; csend = nucleus + n; for (csp = nucleus; csp < csend; ++csp) { symbol = ritem[*csp]; if (ISVAR(symbol)) { dsp = first_derives + symbol * rulesetsize; rsp = ruleset; while (rsp < rsend) *rsp++ |= *dsp++; } } ruleno = 0; itemsetend = itemset; csp = nucleus; for (rsp = ruleset; rsp < rsend; ++rsp) { word = *rsp; if (word) { for (i = 0; i < BITS_PER_WORD; ++i) { if (word & (unsigned)(1 << i)) { itemno = rrhs[ruleno + i]; while (csp < csend && *csp < itemno) *itemsetend++ = *csp++; *itemsetend++ = itemno; while (csp < csend && *csp == itemno) ++csp; } } } ruleno += BITS_PER_WORD; } while (csp < csend) *itemsetend++ = *csp++; #ifdef DEBUG print_closure(n); #endif }
void print_closure (std::ostream &out, const ClosureColor *closure, ShadingSystemImpl *ss) { bool first = true; print_closure(out, closure, ss, Color3(1, 1, 1), first); }