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>
29 #include <ggi/mesa/debug.h>
31 #include "swrast/swrast.h"
32 //#include "swrast_setup/swrast_setup.h"
33 //#include "swrast/s_context.h"
34 //#include "swrast/s_depth.h"
35 //#include "swrast/s_triangle.h"
37 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord)-1)
39 /**********************************************************************/
40 /***** Write spans of pixels *****/
41 /**********************************************************************/
43 void GGIwrite_ci32_span(const GLcontext
*ctx
,
44 GLuint n
, GLint x
, GLint y
,
46 const GLubyte mask
[] )
48 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
54 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, *ci
);
62 ggiPutPixel(ggi_ctx
->ggi_visual
, x
++, y
, *ci
++);
66 void GGIwrite_ci8_span(const GLcontext
*ctx
,
67 GLuint n
, GLint x
, GLint y
,
69 const GLubyte mask
[] )
71 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
77 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, *ci
);
85 ggiPutPixel(ggi_ctx
->ggi_visual
, x
++, y
, *ci
++);
89 void GGIwrite_mono_ci_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
90 const GLuint ci
, const GLubyte mask
[])
92 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
98 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, ci
);
105 ggiPutPixel(ggi_ctx
->ggi_visual
, x
++, y
, ci
);
109 void GGIwrite_mono_rgba_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
110 const GLchan rgba
[4], const GLubyte mask
[])
112 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
118 rgb
.r
= (uint16
)(rgba
[RCOMP
]) << SHIFT
;
119 rgb
.g
= (uint16
)(rgba
[GCOMP
]) << SHIFT
;
120 rgb
.b
= (uint16
)(rgba
[BCOMP
]) << SHIFT
;
121 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
127 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, col
);
133 ggiDrawHLine(ggi_ctx
->ggi_visual
, x
, y
, n
);
137 void GGIwrite_rgba_span( const GLcontext
*ctx
,
138 GLuint n
, GLint x
, GLint y
,
139 const GLubyte rgba
[][4],
140 const GLubyte mask
[])
142 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
152 rgb
.r
= (uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
153 rgb
.g
= (uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
154 rgb
.b
= (uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
155 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
156 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, col
);
166 rgb
.r
= (uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
167 rgb
.g
= (uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
168 rgb
.b
= (uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
169 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
170 ggiPutPixel(ggi_ctx
->ggi_visual
, x
++, y
, col
);
176 void GGIwrite_rgb_span( const GLcontext
*ctx
,
177 GLuint n
, GLint x
, GLint y
,
178 const GLubyte rgba
[][3],
179 const GLubyte mask
[] )
181 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
191 rgb
.r
= (uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
192 rgb
.g
= (uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
193 rgb
.b
= (uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
194 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
195 ggiPutPixel(ggi_ctx
->ggi_visual
, x
, y
, col
);
205 rgb
.r
= (uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
206 rgb
.g
= (uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
207 rgb
.b
= (uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
208 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
209 ggiPutPixel(ggi_ctx
->ggi_visual
, x
++, y
, col
);
217 /**********************************************************************/
218 /***** Read spans of pixels *****/
219 /**********************************************************************/
222 void GGIread_ci32_span( const GLcontext
*ctx
,
223 GLuint n
, GLint x
, GLint y
, GLuint ci
[])
225 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
228 ggiGetPixel(ggi_ctx
->ggi_visual
, x
++, y
, ci
++);
231 void GGIread_rgba_span( const GLcontext
*ctx
,
232 GLuint n
, GLint x
, GLint y
,
235 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
243 ggiGetPixel(ggi_ctx
->ggi_visual
, x
++, y
, &col
);
244 ggiUnmapPixel(ggi_ctx
->ggi_visual
, col
, &rgb
);
245 rgba
[0][RCOMP
] = (GLubyte
) (rgb
.r
>> SHIFT
);
246 rgba
[0][GCOMP
] = (GLubyte
) (rgb
.g
>> SHIFT
);
247 rgba
[0][BCOMP
] = (GLubyte
) (rgb
.b
>> SHIFT
);
253 /**********************************************************************/
254 /***** Write arrays of pixels *****/
255 /**********************************************************************/
257 void GGIwrite_ci32_pixels( const GLcontext
*ctx
,
258 GLuint n
, const GLint x
[], const GLint y
[],
259 const GLuint ci
[], const GLubyte mask
[] )
261 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
264 ggiPutPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), *ci
);
271 void GGIwrite_mono_ci_pixels(const GLcontext
*ctx
,
272 GLuint n
, const GLint x
[], const GLint y
[],
273 GLuint ci
, const GLubyte mask
[])
275 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
278 ggiPutPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), ci
);
284 void GGIwrite_rgba_pixels( const GLcontext
*ctx
,
285 GLuint n
, const GLint x
[], const GLint y
[],
286 const GLubyte rgba
[][4],
287 const GLubyte mask
[] )
289 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
294 rgb
.r
= (uint16
)(rgba
[0][RCOMP
]) << SHIFT
;
295 rgb
.g
= (uint16
)(rgba
[0][GCOMP
]) << SHIFT
;
296 rgb
.b
= (uint16
)(rgba
[0][BCOMP
]) << SHIFT
;
297 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
298 ggiPutPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), col
);
306 void GGIwrite_mono_rgba_pixels(const GLcontext
*ctx
,
307 GLuint n
, const GLint x
[], const GLint y
[],
308 const GLchan rgba
[4], const GLubyte mask
[])
310 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
314 rgb
.r
= (uint16
)(rgba
[RCOMP
]) << SHIFT
;
315 rgb
.g
= (uint16
)(rgba
[GCOMP
]) << SHIFT
;
316 rgb
.b
= (uint16
)(rgba
[BCOMP
]) << SHIFT
;
317 col
= ggiMapColor(ggi_ctx
->ggi_visual
, &rgb
);
321 ggiPutPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), col
);
327 /**********************************************************************/
328 /***** Read arrays of pixels *****/
329 /**********************************************************************/
331 void GGIread_ci32_pixels( const GLcontext
*ctx
,
332 GLuint n
, const GLint x
[], const GLint y
[],
333 GLuint ci
[], const GLubyte mask
[])
335 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
338 ggiGetPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), ci
);
345 void GGIread_rgba_pixels( const GLcontext
*ctx
,
346 GLuint n
, const GLint x
[], const GLint y
[],
348 const GLubyte mask
[] )
350 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
358 ggiGetPixel(ggi_ctx
->ggi_visual
, *x
, FLIP(*y
), &col
);
359 ggiUnmapPixel(ggi_ctx
->ggi_visual
, col
, &rgb
);
360 rgba
[0][RCOMP
] = rgb
.r
>> SHIFT
;
361 rgba
[0][GCOMP
] = rgb
.g
>> SHIFT
;
362 rgba
[0][BCOMP
] = rgb
.b
>> SHIFT
;
371 int GGIextend_visual(ggi_visual_t vis
)
376 //static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx);
378 int GGIsetup_driver(ggi_mesa_context_t ggi_ctx
)
380 struct swrast_device_driver
*swdd
=
381 _swrast_GetDeviceDriverReference(ggi_ctx
->gl_ctx
);
383 GGIMESADPRINT_CORE("stubs: setup_driver\n");
385 swdd
->WriteRGBASpan
= GGIwrite_rgba_span
;
386 swdd
->WriteRGBSpan
= GGIwrite_rgb_span
;
387 swdd
->WriteMonoRGBASpan
= GGIwrite_mono_rgba_span
;
388 swdd
->WriteRGBAPixels
= GGIwrite_rgba_pixels
;
389 swdd
->WriteMonoRGBAPixels
= GGIwrite_mono_rgba_pixels
;
391 swdd
->WriteCI32Span
= GGIwrite_ci32_span
;
392 swdd
->WriteCI8Span
= GGIwrite_ci8_span
;
393 swdd
->WriteMonoCISpan
= GGIwrite_mono_ci_span
;
394 swdd
->WriteCI32Pixels
= GGIwrite_ci32_pixels
;
395 swdd
->WriteMonoCIPixels
= GGIwrite_mono_ci_pixels
;
397 swdd
->ReadCI32Span
= GGIread_ci32_span
;
398 swdd
->ReadRGBASpan
= GGIread_rgba_span
;
399 swdd
->ReadCI32Pixels
= GGIread_ci32_pixels
;
400 swdd
->ReadRGBAPixels
= GGIread_rgba_pixels
;
405 void GGIupdate_state(ggi_mesa_context_t
*ctx
)
407 //ctx->Driver.TriangleFunc = _swsetup_Triangle;
411 void GGItriangle_flat(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1, const SWvertex *v2)
414 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
418 color.r = v0->color[0]; \
419 color.g = v0->color[1]; \
420 color.b = v0->color[2]; \
421 color.a = v0->color[3]; \
422 ggiSetGCForeground(VIS, ggiMapColor(VIS, &color));
424 #define INNER_LOOP(LEFT,RIGHT,Y) \
425 ggiDrawHLine(VIS,LEFT,FLIP(Y),RIGHT-LEFT);
427 #include "swrast/s_tritemp.h"
431 static void GGItriangle_flat_depth(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1, const SWvertex *v2)
434 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
438 color.r = v0->color[0]; \
439 color.g = v0->color[1]; \
440 color.b = v0->color[2]; \
441 color.a = v0->color[3]; \
442 ggiSetGCForeground(VIS, ggiMapColor(VIS, &color));
444 #define INNER_LOOP(LEFT,RIGHT,Y) \
446 GLint i,xx=LEFT,yy=FLIP(Y),n=RIGHT-LEFT,length=0; \
449 GLdepth z=FixedToDepth(ffz); \
459 ggiDrawHLine(VIS,startx,yy,length); \
466 if (length) ggiDrawHLine(VIS,startx,yy,length); \
469 #include "swrast/s_tritemp.h"
473 static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx)
475 if (ctx->Stencil._Enabled) return NULL;
476 if (ctx->Polygon.SmoothFlag) return NULL;
477 if (ctx->Polygon.StippleFlag) return NULL;
478 if (ctx->Texture._ReallyEnabled) return NULL;
479 if (ctx->Light.ShadeModel==GL_SMOOTH) return NULL;
480 if (ctx->Depth.Test && ctx->Depth.Func != GL_LESS) return NULL;
483 return GGItriangle_flat_depth;
485 return GGItriangle_flat;
488 static int GGIopen(ggi_visual_t vis
, struct ggi_dlhandle
*dlh
,
489 const char *args
, void *argptr
, uint32
*dlret
)
491 LIBGGI_MESAEXT(vis
)->update_state
= GGIupdate_state
;
492 LIBGGI_MESAEXT(vis
)->setup_driver
= GGIsetup_driver
;
494 *dlret
= GGI_DL_OPDRAW
;
498 int MesaGGIdl_stubs(int func
, void **funcptr
)
511 return GGI_ENOTFOUND
;