Blender V5.0
attribute_convert.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "util/color.h"
8#include "util/param.h"
9#include "util/types.h"
10
11#include "BLI_color.hh"
14
16
17template<typename BlenderT> struct AttributeConverter {
18 using CyclesT = void;
19};
20
21template<> struct AttributeConverter<float> {
22 using CyclesT = float;
23 static constexpr auto type_desc = TypeFloat;
24 static CyclesT convert(const float &value)
25 {
26 return value;
27 }
28};
29template<> struct AttributeConverter<int> {
30 using CyclesT = float;
31 static constexpr auto type_desc = TypeFloat;
32 static CyclesT convert(const int &value)
33 {
34 return float(value);
35 }
36};
37template<> struct AttributeConverter<blender::float2> {
38 using CyclesT = float2;
39 static constexpr auto type_desc = TypeFloat2;
40 static CyclesT convert(const blender::float2 &value)
41 {
42 return make_float2(value[0], value[1]);
43 }
44};
45template<> struct AttributeConverter<blender::float3> {
46 using CyclesT = float3;
47 static constexpr auto type_desc = TypeVector;
48 static CyclesT convert(const blender::float3 &value)
49 {
50 return make_float3(value[0], value[1], value[2]);
51 }
52};
54 using CyclesT = float4;
55 static constexpr auto type_desc = TypeRGBA;
57 {
58 return make_float4(value[0], value[1], value[2], value[3]);
59 }
60};
61template<> struct AttributeConverter<blender::ColorGeometry4b> {
62 using CyclesT = float4;
63 static constexpr auto type_desc = TypeRGBA;
65 {
67 byte_to_float(value[1]),
68 byte_to_float(value[2]),
69 byte_to_float(value[3])));
70 }
71};
72template<> struct AttributeConverter<bool> {
73 using CyclesT = float;
74 static constexpr auto type_desc = TypeFloat;
75 static CyclesT convert(const bool &value)
76 {
77 return float(value);
78 }
79};
80template<> struct AttributeConverter<int8_t> {
81 using CyclesT = float;
82 static constexpr auto type_desc = TypeFloat;
83 static CyclesT convert(const int8_t &value)
84 {
85 return float(value);
86 }
87};
89 using CyclesT = float4;
90 static constexpr auto type_desc = TypeFloat4;
92 {
93 return make_float4(value.w, value.x, value.y, value.z);
94 }
95};
96
nullptr float
ccl_device float byte_to_float(const uchar val)
Definition color.h:19
ccl_device float4 color_srgb_to_linear_v4(const float4 c)
Definition color.h:347
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
QuaternionBase< float > Quaternion
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR)
#define make_float2
#define make_float4
static CyclesT convert(const blender::ColorGeometry4b &value)
static CyclesT convert(const blender::ColorGeometry4f &value)
static CyclesT convert(const blender::float2 &value)
static CyclesT convert(const blender::float3 &value)
static CyclesT convert(const blender::math::Quaternion &value)
static constexpr auto type_desc
static CyclesT convert(const bool &value)
static CyclesT convert(const float &value)
static constexpr auto type_desc
static CyclesT convert(const int8_t &value)
static constexpr auto type_desc
static constexpr auto type_desc
static CyclesT convert(const int &value)