1 /* $Id: svgamesa16.c,v 1.4 2000/01/25 00:03:02 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-2000 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)
33 #include "svgamesa16.h"
36 static void __svga_drawpixel16(int x
, int y
, unsigned long c
)
39 GLshort
*shortBuffer
=(void *)SVGABuffer
.DrawBuffer
;
40 y
= SVGAInfo
->height
-y
-1;
41 offset
= y
* SVGAInfo
->width
+ x
;
42 shortBuffer
[offset
]=c
;
45 static unsigned long __svga_getpixel16(int x
, int y
)
49 GLshort
*shortBuffer
=(void *)SVGABuffer
.ReadBuffer
;
50 y
= SVGAInfo
->height
-y
-1;
51 offset
= y
* SVGAInfo
->width
+ x
;
52 return shortBuffer
[offset
];
55 void __set_color16( GLcontext
*ctx
,
56 GLubyte red
, GLubyte green
,
57 GLubyte blue
, GLubyte alpha
)
59 SVGAMesa
->hicolor
=(red
>>3)<<11 | (green
>>2)<<5 | (blue
>>3);
60 /* SVGAMesa->hicolor=(red)<<11 | (green)<<5 | (blue); */
63 void __clear_color16( GLcontext
*ctx
,
64 GLubyte red
, GLubyte green
,
65 GLubyte blue
, GLubyte alpha
)
67 SVGAMesa
->clear_hicolor
=(red
>>3)<<11 | (green
>>2)<<5 | (blue
>>3);
68 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
71 GLbitfield
__clear16( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
72 GLint x
, GLint y
, GLint width
, GLint height
)
76 if (mask
& DD_FRONT_LEFT_BIT
) {
78 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
79 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
80 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
83 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
84 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
86 for (j
=y
;j
<height
;j
++)
87 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
88 SVGABuffer
.DrawBuffer
= tmp
;
91 if (mask
& DD_BACK_LEFT_BIT
) {
93 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
94 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
95 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
98 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
99 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
100 for (i
=x
;i
<width
;i
++)
101 for (j
=y
;j
<height
;j
++)
102 __svga_drawpixel16(i
,j
,SVGAMesa
->clear_hicolor
);
103 SVGABuffer
.DrawBuffer
= tmp
;
106 return mask
& (~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
109 void __write_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
110 const GLubyte rgba
[][4], const GLubyte mask
[] )
114 /* draw some pixels */
115 for (i
=0; i
<n
; i
++, x
++) {
117 __svga_drawpixel16( x
, y
, (rgba
[i
][RCOMP
]>>3)<<11 | \
118 (rgba
[i
][GCOMP
]>>2)<<5 | \
119 (rgba
[i
][BCOMP
]>>3));
124 /* draw all pixels */
125 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 void __write_mono_rgba_span16( const GLcontext
*ctx
,
134 GLuint n
, GLint x
, GLint y
,
135 const GLubyte mask
[])
138 for (i
=0; i
<n
; i
++, x
++) {
140 __svga_drawpixel16( x
, y
, SVGAMesa
->hicolor
);
145 void __read_rgba_span16( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
149 for (i
=0; i
<n
; i
++, x
++) {
150 pix
= __svga_getpixel16( x
, y
);
151 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
152 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
153 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
157 void __write_rgba_pixels16( const GLcontext
*ctx
,
158 GLuint n
, const GLint x
[], const GLint y
[],
159 const GLubyte rgba
[][4], const GLubyte mask
[] )
162 for (i
=0; i
<n
; i
++) {
164 __svga_drawpixel16( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<11 | \
165 (rgba
[i
][GCOMP
]>>2)<<5 | \
166 (rgba
[i
][BCOMP
]>>3));
172 void __write_mono_rgba_pixels16( const GLcontext
*ctx
,
174 const GLint x
[], const GLint y
[],
175 const GLubyte mask
[] )
178 /* use current rgb color */
179 for (i
=0; i
<n
; i
++) {
181 __svga_drawpixel16( x
[i
], y
[i
], SVGAMesa
->hicolor
);
186 void __read_rgba_pixels16( const GLcontext
*ctx
,
187 GLuint n
, const GLint x
[], const GLint y
[],
188 GLubyte rgba
[][4], const GLubyte mask
[] )
191 for (i
=0; i
<n
; i
++,x
++) {
192 pix
= __svga_getpixel16( x
[i
], y
[i
] );
193 rgba
[i
][RCOMP
] = ((pix
>>11)<<3) & 0xff;
194 rgba
[i
][GCOMP
] = ((pix
>> 5)<<2) & 0xff;
195 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;