initialize user defined structures
| 26 | |
| 27 | // initialize user defined structures |
| 28 | void DefaultConstructor(bv_program* prog, bv_object* obj) |
| 29 | { |
| 30 | sd::ShaderDebugger* dbg = (sd::ShaderDebugger*)prog->user_data; |
| 31 | |
| 32 | const std::vector<sd::Structure>& strs = dbg->GetCompiler()->GetStructures(); |
| 33 | const sd::Structure* typeData = nullptr; |
| 34 | std::string objName(obj->type->name); |
| 35 | |
| 36 | for (const auto& str : strs) |
| 37 | if (str.Name == objName) { |
| 38 | typeData = &str; |
| 39 | break; |
| 40 | } |
| 41 | |
| 42 | // we can get structure members |
| 43 | if (typeData != nullptr) { |
| 44 | bv_object_info* type = obj->type; |
| 45 | |
| 46 | for (u16 i = 0; i < type->props.name_count; i++) { |
| 47 | std::string propName(type->props.names[i]); |
| 48 | |
| 49 | for (const auto& propData : typeData->Members) { |
| 50 | if (propData.Name == propName) { |
| 51 | // check for semantic |
| 52 | if (!propData.Semantic.empty()) { |
| 53 | bv_variable semValue = dbg->GetSemanticValue(propData.Semantic); |
| 54 | if (semValue.type != bv_type_void) { |
| 55 | obj->prop[i] = bv_variable_copy(semValue); |
| 56 | continue; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | bv_object_info* propObjInfo = bv_program_get_object_info(prog, propData.Type.c_str()); |
| 61 | |
| 62 | // structure |
| 63 | if (propObjInfo != nullptr) { |
| 64 | obj->prop[i] = bv_variable_create_object(propObjInfo); |
| 65 | bv_object* propObj = bv_variable_get_object(obj->prop[i]); |
| 66 | |
| 67 | if (!sd::IsBasicTexture(propObjInfo->name)) { |
| 68 | if (propObjInfo->ext_method_count > 0) { |
| 69 | // probably a vector or matrix |
| 70 | bv_type castType = sd::GetMatrixTypeFromName(propObjInfo->name); |
| 71 | if (castType == bv_type_void) |
| 72 | castType = sd::GetVectorTypeFromName(propObjInfo->name); |
| 73 | |
| 74 | for (u16 j = 0; j < propObjInfo->props.name_count; j++) |
| 75 | propObj->prop[j] = bv_variable_cast(castType, bv_variable_create_float(0.0f)); |
| 76 | } |
| 77 | else |
| 78 | DefaultConstructor(prog, propObj); |
| 79 | } |
| 80 | } |
| 81 | // scalar |
| 82 | else { |
| 83 | bv_type castType = sd::GetVariableTypeFromName(propData.Type.c_str()); |
| 84 | if (castType == bv_type_void) castType = bv_type_float; |
| 85 |
nothing calls this directly
no test coverage detected