1 /* $Id: svgamesa32.c,v 1.12.36.1 2006/11/02 12:02:17 alanh Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-2002 Brian Paul
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.
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.
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.
25 * SVGA driver for Mesa.
26 * Original author: Brian Paul
27 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
37 #include "svgamesa32.h"
38 #include "swrast/swrast.h"
42 /* this doesn't compile with GCC on RedHat 6.1 */
43 static inline int RGB2BGR32(int c
)
53 static unsigned long RGB2BGR32(unsigned long color
)
55 return (color
& 0xff00)|(color
>>16)|((color
& 0xff)<<16);
59 static void __svga_drawpixel32(int x
, int y
, unsigned long c
)
63 GLint
*intBuffer
=(void *)SVGABuffer
.DrawBuffer
;
64 y
= SVGAInfo
->height
-y
-1;
65 offset
= y
* SVGAInfo
->width
+ x
;
69 static unsigned long __svga_getpixel32(int x
, int y
)
73 const GLint
*intBuffer
=(void *)SVGABuffer
.ReadBuffer
;
74 y
= SVGAInfo
->height
-y
-1;
75 offset
= y
* SVGAInfo
->width
+ x
;
76 return intBuffer
[offset
];
79 void __clear_color32( GLcontext
*ctx
, const GLfloat color
[4] )
82 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
83 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
84 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
85 SVGAMesa
->clear_truecolor
= (col
[0] << 16) | (col
[1] << 8) | col
[2];
88 void __clear32( GLcontext
*ctx
, GLbitfield mask
)
91 int x
= ctx
->DrawBuffer
->_Xmin
;
92 int y
= ctx
->DrawBuffer
->_Ymin
;
93 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
94 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
95 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
97 if (mask
& DD_FRONT_LEFT_BIT
) {
99 GLint
*intBuffer
=(void *)SVGABuffer
.FrontBuffer
;
100 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
101 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
104 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
105 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
106 for (i
=x
;i
<width
;i
++)
107 for (j
=y
;j
<height
;j
++)
108 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
109 SVGABuffer
.DrawBuffer
= tmp
;
111 mask
&= ~DD_FRONT_LEFT_BIT
;
113 if (mask
& DD_BACK_LEFT_BIT
) {
115 GLint
*intBuffer
=(void *)SVGABuffer
.BackBuffer
;
116 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
117 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
120 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
121 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
122 for (i
=x
;i
<width
;i
++)
123 for (j
=y
;j
<height
;j
++)
124 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
125 SVGABuffer
.DrawBuffer
= tmp
;
127 mask
&= ~DD_BACK_LEFT_BIT
;
131 _swrast_Clear( ctx
, mask
);
134 void __write_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
135 const GLubyte rgba
[][4], const GLubyte mask
[] )
139 /* draw some pixels */
140 for (i
=0; i
<n
; i
++, x
++) {
142 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
147 /* draw all pixels */
148 for (i
=0; i
<n
; i
++, x
++) {
149 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
154 void __write_mono_rgba_span32( const GLcontext
*ctx
,
155 GLuint n
, GLint x
, GLint y
,
156 const GLchan color
[4], const GLubyte mask
[])
159 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
160 for (i
=0; i
<n
; i
++, x
++) {
162 __svga_drawpixel32( x
, y
, truecolor
);
167 void __read_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
171 for (i
=0; i
<n
; i
++, x
++) {
172 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
, y
));
176 void __write_rgba_pixels32( const GLcontext
*ctx
,
177 GLuint n
, const GLint x
[], const GLint y
[],
178 const GLubyte rgba
[][4], const GLubyte mask
[] )
181 for (i
=0; i
<n
; i
++) {
183 __svga_drawpixel32( x
[i
], y
[i
], RGB2BGR32(*((GLint
*)rgba
[i
])));
188 void __write_mono_rgba_pixels32( const GLcontext
*ctx
,
190 const GLint x
[], const GLint y
[],
191 const GLchan color
[4], const GLubyte mask
[] )
193 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
195 for (i
=0; i
<n
; i
++) {
197 __svga_drawpixel32( x
[i
], y
[i
], truecolor
);
202 void __read_rgba_pixels32( const GLcontext
*ctx
,
203 GLuint n
, const GLint x
[], const GLint y
[],
204 GLubyte rgba
[][4], const GLubyte mask
[] )
207 for (i
=0; i
<n
; i
++,x
++) {
208 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
[i
], y
[i
] ));
216 /* silence compiler warning */
217 extern void _mesa_svga32_dummy_function(void);
218 void _mesa_svga32_dummy_function(void)