Fix for Cycles OSL: The RenderServices pointer in ShadingSystem is no longer accessib...
[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 class OSLRenderServices;
34
35 struct OSLGlobals {
36         /* use */
37         bool use;
38
39         /* shading system */ 
40         OSL::ShadingSystem *ss;
41         OSLRenderServices *services;
42
43         /* shader states */
44         vector<OSL::ShadingAttribStateRef> surface_state;
45         vector<OSL::ShadingAttribStateRef> volume_state;
46         vector<OSL::ShadingAttribStateRef> displacement_state;
47         OSL::ShadingAttribStateRef background_state;
48
49         /* attributes */
50         struct Attribute {
51                 TypeDesc type;
52                 AttributeElement elem;
53                 int offset;
54                 ParamValue value;
55         };
56
57         typedef unordered_map<ustring, Attribute, ustringHash> AttributeMap;
58         typedef unordered_map<ustring, int, ustringHash> ObjectNameMap;
59
60         vector<AttributeMap> attribute_map;
61         ObjectNameMap object_name_map;
62
63         /* thread key for thread specific data lookup */
64         struct ThreadData {
65                 OSL::ShaderGlobals globals;
66                 OSL::PerThreadInfo *thread_info;
67         };
68
69         static tls_ptr(ThreadData, thread_data);
70 };
71
72 CCL_NAMESPACE_END
73
74 #endif
75
76 #endif /* __OSL_GLOBALS_H__ */
77