Blender V5.3
osl/globals.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include <cstdint> /* Needed before `sdlexec.h` for `int32_t` with GCC 15.1. */
6
7#include <OSL/oslexec.h>
8
10
12
13OSLThreadData::OSLThreadData(OSLGlobals *osl_globals, const int thread_index)
14 : globals(osl_globals), thread_index(thread_index)
15{
16 /* If OSL is not used, we don't need this. */
17 if (globals == nullptr || !(globals->use_shading || globals->use_camera)) {
18 return;
19 }
20
21 ss = globals->ss;
22
23 memset((void *)&shader_globals, 0, sizeof(shader_globals));
24 shader_globals.tracedata = &tracedata;
25
26 if (ss) {
27 osl_thread_info = ss->create_thread_info();
28 /* Dummy texture thread info, we don't need it. */
29 context = ss->get_context(osl_thread_info,
30 reinterpret_cast<OSL::TextureSystem::Perthread *>(1));
31 }
32}
33
34OSLThreadData::~OSLThreadData()
35{
36 if (context) {
37 ss->release_context(context);
38 }
39 if (osl_thread_info) {
40 ss->destroy_thread_info(osl_thread_info);
41 }
42}
43
44OSLThreadData::OSLThreadData(OSLThreadData &&other) noexcept
45 : globals(other.globals),
46 ss(other.ss),
47 thread_index(other.thread_index),
48 shader_globals(other.shader_globals),
49 tracedata(other.tracedata),
50 osl_thread_info(other.osl_thread_info),
51 context(other.context)
52{
53 shader_globals.tracedata = &tracedata;
54
55 memset((void *)&other.shader_globals, 0, sizeof(other.shader_globals));
56 memset((void *)&other.tracedata, 0, sizeof(other.tracedata));
57 other.thread_index = -1;
58 other.context = nullptr;
59 other.osl_thread_info = nullptr;
60}
61
#define CCL_NAMESPACE_END
int context(const bContext *C, const char *member, bContextDataResult *result)