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.

t_dd_tritmp.h 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 3.5
  4. *
  5. * Copyright (C) 1999 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. * Author:
  25. * Keith Whitwell <keithw@valinux.com>
  26. */
  27. /* Template for building functions to plug into the driver interface
  28. * of t_vb_render.c:
  29. * ctx->Driver.QuadFunc
  30. * ctx->Driver.TriangleFunc
  31. * ctx->Driver.LineFunc
  32. * ctx->Driver.PointsFunc
  33. *
  34. * DO_TWOSIDE: Plug back-color values from the VB into backfacing triangles,
  35. * and restore vertices afterwards.
  36. * DO_OFFSET: Calculate offset for triangles and adjust vertices. Restore
  37. * vertices after rendering.
  38. * DO_FLAT: For hardware without native flatshading, copy provoking colors
  39. * into the other vertices. Restore after rendering.
  40. * DO_UNFILLED: Decompose triangles to lines and points where appropriate.
  41. *
  42. * HAVE_RGBA: Vertices have rgba values (otherwise index values).
  43. * HAVE_SPEC: Vertices have secondary rgba values.
  44. *
  45. * VERT_X(v): Alias for vertex x value.
  46. * VERT_Y(v): Alias for vertex x value.
  47. * VERT_Z(v): Alias for vertex x value.
  48. * DEPTH_SCALE: Scale for offset.
  49. *
  50. * VERTEX: Hardware vertex type.
  51. * GET_VERTEX(n): Retreive vertex with index n.
  52. * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw.
  53. *
  54. * VERT_SET_RGBA: Assign vertex rgba from VB color.
  55. * VERT_COPY_RGBA: Copy vertex rgba another vertex.
  56. * VERT_SAVE_RGBA: Save vertex rgba to a local variable.
  57. * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable.
  58. * --> Similar for IND and SPEC.
  59. *
  60. * LOCAL_VARS(n): (At least) define local vars for save/restore rgba.
  61. *
  62. */
  63. #if HAVE_RGBA
  64. #define VERT_SET_IND( v, c ) (void) c
  65. #define VERT_COPY_IND( v0, v1 )
  66. #define VERT_SAVE_IND( idx )
  67. #define VERT_RESTORE_IND( idx )
  68. #if HAVE_BACK_COLORS
  69. #define VERT_SET_RGBA( v, c )
  70. #endif
  71. #else
  72. #define VERT_SET_RGBA( v, c ) (void) c
  73. #define VERT_COPY_RGBA( v0, v1 )
  74. #define VERT_SAVE_RGBA( idx )
  75. #define VERT_RESTORE_RGBA( idx )
  76. #if HAVE_BACK_COLORS
  77. #define VERT_SET_IND( v, c )
  78. #endif
  79. #endif
  80. #if !HAVE_SPEC
  81. #define VERT_SET_SPEC( v, c ) (void) c
  82. #define VERT_COPY_SPEC( v0, v1 )
  83. #define VERT_SAVE_SPEC( idx )
  84. #define VERT_RESTORE_SPEC( idx )
  85. #if HAVE_BACK_COLORS
  86. #define VERT_COPY_SPEC1( v )
  87. #endif
  88. #else
  89. #if HAVE_BACK_COLORS
  90. #define VERT_SET_SPEC( v, c )
  91. #endif
  92. #endif
  93. #if !HAVE_BACK_COLORS
  94. #define VERT_COPY_SPEC1( v )
  95. #define VERT_COPY_IND1( v )
  96. #define VERT_COPY_RGBA1( v )
  97. #endif
  98. #ifndef INSANE_VERTICES
  99. #define VERT_SET_Z(v,val) VERT_Z(v) = val
  100. #define VERT_Z_ADD(v,val) VERT_Z(v) += val
  101. #endif
  102. #if DO_TRI
  103. static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  104. {
  105. struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
  106. VERTEX *v[3];
  107. GLfloat offset;
  108. GLfloat z[3];
  109. GLenum mode = GL_FILL;
  110. GLuint facing;
  111. LOCAL_VARS(3);
  112. /* fprintf(stderr, "%s\n", __FUNCTION__); */
  113. v[0] = (VERTEX *)GET_VERTEX(e0);
  114. v[1] = (VERTEX *)GET_VERTEX(e1);
  115. v[2] = (VERTEX *)GET_VERTEX(e2);
  116. if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED)
  117. {
  118. GLfloat ex = VERT_X(v[0]) - VERT_X(v[2]);
  119. GLfloat ey = VERT_Y(v[0]) - VERT_Y(v[2]);
  120. GLfloat fx = VERT_X(v[1]) - VERT_X(v[2]);
  121. GLfloat fy = VERT_Y(v[1]) - VERT_Y(v[2]);
  122. GLfloat cc = ex*fy - ey*fx;
  123. if (DO_TWOSIDE || DO_UNFILLED)
  124. {
  125. facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
  126. if (DO_UNFILLED) {
  127. if (facing) {
  128. mode = ctx->Polygon.BackMode;
  129. if (ctx->Polygon.CullFlag &&
  130. ctx->Polygon.CullFaceMode != GL_FRONT) {
  131. return;
  132. }
  133. } else {
  134. mode = ctx->Polygon.FrontMode;
  135. if (ctx->Polygon.CullFlag &&
  136. ctx->Polygon.CullFaceMode != GL_BACK) {
  137. return;
  138. }
  139. }
  140. }
  141. if (DO_TWOSIDE && facing == 1)
  142. {
  143. if (HAVE_RGBA) {
  144. if (HAVE_BACK_COLORS) {
  145. if (!DO_FLAT) {
  146. VERT_SAVE_RGBA( 0 );
  147. VERT_SAVE_RGBA( 1 );
  148. VERT_COPY_RGBA1( v[0] );
  149. VERT_COPY_RGBA1( v[1] );
  150. }
  151. VERT_SAVE_RGBA( 2 );
  152. VERT_COPY_RGBA1( v[2] );
  153. if (HAVE_SPEC) {
  154. if (!DO_FLAT) {
  155. VERT_SAVE_SPEC( 0 );
  156. VERT_SAVE_SPEC( 1 );
  157. VERT_COPY_SPEC1( v[0] );
  158. VERT_COPY_SPEC1( v[1] );
  159. }
  160. VERT_SAVE_SPEC( 2 );
  161. VERT_COPY_SPEC1( v[2] );
  162. }
  163. }
  164. else {
  165. GLchan (*vbcolor)[4] = VB->ColorPtr[1]->data;
  166. ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLchan));
  167. (void) vbcolor;
  168. if (!DO_FLAT) {
  169. VERT_SET_RGBA( v[0], vbcolor[e0] );
  170. VERT_SET_RGBA( v[1], vbcolor[e1] );
  171. }
  172. VERT_SET_RGBA( v[2], vbcolor[e2] );
  173. if (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
  174. GLchan (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
  175. if (!DO_FLAT) {
  176. VERT_SET_SPEC( v[0], vbspec[e0] );
  177. VERT_SET_SPEC( v[1], vbspec[e1] );
  178. }
  179. VERT_SET_SPEC( v[2], vbspec[e2] );
  180. }
  181. }
  182. }
  183. else {
  184. GLuint *vbindex = VB->IndexPtr[1]->data;
  185. if (!DO_FLAT) {
  186. VERT_SET_IND( v[0], vbindex[e0] );
  187. VERT_SET_IND( v[1], vbindex[e1] );
  188. }
  189. VERT_SET_IND( v[2], vbindex[e2] );
  190. }
  191. }
  192. }
  193. if (DO_OFFSET)
  194. {
  195. offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
  196. z[0] = VERT_Z(v[0]);
  197. z[1] = VERT_Z(v[1]);
  198. z[2] = VERT_Z(v[2]);
  199. if (cc * cc > 1e-16) {
  200. GLfloat ic = 1.0 / cc;
  201. GLfloat ez = z[0] - z[2];
  202. GLfloat fz = z[1] - z[2];
  203. GLfloat a = ey*fz - ez*fy;
  204. GLfloat b = ez*fx - ex*fz;
  205. GLfloat ac = a * ic;
  206. GLfloat bc = b * ic;
  207. if ( ac < 0.0f ) ac = -ac;
  208. if ( bc < 0.0f ) bc = -bc;
  209. offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
  210. }
  211. offset *= ctx->MRD;
  212. }
  213. }
  214. if (DO_FLAT) {
  215. if (HAVE_RGBA) {
  216. VERT_SAVE_RGBA( 0 );
  217. VERT_SAVE_RGBA( 1 );
  218. VERT_COPY_RGBA( v[0], v[2] );
  219. VERT_COPY_RGBA( v[1], v[2] );
  220. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  221. VERT_SAVE_SPEC( 0 );
  222. VERT_SAVE_SPEC( 1 );
  223. VERT_COPY_SPEC( v[0], v[2] );
  224. VERT_COPY_SPEC( v[1], v[2] );
  225. }
  226. }
  227. else {
  228. VERT_SAVE_IND( 0 );
  229. VERT_SAVE_IND( 1 );
  230. VERT_COPY_IND( v[0], v[2] );
  231. VERT_COPY_IND( v[1], v[2] );
  232. }
  233. }
  234. if (mode == GL_POINT) {
  235. if (DO_OFFSET && ctx->Polygon.OffsetPoint) {
  236. VERT_Z_ADD(v[0], offset);
  237. VERT_Z_ADD(v[1], offset);
  238. VERT_Z_ADD(v[2], offset);
  239. }
  240. UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
  241. } else if (mode == GL_LINE) {
  242. if (DO_OFFSET && ctx->Polygon.OffsetLine) {
  243. VERT_Z_ADD(v[0], offset);
  244. VERT_Z_ADD(v[1], offset);
  245. VERT_Z_ADD(v[2], offset);
  246. }
  247. UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
  248. } else {
  249. if (DO_OFFSET && ctx->Polygon.OffsetFill) {
  250. VERT_Z_ADD(v[0], offset);
  251. VERT_Z_ADD(v[1], offset);
  252. VERT_Z_ADD(v[2], offset);
  253. }
  254. if (DO_UNFILLED)
  255. RASTERIZE( GL_TRIANGLES );
  256. TRI( v[0], v[1], v[2] );
  257. }
  258. if (DO_OFFSET)
  259. {
  260. VERT_SET_Z(v[0], z[0]);
  261. VERT_SET_Z(v[1], z[1]);
  262. VERT_SET_Z(v[2], z[2]);
  263. }
  264. if (DO_TWOSIDE && facing == 1)
  265. {
  266. if (HAVE_RGBA) {
  267. if (HAVE_BACK_COLORS) {
  268. VERT_RESTORE_RGBA( 0 );
  269. VERT_RESTORE_RGBA( 1 );
  270. VERT_RESTORE_RGBA( 2 );
  271. if (HAVE_SPEC) {
  272. VERT_RESTORE_SPEC( 0 );
  273. VERT_RESTORE_SPEC( 1 );
  274. VERT_RESTORE_SPEC( 2 );
  275. }
  276. }
  277. else {
  278. GLchan (*vbcolor)[4] = VB->ColorPtr[0]->data;
  279. ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLchan));
  280. (void) vbcolor;
  281. if (!DO_FLAT) {
  282. VERT_SET_RGBA( v[0], vbcolor[e0] );
  283. VERT_SET_RGBA( v[1], vbcolor[e1] );
  284. }
  285. VERT_SET_RGBA( v[2], vbcolor[e2] );
  286. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  287. GLchan (*vbspec)[4] = VB->SecondaryColorPtr[0]->data;
  288. ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLchan));
  289. if (!DO_FLAT) {
  290. VERT_SET_SPEC( v[0], vbspec[e0] );
  291. VERT_SET_SPEC( v[1], vbspec[e1] );
  292. }
  293. VERT_SET_SPEC( v[2], vbspec[e2] );
  294. }
  295. }
  296. }
  297. else {
  298. GLuint *vbindex = VB->IndexPtr[0]->data;
  299. if (!DO_FLAT) {
  300. VERT_SET_IND( v[0], vbindex[e0] );
  301. VERT_SET_IND( v[1], vbindex[e1] );
  302. }
  303. VERT_SET_IND( v[2], vbindex[e2] );
  304. }
  305. }
  306. if (DO_FLAT) {
  307. if (HAVE_RGBA) {
  308. VERT_RESTORE_RGBA( 0 );
  309. VERT_RESTORE_RGBA( 1 );
  310. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  311. VERT_RESTORE_SPEC( 0 );
  312. VERT_RESTORE_SPEC( 1 );
  313. }
  314. }
  315. else {
  316. VERT_RESTORE_IND( 0 );
  317. VERT_RESTORE_IND( 1 );
  318. }
  319. }
  320. }
  321. #endif
  322. #if DO_QUAD
  323. #if DO_FULL_QUAD
  324. static void TAG(quad)( GLcontext *ctx,
  325. GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
  326. {
  327. struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
  328. VERTEX *v[4];
  329. GLfloat offset;
  330. GLfloat z[4];
  331. GLenum mode = GL_FILL;
  332. GLuint facing;
  333. LOCAL_VARS(4);
  334. v[0] = (VERTEX *)GET_VERTEX(e0);
  335. v[1] = (VERTEX *)GET_VERTEX(e1);
  336. v[2] = (VERTEX *)GET_VERTEX(e2);
  337. v[3] = (VERTEX *)GET_VERTEX(e3);
  338. if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED)
  339. {
  340. GLfloat ex = VERT_X(v[2]) - VERT_X(v[0]);
  341. GLfloat ey = VERT_Y(v[2]) - VERT_Y(v[0]);
  342. GLfloat fx = VERT_X(v[3]) - VERT_X(v[1]);
  343. GLfloat fy = VERT_Y(v[3]) - VERT_Y(v[1]);
  344. GLfloat cc = ex*fy - ey*fx;
  345. if (DO_TWOSIDE || DO_UNFILLED)
  346. {
  347. facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
  348. if (DO_UNFILLED) {
  349. if (facing) {
  350. mode = ctx->Polygon.BackMode;
  351. if (ctx->Polygon.CullFlag &&
  352. ctx->Polygon.CullFaceMode != GL_FRONT) {
  353. return;
  354. }
  355. } else {
  356. mode = ctx->Polygon.FrontMode;
  357. if (ctx->Polygon.CullFlag &&
  358. ctx->Polygon.CullFaceMode != GL_BACK) {
  359. return;
  360. }
  361. }
  362. }
  363. if (DO_TWOSIDE && facing == 1)
  364. {
  365. if (HAVE_RGBA) {
  366. GLchan (*vbcolor)[4] = VB->ColorPtr[1]->data;
  367. (void)vbcolor;
  368. if (!DO_FLAT) {
  369. VERT_SET_RGBA( v[0], vbcolor[e0] );
  370. VERT_SET_RGBA( v[1], vbcolor[e1] );
  371. VERT_SET_RGBA( v[2], vbcolor[e2] );
  372. }
  373. VERT_SET_RGBA( v[3], vbcolor[e3] );
  374. if (HAVE_SPEC && VB->SecondaryColorPtr[facing]) {
  375. GLchan (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
  376. ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLchan));
  377. if (!DO_FLAT) {
  378. VERT_SET_SPEC( v[0], vbspec[e0] );
  379. VERT_SET_SPEC( v[1], vbspec[e1] );
  380. VERT_SET_SPEC( v[2], vbspec[e2] );
  381. }
  382. VERT_SET_SPEC( v[3], vbspec[e3] );
  383. }
  384. }
  385. else {
  386. GLuint *vbindex = VB->IndexPtr[1]->data;
  387. if (!DO_FLAT) {
  388. VERT_SET_IND( v[0], vbindex[e0] );
  389. VERT_SET_IND( v[1], vbindex[e1] );
  390. VERT_SET_IND( v[2], vbindex[e2] );
  391. }
  392. VERT_SET_IND( v[3], vbindex[e3] );
  393. }
  394. }
  395. }
  396. if (DO_OFFSET)
  397. {
  398. offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
  399. z[0] = VERT_Z(v[0]);
  400. z[1] = VERT_Z(v[1]);
  401. z[2] = VERT_Z(v[2]);
  402. z[3] = VERT_Z(v[3]);
  403. if (cc * cc > 1e-16) {
  404. GLfloat ez = z[2] - z[0];
  405. GLfloat fz = z[3] - z[1];
  406. GLfloat a = ey*fz - ez*fy;
  407. GLfloat b = ez*fx - ex*fz;
  408. GLfloat ic = 1.0 / cc;
  409. GLfloat ac = a * ic;
  410. GLfloat bc = b * ic;
  411. if ( ac < 0.0f ) ac = -ac;
  412. if ( bc < 0.0f ) bc = -bc;
  413. offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
  414. }
  415. offset *= ctx->MRD;
  416. }
  417. }
  418. if (DO_FLAT) {
  419. if (HAVE_RGBA) {
  420. VERT_SAVE_RGBA( 0 );
  421. VERT_SAVE_RGBA( 1 );
  422. VERT_SAVE_RGBA( 2 );
  423. VERT_COPY_RGBA( v[0], v[3] );
  424. VERT_COPY_RGBA( v[1], v[3] );
  425. VERT_COPY_RGBA( v[2], v[3] );
  426. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  427. VERT_SAVE_SPEC( 0 );
  428. VERT_SAVE_SPEC( 1 );
  429. VERT_SAVE_SPEC( 2 );
  430. VERT_COPY_SPEC( v[0], v[3] );
  431. VERT_COPY_SPEC( v[1], v[3] );
  432. VERT_COPY_SPEC( v[2], v[3] );
  433. }
  434. }
  435. else {
  436. VERT_SAVE_IND( 0 );
  437. VERT_SAVE_IND( 1 );
  438. VERT_SAVE_IND( 2 );
  439. VERT_COPY_IND( v[0], v[3] );
  440. VERT_COPY_IND( v[1], v[3] );
  441. VERT_COPY_IND( v[2], v[3] );
  442. }
  443. }
  444. if (mode == GL_POINT) {
  445. if (( DO_OFFSET) && ctx->Polygon.OffsetPoint) {
  446. VERT_Z_ADD(v[0], offset);
  447. VERT_Z_ADD(v[1], offset);
  448. VERT_Z_ADD(v[2], offset);
  449. VERT_Z_ADD(v[3], offset);
  450. }
  451. UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
  452. } else if (mode == GL_LINE) {
  453. if (DO_OFFSET && ctx->Polygon.OffsetLine) {
  454. VERT_Z_ADD(v[0], offset);
  455. VERT_Z_ADD(v[1], offset);
  456. VERT_Z_ADD(v[2], offset);
  457. VERT_Z_ADD(v[3], offset);
  458. }
  459. UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
  460. } else {
  461. if (DO_OFFSET && ctx->Polygon.OffsetFill) {
  462. VERT_Z_ADD(v[0], offset);
  463. VERT_Z_ADD(v[1], offset);
  464. VERT_Z_ADD(v[2], offset);
  465. VERT_Z_ADD(v[3], offset);
  466. }
  467. RASTERIZE( GL_TRIANGLES );
  468. QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
  469. }
  470. if (DO_OFFSET)
  471. {
  472. VERT_SET_Z(v[0], z[0]);
  473. VERT_SET_Z(v[1], z[1]);
  474. VERT_SET_Z(v[2], z[2]);
  475. VERT_SET_Z(v[3], z[3]);
  476. }
  477. if (DO_TWOSIDE && facing == 1)
  478. {
  479. if (HAVE_RGBA) {
  480. GLchan (*vbcolor)[4] = VB->ColorPtr[0]->data;
  481. ASSERT(VB->ColorPtr[0]->stride == 4*sizeof(GLchan));
  482. (void) vbcolor;
  483. if (!DO_FLAT) {
  484. VERT_SET_RGBA( v[0], vbcolor[e0] );
  485. VERT_SET_RGBA( v[1], vbcolor[e1] );
  486. VERT_SET_RGBA( v[2], vbcolor[e2] );
  487. }
  488. VERT_SET_RGBA( v[3], vbcolor[e3] );
  489. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  490. GLchan (*vbspec)[4] = VB->SecondaryColorPtr[0]->data;
  491. ASSERT(VB->SecondaryColorPtr[0]->stride == 4*sizeof(GLchan));
  492. if (!DO_FLAT) {
  493. VERT_SET_SPEC( v[0], vbspec[e0] );
  494. VERT_SET_SPEC( v[1], vbspec[e1] );
  495. VERT_SET_SPEC( v[2], vbspec[e2] );
  496. }
  497. VERT_SET_SPEC( v[3], vbspec[e3] );
  498. }
  499. }
  500. else {
  501. GLuint *vbindex = VB->IndexPtr[0]->data;
  502. if (!DO_FLAT) {
  503. VERT_SET_IND( v[0], vbindex[e0] );
  504. VERT_SET_IND( v[1], vbindex[e1] );
  505. VERT_SET_IND( v[2], vbindex[e2] );
  506. }
  507. VERT_SET_IND( v[3], vbindex[e3] );
  508. }
  509. }
  510. if (DO_FLAT) {
  511. if (HAVE_RGBA) {
  512. VERT_RESTORE_RGBA( 0 );
  513. VERT_RESTORE_RGBA( 1 );
  514. VERT_RESTORE_RGBA( 2 );
  515. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  516. VERT_RESTORE_SPEC( 0 );
  517. VERT_RESTORE_SPEC( 1 );
  518. VERT_RESTORE_SPEC( 2 );
  519. }
  520. }
  521. else {
  522. VERT_RESTORE_IND( 0 );
  523. VERT_RESTORE_IND( 1 );
  524. VERT_RESTORE_IND( 2 );
  525. }
  526. }
  527. }
  528. #else
  529. static void TAG(quad)( GLcontext *ctx, GLuint e0,
  530. GLuint e1, GLuint e2, GLuint e3 )
  531. {
  532. if (DO_UNFILLED) {
  533. struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
  534. GLubyte ef1 = VB->EdgeFlag[e1];
  535. GLubyte ef3 = VB->EdgeFlag[e3];
  536. VB->EdgeFlag[e1] = 0;
  537. TAG(triangle)( ctx, e0, e1, e3 );
  538. VB->EdgeFlag[e1] = ef1;
  539. VB->EdgeFlag[e3] = 0;
  540. TAG(triangle)( ctx, e1, e2, e3 );
  541. VB->EdgeFlag[e3] = ef3;
  542. } else {
  543. TAG(triangle)( ctx, e0, e1, e3 );
  544. TAG(triangle)( ctx, e1, e2, e3 );
  545. }
  546. }
  547. #endif
  548. #endif
  549. #if DO_LINE
  550. static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
  551. {
  552. TNLvertexbuffer *VB = &TNL_CONTEXT(ctx)->vb;
  553. VERTEX *v[2];
  554. LOCAL_VARS(2);
  555. v[0] = (VERTEX *)GET_VERTEX(e0);
  556. v[1] = (VERTEX *)GET_VERTEX(e1);
  557. if (DO_FLAT) {
  558. if (HAVE_RGBA) {
  559. VERT_SAVE_RGBA( 0 );
  560. VERT_COPY_RGBA( v[0], v[1] );
  561. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  562. VERT_SAVE_SPEC( 0 );
  563. VERT_COPY_SPEC( v[0], v[1] );
  564. }
  565. }
  566. else {
  567. VERT_SAVE_IND( 0 );
  568. VERT_COPY_IND( v[0], v[1] );
  569. }
  570. }
  571. LINE( v[0], v[1] );
  572. if (DO_FLAT) {
  573. if (HAVE_RGBA) {
  574. VERT_RESTORE_RGBA( 0 );
  575. if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
  576. VERT_RESTORE_SPEC( 0 );
  577. }
  578. }
  579. else {
  580. VERT_RESTORE_IND( 0 );
  581. }
  582. }
  583. }
  584. #endif
  585. #if DO_POINT
  586. static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
  587. {
  588. struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
  589. int i;
  590. LOCAL_VARS(1);
  591. if (VB->Elts == 0) {
  592. for ( i = first ; i < last ; i++ ) {
  593. if ( VB->ClipMask[i] == 0 ) {
  594. VERTEX *v = (VERTEX *)GET_VERTEX(i);
  595. POINT( v );
  596. }
  597. }
  598. } else {
  599. for ( i = first ; i < last ; i++ ) {
  600. GLuint e = VB->Elts[i];
  601. if ( VB->ClipMask[e] == 0 ) {
  602. VERTEX *v = (VERTEX *)GET_VERTEX(e);
  603. POINT( v );
  604. }
  605. }
  606. }
  607. }
  608. #endif
  609. static void TAG(init)( void )
  610. {
  611. #if DO_QUAD
  612. TAB[IND].quad = TAG(quad);
  613. #endif
  614. #if DO_TRI
  615. TAB[IND].triangle = TAG(triangle);
  616. #endif
  617. #if DO_LINE
  618. TAB[IND].line = TAG(line);
  619. #endif
  620. #if DO_POINT
  621. TAB[IND].points = TAG(points);
  622. #endif
  623. }
  624. #undef IND
  625. #undef TAG
  626. #if HAVE_RGBA
  627. #undef VERT_SET_IND
  628. #undef VERT_COPY_IND
  629. #undef VERT_SAVE_IND
  630. #undef VERT_RESTORE_IND
  631. #if HAVE_BACK_COLORS
  632. #undef VERT_SET_RGBA
  633. #endif
  634. #else
  635. #undef VERT_SET_RGBA
  636. #undef VERT_COPY_RGBA
  637. #undef VERT_SAVE_RGBA
  638. #undef VERT_RESTORE_RGBA
  639. #if HAVE_BACK_COLORS
  640. #undef VERT_SET_IND
  641. #endif
  642. #endif
  643. #if !HAVE_SPEC
  644. #undef VERT_SET_SPEC
  645. #undef VERT_COPY_SPEC
  646. #undef VERT_SAVE_SPEC
  647. #undef VERT_RESTORE_SPEC
  648. #if HAVE_BACK_COLORS
  649. #undef VERT_COPY_SPEC1
  650. #endif
  651. #else
  652. #if HAVE_BACK_COLORS
  653. #undef VERT_SET_SPEC
  654. #endif
  655. #endif
  656. #if !HAVE_BACK_COLORS
  657. #undef VERT_COPY_SPEC1
  658. #undef VERT_COPY_IND1
  659. #undef VERT_COPY_RGBA1
  660. #endif
  661. #ifndef INSANE_VERTICES
  662. #undef VERT_SET_Z
  663. #undef VERT_Z_ADD
  664. #endif