fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / svga / svgamesa16.c
1 /* $Id: svgamesa16.c,v 1.6 2000/06/14 21:59:07 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 __set_color16( GLcontext *ctx,
60 GLubyte red, GLubyte green,
61 GLubyte blue, GLubyte alpha )
62 {
63 SVGAMesa->hicolor=(red>>3)<<11 | (green>>2)<<5 | (blue>>3);
64 /* SVGAMesa->hicolor=(red)<<11 | (green)<<5 | (blue); */
65 }
66
67 void __clear_color16( GLcontext *ctx,
68 GLubyte red, GLubyte green,
69 GLubyte blue, GLubyte alpha )
70 {
71 SVGAMesa->clear_hicolor=(red>>3)<<11 | (green>>2)<<5 | (blue>>3);
72 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
73 }
74
75 GLbitfield __clear16( GLcontext *ctx, GLbitfield mask, GLboolean all,
76 GLint x, GLint y, GLint width, GLint height )
77 {
78 int i,j;
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 }
95 if (mask & DD_BACK_LEFT_BIT) {
96 if (all) {
97 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
98 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
99 shortBuffer[i]=SVGAMesa->clear_hicolor;
100 }
101 else {
102 GLubyte *tmp = SVGABuffer.DrawBuffer;
103 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
104 for (i=x;i<width;i++)
105 for (j=y;j<height;j++)
106 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
107 SVGABuffer.DrawBuffer = tmp;
108 }
109 }
110 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
111 }
112
113 void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
114 const GLubyte rgba[][4], const GLubyte mask[] )
115 {
116 int i;
117 if (mask) {
118 /* draw some pixels */
119 for (i=0; i<n; i++, x++) {
120 if (mask[i]) {
121 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
122 (rgba[i][GCOMP]>>2)<<5 | \
123 (rgba[i][BCOMP]>>3));
124 }
125 }
126 }
127 else {
128 /* draw all pixels */
129 for (i=0; i<n; i++, x++) {
130 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
131 (rgba[i][GCOMP]>>2)<<5 | \
132 (rgba[i][BCOMP]>>3));
133 }
134 }
135 }
136
137 void __write_mono_rgba_span16( const GLcontext *ctx,
138 GLuint n, GLint x, GLint y,
139 const GLubyte mask[])
140 {
141 int i;
142 for (i=0; i<n; i++, x++) {
143 if (mask[i]) {
144 __svga_drawpixel16( x, y, SVGAMesa->hicolor);
145 }
146 }
147 }
148
149 void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
150 GLubyte rgba[][4] )
151 {
152 int i,pix;
153 for (i=0; i<n; i++, x++) {
154 pix = __svga_getpixel16( x, y );
155 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
156 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
157 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
158 }
159 }
160
161 void __write_rgba_pixels16( const GLcontext *ctx,
162 GLuint n, const GLint x[], const GLint y[],
163 const GLubyte rgba[][4], const GLubyte mask[] )
164 {
165 int i;
166 for (i=0; i<n; i++) {
167 if (mask[i]) {
168 __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
169 (rgba[i][GCOMP]>>2)<<5 | \
170 (rgba[i][BCOMP]>>3));
171 }
172 }
173 }
174
175
176 void __write_mono_rgba_pixels16( const GLcontext *ctx,
177 GLuint n,
178 const GLint x[], const GLint y[],
179 const GLubyte mask[] )
180 {
181 int i;
182 /* use current rgb color */
183 for (i=0; i<n; i++) {
184 if (mask[i]) {
185 __svga_drawpixel16( x[i], y[i], SVGAMesa->hicolor );
186 }
187 }
188 }
189
190 void __read_rgba_pixels16( const GLcontext *ctx,
191 GLuint n, const GLint x[], const GLint y[],
192 GLubyte rgba[][4], const GLubyte mask[] )
193 {
194 int i,pix;
195 for (i=0; i<n; i++,x++) {
196 pix = __svga_getpixel16( x[i], y[i] );
197 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
198 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
199 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
200 }
201 }
202
203 #else
204
205
206 /* silence compiler warning */
207 extern void _mesa_svga16_dummy_function(void);
208 void _mesa_svga16_dummy_function(void)
209 {
210 }
211
212
213 #endif