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 "svgamesa15.h"
37 #include "swrast/swrast.h"
40 static void __svga_drawpixel15(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_getpixel15(int x
, int y
)
52 GLshort
*shortBuffer
=(void *)SVGABuffer
.ReadBuffer
;
53 y
= SVGAInfo
->height
-y
-1;
54 offset
= y
* SVGAInfo
->width
+ x
;
55 return shortBuffer
[offset
];
58 void __clear_color15( GLcontext
*ctx
, const GLfloat color
[4] )
61 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
62 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
63 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
64 SVGAMesa
->clear_hicolor
=(col
[0]>>3)<<10 | (col
[1]>>3)<<5 | (col
[2]>>3);
65 /* SVGAMesa->clear_hicolor=(red)<<10 | (green)<<5 | (blue);*/
68 void __clear15( GLcontext
*ctx
, GLbitfield mask
)
71 int x
= ctx
->DrawBuffer
->_Xmin
;
72 int y
= ctx
->DrawBuffer
->_Ymin
;
73 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
74 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
75 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
77 if (mask
& DD_FRONT_LEFT_BIT
) {
78 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_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
89 SVGABuffer
.DrawBuffer
= tmp
;
91 mask
&= ~DD_FRONT_LEFT_BIT
;
93 if (mask
& DD_BACK_LEFT_BIT
) {
94 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_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
105 SVGABuffer
.DrawBuffer
= tmp
;
107 mask
&= ~DD_BACK_LEFT_BIT
;
111 _swrast_Clear( ctx
, mask
);
114 void __write_rgba_span15( 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_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
123 (rgba
[i
][GCOMP
]>>3)<<5 | \
124 (rgba
[i
][BCOMP
]>>3));
129 /* draw all pixels */
130 for (i
=0; i
<n
; i
++, x
++) {
131 __svga_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
132 (rgba
[i
][GCOMP
]>>3)<<5 | \
133 (rgba
[i
][BCOMP
]>>3));
138 void __write_mono_rgba_span15( const GLcontext
*ctx
,
139 GLuint n
, GLint x
, GLint y
,
140 const GLchan color
[4], const GLubyte mask
[])
142 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
143 (color
[GCOMP
] >> 3) << 5 |
146 for (i
=0; i
<n
; i
++, x
++) {
148 __svga_drawpixel15( x
, y
, hicolor
);
153 void __read_rgba_span15( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
157 for (i
=0; i
<n
; i
++, x
++) {
158 pix
= __svga_getpixel15( x
, y
);
159 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
160 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
161 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
165 void __write_rgba_pixels15( const GLcontext
*ctx
,
166 GLuint n
, const GLint x
[], const GLint y
[],
167 const GLubyte rgba
[][4], const GLubyte mask
[] )
170 for (i
=0; i
<n
; i
++) {
172 __svga_drawpixel15( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<10 | \
173 (rgba
[i
][GCOMP
]>>3)<<5 | \
174 (rgba
[i
][BCOMP
]>>3));
180 void __write_mono_rgba_pixels15( const GLcontext
*ctx
,
182 const GLint x
[], const GLint y
[],
183 const GLchan color
[4], const GLubyte mask
[] )
185 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
186 (color
[GCOMP
] >> 3) << 5 |
189 /* use current rgb color */
190 for (i
=0; i
<n
; i
++) {
192 __svga_drawpixel15( x
[i
], y
[i
], hicolor
);
197 void __read_rgba_pixels15( const GLcontext
*ctx
,
198 GLuint n
, const GLint x
[], const GLint y
[],
199 GLubyte rgba
[][4], const GLubyte mask
[] )
202 for (i
=0; i
<n
; i
++,x
++) {
203 pix
= __svga_getpixel15( x
[i
], y
[i
] );
204 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
205 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
206 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
213 /* silence compiler warning */
214 extern void _mesa_svga15_dummy_function(void);
215 void _mesa_svga15_dummy_function(void)