swizzle */
| 23 | |
| 24 | /* swizzle */ |
| 25 | bv_variable Swizzle(bv_program* prog, bv_object* obj, const bv_string field) |
| 26 | { |
| 27 | const char* rgba = "rgba\0"; |
| 28 | const char* xyzw = "xyzw\0"; |
| 29 | |
| 30 | char name[4][2] = { 0 }; |
| 31 | for (int j = 0; j < strlen(field); j++) |
| 32 | for (int i = 0; i < 4; i++) { |
| 33 | if (field[j] == rgba[i]) |
| 34 | name[j][0] = xyzw[i]; |
| 35 | else if (field[j] == xyzw[i]) |
| 36 | name[j][0] = xyzw[i]; |
| 37 | } |
| 38 | |
| 39 | if (strlen(field) == 1) |
| 40 | return bv_variable_create_pointer(bv_object_get_property(obj, name[0])); |
| 41 | else if (strlen(field) == 2) { |
| 42 | bv_variable ret = Common::create_vec(prog, obj->prop[0].type, 2); |
| 43 | bv_object* vec = bv_variable_get_object(ret); |
| 44 | bv_object_set_property(vec, "x", bv_variable_create_pointer(bv_object_get_property(obj, name[0]))); |
| 45 | bv_object_set_property(vec, "y", bv_variable_create_pointer(bv_object_get_property(obj, name[1]))); |
| 46 | return ret; |
| 47 | } |
| 48 | else if (strlen(field) == 3) { |
| 49 | bv_variable ret = Common::create_vec(prog, obj->prop[0].type, 3); |
| 50 | bv_object* vec = bv_variable_get_object(ret); |
| 51 | bv_object_set_property(vec, "x", bv_variable_create_pointer(bv_object_get_property(obj, name[0]))); |
| 52 | bv_object_set_property(vec, "y", bv_variable_create_pointer(bv_object_get_property(obj, name[1]))); |
| 53 | bv_object_set_property(vec, "z", bv_variable_create_pointer(bv_object_get_property(obj, name[2]))); |
| 54 | return ret; |
| 55 | } |
| 56 | else if (strlen(field) == 4) { |
| 57 | bv_variable ret = Common::create_vec(prog, obj->prop[0].type, 4); |
| 58 | bv_object* vec = bv_variable_get_object(ret); |
| 59 | bv_object_set_property(vec, "x", bv_variable_create_pointer(bv_object_get_property(obj, name[0]))); |
| 60 | bv_object_set_property(vec, "y", bv_variable_create_pointer(bv_object_get_property(obj, name[1]))); |
| 61 | bv_object_set_property(vec, "z", bv_variable_create_pointer(bv_object_get_property(obj, name[2]))); |
| 62 | bv_object_set_property(vec, "w", bv_variable_create_pointer(bv_object_get_property(obj, name[3]))); |
| 63 | return ret; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /* misc */ |
| 68 | bv_variable lib_hlsl_abort(bv_program* prog, u8 count, bv_variable* args) |
nothing calls this directly
no test coverage detected