updated for Mesa 3.3
[mesa.git] / src / mesa / drivers / svga / svgamesa16.c
1 /* $Id: svgamesa16.c,v 1.4 2000/01/25 00:03:02 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 SVGA
31
32 #include "svgapix.h"
33 #include "svgamesa16.h"
34
35
36 static void __svga_drawpixel16(int x, int y, unsigned long c)
37 {
38 unsigned long offset;
39 GLshort *shortBuffer=(void *)SVGABuffer.DrawBuffer;
40 y = SVGAInfo->height-y-1;
41 offset = y * SVGAInfo->width + x;
42 shortBuffer[offset]=c;
43 }
44
45 static unsigned long __svga_getpixel16(int x, int y)
46 {
47 unsigned long offset;
48
49 GLshort *shortBuffer=(void *)SVGABuffer.ReadBuffer;
50 y = SVGAInfo->height-y-1;
51 offset = y * SVGAInfo->width + x;
52 return shortBuffer[offset];
53 }
54
55 void __set_color16( GLcontext *ctx,
56 GLubyte red, GLubyte green,
57 GLubyte blue, GLubyte alpha )
58 {
59 SVGAMesa->hicolor=(red>>3)<<11 | (green>>2)<<5 | (blue>>3);
60 /* SVGAMesa->hicolor=(red)<<11 | (green)<<5 | (blue); */
61 }
62
63 void __clear_color16( GLcontext *ctx,
64 GLubyte red, GLubyte green,
65 GLubyte blue, GLubyte alpha )
66 {
67 SVGAMesa->clear_hicolor=(red>>3)<<11 | (green>>2)<<5 | (blue>>3);
68 /* SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
69 }
70
71 GLbitfield __clear16( GLcontext *ctx, GLbitfield mask, GLboolean all,
72 GLint x, GLint y, GLint width, GLint height )
73 {
74 int i,j;
75
76 if (mask & DD_FRONT_LEFT_BIT) {
77 if (all) {
78 GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
79 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
80 shortBuffer[i]=SVGAMesa->clear_hicolor;
81 }
82 else {
83 GLubyte *tmp = SVGABuffer.DrawBuffer;
84 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
85 for (i=x;i<width;i++)
86 for (j=y;j<height;j++)
87 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
88 SVGABuffer.DrawBuffer = tmp;
89 }
90 }
91 if (mask & DD_BACK_LEFT_BIT) {
92 if (all) {
93 GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
94 for (i=0;i<SVGABuffer.BufferSize / 2;i++)
95 shortBuffer[i]=SVGAMesa->clear_hicolor;
96 }
97 else {
98 GLubyte *tmp = SVGABuffer.DrawBuffer;
99 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
100 for (i=x;i<width;i++)
101 for (j=y;j<height;j++)
102 __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
103 SVGABuffer.DrawBuffer = tmp;
104 }
105 }
106 return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
107 }
108
109 void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
110 const GLubyte rgba[][4], const GLubyte mask[] )
111 {
112 int i;
113 if (mask) {
114 /* draw some pixels */
115 for (i=0; i<n; i++, x++) {
116 if (mask[i]) {
117 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
118 (rgba[i][GCOMP]>>2)<<5 | \
119 (rgba[i][BCOMP]>>3));
120 }
121 }
122 }
123 else {
124 /* draw all pixels */
125 for (i=0; i<n; i++, x++) {
126 __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
127 (rgba[i][GCOMP]>>2)<<5 | \
128 (rgba[i][BCOMP]>>3));
129 }
130 }
131 }
132
133 void __write_mono_rgba_span16( const GLcontext *ctx,
134 GLuint n, GLint x, GLint y,
135 const GLubyte mask[])
136 {
137 int i;
138 for (i=0; i<n; i++, x++) {
139 if (mask[i]) {
140 __svga_drawpixel16( x, y, SVGAMesa->hicolor);
141 }
142 }
143 }
144
145 void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
146 GLubyte rgba[][4] )
147 {
148 int i,pix;
149 for (i=0; i<n; i++, x++) {
150 pix = __svga_getpixel16( x, y );
151 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
152 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
153 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
154 }
155 }
156
157 void __write_rgba_pixels16( const GLcontext *ctx,
158 GLuint n, const GLint x[], const GLint y[],
159 const GLubyte rgba[][4], const GLubyte mask[] )
160 {
161 int i;
162 for (i=0; i<n; i++) {
163 if (mask[i]) {
164 __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
165 (rgba[i][GCOMP]>>2)<<5 | \
166 (rgba[i][BCOMP]>>3));
167 }
168 }
169 }
170
171
172 void __write_mono_rgba_pixels16( const GLcontext *ctx,
173 GLuint n,
174 const GLint x[], const GLint y[],
175 const GLubyte mask[] )
176 {
177 int i;
178 /* use current rgb color */
179 for (i=0; i<n; i++) {
180 if (mask[i]) {
181 __svga_drawpixel16( x[i], y[i], SVGAMesa->hicolor );
182 }
183 }
184 }
185
186 void __read_rgba_pixels16( const GLcontext *ctx,
187 GLuint n, const GLint x[], const GLint y[],
188 GLubyte rgba[][4], const GLubyte mask[] )
189 {
190 int i,pix;
191 for (i=0; i<n; i++,x++) {
192 pix = __svga_getpixel16( x[i], y[i] );
193 rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
194 rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
195 rgba[i][BCOMP] = ((pix )<<3) & 0xff;
196 }
197 }
198
199 #endif