12#define SUPPRESS_GENERIC_MATRIX_API
13#define USE_GPU_PY_MATRIX_API
15#undef USE_GPU_PY_MATRIX_API
25#define MATRIX_STACK_DEPTH 32
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}, \
61 0.0f, 0.0f, 0.0f, 1.0f \
68 state->model_view_stack =
state->projection_stack = identity_stack;
71#undef MATRIX_4X4_IDENTITY
91 state->projection_stack.top = 0;
100static void checkmat(cosnt
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];
674 return int(
state->model_view_stack.top);
680 return int(
state->projection_stack.top);
697 if (winmat[3][3] > 0.5f) {
699 return 0.00001f * dist * viewdist;
701 static float depth_fac = 0.0f;
702 if (depth_fac == 0.0f) {
705 depth_fac = 1.0f /
float((1 << depthbits) - 1);
707 ofs = (-1.0 / winmat[2][2]) * dist * depth_fac;
720 return winmat[3][2] * -0.0025f * dist;
725 static float winmat[4][4], offset = 0.0f;
739 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 unit_m4(float m[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 axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
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])
bool is_finite_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
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)
void GPU_shader_uniform_float_ex(GPUShader *shader, int location, int length, int array_size, const float *value)
@ GPU_UNIFORM_PROJECTION_INV
@ GPU_UNIFORM_MODELVIEW_INV
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
Read Guarded memory(de)allocation.
struct GPUShader GPUShader
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
GPUMatrixState * matrix_state
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
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_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)
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_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])
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)
#define MATRIX_STACK_DEPTH
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]