Blender V5.0
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 context = ss->get_context(osl_thread_info);
29 }
30 if (globals->ts) {
31 oiio_thread_info = globals->ts->get_perthread_info();
32 }
33}
34
35OSLThreadData::~OSLThreadData()
36{
37 if (context) {
38 ss->release_context(context);
39 }
40 if (osl_thread_info) {
41 ss->destroy_thread_info(osl_thread_info);
42 }
43}
44
45OSLThreadData::OSLThreadData(OSLThreadData &&other) noexcept
46 : globals(other.globals),
47 ss(other.ss),
48 thread_index(other.thread_index),
49 shader_globals(other.shader_globals),
50 tracedata(other.tracedata),
51 osl_thread_info(other.osl_thread_info),
52 context(other.context),
53 oiio_thread_info(other.oiio_thread_info)
54{
55 shader_globals.tracedata = &tracedata;
56
57 memset((void *)&other.shader_globals, 0, sizeof(other.shader_globals));
58 memset((void *)&other.tracedata, 0, sizeof(other.tracedata));
59 other.thread_index = -1;
60 other.context = nullptr;
61 other.osl_thread_info = nullptr;
62 other.oiio_thread_info = nullptr;
63}
64
#define CCL_NAMESPACE_END
int context(const bContext *C, const char *member, bContextDataResult *result)