]> icculus.org git repositories - taylor/freespace2.git/blob - include/line.h
remove cpu detection stuff
[taylor/freespace2.git] / include / line.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/Line.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for line.cpp
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:13  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 2     10/07/98 10:53a Dave
26  * Initial checkin.
27  * 
28  * 1     10/07/98 10:49a Dave
29  * 
30  * 10    5/06/98 5:30p John
31  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
32  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
33  * DirectX header files and libs that fixed the Direct3D alpha blending
34  * problems.
35  * 
36  * 9     3/10/98 4:18p John
37  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
38  * & Glide have popups and print screen.  Took out all >8bpp software
39  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
40  * support Fred.  Made zbuffering key off of functions rather than one
41  * global variable.
42  * 
43  * 8     10/03/97 9:10a John
44  * added better antialiased line drawer
45  * 
46  * 7     6/13/97 5:35p John
47  * added some antialiased bitmaps and lines
48  * 
49  * 6     11/26/96 6:50p John
50  * Added some more hicolor primitives.  Made windowed mode run as current
51  * bpp, if bpp is 8,16,or 32.
52  * 
53  * 5     10/26/96 2:56p John
54  * Got gradient code working.
55  * 
56  * 4     10/26/96 1:40p John
57  * Added some now primitives to the 2d library and
58  * cleaned up some old ones.
59  *
60  * $NoKeywords: $
61  */
62
63 #ifndef _LINE_H
64 #define _LINE_H
65
66 void gr8_line(int x1,int y1,int x2,int y2);
67 void gr8_aaline(vertex *v1, vertex *v2);
68                                                                                         
69
70 #define INT_EXCHG(a,b) do {                                              \
71     int __temp__ = (a);                                                 \
72     (a) = (b);                                                          \
73     (b) = __temp__;                                                     \
74 } while(0)
75
76 //#define INT_SCALE(var,arg,num,den) ((var) = ((arg) * (num)) / (den))
77 #define INT_SCALE(var,arg,num,den) ((var) = mul_div(arg, num, den))
78
79 #define INT_CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,WHEN_SWAPPED) do {                                    \
80     int temp;                                                  \
81                                                                         \
82     if(y1 > y2)                                                         \
83         { INT_EXCHG(y1,y2); INT_EXCHG(x1,x2); WHEN_SWAPPED; }                                 \
84     if((y2 < YMIN) || (y1 > YMAX))                    \
85         { WHEN_OUTSIDE; }                                               \
86     if(x1 < x2) {                                                       \
87         if((x2 < XMIN) || (x1 > XMAX)) {              \
88             WHEN_OUTSIDE;                                               \
89         }                                                               \
90         if(x1 < XMIN) {                                        \
91                         INT_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1));      \
92             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
93             x1 = XMIN;                                         \
94             WHEN_CLIPPED;                                               \
95         }                                                               \
96         if(x2 > XMAX) {                                        \
97                         INT_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1));      \
98             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
99             x2 = XMAX;                                         \
100             WHEN_CLIPPED;                                               \
101         }                                                               \
102         if(y1 < YMIN) {                                        \
103                         INT_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1));      \
104             x1 += temp;                                                 \
105             y1 = YMIN;                                         \
106             WHEN_CLIPPED;                                               \
107         }                                                               \
108         if(y2 > YMAX) {                                        \
109                         INT_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1));      \
110             x2 -= temp;                                                 \
111             y2 = YMAX;                                         \
112             WHEN_CLIPPED;                                               \
113         }                                                               \
114     }                                                                   \
115     else {                                                              \
116         if((x1 < XMIN) || (x2 > XMAX)) {              \
117             WHEN_OUTSIDE;                                               \
118         }                                                               \
119         if(x1 > XMAX) {                                        \
120                         INT_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2));      \
121             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
122             x1 = XMAX;                                         \
123             WHEN_CLIPPED;                                               \
124         }                                                               \
125         if(x2 < XMIN) {                                        \
126                         INT_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2));      \
127             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
128             x2 = XMIN;                                         \
129             WHEN_CLIPPED;                                               \
130         }                                                               \
131         if(y1 < YMIN) {                                        \
132                         INT_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1));      \
133             x1 -= temp;                                                 \
134             y1 = YMIN;                                         \
135             WHEN_CLIPPED;                                               \
136         }                                                               \
137         if(y2 > YMAX) {                                        \
138                         INT_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1));      \
139             x2 += temp;                                                 \
140             y2 = YMAX;                                         \
141             WHEN_CLIPPED;                                               \
142         }                                                               \
143     }                                                                   \
144 } while(0)
145
146 #define FL_EXCHG(a,b) do {                                                 \
147     float __temp__ = (a);                                                 \
148     (a) = (b);                                                          \
149     (b) = __temp__;                                                     \
150 } while(0)
151
152 #define FL_SCALE(var,arg,num,den) ((var) = ((arg) * (num)) / (den))
153
154 #define FL_CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,WHEN_SWAPPED) do {                                    \
155     float temp;                                                  \
156                                                                         \
157     if(y1 > y2)                                                         \
158         { FL_EXCHG(y1,y2); FL_EXCHG(x1,x2); WHEN_SWAPPED; }                                 \
159     if((y2 < YMIN) || (y1 > YMAX))                    \
160         { WHEN_OUTSIDE; }                                               \
161     if(x1 < x2) {                                                       \
162         if((x2 < XMIN) || (x1 > XMAX)) {              \
163             WHEN_OUTSIDE;                                               \
164         }                                                               \
165         if(x1 < XMIN) {                                        \
166                         FL_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1));      \
167             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
168             x1 = XMIN;                                         \
169             WHEN_CLIPPED;                                               \
170         }                                                               \
171         if(x2 > XMAX) {                                        \
172                         FL_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1));      \
173             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
174             x2 = XMAX;                                         \
175             WHEN_CLIPPED;                                               \
176         }                                                               \
177         if(y1 < YMIN) {                                        \
178                         FL_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1));      \
179             x1 += temp;                                                 \
180             y1 = YMIN;                                         \
181             WHEN_CLIPPED;                                               \
182         }                                                               \
183         if(y2 > YMAX) {                                        \
184                         FL_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1));      \
185             x2 -= temp;                                                 \
186             y2 = YMAX;                                         \
187             WHEN_CLIPPED;                                               \
188         }                                                               \
189     }                                                                   \
190     else {                                                              \
191         if((x1 < XMIN) || (x2 > XMAX)) {              \
192             WHEN_OUTSIDE;                                               \
193         }                                                               \
194         if(x1 > XMAX) {                                        \
195                         FL_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2));      \
196             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
197             x1 = XMAX;                                         \
198             WHEN_CLIPPED;                                               \
199         }                                                               \
200         if(x2 < XMIN) {                                        \
201                         FL_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2));      \
202             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
203             x2 = XMIN;                                         \
204             WHEN_CLIPPED;                                               \
205         }                                                               \
206         if(y1 < YMIN) {                                        \
207                         FL_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1));      \
208             x1 -= temp;                                                 \
209             y1 = YMIN;                                         \
210             WHEN_CLIPPED;                                               \
211         }                                                               \
212         if(y2 > YMAX) {                                        \
213                         FL_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1));      \
214             x2 += temp;                                                 \
215             y2 = YMAX;                                         \
216             WHEN_CLIPPED;                                               \
217         }                                                               \
218     }                                                                   \
219 } while(0)
220
221 #endif
222