Blender
V5.0
source
blender
gpu
GPU_attribute_convert.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2025 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
7
#include <algorithm>
8
#include <limits>
9
10
#include "
BLI_math_vector_types.hh
"
11
#include "
BLI_span.hh
"
12
13
namespace
blender::gpu
{
14
15
struct
PackedNormal
{
16
int
x
: 10;
17
int
y
: 10;
18
int
z
: 10;
19
int
w
: 2;
/* 0 by default, can manually set to { -2, -1, 0, 1 } */
20
21
PackedNormal
() =
default
;
22
PackedNormal
(
int
_x,
int
_y,
int
_z,
int
_w = 0) :
x
(_x),
y
(_y),
z
(_z),
w
(_w) {}
23
24
/* Cast from int to float. */
25
operator
float4
()
26
{
27
return
float4
(
x
,
y
,
z
,
w
);
28
}
29
};
30
31
inline
int
convert_normalized_f32_to_i10
(
float
x
)
32
{
33
/* OpenGL ES packs in a different order as desktop GL but component conversion is the same.
34
* Of the code here, only PackedNormal needs to change. */
35
constexpr
int
signed_int_10_max = 511;
36
constexpr
int
signed_int_10_min = -512;
37
38
int
qx =
x
* signed_int_10_max;
39
return
std::clamp(qx, signed_int_10_min, signed_int_10_max);
40
}
41
42
template
<
typename
GPUType>
inline
GPUType
convert_normal
(
const
float3
&src);
43
44
template
<>
inline
PackedNormal
convert_normal
(
const
float3
&src)
45
{
46
return
{
47
convert_normalized_f32_to_i10
(src[0]),
48
convert_normalized_f32_to_i10
(src[1]),
49
convert_normalized_f32_to_i10
(src[2]),
50
0,
51
};
52
}
53
54
template
<>
inline
short4
convert_normal
(
const
float3
&src)
55
{
56
return
short4
(src *
float
(std::numeric_limits<short>::max()), 0);
57
}
58
59
template
<
typename
GPUType>
void
convert_normals
(
Span<float3>
src,
MutableSpan<GPUType>
dst);
60
61
}
// namespace blender::gpu
x
x
Definition
BLI_expr_pylike_eval_test.cc:345
BLI_math_vector_types.hh
BLI_span.hh
GPUType
GPUType
Definition
GPU_material.hh:198
blender::MutableSpan
Definition
BLI_span.hh:443
blender::Span
Definition
BLI_span.hh:74
blender::gpu
Definition
blf_internal_types.hh:32
blender::gpu::convert_normal
GPUType convert_normal(const float3 &src)
blender::gpu::convert_normals
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
blender::gpu::convert_normalized_f32_to_i10
int convert_normalized_f32_to_i10(float x)
Definition
GPU_attribute_convert.hh:31
blender::short4
blender::VecBase< int16_t, 4 > short4
Definition
BLI_math_vector_types.hh:611
blender::float4
VecBase< float, 4 > float4
Definition
BLI_math_vector_types.hh:620
blender::float3
VecBase< float, 3 > float3
Definition
BLI_math_vector_types.hh:619
blender::gpu::PackedNormal
Definition
GPU_attribute_convert.hh:15
blender::gpu::PackedNormal::PackedNormal
PackedNormal(int _x, int _y, int _z, int _w=0)
Definition
GPU_attribute_convert.hh:22
blender::gpu::PackedNormal::x
int x
Definition
GPU_attribute_convert.hh:16
blender::gpu::PackedNormal::PackedNormal
PackedNormal()=default
blender::gpu::PackedNormal::w
int w
Definition
GPU_attribute_convert.hh:19
blender::gpu::PackedNormal::y
int y
Definition
GPU_attribute_convert.hh:17
blender::gpu::PackedNormal::z
int z
Definition
GPU_attribute_convert.hh:18
Generated on
for Blender by
doxygen
1.16.1