1 /* $Id: svgamesa32.c,v 1.6 2000/01/31 22:10:07 tanner 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 __set_color32( GLcontext
*ctx
,
78 GLubyte red
, GLubyte green
,
79 GLubyte blue
, GLubyte alpha
)
82 SVGAMesa
->green
= green
;
83 SVGAMesa
->blue
= blue
;
84 SVGAMesa
->truecolor
= red
<<16 | green
<<8 | blue
;
87 void __clear_color32( GLcontext
*ctx
,
88 GLubyte red
, GLubyte green
,
89 GLubyte blue
, GLubyte alpha
)
91 SVGAMesa
->clear_truecolor
= red
<<16 | green
<<8 | blue
;
94 GLbitfield
__clear32( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
95 GLint x
, GLint y
, GLint width
, GLint height
)
99 if (mask
& DD_FRONT_LEFT_BIT
) {
101 GLint
*intBuffer
=(void *)SVGABuffer
.FrontBuffer
;
102 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
103 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
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_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
111 SVGABuffer
.DrawBuffer
= tmp
;
114 if (mask
& DD_BACK_LEFT_BIT
) {
116 GLint
*intBuffer
=(void *)SVGABuffer
.BackBuffer
;
117 for (i
=0;i
<SVGABuffer
.BufferSize
/ 4;i
++)
118 intBuffer
[i
]=SVGAMesa
->clear_truecolor
;
121 GLubyte
*tmp
= SVGABuffer
.DrawBuffer
;
122 SVGABuffer
.DrawBuffer
= SVGABuffer
.BackBuffer
;
123 for (i
=x
;i
<width
;i
++)
124 for (j
=y
;j
<height
;j
++)
125 __svga_drawpixel32(i
,j
,SVGAMesa
->clear_truecolor
);
126 SVGABuffer
.DrawBuffer
= tmp
;
129 return mask
& (~(DD_FRONT_LEFT_BIT
| DD_BACK_LEFT_BIT
));
132 void __write_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
133 const GLubyte rgba
[][4], const GLubyte mask
[] )
137 /* draw some pixels */
138 for (i
=0; i
<n
; i
++, x
++) {
140 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
145 /* draw all pixels */
146 for (i
=0; i
<n
; i
++, x
++) {
147 __svga_drawpixel32( x
, y
, RGB2BGR32(*((GLint
*)rgba
[i
])));
152 void __write_mono_rgba_span32( const GLcontext
*ctx
,
153 GLuint n
, GLint x
, GLint y
,
154 const GLubyte mask
[])
157 for (i
=0; i
<n
; i
++, x
++) {
159 __svga_drawpixel32( x
, y
, SVGAMesa
->truecolor
);
164 void __read_rgba_span32( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
168 for (i
=0; i
<n
; i
++, x
++) {
169 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
, y
));
173 void __write_rgba_pixels32( const GLcontext
*ctx
,
174 GLuint n
, const GLint x
[], const GLint y
[],
175 const GLubyte rgba
[][4], const GLubyte mask
[] )
178 for (i
=0; i
<n
; i
++) {
180 __svga_drawpixel32( x
[i
], y
[i
], RGB2BGR32(*((GLint
*)rgba
[i
])));
185 void __write_mono_rgba_pixels32( const GLcontext
*ctx
,
187 const GLint x
[], const GLint y
[],
188 const GLubyte mask
[] )
191 /* use current rgb color */
192 for (i
=0; i
<n
; i
++) {
194 __svga_drawpixel32( x
[i
], y
[i
], SVGAMesa
->truecolor
);
199 void __read_rgba_pixels32( const GLcontext
*ctx
,
200 GLuint n
, const GLint x
[], const GLint y
[],
201 GLubyte rgba
[][4], const GLubyte mask
[] )
204 for (i
=0; i
<n
; i
++,x
++) {
205 *((GLint
*)rgba
[i
]) = RGB2BGR32(__svga_getpixel32( x
[i
], y
[i
] ));