[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50311] trunk/blender/intern/cycles/kernel /osl: Cycles / OSL:

Thomas Dinges blender at dingto.org
Sun Sep 2 03:10:33 CEST 2012


Revision: 50311
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50311
Author:   dingto
Date:     2012-09-02 01:10:31 +0000 (Sun, 02 Sep 2012)
Log Message:
-----------
Cycles / OSL:
Fixes for API changes in OSL RendererServices:

* Added two new required get_matrix methods, from OSL RendererServices (otherwise the constructor fails). The two new matrix methods probably still need an implementation. 
* Removed deprecated "get_pointcloud_attr_query" and "pointcloud". There are two new routines for pointclouds, function headers for those are there.

* Removed the (unused) PARTIO code parts from OSL. It was marked as not tested / not working, and due to the api changes here broken for sure. Code is still in svn history if needed. 

Modified Paths:
--------------
    trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
    trunk/blender/intern/cycles/kernel/osl/osl_services.h

Modified: trunk/blender/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_services.cpp	2012-09-01 21:23:05 UTC (rev 50310)
+++ trunk/blender/intern/cycles/kernel/osl/osl_services.cpp	2012-09-02 01:10:31 UTC (rev 50311)
@@ -160,6 +160,18 @@
 	return false;
 }
 
+bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform)
+{
+	// XXX implementation
+	return true;
+}
+
+bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from)
+{
+	// XXX implementation
+	return true;
+}
+
 bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives, 
                                             ustring object, TypeDesc type, ustring name,
                                             int index, void *val)
@@ -297,137 +309,16 @@
 	return false; /* never called by OSL */
 }
 
-void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names,
-                                                   TypeDesc *attr_types, int nattrs)
+int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &center,
+		float radius, int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset)
 {
-#ifdef WITH_PARTIO
-	m_attr_queries.push_back(AttrQuery());
-	AttrQuery &query = m_attr_queries.back();
-
-	/* make space for what we need. the only reason to use
-	 * std::vector is to skip the delete */
-	query.attr_names.resize(nattrs);
-	query.attr_partio_types.resize(nattrs);
-	/* capacity will keep the length of the smallest array passed
-	 * to the query. Just to prevent buffer overruns */
-	query.capacity = -1;
-
-	for (int i = 0; i < nattrs; ++i) {
-		query.attr_names[i] = attr_names[i];
-
-		TypeDesc element_type = attr_types[i].elementtype();
-
-		if (query.capacity < 0)
-			query.capacity = attr_types[i].numelements();
-		else
-			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 */
-		}
-	}
-
-	/* this is valid until the end of RenderServices */
-	return &query;
-#else
-	return NULL;
-#endif
+    return 0;
 }
 
-#ifdef WITH_PARTIO
-Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename)
+int OSLRenderServices::pointcloud_get(ustring filename, size_t *indices, int count,
+		ustring attr_name, TypeDesc attr_type, void *out_data)
 {
-	return Partio::readCached(filename.c_str(), true);
+    return 0;
 }
 
-#endif
-
-int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 &center, float radius,
-                                  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)
-		return 0;
-
-	AttrQuery *attr_query = (AttrQuery *)_attr_query;
-	if (attr_query->capacity < max_points)
-		return 0;
-
-	/* get the pointcloud entry for the given filename */
-	Partio::ParticlesData *cloud = get_pointcloud(filename);
-
-	/* now we have to look up all the attributes in the file. we can't do this
-	 * before hand cause we never know what we are going to load. */
-	int nattrs = attr_query->attr_names.size();
-	Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs);
-
-	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)
-			continue;
-
-		/* lookup the attribute by name*/
-		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();
-			return 0;
-		}
-	}
-
-	std::vector<Partio::ParticleIndex> indices;
-	std::vector<float> dist2;
-
-	Partio::beginCachedAccess(cloud);
-
-	/* finally, do the lookup */
-	cloud->findNPoints((const float *)&center, max_points, radius, indices, dist2);
-	int count = indices.size();
-
-	/* retrieve the attributes directly to user space */
-	for (int j = 0; j < nattrs; ++j) {
-		/* special cases */
-		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)
-				((int *)attr_outdata[j])[i] = indices[i];
-		}
-		else {
-			/* note we make a single call per attribute, we don't loop over the
-			 * points. Partio does it, so it is there that we have to care about
-			 * performance */
-			cloud->data(attr[j], count, &indices[0], true, attr_outdata[j]);
-		}
-	}
-
-	Partio::endCachedAccess(cloud);
-	cloud->release();
-
-	return count;
-#else
-	return 0;
-#endif
-}
-
 CCL_NAMESPACE_END
-

Modified: trunk/blender/intern/cycles/kernel/osl/osl_services.h
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/osl_services.h	2012-09-01 21:23:05 UTC (rev 50310)
+++ trunk/blender/intern/cycles/kernel/osl/osl_services.h	2012-09-02 01:10:31 UTC (rev 50311)
@@ -30,10 +30,6 @@
 #include <OSL/oslexec.h>
 #include <OSL/oslclosure.h>
 
-#ifdef WITH_PARTIO
-#include <Partio.h>
-#endif
-
 CCL_NAMESPACE_BEGIN
 
 class Object;
@@ -53,8 +49,12 @@
 
 	bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
 	bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
+	
 	bool get_matrix(OSL::Matrix44 &result, ustring from, float time);
 	bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time);
+	
+	bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform);
+	bool get_matrix(OSL::Matrix44 &result, ustring from);
 
 	bool get_array_attribute(void *renderstate, bool derivatives, 
 	                         ustring object, TypeDesc type, ustring name,
@@ -68,33 +68,17 @@
 
 	void *get_pointcloud_attr_query(ustring *attr_names,
 	                                TypeDesc *attr_types, int nattrs);
-	int pointcloud(ustring filename, const OSL::Vec3 &center, float radius,
-	               int max_points, void *attr_query, void **attr_outdata);
+				   
+	int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &center,
+						float radius, int max_points, bool sort, size_t *out_indices,
+						float *out_distances, int derivs_offset);
 
+	int pointcloud_get(ustring filename, size_t *indices, int count, ustring attr_name,
+						TypeDesc attr_type, void *out_data);
+
 private:
 	KernelGlobals *kernel_globals;
 
-#ifdef WITH_PARTIO
-	/* OSL gets pointers to this but its definition is private.
-	 * right now it only caches the types already converted to
-	 * Partio constants. this is what get_pointcloud_attr_query
-	 * returns */
-	struct AttrQuery {
-		/* names of the attributes to query */
-		std::vector<ustring> attr_names;
-		/* types as (enum Partio::ParticleAttributeType) of the
-		 * attributes in the query */
-		std::vector<int> attr_partio_types;
-		/* for sanity checks, capacity of the output arrays */
-		int capacity;
-	};
-
-	Partio::ParticlesData *get_pointcloud(ustring filename);
-
-	/* keep a list so adding elements doesn't invalidate pointers */
-	std::list<AttrQuery> m_attr_queries;
-#endif
-
 	static ustring u_distance;
 	static ustring u_index;
 	static ustring u_camera;




More information about the Bf-blender-cvs mailing list