Remove x/y/width/height parameters from Clear functions.
[mesa.git] / src / mesa / drivers / svga / svgamesa15.c
1 /* $Id: svgamesa15.c,v 1.12 2006/11/01 19:35:23 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 )
70 {
71 int i, j;
72 int x = ctx->DrawBuffer->_Xmin;
73 int y = ctx->DrawBuffer->_Ymin;
74 int width = ctx->DrawBuffer->_Xmax - x;
75 int height = ctx->DrawBuffer->_Ymax - y;
76 GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
77
78 if (mask & DD_FRONT_LEFT_BIT) {
79 GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
80 if (all) {
81 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
82 shortBuffer[i]=SVGAMesa->clear_hicolor;
83 }
84 else {
85 GLubyte *tmp = SVGABuffer.DrawBuffer;
86 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
87 for (i=x;i<width;i++)
88 for (j=y;j<height;j++)
89 __svga_drawpixel15(i,j,SVGAMesa->clear_hicolor);
90 SVGABuffer.DrawBuffer = tmp;
91 }
92 mask &= ~DD_FRONT_LEFT_BIT;
93 }
94 if (mask & DD_BACK_LEFT_BIT) {
95 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
96 if (all) {
97 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
98 shortBuffer[i]=SVGAMesa->clear_hicolor;
99 }
100 else {
101 GLubyte *tmp = SVGABuffer.DrawBuffer;
102 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
103 for (i=x;i<width;i++)
104 for (j=y;j<height;j++)
105 __svga_drawpixel15(i,j,SVGAMesa->clear_hicolor);
106 SVGABuffer.DrawBuffer = tmp;
107 }
108 mask &= ~DD_BACK_LEFT_BIT;
109 }
110
111 if (mask)
112 _swrast_Clear( ctx, mask );
113 }
114
115 void __write_rgba_span15( const GLcontext *ctx, GLuint n, GLint x, GLint y,
116 const GLubyte rgba[][4], const GLubyte mask[] )
117 {
118 int i;
119 if (mask) {
120 /* draw some pixels */
121 for (i=0; i<n; i++, x++) {
122 if (mask[i]) {
123 __svga_drawpixel15( x, y, (rgba[i][RCOMP]>>3)<<10 | \
124 (rgba[i][GCOMP]>>3)<<5 | \
125 (rgba[i][BCOMP]>>3));
126 }
127 }
128 }
129 else {
130 /* draw all pixels */
131 for (i=0; i<n; i++, x++) {
132 __svga_drawpixel15( x, y, (rgba[i][RCOMP]>>3)<<10 | \
133 (rgba[i][GCOMP]>>3)<<5 | \
134 (rgba[i][BCOMP]>>3));
135 }
136 }
137 }
138
139 void __write_mono_rgba_span15( const GLcontext *ctx,
140 GLuint n, GLint x, GLint y,
141 const GLchan color[4], const GLubyte mask[])
142 {
143 GLushort hicolor = (color[RCOMP] >> 3) << 10 |
144 (color[GCOMP] >> 3) << 5 |
145 (color[BCOMP] >> 3);
146 int i;
147 for (i=0; i<n; i++, x++) {
148 if (mask[i]) {
149 __svga_drawpixel15( x, y, hicolor);
150 }
151 }
152 }
153
154 void __read_rgba_span15( 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_getpixel15( x, y);
160 rgba[i][RCOMP] = ((pix>>10)<<3) & 0xff;
161 rgba[i][GCOMP] = ((pix>> 5)<<3) & 0xff;
162 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
163 }
164 }
165
166 void __write_rgba_pixels15( 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_drawpixel15( x[i], y[i], (rgba[i][RCOMP]>>3)<<10 | \
174 (rgba[i][GCOMP]>>3)<<5 | \
175 (rgba[i][BCOMP]>>3));
176 }
177 }
178 }
179
180
181 void __write_mono_rgba_pixels15( 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) << 10 |
187 (color[GCOMP] >> 3) << 5 |
188 (color[BCOMP] >> 3);
189 int i;
190 /* use current rgb color */
191 for (i=0; i<n; i++) {
192 if (mask[i]) {
193 __svga_drawpixel15( x[i], y[i], hicolor );
194 }
195 }
196 }
197
198 void __read_rgba_pixels15( const GLcontext *ctx,
199 GLuint n, const GLint x[], const GLint y[],
200 GLubyte rgba[][4], const GLubyte mask[] )
201 {
202 int i,pix;
203 for (i=0; i<n; i++,x++) {
204 pix = __svga_getpixel15( x[i], y[i] );
205 rgba[i][RCOMP] = ((pix>>10)<<3) & 0xff;
206 rgba[i][GCOMP] = ((pix>> 5)<<3) & 0xff;
207 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
208 }
209 }
210
211 #else
212
213
214 /* silence compiler warning */
215 extern void _mesa_svga15_dummy_function(void);
216 void _mesa_svga15_dummy_function(void)
217 {
218 }
219
220
221 #endif