Blender  V3.3
gpu_matrix.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. All rights reserved. */
3 
8 #include "gpu_context_private.hh"
9 #include "gpu_matrix_private.h"
10 
11 #define SUPPRESS_GENERIC_MATRIX_API
12 #define USE_GPU_PY_MATRIX_API /* only so values are declared */
13 #include "GPU_matrix.h"
14 #undef USE_GPU_PY_MATRIX_API
15 
16 #include "BLI_math_matrix.h"
17 #include "BLI_math_rotation.h"
18 #include "BLI_math_vector.h"
19 
20 #include "MEM_guardedalloc.h"
21 
22 using namespace blender::gpu;
23 
24 #define MATRIX_STACK_DEPTH 32
25 
26 using Mat4 = float[4][4];
27 using Mat3 = float[3][3];
28 
29 struct MatrixStack {
32 };
33 
37 
38  bool dirty;
39 
40  /* TODO: cache of derived matrices (Normal, MVP, inverse MVP, etc)
41  * generate as needed for shaders, invalidate when original matrices change
42  *
43  * TODO: separate Model from View transform? Batches/objects have model,
44  * camera/eye has view & projection
45  */
46 };
47 
48 #define ModelViewStack Context::get()->matrix_state->model_view_stack
49 #define ModelView ModelViewStack.stack[ModelViewStack.top]
50 
51 #define ProjectionStack Context::get()->matrix_state->projection_stack
52 #define Projection ProjectionStack.stack[ProjectionStack.top]
53 
55 {
56 #define MATRIX_4X4_IDENTITY \
57  { \
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}, \
59  { \
60  0.0f, 0.0f, 0.0f, 1.0f \
61  } \
62  }
63 
64  GPUMatrixState *state = (GPUMatrixState *)MEM_mallocN(sizeof(*state), __func__);
65  const MatrixStack identity_stack = {{MATRIX_4X4_IDENTITY}, 0};
66 
67  state->model_view_stack = state->projection_stack = identity_stack;
68  state->dirty = true;
69 
70 #undef MATRIX_4X4_IDENTITY
71 
72  return state;
73 }
74 
76 {
78 }
79 
80 static void gpu_matrix_state_active_set_dirty(bool value)
81 {
83  state->dirty = value;
84 }
85 
87 {
89  state->model_view_stack.top = 0;
90  state->projection_stack.top = 0;
94 }
95 
96 #ifdef WITH_GPU_SAFETY
97 
98 /* Check if matrix is numerically good */
99 static void checkmat(cosnt float *m)
100 {
101  const int n = 16;
102  for (int i = 0; i < n; i++) {
103 # if _MSC_VER
104  BLI_assert(_finite(m[i]));
105 # else
106  BLI_assert(!isinf(m[i]));
107 # endif
108  }
109 }
110 
111 # define CHECKMAT(m) checkmat((const float *)m)
112 
113 #else
114 
115 # define CHECKMAT(m)
116 
117 #endif
118 
120 {
122  ModelViewStack.top++;
124 }
125 
127 {
128  BLI_assert(ModelViewStack.top > 0);
129  ModelViewStack.top--;
131 }
132 
134 {
136  ProjectionStack.top++;
138 }
139 
141 {
142  BLI_assert(ProjectionStack.top > 0);
143  ProjectionStack.top--;
145 }
146 
147 void GPU_matrix_set(const float m[4][4])
148 {
149  copy_m4_m4(ModelView, m);
150  CHECKMAT(ModelView3D);
152 }
153 
155 {
157  CHECKMAT(Projection3D);
159 }
160 
161 void GPU_matrix_projection_set(const float m[4][4])
162 {
164  CHECKMAT(Projection3D);
166 }
167 
169 {
172 }
173 
174 void GPU_matrix_translate_2f(float x, float y)
175 {
176  Mat4 m;
177  unit_m4(m);
178  m[3][0] = x;
179  m[3][1] = y;
180  GPU_matrix_mul(m);
181 }
182 
183 void GPU_matrix_translate_2fv(const float vec[2])
184 {
185  GPU_matrix_translate_2f(vec[0], vec[1]);
186 }
187 
188 void GPU_matrix_translate_3f(float x, float y, float z)
189 {
190 #if 1
191  translate_m4(ModelView, x, y, z);
193 #else /* above works well in early testing, below is generic version */
194  Mat4 m;
195  unit_m4(m);
196  m[3][0] = x;
197  m[3][1] = y;
198  m[3][2] = z;
199  GPU_matrix_mul(m);
200 #endif
202 }
203 
204 void GPU_matrix_translate_3fv(const float vec[3])
205 {
206  GPU_matrix_translate_3f(vec[0], vec[1], vec[2]);
207 }
208 
209 void GPU_matrix_scale_1f(float factor)
210 {
211  Mat4 m;
212  scale_m4_fl(m, factor);
213  GPU_matrix_mul(m);
214 }
215 
216 void GPU_matrix_scale_2f(float x, float y)
217 {
218  Mat4 m = {{0.0f}};
219  m[0][0] = x;
220  m[1][1] = y;
221  m[2][2] = 1.0f;
222  m[3][3] = 1.0f;
223  GPU_matrix_mul(m);
224 }
225 
226 void GPU_matrix_scale_2fv(const float vec[2])
227 {
228  GPU_matrix_scale_2f(vec[0], vec[1]);
229 }
230 
231 void GPU_matrix_scale_3f(float x, float y, float z)
232 {
233  Mat4 m = {{0.0f}};
234  m[0][0] = x;
235  m[1][1] = y;
236  m[2][2] = z;
237  m[3][3] = 1.0f;
238  GPU_matrix_mul(m);
239 }
240 
241 void GPU_matrix_scale_3fv(const float vec[3])
242 {
243  GPU_matrix_scale_3f(vec[0], vec[1], vec[2]);
244 }
245 
246 void GPU_matrix_mul(const float m[4][4])
247 {
251 }
252 
254 {
255  /* essentially RotateAxis('Z')
256  * TODO: simpler math for 2D case
257  */
259 }
260 
261 void GPU_matrix_rotate_3f(float deg, float x, float y, float z)
262 {
263  const float axis[3] = {x, y, z};
264  GPU_matrix_rotate_3fv(deg, axis);
265 }
266 
267 void GPU_matrix_rotate_3fv(float deg, const float axis[3])
268 {
269  Mat4 m;
270  axis_angle_to_mat4(m, axis, DEG2RADF(deg));
271  GPU_matrix_mul(m);
272 }
273 
274 void GPU_matrix_rotate_axis(float deg, char axis)
275 {
276  /* rotate_m4 works in place */
277  rotate_m4(ModelView, axis, DEG2RADF(deg));
280 }
281 
282 static void mat4_ortho_set(
283  float m[4][4], float left, float right, float bottom, float top, float near, float far)
284 {
285  m[0][0] = 2.0f / (right - left);
286  m[1][0] = 0.0f;
287  m[2][0] = 0.0f;
288  m[3][0] = -(right + left) / (right - left);
289 
290  m[0][1] = 0.0f;
291  m[1][1] = 2.0f / (top - bottom);
292  m[2][1] = 0.0f;
293  m[3][1] = -(top + bottom) / (top - bottom);
294 
295  m[0][2] = 0.0f;
296  m[1][2] = 0.0f;
297  m[2][2] = -2.0f / (far - near);
298  m[3][2] = -(far + near) / (far - near);
299 
300  m[0][3] = 0.0f;
301  m[1][3] = 0.0f;
302  m[2][3] = 0.0f;
303  m[3][3] = 1.0f;
304 
306 }
307 
308 static void mat4_frustum_set(
309  float m[4][4], float left, float right, float bottom, float top, float near, float far)
310 {
311  m[0][0] = 2.0f * near / (right - left);
312  m[1][0] = 0.0f;
313  m[2][0] = (right + left) / (right - left);
314  m[3][0] = 0.0f;
315 
316  m[0][1] = 0.0f;
317  m[1][1] = 2.0f * near / (top - bottom);
318  m[2][1] = (top + bottom) / (top - bottom);
319  m[3][1] = 0.0f;
320 
321  m[0][2] = 0.0f;
322  m[1][2] = 0.0f;
323  m[2][2] = -(far + near) / (far - near);
324  m[3][2] = -2.0f * far * near / (far - near);
325 
326  m[0][3] = 0.0f;
327  m[1][3] = 0.0f;
328  m[2][3] = -1.0f;
329  m[3][3] = 0.0f;
330 
332 }
333 
334 static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
335 {
336  /* This function is loosely based on Mesa implementation.
337  *
338  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
339  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
340  *
341  * Permission is hereby granted, free of charge, to any person obtaining a
342  * copy of this software and associated documentation files (the "Software"),
343  * to deal in the Software without restriction, including without limitation
344  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
345  * and/or sell copies of the Software, and to permit persons to whom the
346  * Software is furnished to do so, subject to the following conditions:
347  *
348  * The above copyright notice including the dates of first publication and
349  * either this permission notice or a reference to
350  * http://oss.sgi.com/projects/FreeB/
351  * shall be included in all copies or substantial portions of the Software.
352  *
353  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
354  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
355  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
356  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
357  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
358  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
359  * SOFTWARE.
360  *
361  * Except as contained in this notice, the name of Silicon Graphics, Inc.
362  * shall not be used in advertising or otherwise to promote the sale, use or
363  * other dealings in this Software without prior written authorization from
364  * Silicon Graphics, Inc.
365  */
366  float side[3];
367 
368  normalize_v3(lookdir);
369 
370  cross_v3_v3v3(side, lookdir, camup);
371 
372  normalize_v3(side);
373 
374  cross_v3_v3v3(camup, side, lookdir);
375 
376  m[0][0] = side[0];
377  m[1][0] = side[1];
378  m[2][0] = side[2];
379  m[3][0] = 0.0f;
380 
381  m[0][1] = camup[0];
382  m[1][1] = camup[1];
383  m[2][1] = camup[2];
384  m[3][1] = 0.0f;
385 
386  m[0][2] = -lookdir[0];
387  m[1][2] = -lookdir[1];
388  m[2][2] = -lookdir[2];
389  m[3][2] = 0.0f;
390 
391  m[0][3] = 0.0f;
392  m[1][3] = 0.0f;
393  m[2][3] = 0.0f;
394  m[3][3] = 1.0f;
395 
397 }
398 
399 void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
400 {
401  mat4_ortho_set(Projection, left, right, bottom, top, near, far);
404 }
405 
406 void GPU_matrix_ortho_set_z(float near, float far)
407 {
409  Projection[2][2] = -2.0f / (far - near);
410  Projection[3][2] = -(far + near) / (far - near);
412 }
413 
414 void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
415 {
416  Mat4 m;
417  mat4_ortho_set(m, left, right, bottom, top, -1.0f, 1.0f);
418  CHECKMAT(Projection2D);
420 }
421 
423  float left, float right, float bottom, float top, float near, float far)
424 {
428 }
429 
430 void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far)
431 {
432  float half_height = tanf(fovy * (float)(M_PI / 360.0)) * near;
433  float half_width = half_height * aspect;
434  GPU_matrix_frustum_set(-half_width, +half_width, -half_height, +half_height, near, far);
435 }
436 
437 void GPU_matrix_look_at(float eyeX,
438  float eyeY,
439  float eyeZ,
440  float centerX,
441  float centerY,
442  float centerZ,
443  float upX,
444  float upY,
445  float upZ)
446 {
447  Mat4 cm;
448  float lookdir[3];
449  float camup[3] = {upX, upY, upZ};
450 
451  lookdir[0] = centerX - eyeX;
452  lookdir[1] = centerY - eyeY;
453  lookdir[2] = centerZ - eyeZ;
454 
455  mat4_look_from_origin(cm, lookdir, camup);
456 
457  GPU_matrix_mul(cm);
458  GPU_matrix_translate_3f(-eyeX, -eyeY, -eyeZ);
459 }
460 
461 void GPU_matrix_project_3fv(const float world[3],
462  const float model[4][4],
463  const float proj[4][4],
464  const int view[4],
465  float win[3])
466 {
467  float v[4];
468 
469  mul_v4_m4v3(v, model, world);
470  mul_m4_v4(proj, v);
471 
472  if (v[3] != 0.0f) {
473  mul_v3_fl(v, 1.0f / v[3]);
474  }
475 
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;
479 }
480 
481 void GPU_matrix_project_2fv(const float world[3],
482  const float model[4][4],
483  const float proj[4][4],
484  const int view[4],
485  float win[2])
486 {
487  float v[4];
488 
489  mul_v4_m4v3(v, model, world);
490  mul_m4_v4(proj, v);
491 
492  if (v[3] != 0.0f) {
493  mul_v2_fl(v, 1.0f / v[3]);
494  }
495 
496  win[0] = view[0] + (view[2] * (v[0] + 1)) * 0.5f;
497  win[1] = view[1] + (view[3] * (v[1] + 1)) * 0.5f;
498 }
499 
500 bool GPU_matrix_unproject_3fv(const float win[3],
501  const float model_inverted[4][4],
502  const float proj[4][4],
503  const int view[4],
504  float r_world[3])
505 {
506  zero_v3(r_world);
507  float in[3] = {
508  2 * ((win[0] - view[0]) / view[2]) - 1.0f,
509  2 * ((win[1] - view[1]) / view[3]) - 1.0f,
510  2 * win[2] - 1.0f,
511  };
512 
527  float out[3];
528  const bool is_persp = proj[3][3] == 0.0f;
529  if (is_persp) {
530  out[2] = proj[3][2] / (proj[2][2] + in[2]);
531  if (isinf(out[2])) {
532  out[2] = FLT_MAX;
533  }
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]);
536  out[2] *= -1;
537  }
538  else {
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];
542  }
543 
544  if (!is_finite_v3(out)) {
545  return false;
546  }
547 
548  mul_v3_m4v3(r_world, model_inverted, out);
549  return true;
550 }
551 
552 const float (*GPU_matrix_model_view_get(float m[4][4]))[4]
553 {
554  if (m) {
555  copy_m4_m4(m, ModelView);
556  return m;
557  }
558 
559  return ModelView;
560 }
561 
562 const float (*GPU_matrix_projection_get(float m[4][4]))[4]
563 {
564  if (m) {
566  return m;
567  }
568 
569  return Projection;
570 }
571 
572 const float (*GPU_matrix_model_view_projection_get(float m[4][4]))[4]
573 {
574  if (m == nullptr) {
575  static Mat4 temp;
576  m = temp;
577  }
578 
580  return m;
581 }
582 
583 const float (*GPU_matrix_normal_get(float m[3][3]))[3]
584 {
585  if (m == nullptr) {
586  static Mat3 temp3;
587  m = temp3;
588  }
589 
590  copy_m3_m4(m, (const float(*)[4])GPU_matrix_model_view_get(nullptr));
591 
592  invert_m3(m);
593  transpose_m3(m);
594 
595  return m;
596 }
597 
598 const float (*GPU_matrix_normal_inverse_get(float m[3][3]))[3]
599 {
600  if (m == nullptr) {
601  static Mat3 temp3;
602  m = temp3;
603  }
604 
606  invert_m3(m);
607 
608  return m;
609 }
610 
612 {
613  /* set uniform values to matrix stack values
614  * call this before a draw call if desired matrices are dirty
615  * call glUseProgram before this, as glUniform expects program to be bound
616  */
620 
624 
625  if (MV != -1) {
627  shader, MV, 16, 1, (const float *)GPU_matrix_model_view_get(nullptr));
628  }
629  if (P != -1) {
630  GPU_shader_uniform_vector(shader, P, 16, 1, (const float *)GPU_matrix_projection_get(nullptr));
631  }
632  if (MVP != -1) {
634  shader, MVP, 16, 1, (const float *)GPU_matrix_model_view_projection_get(nullptr));
635  }
636  if (N != -1) {
637  GPU_shader_uniform_vector(shader, N, 9, 1, (const float *)GPU_matrix_normal_get(nullptr));
638  }
639  if (MV_inv != -1) {
640  Mat4 m;
642  invert_m4(m);
643  GPU_shader_uniform_vector(shader, MV_inv, 16, 1, (const float *)m);
644  }
645  if (P_inv != -1) {
646  Mat4 m;
648  invert_m4(m);
649  GPU_shader_uniform_vector(shader, P_inv, 16, 1, (const float *)m);
650  }
651 
653 }
654 
656 {
658  return state->dirty;
659 }
660 
661 /* -------------------------------------------------------------------- */
665 BLI_STATIC_ASSERT(GPU_PY_MATRIX_STACK_LEN + 1 == MATRIX_STACK_DEPTH, "define mismatch");
666 
667 /* Return int since caller is may subtract. */
668 
670 {
672  return (int)state->model_view_stack.top;
673 }
674 
676 {
678  return (int)state->projection_stack.top;
679 }
680 
683 /* -------------------------------------------------------------------- */
690 float GPU_polygon_offset_calc(const float (*winmat)[4], float viewdist, float dist)
691 {
692  /* Seems like we have a factor of 2 more offset than 2.79 for some reason. Correct for this. */
693  dist *= 0.5f;
694 
695  if (winmat[3][3] > 0.5f) {
696 #if 1
697  return 0.00001f * dist * viewdist; // ortho tweaking
698 #else
699  static float depth_fac = 0.0f;
700  if (depth_fac == 0.0f) {
701  /* Hard-code for 24 bit precision. */
702  int depthbits = 24;
703  depth_fac = 1.0f / (float)((1 << depthbits) - 1);
704  }
705  ofs = (-1.0 / winmat[2][2]) * dist * depth_fac;
706 
707  UNUSED_VARS(viewdist);
708 #endif
709  }
710 
711  /* This adjustment effectively results in reducing the Z value by 0.25%.
712  *
713  * winmat[4][3] actually evaluates to `-2 * far * near / (far - near)`,
714  * is very close to -0.2 with default clip range,
715  * and is used as the coefficient multiplied by `w / z`,
716  * thus controlling the z dependent part of the depth value.
717  */
718  return winmat[3][2] * -0.0025f * dist;
719 }
720 
721 void GPU_polygon_offset(float viewdist, float dist)
722 {
723  static float winmat[4][4], offset = 0.0f;
724 
725  if (dist != 0.0f) {
726  /* hack below is to mimic polygon offset */
728 
729  /* dist is from camera to center point */
730 
731  float ofs = GPU_polygon_offset_calc(winmat, viewdist, dist);
732 
733  winmat[3][2] -= ofs;
734  offset += ofs;
735  }
736  else {
737  winmat[3][2] += offset;
738  offset = 0.0;
739  }
740 
742 }
743 
typedef float(TangentPoint)[2]
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define M_PI
Definition: BLI_math_base.h:20
void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3])
Definition: math_matrix.c:888
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1206
void mul_m4_v4(const float M[4][4], float r[4])
Definition: math_matrix.c:862
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void unit_m4(float m[4][4])
Definition: rct.c:1090
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2318
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2297
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
void rotate_m4(float mat[4][4], char axis, float angle)
Definition: math_matrix.c:2325
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1171
void transpose_m3(float R[3][3])
Definition: math_matrix.c:1332
void mul_m4_m4_post(float R[4][4], const float B[4][4])
Definition: math_matrix.c:380
#define DEG2RADF(_deg)
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
Definition: math_vector.c:349
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNUSED_VARS(...)
static AppView * view
_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
Definition: GPU_shader.h:20
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, int arraysize, const float *value)
Definition: gpu_shader.cc:630
@ GPU_UNIFORM_PROJECTION
Definition: GPU_shader.h:115
@ GPU_UNIFORM_MODELVIEW
Definition: GPU_shader.h:114
@ GPU_UNIFORM_PROJECTION_INV
Definition: GPU_shader.h:122
@ GPU_UNIFORM_MODELVIEW_INV
Definition: GPU_shader.h:121
@ GPU_UNIFORM_NORMAL
Definition: GPU_shader.h:125
@ GPU_UNIFORM_MVP
Definition: GPU_shader.h:117
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
Definition: gpu_shader.cc:566
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
static Context * get()
Definition: gpu_context.cc:82
GPUMatrixState * matrix_state
#define tanf(x)
Definition: cuda/compat.h:104
World world
void GPU_matrix_look_at(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Definition: gpu_matrix.cc:437
int GPU_matrix_stack_level_get_projection()
Definition: gpu_matrix.cc:675
const float(* GPU_matrix_normal_inverse_get(float m[3][3]))[3]
Definition: gpu_matrix.cc:598
void GPU_matrix_reset()
Definition: gpu_matrix.cc:86
void GPU_matrix_translate_2fv(const float vec[2])
Definition: gpu_matrix.cc:183
#define MATRIX_4X4_IDENTITY
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
Definition: gpu_matrix.cc:562
void GPU_matrix_rotate_axis(float deg, char axis)
Definition: gpu_matrix.cc:274
void GPU_matrix_mul(const float m[4][4])
Definition: gpu_matrix.cc:246
float GPU_polygon_offset_calc(const float(*winmat)[4], float viewdist, float dist)
Definition: gpu_matrix.cc:690
static void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:308
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])
Definition: gpu_matrix.cc:481
void GPU_matrix_identity_projection_set()
Definition: gpu_matrix.cc:154
void GPU_matrix_projection_set(const float m[4][4])
Definition: gpu_matrix.cc:161
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:399
void GPU_matrix_identity_set()
Definition: gpu_matrix.cc:168
void GPU_matrix_scale_2f(float x, float y)
Definition: gpu_matrix.cc:216
void GPU_matrix_bind(GPUShader *shader)
Definition: gpu_matrix.cc:611
void GPU_matrix_set(const float m[4][4])
Definition: gpu_matrix.cc:147
#define CHECKMAT(m)
Definition: gpu_matrix.cc:115
void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far)
Definition: gpu_matrix.cc:430
void GPU_matrix_scale_2fv(const float vec[2])
Definition: gpu_matrix.cc:226
void GPU_matrix_frustum_set(float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:422
void GPU_matrix_ortho_set_z(float near, float far)
Definition: gpu_matrix.cc:406
void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
Definition: gpu_matrix.cc:414
void GPU_matrix_push()
Definition: gpu_matrix.cc:119
#define MATRIX_STACK_DEPTH
Definition: gpu_matrix.cc:24
void GPU_matrix_push_projection()
Definition: gpu_matrix.cc:133
float[3][3] Mat3
Definition: gpu_matrix.cc:27
const float(* GPU_matrix_model_view_get(float m[4][4]))[4]
Definition: gpu_matrix.cc:552
const float(* GPU_matrix_model_view_projection_get(float m[4][4]))[4]
Definition: gpu_matrix.cc:572
static void mat4_ortho_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
Definition: gpu_matrix.cc:282
void GPU_matrix_scale_3fv(const float vec[3])
Definition: gpu_matrix.cc:241
void GPU_matrix_scale_3f(float x, float y, float z)
Definition: gpu_matrix.cc:231
int GPU_matrix_stack_level_get_model_view()
Definition: gpu_matrix.cc:669
static void gpu_matrix_state_active_set_dirty(bool value)
Definition: gpu_matrix.cc:80
#define Projection
Definition: gpu_matrix.cc:52
#define ModelView
Definition: gpu_matrix.cc:49
void GPU_matrix_scale_1f(float factor)
Definition: gpu_matrix.cc:209
void GPU_matrix_rotate_3fv(float deg, const float axis[3])
Definition: gpu_matrix.cc:267
void GPU_matrix_rotate_2d(float deg)
Definition: gpu_matrix.cc:253
void GPU_matrix_pop_projection()
Definition: gpu_matrix.cc:140
GPUMatrixState * GPU_matrix_state_create()
Definition: gpu_matrix.cc:54
void GPU_matrix_state_discard(GPUMatrixState *state)
Definition: gpu_matrix.cc:75
static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
Definition: gpu_matrix.cc:334
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])
Definition: gpu_matrix.cc:461
bool GPU_matrix_dirty_get()
Definition: gpu_matrix.cc:655
#define ProjectionStack
Definition: gpu_matrix.cc:51
#define ModelViewStack
Definition: gpu_matrix.cc:48
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])
Definition: gpu_matrix.cc:500
void GPU_matrix_translate_3fv(const float vec[3])
Definition: gpu_matrix.cc:204
void GPU_matrix_translate_3f(float x, float y, float z)
Definition: gpu_matrix.cc:188
void GPU_polygon_offset(float viewdist, float dist)
Definition: gpu_matrix.cc:721
void GPU_matrix_rotate_3f(float deg, float x, float y, float z)
Definition: gpu_matrix.cc:261
void GPU_matrix_pop()
Definition: gpu_matrix.cc:126
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:174
const float(* GPU_matrix_normal_get(float m[3][3]))[3]
Definition: gpu_matrix.cc:583
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
const int state
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
static float P(float k)
Definition: math_interp.c:25
static int left
#define N
BLI_STATIC_ASSERT(sizeof(GPUState)==sizeof(uint64_t), "GPUState is too big.")
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
signed int int32_t
Definition: stdint.h:77
MatrixStack model_view_stack
Definition: gpu_matrix.cc:35
MatrixStack projection_stack
Definition: gpu_matrix.cc:36