t_dd_unfilled.h revision a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7f
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5.1
4 *
5 * Copyright (C) 1999-2006  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 * Authors:
25 *    Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28#if HAVE_RGBA
29#define VERT_SET_IND( v, c )
30#define VERT_COPY_IND( v0, v1 )
31#define VERT_SAVE_IND( idx )
32#define VERT_RESTORE_IND( idx )
33#endif
34
35#if !HAVE_SPEC
36#define VERT_SET_SPEC( v, c )
37#define VERT_COPY_SPEC( v0, v1 )
38#define VERT_SAVE_SPEC( idx )
39#define VERT_RESTORE_SPEC( idx )
40#endif
41
42static void TAG(unfilled_tri)( GLcontext *ctx,
43			       GLenum mode,
44			       GLuint e0, GLuint e1, GLuint e2 )
45{
46   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
47   GLubyte *ef = VB->EdgeFlag;
48   VERTEX *v[3];
49   LOCAL_VARS(3);
50
51   v[0] = (VERTEX *)GET_VERTEX(e0);
52   v[1] = (VERTEX *)GET_VERTEX(e1);
53   v[2] = (VERTEX *)GET_VERTEX(e2);
54
55   if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
56      if (HAVE_RGBA) {
57	 VERT_SAVE_RGBA(0);
58	 VERT_SAVE_RGBA(1);
59	 VERT_COPY_RGBA(v[0], v[2]);
60	 VERT_COPY_RGBA(v[1], v[2]);
61
62	 if (HAVE_SPEC) {
63	    VERT_SAVE_SPEC(0);
64	    VERT_SAVE_SPEC(1);
65	    VERT_COPY_SPEC(v[0], v[2]);
66	    VERT_COPY_SPEC(v[1], v[2]);
67	 }
68      } else {
69	 VERT_SAVE_IND(0);
70	 VERT_SAVE_IND(1);
71	 VERT_COPY_IND(v[0], v[2]);
72	 VERT_COPY_IND(v[1], v[2]);
73      }
74   }
75
76/*     fprintf(stderr, "%s %s %d %d %d\n", __FUNCTION__, */
77/*  	   _mesa_lookup_enum_by_nr( mode ), */
78/*  	   ef[e0], ef[e1], ef[e2]); */
79
80   if (mode == GL_POINT) {
81      RASTERIZE(GL_POINTS);
82      if (ef[e0]) POINT( v[0] );
83      if (ef[e1]) POINT( v[1] );
84      if (ef[e2]) POINT( v[2] );
85   }
86   else {
87      RASTERIZE(GL_LINES);
88      if (RENDER_PRIMITIVE == GL_POLYGON) {
89	 if (ef[e2]) LINE( v[2], v[0] );
90	 if (ef[e0]) LINE( v[0], v[1] );
91	 if (ef[e1]) LINE( v[1], v[2] );
92      }
93      else {
94	 if (ef[e0]) LINE( v[0], v[1] );
95	 if (ef[e1]) LINE( v[1], v[2] );
96	 if (ef[e2]) LINE( v[2], v[0] );
97      }
98   }
99
100   if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
101      if (HAVE_RGBA) {
102	 VERT_RESTORE_RGBA(0);
103	 VERT_RESTORE_RGBA(1);
104
105	 if (HAVE_SPEC) {
106	    VERT_RESTORE_SPEC(0);
107	    VERT_RESTORE_SPEC(1);
108	 }
109      } else {
110	 VERT_RESTORE_IND(0);
111	 VERT_RESTORE_IND(1);
112      }
113   }
114}
115
116
117static void TAG(unfilled_quad)( GLcontext *ctx,
118				GLenum mode,
119				GLuint e0, GLuint e1,
120				GLuint e2, GLuint e3 )
121{
122   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
123   GLubyte *ef = VB->EdgeFlag;
124   VERTEX *v[4];
125   LOCAL_VARS(4);
126
127   v[0] = (VERTEX *)GET_VERTEX(e0);
128   v[1] = (VERTEX *)GET_VERTEX(e1);
129   v[2] = (VERTEX *)GET_VERTEX(e2);
130   v[3] = (VERTEX *)GET_VERTEX(e3);
131
132   /* Hardware flatshading breaks down here.  If the hardware doesn't
133    * support flatshading, this will already have been done:
134    */
135   if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
136      if (HAVE_RGBA) {
137	 VERT_SAVE_RGBA(0);
138	 VERT_SAVE_RGBA(1);
139	 VERT_SAVE_RGBA(2);
140	 VERT_COPY_RGBA(v[0], v[3]);
141	 VERT_COPY_RGBA(v[1], v[3]);
142	 VERT_COPY_RGBA(v[2], v[3]);
143
144	 if (HAVE_SPEC) {
145	    VERT_SAVE_SPEC(0);
146	    VERT_SAVE_SPEC(1);
147	    VERT_SAVE_SPEC(2);
148	    VERT_COPY_SPEC(v[0], v[3]);
149	    VERT_COPY_SPEC(v[1], v[3]);
150	    VERT_COPY_SPEC(v[2], v[3]);
151	 }
152      } else {
153	 VERT_SAVE_IND(0);
154	 VERT_SAVE_IND(1);
155	 VERT_SAVE_IND(2);
156	 VERT_COPY_IND(v[0], v[3]);
157	 VERT_COPY_IND(v[1], v[3]);
158	 VERT_COPY_IND(v[2], v[3]);
159      }
160   }
161
162   if (mode == GL_POINT) {
163      RASTERIZE(GL_POINTS);
164      if (ef[e0]) POINT( v[0] );
165      if (ef[e1]) POINT( v[1] );
166      if (ef[e2]) POINT( v[2] );
167      if (ef[e3]) POINT( v[3] );
168   }
169   else {
170      RASTERIZE(GL_LINES);
171      if (ef[e0]) LINE( v[0], v[1] );
172      if (ef[e1]) LINE( v[1], v[2] );
173      if (ef[e2]) LINE( v[2], v[3] );
174      if (ef[e3]) LINE( v[3], v[0] );
175   }
176
177   if (ctx->Light.ShadeModel == GL_FLAT && HAVE_HW_FLATSHADE) {
178      if (HAVE_RGBA) {
179	 VERT_RESTORE_RGBA(0);
180	 VERT_RESTORE_RGBA(1);
181	 VERT_RESTORE_RGBA(2);
182
183	 if (HAVE_SPEC) {
184	    VERT_RESTORE_SPEC(0);
185	    VERT_RESTORE_SPEC(1);
186	    VERT_RESTORE_SPEC(2);
187	 }
188      } else {
189	 VERT_RESTORE_IND(0);
190	 VERT_RESTORE_IND(1);
191	 VERT_RESTORE_IND(2);
192      }
193   }
194}
195
196
197#if HAVE_RGBA
198#undef VERT_SET_IND
199#undef VERT_COPY_IND
200#undef VERT_SAVE_IND
201#undef VERT_RESTORE_IND
202#endif
203
204#if !HAVE_SPEC
205#undef VERT_SET_SPEC
206#undef VERT_COPY_SPEC
207#undef VERT_SAVE_SPEC
208#undef VERT_RESTORE_SPEC
209#endif
210
211#undef TAG
212