Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / intern / cycles / kernel / osl / osl_globals.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifndef __OSL_GLOBALS_H__
20 #define __OSL_GLOBALS_H__
21
22 #ifdef WITH_OSL
23
24 #include <OSL/oslexec.h>
25
26 #include "util_map.h"
27 #include "util_param.h"
28 #include "util_thread.h"
29 #include "util_vector.h"
30
31 CCL_NAMESPACE_BEGIN
32
33 struct OSLGlobals {
34         /* use */
35         bool use;
36
37         /* shading system */ 
38         OSL::ShadingSystem *ss;
39
40         /* shader states */
41         vector<OSL::ShadingAttribStateRef> surface_state;
42         vector<OSL::ShadingAttribStateRef> volume_state;
43         vector<OSL::ShadingAttribStateRef> displacement_state;
44         OSL::ShadingAttribStateRef background_state;
45
46         /* attributes */
47         struct Attribute {
48                 TypeDesc type;
49                 AttributeElement elem;
50                 int offset;
51                 ParamValue value;
52         };
53
54         typedef unordered_map<ustring, Attribute, ustringHash> AttributeMap;
55         typedef unordered_map<ustring, int, ustringHash> ObjectNameMap;
56
57         vector<AttributeMap> attribute_map;
58         ObjectNameMap object_name_map;
59
60         /* thread key for thread specific data lookup */
61         struct ThreadData {
62                 OSL::ShaderGlobals globals;
63                 void *thread_info;
64         };
65
66         static tls_ptr(ThreadData, thread_data);
67 };
68
69 CCL_NAMESPACE_END
70
71 #endif
72
73 #endif /* __OSL_GLOBALS_H__ */
74