ClangFormat: apply to source, most of intern
[blender.git] / intern / cycles / kernel / osl / osl_services.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __OSL_SERVICES_H__
18 #define __OSL_SERVICES_H__
19
20 /* OSL Render Services
21  *
22  * Implementation of OSL render services, to retriever matrices, attributes,
23  * textures and point clouds. In principle this should only be accessing
24  * kernel data, but currently we also reach back into the Scene to retrieve
25  * attributes.
26  */
27
28 #include <OSL/oslexec.h>
29 #include <OSL/oslclosure.h>
30
31 #ifdef WITH_PTEX
32 class PtexCache;
33 #endif
34
35 CCL_NAMESPACE_BEGIN
36
37 class Object;
38 class Scene;
39 class Shader;
40 struct ShaderData;
41 struct float3;
42 struct KernelGlobals;
43 class OSLRenderServices : public OSL::RendererServices {
44  public:
45   OSLRenderServices();
46   ~OSLRenderServices();
47
48   void thread_init(KernelGlobals *kernel_globals, OSL::TextureSystem *ts);
49
50   bool get_matrix(OSL::ShaderGlobals *sg,
51                   OSL::Matrix44 &result,
52                   OSL::TransformationPtr xform,
53                   float time) override;
54   bool get_inverse_matrix(OSL::ShaderGlobals *sg,
55                           OSL::Matrix44 &result,
56                           OSL::TransformationPtr xform,
57                           float time) override;
58
59   bool get_matrix(OSL::ShaderGlobals *sg,
60                   OSL::Matrix44 &result,
61                   ustring from,
62                   float time) override;
63   bool get_inverse_matrix(OSL::ShaderGlobals *sg,
64                           OSL::Matrix44 &result,
65                           ustring to,
66                           float time) override;
67
68   bool get_matrix(OSL::ShaderGlobals *sg,
69                   OSL::Matrix44 &result,
70                   OSL::TransformationPtr xform) override;
71   bool get_inverse_matrix(OSL::ShaderGlobals *sg,
72                           OSL::Matrix44 &result,
73                           OSL::TransformationPtr xform) override;
74
75   bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from) override;
76   bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from) override;
77
78   bool get_array_attribute(OSL::ShaderGlobals *sg,
79                            bool derivatives,
80                            ustring object,
81                            TypeDesc type,
82                            ustring name,
83                            int index,
84                            void *val) override;
85   bool get_attribute(OSL::ShaderGlobals *sg,
86                      bool derivatives,
87                      ustring object,
88                      TypeDesc type,
89                      ustring name,
90                      void *val) override;
91   bool get_attribute(ShaderData *sd,
92                      bool derivatives,
93                      ustring object_name,
94                      TypeDesc type,
95                      ustring name,
96                      void *val);
97
98   bool get_userdata(
99       bool derivatives, ustring name, TypeDesc type, OSL::ShaderGlobals *sg, void *val) override;
100
101   int pointcloud_search(OSL::ShaderGlobals *sg,
102                         ustring filename,
103                         const OSL::Vec3 &center,
104                         float radius,
105                         int max_points,
106                         bool sort,
107                         size_t *out_indices,
108                         float *out_distances,
109                         int derivs_offset) override;
110
111   int pointcloud_get(OSL::ShaderGlobals *sg,
112                      ustring filename,
113                      size_t *indices,
114                      int count,
115                      ustring attr_name,
116                      TypeDesc attr_type,
117                      void *out_data) override;
118
119   bool pointcloud_write(OSL::ShaderGlobals *sg,
120                         ustring filename,
121                         const OSL::Vec3 &pos,
122                         int nattribs,
123                         const ustring *names,
124                         const TypeDesc *types,
125                         const void **data) override;
126
127   bool trace(TraceOpt &options,
128              OSL::ShaderGlobals *sg,
129              const OSL::Vec3 &P,
130              const OSL::Vec3 &dPdx,
131              const OSL::Vec3 &dPdy,
132              const OSL::Vec3 &R,
133              const OSL::Vec3 &dRdx,
134              const OSL::Vec3 &dRdy) override;
135
136   bool getmessage(OSL::ShaderGlobals *sg,
137                   ustring source,
138                   ustring name,
139                   TypeDesc type,
140                   void *val,
141                   bool derivatives) override;
142
143   TextureSystem::TextureHandle *get_texture_handle(ustring filename) override;
144
145   bool good(TextureSystem::TextureHandle *texture_handle) override;
146
147   bool texture(ustring filename,
148                TextureSystem::TextureHandle *texture_handle,
149                TexturePerthread *texture_thread_info,
150                TextureOpt &options,
151                OSL::ShaderGlobals *sg,
152                float s,
153                float t,
154                float dsdx,
155                float dtdx,
156                float dsdy,
157                float dtdy,
158                int nchannels,
159                float *result,
160                float *dresultds,
161                float *dresultdt,
162                ustring *errormessage) override;
163
164   bool texture3d(ustring filename,
165                  TextureHandle *texture_handle,
166                  TexturePerthread *texture_thread_info,
167                  TextureOpt &options,
168                  OSL::ShaderGlobals *sg,
169                  const OSL::Vec3 &P,
170                  const OSL::Vec3 &dPdx,
171                  const OSL::Vec3 &dPdy,
172                  const OSL::Vec3 &dPdz,
173                  int nchannels,
174                  float *result,
175                  float *dresultds,
176                  float *dresultdt,
177                  float *dresultdr,
178                  ustring *errormessage) override;
179
180   bool environment(ustring filename,
181                    TextureHandle *texture_handle,
182                    TexturePerthread *texture_thread_info,
183                    TextureOpt &options,
184                    OSL::ShaderGlobals *sg,
185                    const OSL::Vec3 &R,
186                    const OSL::Vec3 &dRdx,
187                    const OSL::Vec3 &dRdy,
188                    int nchannels,
189                    float *result,
190                    float *dresultds,
191                    float *dresultdt,
192                    ustring *errormessage) override;
193
194   bool get_texture_info(OSL::ShaderGlobals *sg,
195                         ustring filename,
196                         TextureHandle *texture_handle,
197                         int subimage,
198                         ustring dataname,
199                         TypeDesc datatype,
200                         void *data) override;
201
202   static bool get_background_attribute(
203       KernelGlobals *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val);
204   static bool get_object_standard_attribute(
205       KernelGlobals *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val);
206
207   static ustring u_distance;
208   static ustring u_index;
209   static ustring u_world;
210   static ustring u_camera;
211   static ustring u_screen;
212   static ustring u_raster;
213   static ustring u_ndc;
214   static ustring u_object_location;
215   static ustring u_object_index;
216   static ustring u_geom_dupli_generated;
217   static ustring u_geom_dupli_uv;
218   static ustring u_material_index;
219   static ustring u_object_random;
220   static ustring u_particle_index;
221   static ustring u_particle_random;
222   static ustring u_particle_age;
223   static ustring u_particle_lifetime;
224   static ustring u_particle_location;
225   static ustring u_particle_rotation;
226   static ustring u_particle_size;
227   static ustring u_particle_velocity;
228   static ustring u_particle_angular_velocity;
229   static ustring u_geom_numpolyvertices;
230   static ustring u_geom_trianglevertices;
231   static ustring u_geom_polyvertices;
232   static ustring u_geom_name;
233   static ustring u_geom_undisplaced;
234   static ustring u_is_smooth;
235   static ustring u_is_curve;
236   static ustring u_curve_thickness;
237   static ustring u_curve_tangent_normal;
238   static ustring u_curve_random;
239   static ustring u_path_ray_length;
240   static ustring u_path_ray_depth;
241   static ustring u_path_diffuse_depth;
242   static ustring u_path_glossy_depth;
243   static ustring u_path_transparent_depth;
244   static ustring u_path_transmission_depth;
245   static ustring u_trace;
246   static ustring u_hit;
247   static ustring u_hitdist;
248   static ustring u_N;
249   static ustring u_Ng;
250   static ustring u_P;
251   static ustring u_I;
252   static ustring u_u;
253   static ustring u_v;
254   static ustring u_empty;
255   static ustring u_at_bevel;
256   static ustring u_at_ao;
257
258  private:
259   KernelGlobals *kernel_globals;
260   OSL::TextureSystem *osl_ts;
261 #ifdef WITH_PTEX
262   PtexCache *ptex_cache;
263 #endif
264 };
265
266 CCL_NAMESPACE_END
267
268 #endif /* __OSL_SERVICES_H__  */