1 /* $Id: svgamesa32.c,v 1.12 2002/11/11 18:42:42 brianp 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
, GLboolean all
,
89 GLint x
, GLint y
, GLint width
, GLint height
)
93 if (mask
& DD_FRONT_LEFT_BIT
) {
95 GLint
*intBuffer
=(void *)SVGABuffer
.FrontBuffer
;
96 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
97 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
100 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
101 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
102 for (i
=x
;i
<width
;i
++)
103 for (j
=y
;j
<height
;j
++)
104 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
105 SVGABuffer
.DrawBuffer
= tmp
;
107 mask
&= ~DD_FRONT_LEFT_BIT
;
109 if (mask
& DD_BACK_LEFT_BIT
) {
111 GLint
*intBuffer
=(void *)SVGABuffer
.BackBuffer
;
112 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
113 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
116 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
117 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
118 for (i
=x
;i
<width
;i
++)
119 for (j
=y
;j
<height
;j
++)
120 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
121 SVGABuffer
.DrawBuffer
= tmp
;
123 mask
&= ~DD_BACK_LEFT_BIT
;
127 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
130 void __write_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
131 const GLubyte rgba
[][4], const GLubyte mask
[] )
135 /* draw some pixels */
136 for (i
=0; i
<n
; i
++, x
++) {
138 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
143 /* draw all pixels */
144 for (i
=0; i
<n
; i
++, x
++) {
145 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
150 void __write_mono_rgba_span32( const GLcontext
*ctx
,
151 GLuint n
, GLint x
, GLint y
,
152 const GLchan color
[4], const GLubyte mask
[])
155 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
156 for (i
=0; i
<n
; i
++, x
++) {
158 __svga_drawpixel32( x
, y
, truecolor
);
163 void __read_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
167 for (i
=0; i
<n
; i
++, x
++) {
168 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
, y
));
172 void __write_rgba_pixels32( const GLcontext
*ctx
,
173 GLuint n
, const GLint x
[], const GLint y
[],
174 const GLubyte rgba
[][4], const GLubyte mask
[] )
177 for (i
=0; i
<n
; i
++) {
179 __svga_drawpixel32( x
[i
], y
[i
], RGB2BGR32(*((GLint
*)rgba
[i
])));
184 void __write_mono_rgba_pixels32( const GLcontext
*ctx
,
186 const GLint x
[], const GLint y
[],
187 const GLchan color
[4], const GLubyte mask
[] )
189 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
191 for (i
=0; i
<n
; i
++) {
193 __svga_drawpixel32( x
[i
], y
[i
], truecolor
);
198 void __read_rgba_pixels32( const GLcontext
*ctx
,
199 GLuint n
, const GLint x
[], const GLint y
[],
200 GLubyte rgba
[][4], const GLubyte mask
[] )
203 for (i
=0; i
<n
; i
++,x
++) {
204 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
[i
], y
[i
] ));
212 /* silence compiler warning */
213 extern void _mesa_svga32_dummy_function(void);
214 void _mesa_svga32_dummy_function(void)