Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / drivers / svga / svgamesa16.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.0
5 * Copyright (C) 1995-2002 Brian Paul
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22
23 /*
24 * SVGA driver for Mesa.
25 * Original author: Brian Paul
26 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "conf.h"
31 #endif
32
33 #ifdef SVGA
34
35 #include "svgapix.h"
36 #include "svgamesa16.h"
37 #include "swrast/swrast.h"
38
39
40 static void __svga_drawpixel16(int x, int y, unsigned long c)
41 {
42 unsigned long offset;
43 GLshort *shortBuffer=(void *)SVGABuffer.DrawBuffer;
44 y = SVGAInfo->height-y-1;
45 offset = y * SVGAInfo->width + x;
46 shortBuffer[offset]=c;
47 }
48
49 static unsigned long __svga_getpixel16(int x, int y)
50 {
51 unsigned long offset;
52
53 GLshort *shortBuffer=(void *)SVGABuffer.ReadBuffer;
54 y = SVGAInfo->height-y-1;
55 offset = y * SVGAInfo->width + x;
56 return shortBuffer[offset];
57 }
58
59 void __clear_color16( GLcontext *ctx, const GLfloat color[4] )
60 {
61 GLubyte col[3];
62 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
63 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
64 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
65 SVGAMesa->clear_hicolor = (col[0] >> 3) << 11 |
66 (col[1] >> 2) << 5 |
67 (col[2] >> 3);
68 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
69 }
70
71 void __clear16( GLcontext *ctx, GLbitfield mask )
72 {
73 int i,j;
74 int x = ctx->DrawBuffer->_Xmin;
75 int y = ctx->DrawBuffer->_Ymin;
76 int width = ctx->DrawBuffer->_Xmax - x;
77 int height = ctx->DrawBuffer->_Ymax - y;
78 GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
79
80 if (mask & DD_FRONT_LEFT_BIT) {
81 if (all) {
82 GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
83 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
84 shortBuffer[i]=SVGAMesa->clear_hicolor;
85 }
86 else {
87 GLubyte *tmp = SVGABuffer.DrawBuffer;
88 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
89 for (i=x;i<width;i++)
90 for (j=y;j<height;j++)
91 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
92 SVGABuffer.DrawBuffer = tmp;
93 }
94 mask &= ~DD_FRONT_LEFT_BIT;
95 }
96 if (mask & DD_BACK_LEFT_BIT) {
97 if (all) {
98 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
99 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
100 shortBuffer[i]=SVGAMesa->clear_hicolor;
101 }
102 else {
103 GLubyte *tmp = SVGABuffer.DrawBuffer;
104 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
105 for (i=x;i<width;i++)
106 for (j=y;j<height;j++)
107 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
108 SVGABuffer.DrawBuffer = tmp;
109 }
110 mask &= ~DD_BACK_LEFT_BIT;
111 }
112
113 if (mask)
114 _swrast_Clear( ctx, mask );
115 }
116
117 void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
118 const GLubyte rgba[][4], const GLubyte mask[] )
119 {
120 int i;
121 if (mask) {
122 /* draw some pixels */
123 for (i=0; i<n; i++, x++) {
124 if (mask[i]) {
125 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
126 (rgba[i][GCOMP]>>2)<<5 | \
127 (rgba[i][BCOMP]>>3));
128 }
129 }
130 }
131 else {
132 /* draw all pixels */
133 for (i=0; i<n; i++, x++) {
134 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
135 (rgba[i][GCOMP]>>2)<<5 | \
136 (rgba[i][BCOMP]>>3));
137 }
138 }
139 }
140
141 void __write_mono_rgba_span16( const GLcontext *ctx,
142 GLuint n, GLint x, GLint y,
143 const GLchan color[4], const GLubyte mask[])
144 {
145 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
146 int i;
147 for (i=0; i<n; i++, x++) {
148 if (mask[i]) {
149 __svga_drawpixel16( x, y, hicolor);
150 }
151 }
152 }
153
154 void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
155 GLubyte rgba[][4] )
156 {
157 int i,pix;
158 for (i=0; i<n; i++, x++) {
159 pix = __svga_getpixel16( x, y );
160 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
161 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
162 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
163 }
164 }
165
166 void __write_rgba_pixels16( const GLcontext *ctx,
167 GLuint n, const GLint x[], const GLint y[],
168 const GLubyte rgba[][4], const GLubyte mask[] )
169 {
170 int i;
171 for (i=0; i<n; i++) {
172 if (mask[i]) {
173 __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
174 (rgba[i][GCOMP]>>2)<<5 | \
175 (rgba[i][BCOMP]>>3));
176 }
177 }
178 }
179
180
181 void __write_mono_rgba_pixels16( const GLcontext *ctx,
182 GLuint n,
183 const GLint x[], const GLint y[],
184 const GLchan color[4], const GLubyte mask[] )
185 {
186 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
187 int i;
188 for (i=0; i<n; i++) {
189 if (mask[i]) {
190 __svga_drawpixel16( x[i], y[i], hicolor );
191 }
192 }
193 }
194
195 void __read_rgba_pixels16( const GLcontext *ctx,
196 GLuint n, const GLint x[], const GLint y[],
197 GLubyte rgba[][4], const GLubyte mask[] )
198 {
199 int i,pix;
200 for (i=0; i<n; i++,x++) {
201 pix = __svga_getpixel16( x[i], y[i] );
202 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
203 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
204 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
205 }
206 }
207
208 #else
209
210
211 /* silence compiler warning */
212 extern void _mesa_svga16_dummy_function(void);
213 void _mesa_svga16_dummy_function(void)
214 {
215 }
216
217
218 #endif