8a366998d6bb3567ac359d26d5c7254360a02281
[mesa.git] / src / mesa / drivers / svga / svgamesa32.c
1 /* $Id: svgamesa32.c,v 1.12 2002/11/11 18:42:42 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 "svgamesa32.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 RGB2BGR32(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 RGB2BGR32(unsigned long color)
54 {
55 return (color & 0xff00)|(color>>16)|((color & 0xff)<<16);
56 }
57 #endif
58
59 static void __svga_drawpixel32(int x, int y, unsigned long c)
60 {
61 unsigned long offset;
62
63 GLint *intBuffer=(void *)SVGABuffer.DrawBuffer;
64 y = SVGAInfo->height-y-1;
65 offset = y * SVGAInfo->width + x;
66 intBuffer[offset]=c;
67 }
68
69 static unsigned long __svga_getpixel32(int x, int y)
70 {
71 unsigned long offset;
72
73 const GLint *intBuffer=(void *)SVGABuffer.ReadBuffer;
74 y = SVGAInfo->height-y-1;
75 offset = y * SVGAInfo->width + x;
76 return intBuffer[offset];
77 }
78
79 void __clear_color32( GLcontext *ctx, const GLfloat color[4] )
80 {
81 GLubyte col[3];
82 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
83 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
84 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
85 SVGAMesa->clear_truecolor = (col[0] << 16) | (col[1] << 8) | col[2];
86 }
87
88 void __clear32( GLcontext *ctx, GLbitfield mask, GLboolean all,
89 GLint x, GLint y, GLint width, GLint height )
90 {
91 int i,j;
92
93 if (mask & DD_FRONT_LEFT_BIT) {
94 if (all) {
95 GLint *intBuffer=(void *)SVGABuffer.FrontBuffer;
96 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
97 intBuffer[i]=SVGAMesa->clear_truecolor;
98 }
99 else {
100 GLubyte *tmp = SVGABuffer.DrawBuffer;
101 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
102 for (i=x;i<width;i++)
103 for (j=y;j<height;j++)
104 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
105 SVGABuffer.DrawBuffer = tmp;
106 }
107 mask &= ~DD_FRONT_LEFT_BIT;
108 }
109 if (mask & DD_BACK_LEFT_BIT) {
110 if (all) {
111 GLint *intBuffer=(void *)SVGABuffer.BackBuffer;
112 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
113 intBuffer[i]=SVGAMesa->clear_truecolor;
114 }
115 else {
116 GLubyte *tmp = SVGABuffer.DrawBuffer;
117 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
118 for (i=x;i<width;i++)
119 for (j=y;j<height;j++)
120 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
121 SVGABuffer.DrawBuffer = tmp;
122 }
123 mask &= ~DD_BACK_LEFT_BIT;
124 }
125
126 if (mask)
127 _swrast_Clear( ctx, mask, all, x, y, width, height );
128 }
129
130 void __write_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
131 const GLubyte rgba[][4], const GLubyte mask[] )
132 {
133 int i;
134 if (mask) {
135 /* draw some pixels */
136 for (i=0; i<n; i++, x++) {
137 if (mask[i]) {
138 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
139 }
140 }
141 }
142 else {
143 /* draw all pixels */
144 for (i=0; i<n; i++, x++) {
145 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
146 }
147 }
148 }
149
150 void __write_mono_rgba_span32( const GLcontext *ctx,
151 GLuint n, GLint x, GLint y,
152 const GLchan color[4], const GLubyte mask[])
153 {
154 int i;
155 GLuint truecolor = color[RCOMP]<<16 | color[GCOMP]<<8 | color[BCOMP];
156 for (i=0; i<n; i++, x++) {
157 if (mask[i]) {
158 __svga_drawpixel32( x, y, truecolor);
159 }
160 }
161 }
162
163 void __read_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
164 GLubyte rgba[][4] )
165 {
166 int i;
167 for (i=0; i<n; i++, x++) {
168 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x, y ));
169 }
170 }
171
172 void __write_rgba_pixels32( const GLcontext *ctx,
173 GLuint n, const GLint x[], const GLint y[],
174 const GLubyte rgba[][4], const GLubyte mask[] )
175 {
176 int i;
177 for (i=0; i<n; i++) {
178 if (mask[i]) {
179 __svga_drawpixel32( x[i], y[i], RGB2BGR32(*((GLint*)rgba[i])));
180 }
181 }
182 }
183
184 void __write_mono_rgba_pixels32( const GLcontext *ctx,
185 GLuint n,
186 const GLint x[], const GLint y[],
187 const GLchan color[4], const GLubyte mask[] )
188 {
189 GLuint truecolor = color[RCOMP]<<16 | color[GCOMP]<<8 | color[BCOMP];
190 int i;
191 for (i=0; i<n; i++) {
192 if (mask[i]) {
193 __svga_drawpixel32( x[i], y[i], truecolor );
194 }
195 }
196 }
197
198 void __read_rgba_pixels32( const GLcontext *ctx,
199 GLuint n, const GLint x[], const GLint y[],
200 GLubyte rgba[][4], const GLubyte mask[] )
201 {
202 int i;
203 for (i=0; i<n; i++,x++) {
204 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x[i], y[i] ));
205 }
206 }
207
208
209 #else
210
211
212 /* silence compiler warning */
213 extern void _mesa_svga32_dummy_function(void);
214 void _mesa_svga32_dummy_function(void)
215 {
216 }
217
218
219 #endif
220