removed a printf
[mesa.git] / src / mesa / drivers / svga / svgamesa32.c
1 /* $Id: svgamesa32.c,v 1.6 2000/01/31 22:10:07 tanner 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 "svgamesa32.h"
38
39 #if 0
40 /* this doesn't compile with GCC on RedHat 6.1 */
41 static inline int RGB2BGR32(int c)
42 {
43 asm("rorw $8, %0\n"
44 "rorl $16, %0\n"
45 "rorw $8, %0\n"
46 "shrl $8, %0\n"
47 : "=q"(c):"0"(c));
48 return c;
49 }
50 #else
51 static unsigned long RGB2BGR32(unsigned long color)
52 {
53 return (color & 0xff00)|(color>>16)|((color & 0xff)<<16);
54 }
55 #endif
56
57 static void __svga_drawpixel32(int x, int y, unsigned long c)
58 {
59 unsigned long offset;
60
61 GLint *intBuffer=(void *)SVGABuffer.DrawBuffer;
62 y = SVGAInfo->height-y-1;
63 offset = y * SVGAInfo->width + x;
64 intBuffer[offset]=c;
65 }
66
67 static unsigned long __svga_getpixel32(int x, int y)
68 {
69 unsigned long offset;
70
71 const GLint *intBuffer=(void *)SVGABuffer.ReadBuffer;
72 y = SVGAInfo->height-y-1;
73 offset = y * SVGAInfo->width + x;
74 return intBuffer[offset];
75 }
76
77 void __set_color32( GLcontext *ctx,
78 GLubyte red, GLubyte green,
79 GLubyte blue, GLubyte alpha )
80 {
81 SVGAMesa->red = red;
82 SVGAMesa->green = green;
83 SVGAMesa->blue = blue;
84 SVGAMesa->truecolor = red<<16 | green<<8 | blue;
85 }
86
87 void __clear_color32( GLcontext *ctx,
88 GLubyte red, GLubyte green,
89 GLubyte blue, GLubyte alpha )
90 {
91 SVGAMesa->clear_truecolor = red<<16 | green<<8 | blue;
92 }
93
94 GLbitfield __clear32( 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 GLint *intBuffer=(void *)SVGABuffer.FrontBuffer;
102 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
103 intBuffer[i]=SVGAMesa->clear_truecolor;
104 }
105 else {
106 GLubyte *tmp = SVGABuffer.DrawBuffer;
107 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
108 for (i=x;i<width;i++)
109 for (j=y;j<height;j++)
110 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
111 SVGABuffer.DrawBuffer = tmp;
112 }
113 }
114 if (mask & DD_BACK_LEFT_BIT) {
115 if (all) {
116 GLint *intBuffer=(void *)SVGABuffer.BackBuffer;
117 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
118 intBuffer[i]=SVGAMesa->clear_truecolor;
119 }
120 else {
121 GLubyte *tmp = SVGABuffer.DrawBuffer;
122 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
123 for (i=x;i<width;i++)
124 for (j=y;j<height;j++)
125 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
126 SVGABuffer.DrawBuffer = tmp;
127 }
128 }
129 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
130 }
131
132 void __write_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
133 const GLubyte rgba[][4], const GLubyte mask[] )
134 {
135 int i;
136 if (mask) {
137 /* draw some pixels */
138 for (i=0; i<n; i++, x++) {
139 if (mask[i]) {
140 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
141 }
142 }
143 }
144 else {
145 /* draw all pixels */
146 for (i=0; i<n; i++, x++) {
147 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
148 }
149 }
150 }
151
152 void __write_mono_rgba_span32( const GLcontext *ctx,
153 GLuint n, GLint x, GLint y,
154 const GLubyte mask[])
155 {
156 int i;
157 for (i=0; i<n; i++, x++) {
158 if (mask[i]) {
159 __svga_drawpixel32( x, y, SVGAMesa->truecolor);
160 }
161 }
162 }
163
164 void __read_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
165 GLubyte rgba[][4] )
166 {
167 int i;
168 for (i=0; i<n; i++, x++) {
169 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x, y ));
170 }
171 }
172
173 void __write_rgba_pixels32( const GLcontext *ctx,
174 GLuint n, const GLint x[], const GLint y[],
175 const GLubyte rgba[][4], const GLubyte mask[] )
176 {
177 int i;
178 for (i=0; i<n; i++) {
179 if (mask[i]) {
180 __svga_drawpixel32( x[i], y[i], RGB2BGR32(*((GLint*)rgba[i])));
181 }
182 }
183 }
184
185 void __write_mono_rgba_pixels32( const GLcontext *ctx,
186 GLuint n,
187 const GLint x[], const GLint y[],
188 const GLubyte mask[] )
189 {
190 int i;
191 /* use current rgb color */
192 for (i=0; i<n; i++) {
193 if (mask[i]) {
194 __svga_drawpixel32( x[i], y[i], SVGAMesa->truecolor );
195 }
196 }
197 }
198
199 void __read_rgba_pixels32( const GLcontext *ctx,
200 GLuint n, const GLint x[], const GLint y[],
201 GLubyte rgba[][4], const GLubyte mask[] )
202 {
203 int i;
204 for (i=0; i<n; i++,x++) {
205 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x[i], y[i] ));
206 }
207 }
208
209 #endif
210