Leaked source code of windows server 2003
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.

413 lines
13 KiB

  1. #ifndef __gllighting_h_
  2. #define __gllighting_h_
  3. /*
  4. ** Copyright 1991, 1992, 1993, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. */
  19. #include "types.h"
  20. #include "xform.h"
  21. /*
  22. ** Light state. Contains all the user controllable lighting state.
  23. ** Most of the colors kept in user state are scaled to match the
  24. ** drawing surfaces color resolution.
  25. **
  26. ** Exposed to the MCD as MCDMATERIAL.
  27. */
  28. struct __GLmaterialStateRec {
  29. __GLcolor ambient; /* unscaled */
  30. __GLcolor diffuse; /* unscaled */
  31. __GLcolor specular; /* unscaled */
  32. __GLcolor emissive; /* scaled */
  33. __GLfloat specularExponent;
  34. #ifdef NT
  35. // SGIBUG align it properly, otherwise GetMateriali returns wrong result!
  36. __GLfloat cmapa, cmapd, cmaps;
  37. #else
  38. __GLfloat cmapa, cmaps, cmapd;
  39. #endif
  40. };
  41. /*
  42. ** Exposed to the MCD as MCDLIGHTMODEL
  43. */
  44. struct __GLlightModelStateRec {
  45. __GLcolor ambient; /* scaled */
  46. GLboolean localViewer;
  47. GLboolean twoSided;
  48. };
  49. /*
  50. ** Partially exposed to the MCD as MCDLIGHT
  51. */
  52. typedef struct {
  53. __GLcolor ambient; /* scaled */
  54. __GLcolor diffuse; /* scaled */
  55. __GLcolor specular; /* scaled */
  56. __GLcoord position;
  57. __GLcoord positionEye;
  58. __GLcoord direction;
  59. __GLcoord directionEyeNorm;
  60. __GLfloat spotLightExponent;
  61. __GLfloat spotLightCutOffAngle;
  62. __GLfloat constantAttenuation;
  63. __GLfloat linearAttenuation;
  64. __GLfloat quadraticAttenuation;
  65. /* MCDLIGHT ends */
  66. /* Need both directionEyeNorm and directionEye because MCD 2.0 wants
  67. a normalized direction but glGetLightfv specifies that the value
  68. returned for spot direction is the pre-normalized eye coordinate
  69. direction */
  70. __GLcoord directionEye;
  71. struct __GLmatrixRec lightMatrix;
  72. } __GLlightSourceState;
  73. typedef struct {
  74. GLenum colorMaterialFace;
  75. GLenum colorMaterialParam;
  76. GLenum shadingModel;
  77. __GLlightModelState model;
  78. __GLmaterialState front;
  79. __GLmaterialState back;
  80. GLuint dirtyLights;
  81. __GLlightSourceState *source;
  82. } __GLlightState;
  83. /************************************************************************/
  84. /*
  85. ** What bits are affected by color index anti-aliasing. This isn't a
  86. ** really a changeable parameter (it is defined by the spec), but it
  87. ** is useful for documentation instead of a mysterious 4 or 16 sitting
  88. ** around in the code.
  89. */
  90. #define __GL_CI_ANTI_ALIAS_BITS 4
  91. #define __GL_CI_ANTI_ALIAS_DIVISOR (1 << __GL_CI_ANTI_ALIAS_BITS)
  92. /************************************************************************/
  93. /*
  94. ** These macros are used to convert incoming color values into the
  95. ** abstract color range from 0.0 to 1.0
  96. */
  97. #ifdef NT
  98. #define __GL_B_TO_FLOAT(b) (__glByteToFloat[(GLubyte)(b)])
  99. #define __GL_UB_TO_FLOAT(ub) (__glUByteToFloat[ub])
  100. #define __GL_S_TO_FLOAT(s) ((((s)<<1) + 1) * __glOneOver65535)
  101. #define __GL_US_TO_FLOAT(us) ((us) * __glOneOver65535)
  102. #else
  103. #define __GL_B_TO_FLOAT(b) ((((b)<<1) + 1) * gc->constants.oneOver255)
  104. #define __GL_UB_TO_FLOAT(ub) (gc->constants.uByteToFloat[ub])
  105. #define __GL_S_TO_FLOAT(s) ((((s)<<1) + 1) * gc->constants.oneOver65535)
  106. #define __GL_US_TO_FLOAT(us) ((us) * gc->constants.oneOver65535)
  107. #endif
  108. /*
  109. ** Not quite 2^31-1 because of possible floating point errors. 4294965000
  110. ** is a much safer number to use.
  111. */
  112. #ifdef NT
  113. #define __GL_I_TO_FLOAT(i) \
  114. ((((__GLfloat)(i) * (__GLfloat) 2.0) + 1) * \
  115. __glOneOver4294965000)
  116. #define __GL_UI_TO_FLOAT(ui) \
  117. ((__GLfloat)(ui) * __glOneOver4294965000)
  118. #else
  119. #define __GL_I_TO_FLOAT(i) \
  120. ((((__GLfloat)(i) * (__GLfloat) 2.0) + 1) * \
  121. gc->constants.oneOver4294965000)
  122. #define __GL_UI_TO_FLOAT(ui) \
  123. ((__GLfloat)(ui) * gc->constants.oneOver4294965000)
  124. #endif
  125. /*
  126. ** Bloody "round towards 0" convention. We could avoid these floor() calls
  127. ** were it not for that!
  128. */
  129. #ifdef NT
  130. #define __GL_FLOAT_TO_B(f) \
  131. ((GLbyte) __GL_FLOORF(((f) * __glVal255) * __glHalf))
  132. #define __GL_FLOAT_TO_UB(f) \
  133. ((GLubyte) ((f) * __glVal255 + __glHalf))
  134. #define __GL_FLOAT_TO_S(f) \
  135. ((GLshort) __GL_FLOORF(((f) * __glVal65535) * __glHalf))
  136. #define __GL_FLOAT_TO_US(f) \
  137. ((GLushort) ((f) * __glVal65535 + __glHalf))
  138. #else
  139. #define __GL_FLOAT_TO_B(f) \
  140. ((GLbyte) __GL_FLOORF(((f) * gc->constants.val255) * __glHalf))
  141. #define __GL_FLOAT_TO_UB(f) \
  142. ((GLubyte) ((f) * gc->constants.val255 + __glHalf))
  143. #define __GL_FLOAT_TO_S(f) \
  144. ((GLshort) __GL_FLOORF(((f) * gc->constants.val65535) * __glHalf))
  145. #define __GL_FLOAT_TO_US(f) \
  146. ((GLushort) ((f) * gc->constants.val65535 + __glHalf))
  147. #endif
  148. /*
  149. ** Not quite 2^31-1 because of possible floating point errors. 4294965000
  150. ** is a much safer number to use.
  151. */
  152. #ifdef NT
  153. #define __GL_FLOAT_TO_I(f) \
  154. ((GLint) __GL_FLOORF(((f) * __glVal4294965000) * __glHalf))
  155. #define __GL_FLOAT_TO_UI(f) \
  156. ((GLuint) ((f) * __glVal4294965000 + __glHalf))
  157. #else
  158. #define __GL_FLOAT_TO_I(f) \
  159. ((GLint) __GL_FLOORF(((f) * gc->constants.val4294965000) * __glHalf))
  160. #define __GL_FLOAT_TO_UI(f) \
  161. ((GLuint) ((f) * gc->constants.val4294965000 + __glHalf))
  162. #endif
  163. /*
  164. ** Mask the incoming color index (in floating point) against the
  165. ** maximum color index value for the color buffers. Keep 4 bits
  166. ** of fractional precision.
  167. */
  168. #define __GL_MASK_INDEXF(gc, val) \
  169. (((__GLfloat) (((GLint) ((val) * 16)) \
  170. & (((gc)->frontBuffer.redMax << 4) | 0xf))) \
  171. / (__GLfloat)16.0)
  172. #define __GL_MASK_INDEXI(gc, val) \
  173. ((val) & (gc)->frontBuffer.redMax)
  174. /************************************************************************/
  175. /*
  176. ** These two must be the same size, because they cache their tables in the
  177. ** same arena.
  178. */
  179. #define __GL_SPEC_LOOKUP_TABLE_SIZE 256
  180. #define __GL_SPOT_LOOKUP_TABLE_SIZE __GL_SPEC_LOOKUP_TABLE_SIZE
  181. typedef struct {
  182. GLint refcount;
  183. __GLfloat threshold, scale, exp;
  184. __GLfloat table[__GL_SPEC_LOOKUP_TABLE_SIZE];
  185. } __GLspecLUTEntry;
  186. __GLspecLUTEntry *__glCreateSpecLUT(__GLcontext *gc, __GLfloat exp);
  187. void FASTCALL __glFreeSpecLUT(__GLcontext *gc, __GLspecLUTEntry *lut);
  188. void FASTCALL __glInitLUTCache(__GLcontext *gc);
  189. void FASTCALL __glFreeLUTCache(__GLcontext *gc);
  190. #define __GL_LIGHT_UPDATE_FRONT_MATERIAL_AMBIENT
  191. /*
  192. ** Per light source per material computed state.
  193. */
  194. typedef struct __GLlightSourcePerMaterialMachineRec {
  195. __GLcolor ambient; /* light ambient times material ambient */
  196. __GLcolor diffuse; /* light diffuse times material diffuse */
  197. __GLcolor specular; /* light specular times material specular */
  198. } __GLlightSourcePerMaterialMachine;
  199. /*
  200. ** Per light source computed state.
  201. */
  202. struct __GLlightSourceMachineRec {
  203. /*
  204. ** ambient, diffuse and specular are each pre-multiplied by the
  205. ** material ambient, material diffuse and material specular.
  206. ** We use the face being lit to pick between the two sets.
  207. */
  208. __GLlightSourcePerMaterialMachine front, back;
  209. __GLlightSourceState *state;
  210. __GLfloat constantAttenuation;
  211. __GLfloat linearAttenuation;
  212. __GLfloat quadraticAttenuation;
  213. __GLfloat spotLightExponent;
  214. /* Position of the light source in eye coordinates */
  215. __GLcoord position;
  216. /* Direction of the light source in eye coordinates, normalize */
  217. __GLcoord direction;
  218. /* Cosine of the spot light cutoff angle */
  219. __GLfloat cosCutOffAngle;
  220. /* Precomputed attenuation, only when k1 and k2 are zero */
  221. __GLfloat attenuation;
  222. /* This will be set when the cut off angle != 180 */
  223. GLboolean isSpot;
  224. /* When possible, the normalized "h" value from the spec is pre-computed */
  225. __GLcoord hHat;
  226. /* Unit vector VPpli pre-computed (only when light is at infinity) */
  227. __GLcoord unitVPpli;
  228. /* sli and dli values pre-computed (color index mode only) */
  229. __GLfloat sli, dli;
  230. /* Link to next active light */
  231. __GLlightSourceMachine *next;
  232. /* Spot light exponent lookup table */
  233. __GLfloat *spotTable;
  234. /* Values used to avoid pow function during spot computations */
  235. __GLfloat threshold, scale;
  236. /* cache entry where this data came from */
  237. __GLspecLUTEntry *cache;
  238. /* Set to GL_TRUE if slow processing path is needed */
  239. GLboolean slowPath;
  240. /* temporary storage for hHat when original hHat is transformed into *
  241. /* normal space */
  242. __GLcoord tmpHHat;
  243. /* temporary storage for unitVPpli when original is transformed into *
  244. /* normal space */
  245. __GLcoord tmpUnitVPpli;
  246. };
  247. /*
  248. ** Per material computed state.
  249. */
  250. struct __GLmaterialMachineRec {
  251. #ifdef NT
  252. /*
  253. ** Sum of:
  254. ** invariant material emissive color (with respect to color material)
  255. ** invariant material ambient color * scene ambient color (with
  256. ** respect to color material)
  257. **
  258. ** This sum is carefully kept scaled.
  259. */
  260. __GLcolor paSceneColor;
  261. /*
  262. ** Cached values for the total emissive+ambient for a material, and
  263. ** the clamped version of this value which can be directly applied
  264. ** to backface vertices with no effective specular or diffuse components.
  265. */
  266. __GLcolor cachedEmissiveAmbient;
  267. __GLcolor cachedNonLit;
  268. #else
  269. /*
  270. ** Sum of:
  271. ** material emissive color
  272. ** material ambient color * scene ambient color
  273. **
  274. ** This sum is carefully kept scaled.
  275. */
  276. __GLcolor sceneColor;
  277. #endif
  278. /* Specular exponent */
  279. __GLfloat specularExponent;
  280. /* Specular exponent lookup table */
  281. __GLfloat *specTable;
  282. /* Values used to avoid pow function during specular computations */
  283. __GLfloat threshold, scale;
  284. /* cache entry where this data came from */
  285. __GLspecLUTEntry *cache;
  286. /* Scaled and clamped form of material diffuse alpha */
  287. __GLfloat alpha;
  288. #ifdef NT
  289. /* color material change bits */
  290. GLuint colorMaterialChange;
  291. #endif
  292. };
  293. typedef struct {
  294. __GLlightSourceMachine *source;
  295. __GLmaterialMachine front, back;
  296. /* List of enabled light sources */
  297. __GLlightSourceMachine *sources;
  298. /* Current material color material (iff one material is being updated) */
  299. __GLmaterialState *cm;
  300. __GLmaterialMachine *cmm;
  301. /* Cache of lookup tables for spot lights and specular highlights */
  302. struct __GLspecLUTCache_Rec *lutCache;
  303. } __GLlightMachine;
  304. /* Values for cmParam */
  305. #define __GL_EMISSION 0
  306. #define __GL_AMBIENT 1
  307. #define __GL_SPECULAR 2
  308. #define __GL_AMBIENT_AND_DIFFUSE 3
  309. #define __GL_DIFFUSE 4
  310. extern void FASTCALL __glCopyCIColor(__GLcontext *gc, GLuint faceBit, __GLvertex *v);
  311. extern void FASTCALL __glCopyRGBColor(__GLcontext *gc, GLuint faceBit, __GLvertex *v);
  312. extern void FASTCALL __glClampRGBColor(__GLcontext *gc, __GLcolor *dst,
  313. const __GLcolor *src);
  314. extern void FASTCALL __glClampAndScaleColor(__GLcontext *gc);
  315. /* Stuff for converting float colors */
  316. extern void FASTCALL __glClampAndScaleColorf(__GLcontext *gc, __GLcolor *dst,
  317. const GLfloat src[4]);
  318. extern void FASTCALL __glClampColorf(__GLcontext *gc, __GLcolor *dst,
  319. const GLfloat src[4]);
  320. extern void FASTCALL __glScaleColorf(__GLcontext *gc, __GLcolor *dst,
  321. const GLfloat src[4]);
  322. extern void FASTCALL __glUnScaleColorf(__GLcontext *gc, GLfloat dst[4],
  323. const __GLcolor *src);
  324. /* Stuff for converting integer colors */
  325. extern void FASTCALL __glClampAndScaleColori(__GLcontext *gc, __GLcolor *dst,
  326. const GLint src[4]);
  327. extern void FASTCALL __glClampColori(__GLcontext *gc, __GLcolor *dst,
  328. const GLint src[4]);
  329. extern void FASTCALL __glScaleColori(__GLcontext *gc, __GLcolor *dst,
  330. const GLint src[4]);
  331. extern void FASTCALL __glUnScaleColori(__GLcontext *gc, GLint dst[4],
  332. const __GLcolor *src);
  333. extern void FASTCALL __glTransformLightDirection(__GLcontext *gc,
  334. __GLlightSourceState *ls);
  335. extern void FASTCALL __glValidateLighting(__GLcontext *gc);
  336. extern void FASTCALL __glValidateMaterial(__GLcontext *gc, GLint front, GLint back);
  337. /* Procs for handling color material changes */
  338. extern void FASTCALL __glChangeOneMaterialColor(__GLcontext *gc);
  339. extern void FASTCALL __glChangeBothMaterialColors(__GLcontext *gc);
  340. /* Lighting procs */
  341. extern void FASTCALL __glCalcRGBColor(__GLcontext *gc, GLint face, __GLvertex *vx);
  342. extern void FASTCALL __glFastCalcRGBColor(__GLcontext *gc, GLint face, __GLvertex *vx);
  343. extern void FASTCALL __glCalcCIColor(__GLcontext *gc, GLint face, __GLvertex *vx);
  344. extern void FASTCALL __glFastCalcCIColor(__GLcontext *gc, GLint face, __GLvertex *vx);
  345. extern void FASTCALL ComputeColorMaterialChange(__GLcontext *gc);
  346. #endif /* __gllighting_h_ */