Lots of GLchan datatype changes.
[mesa.git] / src / mesa / drivers / svga / svgamesa16.c
1 /* $Id: svgamesa16.c,v 1.8 2001/01/24 00:04:59 brianp 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 "svgamesa16.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 GLchan color[4] )
60 {
61 SVGAMesa->clear_hicolor = (color[0] >> 3) << 11 |
62 (color[1] >> 2) << 5 |
63 (color[2] >> 3);
64 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
65 }
66
67 GLbitfield __clear16( GLcontext *ctx, GLbitfield mask, GLboolean all,
68 GLint x, GLint y, GLint width, GLint height )
69 {
70 int i,j;
71
72 if (mask & DD_FRONT_LEFT_BIT) {
73 if (all) {
74 GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
75 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
76 shortBuffer[i]=SVGAMesa->clear_hicolor;
77 }
78 else {
79 GLubyte *tmp = SVGABuffer.DrawBuffer;
80 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
81 for (i=x;i<width;i++)
82 for (j=y;j<height;j++)
83 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
84 SVGABuffer.DrawBuffer = tmp;
85 }
86 }
87 if (mask & DD_BACK_LEFT_BIT) {
88 if (all) {
89 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
90 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
91 shortBuffer[i]=SVGAMesa->clear_hicolor;
92 }
93 else {
94 GLubyte *tmp = SVGABuffer.DrawBuffer;
95 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
96 for (i=x;i<width;i++)
97 for (j=y;j<height;j++)
98 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
99 SVGABuffer.DrawBuffer = tmp;
100 }
101 }
102 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
103 }
104
105 void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
106 const GLubyte rgba[][4], const GLubyte mask[] )
107 {
108 int i;
109 if (mask) {
110 /* draw some pixels */
111 for (i=0; i<n; i++, x++) {
112 if (mask[i]) {
113 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
114 (rgba[i][GCOMP]>>2)<<5 | \
115 (rgba[i][BCOMP]>>3));
116 }
117 }
118 }
119 else {
120 /* draw all pixels */
121 for (i=0; i<n; i++, x++) {
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
129 void __write_mono_rgba_span16( const GLcontext *ctx,
130 GLuint n, GLint x, GLint y,
131 const GLchan color[4], const GLubyte mask[])
132 {
133 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
134 int i;
135 for (i=0; i<n; i++, x++) {
136 if (mask[i]) {
137 __svga_drawpixel16( x, y, hicolor);
138 }
139 }
140 }
141
142 void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
143 GLubyte rgba[][4] )
144 {
145 int i,pix;
146 for (i=0; i<n; i++, x++) {
147 pix = __svga_getpixel16( x, y );
148 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
149 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
150 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
151 }
152 }
153
154 void __write_rgba_pixels16( const GLcontext *ctx,
155 GLuint n, const GLint x[], const GLint y[],
156 const GLubyte rgba[][4], const GLubyte mask[] )
157 {
158 int i;
159 for (i=0; i<n; i++) {
160 if (mask[i]) {
161 __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
162 (rgba[i][GCOMP]>>2)<<5 | \
163 (rgba[i][BCOMP]>>3));
164 }
165 }
166 }
167
168
169 void __write_mono_rgba_pixels16( const GLcontext *ctx,
170 GLuint n,
171 const GLint x[], const GLint y[],
172 const GLchan color[4], const GLubyte mask[] )
173 {
174 GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3);
175 int i;
176 for (i=0; i<n; i++) {
177 if (mask[i]) {
178 __svga_drawpixel16( x[i], y[i], hicolor );
179 }
180 }
181 }
182
183 void __read_rgba_pixels16( const GLcontext *ctx,
184 GLuint n, const GLint x[], const GLint y[],
185 GLubyte rgba[][4], const GLubyte mask[] )
186 {
187 int i,pix;
188 for (i=0; i<n; i++,x++) {
189 pix = __svga_getpixel16( x[i], y[i] );
190 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
191 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
192 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
193 }
194 }
195
196 #else
197
198
199 /* silence compiler warning */
200 extern void _mesa_svga16_dummy_function(void);
201 void _mesa_svga16_dummy_function(void)
202 {
203 }
204
205
206 #endif