Add a couple of helper functions for completeness.
[mesa.git] / src / mesa / drivers / svga / svgamesa24.c
1 /* $Id: svgamesa24.c,v 1.12 2002/11/11 18:42:41 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, GLboolean all,
95 GLint x, GLint y, GLint width, GLint height )
96 {
97 int i,j;
98
99 if (mask & DD_FRONT_LEFT_BIT) {
100 if (all) {
101 _RGB *rgbBuffer=(void *)SVGABuffer.FrontBuffer;
102 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
103 rgbBuffer[i].r=SVGAMesa->clear_red;
104 rgbBuffer[i].g=SVGAMesa->clear_green;
105 rgbBuffer[i].b=SVGAMesa->clear_blue;
106 }
107 }
108 else {
109 GLubyte *tmp = SVGABuffer.DrawBuffer;
110 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
111 for (i=x;i<width;i++)
112 for (j=y;j<height;j++)
113 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
114 SVGAMesa->clear_green,
115 SVGAMesa->clear_blue);
116 SVGABuffer.DrawBuffer = tmp;
117 }
118 mask &= ~DD_FRONT_LEFT_BIT;
119 }
120 if (mask & DD_BACK_LEFT_BIT) {
121 if (all) {
122 _RGB *rgbBuffer=(void *)SVGABuffer.BackBuffer;
123 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
124 rgbBuffer[i].r=SVGAMesa->clear_red;
125 rgbBuffer[i].g=SVGAMesa->clear_green;
126 rgbBuffer[i].b=SVGAMesa->clear_blue;
127 }
128 }
129 else {
130 GLubyte *tmp = SVGABuffer.DrawBuffer;
131 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
132 for (i=x;i<width;i++)
133 for (j=y;j<height;j++)
134 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
135 SVGAMesa->clear_green,
136 SVGAMesa->clear_blue);
137 SVGABuffer.DrawBuffer = tmp;
138 }
139 mask &= ~DD_BACK_LEFT_BIT;
140 }
141
142 if (mask)
143 _swrast_Clear( ctx, mask, all, x, y, width, height );
144 }
145
146 void __write_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
147 const GLubyte rgba[][4], const GLubyte mask[] )
148 {
149 int i;
150 if (mask) {
151 /* draw some pixels */
152 for (i=0; i<n; i++, x++) {
153 if (mask[i]) {
154 __svga_drawpixel24( x, y, rgba[i][RCOMP],
155 rgba[i][GCOMP],
156 rgba[i][BCOMP]);
157 }
158 }
159 }
160 else {
161 /* draw all pixels */
162 for (i=0; i<n; i++, x++) {
163 __svga_drawpixel24( x, y, rgba[i][RCOMP],
164 rgba[i][GCOMP],
165 rgba[i][BCOMP]);
166 }
167 }
168 }
169
170 void __write_mono_rgba_span24( const GLcontext *ctx,
171 GLuint n, GLint x, GLint y,
172 const GLchan color[4], const GLubyte mask[])
173 {
174 int i;
175 for (i=0; i<n; i++, x++) {
176 if (mask[i]) {
177 __svga_drawpixel24( x, y, color[RCOMP], color[GCOMP], color[BCOMP]);
178 }
179 }
180 }
181
182 void __read_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
183 GLubyte rgba[][4] )
184 {
185 int i;
186 for (i=0; i<n; i++, x++) {
187 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x, y));
188 }
189 }
190
191 void __write_rgba_pixels24( const GLcontext *ctx,
192 GLuint n, const GLint x[], const GLint y[],
193 const GLubyte rgba[][4], const GLubyte mask[] )
194 {
195 int i;
196 for (i=0; i<n; i++) {
197 if (mask[i]) {
198 __svga_drawpixel24( x[i], y[i], rgba[i][RCOMP],
199 rgba[i][GCOMP],
200 rgba[i][BCOMP]);
201 }
202 }
203 }
204
205 void __write_mono_rgba_pixels24( const GLcontext *ctx,
206 GLuint n,
207 const GLint x[], const GLint y[],
208 const GLchan color[4], const GLubyte mask[] )
209 {
210 int i;
211 for (i=0; i<n; i++) {
212 if (mask[i]) {
213 __svga_drawpixel24( x[i], y[i],
214 color[RCOMP], color[GCOMP], color[BCOMP] );
215 }
216 }
217 }
218
219 void __read_rgba_pixels24( const GLcontext *ctx,
220 GLuint n, const GLint x[], const GLint y[],
221 GLubyte rgba[][4], const GLubyte mask[] )
222 {
223 int i;
224 for (i=0; i<n; i++,x++) {
225 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x[i], y[i]));
226 }
227 }
228
229 #else
230
231
232 /* silence compiler warning */
233 extern void _mesa_svga24_dummy_function(void);
234 void _mesa_svga24_dummy_function(void)
235 {
236 }
237
238
239 #endif