3 * Copyright (C) 1997 Uwe Maurer
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * ---------------------------------------------------------------------
19 * This code was derived from the following source of information:
21 * svgamesa.c and ddsample.c by Brian Paul
27 #include <ggi/internal/ggi-dl.h>
28 #include <ggi/mesa/ggimesa_int.h>
30 /**********************************************************************/
31 /***** Write spans of pixels *****/
32 /**********************************************************************/
34 void GGIwrite_ci32_span(const GLcontext
*ctx
,
35 GLuint n
, GLint x
, GLint y
,
37 const GLubyte mask
[] )
43 if (*mask
++) ggiPutPixel(VIS
,x
,y
,*ci
);
50 while (n
--) ggiPutPixel(VIS
,x
++,y
,*ci
++);
54 void GGIwrite_ci8_span(const GLcontext
*ctx
,
55 GLuint n
, GLint x
, GLint y
,
57 const GLubyte mask
[] )
63 if (*mask
++) ggiPutPixel(VIS
,x
,y
,*ci
);
70 while (n
--) ggiPutPixel(VIS
,x
++,y
,*ci
++);
74 void GGIwrite_mono_span( const GLcontext
*ctx
,
75 GLuint n
, GLint x
, GLint y
,
76 const GLubyte mask
[] )
82 if (*mask
++) ggiDrawPixel(VIS
,x
,y
);
88 ggiDrawHLine(VIS
,x
,y
,n
);
92 void GGIwrite_rgba_span( const GLcontext
*ctx
,
93 GLuint n
, GLint x
, GLint y
,
94 const GLubyte rgba
[][4],
106 rgb
.r
=(uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
107 rgb
.g
=(uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
108 rgb
.b
=(uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
109 col
=ggiMapColor(VIS
,&rgb
);
110 ggiPutPixel(VIS
,x
,y
,col
);
120 rgb
.r
=(uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
121 rgb
.g
=(uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
122 rgb
.b
=(uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
123 col
=ggiMapColor(VIS
,&rgb
);
124 ggiPutPixel(VIS
,x
++,y
,col
);
129 void GGIwrite_rgb_span( const GLcontext
*ctx
,
130 GLuint n
, GLint x
, GLint y
,
131 const GLubyte rgba
[][3],
132 const GLubyte mask
[] )
143 rgb
.r
=(uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
144 rgb
.g
=(uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
145 rgb
.b
=(uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
146 col
=ggiMapColor(VIS
,&rgb
);
147 ggiPutPixel(VIS
,x
,y
,col
);
157 rgb
.r
=(uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
158 rgb
.g
=(uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
159 rgb
.b
=(uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
160 col
=ggiMapColor(VIS
,&rgb
);
161 ggiPutPixel(VIS
,x
++,y
,col
);
169 /**********************************************************************/
170 /***** Read spans of pixels *****/
171 /**********************************************************************/
174 void GGIread_ci32_span( const GLcontext
*ctx
,
175 GLuint n
, GLint x
, GLint y
, GLuint ci
[])
179 ggiGetPixel(VIS
, x
++, y
,ci
++);
182 void GGIread_rgba_span( const GLcontext
*ctx
,
183 GLuint n
, GLint x
, GLint y
,
193 ggiGetPixel(VIS
,x
++,y
,&col
);
194 ggiUnmapPixel(VIS
,col
,&rgb
);
195 rgba
[0][RCOMP
] = (GLubyte
) (rgb
.r
>> SHIFT
);
196 rgba
[0][GCOMP
] = (GLubyte
) (rgb
.g
>> SHIFT
);
197 rgba
[0][BCOMP
] = (GLubyte
) (rgb
.b
>> SHIFT
);
203 /**********************************************************************/
204 /***** Write arrays of pixels *****/
205 /**********************************************************************/
207 void GGIwrite_ci32_pixels( const GLcontext
*ctx
,
208 GLuint n
, const GLint x
[], const GLint y
[],
209 const GLuint ci
[], const GLubyte mask
[] )
212 if (*mask
++) ggiPutPixel(VIS
,*x
, FLIP(*y
),*ci
);
219 void GGIwrite_mono_pixels( const GLcontext
*ctx
,
221 const GLint x
[], const GLint y
[],
222 const GLubyte mask
[] )
225 if (*mask
++) ggiDrawPixel(VIS
,*x
,FLIP(*y
));
231 void GGIwrite_rgba_pixels( const GLcontext
*ctx
,
232 GLuint n
, const GLint x
[], const GLint y
[],
233 const GLubyte rgba
[][4],
234 const GLubyte mask
[] )
240 rgb
.r
=(uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
241 rgb
.g
=(uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
242 rgb
.b
=(uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
243 col
=ggiMapColor(VIS
,&rgb
);
244 ggiPutPixel(VIS
,*x
,FLIP(*y
),col
);
252 /**********************************************************************/
253 /***** Read arrays of pixels *****/
254 /**********************************************************************/
256 void GGIread_ci32_pixels( const GLcontext
*ctx
,
257 GLuint n
, const GLint x
[], const GLint y
[],
258 GLuint ci
[], const GLubyte mask
[])
262 ggiGetPixel(VIS
, *x
, FLIP(*y
) ,ci
);
269 void GGIread_rgba_pixels( const GLcontext
*ctx
,
270 GLuint n
, const GLint x
[], const GLint y
[],
272 const GLubyte mask
[] )
281 ggiGetPixel(VIS
,*x
,FLIP(*y
),&col
);
282 ggiUnmapPixel(VIS
,col
,&rgb
);
283 rgba
[0][RCOMP
]= rgb
.r
>> SHIFT
;
284 rgba
[0][GCOMP
]= rgb
.g
>> SHIFT
;
285 rgba
[0][BCOMP
]= rgb
.b
>> SHIFT
;
294 triangle_func
ggiGetTriangleFunc(GLcontext
*ctx
);
296 int GGIsetup_driver(GGIMesaContext ggictx
,struct ggi_mesa_info
*info
)
298 GLcontext
*ctx
=ggictx
->gl_ctx
;
300 ctx
->Driver
.WriteRGBASpan
= GGIwrite_rgba_span
;
301 ctx
->Driver
.WriteRGBSpan
= GGIwrite_rgb_span
;
302 ctx
->Driver
.WriteMonoRGBASpan
= GGIwrite_mono_span
;
303 ctx
->Driver
.WriteRGBAPixels
= GGIwrite_rgba_pixels
;
304 ctx
->Driver
.WriteMonoRGBAPixels
= GGIwrite_mono_pixels
;
306 ctx
->Driver
.WriteCI32Span
= GGIwrite_ci32_span
;
307 ctx
->Driver
.WriteCI8Span
= GGIwrite_ci8_span
;
308 ctx
->Driver
.WriteMonoCISpan
= GGIwrite_mono_span
;
309 ctx
->Driver
.WriteCI32Pixels
= GGIwrite_ci32_pixels
;
310 ctx
->Driver
.WriteMonoCIPixels
= GGIwrite_mono_pixels
;
312 ctx
->Driver
.ReadCI32Span
= GGIread_ci32_span
;
313 ctx
->Driver
.ReadRGBASpan
= GGIread_rgba_span
;
314 ctx
->Driver
.ReadCI32Pixels
= GGIread_ci32_pixels
;
315 ctx
->Driver
.ReadRGBAPixels
= GGIread_rgba_pixels
;
320 void GGIupdate_state(GLcontext
*ctx
)
322 ctx
->Driver
.TriangleFunc
= ggiGetTriangleFunc(ctx
);
326 void GGItriangle_flat(GLcontext
*ctx
,GLuint v0
,GLuint v1
,GLuint v2
,GLuint pv
)
329 //#define INTERP_RGB 1
330 //#define INTERP_ALPHA 1
333 GLubyte r = VB->ColorPtr->data[pv][0]; \
334 GLubyte g = VB->ColorPtr->data[pv][1]; \
335 GLubyte b = VB->ColorPtr->data[pv][2]; \
336 GLubyte a = VB->ColorPtr->data[pv][3]; \
337 (*ctx->Driver.Color)(ctx,r,g,b,a);
339 #define INNER_LOOP(LEFT,RIGHT,Y) \
340 ggiDrawHLine(VIS,LEFT,FLIP(Y),RIGHT-LEFT);
346 void GGItriangle_flat_depth(GLcontext
*ctx
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint pv
)
349 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
352 GLubyte r = VB->ColorPtr->data[pv][0]; \
353 GLubyte g = VB->ColorPtr->data[pv][1]; \
354 GLubyte b = VB->ColorPtr->data[pv][2]; \
355 GLubyte a = VB->ColorPtr->data[pv][3]; \
356 (*ctx->Driver.Color)(ctx,r,g,b,a);
358 #define INNER_LOOP(LEFT,RIGHT,Y) \
360 GLint i,xx=LEFT,yy=FLIP(Y),n=RIGHT-LEFT,length=0; \
363 GLdepth z=FixedToDepth(ffz); \
373 ggiDrawHLine(VIS,startx,yy,length); \
380 if (length) ggiDrawHLine(VIS,startx,yy,length); \
387 triangle_func
ggiGetTriangleFunc(GLcontext
*ctx
)
389 if (ctx
->Stencil
.Enabled
) return NULL
;
390 if (ctx
->Polygon
.SmoothFlag
) return NULL
;
391 if (ctx
->Polygon
.StippleFlag
) return NULL
;
392 if (ctx
->Texture
.Enabled
) return NULL
;
393 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
) return NULL
;
394 if (ctx
->Depth
.Test
&& ctx
->Depth
.Func
!= GL_LESS
) return NULL
;
397 return GGItriangle_flat_depth
;
399 return GGItriangle_flat
;
402 int GGIdlinit(ggi_visual_t vis
, const char *version
, void *argptr
)
404 LIBGGI_MESAEXT(vis
)->update_state
= GGIupdate_state
;
405 LIBGGI_MESAEXT(vis
)->setup_driver
= GGIsetup_driver
;
410 int GGIdlcleanup(ggi_visual_t vis
)