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