2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #ifndef _SAVAGE_SPAN_H
26 #define _SAVAGE_SPAN_H
28 #include "drirenderbuffer.h"
31 extern void savageDDInitSpanFuncs( GLcontext
*ctx
);
34 savageSetSpanFunctions(driRenderbuffer
*rb
, const GLvisual
*vis
,
35 GLboolean float_depth
);
39 * Savage 16-bit float depth format with zExpOffset=16:
40 * 4 bit unsigned exponent, 12 bit mantissa
42 * The meaning of the mantissa is different from IEEE floatint point
43 * formats. The same number can't be encoded with different exponents.
44 * So no bits are wasted.
46 * exponent | range encoded by mantissa | accuracy or mantissa
47 * ---------+---------------------------+---------------------
48 * 15 | 2^-1 .. 1 | 2^-13
49 * 14 | 2^-2 .. 2^-1 | 2^-14
50 * 13 | 2^-3 .. 2^-2 | 2^-15
52 * 2 | 2^-14 .. 2^-13 | 2^-27
53 * 1 | 2^-15 .. 2^-14 | 2^-27
54 * 0 | 2^-16 .. 2^-15 | 2^-28
56 * Note that there is no encoding for numbers < 2^-16.
58 static __inline GLuint
savageEncodeFloat16( GLdouble x
)
60 GLint r
= (GLint
)(x
* 0x10000000);
64 while (r
- 0x1000 > 0x0fff) {
68 return exp
> 0xf ? 0xffff : (r
- 0x1000) | (exp
<< 12);
70 static __inline GLdouble
savageDecodeFloat16( GLuint x
)
72 static const GLdouble pow2
[16] = {
73 1.0/(1<<28), 1.0/(1<<27), 1.0/(1<<26), 1.0/(1<<25),
74 1.0/(1<<24), 1.0/(1<<23), 1.0/(1<<22), 1.0/(1<<21),
75 1.0/(1<<20), 1.0/(1<<19), 1.0/(1<<18), 1.0/(1<<17),
76 1.0/(1<<16), 1.0/(1<<15), 1.0/(1<<14), 1.0/(1<<13)
78 static const GLdouble bias
[16] = {
79 1.0/(1<<16), 1.0/(1<<15), 1.0/(1<<14), 1.0/(1<<13),
80 1.0/(1<<12), 1.0/(1<<11), 1.0/(1<<10), 1.0/(1<< 9),
81 1.0/(1<< 8), 1.0/(1<< 7), 1.0/(1<< 6), 1.0/(1<< 5),
82 1.0/(1<< 4), 1.0/(1<< 3), 1.0/(1<< 2), 1.0/(1<< 1)
84 GLuint mant
= x
& 0x0fff;
85 GLuint exp
= (x
>> 12) & 0xf;
86 return bias
[exp
] + pow2
[exp
]*mant
;
90 * Savage 24-bit float depth format with zExpOffset=32:
91 * 5 bit unsigned exponent, 19 bit mantissa
93 * Details analogous to the 16-bit format.
95 static __inline GLuint
savageEncodeFloat24( GLdouble x
)
97 int64_t r
= (int64_t)(x
* ((int64_t)1 << (19+32)));
101 while (r
- 0x80000 > 0x7ffff) {
105 return exp
> 0x1f ? 0xffffff : (r
- 0x80000) | (exp
<< 19);
107 #define _1 (int64_t)1
108 static __inline GLdouble
savageDecodeFloat24( GLuint x
)
110 static const GLdouble pow2
[32] = {
111 1.0/(_1
<<51), 1.0/(_1
<<50), 1.0/(_1
<<49), 1.0/(_1
<<48),
112 1.0/(_1
<<47), 1.0/(_1
<<46), 1.0/(_1
<<45), 1.0/(_1
<<44),
113 1.0/(_1
<<43), 1.0/(_1
<<42), 1.0/(_1
<<41), 1.0/(_1
<<40),
114 1.0/(_1
<<39), 1.0/(_1
<<38), 1.0/(_1
<<37), 1.0/(_1
<<36),
115 1.0/(_1
<<35), 1.0/(_1
<<34), 1.0/(_1
<<33), 1.0/(_1
<<32),
116 1.0/(_1
<<31), 1.0/(_1
<<30), 1.0/(_1
<<29), 1.0/(_1
<<28),
117 1.0/(_1
<<27), 1.0/(_1
<<26), 1.0/(_1
<<25), 1.0/(_1
<<24),
118 1.0/(_1
<<23), 1.0/(_1
<<22), 1.0/(_1
<<21), 1.0/(_1
<<20)
120 static const GLdouble bias
[32] = {
121 1.0/(_1
<<32), 1.0/(_1
<<31), 1.0/(_1
<<30), 1.0/(_1
<<29),
122 1.0/(_1
<<28), 1.0/(_1
<<27), 1.0/(_1
<<26), 1.0/(_1
<<25),
123 1.0/(_1
<<24), 1.0/(_1
<<23), 1.0/(_1
<<22), 1.0/(_1
<<21),
124 1.0/(_1
<<20), 1.0/(_1
<<19), 1.0/(_1
<<18), 1.0/(_1
<<17),
125 1.0/(_1
<<16), 1.0/(_1
<<15), 1.0/(_1
<<14), 1.0/(_1
<<13),
126 1.0/(_1
<<12), 1.0/(_1
<<11), 1.0/(_1
<<10), 1.0/(_1
<< 9),
127 1.0/(_1
<< 8), 1.0/(_1
<< 7), 1.0/(_1
<< 6), 1.0/(_1
<< 5),
128 1.0/(_1
<< 4), 1.0/(_1
<< 3), 1.0/(_1
<< 2), 1.0/(_1
<< 1)
130 GLuint mant
= x
& 0x7ffff;
131 GLuint exp
= (x
>> 19) & 0x1f;
132 return bias
[exp
] + pow2
[exp
]*mant
;