1 /* $Id: svgamesa16.c,v 1.11 2002/11/11 18:42:40 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-2002 Brian Paul
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.
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.
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.
25 * SVGA driver for Mesa.
26 * Original author: Brian Paul
27 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
37 #include "svgamesa16.h"
38 #include "swrast/swrast.h"
41 static void __svga_drawpixel16(int x
, int y
, unsigned long c
)
44 GLshort
*shortBuffer
=(void *)SVGABuffer
.DrawBuffer
;
45 y
= SVGAInfo
->height
-y
-1;
46 offset
= y
* SVGAInfo
->width
+ x
;
47 shortBuffer
[offset
]=c
;
50 static unsigned long __svga_getpixel16(int x
, int y
)
54 GLshort
*shortBuffer
=(void *)SVGABuffer
.ReadBuffer
;
55 y
= SVGAInfo
->height
-y
-1;
56 offset
= y
* SVGAInfo
->width
+ x
;
57 return shortBuffer
[offset
];
60 void __clear_color16( GLcontext
*ctx
, const GLfloat color
[4] )
63 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
64 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
65 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
66 SVGAMesa
->clear_hicolor
= (col
[0] >> 3) << 11 |
69 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
72 void __clear16( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
73 GLint x
, GLint y
, GLint width
, GLint height
)
77 if (mask
& DD_FRONT_LEFT_BIT
) {
79 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
80 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
81 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
84 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
85 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
87 for (j
=y
;j
<height
;j
++)
88 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
89 SVGABuffer
.DrawBuffer
= tmp
;
91 mask
&= ~DD_FRONT_LEFT_BIT
;
93 if (mask
& DD_BACK_LEFT_BIT
) {
95 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
96 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
97 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
100 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
101 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
102 for (i
=x
;i
<width
;i
++)
103 for (j
=y
;j
<height
;j
++)
104 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
105 SVGABuffer
.DrawBuffer
= tmp
;
107 mask
&= ~DD_BACK_LEFT_BIT
;
111 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
114 void __write_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
115 const GLubyte rgba
[][4], const GLubyte mask
[] )
119 /* draw some pixels */
120 for (i
=0; i
<n
; i
++, x
++) {
122 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
123 (rgba
[i
][GCOMP
]>>2)<<5 | \
124 (rgba
[i
][BCOMP
]>>3));
129 /* draw all pixels */
130 for (i
=0; i
<n
; i
++, x
++) {
131 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
132 (rgba
[i
][GCOMP
]>>2)<<5 | \
133 (rgba
[i
][BCOMP
]>>3));
138 void __write_mono_rgba_span16( const GLcontext
*ctx
,
139 GLuint n
, GLint x
, GLint y
,
140 const GLchan color
[4], const GLubyte mask
[])
142 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
144 for (i
=0; i
<n
; i
++, x
++) {
146 __svga_drawpixel16( x
, y
, hicolor
);
151 void __read_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
155 for (i
=0; i
<n
; i
++, x
++) {
156 pix
= __svga_getpixel16( x
, y
);
157 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
158 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
159 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
163 void __write_rgba_pixels16( const GLcontext
*ctx
,
164 GLuint n
, const GLint x
[], const GLint y
[],
165 const GLubyte rgba
[][4], const GLubyte mask
[] )
168 for (i
=0; i
<n
; i
++) {
170 __svga_drawpixel16( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<11 | \
171 (rgba
[i
][GCOMP
]>>2)<<5 | \
172 (rgba
[i
][BCOMP
]>>3));
178 void __write_mono_rgba_pixels16( const GLcontext
*ctx
,
180 const GLint x
[], const GLint y
[],
181 const GLchan color
[4], const GLubyte mask
[] )
183 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
185 for (i
=0; i
<n
; i
++) {
187 __svga_drawpixel16( x
[i
], y
[i
], hicolor
);
192 void __read_rgba_pixels16( const GLcontext
*ctx
,
193 GLuint n
, const GLint x
[], const GLint y
[],
194 GLubyte rgba
[][4], const GLubyte mask
[] )
197 for (i
=0; i
<n
; i
++,x
++) {
198 pix
= __svga_getpixel16( x
[i
], y
[i
] );
199 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
200 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
201 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
208 /* silence compiler warning */
209 extern void _mesa_svga16_dummy_function(void);
210 void _mesa_svga16_dummy_function(void)