72ac8183294e87437eeae48443c42a50419c9c27
[mesa.git] / src / mesa / drivers / svga / svgamesa16.c
1 /* $Id: svgamesa16.c,v 1.11 2002/11/11 18:42:40 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 "svgamesa16.h"
38 #include "swrast/swrast.h"
39
40
41 static void __svga_drawpixel16(int x, int y, unsigned long c)
42 {
43 unsigned long offset;
44 GLshort *shortBuffer=(void *)SVGABuffer.DrawBuffer;
45 y = SVGAInfo->height-y-1;
46 offset = y * SVGAInfo->width + x;
47 shortBuffer[offset]=c;
48 }
49
50 static unsigned long __svga_getpixel16(int x, int y)
51 {
52 unsigned long offset;
53
54 GLshort *shortBuffer=(void *)SVGABuffer.ReadBuffer;
55 y = SVGAInfo->height-y-1;
56 offset = y * SVGAInfo->width + x;
57 return shortBuffer[offset];
58 }
59
60 void __clear_color16( GLcontext *ctx, const GLfloat color[4] )
61 {
62 GLubyte col[3];
63 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
64 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
65 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
66 SVGAMesa->clear_hicolor = (col[0] >> 3) << 11 |
67 (col[1] >> 2) << 5 |
68 (col[2] >> 3);
69 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
70 }
71
72 void __clear16( GLcontext *ctx, GLbitfield mask, GLboolean all,
73 GLint x, GLint y, GLint width, GLint height )
74 {
75 int i,j;
76
77 if (mask & DD_FRONT_LEFT_BIT) {
78 if (all) {
79 GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
80 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
81 shortBuffer[i]=SVGAMesa->clear_hicolor;
82 }
83 else {
84 GLubyte *tmp = SVGABuffer.DrawBuffer;
85 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
86 for (i=x;i<width;i++)
87 for (j=y;j<height;j++)
88 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
89 SVGABuffer.DrawBuffer = tmp;
90 }
91 mask &= ~DD_FRONT_LEFT_BIT;
92 }
93 if (mask & DD_BACK_LEFT_BIT) {
94 if (all) {
95 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
96 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
97 shortBuffer[i]=SVGAMesa->clear_hicolor;
98 }
99 else {
100 GLubyte *tmp = SVGABuffer.DrawBuffer;
101 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
102 for (i=x;i<width;i++)
103 for (j=y;j<height;j++)
104 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
105 SVGABuffer.DrawBuffer = tmp;
106 }
107 mask &= ~DD_BACK_LEFT_BIT;
108 }
109
110 if (mask)
111 _swrast_Clear( ctx, mask, all, x, y, width, height );
112 }
113
114 void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
115 const GLubyte rgba[][4], const GLubyte mask[] )
116 {
117 int i;
118 if (mask) {
119 /* draw some pixels */
120 for (i=0; i<n; i++, x++) {
121 if (mask[i]) {
122 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
123 (rgba[i][GCOMP]>>2)<<5 | \
124 (rgba[i][BCOMP]>>3));
125 }
126 }
127 }
128 else {
129 /* draw all pixels */
130 for (i=0; i<n; i++, x++) {
131 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
132 (rgba[i][GCOMP]>>2)<<5 | \
133 (rgba[i][BCOMP]>>3));
134 }
135 }
136 }
137
138 void __write_mono_rgba_span16( const GLcontext *ctx,
139 GLuint n, GLint x, GLint y,
140 const GLchan color[4], const GLubyte mask[])
141 {
142 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
143 int i;
144 for (i=0; i<n; i++, x++) {
145 if (mask[i]) {
146 __svga_drawpixel16( x, y, hicolor);
147 }
148 }
149 }
150
151 void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
152 GLubyte rgba[][4] )
153 {
154 int i,pix;
155 for (i=0; i<n; i++, x++) {
156 pix = __svga_getpixel16( x, y );
157 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
158 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
159 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
160 }
161 }
162
163 void __write_rgba_pixels16( const GLcontext *ctx,
164 GLuint n, const GLint x[], const GLint y[],
165 const GLubyte rgba[][4], const GLubyte mask[] )
166 {
167 int i;
168 for (i=0; i<n; i++) {
169 if (mask[i]) {
170 __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
171 (rgba[i][GCOMP]>>2)<<5 | \
172 (rgba[i][BCOMP]>>3));
173 }
174 }
175 }
176
177
178 void __write_mono_rgba_pixels16( const GLcontext *ctx,
179 GLuint n,
180 const GLint x[], const GLint y[],
181 const GLchan color[4], const GLubyte mask[] )
182 {
183 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
184 int i;
185 for (i=0; i<n; i++) {
186 if (mask[i]) {
187 __svga_drawpixel16( x[i], y[i], hicolor );
188 }
189 }
190 }
191
192 void __read_rgba_pixels16( const GLcontext *ctx,
193 GLuint n, const GLint x[], const GLint y[],
194 GLubyte rgba[][4], const GLubyte mask[] )
195 {
196 int i,pix;
197 for (i=0; i<n; i++,x++) {
198 pix = __svga_getpixel16( x[i], y[i] );
199 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
200 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
201 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
202 }
203 }
204
205 #else
206
207
208 /* silence compiler warning */
209 extern void _mesa_svga16_dummy_function(void);
210 void _mesa_svga16_dummy_function(void)
211 {
212 }
213
214
215 #endif