1 /* $Id: fixed.h,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2 
3 /*
4  * Mesa 3-D graphics library
5  * Version:  2.0
6  * Copyright (C) 1995-1996  Brian Paul
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 #ifndef FIXED_H
24 #define FIXED_H
25 
26 
27 typedef int GLfixed;
28 
29 #define FIXED_ONE       0x00000800
30 #define FIXED_HALF      0x00000400
31 #define FIXED_FRAC_MASK 0x000007FF
32 #define FIXED_INT_MASK  (~FIXED_FRAC_MASK)
33 #define FIXED_EPSILON   1
34 #define FIXED_SCALE     2048.0f
35 #define FIXED_SHIFT     11
36 #define FloatToFixed(X) ((GLfixed) ((X) * FIXED_SCALE))
37 #define IntToFixed(I)   ((I) << FIXED_SHIFT)
38 #define FixedToInt(X)   ((X) >> FIXED_SHIFT)
39 #define FixedToUns(X)   (((unsigned int)(X)) >> 11)
40 #define FixedCeil(X)    (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK)
41 #define FixedFloor(X)   ((X) & FIXED_INT_MASK)
42 /* 0.00048828125 = 1/FIXED_SCALE */
43 #define FixedToFloat(X) ((X) * 0.00048828125f)
44 #define PosFloatToFixed(X)      FloatToFixed(X)
45 #define SignedFloatToFixed(X)   FloatToFixed(X)
46 
47 
48 #if DEPTH_BITS==16
49 /* use fixed-point interpolation */
50 #define FixedToDepth(I) ((I) >> FIXED_SHIFT)
51 #else
52 /* don't really use fixed-point */
53 #define FixedToDepth(I) (I)
54 #endif
55 
56 
57 #endif
58