1 /* $Id: svgamesa15.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 "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
)
72 int x
= ctx
->DrawBuffer
->_Xmin
;
73 int y
= ctx
->DrawBuffer
->_Ymin
;
74 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
75 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
76 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
78 if (mask
& DD_FRONT_LEFT_BIT
) {
79 GLshort
*shortBuffer
=(void *)SVGABuffer
.FrontBuffer
;
81 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
82 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
85 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
86 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
88 for (j
=y
;j
<height
;j
++)
89 __svga_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
90 SVGABuffer
.DrawBuffer
= tmp
;
92 mask
&= ~DD_FRONT_LEFT_BIT
;
94 if (mask
& DD_BACK_LEFT_BIT
) {
95 GLshort
*shortBuffer
=(void *)SVGABuffer
.BackBuffer
;
97 for (i
=0;i
<SVGABuffer
.BufferSize
/ 2;i
++)
98 shortBuffer
[i
]=SVGAMesa
->clear_hicolor
;
101 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
102 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
103 for (i
=x
;i
<width
;i
++)
104 for (j
=y
;j
<height
;j
++)
105 __svga_drawpixel15(i
,j
,SVGAMesa
->clear_hicolor
);
106 SVGABuffer
.DrawBuffer
= tmp
;
108 mask
&= ~DD_BACK_LEFT_BIT
;
112 _swrast_Clear( ctx
, mask
);
115 void __write_rgba_span15( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
116 const GLubyte rgba
[][4], const GLubyte mask
[] )
120 /* draw some pixels */
121 for (i
=0; i
<n
; i
++, x
++) {
123 __svga_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
124 (rgba
[i
][GCOMP
]>>3)<<5 | \
125 (rgba
[i
][BCOMP
]>>3));
130 /* draw all pixels */
131 for (i
=0; i
<n
; i
++, x
++) {
132 __svga_drawpixel15( x
, y
, (rgba
[i
][RCOMP
]>>3)<<10 | \
133 (rgba
[i
][GCOMP
]>>3)<<5 | \
134 (rgba
[i
][BCOMP
]>>3));
139 void __write_mono_rgba_span15( const GLcontext
*ctx
,
140 GLuint n
, GLint x
, GLint y
,
141 const GLchan color
[4], const GLubyte mask
[])
143 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
144 (color
[GCOMP
] >> 3) << 5 |
147 for (i
=0; i
<n
; i
++, x
++) {
149 __svga_drawpixel15( x
, y
, hicolor
);
154 void __read_rgba_span15( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
158 for (i
=0; i
<n
; i
++, x
++) {
159 pix
= __svga_getpixel15( x
, y
);
160 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
161 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
162 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
166 void __write_rgba_pixels15( 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_drawpixel15( x
[i
], y
[i
], (rgba
[i
][RCOMP
]>>3)<<10 | \
174 (rgba
[i
][GCOMP
]>>3)<<5 | \
175 (rgba
[i
][BCOMP
]>>3));
181 void __write_mono_rgba_pixels15( const GLcontext
*ctx
,
183 const GLint x
[], const GLint y
[],
184 const GLchan color
[4], const GLubyte mask
[] )
186 GLushort hicolor
= (color
[RCOMP
] >> 3) << 10 |
187 (color
[GCOMP
] >> 3) << 5 |
190 /* use current rgb color */
191 for (i
=0; i
<n
; i
++) {
193 __svga_drawpixel15( x
[i
], y
[i
], hicolor
);
198 void __read_rgba_pixels15( const GLcontext
*ctx
,
199 GLuint n
, const GLint x
[], const GLint y
[],
200 GLubyte rgba
[][4], const GLubyte mask
[] )
203 for (i
=0; i
<n
; i
++,x
++) {
204 pix
= __svga_getpixel15( x
[i
], y
[i
] );
205 rgba
[i
][RCOMP
] = ((pix
>>10)<<3) & 0xff;
206 rgba
[i
][GCOMP
] = ((pix
>> 5)<<3) & 0xff;
207 rgba
[i
][BCOMP
] = ((pix
)<<3) & 0xff;
214 /* silence compiler warning */
215 extern void _mesa_svga15_dummy_function(void);
216 void _mesa_svga15_dummy_function(void)