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