nouveau: fix nv30 line width
[mesa.git] / src / mesa / drivers / svga / svgamesa24.c
1 /* $Id: svgamesa24.c,v 1.13 2006/11/01 19:35:23 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.0
6 * Copyright (C) 1995-2002 Brian Paul
7 *
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.
12 *
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.
17 *
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.
21 */
22
23
24 /*
25 * SVGA driver for Mesa.
26 * Original author: Brian Paul
27 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include "conf.h"
32 #endif
33
34 #ifdef SVGA
35
36 #include "svgapix.h"
37 #include "svgamesa24.h"
38 #include "swrast/swrast.h"
39
40
41 #if 0
42 /* this doesn't compile with GCC on RedHat 6.1 */
43 static inline int RGB2BGR24(int c)
44 {
45 asm("rorw $8, %0\n"
46 "rorl $16, %0\n"
47 "rorw $8, %0\n"
48 "shrl $8, %0\n"
49 : "=q"(c):"0"(c));
50 return c;
51 }
52 #else
53 static unsigned long RGB2BGR24(unsigned long color)
54 {
55 return (color & 0xff00)|(color>>16)|((color & 0xff)<<16);
56 }
57 #endif
58
59 static void __svga_drawpixel24(int x, int y, GLubyte r, GLubyte g, GLubyte b)
60 {
61 unsigned long offset;
62
63 _RGB *rgbBuffer=(void *)SVGABuffer.DrawBuffer;
64 y = SVGAInfo->height-y-1;
65 offset = y * SVGAInfo->width + x;
66
67 rgbBuffer[offset].r=r;
68 rgbBuffer[offset].g=g;
69 rgbBuffer[offset].b=b;
70 }
71
72 static unsigned long __svga_getpixel24(int x, int y)
73 {
74 unsigned long offset;
75
76 _RGB *rgbBuffer=(void *)SVGABuffer.ReadBuffer;
77 y = SVGAInfo->height-y-1;
78 offset = y * SVGAInfo->width + x;
79 return rgbBuffer[offset].r<<16 | rgbBuffer[offset].g<<8 | rgbBuffer[offset].b;
80 }
81
82 void __clear_color24( GLcontext *ctx, const GLfloat color[4] )
83 {
84 GLubyte col[3];
85 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
86 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
87 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
88 SVGAMesa->clear_red = col[0];
89 SVGAMesa->clear_green = col[1];
90 SVGAMesa->clear_blue = col[2];
91 /* SVGAMesa->clear_truecolor = red<<16 | green<<8 | blue; */
92 }
93
94 void __clear24( GLcontext *ctx, GLbitfield mask )
95 {
96 int i,j;
97 int x = ctx->DrawBuffer->_Xmin;
98 int y = ctx->DrawBuffer->_Ymin;
99 int width = ctx->DrawBuffer->_Xmax - x;
100 int height = ctx->DrawBuffer->_Ymax - y;
101 GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
102
103 if (mask & DD_FRONT_LEFT_BIT) {
104 if (all) {
105 _RGB *rgbBuffer=(void *)SVGABuffer.FrontBuffer;
106 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
107 rgbBuffer[i].r=SVGAMesa->clear_red;
108 rgbBuffer[i].g=SVGAMesa->clear_green;
109 rgbBuffer[i].b=SVGAMesa->clear_blue;
110 }
111 }
112 else {
113 GLubyte *tmp = SVGABuffer.DrawBuffer;
114 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
115 for (i=x;i<width;i++)
116 for (j=y;j<height;j++)
117 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
118 SVGAMesa->clear_green,
119 SVGAMesa->clear_blue);
120 SVGABuffer.DrawBuffer = tmp;
121 }
122 mask &= ~DD_FRONT_LEFT_BIT;
123 }
124 if (mask & DD_BACK_LEFT_BIT) {
125 if (all) {
126 _RGB *rgbBuffer=(void *)SVGABuffer.BackBuffer;
127 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
128 rgbBuffer[i].r=SVGAMesa->clear_red;
129 rgbBuffer[i].g=SVGAMesa->clear_green;
130 rgbBuffer[i].b=SVGAMesa->clear_blue;
131 }
132 }
133 else {
134 GLubyte *tmp = SVGABuffer.DrawBuffer;
135 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
136 for (i=x;i<width;i++)
137 for (j=y;j<height;j++)
138 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
139 SVGAMesa->clear_green,
140 SVGAMesa->clear_blue);
141 SVGABuffer.DrawBuffer = tmp;
142 }
143 mask &= ~DD_BACK_LEFT_BIT;
144 }
145
146 if (mask)
147 _swrast_Clear( ctx, mask );
148 }
149
150 void __write_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
151 const GLubyte rgba[][4], const GLubyte mask[] )
152 {
153 int i;
154 if (mask) {
155 /* draw some pixels */
156 for (i=0; i<n; i++, x++) {
157 if (mask[i]) {
158 __svga_drawpixel24( x, y, rgba[i][RCOMP],
159 rgba[i][GCOMP],
160 rgba[i][BCOMP]);
161 }
162 }
163 }
164 else {
165 /* draw all pixels */
166 for (i=0; i<n; i++, x++) {
167 __svga_drawpixel24( x, y, rgba[i][RCOMP],
168 rgba[i][GCOMP],
169 rgba[i][BCOMP]);
170 }
171 }
172 }
173
174 void __write_mono_rgba_span24( const GLcontext *ctx,
175 GLuint n, GLint x, GLint y,
176 const GLchan color[4], const GLubyte mask[])
177 {
178 int i;
179 for (i=0; i<n; i++, x++) {
180 if (mask[i]) {
181 __svga_drawpixel24( x, y, color[RCOMP], color[GCOMP], color[BCOMP]);
182 }
183 }
184 }
185
186 void __read_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
187 GLubyte rgba[][4] )
188 {
189 int i;
190 for (i=0; i<n; i++, x++) {
191 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x, y));
192 }
193 }
194
195 void __write_rgba_pixels24( const GLcontext *ctx,
196 GLuint n, const GLint x[], const GLint y[],
197 const GLubyte rgba[][4], const GLubyte mask[] )
198 {
199 int i;
200 for (i=0; i<n; i++) {
201 if (mask[i]) {
202 __svga_drawpixel24( x[i], y[i], rgba[i][RCOMP],
203 rgba[i][GCOMP],
204 rgba[i][BCOMP]);
205 }
206 }
207 }
208
209 void __write_mono_rgba_pixels24( const GLcontext *ctx,
210 GLuint n,
211 const GLint x[], const GLint y[],
212 const GLchan color[4], const GLubyte mask[] )
213 {
214 int i;
215 for (i=0; i<n; i++) {
216 if (mask[i]) {
217 __svga_drawpixel24( x[i], y[i],
218 color[RCOMP], color[GCOMP], color[BCOMP] );
219 }
220 }
221 }
222
223 void __read_rgba_pixels24( const GLcontext *ctx,
224 GLuint n, const GLint x[], const GLint y[],
225 GLubyte rgba[][4], const GLubyte mask[] )
226 {
227 int i;
228 for (i=0; i<n; i++,x++) {
229 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x[i], y[i]));
230 }
231 }
232
233 #else
234
235
236 /* silence compiler warning */
237 extern void _mesa_svga24_dummy_function(void);
238 void _mesa_svga24_dummy_function(void)
239 {
240 }
241
242
243 #endif