3 * Mesa 3-D graphics library
5 * Copyright (C) 1995-2002 Brian Paul
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * SVGA driver for Mesa.
25 * Original author: Brian Paul
26 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
36 #include "svgamesa32.h"
37 #include "swrast/swrast.h"
41 /* this doesn't compile with GCC on RedHat 6.1 */
42 static INLINE
int RGB2BGR32(int c
)
52 static unsigned long RGB2BGR32(unsigned long color
)
54 return (color
& 0xff00)|(color
>>16)|((color
& 0xff)<<16);
58 static void __svga_drawpixel32(int x
, int y
, unsigned long c
)
62 GLint
*intBuffer
=(void *)SVGABuffer
.DrawBuffer
;
63 y
= SVGAInfo
->height
-y
-1;
64 offset
= y
* SVGAInfo
->width
+ x
;
68 static unsigned long __svga_getpixel32(int x
, int y
)
72 const GLint
*intBuffer
=(void *)SVGABuffer
.ReadBuffer
;
73 y
= SVGAInfo
->height
-y
-1;
74 offset
= y
* SVGAInfo
->width
+ x
;
75 return intBuffer
[offset
];
78 void __clear_color32( GLcontext
*ctx
, const GLfloat color
[4] )
81 CLAMPED_FLOAT_TO_UBYTE(col
[0], color
[0]);
82 CLAMPED_FLOAT_TO_UBYTE(col
[1], color
[1]);
83 CLAMPED_FLOAT_TO_UBYTE(col
[2], color
[2]);
84 SVGAMesa
->clear_truecolor
= (col
[0] << 16) | (col
[1] << 8) | col
[2];
87 void __clear32( GLcontext
*ctx
, GLbitfield mask
)
90 int x
= ctx
->DrawBuffer
->_Xmin
;
91 int y
= ctx
->DrawBuffer
->_Ymin
;
92 int width
= ctx
->DrawBuffer
->_Xmax
- x
;
93 int height
= ctx
->DrawBuffer
->_Ymax
- y
;
94 GLboolean all
= (width
== ctx
->DrawBuffer
->Width
&& height
== ctx
->DrawBuffer
->height
)
96 if (mask
& DD_FRONT_LEFT_BIT
) {
98 GLint
*intBuffer
=(void *)SVGABuffer
.FrontBuffer
;
99 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
100 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
103 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
104 SVGABuffer
.DrawBuffer
= SVGABuffer
.FrontBuffer
;
105 for (i
=x
;i
<width
;i
++)
106 for (j
=y
;j
<height
;j
++)
107 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
108 SVGABuffer
.DrawBuffer
= tmp
;
110 mask
&= ~DD_FRONT_LEFT_BIT
;
112 if (mask
& DD_BACK_LEFT_BIT
) {
114 GLint
*intBuffer
=(void *)SVGABuffer
.BackBuffer
;
115 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
116 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
119 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
120 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
121 for (i
=x
;i
<width
;i
++)
122 for (j
=y
;j
<height
;j
++)
123 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
124 SVGABuffer
.DrawBuffer
= tmp
;
126 mask
&= ~DD_BACK_LEFT_BIT
;
130 _swrast_Clear( ctx
, mask
);
133 void __write_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
134 const GLubyte rgba
[][4], const GLubyte mask
[] )
138 /* draw some pixels */
139 for (i
=0; i
<n
; i
++, x
++) {
141 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
146 /* draw all pixels */
147 for (i
=0; i
<n
; i
++, x
++) {
148 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
153 void __write_mono_rgba_span32( const GLcontext
*ctx
,
154 GLuint n
, GLint x
, GLint y
,
155 const GLchan color
[4], const GLubyte mask
[])
158 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
159 for (i
=0; i
<n
; i
++, x
++) {
161 __svga_drawpixel32( x
, y
, truecolor
);
166 void __read_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
170 for (i
=0; i
<n
; i
++, x
++) {
171 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
, y
));
175 void __write_rgba_pixels32( const GLcontext
*ctx
,
176 GLuint n
, const GLint x
[], const GLint y
[],
177 const GLubyte rgba
[][4], const GLubyte mask
[] )
180 for (i
=0; i
<n
; i
++) {
182 __svga_drawpixel32( x
[i
], y
[i
], RGB2BGR32(*((GLint
*)rgba
[i
])));
187 void __write_mono_rgba_pixels32( const GLcontext
*ctx
,
189 const GLint x
[], const GLint y
[],
190 const GLchan color
[4], const GLubyte mask
[] )
192 GLuint truecolor
= color
[RCOMP
]<<16 | color
[GCOMP
]<<8 | color
[BCOMP
];
194 for (i
=0; i
<n
; i
++) {
196 __svga_drawpixel32( x
[i
], y
[i
], truecolor
);
201 void __read_rgba_pixels32( const GLcontext
*ctx
,
202 GLuint n
, const GLint x
[], const GLint y
[],
203 GLubyte rgba
[][4], const GLubyte mask
[] )
206 for (i
=0; i
<n
; i
++,x
++) {
207 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
[i
], y
[i
] ));
215 /* silence compiler warning */
216 extern void _mesa_svga32_dummy_function(void);
217 void _mesa_svga32_dummy_function(void)