~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/svga/svgamesa16.c

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: svgamesa16.c,v 1.11.36.1 2006/11/02 12:02:17 alanh Exp $ */
 
2
 
 
3
/*
 
4
 * Mesa 3-D graphics library
 
5
 * Version:  5.0
 
6
 * Copyright (C) 1995-2002  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
#include "svgapix.h"
 
37
#include "svgamesa16.h"
 
38
#include "swrast/swrast.h"
 
39
 
 
40
 
 
41
static void __svga_drawpixel16(int x, int y, unsigned long c)
 
42
{
 
43
    unsigned long offset;
 
44
    GLshort *shortBuffer=(void *)SVGABuffer.DrawBuffer;
 
45
    y = SVGAInfo->height-y-1;
 
46
    offset = y * SVGAInfo->width + x;
 
47
    shortBuffer[offset]=c;
 
48
}
 
49
 
 
50
static unsigned long __svga_getpixel16(int x, int y)
 
51
{
 
52
    unsigned long offset;
 
53
 
 
54
    GLshort *shortBuffer=(void *)SVGABuffer.ReadBuffer;
 
55
    y = SVGAInfo->height-y-1;
 
56
    offset = y * SVGAInfo->width + x;
 
57
    return shortBuffer[offset];
 
58
}
 
59
 
 
60
void __clear_color16( GLcontext *ctx, const GLfloat color[4] )
 
61
{
 
62
   GLubyte col[3];
 
63
   CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
 
64
   CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
 
65
   CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
 
66
   SVGAMesa->clear_hicolor = (col[0] >> 3) << 11 |
 
67
                              (col[1] >> 2) << 5 |
 
68
                              (col[2] >> 3); 
 
69
/*    SVGAMesa->clear_hicolor=(red)<<11 | (green)<<5 | (blue); */
 
70
}   
 
71
 
 
72
void __clear16( GLcontext *ctx, GLbitfield mask )
 
73
{
 
74
   int i,j;
 
75
   int x = ctx->DrawBuffer->_Xmin;
 
76
   int y = ctx->DrawBuffer->_Ymin;
 
77
   int width = ctx->DrawBuffer->_Xmax - x;
 
78
   int height = ctx->DrawBuffer->_Ymax - y;
 
79
   GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
 
80
 
 
81
   if (mask & DD_FRONT_LEFT_BIT) {
 
82
      if (all) {
 
83
         GLshort *shortBuffer=(void *)SVGABuffer.FrontBuffer;
 
84
         for (i=0;i<SVGABuffer.BufferSize / 2;i++)
 
85
            shortBuffer[i]=SVGAMesa->clear_hicolor;
 
86
      }
 
87
      else {
 
88
         GLubyte *tmp = SVGABuffer.DrawBuffer;
 
89
         SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
 
90
         for (i=x;i<width;i++)    
 
91
            for (j=y;j<height;j++)    
 
92
               __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
 
93
         SVGABuffer.DrawBuffer = tmp;
 
94
      }
 
95
      mask &= ~DD_FRONT_LEFT_BIT;
 
96
   }
 
97
   if (mask & DD_BACK_LEFT_BIT) {
 
98
      if (all) {
 
99
         GLshort *shortBuffer=(void *)SVGABuffer.BackBuffer;
 
100
         for (i=0;i<SVGABuffer.BufferSize / 2;i++)
 
101
            shortBuffer[i]=SVGAMesa->clear_hicolor;
 
102
      }
 
103
      else {
 
104
         GLubyte *tmp = SVGABuffer.DrawBuffer;
 
105
         SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
 
106
         for (i=x;i<width;i++)    
 
107
            for (j=y;j<height;j++)    
 
108
               __svga_drawpixel16(i,j,SVGAMesa->clear_hicolor);
 
109
         SVGABuffer.DrawBuffer = tmp;
 
110
      }
 
111
      mask &= ~DD_BACK_LEFT_BIT;
 
112
   }
 
113
 
 
114
   if (mask)
 
115
      _swrast_Clear( ctx, mask );
 
116
}
 
117
 
 
118
void __write_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
 
