style cleanup
This commit is contained in:
@@ -37,7 +37,7 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* RenderServices implementation */
|
||||
|
||||
#define TO_MATRIX44(m) (*(OSL::Matrix44*)&(m))
|
||||
#define TO_MATRIX44(m) (*(OSL::Matrix44 *)&(m))
|
||||
|
||||
/* static ustrings */
|
||||
ustring OSLRenderServices::u_distance("distance");
|
||||
@@ -66,12 +66,12 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr
|
||||
{
|
||||
/* this is only used for shader and object space, we don't really have
|
||||
a concept of shader space, so we just use object space for both. */
|
||||
if(xform) {
|
||||
if (xform) {
|
||||
KernelGlobals *kg = kernel_globals;
|
||||
const ShaderData *sd = (const ShaderData*)xform;
|
||||
const ShaderData *sd = (const ShaderData *)xform;
|
||||
int object = sd->object;
|
||||
|
||||
if(object != ~0) {
|
||||
if (object != ~0) {
|
||||
Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
|
||||
tfm = transform_transpose(tfm);
|
||||
result = TO_MATRIX44(tfm);
|
||||
@@ -87,12 +87,12 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, OSL::Transform
|
||||
{
|
||||
/* this is only used for shader and object space, we don't really have
|
||||
a concept of shader space, so we just use object space for both. */
|
||||
if(xform) {
|
||||
if (xform) {
|
||||
KernelGlobals *kg = kernel_globals;
|
||||
const ShaderData *sd = (const ShaderData*)xform;
|
||||
const ShaderData *sd = (const ShaderData *)xform;
|
||||
int object = sd->object;
|
||||
|
||||
if(object != ~0) {
|
||||
if (object != ~0) {
|
||||
Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
|
||||
tfm = transform_transpose(tfm);
|
||||
result = TO_MATRIX44(tfm);
|
||||
@@ -108,22 +108,22 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from, float ti
|
||||
{
|
||||
KernelGlobals *kg = kernel_globals;
|
||||
|
||||
if(from == u_ndc) {
|
||||
if (from == u_ndc) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.ndctoworld);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(from == u_raster) {
|
||||
else if (from == u_raster) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.rastertoworld);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(from == u_screen) {
|
||||
else if (from == u_screen) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.screentoworld);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(from == u_camera) {
|
||||
else if (from == u_camera) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.cameratoworld);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
@@ -136,22 +136,22 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl
|
||||
{
|
||||
KernelGlobals *kg = kernel_globals;
|
||||
|
||||
if(to == u_ndc) {
|
||||
if (to == u_ndc) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.worldtondc);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(to == u_raster) {
|
||||
else if (to == u_raster) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.worldtoraster);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(to == u_screen) {
|
||||
else if (to == u_screen) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.worldtoscreen);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
}
|
||||
else if(to == u_camera) {
|
||||
else if (to == u_camera) {
|
||||
Transform tfm = transform_transpose(kernel_data.cam.worldtocamera);
|
||||
result = TO_MATRIX44(tfm);
|
||||
return true;
|
||||
@@ -161,56 +161,57 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl
|
||||
}
|
||||
|
||||
bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives,
|
||||
ustring object, TypeDesc type, ustring name,
|
||||
int index, void *val)
|
||||
ustring object, TypeDesc type, ustring name,
|
||||
int index, void *val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd,
|
||||
const OSLGlobals::Attribute& attr, bool derivatives, void *val)
|
||||
const OSLGlobals::Attribute& attr, bool derivatives, void *val)
|
||||
{
|
||||
if(attr.type == TypeDesc::TypeFloat) {
|
||||
float *fval = (float*)val;
|
||||
if (attr.type == TypeDesc::TypeFloat) {
|
||||
float *fval = (float *)val;
|
||||
fval[0] = triangle_attribute_float(kg, sd, attr.elem, attr.offset,
|
||||
(derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
|
||||
(derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
||||
}
|
||||
else {
|
||||
/* todo: this won't work when float3 has w component */
|
||||
float3 *fval = (float3*)val;
|
||||
float3 *fval = (float3 *)val;
|
||||
fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset,
|
||||
(derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
|
||||
(derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool get_mesh_attribute_convert(KernelGlobals *kg, const ShaderData *sd,
|
||||
const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val)
|
||||
const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val)
|
||||
{
|
||||
if(attr.type == TypeDesc::TypeFloat) {
|
||||
if (attr.type == TypeDesc::TypeFloat) {
|
||||
float tmp[3];
|
||||
float3 *fval = (float3*)val;
|
||||
float3 *fval = (float3 *)val;
|
||||
|
||||
get_mesh_attribute(kg, sd, attr, derivatives, tmp);
|
||||
|
||||
fval[0] = make_float3(tmp[0], tmp[0], tmp[0]);
|
||||
if(derivatives) {
|
||||
if (derivatives) {
|
||||
fval[1] = make_float3(tmp[1], tmp[1], tmp[1]);
|
||||
fval[2] = make_float3(tmp[2], tmp[2], tmp[2]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
|
||||
attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
|
||||
else if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
|
||||
attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor)
|
||||
{
|
||||
float3 tmp[3];
|
||||
float *fval = (float*)val;
|
||||
float *fval = (float *)val;
|
||||
|
||||
get_mesh_attribute(kg, sd, attr, derivatives, tmp);
|
||||
|
||||
fval[0] = average(tmp[0]);
|
||||
if(derivatives) {
|
||||
if (derivatives) {
|
||||
fval[1] = average(tmp[1]);
|
||||
fval[2] = average(tmp[2]);
|
||||
}
|
||||
@@ -226,29 +227,29 @@ static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivat
|
||||
size_t datasize = attr.value.datasize();
|
||||
|
||||
memcpy(val, attr.value.data(), datasize);
|
||||
if(derivatives)
|
||||
memset((char*)val + datasize, 0, datasize*2);
|
||||
if (derivatives)
|
||||
memset((char *)val + datasize, 0, datasize * 2);
|
||||
}
|
||||
|
||||
bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name,
|
||||
TypeDesc type, ustring name, void *val)
|
||||
TypeDesc type, ustring name, void *val)
|
||||
{
|
||||
KernelGlobals *kg = kernel_globals;
|
||||
const ShaderData *sd = (const ShaderData*)renderstate;
|
||||
const ShaderData *sd = (const ShaderData *)renderstate;
|
||||
int object = sd->object;
|
||||
int tri = sd->prim;
|
||||
|
||||
/* lookup of attribute on another object */
|
||||
if(object_name != u_empty) {
|
||||
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())
|
||||
if (it == kg->osl.object_name_map.end())
|
||||
return false;
|
||||
|
||||
object = it->second;
|
||||
tri = ~0;
|
||||
}
|
||||
else if(object == ~0) {
|
||||
else if (object == ~0) {
|
||||
/* no background attributes supported */
|
||||
return false;
|
||||
}
|
||||
@@ -257,20 +258,23 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri
|
||||
OSLGlobals::AttributeMap& attribute_map = kg->osl.attribute_map[object];
|
||||
OSLGlobals::AttributeMap::iterator it = attribute_map.find(name);
|
||||
|
||||
if(it == attribute_map.end())
|
||||
if (it == attribute_map.end())
|
||||
return false;
|
||||
|
||||
/* type mistmatch? */
|
||||
const OSLGlobals::Attribute& attr = it->second;
|
||||
|
||||
if(attr.elem != ATTR_ELEMENT_VALUE) {
|
||||
if (attr.elem != ATTR_ELEMENT_VALUE) {
|
||||
/* triangle and vertex attributes */
|
||||
if(tri != ~0) {
|
||||
if(attr.type == type || (attr.type == TypeDesc::TypeColor &&
|
||||
(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal)))
|
||||
if (tri != ~0) {
|
||||
if (attr.type == type || (attr.type == TypeDesc::TypeColor &&
|
||||
(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal)))
|
||||
{
|
||||
return get_mesh_attribute(kg, sd, attr, derivatives, val);
|
||||
else
|
||||
}
|
||||
else {
|
||||
return get_mesh_attribute_convert(kg, sd, attr, type, derivatives, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -283,7 +287,7 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri
|
||||
}
|
||||
|
||||
bool OSLRenderServices::get_userdata(bool derivatives, ustring name, TypeDesc type,
|
||||
void *renderstate, void *val)
|
||||
void *renderstate, void *val)
|
||||
{
|
||||
return false; /* disabled by lockgeom */
|
||||
}
|
||||
@@ -294,7 +298,7 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst
|
||||
}
|
||||
|
||||
void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names,
|
||||
TypeDesc *attr_types, int nattrs)
|
||||
TypeDesc *attr_types, int nattrs)
|
||||
{
|
||||
#ifdef WITH_PARTIO
|
||||
m_attr_queries.push_back(AttrQuery());
|
||||
@@ -308,28 +312,32 @@ void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names,
|
||||
to the query. Just to prevent buffer overruns */
|
||||
query.capacity = -1;
|
||||
|
||||
for(int i = 0; i < nattrs; ++i)
|
||||
{
|
||||
for (int i = 0; i < nattrs; ++i) {
|
||||
query.attr_names[i] = attr_names[i];
|
||||
|
||||
TypeDesc element_type = attr_types[i].elementtype ();
|
||||
TypeDesc element_type = attr_types[i].elementtype();
|
||||
|
||||
if(query.capacity < 0)
|
||||
query.capacity = attr_types[i].numelements();
|
||||
if (query.capacity < 0)
|
||||
query.capacity = attr_types[i].numelements();
|
||||
else
|
||||
query.capacity = min(query.capacity, (int)attr_types[i].numelements());
|
||||
query.capacity = min(query.capacity, (int)attr_types[i].numelements());
|
||||
|
||||
/* convert the OSL (OIIO) type to the equivalent Partio type so
|
||||
we can do a fast check at query time. */
|
||||
if(element_type == TypeDesc::TypeFloat)
|
||||
query.attr_partio_types[i] = Partio::FLOAT;
|
||||
else if(element_type == TypeDesc::TypeInt)
|
||||
query.attr_partio_types[i] = Partio::INT;
|
||||
else if(element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint ||
|
||||
element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal)
|
||||
query.attr_partio_types[i] = Partio::VECTOR;
|
||||
else
|
||||
return NULL; /* report some error of unknown type */
|
||||
if (element_type == TypeDesc::TypeFloat) {
|
||||
query.attr_partio_types[i] = Partio::FLOAT;
|
||||
}
|
||||
else if (element_type == TypeDesc::TypeInt) {
|
||||
query.attr_partio_types[i] = Partio::INT;
|
||||
}
|
||||
else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint ||
|
||||
element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal)
|
||||
{
|
||||
query.attr_partio_types[i] = Partio::VECTOR;
|
||||
}
|
||||
else {
|
||||
return NULL; /* report some error of unknown type */
|
||||
}
|
||||
}
|
||||
|
||||
/* this is valid until the end of RenderServices */
|
||||
@@ -348,18 +356,18 @@ Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename)
|
||||
#endif
|
||||
|
||||
int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, float radius,
|
||||
int max_points, void *_attr_query, void **attr_outdata)
|
||||
int max_points, void *_attr_query, void **attr_outdata)
|
||||
{
|
||||
/* todo: this code has never been tested, and most likely does not
|
||||
work. it's based on the example code in OSL */
|
||||
|
||||
#ifdef WITH_PARTIO
|
||||
/* query Partio for this pointcloud lookup using cached attr_query */
|
||||
if(!_attr_query)
|
||||
if (!_attr_query)
|
||||
return 0;
|
||||
|
||||
AttrQuery *attr_query = (AttrQuery *)_attr_query;
|
||||
if(attr_query->capacity < max_points)
|
||||
if (attr_query->capacity < max_points)
|
||||
return 0;
|
||||
|
||||
/* get the pointcloud entry for the given filename */
|
||||
@@ -370,13 +378,13 @@ int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, flo
|
||||
int nattrs = attr_query->attr_names.size();
|
||||
Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs);
|
||||
|
||||
for(int i = 0; i < nattrs; ++i) {
|
||||
for (int i = 0; i < nattrs; ++i) {
|
||||
/* special case attributes */
|
||||
if(attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index)
|
||||
if (attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index)
|
||||
continue;
|
||||
|
||||
/* lookup the attribute by name*/
|
||||
if(!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) {
|
||||
if (!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) {
|
||||
/* issue an error here and return, types don't match */
|
||||
Partio::endCachedAccess(cloud);
|
||||
cloud->release();
|
||||
@@ -394,14 +402,14 @@ int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 ¢er, flo
|
||||
int count = indices.size();
|
||||
|
||||
/* retrieve the attributes directly to user space */
|
||||
for(int j = 0; j < nattrs; ++j) {
|
||||
for (int j = 0; j < nattrs; ++j) {
|
||||
/* special cases */
|
||||
if(attr_query->attr_names[j] == u_distance) {
|
||||
for(int i = 0; i < count; ++i)
|
||||
if (attr_query->attr_names[j] == u_distance) {
|
||||
for (int i = 0; i < count; ++i)
|
||||
((float *)attr_outdata[j])[i] = sqrtf(dist2[i]);
|
||||
}
|
||||
else if(attr_query->attr_names[j] == u_index) {
|
||||
for(int i = 0; i < count; ++i)
|
||||
else if (attr_query->attr_names[j] == u_index) {
|
||||
for (int i = 0; i < count; ++i)
|
||||
((int *)attr_outdata[j])[i] = indices[i];
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user