bool OSLRenderServices::get_attribute( ShaderData *sd, bool derivatives, ustring object_name, TypeDesc type, ustring name, void *val) { KernelGlobals *kg = sd->osl_globals; int prim_type = 0; int object; /* lookup of attribute on another object */ if (object_name != u_empty) { OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name); if (it == kg->osl->object_name_map.end()) return false; object = it->second; } else { object = sd->object; prim_type = attribute_primitive_type(kg, sd); if (object == OBJECT_NONE) return get_background_attribute(kg, sd, name, type, derivatives, val); } /* find attribute on object */ object = object * ATTR_PRIM_TYPES + prim_type; OSLGlobals::AttributeMap &attribute_map = kg->osl->attribute_map[object]; OSLGlobals::AttributeMap::iterator it = attribute_map.find(name); if (it != attribute_map.end()) { const OSLGlobals::Attribute &attr = it->second; if (attr.desc.element != ATTR_ELEMENT_OBJECT) { /* triangle and vertex attributes */ if (get_primitive_attribute(kg, sd, attr, type, derivatives, val)) return true; else return get_mesh_attribute(kg, sd, attr, type, derivatives, val); } else { /* object attribute */ get_object_attribute(attr, derivatives, val); return true; } } else { /* not found in attribute, check standard object info */ bool is_std_object_attribute = get_object_standard_attribute( kg, sd, name, type, derivatives, val); if (is_std_object_attribute) return true; return get_background_attribute(kg, sd, name, type, derivatives, val); } return false; }
bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name, TypeDesc type, ustring name, void *val) { KernelGlobals *kg = kernel_globals; ShaderData *sd = (ShaderData *)renderstate; int object, prim, segment; /* lookup of attribute on another object */ if (object_name != u_empty || sd == NULL) { OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name); if (it == kg->osl->object_name_map.end()) return false; object = it->second; prim = ~0; segment = ~0; } else { object = sd->object; prim = sd->prim; #ifdef __HAIR__ segment = sd->segment; #else segment = ~0; #endif if (object == ~0) return get_background_attribute(kg, sd, name, type, derivatives, val); } /* find attribute on object */ object = object*ATTR_PRIM_TYPES + (segment != ~0); OSLGlobals::AttributeMap& attribute_map = kg->osl->attribute_map[object]; OSLGlobals::AttributeMap::iterator it = attribute_map.find(name); if (it != attribute_map.end()) { const OSLGlobals::Attribute& attr = it->second; if (attr.elem != ATTR_ELEMENT_VALUE) { /* triangle and vertex attributes */ if (prim != ~0) return get_mesh_attribute(kg, sd, attr, type, derivatives, val); } else { /* object attribute */ get_object_attribute(attr, derivatives, val); return true; } } else { /* not found in attribute, check standard object info */ bool is_std_object_attribute = get_object_standard_attribute(kg, sd, name, type, derivatives, val); if (is_std_object_attribute) return true; return get_background_attribute(kg, sd, name, type, derivatives, val); } return false; }