fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / svga / svgamesa15.c
1 /* $Id: svgamesa15.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 "svgamesa15.h"
38
39 static void __svga_drawpixel15(int x, int y, unsigned long c)
40 {
41 unsigned long offset;
42 GLshort *shortBuffer=(void *)SVGABuffer.DrawBuffer;
43 y = SVGAInfo->height-y-1;
44 offset = y * SVGAInfo->width + x;
45 shortBuffer[offset]=c;
46 }
47
48 static unsigned long __svga_getpixel15(int x, int y)
49 {
50 unsigned long offset;
51 GLshort *shortBuffer=(void *)SVGABuffer.ReadBuffer;
52 y = SVGAInfo->height-y-1;
53 offset = y * SVGAInfo->width + x;
54 return shortBuffer[offset];
55 }
56
57 void __set_color15( GLcontext *ctx,
58 GLubyte red, GLubyte green,
59 GLubyte blue, GLubyte alpha )
60 {
61 SVGAMesa->hicolor=(red>>3)<<10 | (green>>3)<<5 | (blue>>3);
62 /* SVGAMesa->hicolor=(red)<<10 | (green)<<5 | (blue); */
63 }
64
65 void __clear_color15( GLcontext *ctx,
66 GLubyte red, GLubyte green,
67 GLubyte blue, GLubyte alpha )
68 {
69 SVGAMesa->clear_hicolor=(red>>3)<<10 | (green>>3)<<5 | (blue>>3);
70 /* SVGAMesa->clear_hicolor=(red)<<10 | (green)<<5 | (blue);*/
71 }
72
73 GLbitfield __clear15( GLcontext *ctx, GLbitfield mask, GLboolean all,
74 GLint x, GLint y, GLint width, GLint height )
75 {
76 int i, j;
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 }
93 if (mask & DD_BACK_LEFT_BIT) {
94 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
95 if (all) {
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_drawpixel15(i,j,SVGAMesa->clear_hicolor);
105 SVGABuffer.DrawBuffer = tmp;
106 }
107 }
108 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
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 GLubyte mask[])
138 {
139 int i;
140 for (i=0; i<n; i++, x++) {
141 if (mask[i]) {
142 __svga_drawpixel15( x, y, SVGAMesa->hicolor);
143 }
144 }
145 }
146
147 void __read_rgba_span15( const GLcontext *ctx, GLuint n, GLint x, GLint y,
148 GLubyte rgba[][4] )
149 {
150 int i,pix;
151 for (i=0; i<n; i++, x++) {
152 pix = __svga_getpixel15( x, y);
153 rgba[i][RCOMP] = ((pix>>10)<<3) & 0xff;
154 rgba[i][GCOMP] = ((pix>> 5)<<3) & 0xff;
155 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
156 }
157 }
158
159 void __write_rgba_pixels15( const GLcontext *ctx,
160 GLuint n, const GLint x[], const GLint y[],
161 const GLubyte rgba[][4], const GLubyte mask[] )
162 {
163 int i;
164 for (i=0; i<n; i++) {
165 if (mask[i]) {
166 __svga_drawpixel15( x[i], y[i], (rgba[i][RCOMP]>>3)<<10 | \
167 (rgba[i][GCOMP]>>3)<<5 | \
168 (rgba[i][BCOMP]>>3));
169 }
170 }
171 }
172
173
174 void __write_mono_rgba_pixels15( const GLcontext *ctx,
175 GLuint n,
176 const GLint x[], const GLint y[],
177 const GLubyte mask[] )
178 {
179 int i;
180 /* use current rgb color */
181 for (i=0; i<n; i++) {
182 if (mask[i]) {
183 __svga_drawpixel15( x[i], y[i], SVGAMesa->hicolor );
184 }
185 }
186 }
187
188 void __read_rgba_pixels15( const GLcontext *ctx,
189 GLuint n, const GLint x[], const GLint y[],
190 GLubyte rgba[][4], const GLubyte mask[] )
191 {
192 int i,pix;
193 for (i=0; i<n; i++,x++) {
194 pix = __svga_getpixel15( x[i], y[i] );
195 rgba[i][RCOMP] = ((pix>>10)<<3) & 0xff;
196 rgba[i][GCOMP] = ((pix>> 5)<<3) & 0xff;
197 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
198 }
199 }
200
201 #else
202
203
204 /* silence compiler warning */
205 extern void _mesa_svga15_dummy_function(void);
206 void _mesa_svga15_dummy_function(void)
207 {
208 }
209
210
211 #endif