119
                          const GLubyte rgba[][4], const GLubyte mask[] )
 
120
{
 
121
   int i;
 
122
   if (mask) {
 
123
      /* draw some pixels */
 
124
      for (i=0; i<n; i++, x++) {
 
125
         if (mask[i]) {
 
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
   else {
 
133
      /* draw all pixels */
 
134
      for (i=0; i<n; i++, x++) {
 
135
         __svga_drawpixel16( x, y, (rgba[i][RCOMP]>>3)<<11 | \
 
136
                                   (rgba[i][GCOMP]>>2)<<5  | \
 
137
                                   (rgba[i][BCOMP]>>3));
 
138
      }
 
139
   }
 
140
}
 
141
 
 
142
void __write_mono_rgba_span16( const GLcontext *ctx,
 
143
                               GLuint n, GLint x, GLint y,
 
144
                               const GLchan color[4], const GLubyte mask[])
 
145
{
 
146
   GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3); 
 
147
   int i;
 
148
   for (i=0; i<n; i++, x++) {
 
149
      if (mask[i]) {
 
150
         __svga_drawpixel16( x, y, hicolor);
 
151
      }
 
152
   }
 
153
}
 
154
 
 
155
void __read_rgba_span16( const GLcontext *ctx, GLuint n, GLint x, GLint y,
 
156
                         GLubyte rgba[][4] )
 
157
{
 
158
   int i,pix;
 
159
   for (i=0; i<n; i++, x++) {
 
160
    pix = __svga_getpixel16( x, y );
 
161
    rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
 
162
    rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
 
163
    rgba[i][BCOMP] = ((pix    )<<3) & 0xff;
 
164
   }
 
165
}
 
166
 
 
167
void __write_rgba_pixels16( const GLcontext *ctx,
 
168
                            GLuint n, const GLint x[], const GLint y[],
 
169
                            const GLubyte rgba[][4], const GLubyte mask[] )
 
170
{
 
171
   int i;
 
172
   for (i=0; i<n; i++) {
 
173
      if (mask[i]) {
 
174
         __svga_drawpixel16( x[i], y[i], (rgba[i][RCOMP]>>3)<<11 | \
 
175
                                         (rgba[i][GCOMP]>>2)<<5  | \
 
176
                                         (rgba[i][BCOMP]>>3));
 
177
      }
 
178
   }
 
179
}
 
180
 
 
181
 
 
182
void __write_mono_rgba_pixels16( const GLcontext *ctx,
 
183
                                 GLuint n,
 
184
                                 const GLint x[], const GLint y[],
 
185
                                 const GLchan color[4], const GLubyte mask[] )
 
186
{
 
187
   GLushort hicolor=(color[RCOMP]>>3)<<11 | (color[GCOMP]>>2)<<5 | (color[BCOMP]>>3); 
 
188
   int i;
 
189
   for (i=0; i<n; i++) {
 
190
      if (mask[i]) {
 
191
         __svga_drawpixel16( x[i], y[i], hicolor );
 
192
      }
 
193
   }
 
194
}
 
195
 
 
196
void __read_rgba_pixels16( const GLcontext *ctx,
 
197
                           GLuint n, const GLint x[], const GLint y[],
 
198
                           GLubyte rgba[][4], const GLubyte mask[] )
 
199
{
 
200
   int i,pix;
 
201
   for (i=0; i<n; i++,x++) {
 
202
    pix = __svga_getpixel16( x[i], y[i] );
 
203
    rgba[i][RCOMP] = ((pix>>11)<<3) & 0xff;
 
204
    rgba[i][GCOMP] = ((pix>> 5)<<2) & 0xff;
 
205
    rgba[i][BCOMP] = ((pix    )<<3) & 0xff;
 
206
   }
 
207
}
 
208
 
 
209
#else
 
210
 
 
211
 
 
212
/* silence compiler warning */
 
213
extern void _mesa_svga16_dummy_function(void);
 
214
void _mesa_svga16_dummy_function(void)
 
215
{
 
216
}
 
217
 
 
218
 
 
219
#endif