Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

m_xform.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 7.3
  4. *
  5. * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #ifndef _M_XFORM_H
  25. #define _M_XFORM_H
  26. #include "main/compiler.h"
  27. #include "main/glheader.h"
  28. #include "math/m_matrix.h"
  29. #include "math/m_vector.h"
  30. #ifdef USE_X86_ASM
  31. #define _XFORMAPI _ASMAPI
  32. #define _XFORMAPIP _ASMAPIP
  33. #else
  34. #define _XFORMAPI
  35. #define _XFORMAPIP *
  36. #endif
  37. extern void
  38. _math_init_transformation(void);
  39. extern void
  40. init_c_cliptest(void);
  41. /* KW: Clip functions now do projective divide as well. The projected
  42. * coordinates are very useful to us because they let us cull
  43. * backfaces and eliminate vertices from lighting, fogging, etc
  44. * calculations. Despite the fact that this divide could be done one
  45. * day in hardware, we would still have a reason to want to do it here
  46. * as long as those other calculations remain in software.
  47. *
  48. * Clipping is a convenient place to do the divide on x86 as it should be
  49. * possible to overlap with integer outcode calculations.
  50. *
  51. * There are two cases where we wouldn't want to do the divide in cliptest:
  52. * - When we aren't clipping. We still might want to cull backfaces
  53. * so the divide should be done elsewhere. This currently never
  54. * happens.
  55. *
  56. * - When culling isn't likely to help us, such as when the GL culling
  57. * is disabled and we not lighting or are only lighting
  58. * one-sided. In this situation, backface determination provides
  59. * us with no useful information. A tricky case to detect is when
  60. * all input data is already culled, although hopefully the
  61. * application wouldn't turn on culling in such cases.
  62. *
  63. * We supply a buffer to hold the [x/w,y/w,z/w,1/w] values which
  64. * are the result of the projection. This is only used in the
  65. * 4-vector case - in other cases, we just use the clip coordinates
  66. * as the projected coordinates - they are identical.
  67. *
  68. * This is doubly convenient because it means the Win[] array is now
  69. * of the same stride as all the others, so I can now turn map_vertices
  70. * into a straight-forward matrix transformation, with asm acceleration
  71. * automatically available.
  72. */
  73. /* Vertex buffer clipping flags
  74. */
  75. #define CLIP_RIGHT_SHIFT 0
  76. #define CLIP_LEFT_SHIFT 1
  77. #define CLIP_TOP_SHIFT 2
  78. #define CLIP_BOTTOM_SHIFT 3
  79. #define CLIP_NEAR_SHIFT 4
  80. #define CLIP_FAR_SHIFT 5
  81. #define CLIP_RIGHT_BIT 0x01
  82. #define CLIP_LEFT_BIT 0x02
  83. #define CLIP_TOP_BIT 0x04
  84. #define CLIP_BOTTOM_BIT 0x08
  85. #define CLIP_NEAR_BIT 0x10
  86. #define CLIP_FAR_BIT 0x20
  87. #define CLIP_USER_BIT 0x40
  88. #define CLIP_CULL_BIT 0x80
  89. #define CLIP_FRUSTUM_BITS 0x3f
  90. typedef GLvector4f * (_XFORMAPIP clip_func)( GLvector4f *vClip,
  91. GLvector4f *vProj,
  92. GLubyte clipMask[],
  93. GLubyte *orMask,
  94. GLubyte *andMask,
  95. GLboolean viewport_z_clip );
  96. typedef void (*dotprod_func)( GLfloat *out,
  97. GLuint out_stride,
  98. CONST GLvector4f *coord_vec,
  99. CONST GLfloat plane[4] );
  100. typedef void (*vec_copy_func)( GLvector4f *to,
  101. CONST GLvector4f *from );
  102. /*
  103. * Functions for transformation of normals in the VB.
  104. */
  105. typedef void (_NORMAPIP normal_func)( CONST GLmatrix *mat,
  106. GLfloat scale,
  107. CONST GLvector4f *in,
  108. CONST GLfloat lengths[],
  109. GLvector4f *dest );
  110. /* Flags for selecting a normal transformation function.
  111. */
  112. #define NORM_RESCALE 0x1 /* apply the scale factor */
  113. #define NORM_NORMALIZE 0x2 /* normalize */
  114. #define NORM_TRANSFORM 0x4 /* apply the transformation matrix */
  115. #define NORM_TRANSFORM_NO_ROT 0x8 /* apply the transformation matrix */
  116. /* KW: New versions of the transform function allow a mask array
  117. * specifying that individual vector transform should be skipped
  118. * when the mask byte is zero. This is always present as a
  119. * parameter, to allow a unified interface.
  120. */
  121. typedef void (_XFORMAPIP transform_func)( GLvector4f *to_vec,
  122. CONST GLfloat m[16],
  123. CONST GLvector4f *from_vec );
  124. extern dotprod_func _mesa_dotprod_tab[5];
  125. extern vec_copy_func _mesa_copy_tab[0x10];
  126. extern vec_copy_func _mesa_copy_clean_tab[5];
  127. extern clip_func _mesa_clip_tab[5];
  128. extern clip_func _mesa_clip_np_tab[5];
  129. extern normal_func _mesa_normal_tab[0xf];
  130. /* Use of 2 layers of linked 1-dimensional arrays to reduce
  131. * cost of lookup.
  132. */
  133. extern transform_func *_mesa_transform_tab[5];
  134. #define TransformRaw( to, mat, from ) \
  135. ( _mesa_transform_tab[(from)->size][(mat)->type]( to, (mat)->m, from ), \
  136. (to) )
  137. #endif