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