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