1 /* $Id: svgamesa32.c,v 1.8 2000/11/14 17:40:14 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-2000 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"
40 /* this doesn't compile with GCC on RedHat 6.1 */
41 static inline int RGB2BGR32(int c
)
51 static unsigned long RGB2BGR32(unsigned long color
)
53 return (color
& 0xff00)|(color
>>16)|((color
& 0xff)<<16);
57 static void __svga_drawpixel32(int x
, int y
, unsigned long c
)
61 GLint
*intBuffer
=(void *)SVGABuffer
.DrawBuffer
;
62 y
= SVGAInfo
->height
-y
-1;
63 offset
= y
* SVGAInfo
->width
+ x
;
67 static unsigned long __svga_getpixel32(int x
, int y
)
71 const GLint
*intBuffer
=(void *)SVGABuffer
.ReadBuffer
;
72 y
= SVGAInfo
->height
-y
-1;
73 offset
= y
* SVGAInfo
->width
+ x
;
74 return intBuffer
[offset
];
77 void __clear_color32( GLcontext
*ctx
,
78 GLubyte red
, GLubyte green
,
79 GLubyte blue
, GLubyte alpha
)
81 SVGAMesa
->clear_truecolor
= red
<<16 | green
<<8 | blue
;
84 GLbitfield
__clear32( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
85 GLint x
, GLint y
, GLint width
, GLint height
)
89 if (mask
& DD_FRONT_LEFT_BIT
) {
91 GLint
*intBuffer
=(void *)SVGABuffer
.FrontBuffer
;
92 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
93 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
96 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
97 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
99 for (j
=y
;j
<height
;j
++)
100 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
101 SVGABuffer
.DrawBuffer
= tmp
;
104 if (mask
& DD_BACK_LEFT_BIT
) {
106 GLint
*intBuffer
=(void *)SVGABuffer
.BackBuffer
;
107 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
108 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
111 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
112 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
113 for (i
=x
;i
<width
;i
++)
114 for (j
=y
;j
<height
;j
++)
115 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
116 SVGABuffer
.DrawBuffer
= tmp
;
119 return mask
& (~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
122 void __write_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
123 const GLubyte rgba
[][4], const GLubyte mask
[] )
127 /* draw some pixels */
128 for (i
=0; i
<n
; i
++, x
++) {
130 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
135 /* draw all pixels */
136 for (i
=0; i
<n
; i
++, x
++) {
137 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
142 void __write_mono_rgba_span32( const GLcontext
*ctx
,
143 GLuint n
, GLint x
, GLint y
,
144 const GLchan color
[4], const GLubyte mask
[])
147 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
148 for (i
=0; i
<n
; i
++, x
++) {
150 __svga_drawpixel32( x
, y
, truecolor
);
155 void __read_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
159 for (i
=0; i
<n
; i
++, x
++) {
160 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
, y
));
164 void __write_rgba_pixels32( const GLcontext
*ctx
,
165 GLuint n
, const GLint x
[], const GLint y
[],
166 const GLubyte rgba
[][4], const GLubyte mask
[] )
169 for (i
=0; i
<n
; i
++) {
171 __svga_drawpixel32( x
[i
], y
[i
], RGB2BGR32(*((GLint
*)rgba
[i
])));
176 void __write_mono_rgba_pixels32( const GLcontext
*ctx
,
178 const GLint x
[], const GLint y
[],
179 const GLchan color
[4], const GLubyte mask
[] )
181 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
183 for (i
=0; i
<n
; i
++) {
185 __svga_drawpixel32( x
[i
], y
[i
], truecolor
);
190 void __read_rgba_pixels32( const GLcontext
*ctx
,
191 GLuint n
, const GLint x
[], const GLint y
[],
192 GLubyte rgba
[][4], const GLubyte mask
[] )
195 for (i
=0; i
<n
; i
++,x
++) {
196 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
[i
], y
[i
] ));
204 /* silence compiler warning */
205 extern void _mesa_svga32_dummy_function(void);
206 void _mesa_svga32_dummy_function(void)