3 * Mesa 3-D graphics library
5 * Copyright (C) 1995-2002 Brian Paul
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * SVGA driver for Mesa.
25 * Original author: Brian Paul
26 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
36 #include "svgamesa16.h"
37 #include "swrast/swrast.h"
40 static void __svga_drawpixel16(int x
, int y
, unsigned long c
)
43 GLshort
*shortBuffer
=(void *)SVGABuffer
.DrawBuffer
;
44 y
= SVGAInfo
->height
-y
-1;
45 offset
= y
* SVGAInfo
->width
+ x
;
46 shortBuffer
[offset
]=c
;
49 static unsigned long __svga_getpixel16(int x
, int y
)
53 GLshort
*shortBuffer
=(void *)SVGABuffer
.ReadBuffer
;
54 y
= SVGAInfo
->height
-y
-1;
55 offset
= y
* SVGAInfo
->width
+ x
;
56 return shortBuffer
[offset
];
59 void __clear_color16( GLcontext
*ctx
, const GLfloat color
[4] )
62 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
63 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
64 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
65 SVGAMesa
->clear_hicolor
= (col
[0] >> 3) << 11 |
68 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
71 void __clear16( GLcontext
*ctx
, GLbitfield mask
)
74 int x
= ctx
->DrawBuffer
->_Xmin
;
75 int y
= ctx
->DrawBuffer
->_Ymin
;
76 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
77 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
78 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
80 if (mask
& DD_FRONT_LEFT_BIT
) {
82 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
83 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
84 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
87 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
88 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
90 for (j
=y
;j
<height
;j
++)
91 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
92 SVGABuffer
.DrawBuffer
= tmp
;
94 mask
&= ~DD_FRONT_LEFT_BIT
;
96 if (mask
& DD_BACK_LEFT_BIT
) {
98 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
99 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
100 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
103 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
104 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
105 for (i
=x
;i
<width
;i
++)
106 for (j
=y
;j
<height
;j
++)
107 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
108 SVGABuffer
.DrawBuffer
= tmp
;
110 mask
&= ~DD_BACK_LEFT_BIT
;
114 _swrast_Clear( ctx
, mask
);
117 void __write_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
118 const GLubyte rgba
[][4], const GLubyte mask
[] )
122 /* draw some pixels */
123 for (i
=0; i
<n
; i
++, x
++) {
125 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
126 (rgba
[i
][GCOMP
]>>2)<<5 | \
127 (rgba
[i
][BCOMP
]>>3));
132 /* draw all pixels */
133 for (i
=0; i
<n
; i
++, x
++) {
134 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
135 (rgba
[i
][GCOMP
]>>2)<<5 | \
136 (rgba
[i
][BCOMP
]>>3));
141 void __write_mono_rgba_span16( const GLcontext
*ctx
,
142 GLuint n
, GLint x
, GLint y
,
143 const GLchan color
[4], const GLubyte mask
[])
145 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
147 for (i
=0; i
<n
; i
++, x
++) {
149 __svga_drawpixel16( x
, y
, hicolor
);
154 void __read_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
158 for (i
=0; i
<n
; i
++, x
++) {
159 pix
= __svga_getpixel16( x
, y
);
160 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
161 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
162 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
166 void __write_rgba_pixels16( const GLcontext
*ctx
,
167 GLuint n
, const GLint x
[], const GLint y
[],
168 const GLubyte rgba
[][4], const GLubyte mask
[] )
171 for (i
=0; i
<n
; i
++) {
173 __svga_drawpixel16( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<11 | \
174 (rgba
[i
][GCOMP
]>>2)<<5 | \
175 (rgba
[i
][BCOMP
]>>3));
181 void __write_mono_rgba_pixels16( const GLcontext
*ctx
,
183 const GLint x
[], const GLint y
[],
184 const GLchan color
[4], const GLubyte mask
[] )
186 GLushort hicolor
=(color
[RCOMP
]>>3)<<11 | (color
[GCOMP
]>>2)<<5 | (color
[BCOMP
]>>3);
188 for (i
=0; i
<n
; i
++) {
190 __svga_drawpixel16( x
[i
], y
[i
], hicolor
);
195 void __read_rgba_pixels16( const GLcontext
*ctx
,
196 GLuint n
, const GLint x
[], const GLint y
[],
197 GLubyte rgba
[][4], const GLubyte mask
[] )
200 for (i
=0; i
<n
; i
++,x
++) {
201 pix
= __svga_getpixel16( x
[i
], y
[i
] );
202 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
203 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
204 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
211 /* silence compiler warning */
212 extern void _mesa_svga16_dummy_function(void);
213 void _mesa_svga16_dummy_function(void)