1 /* $Id: svgamesa24.c,v 1.13 2006/11/01 19:35:23 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
)
97 int x
= ctx
->DrawBuffer
->_Xmin
;
98 int y
= ctx
->DrawBuffer
->_Ymin
;
99 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
100 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
101 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
103 if (mask
& DD_FRONT_LEFT_BIT
) {
105 _RGB
*rgbBuffer
=(void *)SVGABuffer
.FrontBuffer
;
106 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
107 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
108 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
109 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
113 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
114 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
115 for (i
=x
;i
<width
;i
++)
116 for (j
=y
;j
<height
;j
++)
117 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
118 SVGAMesa
->clear_green
,
119 SVGAMesa
->clear_blue
);
120 SVGABuffer
.DrawBuffer
= tmp
;
122 mask
&= ~DD_FRONT_LEFT_BIT
;
124 if (mask
& DD_BACK_LEFT_BIT
) {
126 _RGB
*rgbBuffer
=(void *)SVGABuffer
.BackBuffer
;
127 for (i
=0;i
<SVGABuffer
.BufferSize
/ 3;i
++) {
128 rgbBuffer
[i
].r
=SVGAMesa
->clear_red
;
129 rgbBuffer
[i
].g
=SVGAMesa
->clear_green
;
130 rgbBuffer
[i
].b
=SVGAMesa
->clear_blue
;
134 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
135 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
136 for (i
=x
;i
<width
;i
++)
137 for (j
=y
;j
<height
;j
++)
138 __svga_drawpixel24( i
, j
, SVGAMesa
->clear_red
,
139 SVGAMesa
->clear_green
,
140 SVGAMesa
->clear_blue
);
141 SVGABuffer
.DrawBuffer
= tmp
;
143 mask
&= ~DD_BACK_LEFT_BIT
;
147 _swrast_Clear( ctx
, mask
);
150 void __write_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
151 const GLubyte rgba
[][4], const GLubyte mask
[] )
155 /* draw some pixels */
156 for (i
=0; i
<n
; i
++, x
++) {
158 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
165 /* draw all pixels */
166 for (i
=0; i
<n
; i
++, x
++) {
167 __svga_drawpixel24( x
, y
, rgba
[i
][RCOMP
],
174 void __write_mono_rgba_span24( const GLcontext
*ctx
,
175 GLuint n
, GLint x
, GLint y
,
176 const GLchan color
[4], const GLubyte mask
[])
179 for (i
=0; i
<n
; i
++, x
++) {
181 __svga_drawpixel24( x
, y
, color
[RCOMP
], color
[GCOMP
], color
[BCOMP
]);
186 void __read_rgba_span24( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
190 for (i
=0; i
<n
; i
++, x
++) {
191 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
, y
));
195 void __write_rgba_pixels24( const GLcontext
*ctx
,
196 GLuint n
, const GLint x
[], const GLint y
[],
197 const GLubyte rgba
[][4], const GLubyte mask
[] )
200 for (i
=0; i
<n
; i
++) {
202 __svga_drawpixel24( x
[i
], y
[i
], rgba
[i
][RCOMP
],
209 void __write_mono_rgba_pixels24( const GLcontext
*ctx
,
211 const GLint x
[], const GLint y
[],
212 const GLchan color
[4], const GLubyte mask
[] )
215 for (i
=0; i
<n
; i
++) {
217 __svga_drawpixel24( x
[i
], y
[i
],
218 color
[RCOMP
], color
[GCOMP
], color
[BCOMP
] );
223 void __read_rgba_pixels24( const GLcontext
*ctx
,
224 GLuint n
, const GLint x
[], const GLint y
[],
225 GLubyte rgba
[][4], const GLubyte mask
[] )
228 for (i
=0; i
<n
; i
++,x
++) {
229 *((GLint
*)rgba
[i
]) = RGB2BGR24(__svga_getpixel24( x
[i
], y
[i
]));
236 /* silence compiler warning */
237 extern void _mesa_svga24_dummy_function(void);
238 void _mesa_svga24_dummy_function(void)