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