Code refactor: use KernelOject struct instead of float4 array.
Original patch by Stefan with modifications by Brecht.
This commit is contained in:

committed by
Brecht Van Lommel

parent
41b38c5f75
commit
f66ff4ee86
@@ -289,7 +289,7 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
|
||||
Object *ob,
|
||||
int object_index)
|
||||
{
|
||||
float4 *objects = state->objects;
|
||||
KernelObject& kobject = state->objects[object_index];
|
||||
float4 *objects_vector = state->objects_vector;
|
||||
|
||||
Mesh *mesh = ob->mesh;
|
||||
@@ -357,15 +357,15 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
|
||||
}
|
||||
}
|
||||
|
||||
/* Pack in texture. */
|
||||
int offset = object_index*OBJECT_SIZE;
|
||||
|
||||
/* OBJECT_TRANSFORM */
|
||||
memcpy(&objects[offset], &tfm, sizeof(float4)*3);
|
||||
memcpy(&kobject.tfm.pre, &tfm, sizeof(float4)*3);
|
||||
/* OBJECT_INVERSE_TRANSFORM */
|
||||
memcpy(&objects[offset+4], &itfm, sizeof(float4)*3);
|
||||
memcpy(&kobject.tfm.mid, &itfm, sizeof(float4)*3);
|
||||
/* OBJECT_PROPERTIES */
|
||||
objects[offset+12] = make_float4(surface_area, pass_id, random_number, __int_as_float(particle_index));
|
||||
kobject.surface_area = surface_area;
|
||||
kobject.pass_id = pass_id;
|
||||
kobject.random_number = random_number;
|
||||
kobject.particle_index = particle_index;
|
||||
|
||||
if(mesh->use_motion_blur) {
|
||||
state->have_motion = true;
|
||||
@@ -404,21 +404,24 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
|
||||
MotionTransform decomp;
|
||||
|
||||
transform_motion_decompose(&decomp, &ob->motion, &ob->tfm);
|
||||
memcpy(&objects[offset], &decomp, sizeof(float4)*12);
|
||||
kobject.tfm = decomp;
|
||||
flag |= SD_OBJECT_MOTION;
|
||||
state->have_motion = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dupli object coords and motion info. */
|
||||
kobject.dupli_generated[0] = ob->dupli_generated[0];
|
||||
kobject.dupli_generated[1] = ob->dupli_generated[1];
|
||||
kobject.dupli_generated[2] = ob->dupli_generated[2];
|
||||
kobject.numkeys = mesh->curve_keys.size();
|
||||
kobject.dupli_uv[0] = ob->dupli_uv[0];
|
||||
kobject.dupli_uv[1] = ob->dupli_uv[1];
|
||||
int totalsteps = mesh->motion_steps;
|
||||
int numsteps = (totalsteps - 1)/2;
|
||||
int numverts = mesh->verts.size();
|
||||
int numkeys = mesh->curve_keys.size();
|
||||
|
||||
objects[offset+13] = make_float4(ob->dupli_generated[0], ob->dupli_generated[1], ob->dupli_generated[2], __int_as_float(numkeys));
|
||||
objects[offset+14] = make_float4(ob->dupli_uv[0], ob->dupli_uv[1], __int_as_float(numsteps), __int_as_float(numverts));
|
||||
objects[offset+15] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
kobject.numsteps = (totalsteps - 1)/2;
|
||||
kobject.numverts = mesh->verts.size();;
|
||||
kobject.patch_map_offset = 0;
|
||||
kobject.attribute_map_offset = 0;
|
||||
|
||||
/* Object flag. */
|
||||
if(ob->use_holdout) {
|
||||
@@ -486,7 +489,7 @@ void ObjectManager::device_update_transforms(DeviceScene *dscene,
|
||||
state.queue_start_object = 0;
|
||||
|
||||
state.object_flag = object_flag;
|
||||
state.objects = dscene->objects.alloc(OBJECT_SIZE*scene->objects.size());
|
||||
state.objects = dscene->objects.alloc(scene->objects.size());
|
||||
if(state.need_motion == Scene::MOTION_PASS) {
|
||||
state.objects_vector = dscene->objects_vector.alloc(OBJECT_VECTOR_SIZE*scene->objects.size());
|
||||
}
|
||||
@@ -652,27 +655,26 @@ void ObjectManager::device_update_mesh_offsets(Device *, DeviceScene *dscene, Sc
|
||||
return;
|
||||
}
|
||||
|
||||
uint4* objects = (uint4*)dscene->objects.data();
|
||||
KernelObject *kobjects = dscene->objects.data();
|
||||
|
||||
bool update = false;
|
||||
int object_index = 0;
|
||||
|
||||
foreach(Object *object, scene->objects) {
|
||||
Mesh* mesh = object->mesh;
|
||||
int offset = object_index*OBJECT_SIZE + 15;
|
||||
|
||||
if(mesh->patch_table) {
|
||||
uint patch_map_offset = 2*(mesh->patch_table_offset + mesh->patch_table->total_size() -
|
||||
mesh->patch_table->num_nodes * PATCH_NODE_SIZE) - mesh->patch_offset;
|
||||
|
||||
if(objects[offset].x != patch_map_offset) {
|
||||
objects[offset].x = patch_map_offset;
|
||||
if(kobjects[object_index].patch_map_offset != patch_map_offset) {
|
||||
kobjects[object_index].patch_map_offset = patch_map_offset;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(objects[offset].y != mesh->attr_map_offset) {
|
||||
objects[offset].y = mesh->attr_map_offset;
|
||||
if(kobjects[object_index].attribute_map_offset != mesh->attr_map_offset) {
|
||||
kobjects[object_index].attribute_map_offset = mesh->attr_map_offset;
|
||||
update = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user