Blender V5.0
gpu_shader_cxx_matrix.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
14
15/* Some compilers complain about lack of return values. Keep it short. */
16#define RET \
17 { \
18 return {}; \
19 }
20
21/* -------------------------------------------------------------------- */
24
25template<int C, int R> struct MatBase {};
26
27template<int C, int R> struct MatOp {
31
32 const ColT &operator[](int) const
33 {
34 return *reinterpret_cast<const ColT *>(this);
35 }
37 {
38 return *reinterpret_cast<ColT *>(this);
39 }
40
42 MatT operator-() RET;
43
44 MatT operator*(MatT) const RET;
45
46 friend RowT operator*(ColT, MatT) RET;
47 friend ColT operator*(MatT, RowT) RET;
48};
49
50template<int R> struct MatBase<2, R> : MatOp<2, R> {
51 using T = float;
54
55 MatBase() = default;
56 explicit MatBase(T) {}
57 explicit MatBase(T, T, T, T) {}
58 explicit MatBase(ColT, ColT) {}
59 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
60};
61
62template<int R> struct MatBase<3, R> : MatOp<3, R> {
63 using T = float;
65 ColT x, y, z;
66
67 MatBase() = default;
68 explicit MatBase(T) {}
69 explicit MatBase(T, T, T, T, T, T, T, T, T) {}
70 explicit MatBase(ColT, ColT, ColT) {}
71 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
72};
73
74template<int R> struct MatBase<4, R> : MatOp<4, R> {
75 using T = float;
77 ColT x, y, z, w;
78
79 MatBase() = default;
80 explicit MatBase(T) {}
81 explicit MatBase(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) {}
82 explicit MatBase(ColT, ColT, ColT, ColT) {}
83 template<int OtherC, int OtherR> explicit MatBase(const MatBase<OtherC, OtherR> &) {}
84};
85
95
96/* Matrix reshaping functions. */
97#define RESHAPE(mat_to, mat_from, ...) \
98 mat_to to_##mat_to(mat_from m) \
99 { \
100 return mat_to(__VA_ARGS__); \
101 }
102
103/* clang-format off */
104RESHAPE(float2x2, float3x3, m[0].xy, m[1].xy)
105RESHAPE(float2x2, float4x4, m[0].xy, m[1].xy)
106RESHAPE(float3x3, float4x4, m[0].xyz, m[1].xyz, m[2].xyz)
107RESHAPE(float3x3, float2x2, m[0].x, m[0].y, 0, m[1].x, m[1].y, 0, 0, 0, 1)
108RESHAPE(float4x4, float2x2, m[0].x, m[0].y, 0, 0, m[1].x, m[1].y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
109RESHAPE(float4x4, float3x3, m[0].x, m[0].y, m[0].z, 0, m[1].x, m[1].y, m[1].z, 0, m[2].x, m[2].y, m[2].z, 0, 0, 0, 0, 1)
110/* clang-format on */
111/* TODO(fclem): Remove. Use Transform instead. */
112RESHAPE(float3x3, float3x4, m[0].xyz, m[1].xyz, m[2].xyz)
113#undef RESHAPE
114
116
117#undef RET
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
nullptr float
MatBase< 3, 4 > float3x4
#define RESHAPE(mat_to, mat_from,...)
MatBase< 2, 4 > float2x4
MatBase< 3, 2 > float3x2
MatBase< 2, 2 > float2x2
MatBase< 4, 4 > float4x4
MatBase< 2, 3 > float2x3
MatBase< 4, 3 > float4x3
MatBase< 3, 3 > float3x3
MatBase< 4, 2 > float4x2
#define RET
#define R
MatBase(const MatBase< OtherC, OtherR > &)
VecBase< float, R > ColT
MatBase()=default
VecBase< float, R > ColT
MatBase()=default
MatBase(T, T, T, T, T, T, T, T, T)
MatBase(ColT, ColT, ColT)
MatBase(const MatBase< OtherC, OtherR > &)
MatBase(ColT, ColT, ColT, ColT)
VecBase< float, R > ColT
MatBase(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)
MatBase(const MatBase< OtherC, OtherR > &)
MatBase()=default
ColT & operator[](int)
VecBase< float, C > RowT
MatBase< C, R > MatT
VecBase< float, R > ColT
const ColT & operator[](int) const
MatT operator+() RET
int xy[2]
Definition wm_draw.cc:178