1 /* $Id: svgamesa24.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 "svgamesa24.h"
41 /* this doesn't compile with GCC on RedHat 6.1 */
42 static inline int RGB2BGR24(int c
)
52 static unsigned long RGB2BGR24(unsigned long color
)
54 return (color
& 0xff00)|(color
>>16)|((color
& 0xff)<<16);
58 static void __svga_drawpixel24(int x
, int y
, GLubyte r
, GLubyte g
, GLubyte b
)
62 _RGB
*rgbBuffer
=(void *)SVGABuffer
.DrawBuffer
;
63 y
= SVGAInfo
->height
-y
-1;
64 offset
= y
* SVGAInfo
->width
+ x
;
66 rgbBuffer
[offset
].r
=r
;
67 rgbBuffer
[offset
].g
=g
;
68 rgbBuffer
[offset
].b
=b
;
71 static unsigned long __svga_getpixel24(int x
, int y
)
75 _RGB
*rgbBuffer
=(void *)SVGABuffer
.ReadBuffer
;
76 y
= SVGAInfo
->height
-y
-1;
77 offset
= y
* SVGAInfo
->width
+ x
;
78 return rgbBuffer
[offset
].r
<<16 | rgbBuffer
[offset
].g
<<8 | rgbBuffer
[offset
].b
;
81 void __clear_color24( GLcontext
*ctx
,
82 GLubyte red
, GLubyte green
,
83 GLubyte blue
, GLubyte alpha
)
85 SVGAMesa
->clear_red
= red
;
86 SVGAMesa
->clear_green
= green
;
87 SVGAMesa
->clear_blue
= blue
;
88 /* SVGAMesa->clear_truecolor = red<<16 | green<<8 | blue; */
91 GLbitfield
__clear24( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
92 GLint x
, GLint y
, GLint width
, GLint height
)
96 if (mask
& DD_FRONT_LEFT_BIT
) {
98 _RGB
*rgbBuffer
=(void *)SVGABuffer
.FrontBuffer
;
99 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
100 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
101 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
102 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
106 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
107 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
108 for (i
=x
;i
<width
;i
++)
109 for (j
=y
;j
<height
;j
++)
110 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
111 SVGAMesa
->clear_green
,
112 SVGAMesa
->clear_blue
);
113 SVGABuffer
.DrawBuffer
= tmp
;
116 if (mask
& DD_BACK_LEFT_BIT
) {
118 _RGB
*rgbBuffer
=(void *)SVGABuffer
.BackBuffer
;
119 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
120 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
121 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
122 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
126 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
127 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
128 for (i
=x
;i
<width
;i
++)
129 for (j
=y
;j
<height
;j
++)
130 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
131 SVGAMesa
->clear_green
,
132 SVGAMesa
->clear_blue
);
133 SVGABuffer
.DrawBuffer
= tmp
;
136 return mask
& (~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
139 void __write_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
140 const GLubyte rgba
[][4], const GLubyte mask
[] )
144 /* draw some pixels */
145 for (i
=0; i
<n
; i
++, x
++) {
147 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
154 /* draw all pixels */
155 for (i
=0; i
<n
; i
++, x
++) {
156 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
163 void __write_mono_rgba_span24( const GLcontext
*ctx
,
164 GLuint n
, GLint x
, GLint y
,
165 const GLchan color
[4], const GLubyte mask
[])
168 for (i
=0; i
<n
; i
++, x
++) {
170 __svga_drawpixel24( x
, y
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
175 void __read_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
179 for (i
=0; i
<n
; i
++, x
++) {
180 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
, y
));
184 void __write_rgba_pixels24( const GLcontext
*ctx
,
185 GLuint n
, const GLint x
[], const GLint y
[],
186 const GLubyte rgba
[][4], const GLubyte mask
[] )
189 for (i
=0; i
<n
; i
++) {
191 __svga_drawpixel24( x
[i
], y
[i
], rgba
[i
][RCOMP
],
198 void __write_mono_rgba_pixels24( const GLcontext
*ctx
,
200 const GLint x
[], const GLint y
[],
201 const GLchan color
[4], const GLubyte mask
[] )
204 for (i
=0; i
<n
; i
++) {
206 __svga_drawpixel24( x
[i
], y
[i
],
207 color
[RCOMP
], color
[GCOMP
], color
[BCOMP
] );
212 void __read_rgba_pixels24( const GLcontext
*ctx
,
213 GLuint n
, const GLint x
[], const GLint y
[],
214 GLubyte rgba
[][4], const GLubyte mask
[] )
217 for (i
=0; i
<n
; i
++,x
++) {
218 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
[i
], y
[i
]));
225 /* silence compiler warning */
226 extern void _mesa_svga24_dummy_function(void);
227 void _mesa_svga24_dummy_function(void)