11 #define SUPPRESS_GENERIC_MATRIX_API
12 #define USE_GPU_PY_MATRIX_API
14 #undef USE_GPU_PY_MATRIX_API
24 #define MATRIX_STACK_DEPTH 32
48 #define ModelViewStack Context::get()->matrix_state->model_view_stack
49 #define ModelView ModelViewStack.stack[ModelViewStack.top]
51 #define ProjectionStack Context::get()->matrix_state->projection_stack
52 #define Projection ProjectionStack.stack[ProjectionStack.top]
56 #define MATRIX_4X4_IDENTITY \
58 {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 \
67 state->model_view_stack =
state->projection_stack = identity_stack;
70 #undef MATRIX_4X4_IDENTITY
89 state->model_view_stack.top = 0;
90 state->projection_stack.top = 0;
96 #ifdef WITH_GPU_SAFETY
99 static void checkmat(cosnt
float *m)
102 for (
int i = 0; i < n; i++) {
111 # define CHECKMAT(m) checkmat((const float *)m)
263 const float axis[3] = {
x,
y,
z};
283 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
297 m[2][2] = -2.0f / (far - near);
298 m[3][2] = -(far + near) / (far - near);
309 float m[4][4],
float left,
float right,
float bottom,
float top,
float near,
float far)
323 m[2][2] = -(far + near) / (far - near);
324 m[3][2] = -2.0f * far * near / (far - near);
386 m[0][2] = -lookdir[0];
387 m[1][2] = -lookdir[1];
388 m[2][2] = -lookdir[2];
410 Projection[3][2] = -(far + near) / (far - near);
432 float half_height =
tanf(fovy * (
float)(
M_PI / 360.0)) * near;
433 float half_width = half_height * aspect;
449 float camup[3] = {upX, upY, upZ};
451 lookdir[0] = centerX - eyeX;
452 lookdir[1] = centerY - eyeY;
453 lookdir[2] = centerZ - eyeZ;
462 const float model[4][4],
463 const float proj[4][4],
476 win[0] =
view[0] + (
view[2] * (
v[0] + 1)) * 0.5f;
477 win[1] =
view[1] + (
view[3] * (
v[1] + 1)) * 0.5f;
478 win[2] = (
v[2] + 1) * 0.5f;
482 const float model[4][4],
483 const float proj[4][4],
496 win[0] =
view[0] + (
view[2] * (
v[0] + 1)) * 0.5f;
497 win[1] =
view[1] + (
view[3] * (
v[1] + 1)) * 0.5f;
501 const float model_inverted[4][4],
502 const float proj[4][4],
508 2 * ((win[0] -
view[0]) /
view[2]) - 1.0f,
509 2 * ((win[1] -
view[1]) /
view[3]) - 1.0f,
528 const bool is_persp = proj[3][3] == 0.0f;
530 out[2] = proj[3][2] / (proj[2][2] + in[2]);
534 out[0] =
out[2] * ((proj[2][0] + in[0]) / proj[0][0]);
535 out[1] =
out[2] * ((proj[2][1] + in[1]) / proj[1][1]);
539 out[0] = (-proj[3][0] + in[0]) / proj[0][0];
540 out[1] = (-proj[3][1] + in[1]) / proj[1][1];
541 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;
typedef float(TangentPoint)[2]
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])
bool invert_m4(float R[4][4])
void mul_m4_v4(const float M[4][4], float r[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 M[4][4], const float v[3])
void rotate_m4(float mat[4][4], char axis, float angle)
bool invert_m3(float R[3][3])
void transpose_m3(float R[3][3])
void mul_m4_m4_post(float R[4][4], const float B[4][4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
MINLINE float normalize_v3(float r[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void mul_v3_fl(float r[3], float f)
bool is_finite_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble top
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble bottom
struct GPUShader GPUShader
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, int arraysize, 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.
ATTR_WARN_UNUSED_RESULT const BMVert * v
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()
const float(* GPU_matrix_normal_inverse_get(float m[3][3]))[3]
void GPU_matrix_translate_2fv(const float vec[2])
#define MATRIX_4X4_IDENTITY
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void GPU_matrix_rotate_axis(float deg, char axis)
void GPU_matrix_mul(const float m[4][4])
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_project_2fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[2])
void GPU_matrix_identity_projection_set()
void GPU_matrix_projection_set(const float m[4][4])
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_set(const float m[4][4])
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()
const float(* GPU_matrix_model_view_get(float m[4][4]))[4]
const float(* GPU_matrix_model_view_projection_get(float m[4][4]))[4]
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()
GPUMatrixState * GPU_matrix_state_create()
void GPU_matrix_state_discard(GPUMatrixState *state)
static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
void GPU_matrix_project_3fv(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[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_translate_2f(float x, float y)
const float(* GPU_matrix_normal_get(float m[3][3]))[3]
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
BLI_STATIC_ASSERT(sizeof(GPUState)==sizeof(uint64_t), "GPUState is too big.")
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
MatrixStack model_view_stack
MatrixStack projection_stack