12#define SUPPRESS_GENERIC_MATRIX_API
13#define USE_GPU_PY_MATRIX_API
15#undef USE_GPU_PY_MATRIX_API
49#define ModelViewStack Context::get()->matrix_state->model_view_stack
50#define ModelView ModelViewStack.stack[ModelViewStack.top]
52#define ProjectionStack Context::get()->matrix_state->projection_stack
53#define Projection ProjectionStack.stack[ProjectionStack.top]
57#define MATRIX_4X4_IDENTITY \
59 {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, \
60 {0.0f, 0.0f, 0.0f, 1.0f} \
66 state->model_view_stack =
state->projection_stack = identity_stack;
69#undef MATRIX_4X4_IDENTITY
88 state->model_view_stack.top = 0;
89 state->projection_stack.top = 0;
98static void checkmat(cosnt
float *m)
101 for (
int i = 0;
i < n;
i++) {
110# define CHECKMAT(m) checkmat((const float *)m)
262 const float axis[3] = {
x,
y,
z};
282 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
284 m[0][0] = 2.0f / (right -
left);
287 m[3][0] = -(right +
left) / (right -
left);
290 m[1][1] = 2.0f / (
top - bottom);
292 m[3][1] = -(
top + bottom) / (
top - bottom);
296 m[2][2] = -2.0f / (far - near);
297 m[3][2] = -(far + near) / (far - near);
308 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
310 m[0][0] = 2.0f * near / (right -
left);
312 m[2][0] = (right +
left) / (right -
left);
316 m[1][1] = 2.0f * near / (
top - bottom);
317 m[2][1] = (
top + bottom) / (
top - bottom);
322 m[2][2] = -(far + near) / (far - near);
323 m[3][2] = -2.0f * far * near / (far - near);
385 m[0][2] = -lookdir[0];
386 m[1][2] = -lookdir[1];
387 m[2][2] = -lookdir[2];
409 Projection[3][2] = -(far + near) / (far - near);
422 float left,
float right,
float bottom,
float top,
float near,
float far)
431 float half_height =
tanf(fovy *
float(
M_PI / 360.0)) * near;
432 float half_width = half_height * aspect;
448 float camup[3] = {upX, upY, upZ};
450 lookdir[0] = centerX - eyeX;
451 lookdir[1] = centerY - eyeY;
452 lookdir[2] = centerZ - eyeZ;
461 const float model[4][4],
462 const float proj[4][4],
475 r_win[0] =
view[0] + (
view[2] * (
v[0] + 1)) * 0.5f;
476 r_win[1] =
view[1] + (
view[3] * (
v[1] + 1)) * 0.5f;
477 r_win[2] = (
v[2] + 1) * 0.5f;
481 const float model[4][4],
482 const float proj[4][4],
495 r_win[0] =
view[0] + (
view[2] * (
v[0] + 1)) * 0.5f;
496 r_win[1] =
view[1] + (
view[3] * (
v[1] + 1)) * 0.5f;
500 const float model_inverted[4][4],
501 const float proj[4][4],
506 const float in[3] = {
507 2 * ((win[0] -
view[0]) /
view[2]) - 1.0f,
508 2 * ((win[1] -
view[1]) /
view[3]) - 1.0f,
527 const bool is_persp = proj[3][3] == 0.0f;
529 out[2] = proj[3][2] / (proj[2][2] +
in[2]);
533 out[0] =
out[2] * ((proj[2][0] +
in[0]) / proj[0][0]);
534 out[1] =
out[2] * ((proj[2][1] +
in[1]) / proj[1][1]);
538 out[0] = (-proj[3][0] +
in[0]) / proj[0][0];
539 out[1] = (-proj[3][1] +
in[1]) / proj[1][1];
540 out[2] = (-proj[3][2] +
in[2]) / proj[2][2];
672 return int(
state->model_view_stack.top);
678 return int(
state->projection_stack.top);
695 if (winmat[3][3] > 0.5f) {
697 return 0.00001f * dist * viewdist;
699 static float depth_fac = 0.0f;
700 if (depth_fac == 0.0f) {
703 depth_fac = 1.0f /
float((1 << depthbits) - 1);
705 ofs = (-1.0 / winmat[2][2]) * dist * depth_fac;
718 return winmat[3][2] * -0.0025f * dist;
723 static float winmat[4][4], offset = 0.0f;
737 winmat[3][2] += offset;
#define BLI_STATIC_ASSERT(a, msg)
void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void scale_m4_fl(float R[4][4], float scale)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void mul_m4_v4(const float mat[4][4], float r[4])
void rotate_m4(float mat[4][4], char axis, float angle)
bool invert_m4(float mat[4][4])
void transpose_m3(float R[3][3])
void mul_m4_m4_post(float R[4][4], const float B[4][4])
bool invert_m3(float mat[3][3])
void unit_m4(float m[4][4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
MINLINE bool is_finite_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v3(float n[3])
#define GPU_matrix_normal_get(x)
#define GPU_matrix_model_view_get(x)
#define GPU_matrix_set(x)
#define GPU_matrix_mul(x)
#define GPU_matrix_normal_inverse_get(x)
#define GPU_matrix_projection_get(x)
#define GPU_matrix_projection_set(x)
#define GPU_matrix_model_view_projection_get(x)
@ GPU_UNIFORM_PROJECTION_INV
@ GPU_UNIFORM_MODELVIEW_INV
int GPU_shader_get_builtin_uniform(blender::gpu::Shader *shader, int builtin)
void GPU_shader_uniform_float_ex(blender::gpu::Shader *shader, int location, int length, int array_size, const float *value)
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
GPUMatrixState * matrix_state
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()
GPUMatrixState * GPU_matrix_state_create()
void GPU_matrix_translate_2fv(const float vec[2])
#define MATRIX_4X4_IDENTITY
void GPU_matrix_bind(blender::gpu::Shader *shader)
void GPU_matrix_rotate_axis(float deg, char axis)
float GPU_polygon_offset_calc(const float(*winmat)[4], float viewdist, float dist)
static void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
static constexpr int MATRIX_STACK_DEPTH
void GPU_matrix_identity_projection_set()
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_perspective_set(float fovy, float aspect, float near, float far)
void GPU_matrix_scale_2fv(const float vec[2])
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_projection()
static void mat4_ortho_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
void GPU_matrix_scale_3fv(const float vec[3])
void GPU_matrix_scale_3f(float x, float y, float z)
int GPU_matrix_stack_level_get_model_view()
static void gpu_matrix_state_active_set_dirty(bool value)
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()
void GPU_matrix_state_discard(GPUMatrixState *state)
static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
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])
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_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)
void * MEM_mallocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
MatrixStack model_view_stack
MatrixStack projection_stack
Mat4 stack[MATRIX_STACK_DEPTH]