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.

667 lines
15 KiB

  1. /*
  2. ** Copyright 1991, 1992, 1993, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. static __GLzValue FASTCALL Fetch(__GLdepthBuffer *fb, GLint x, GLint y)
  20. {
  21. __GLzValue *fp;
  22. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  23. return fp[0];
  24. }
  25. static GLboolean StoreNEVER(__GLdepthBuffer *fb,
  26. GLint x, GLint y, __GLzValue z)
  27. {
  28. #ifdef __GL_LINT
  29. fb = fb;
  30. x = y;
  31. z = z;
  32. #endif
  33. return GL_FALSE;
  34. }
  35. static GLboolean StoreLESS(__GLdepthBuffer *fb,
  36. GLint x, GLint y, __GLzValue z)
  37. {
  38. __GLzValue *fp;
  39. #ifdef ASSERT_BUFFER
  40. ASSERTOPENGL(fb->buf.base != NULL, "StoreLESS: No depth buffer\n");
  41. #endif
  42. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  43. if (z < fp[0]) {
  44. fp[0] = z;
  45. return GL_TRUE;
  46. }
  47. return GL_FALSE;
  48. }
  49. static GLboolean StoreEQUAL(__GLdepthBuffer *fb,
  50. GLint x, GLint y, __GLzValue z)
  51. {
  52. __GLzValue *fp;
  53. #ifdef ASSERT_BUFFER
  54. ASSERTOPENGL(fb->buf.base != NULL, "StoreEQUAL: No depth buffer\n");
  55. #endif
  56. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  57. if (z == fp[0]) {
  58. fp[0] = z;
  59. return GL_TRUE;
  60. }
  61. return GL_FALSE;
  62. }
  63. static GLboolean StoreLEQUAL(__GLdepthBuffer *fb,
  64. GLint x, GLint y, __GLzValue z)
  65. {
  66. __GLzValue *fp;
  67. #ifdef ASSERT_BUFFER
  68. ASSERTOPENGL(fb->buf.base != NULL, "StoreLEQUAL: No depth buffer\n");
  69. #endif
  70. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  71. if (z <= fp[0]) {
  72. fp[0] = z;
  73. return GL_TRUE;
  74. }
  75. return GL_FALSE;
  76. }
  77. static GLboolean StoreGREATER(__GLdepthBuffer *fb,
  78. GLint x, GLint y, __GLzValue z)
  79. {
  80. __GLzValue *fp;
  81. #ifdef ASSERT_BUFFER
  82. ASSERTOPENGL(fb->buf.base != NULL, "StoreGREATER: No depth buffer\n");
  83. #endif
  84. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  85. if (z > fp[0]) {
  86. fp[0] = z;
  87. return GL_TRUE;
  88. }
  89. return GL_FALSE;
  90. }
  91. static GLboolean StoreNOTEQUAL(__GLdepthBuffer *fb,
  92. GLint x, GLint y, __GLzValue z)
  93. {
  94. __GLzValue *fp;
  95. #ifdef ASSERT_BUFFER
  96. ASSERTOPENGL(fb->buf.base != NULL, "StoreNOTEQUAL: No depth buffer\n");
  97. #endif
  98. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  99. if (z != fp[0]) {
  100. fp[0] = z;
  101. return GL_TRUE;
  102. }
  103. return GL_FALSE;
  104. }
  105. static GLboolean StoreGEQUAL(__GLdepthBuffer *fb,
  106. GLint x, GLint y, __GLzValue z)
  107. {
  108. __GLzValue *fp;
  109. #ifdef ASSERT_BUFFER
  110. ASSERTOPENGL(fb->buf.base != NULL, "StoreGEQUAL: No depth buffer\n");
  111. #endif
  112. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  113. if (z >= fp[0]) {
  114. fp[0] = z;
  115. return GL_TRUE;
  116. }
  117. return GL_FALSE;
  118. }
  119. static GLboolean StoreALWAYS(__GLdepthBuffer *fb,
  120. GLint x, GLint y, __GLzValue z)
  121. {
  122. __GLzValue *fp;
  123. #ifdef ASSERT_BUFFER
  124. ASSERTOPENGL(fb->buf.base != NULL, "StoreALWAYS: No depth buffer\n");
  125. #endif
  126. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  127. fp[0] = z;
  128. return GL_TRUE;
  129. }
  130. /************************************************************************/
  131. static GLboolean StoreLESS_W(__GLdepthBuffer *fb,
  132. GLint x, GLint y, __GLzValue z)
  133. {
  134. __GLzValue *fp;
  135. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  136. return z < fp[0];
  137. }
  138. static GLboolean StoreEQUAL_W(__GLdepthBuffer *fb,
  139. GLint x, GLint y, __GLzValue z)
  140. {
  141. __GLzValue *fp;
  142. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  143. return z == fp[0];
  144. }
  145. static GLboolean StoreLEQUAL_W(__GLdepthBuffer *fb,
  146. GLint x, GLint y, __GLzValue z)
  147. {
  148. __GLzValue *fp;
  149. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  150. return z <= fp[0];
  151. }
  152. static GLboolean StoreGREATER_W(__GLdepthBuffer *fb,
  153. GLint x, GLint y, __GLzValue z)
  154. {
  155. __GLzValue *fp;
  156. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  157. return z > fp[0];
  158. }
  159. static GLboolean StoreNOTEQUAL_W(__GLdepthBuffer *fb,
  160. GLint x, GLint y, __GLzValue z)
  161. {
  162. __GLzValue *fp;
  163. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  164. return z != fp[0];
  165. }
  166. static GLboolean StoreGEQUAL_W(__GLdepthBuffer *fb,
  167. GLint x, GLint y, __GLzValue z)
  168. {
  169. __GLzValue *fp;
  170. fp = __GL_DEPTH_ADDR(fb, (__GLzValue*), x, y);
  171. return z >= fp[0];
  172. }
  173. static GLboolean StoreALWAYS_W(__GLdepthBuffer *fb,
  174. GLint x, GLint y, __GLzValue z)
  175. {
  176. #ifdef __GL_LINT
  177. fb = fb;
  178. x = y;
  179. z = z;
  180. #endif
  181. return GL_TRUE;
  182. }
  183. #ifdef NT
  184. static __GLzValue FASTCALL Fetch16(__GLdepthBuffer *fb, GLint x, GLint y)
  185. {
  186. __GLz16Value *fp;
  187. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  188. return (__GLzValue) fp[0];
  189. }
  190. static GLboolean Store16NEVER(__GLdepthBuffer *fb,
  191. GLint x, GLint y, __GLzValue z)
  192. {
  193. #ifdef __GL_LINT
  194. fb = fb;
  195. x = y;
  196. z = z;
  197. #endif
  198. return GL_FALSE;
  199. }
  200. static GLboolean Store16LESS(__GLdepthBuffer *fb,
  201. GLint x, GLint y, __GLzValue z)
  202. {
  203. __GLz16Value *fp;
  204. #ifdef ASSERT_BUFFER
  205. ASSERTOPENGL(fb->buf.base != NULL, "Store16LESS: No depth buffer\n");
  206. #endif
  207. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  208. if (z < fp[0]) {
  209. fp[0] = (__GLz16Value)z;
  210. return GL_TRUE;
  211. }
  212. return GL_FALSE;
  213. }
  214. static GLboolean Store16EQUAL(__GLdepthBuffer *fb,
  215. GLint x, GLint y, __GLzValue z)
  216. {
  217. __GLz16Value *fp;
  218. #ifdef ASSERT_BUFFER
  219. ASSERTOPENGL(fb->buf.base != NULL, "Store16EQUAL: No depth buffer\n");
  220. #endif
  221. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  222. if (z == fp[0]) {
  223. fp[0] = (__GLz16Value)z;
  224. return GL_TRUE;
  225. }
  226. return GL_FALSE;
  227. }
  228. static GLboolean Store16LEQUAL(__GLdepthBuffer *fb,
  229. GLint x, GLint y, __GLzValue z)
  230. {
  231. __GLz16Value *fp;
  232. #ifdef ASSERT_BUFFER
  233. ASSERTOPENGL(fb->buf.base != NULL, "Store16LEQUAL: No depth buffer\n");
  234. #endif
  235. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  236. if (z <= fp[0]) {
  237. fp[0] = (__GLz16Value)z;
  238. return GL_TRUE;
  239. }
  240. return GL_FALSE;
  241. }
  242. static GLboolean Store16GREATER(__GLdepthBuffer *fb,
  243. GLint x, GLint y, __GLzValue z)
  244. {
  245. __GLz16Value *fp;
  246. #ifdef ASSERT_BUFFER
  247. ASSERTOPENGL(fb->buf.base != NULL, "Store16GREATER: No depth buffer\n");
  248. #endif
  249. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  250. if (z > fp[0]) {
  251. fp[0] = (__GLz16Value)z;
  252. return GL_TRUE;
  253. }
  254. return GL_FALSE;
  255. }
  256. static GLboolean Store16NOTEQUAL(__GLdepthBuffer *fb,
  257. GLint x, GLint y, __GLzValue z)
  258. {
  259. __GLz16Value *fp;
  260. #ifdef ASSERT_BUFFER
  261. ASSERTOPENGL(fb->buf.base != NULL, "Store16NOTEQUAL: No depth buffer\n");
  262. #endif
  263. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  264. if (z != fp[0]) {
  265. fp[0] = (__GLz16Value)z;
  266. return GL_TRUE;
  267. }
  268. return GL_FALSE;
  269. }
  270. static GLboolean Store16GEQUAL(__GLdepthBuffer *fb,
  271. GLint x, GLint y, __GLzValue z)
  272. {
  273. __GLz16Value *fp;
  274. #ifdef ASSERT_BUFFER
  275. ASSERTOPENGL(fb->buf.base != NULL, "Store16GEQUAL: No depth buffer\n");
  276. #endif
  277. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  278. if (z >= fp[0]) {
  279. fp[0] = (__GLz16Value)z;
  280. return GL_TRUE;
  281. }
  282. return GL_FALSE;
  283. }
  284. static GLboolean Store16ALWAYS(__GLdepthBuffer *fb,
  285. GLint x, GLint y, __GLzValue z)
  286. {
  287. __GLz16Value *fp;
  288. #ifdef ASSERT_BUFFER
  289. ASSERTOPENGL(fb->buf.base != NULL, "Store16ALWAYS: No depth buffer\n");
  290. #endif
  291. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  292. fp[0] = (__GLz16Value)z;
  293. return GL_TRUE;
  294. }
  295. /************************************************************************/
  296. static GLboolean Store16LESS_W(__GLdepthBuffer *fb,
  297. GLint x, GLint y, __GLzValue z)
  298. {
  299. __GLz16Value *fp;
  300. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  301. return z < fp[0];
  302. }
  303. static GLboolean Store16EQUAL_W(__GLdepthBuffer *fb,
  304. GLint x, GLint y, __GLzValue z)
  305. {
  306. __GLz16Value *fp;
  307. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  308. return z == fp[0];
  309. }
  310. static GLboolean Store16LEQUAL_W(__GLdepthBuffer *fb,
  311. GLint x, GLint y, __GLzValue z)
  312. {
  313. __GLz16Value *fp;
  314. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  315. return z <= fp[0];
  316. }
  317. static GLboolean Store16GREATER_W(__GLdepthBuffer *fb,
  318. GLint x, GLint y, __GLzValue z)
  319. {
  320. __GLz16Value *fp;
  321. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  322. return z > fp[0];
  323. }
  324. static GLboolean Store16NOTEQUAL_W(__GLdepthBuffer *fb,
  325. GLint x, GLint y, __GLzValue z)
  326. {
  327. __GLz16Value *fp;
  328. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  329. return z != fp[0];
  330. }
  331. static GLboolean Store16GEQUAL_W(__GLdepthBuffer *fb,
  332. GLint x, GLint y, __GLzValue z)
  333. {
  334. __GLz16Value *fp;
  335. fp = __GL_DEPTH_ADDR(fb, (__GLz16Value*), x, y);
  336. return z >= fp[0];
  337. }
  338. static GLboolean Store16ALWAYS_W(__GLdepthBuffer *fb,
  339. GLint x, GLint y, __GLzValue z)
  340. {
  341. #ifdef __GL_LINT
  342. fb = fb;
  343. x = y;
  344. z = z;
  345. #endif
  346. return GL_TRUE;
  347. }
  348. #endif //NT
  349. /************************************************************************/
  350. static void FASTCALL Clear(__GLdepthBuffer *dfb)
  351. {
  352. __GLcontext *gc = dfb->buf.gc;
  353. __GLzValue *fb;
  354. GLint x, y, x1, y1;
  355. GLint skip, w, w32, w4, w1;
  356. __GLzValue z = (__GLzValue)(gc->state.depth.clear * dfb->scale);
  357. #ifdef NT
  358. if( !gc->state.depth.writeEnable )
  359. return;
  360. #endif
  361. x = gc->transform.clipX0;
  362. y = gc->transform.clipY0;
  363. x1 = gc->transform.clipX1;
  364. y1 = gc->transform.clipY1;
  365. if (((w = x1 - x) == 0) || (y1 - y == 0)) {
  366. return;
  367. }
  368. fb = __GL_DEPTH_ADDR(dfb, (__GLzValue*), x, y);
  369. #ifdef NT
  370. ASSERTOPENGL(sizeof(ULONG) == sizeof(__GLzValue),
  371. "Incorrect __GLzValue size\n");
  372. skip = dfb->buf.outerWidth;
  373. if (skip == w)
  374. {
  375. w = w * (y1 - y) * sizeof(ULONG);
  376. RtlFillMemoryUlong((PVOID) fb, (ULONG) w, (ULONG) z);
  377. }
  378. else
  379. {
  380. w = w * sizeof(ULONG); // convert to byte count
  381. for (; y < y1; y++)
  382. {
  383. RtlFillMemoryUlong((PVOID) fb, (ULONG) w, (ULONG) z);
  384. fb += skip;
  385. }
  386. }
  387. #else
  388. skip = dfb->buf.outerWidth - w;
  389. w32 = w >> 5;
  390. w4 = (w & 31) >> 2;
  391. w1 = w & 3;
  392. for (; y < y1; y++) {
  393. w = w32;
  394. while (--w >= 0) {
  395. fb[0] = z; fb[1] = z; fb[2] = z; fb[3] = z;
  396. fb[4] = z; fb[5] = z; fb[6] = z; fb[7] = z;
  397. fb[8] = z; fb[9] = z; fb[10] = z; fb[11] = z;
  398. fb[12] = z; fb[13] = z; fb[14] = z; fb[15] = z;
  399. fb[16] = z; fb[17] = z; fb[18] = z; fb[19] = z;
  400. fb[20] = z; fb[21] = z; fb[22] = z; fb[23] = z;
  401. fb[24] = z; fb[25] = z; fb[26] = z; fb[27] = z;
  402. fb[28] = z; fb[29] = z; fb[30] = z; fb[31] = z;
  403. fb += 32;
  404. }
  405. w = w4;
  406. while (--w >= 0) {
  407. fb[0] = z; fb[1] = z; fb[2] = z; fb[3] = z;
  408. fb += 4;
  409. }
  410. w = w1;
  411. while (--w >= 0) {
  412. *fb++ = z;
  413. }
  414. fb += skip;
  415. }
  416. #endif // NT
  417. }
  418. #ifdef NT
  419. /************************************************************************/
  420. static void FASTCALL Clear16(__GLdepthBuffer *dfb)
  421. {
  422. __GLcontext *gc = dfb->buf.gc;
  423. __GLz16Value *fb;
  424. GLint x, y, x1, y1;
  425. GLint skip, w;
  426. __GLz16Value z = (__GLz16Value)(gc->state.depth.clear * dfb->scale);
  427. __GLzValue zz = (z << 16) | z;
  428. #ifdef NT
  429. if( !gc->state.depth.writeEnable )
  430. return;
  431. #endif
  432. x = gc->transform.clipX0;
  433. y = gc->transform.clipY0;
  434. x1 = gc->transform.clipX1;
  435. y1 = gc->transform.clipY1;
  436. if (((w = x1 - x) == 0) || (y1 - y == 0)) {
  437. return;
  438. }
  439. fb = __GL_DEPTH_ADDR(dfb, (__GLz16Value*), x, y);
  440. skip = dfb->buf.outerWidth;
  441. // handle word overhangs onto long boundaries
  442. if( (ULONG_PTR)fb & 0x2 ) { // Left word overhang
  443. int ysav = y;
  444. __GLz16Value *fbsav = fb;
  445. for( ; y < y1; y ++, fb+=skip ) {
  446. *fb = z;
  447. }
  448. y = ysav;
  449. fb = fbsav+1;
  450. w--;
  451. }
  452. if( (ULONG)((ULONG_PTR)fb + w*sizeof(__GLz16Value)) & 0x2 ) { // Right overhang
  453. int ysav = y;
  454. __GLz16Value *fbsav = fb;
  455. w--;
  456. fb += w;
  457. for( ; y < y1; y ++, fb+=skip ) {
  458. *fb = z;
  459. }
  460. y = ysav;
  461. fb = fbsav;
  462. }
  463. // Do 4byte-aligned stuff
  464. if (skip == w)
  465. {
  466. w = w * (y1 - y) * sizeof(__GLz16Value);
  467. RtlFillMemoryUlong((PVOID) fb, (ULONG) w, (ULONG) zz);
  468. }
  469. else
  470. {
  471. if( skip & 0x1 ) { // skip is odd - successive lines will NOT be
  472. // quad-word aligned
  473. int i;
  474. for (; y < y1; y++)
  475. {
  476. for( i = 0; i < w; i ++ )
  477. *fb++ = z;
  478. fb += (skip-w);
  479. }
  480. }
  481. else {
  482. w = w * sizeof(__GLz16Value); // convert to byte count
  483. for (; y < y1; y++)
  484. {
  485. RtlFillMemoryUlong((PVOID) fb, (ULONG) w, (ULONG) zz);
  486. fb += skip;
  487. }
  488. }
  489. }
  490. }
  491. #endif // NT
  492. /************************************************************************/
  493. static GLboolean (*StoreProcs[32])(__GLdepthBuffer*, GLint, GLint, __GLzValue)
  494. = {
  495. StoreNEVER,
  496. StoreLESS,
  497. StoreEQUAL,
  498. StoreLEQUAL,
  499. StoreGREATER,
  500. StoreNOTEQUAL,
  501. StoreGEQUAL,
  502. StoreALWAYS,
  503. StoreNEVER,
  504. StoreLESS_W,
  505. StoreEQUAL_W,
  506. StoreLEQUAL_W,
  507. StoreGREATER_W,
  508. StoreNOTEQUAL_W,
  509. StoreGEQUAL_W,
  510. StoreALWAYS_W,
  511. Store16NEVER,
  512. Store16LESS,
  513. Store16EQUAL,
  514. Store16LEQUAL,
  515. Store16GREATER,
  516. Store16NOTEQUAL,
  517. Store16GEQUAL,
  518. Store16ALWAYS,
  519. Store16NEVER,
  520. Store16LESS_W,
  521. Store16EQUAL_W,
  522. Store16LEQUAL_W,
  523. Store16GREATER_W,
  524. Store16NOTEQUAL_W,
  525. Store16GEQUAL_W,
  526. Store16ALWAYS_W
  527. };
  528. static void FASTCALL Pick(__GLcontext *gc, __GLdepthBuffer *fb, GLint depthIndex)
  529. {
  530. fb->store = StoreProcs[depthIndex];
  531. fb->storeRaw = StoreProcs[depthIndex];
  532. }
  533. void FASTCALL __glInitDepth32(__GLcontext *gc, __GLdepthBuffer *fb)
  534. {
  535. fb->buf.elementSize = sizeof(__GLzValue);
  536. fb->buf.gc = gc;
  537. fb->scale = (__GLzValue) ~0;
  538. fb->writeMask = (__GLzValue) ~0;
  539. fb->pick = Pick;
  540. fb->clear = Clear;
  541. fb->store2 = StoreALWAYS;
  542. fb->fetch = Fetch;
  543. }
  544. #ifdef NT
  545. void FASTCALL __glInitDepth16(__GLcontext *gc, __GLdepthBuffer *fb)
  546. {
  547. fb->buf.elementSize = sizeof(__GLz16Value);
  548. fb->buf.gc = gc;
  549. fb->scale = (__GLz16Value) ~0;
  550. fb->writeMask = (__GLz16Value) ~0;
  551. fb->pick = Pick;
  552. fb->clear = Clear16;
  553. fb->store2 = Store16ALWAYS;
  554. fb->fetch = Fetch16;
  555. }
  556. #endif
  557. void FASTCALL __glFreeDepth32(__GLcontext *gc, __GLdepthBuffer *fb)
  558. {
  559. #ifdef __GL_LINT
  560. gc = gc;
  561. fb = fb;
  562. #endif
  563. }