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