12#define SUPPRESS_GENERIC_MATRIX_API
13#define USE_GPU_PY_MATRIX_API
15#undef USE_GPU_PY_MATRIX_API
51#define ModelViewStack Context::get()->matrix_state->model_view_stack
52#define ModelView ModelViewStack.stack[ModelViewStack.top]
54#define ProjectionStack Context::get()->matrix_state->projection_stack
55#define Projection ProjectionStack.stack[ProjectionStack.top]
59#define MATRIX_4X4_IDENTITY \
61 {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, \
62 {0.0f, 0.0f, 0.0f, 1.0f} \
68 state->model_view_stack =
state->projection_stack = identity_stack;
71#undef MATRIX_4X4_IDENTITY
90 state->model_view_stack.top = 0;
91 state->projection_stack.top = 0;
100static void checkmat(
const float *m)
103 for (
int i = 0; i < n; i++) {
112# define CHECKMAT(m) checkmat((const float *)m)
264 const float axis[3] = {
x,
y,
z};
284 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
286 m[0][0] = 2.0f / (right - left);
289 m[3][0] = -(right + left) / (right - left);
292 m[1][1] = 2.0f / (top - bottom);
294 m[3][1] = -(top + bottom) / (top - bottom);
298 m[2][2] = -2.0f / (far - near);
299 m[3][2] = -(far + near) / (far - near);
310 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
312 m[0][0] = 2.0f * near / (right - left);
314 m[2][0] = (right + left) / (right - left);
318 m[1][1] = 2.0f * near / (top - bottom);
319 m[2][1] = (top + bottom) / (top - bottom);
324 m[2][2] = -(far + near) / (far - near);
325 m[3][2] = -2.0f * far * near / (far - near);
387 m[0][2] = -lookdir[0];
388 m[1][2] = -lookdir[1];
389 m[2][2] = -lookdir[2];
411 Projection[3][2] = -(far + near) / (far - near);
424 float left,
float right,
float bottom,
float top,
float near,
float far)
433 float half_height =
tanf(fovy *
float(
M_PI / 360.0)) * near;
434 float half_width = half_height * aspect;
450 float camup[3] = {upX, upY, upZ};
452 lookdir[0] = centerX - eyeX;
453 lookdir[1] = centerY - eyeY;
454 lookdir[2] = centerZ - eyeZ;
463 const float model[4][4],
464 const float proj[4][4],
477 r_win[0] = view[0] + (view[2] * (
v[0] + 1)) * 0.5f;
478 r_win[1] = view[1] + (view[3] * (
v[1] + 1)) * 0.5f;
479 r_win[2] = (
v[2] + 1) * 0.5f;
483 const float model[4][4],
484 const float proj[4][4],
497 r_win[0] = view[0] + (view[2] * (
v[0] + 1)) * 0.5f;
498 r_win[1] = view[1] + (view[3] * (
v[1] + 1)) * 0.5f;
502 const float model_inverted[4][4],
503 const float proj[4][4],
508 const float in[3] = {
509 2 * ((win[0] - view[0]) / view[2]) - 1.0f,
510 2 * ((win[1] - view[1]) / view[3]) - 1.0f,
529 const bool is_persp = proj[3][3] == 0.0f;
531 out[2] = proj[3][2] / (proj[2][2] +
in[2]);
535 out[0] =
out[2] * ((proj[2][0] +
in[0]) / proj[0][0]);
536 out[1] =
out[2] * ((proj[2][1] +
in[1]) / proj[1][1]);
540 out[0] = (-proj[3][0] +
in[0]) / proj[0][0];
541 out[1] = (-proj[3][1] +
in[1]) / proj[1][1];
542 out[2] = (-proj[3][2] +
in[2]) / proj[2][2];
679 return int(
state->model_view_stack.top);
685 return int(
state->projection_stack.top);
702 if (winmat[3][3] > 0.5f) {
704 return 0.00001f * dist * viewdist;
706 static float depth_fac = 0.0f;
707 if (depth_fac == 0.0f) {
710 depth_fac = 1.0f /
float((1 << depthbits) - 1);
712 ofs = (-1.0 / winmat[2][2]) * dist * depth_fac;
725 return winmat[3][2] * -0.0025f * dist;
730 static float winmat[4][4], offset = 0.0f;
744 winmat[3][2] += offset;
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
GPUMatrixState * matrix_state
#define MATRIX_4X4_IDENTITY
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_matrix_state_discard(GPUMatrixState *state)
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
MINLINE bool is_finite_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
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)
void GPU_matrix_scale_2fv(const float vec[2])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
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])
MINLINE void mul_v2_fl(float r[2], float f)
void GPU_matrix_identity_set()
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
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 mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
bool invert_m4(float mat[4][4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
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)
ATTR_WARN_UNUSED_RESULT const BMVert * v
const float(* GPU_matrix_normal_inverse_get(float m[3][3]))[3]
void GPU_matrix_mul(const float m[4][4])
MINLINE void mul_v3_fl(float r[3], float f)
static constexpr int MATRIX_STACK_DEPTH
void GPU_matrix_scale_2f(float x, float y)
@ GPU_UNIFORM_PROJECTION_INV
@ GPU_UNIFORM_MODELVIEW_INV
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 transpose_m3(float R[3][3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void GPU_shader_uniform_float_ex(gpu::Shader *shader, int location, int length, int array_size, const float *value)
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)
void unit_m4(float m[4][4])
static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
void GPU_matrix_projection_set(const float m[4][4])
void GPU_matrix_translate_2f(float x, float y)
MINLINE void zero_v3(float r[3])
void mul_m4_v4(const float mat[4][4], float r[4])
GPUMatrixState * GPU_matrix_state_create()
bool invert_m3(float mat[3][3])
void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3])
MINLINE float normalize_v3(float n[3])
void rotate_m4(float mat[4][4], char axis, float angle)
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 mul_m4_m4_post(float R[4][4], const float B[4][4])
static void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
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_translate_2fv(const float vec[2])
bool GPU_matrix_dirty_get()
void GPU_polygon_offset(float viewdist, float dist)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void GPU_matrix_translate_3f(float x, float y, float z)
void scale_m4_fl(float R[4][4], float scale)
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]
int GPU_shader_get_builtin_uniform(gpu::Shader *shader, int builtin)
void GPU_matrix_push_projection()
void GPU_matrix_set(const float m[4][4])
static void mat4_ortho_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
static void gpu_matrix_state_active_set_dirty(bool value)
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
MatrixStack model_view_stack
MatrixStack projection_stack
Mat4 stack[MATRIX_STACK_DEPTH]