07491cc67ac3f006e739897b31d4b296cbf7a490
1 /* $Id: svgamesa24.c,v 1.12 2002/11/11 18:42:41 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 "svgamesa24.h"
38 #include "swrast/swrast.h"
42 /* this doesn't compile with GCC on RedHat 6.1 */
43 static inline int RGB2BGR24(int c
)
53 static unsigned long RGB2BGR24(unsigned long color
)
55 return (color
& 0xff00)|(color
>>16)|((color
& 0xff)<<16);
59 static void __svga_drawpixel24(int x
, int y
, GLubyte r
, GLubyte g
, GLubyte b
)
63 _RGB
*rgbBuffer
=(void *)SVGABuffer
.DrawBuffer
;
64 y
= SVGAInfo
->height
-y
-1;
65 offset
= y
* SVGAInfo
->width
+ x
;
67 rgbBuffer
[offset
].r
=r
;
68 rgbBuffer
[offset
].g
=g
;
69 rgbBuffer
[offset
].b
=b
;
72 static unsigned long __svga_getpixel24(int x
, int y
)
76 _RGB
*rgbBuffer
=(void *)SVGABuffer
.ReadBuffer
;
77 y
= SVGAInfo
->height
-y
-1;
78 offset
= y
* SVGAInfo
->width
+ x
;
79 return rgbBuffer
[offset
].r
<<16 | rgbBuffer
[offset
].g
<<8 | rgbBuffer
[offset
].b
;
82 void __clear_color24( GLcontext
*ctx
, const GLfloat color
[4] )
85 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
86 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
87 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
88 SVGAMesa
->clear_red
= col
[0];
89 SVGAMesa
->clear_green
= col
[1];
90 SVGAMesa
->clear_blue
= col
[2];
91 /* SVGAMesa->clear_truecolor = red<<16 | green<<8 | blue; */
94 void __clear24( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
95 GLint x
, GLint y
, GLint width
, GLint height
)
99 if (mask
& DD_FRONT_LEFT_BIT
) {
101 _RGB
*rgbBuffer
=(void *)SVGABuffer
.FrontBuffer
;
102 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
103 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
104 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
105 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
109 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
110 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
111 for (i
=x
;i
<width
;i
++)
112 for (j
=y
;j
<height
;j
++)
113 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
114 SVGAMesa
->clear_green
,
115 SVGAMesa
->clear_blue
);
116 SVGABuffer
.DrawBuffer
= tmp
;
118 mask
&= ~DD_FRONT_LEFT_BIT
;
120 if (mask
& DD_BACK_LEFT_BIT
) {
122 _RGB
*rgbBuffer
=(void *)SVGABuffer
.BackBuffer
;
123 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
124 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
125 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
126 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
130 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
131 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
132 for (i
=x
;i
<width
;i
++)
133 for (j
=y
;j
<height
;j
++)
134 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
135 SVGAMesa
->clear_green
,
136 SVGAMesa
->clear_blue
);
137 SVGABuffer
.DrawBuffer
= tmp
;
139 mask
&= ~DD_BACK_LEFT_BIT
;
143 _swrast_Clear( ctx
, mask
, all
, x
, y
, width
, height
);
146 void __write_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
147 const GLubyte rgba
[][4], const GLubyte mask
[] )
151 /* draw some pixels */
152 for (i
=0; i
<n
; i
++, x
++) {
154 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
161 /* draw all pixels */
162 for (i
=0; i
<n
; i
++, x
++) {
163 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
170 void __write_mono_rgba_span24( const GLcontext
*ctx
,
171 GLuint n
, GLint x
, GLint y
,
172 const GLchan color
[4], const GLubyte mask
[])
175 for (i
=0; i
<n
; i
++, x
++) {
177 __svga_drawpixel24( x
, y
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
182 void __read_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
186 for (i
=0; i
<n
; i
++, x
++) {
187 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
, y
));
191 void __write_rgba_pixels24( const GLcontext
*ctx
,
192 GLuint n
, const GLint x
[], const GLint y
[],
193 const GLubyte rgba
[][4], const GLubyte mask
[] )
196 for (i
=0; i
<n
; i
++) {
198 __svga_drawpixel24( x
[i
], y
[i
], rgba
[i
][RCOMP
],
205 void __write_mono_rgba_pixels24( const GLcontext
*ctx
,
207 const GLint x
[], const GLint y
[],
208 const GLchan color
[4], const GLubyte mask
[] )
211 for (i
=0; i
<n
; i
++) {
213 __svga_drawpixel24( x
[i
], y
[i
],
214 color
[RCOMP
], color
[GCOMP
], color
[BCOMP
] );
219 void __read_rgba_pixels24( const GLcontext
*ctx
,
220 GLuint n
, const GLint x
[], const GLint y
[],
221 GLubyte rgba
[][4], const GLubyte mask
[] )
224 for (i
=0; i
<n
; i
++,x
++) {
225 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
[i
], y
[i
]));
232 /* silence compiler warning */
233 extern void _mesa_svga24_dummy_function(void);
234 void _mesa_svga24_dummy_function(void)