fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / svga / svgamesa8.c
1 /* $Id: svgamesa8.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
37 #include "svgapix.h"
38 #include "svgamesa8.h"
39
40 static void __svga_drawpixel8(int x, int y, unsigned long c)
41 {
42 unsigned long offset;
43 y = SVGAInfo->height-y-1;
44 offset = y * SVGAInfo->linewidth + x;
45 SVGABuffer.DrawBuffer[offset]=c;
46 }
47
48 static unsigned long __svga_getpixel8(int x, int y)
49 {
50 unsigned long offset;
51 y = SVGAInfo->height-y-1;
52 offset = y * SVGAInfo->linewidth + x;
53 return SVGABuffer.ReadBuffer[offset];
54 }
55
56 void __set_index8( GLcontext *ctx, GLuint index )
57 {
58 SVGAMesa->index = index;
59 }
60
61 void __clear_index8( GLcontext *ctx, GLuint index )
62 {
63 SVGAMesa->clear_index = index;
64 }
65
66 GLbitfield __clear8( GLcontext *ctx, GLbitfield mask, GLboolean all,
67 GLint x, GLint y, GLint width, GLint height )
68 {
69 int i,j;
70
71 if (mask & DD_FRONT_LEFT_BIT) {
72 if (all) {
73 memset(SVGABuffer.FrontBuffer, SVGAMesa->clear_index, SVGABuffer.BufferSize);
74 }
75 else {
76 GLubyte *tmp = SVGABuffer.DrawBuffer;
77 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
78 for (i=x;i<width;i++)
79 for (j=y;j<height;j++)
80 __svga_drawpixel8(i,j,SVGAMesa->clear_index);
81 SVGABuffer.DrawBuffer = tmp;
82 }
83 }
84 if (mask & DD_BACK_LEFT_BIT) {
85 if (all) {
86 memset(SVGABuffer.BackBuffer, SVGAMesa->clear_index, SVGABuffer.BufferSize);
87 }
88 else {
89 GLubyte *tmp = SVGABuffer.DrawBuffer;
90 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
91 for (i=x;i<width;i++)
92 for (j=y;j<height;j++)
93 __svga_drawpixel8(i,j,SVGAMesa->clear_index);
94 SVGABuffer.DrawBuffer = tmp;
95 }
96 }
97 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
98 }
99
100 void __write_ci32_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
101 const GLuint index[], const GLubyte mask[] )
102 {
103 int i;
104 for (i=0;i<n;i++,x++) {
105 if (mask[i]) {
106 __svga_drawpixel8( x, y, index[i]);
107 }
108 }
109 }
110
111 void __write_ci8_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
112 const GLubyte index[], const GLubyte mask[] )
113 {
114 int i;
115
116 for (i=0;i<n;i++,x++) {
117 if (mask[i]) {
118 __svga_drawpixel8( x, y, index[i]);
119 }
120 }
121 }
122
123 void __write_mono_ci_span8( const GLcontext *ctx, GLuint n,
124 GLint x, GLint y, const GLubyte mask[] )
125 {
126 int i;
127 for (i=0;i<n;i++,x++) {
128 if (mask[i]) {
129 __svga_drawpixel8( x, y, SVGAMesa->index);
130 }
131 }
132 }
133
134 void __read_ci32_span8( const GLcontext *ctx,
135 GLuint n, GLint x, GLint y, GLuint index[])
136 {
137 int i;
138 for (i=0; i<n; i++,x++) {
139 index[i] = __svga_getpixel8( x, y);
140 }
141 }
142
143 void __write_ci32_pixels8( const GLcontext *ctx,
144 GLuint n, const GLint x[], const GLint y[],
145 const GLuint index[], const GLubyte mask[] )
146 {
147 int i;
148 for (i=0; i<n; i++) {
149 if (mask[i]) {
150 __svga_drawpixel8( x[i], y[i], index[i]);
151 }
152 }
153 }
154
155
156 void __write_mono_ci_pixels8( const GLcontext *ctx, GLuint n,
157 const GLint x[], const GLint y[],
158 const GLubyte mask[] )
159 {
160 int i;
161 for (i=0; i<n; i++) {
162 if (mask[i]) {
163 __svga_drawpixel8( x[i], y[i], SVGAMesa->index);
164 }
165 }
166 }
167
168 void __read_ci32_pixels8( const GLcontext *ctx,
169 GLuint n, const GLint x[], const GLint y[],
170 GLuint index[], const GLubyte mask[] )
171 {
172 int i;
173 for (i=0; i<n; i++,x++) {
174 index[i] = __svga_getpixel8( x[i], y[i]);
175 }
176 }
177
178
179 #else
180
181
182 /* silence compiler warning */
183 extern void _mesa_svga8_dummy_function(void);
184 void _mesa_svga8_dummy_function(void)
185 {
186 }
187
188
189 #endif