osl_globals.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef __OSL_GLOBALS_H__
  17. #define __OSL_GLOBALS_H__
  18. #ifdef WITH_OSL
  19. # include <OSL/oslexec.h>
  20. # include <OpenImageIO/refcnt.h>
  21. # include <OpenImageIO/unordered_map_concurrent.h>
  22. # include "util/util_map.h"
  23. # include "util/util_param.h"
  24. # include "util/util_thread.h"
  25. # include "util/util_vector.h"
  26. # include "util/util_unique_ptr.h"
  27. # ifndef WIN32
  28. using std::isfinite;
  29. # endif
  30. CCL_NAMESPACE_BEGIN
  31. class OSLRenderServices;
  32. class ColorSpaceProcessor;
  33. /* OSL Globals
  34. *
  35. * Data needed by OSL render services, that is global to a rendering session.
  36. * This includes all OSL shaders, name to attribute mapping and texture handles.
  37. * */
  38. struct OSLGlobals {
  39. OSLGlobals()
  40. {
  41. ss = NULL;
  42. ts = NULL;
  43. services = NULL;
  44. use = false;
  45. }
  46. bool use;
  47. /* shading system */
  48. OSL::ShadingSystem *ss;
  49. OSL::TextureSystem *ts;
  50. OSLRenderServices *services;
  51. /* shader states */
  52. vector<OSL::ShaderGroupRef> surface_state;
  53. vector<OSL::ShaderGroupRef> volume_state;
  54. vector<OSL::ShaderGroupRef> displacement_state;
  55. vector<OSL::ShaderGroupRef> bump_state;
  56. OSL::ShaderGroupRef background_state;
  57. /* attributes */
  58. struct Attribute {
  59. TypeDesc type;
  60. AttributeDescriptor desc;
  61. ParamValue value;
  62. };
  63. typedef unordered_map<ustring, Attribute, ustringHash> AttributeMap;
  64. typedef unordered_map<ustring, int, ustringHash> ObjectNameMap;
  65. vector<AttributeMap> attribute_map;
  66. ObjectNameMap object_name_map;
  67. vector<ustring> object_names;
  68. };
  69. /* trace() call result */
  70. struct OSLTraceData {
  71. Ray ray;
  72. Intersection isect;
  73. ShaderData sd;
  74. bool setup;
  75. bool init;
  76. };
  77. /* thread key for thread specific data lookup */
  78. struct OSLThreadData {
  79. OSL::ShaderGlobals globals;
  80. OSL::PerThreadInfo *osl_thread_info;
  81. OSLTraceData tracedata;
  82. OSL::ShadingContext *context;
  83. OIIO::TextureSystem::Perthread *oiio_thread_info;
  84. };
  85. CCL_NAMESPACE_END
  86. #endif
  87. #endif /* __OSL_GLOBALS_H__ */