a59937bfb4b003e67cf9f2368d9c9ff2735137d3
1 /* $Id: svgamesa16.c,v 1.11.36.1 2006/11/02 12:02:17 alanh 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
)
75 int x
= ctx
->DrawBuffer
->_Xmin
;
76 int y
= ctx
->DrawBuffer
->_Ymin
;
77 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
78 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
79 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
81 if (mask
& DD_FRONT_LEFT_BIT
) {
83 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
84 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
85 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
88 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
89 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
91 for (j
=y
;j
<height
;j
++)
92 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
93 SVGABuffer
.DrawBuffer
= tmp
;
95 mask
&= ~DD_FRONT_LEFT_BIT
;
97 if (mask
& DD_BACK_LEFT_BIT
) {
99 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
100 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
101 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
104 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
105 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
106 for (i
=x
;i
<width
;i
++)
107 for (j
=y
;j
<height
;j
++)
108 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
109 SVGABuffer
.DrawBuffer
= tmp
;
111 mask
&= ~DD_BACK_LEFT_BIT
;
115 _swrast_Clear( ctx
, mask
);
118 void __write_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
119 const GLubyte rgba
[][4], const GLubyte mask
[] )
123 /* draw some pixels */
124 for (i
=0; i
<n
; i
++, x
++) {
126 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
127 (rgba
[i
][GCOMP
]>>2)<<5 | \
128 (rgba
[i
][BCOMP
]>>3));
133 /* draw all pixels */
134 for (i
=0; i
<n
; i
++, x
++) {
135 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
136 (rgba
[i
][GCOMP
]>>2)<<5 | \
137 (rgba
[i
][BCOMP
]>>3));
142 void __write_mono_rgba_span16( const GLcontext
*ctx
,
143 GLuint n
, GLint x
, GLint y
,
144 const GLchan color
[4], const GLubyte mask
[])
146 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
148 for (i
=0; i
<n
; i
++, x
++) {
150 __svga_drawpixel16( x
, y
, hicolor
);
155 void __read_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
159 for (i
=0; i
<n
; i
++, x
++) {
160 pix
= __svga_getpixel16( x
, y
);
161 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
162 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
163 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
167 void __write_rgba_pixels16( const GLcontext
*ctx
,
168 GLuint n
, const GLint x
[], const GLint y
[],
169 const GLubyte rgba
[][4], const GLubyte mask
[] )
172 for (i
=0; i
<n
; i
++) {
174 __svga_drawpixel16( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<11 | \
175 (rgba
[i
][GCOMP
]>>2)<<5 | \
176 (rgba
[i
][BCOMP
]>>3));
182 void __write_mono_rgba_pixels16( const GLcontext
*ctx
,
184 const GLint x
[], const GLint y
[],
185 const GLchan color
[4], const GLubyte mask
[] )
187 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
189 for (i
=0; i
<n
; i
++) {
191 __svga_drawpixel16( x
[i
], y
[i
], hicolor
);
196 void __read_rgba_pixels16( const GLcontext
*ctx
,
197 GLuint n
, const GLint x
[], const GLint y
[],
198 GLubyte rgba
[][4], const GLubyte mask
[] )
201 for (i
=0; i
<n
; i
++,x
++) {
202 pix
= __svga_getpixel16( x
[i
], y
[i
] );
203 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
204 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
205 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
212 /* silence compiler warning */
213 extern void _mesa_svga16_dummy_function(void);
214 void _mesa_svga16_dummy_function(void)