Blender V2.61 - r43446

osl_services.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef __OSL_SERVICES_H__
00020 #define __OSL_SERVICES_H__
00021 
00022 /* OSL Render Services
00023  *
00024  * Implementation of OSL render services, to retriever matrices, attributes,
00025  * textures and point clouds. In principle this should only be accessing
00026  * kernel data, but currently we also reach back into the Scene to retrieve
00027  * attributes.
00028  */
00029 
00030 #include <OSL/oslexec.h>
00031 #include <OSL/oslclosure.h>
00032 
00033 #ifdef WITH_PARTIO
00034 #include <Partio.h>
00035 #endif
00036 
00037 CCL_NAMESPACE_BEGIN
00038 
00039 class Object;
00040 class Scene;
00041 class Shader;
00042 class ShaderData;
00043 class float3;
00044 class KernelGlobals;
00045 
00046 class OSLRenderServices : public OSL::RendererServices
00047 {
00048 public:
00049     OSLRenderServices();
00050     ~OSLRenderServices();
00051     
00052     void thread_init(KernelGlobals *kernel_globals);
00053 
00054     bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
00055     bool get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time);
00056     bool get_matrix(OSL::Matrix44 &result, ustring from, float time);
00057     bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time);
00058 
00059     bool get_array_attribute(void *renderstate, bool derivatives, 
00060         ustring object, TypeDesc type, ustring name,
00061         int index, void *val);
00062     bool get_attribute(void *renderstate, bool derivatives, ustring object,
00063         TypeDesc type, ustring name, void *val);
00064 
00065     bool get_userdata(bool derivatives, ustring name, TypeDesc type, 
00066         void *renderstate, void *val);
00067     bool has_userdata(ustring name, TypeDesc type, void *renderstate);
00068 
00069     void *get_pointcloud_attr_query(ustring *attr_names,
00070         TypeDesc *attr_types, int nattrs);
00071     int pointcloud(ustring filename, const OSL::Vec3 &center, float radius,
00072         int max_points, void *attr_query, void **attr_outdata);
00073 
00074 private:
00075     KernelGlobals *kernel_globals;
00076 
00077 #ifdef WITH_PARTIO
00078     /* OSL gets pointers to this but its definition is private.
00079        right now it only caches the types already converted to
00080        Partio constants. this is what get_pointcloud_attr_query
00081        returns */
00082     struct AttrQuery
00083     {
00084         /* names of the attributes to query */
00085         std::vector<ustring> attr_names;
00086         /* types as (enum Partio::ParticleAttributeType) of the
00087            attributes in the query */
00088         std::vector<int> attr_partio_types;
00089         /* for sanity checks, capacity of the output arrays */
00090         int capacity;
00091     };
00092 
00093     Partio::ParticlesData *get_pointcloud(ustring filename);
00094 
00095     /* keep a list so adding elements doesn't invalidate pointers */
00096     std::list<AttrQuery> m_attr_queries;
00097 #endif
00098 
00099     static ustring u_distance;
00100     static ustring u_index;
00101     static ustring u_camera;
00102     static ustring u_screen;
00103     static ustring u_raster;
00104     static ustring u_ndc;
00105     static ustring u_empty;
00106 };
00107 
00108 CCL_NAMESPACE_END
00109 
00110 #endif /* __OSL_SERVICES_H__  */
00111