Blender V4.5
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
11struct GPUShader;
12
16void GPU_matrix_reset();
17
18/* ModelView Matrix (2D or 3D) */
19
26void GPU_matrix_push();
27void GPU_matrix_pop();
28
33
37void GPU_matrix_scale_1f(float factor);
38
39/* 3D ModelView Matrix */
40
41void GPU_matrix_set(const float m[4][4]);
42void GPU_matrix_mul(const float m[4][4]);
43
44void GPU_matrix_translate_3f(float x, float y, float z);
45void GPU_matrix_translate_3fv(const float vec[3]);
46void GPU_matrix_scale_3f(float x, float y, float z);
47void GPU_matrix_scale_3fv(const float vec[3]);
48
52void GPU_matrix_rotate_3f(float deg, float x, float y, float z);
56void GPU_matrix_rotate_3fv(float deg, const float axis[3]);
57
58void GPU_matrix_rotate_axis(float deg, char axis); /* TODO: enum for axis? */
59
60void GPU_matrix_look_at(float eyeX,
61 float eyeY,
62 float eyeZ,
63 float centerX,
64 float centerY,
65 float centerZ,
66 float upX,
67 float upY,
68 float upZ);
69/* TODO: variant that takes eye[3], center[3], up[3] */
70
71/* 2D ModelView Matrix */
72
73void GPU_matrix_translate_2f(float x, float y);
74void GPU_matrix_translate_2fv(const float vec[2]);
75void GPU_matrix_scale_2f(float x, float y);
76void GPU_matrix_scale_2fv(const float vec[2]);
77void GPU_matrix_rotate_2d(float deg);
78
79/* Projection Matrix (2D or 3D). */
80
83
84/* 3D Projection Matrix. */
85
87void GPU_matrix_projection_set(const float m[4][4]);
88
89void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far);
90void GPU_matrix_ortho_set_z(float near, float far);
91
93 float left, float right, float bottom, float top, float near, float far);
94void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far);
95
96/* 3D Projection between Window and World Space */
97
99 float model_inverted[4][4];
100 float view[4];
107 struct {
108 double xmin, xmax;
109 double ymin, ymax;
110 double zmin, zmax;
112};
113
115 const float model[4][4],
116 const float proj[4][4],
117 const int view[4]);
118
119void GPU_matrix_project_3fv(const float world[3],
120 const float model[4][4],
121 const float proj[4][4],
122 const int view[4],
123 float r_win[3]);
124
125void GPU_matrix_project_2fv(const float world[3],
126 const float model[4][4],
127 const float proj[4][4],
128 const int view[4],
129 float r_win[2]);
130
131bool GPU_matrix_unproject_3fv(const float win[3],
132 const float model_inverted[4][4],
133 const float proj[4][4],
134 const int view[4],
135 float r_world[3]);
136
137/* 2D Projection Matrix. */
138
139void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top);
140
141/* Functions to get matrix values. */
142
143const float (*GPU_matrix_model_view_get(float m[4][4]))[4];
144const float (*GPU_matrix_projection_get(float m[4][4]))[4];
145const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4];
146
147const float (*GPU_matrix_normal_get(float m[3][3]))[3];
148const float (*GPU_matrix_normal_inverse_get(float m[3][3]))[3];
149
153void GPU_matrix_bind(GPUShader *shader);
154bool GPU_matrix_dirty_get(); /* since last bind */
155
159float GPU_polygon_offset_calc(const float (*winmat)[4], float viewdist, float dist);
163void GPU_polygon_offset(float viewdist, float dist);
164
165/* Python API needs to be able to inspect the stack so errors raise exceptions
166 * instead of crashing. */
167#ifdef USE_GPU_PY_MATRIX_API
170/* static assert ensures this doesn't change! */
171# define GPU_PY_MATRIX_STACK_LEN 31
172#endif /* USE_GPU_PY_MATRIX_API */
173
174#ifndef SUPPRESS_GENERIC_MATRIX_API
175
176# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
177# define _GPU_MAT3_CONST_CAST(x) \
178 (_Generic((x), \
179 void *: (const float(*)[3])(x), \
180 float *: (const float(*)[3])(x), \
181 float(*)[4]: (const float(*)[3])(x), \
182 const void *: (const float(*)[3])(x), \
183 const float *: (const float(*)[3])(x), \
184 const float(*)[3]: (const float(*)[3])(x)))
185# define _GPU_MAT3_CAST(x) \
186 (_Generic((x), \
187 void *: (float(*)[3])(x), \
188 float *: (float(*)[3])(x), \
189 float(*)[3]: (float(*)[3])(x)))
190# define _GPU_MAT4_CONST_CAST(x) \
191 (_Generic((x), \
192 void *: (const float(*)[4])(x), \
193 float *: (const float(*)[4])(x), \
194 float(*)[4]: (const float(*)[4])(x), \
195 const void *: (const float(*)[4])(x), \
196 const float *: (const float(*)[4])(x), \
197 const float(*)[4]: (const float(*)[4])(x)))
198# define _GPU_MAT4_CAST(x) \
199 (_Generic((x), \
200 void *: (float(*)[4])(x), \
201 float *: (float(*)[4])(x), \
202 float(*)[4]: (float(*)[4])(x)))
203# else
204# define _GPU_MAT3_CONST_CAST(x) (const float(*)[3])(x)
205# define _GPU_MAT3_CAST(x) (float(*)[3])(x)
206# define _GPU_MAT4_CONST_CAST(x) (const float(*)[4])(x)
207# define _GPU_MAT4_CAST(x) (float(*)[4])(x)
208# endif /* C11 */
209
210/* make matrix inputs generic, to avoid warnings */
211# define GPU_matrix_mul(x) GPU_matrix_mul(_GPU_MAT4_CONST_CAST(x))
212# define GPU_matrix_set(x) GPU_matrix_set(_GPU_MAT4_CONST_CAST(x))
213# define GPU_matrix_projection_set(x) GPU_matrix_projection_set(_GPU_MAT4_CONST_CAST(x))
214# define GPU_matrix_model_view_get(x) GPU_matrix_model_view_get(_GPU_MAT4_CAST(x))
215# define GPU_matrix_projection_get(x) GPU_matrix_projection_get(_GPU_MAT4_CAST(x))
216# define GPU_matrix_model_view_projection_get(x) \
217 GPU_matrix_model_view_projection_get(_GPU_MAT4_CAST(x))
218# define GPU_matrix_normal_get(x) GPU_matrix_normal_get(_GPU_MAT3_CAST(x))
219# define GPU_matrix_normal_inverse_get(x) GPU_matrix_normal_inverse_get(_GPU_MAT3_CAST(x))
220#endif /* SUPPRESS_GENERIC_MATRIX_API */
221
222/* Not part of the GPU_matrix API,
223 * however we need to check these limits in code that calls into these API's. */
224constexpr static int GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT = -100;
225constexpr static int GPU_MATRIX_ORTHO_CLIP_FAR_DEFAULT = 100;
static AppView * view
void GPU_matrix_look_at(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
#define GPU_matrix_normal_get(x)
void GPU_matrix_reset()
Definition gpu_matrix.cc:87
void GPU_matrix_translate_2fv(const float vec[2])
void GPU_matrix_rotate_axis(float deg, char axis)
float GPU_polygon_offset_calc(const float(*winmat)[4], float viewdist, float dist)
void GPU_matrix_identity_projection_set()
#define GPU_matrix_model_view_get(x)
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_ortho_set(float left, float right, float bottom, float top, float near, float far)
void GPU_matrix_identity_set()
void GPU_matrix_scale_2f(float x, float y)
void GPU_matrix_bind(GPUShader *shader)
void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far)
void GPU_matrix_scale_2fv(const float vec[2])
#define GPU_matrix_set(x)
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
void GPU_matrix_ortho_set_z(float near, float far)
void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
void GPU_matrix_push()
void GPU_matrix_push_projection()
#define GPU_matrix_mul(x)
void GPU_matrix_scale_3fv(const float vec[3])
void GPU_matrix_scale_3f(float x, float y, float z)
#define GPU_matrix_normal_inverse_get(x)
void GPU_matrix_scale_1f(float factor)
void GPU_matrix_rotate_3fv(float deg, const float axis[3])
void GPU_matrix_rotate_2d(float deg)
void GPU_matrix_pop_projection()
#define GPU_matrix_projection_get(x)
#define GPU_matrix_projection_set(x)
bool GPU_matrix_dirty_get()
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])
bool GPU_matrix_unproject_precalc(GPUMatrixUnproject_Precalc *unproj_precalc, const float model[4][4], const float proj[4][4], const int view[4])
#define GPU_matrix_model_view_projection_get(x)
void GPU_matrix_translate_3fv(const float vec[3])
void GPU_matrix_translate_3f(float x, float y, float z)
void GPU_polygon_offset(float viewdist, float dist)
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_pop()
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])
static constexpr int GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT
void GPU_matrix_translate_2f(float x, float y)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
uint top
int GPU_matrix_stack_level_get_projection()
int GPU_matrix_stack_level_get_model_view()
static int left
struct GPUMatrixUnproject_Precalc::@074106112015250112224331071346106010136226121114 dims