1 /* $Id: svgamesa15.c,v 1.11 2002/11/11 18:42:39 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 "svgamesa15.h"
38 #include "swrast/swrast.h"
41 static void __svga_drawpixel15(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_getpixel15(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_color15( 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)<<10 | (col
[1]>>3)<<5 | (col
[2]>>3);
66 /* SVGAMesa->clear_hicolor=(red)<<10 | (green)<<5 | (blue);*/
69 void __clear15( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
70 GLint x
, GLint y
, GLint width
, GLint height
)
74 if (mask
& DD_FRONT_LEFT_BIT
) {
75 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
77 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
78 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
81 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
82 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
84 for (j
=y
;j
<height
;j
++)
85 __svga_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
86 SVGABuffer
.DrawBuffer
= tmp
;
88 mask
&= ~DD_FRONT_LEFT_BIT
;
90 if (mask
& DD_BACK_LEFT_BIT
) {
91 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
93 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
94 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
97 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
98 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
100 for (j
=y
;j
<height
;j
++)
101 __svga_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
102 SVGABuffer
.DrawBuffer
= tmp
;
104 mask
&= ~DD_BACK_LEFT_BIT
;
108 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
111 void __write_rgba_span15( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
112 const GLubyte rgba
[][4], const GLubyte mask
[] )
116 /* draw some pixels */
117 for (i
=0; i
<n
; i
++, x
++) {
119 __svga_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
120 (rgba
[i
][GCOMP
]>>3)<<5 | \
121 (rgba
[i
][BCOMP
]>>3));
126 /* draw all pixels */
127 for (i
=0; i
<n
; i
++, x
++) {
128 __svga_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
129 (rgba
[i
][GCOMP
]>>3)<<5 | \
130 (rgba
[i
][BCOMP
]>>3));
135 void __write_mono_rgba_span15( const GLcontext
*ctx
,
136 GLuint n
, GLint x
, GLint y
,
137 const GLchan color
[4], const GLubyte mask
[])
139 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
140 (color
[GCOMP
] >> 3) << 5 |
143 for (i
=0; i
<n
; i
++, x
++) {
145 __svga_drawpixel15( x
, y
, hicolor
);
150 void __read_rgba_span15( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
154 for (i
=0; i
<n
; i
++, x
++) {
155 pix
= __svga_getpixel15( x
, y
);
156 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
157 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
158 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
162 void __write_rgba_pixels15( const GLcontext
*ctx
,
163 GLuint n
, const GLint x
[], const GLint y
[],
164 const GLubyte rgba
[][4], const GLubyte mask
[] )
167 for (i
=0; i
<n
; i
++) {
169 __svga_drawpixel15( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<10 | \
170 (rgba
[i
][GCOMP
]>>3)<<5 | \
171 (rgba
[i
][BCOMP
]>>3));
177 void __write_mono_rgba_pixels15( const GLcontext
*ctx
,
179 const GLint x
[], const GLint y
[],
180 const GLchan color
[4], const GLubyte mask
[] )
182 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
183 (color
[GCOMP
] >> 3) << 5 |
186 /* use current rgb color */
187 for (i
=0; i
<n
; i
++) {
189 __svga_drawpixel15( x
[i
], y
[i
], hicolor
);
194 void __read_rgba_pixels15( const GLcontext
*ctx
,
195 GLuint n
, const GLint x
[], const GLint y
[],
196 GLubyte rgba
[][4], const GLubyte mask
[] )
199 for (i
=0; i
<n
; i
++,x
++) {
200 pix
= __svga_getpixel15( x
[i
], y
[i
] );
201 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
202 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
203 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
210 /* silence compiler warning */
211 extern void _mesa_svga15_dummy_function(void);
212 void _mesa_svga15_dummy_function(void)