1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10
11
12 #include <dx/dx.h>
13 #include "render.h"
14 #include "internals.h"
15 #include "zclip.h"
16
17 #define EXTRA 30
18
19 int
_dxf_zclip_quads(struct xfield * xf,int * elements,int i,int * indices,int nelt,struct xfield * xx,inv_stat invalid_status)20 _dxf_zclip_quads(struct xfield *xf, int *elements, int i, int *indices,
21 int nelt, struct xfield *xx, inv_stat invalid_status)
22 {
23 static Triangle xtriangles[EXTRA];
24 static RGBColor xfcolors[3*EXTRA];
25 static RGBColor xbcolors[3*EXTRA];
26 static Point xpositions[3*EXTRA];
27 static float xopacities[3*EXTRA];
28 static Vector xnormals[3*EXTRA];
29 static int xindices[EXTRA];
30 InvalidComponentHandle ich =
31 (invalid_status == INV_UNKNOWN) ? xf->iElts : NULL;
32 Triangle *xtri;
33 RGBColor *xfc, *xbc;
34 Vector *xnrm;
35 Point *xpos, *positions, *p1, *p2, *p3;
36 float *xop;
37 RGBColor *fcolors = xf->fcolors;
38 RGBColor *bcolors = xf->bcolors;
39 float *opacities = xf->opacities;
40 Vector *normals = xf->normals;
41 float nearPlane = xf->nearPlane;
42
43 int fcst = xf->fcst;
44 int bcst = xf->bcst;
45 int ncst = xf->ncst;
46 int ocst = xf->ocst;
47
48
49 int nxtri, nxpt, v1, v2, v3, interp_colors, interp_normals;
50 float z1, z2, z3;
51
52 RGBColor *cmap = xf->cmap;
53 float *omap = xf->omap;
54
55 /* no clipping to do? */
56 if (xf->box[7].z <= nearPlane) {
57 xx->nconnections = 0;
58 DXDebug("R", "%d triangles accepted", nelt);
59 return nelt;
60 }
61
62 positions = xf->positions;
63
64 xfc = xfcolors;
65 xbc = xbcolors;
66 xpos = xpositions;
67 xop = xopacities;
68 xnrm = xnormals;
69
70 xpos = xpositions;
71 xtri = xtriangles;
72 nxtri = 0;
73 nxpt = 0;
74
75 interp_colors = xf->colors_dep == dep_positions;
76 interp_normals = xf->normals && xf->normals_dep==dep_positions;
77
78 for (elements += 4*i; i<nelt && nxtri<EXTRA-4; i++, elements += 4) {
79
80 if (ich && DXIsElementInvalid(ich, i))
81 continue;
82 v1 = elements[0];
83 v2 = elements[2];
84 v3 = elements[1];
85 p1 = &positions[v1];
86 p2 = &positions[v2];
87 p3 = &positions[v3];
88 z1 = p1->z;
89 z2 = p2->z;
90 z3 = p3->z;
91 TRYCLIP(z1,z2,z3, p1,p2,p3, v1,v2,v3) else
92 TRYCLIP(z2,z3,z1, p2,p3,p1, v2,v3,v1) else
93 TRYCLIP(z3,z1,z2, p3,p1,p2, v3,v1,v2)
94
95 v1 = elements[1];
96 v2 = elements[2];
97 v3 = elements[3];
98 p1 = &positions[v1];
99 p2 = &positions[v2];
100 p3 = &positions[v3];
101 z1 = p1->z;
102 z2 = p2->z;
103 z3 = p3->z;
104 TRYCLIP(z1,z2,z3, p1,p2,p3, v1,v2,v3) else
105 TRYCLIP(z2,z3,z1, p2,p3,p1, v2,v3,v1) else
106 TRYCLIP(z3,z1,z2, p3,p1,p2, v3,v1,v2)
107 }
108
109 if (nxtri) {
110 *xx = *xf;
111 xx->cmap = NULL;
112 xx->omap = NULL;
113 xx->fcolors = fcolors? (Pointer)xfcolors : NULL;
114 xx->bcolors = bcolors? (Pointer)xbcolors : NULL;
115 xx->opacities = opacities? (Pointer)xopacities : NULL;
116 xx->positions = positions? xpositions : NULL;
117 xx->normals = normals? xnormals : NULL;
118 xx->indices = indices? xindices : NULL;
119 xx->c.triangles = xtriangles;
120 xx->lights = xf->lights;
121 }
122 DXDebug("R", "%d triangles in, %d clipped triangles out", nelt, nxtri);
123 xx->nconnections = nxtri;
124
125 return i;
126 }
127