Blender V5.3
GPU_matrix.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11namespace blender {
12
13namespace gpu {
14class Shader;
15} // namespace gpu
16
20void GPU_matrix_reset();
21
22/* ModelView Matrix (2D or 3D) */
23
30void GPU_matrix_push();
31void GPU_matrix_pop();
32
37
41void GPU_matrix_scale_1f(float factor);
42
43/* 3D ModelView Matrix */
44
45void GPU_matrix_set(const float m[4][4]);
46void GPU_matrix_mul(const float m[4][4]);
47
48void GPU_matrix_translate_3f(float x, float y, float z);
49void GPU_matrix_translate_3fv(const float vec[3]);
50void GPU_matrix_scale_3f(float x, float y, float z);
51void GPU_matrix_scale_3fv(const float vec[3]);
52
56void GPU_matrix_rotate_3f(float deg, float x, float y, float z);
60void GPU_matrix_rotate_3fv(float deg, const float axis[3]);
61
62void GPU_matrix_rotate_axis(float deg, char axis); /* TODO: enum for axis? */
63
64void GPU_matrix_look_at(float eyeX,
65 float eyeY,
66 float eyeZ,
67 float centerX,
68 float centerY,
69 float centerZ,
70 float upX,
71 float upY,
72 float upZ);
73/* TODO: variant that takes eye[3], center[3], up[3] */
74
75/* 2D ModelView Matrix */
76
77void GPU_matrix_translate_2f(float x, float y);
78void GPU_matrix_translate_2fv(const float vec[2]);
79void GPU_matrix_scale_2f(float x, float y);
80void GPU_matrix_scale_2fv(const float vec[2]);
81void GPU_matrix_rotate_2d(float deg);
82
83/* Projection Matrix (2D or 3D). */
84
87
88/* 3D Projection Matrix. */
89
91void GPU_matrix_projection_set(const float m[4][4]);
92
93void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far);
94void GPU_matrix_ortho_set_z(float near, float far);
95
97 float left, float right, float bottom, float top, float near, float far);
98void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far);
99
100/* 3D Projection between Window and World Space */
101
103 float model_inverted[4][4];
104 float view[4];
111 struct {
112 double xmin, xmax;
113 double ymin, ymax;
114 double zmin, zmax;
116};
117
119 const float model[4][4],
120 const float proj[4][4],
121 const int view[4]);
122
123void GPU_matrix_project_3fv(const float world[3],
124 const float model[4][4],
125 const float proj[4][4],
126 const int view[4],
127 float r_win[3]);
128
129void GPU_matrix_project_2fv(const float world[3],
130 const float model[4][4],
131 const float proj[4][4],
132 const int view[4],
133 float r_win[2]);
134
135bool GPU_matrix_unproject_3fv(const float win[3],
136 const float model_inverted[4][4],
137 const float proj[4][4],
138 const int view[4],
139 float r_world[3]);
140
141/* 2D Projection Matrix. */
142
143void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top);
144
145/* Functions to get matrix values. */
146
147const float (*GPU_matrix_model_view_get(float m[4][4]))[4];
148const float (*GPU_matrix_projection_get(float m[4][4]))[4];
149const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4];
150
151const float (*GPU_matrix_normal_get(float m[3][3]))[3];
152const float (*GPU_matrix_normal_inverse_get(float m[3][3]))[3];
153
158bool GPU_matrix_dirty_get(); /* since last bind */
159
163float GPU_polygon_offset_calc(const float (*winmat)[4], float viewdist, float dist);
167void GPU_polygon_offset(float viewdist, float dist);
168
169/* Python API needs to be able to inspect the stack so errors raise exceptions
170 * instead of crashing. */
171#ifdef USE_GPU_PY_MATRIX_API
174/* static assert ensures this doesn't change! */
175# define GPU_PY_MATRIX_STACK_LEN 31
176#endif /* USE_GPU_PY_MATRIX_API */
177
178#ifndef SUPPRESS_GENERIC_MATRIX_API
179
180# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
181# define _GPU_MAT3_CONST_CAST(x) \
182 (_Generic((x), \
183 void *: (const float (*)[3])(x), \
184 float *: (const float (*)[3])(x), \
185 float (*)[4]: (const float (*)[3])(x), \
186 const void *: (const float (*)[3])(x), \
187 const float *: (const float (*)[3])(x), \
188 const float (*)[3]: (const float (*)[3])(x)))
189# define _GPU_MAT3_CAST(x) \
190 (_Generic((x), \
191 void *: (float (*)[3])(x), \
192 float *: (float (*)[3])(x), \
193 float (*)[3]: (float (*)[3])(x)))
194# define _GPU_MAT4_CONST_CAST(x) \
195 (_Generic((x), \
196 void *: (const float (*)[4])(x), \
197 float *: (const float (*)[4])(x), \
198 float (*)[4]: (const float (*)[4])(x), \
199 const void *: (const float (*)[4])(x), \
200 const float *: (const float (*)[4])(x), \
201 const float (*)[4]: (const float (*)[4])(x)))
202# define _GPU_MAT4_CAST(x) \
203 (_Generic((x), \
204 void *: (float (*)[4])(x), \
205 float *: (float (*)[4])(x), \
206 float (*)[4]: (float (*)[4])(x)))
207# else
208# define _GPU_MAT3_CONST_CAST(x) (const float (*)[3])(x)
209# define _GPU_MAT3_CAST(x) (float (*)[3])(x)
210# define _GPU_MAT4_CONST_CAST(x) (const float (*)[4])(x)
211# define _GPU_MAT4_CAST(x) (float (*)[4])(x)
212# endif /* C11 */
213
214/* make matrix inputs generic, to avoid warnings */
215# define GPU_matrix_mul(x) GPU_matrix_mul(_GPU_MAT4_CONST_CAST(x))
216# define GPU_matrix_set(x) GPU_matrix_set(_GPU_MAT4_CONST_CAST(x))
217# define GPU_matrix_projection_set(x) GPU_matrix_projection_set(_GPU_MAT4_CONST_CAST(x))
218# define GPU_matrix_model_view_get(x) GPU_matrix_model_view_get(_GPU_MAT4_CAST(x))
219# define GPU_matrix_projection_get(x) GPU_matrix_projection_get(_GPU_MAT4_CAST(x))
220# define GPU_matrix_model_view_projection_get(x) \
221 GPU_matrix_model_view_projection_get(_GPU_MAT4_CAST(x))
222# define GPU_matrix_normal_get(x) GPU_matrix_normal_get(_GPU_MAT3_CAST(x))
223# define GPU_matrix_normal_inverse_get(x) GPU_matrix_normal_inverse_get(_GPU_MAT3_CAST(x))
224#endif /* SUPPRESS_GENERIC_MATRIX_API */
225
226/* Not part of the GPU_matrix API,
227 * however we need to check these limits in code that calls into these API's. */
228constexpr static int GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT = -100;
229constexpr static int GPU_MATRIX_ORTHO_CLIP_FAR_DEFAULT = 100;
230
231} // namespace blender
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
BMesh Iterators.
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
void GPU_matrix_look_at(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
int GPU_matrix_stack_level_get_projection()
void GPU_matrix_scale_1f(float factor)
static constexpr int GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT
void GPU_matrix_scale_2fv(const float vec[2])
void GPU_matrix_project_2fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float r_win[2])
void GPU_matrix_identity_set()
void GPU_matrix_scale_3fv(const float vec[3])
void GPU_matrix_scale_3f(float x, float y, float z)
void GPU_matrix_rotate_axis(float deg, char axis)
void GPU_matrix_ortho_set_z(float near, float far)
void GPU_matrix_identity_projection_set()
void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far)
void GPU_matrix_rotate_2d(float deg)
const float(* GPU_matrix_normal_inverse_get(float m[3][3]))[3]
void GPU_matrix_mul(const float m[4][4])
void GPU_matrix_scale_2f(float x, float y)
void GPU_matrix_translate_3fv(const float vec[3])
void GPU_matrix_bind(gpu::Shader *shader)
void GPU_matrix_rotate_3fv(float deg, const float axis[3])
void GPU_matrix_project_3fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float r_win[3])
void GPU_matrix_rotate_3f(float deg, float x, float y, float z)
static constexpr int GPU_MATRIX_ORTHO_CLIP_FAR_DEFAULT
void GPU_matrix_projection_set(const float m[4][4])
void GPU_matrix_translate_2f(float x, float y)
bool GPU_matrix_unproject_precalc(GPUMatrixUnproject_Precalc *unproj_precalc, const float model[4][4], const float proj[4][4], const int view[4])
void GPU_matrix_pop_projection()
const float(* GPU_matrix_model_view_projection_get(float m[4][4]))[4]
bool GPU_matrix_unproject_3fv(const float win[3], const float model_inverted[4][4], const float proj[4][4], const int view[4], float r_world[3])
const float(* GPU_matrix_normal_get(float m[3][3]))[3]
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
int GPU_matrix_stack_level_get_model_view()
void GPU_matrix_reset()
Definition gpu_matrix.cc:87
void GPU_matrix_translate_2fv(const float vec[2])
bool GPU_matrix_dirty_get()
void GPU_polygon_offset(float viewdist, float dist)
void GPU_matrix_translate_3f(float x, float y, float z)
void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void GPU_matrix_pop()
void GPU_matrix_push_projection()
void GPU_matrix_set(const float m[4][4])
void GPU_matrix_push()
float GPU_polygon_offset_calc(const float(*winmat)[4], float viewdist, float dist)
const float(* GPU_matrix_model_view_get(float m[4][4]))[4]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct blender::GPUMatrixUnproject_Precalc::@331003270254071040320156152215347060215031241256 dims