GGI driver updates (Filip Spacek)

This commit is contained in:
Brian Paul 2002-06-10 15:16:44 +00:00
parent dd41748f63
commit b58c5ad7b0
8 changed files with 962 additions and 751 deletions

View File

@ -1,10 +1,11 @@
/* $Id: ggimesa.h,v 1.3 2000/02/09 19:03:28 brianp Exp $ */
/* $Id: ggimesa.h,v 1.4 2002/06/10 15:16:44 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
* Mesa 3-D graphics library GGI bindings (GGIGL [giggle])
* Version: 4.0
* Copyright (C) 1995-2000 Brian Paul
* Copyright (C) 1998 Uwe Maurer
* Copyrigth (C) 2001 Filip Spacek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -25,34 +26,59 @@
#ifndef GGIMESA_H
#define GGIMESA_H
#define GGIMESA_MAJOR_VERSION 3
#define GGIMESA_MINOR_VERSION 3
#define GGIMESA_MAJOR_VERSION 4
#define GGIMESA_MINOR_VERSION 0
#ifdef __cplusplus
extern "C" {
#endif
#include "GL/gl.h"
typedef struct ggi_mesa_context *GGIMesaContext;
#include <ggi/ggi.h>
#include "GL/gl.h"
typedef struct ggi_mesa_context *ggi_mesa_context_t;
extern GGIMesaContext GGIMesaCreateContext(void);
/*
* Initialize Mesa GGI extension
*/
int ggiMesaInit(void);
/*
* Clean up Mesa GGI exension
*/
int ggiMesaExit(void);
extern void GGIMesaDestroyContext(GGIMesaContext ctx);
/*
* Attach Mesa GGI extension to the visual 'vis'
*/
int ggiMesaAttach(ggi_visual_t vis);
/*
* Detach Mesa GGI extension from the visual 'vis'
*/
int ggiMesaDetach(ggi_visual_t vis);
extern void GGIMesaMakeCurrent(GGIMesaContext ctx);
int ggiMesaExtendVisual(ggi_visual_t vis, GLboolean alpha_flag,
GLboolean stereo_flag, GLint depth_size,
GLint stencil_size, GLint accum_red_size,
GLint accum_green_size, GLint accum_blue_size,
GLint accum_alpha_size, GLint num_samples);
extern GGIMesaContext GGIMesaGetCurrentContext(void);
/*
* Create a new context capable of displaying on the visual vis.
*/
ggi_mesa_context_t ggiMesaCreateContext(ggi_visual_t vis);
/*
* Destroy the context 'ctx'
*/
void ggiMesaDestroyContext(ggi_mesa_context_t ctx);
extern void GGIMesaSwapBuffers(void);
/*
* Make context 'ctx' the current context and bind it to visual 'vis'.
* Note that the context must have been created with respect to that visual.
*/
void ggiMesaMakeCurrent(ggi_mesa_context_t ctx, ggi_visual_t vis);
void ggiMesaSwapBuffers(void);
extern int GGIMesaSetVisual(GGIMesaContext ctx, ggi_visual_t vis,
GLboolean rgb_flag, GLboolean db_flag);
#ifdef __cplusplus
}

View File

@ -19,6 +19,7 @@
ggi_visual_t vis;
char text[100];
int db_flag,vis_x, vis_y, vir_x, vir_y, gt;
/*
* Draw a gear wheel. You'll probably want to call this function when
@ -157,6 +158,7 @@ static GLuint count = 1;
static void draw( void )
{
static int n = 0;
glClearColor(0,0,0,0);
glClearIndex(0);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@ -197,12 +199,25 @@ static void draw( void )
ggiPuts(vis,0,ggiGetInfo(vis)->mode->visible.y+16,text);
#endif
GGIMesaSwapBuffers();
if(db_flag)
ggiMesaSwapBuffers();
count++;
if (count==limit) {
exit(1);
}
++n;
/*
if (!(n%10)){
ggi_color rgb = { 10000, 10000, 10000 };
ggiSetSimpleMode(vis,vis_x+(n/10),vis_y+(n/10),db_flag?2:1, gt);
glViewport(0, 0,vis_x+(n/10),vis_y+(n/10));
ggiSetGCForeground(vis, ggiMapColor(vis, &rgb));
ggiDrawBox(vis, 20, 20, 100, 100);
if(db_flag)
ggiSetWriteFrame(vis, 1);
}
*/
}
static void idle( void )
@ -216,6 +231,10 @@ static void reshape( int width, int height )
{
GLfloat h = (GLfloat) height / (GLfloat) width;
if(db_flag)
glDrawBuffer(GL_BACK);
else
glDrawBuffer(GL_FRONT);
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@ -231,8 +250,8 @@ static void reshape( int width, int height )
static void init( void )
{
static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
static GLfloat red[4] = {0.9, 0.9, 0.9, 1.0 };
static GLfloat green[4] = {0.0, 0.8, 0.9, 1.0 };
static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
glLightfv( GL_LIGHT0, GL_POSITION, pos );
@ -276,9 +295,9 @@ static void usage(char *s)
int main( int argc, char *argv[] )
{
GGIMesaContext ctx;
int vis_x,vis_y,vir_x,vir_y,bpp,db_flag,gt;
ggi_mesa_context_t ctx;
ggi_mode mode;
int bpp;
limit=0;
@ -313,13 +332,12 @@ int main( int argc, char *argv[] )
exit(1);
}
ctx=GGIMesaCreateContext();
if (ctx==NULL)
if (ggiMesaInit() < 0)
{
printf("GGIMesaCreateContext() failed\n");
printf("ggiMesaInit failed\n");
exit(1);
}
vis=ggiOpen(NULL);
if (vis==NULL)
{
@ -327,29 +345,42 @@ int main( int argc, char *argv[] )
exit(1);
}
if (ggiSetGraphMode(vis,vis_x,vis_y,vir_x,vir_y,gt)<0)
if (ggiSetSimpleMode(vis,vis_x,vis_y,db_flag ? 2 : 1,gt)<0)
{
printf("%s: can't set graphmode (%i %i %i %i) %i BPP\n",
argv[0],vis_x,vis_y,vir_x,vir_y,bpp);
exit(1);
}
if (GGIMesaSetVisual(ctx,vis,GL_TRUE,db_flag)<0)
if (ggiMesaAttach(vis) < 0)
{
printf("ggiMesaAttach failed\n");
exit(1);
}
if (ggiMesaExtendVisual(vis, GL_FALSE, GL_FALSE, 16,
0, 0, 0, 0, 0, 1) < 0)
{
printf ("GGIMesaSetVisual() failed\n");
exit(1);
}
GGIMesaMakeCurrent(ctx);
ctx = ggiMesaCreateContext(vis);
if (ctx==NULL)
{
printf("GGIMesaCreateContext() failed\n");
exit(1);
}
ggiMesaMakeCurrent(ctx, vis);
ggiGetMode(vis,&mode);
reshape(mode.visible.x,mode.visible.y);
init();
while (!ggiKbhit(vis)) idle();
while (!ggiKbhit(vis)) { /*sleep(1);*/ idle(); }
GGIMesaDestroyContext(ctx);
ggiMesaDestroyContext(ctx);
ggiClose(vis);
printf("%s\n",text);

View File

@ -238,11 +238,6 @@ int glutCreateWindow(const char *title)
gt = (rgb) ? __glut_gt_rgb : __glut_gt_index;
__glut_ctx = GGIMesaCreateContext();
if (__glut_ctx == NULL)
ggiPanic("Can't create mesa-context\n");
__glut_vis = ggiOpen(NULL);
if (__glut_vis == NULL)
{
@ -261,20 +256,27 @@ int glutCreateWindow(const char *title)
/* return GL_FALSE; */
}
ggiGetMode(__glut_vis, &mode);
if (GGIMesaSetVisual(__glut_ctx, __glut_vis, rgb, frames > 1) < 0)
if (ggiMesaExtendVisual(__glut_vis, GL_FALSE, GL_FALSE,
16, 0, 0, 0, 0, 0, 1) < 0)
{
ggiPanic("GGIMesaSetVisual failed!\n");
}
__glut_ctx = ggiMesaCreateContext(__glut_vis);
if (__glut_ctx == NULL)
ggiPanic("Can't create mesa-context\n");
ggiGetMode(__glut_vis, &mode);
__glut_width = mode.visible.x;
__glut_height = mode.visible.y;
mousex = mode.visible.x / 2;
mousey = mode.visible.y / 2;
GGIMesaMakeCurrent(__glut_ctx);
ggiMesaMakeCurrent(__glut_ctx, __glut_vis);
if (__glut_reshape)
__glut_reshape(__glut_width, __glut_height);

View File

@ -24,6 +24,8 @@
#include <ggi/mesa/ggimesa.h>
#include <ggi/mesa/ggimesa_int.h>
#include <ggi/mesa/debug.h>
#include "swrast/swrast.h"
#define RMASK ((1<<R)-1)
#define GMASK ((1<<G)-1)
@ -33,21 +35,30 @@
#define GS (8-G)
#define BS (8-B)
#define PACK(color) (((color[RCOMP]>>RS) << (G+B)) | \
((color[GCOMP]>>GS) << B) | \
((color[BCOMP]>>BS)))
#define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1)
/**********************************************************************/
/***** Write spans of pixels *****/
/**********************************************************************/
void GGIwrite_ci32_span(const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLuint ci[],
const GLubyte mask[])
void GGIwrite_ci32_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLuint ci[], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask)
{
while (n--) {
if (*mask++) *fb=*ci;
if (*mask++)
*fb = *ci;
fb++;
ci++;
}
@ -58,17 +69,19 @@ void GGIwrite_ci32_span(const GLcontext *ctx,
}
}
void GGIwrite_ci8_span(const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte ci[],
const GLubyte mask[] )
void GGIwrite_ci8_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLubyte ci[], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask)
{
while (n--) {
if (*mask++) *fb=*ci;
if (*mask++)
*fb = *ci;
fb++;
ci++;
}
@ -80,87 +93,108 @@ void GGIwrite_ci8_span(const GLcontext *ctx,
}
void GGIwrite_rgba_span(const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgba[][4],
const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
if (mask)
{
while (n--) {
if (*mask++) {
*fb= ((rgba[0][RCOMP]>>RS) << (G+B)) |
((rgba[0][GCOMP]>>GS) << B) |
((rgba[0][BCOMP]>>BS));
}
fb++;
rgba++;
}
}
else
{
while (n--) {
*fb++= ((rgba[0][RCOMP]>>RS) << (G+B)) |
((rgba[0][GCOMP]>>GS) << B)|
((rgba[0][BCOMP]>>BS));
rgba++;
}
}
}
void GGIwrite_rgb_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgba[][3],
const GLubyte mask[] )
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
if (mask)
{
while (n--) {
if (*mask++) {
*fb= ((rgba[0][RCOMP]>>RS) << (G+B)) |
((rgba[0][GCOMP]>>GS) << B) |
((rgba[0][BCOMP]>>BS));
}
fb++;
rgba++;
}
}
else
{
while (n--) {
*fb++= ((rgba[0][RCOMP]>>RS) << (G+B)) |
((rgba[0][GCOMP]>>GS) << B) |
((rgba[0][BCOMP]>>BS));
rgba++;
}
}
}
void GGIwrite_mono_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte mask[])
void GGIwrite_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLchan rgba[][4], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
FB_TYPE color;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask)
{
fb=LFB(FB_TYPE,x,FLIP(y));
color=(FB_TYPE) GGICTX->color;
while (n--)
{
if (*mask++) *fb=color;
while (n--) {
if (*mask++)
*fb = PACK(rgba[0]);
fb++;
rgba++;
}
}
else
{
ggiDrawHLine(VIS,x,FLIP(y),n);
while (n--) {
*fb++ = PACK(rgba[0]);
rgba++;
}
}
}
void GGIwrite_rgb_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLchan rgba[][3], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask)
{
while (n--) {
if (*mask++)
*fb = PACK(rgba[0]);
fb++;
rgba++;
}
}
else
{
while (n--) {
*fb++ = PACK(rgba[0]);
rgba++;
}
}
}
void GGIwrite_mono_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLchan color[4], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask){
while (n--){
if (*mask++)
*fb = PACK(color);
++fb;
}
}
else {
while (n--)
*fb++ = PACK(color);
/* Alternatively we could write a potentialy faster HLine
ggiSetGCForeground(ggi_ctx->ggi_visual, color);
ggiDrawHLine(ggi_ctx->ggi_visual,x,FLIP(y),n);
*/
}
}
void GGIwrite_mono_ci_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLuint ci, const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
if (mask){
while (n--){
if (*mask++)
*fb = ci;
++fb;
}
}
else {
while (n--)
*fb++ = ci;
/* Alternatively we could write a potentialy faster HLine
ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
ggiDrawHLine(ggi_ctx->ggi_visual, x, FLIP(y), n);
*/
}
}
@ -171,27 +205,33 @@ void GGIwrite_mono_span( const GLcontext *ctx,
void GGIread_ci32_span(const GLcontext *ctx,
GLuint n, GLint x, GLint y, GLuint ci[])
GLuint n, GLint x, GLint y, GLuint ci[])
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
while (n--)
*ci++=(GLuint)*fb++;
*ci++ = (GLuint)*fb++;
}
void GGIread_rgba_span(const GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLubyte rgba[][4])
GLuint n, GLint x, GLint y, GLchan rgba[][4])
{
FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
FB_TYPE color;
FB_TYPE *fb;
fb = (FB_TYPE *)(LIBGGI_CURWRITE(ggi_ctx->ggi_visual) +
FLIP(y)*LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual)) + x;
while (n--)
{
color=*fb++;
color = *fb++;
rgba[0][RCOMP] = (GLubyte) (color>>(G+B))<<RS;
rgba[0][GCOMP] = (GLubyte) ((color>>B)& ((1<<G)-1))<<GS;
rgba[0][BCOMP] = (GLubyte) (color & ((1<<B)-1))<<BS;
rgba[0][ACOMP] =0;
rgba[0][ACOMP] = 0;
rgba++;
}
}
@ -201,68 +241,97 @@ void GGIread_rgba_span(const GLcontext *ctx,
/**********************************************************************/
void GGIwrite_ci32_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
const GLuint ci[], const GLubyte mask[] )
GLuint n, const GLint x[], const GLint y[],
const GLuint ci[], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,0,0);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
while (n--) {
if (*mask++) *(fb+ *x + FLIP(*y)*GGICTX->width)=*ci;
if (*mask++){
FB_TYPE *dst = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
*dst = *ci;
}
ci++;
x++;
y++;
}
}
void GGIwrite_mono_pixels(const GLcontext *ctx,
GLuint n,
const GLint x[], const GLint y[],
const GLubyte mask[] )
void GGIwrite_mono_ci_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLuint ci, const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,0,0);
FB_TYPE color=(FB_TYPE) GGICTX->color;
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
while (n--) {
if (*mask++) *(fb+ *x + FLIP(*y)*GGICTX->width)=color;
if (*mask++){
FB_TYPE *dst = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
*dst = ci;
}
x++;
y++;
}
}
void GGIwrite_rgba_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
const GLubyte rgba[][4],
const GLubyte mask[] )
GLuint n, const GLint x[], const GLint y[],
const GLchan rgba[][4], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,0,0);
FB_TYPE color;
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
while (n--) {
if (*mask++) {
color= ((rgba[0][RCOMP]>>RS) << (G+B)) |
((rgba[0][GCOMP]>>GS) << B) |
((rgba[0][BCOMP]>>BS));
*(fb+ *x + FLIP(*y)*GGICTX->width)=color;
if (*mask++){
FB_TYPE *dst = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
*dst = PACK(rgba[0]);
}
x++;y++;
x++;
y++;
rgba++;
}
}
void GGIwrite_mono_rgba_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
const GLchan rgba[4], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
while (n--) {
if (*mask++){
FB_TYPE *dst = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
*dst = PACK(rgba);
}
x++;
y++;
}
}
/**********************************************************************/
/***** Read arrays of pixels *****/
/**********************************************************************/
void GGIread_ci32_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLuint ci[], const GLubyte mask[])
GLuint n, const GLint x[], const GLint y[],
GLuint ci[], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,0,0);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
while (n--) {
if (*mask++)
*ci=*(fb+ *x + FLIP(*y)*GGICTX->width);
if (*mask++){
FB_TYPE *src = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
*ci = *src;
}
ci++;
x++;
y++;
@ -270,60 +339,70 @@ void GGIread_ci32_pixels(const GLcontext *ctx,
}
void GGIread_rgba_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4],
const GLubyte mask[] )
GLuint n, const GLint x[], const GLint y[],
GLubyte rgba[][4], const GLubyte mask[])
{
FB_TYPE *fb=LFB(FB_TYPE,0,0);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
int stride = LIBGGI_FB_W_STRIDE(ggi_ctx->ggi_visual);
void *fb = LIBGGI_CURWRITE(ggi_ctx->ggi_visual);
FB_TYPE color;
while (n--)
{
if (*mask++)
{
color=*(fb+ *x + FLIP(*y)*GGICTX->width);
rgba[0][RCOMP] =(GLubyte)(color>>(G+B))<<RS;
rgba[0][GCOMP] =(GLubyte)((color>>B)& ((1<<G)-1))<<GS;
rgba[0][BCOMP] =(GLubyte) (color & ((1<<B)-1))<<BS;
rgba[0][ACOMP] =0;
{
FB_TYPE *src = (FB_TYPE*)(fb + FLIP(*y)*stride) + *x;
color = *src;
rgba[0][RCOMP] = (GLubyte)(color>>(G+B))<<RS;
rgba[0][GCOMP] = (GLubyte)((color>>B)& ((1<<G)-1))<<GS;
rgba[0][BCOMP] = (GLubyte) (color & ((1<<B)-1))<<BS;
rgba[0][ACOMP] = 0;
}
x++; y++;
x++;
y++;
rgba++;
}
}
int GGIsetup_driver(GGIMesaContext ggictx, struct ggi_mesa_info *info)
void GGIset_read_buffer(GLcontext *ctx, GLframebuffer *buffer, GLenum mode)
{
GLcontext *ctx = ggictx->gl_ctx;
}
ctx->Driver.WriteRGBASpan = GGIwrite_rgba_span;
ctx->Driver.WriteRGBSpan = GGIwrite_rgb_span;
// ctx->Driver.WriteMonoRGBASpan = GGIwrite_mono_span;
ctx->Driver.WriteRGBAPixels = GGIwrite_rgba_pixels;
// ctx->Driver.WriteMonoRGBAPixels = GGIwrite_mono_pixels;
int GGIsetup_driver(ggi_mesa_context_t ggi_ctx)
{
struct swrast_device_driver *swdd =
_swrast_GetDeviceDriverReference(ggi_ctx->gl_ctx);
ctx->Driver.WriteCI32Span = GGIwrite_ci32_span;
ctx->Driver.WriteCI8Span = GGIwrite_ci8_span;
// ctx->Driver.WriteMonoCISpan = GGIwrite_mono_span;
ctx->Driver.WriteCI32Pixels = GGIwrite_ci32_pixels;
// ctx->Driver.WriteMonoCIPixels = GGIwrite_mono_pixels;
GGIMESADPRINT_LIBS("linear_%d: GGIsetup_driver\n", sizeof(FB_TYPE)*8);
swdd->WriteRGBASpan = GGIwrite_rgba_span;
swdd->WriteRGBSpan = GGIwrite_rgb_span;
swdd->WriteMonoRGBASpan = GGIwrite_mono_rgba_span;
swdd->WriteRGBAPixels = GGIwrite_rgba_pixels;
swdd->WriteMonoRGBAPixels = GGIwrite_mono_rgba_pixels;
ctx->Driver.ReadCI32Span = GGIread_ci32_span;
ctx->Driver.ReadRGBASpan = GGIread_rgba_span;
ctx->Driver.ReadCI32Pixels = GGIread_ci32_pixels;
ctx->Driver.ReadRGBAPixels = GGIread_rgba_pixels;
swdd->WriteCI32Span = GGIwrite_ci32_span;
swdd->WriteCI8Span = GGIwrite_ci8_span;
swdd->WriteMonoCISpan = GGIwrite_mono_ci_span;
swdd->WriteCI32Pixels = GGIwrite_ci32_pixels;
swdd->WriteMonoCIPixels = GGIwrite_mono_ci_pixels;
info->red_bits = R;
info->green_bits =G;
info->blue_bits = B;
swdd->ReadCI32Span = GGIread_ci32_span;
swdd->ReadRGBASpan = GGIread_rgba_span;
swdd->ReadCI32Pixels = GGIread_ci32_pixels;
swdd->ReadRGBAPixels = GGIread_rgba_pixels;
swdd->SetReadBuffer = GGIset_read_buffer;
return 0;
}
static int GGIopen(ggi_visual_t vis,struct ggi_dlhandle *dlh,
const char *args,void *argptr, uint32 *dlret)
{
LIBGGI_MESAEXT(vis)->setup_driver=GGIsetup_driver;
const char *args,void *argptr, uint32 *dlret)
{
GGIMESADPRINT_CORE("linear_%d: GGIOpen\n", sizeof(FB_TYPE)*8);
LIBGGI_MESAEXT(vis)->setup_driver = GGIsetup_driver;
*dlret = GGI_DL_OPDRAW;
return 0;
@ -332,15 +411,15 @@ static int GGIopen(ggi_visual_t vis,struct ggi_dlhandle *dlh,
int DLOPENFUNC(int func, void **funcptr)
{
switch (func) {
case GGIFUNC_open:
*funcptr = GGIopen;
return 0;
case GGIFUNC_exit:
case GGIFUNC_close:
*funcptr = NULL;
return 0;
default:
*funcptr = NULL;
case GGIFUNC_open:
*funcptr = GGIopen;
return 0;
case GGIFUNC_exit:
case GGIFUNC_close:
*funcptr = NULL;
return 0;
default:
*funcptr = NULL;
}
return GGI_ENOTFOUND;
}

View File

@ -26,13 +26,16 @@
#include <ggi/internal/ggi-dl.h>
#include <ggi/mesa/ggimesa_int.h>
#include <ggi/mesa/debug.h>
#include "mmath.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "swrast/s_context.h"
#include "swrast/s_depth.h"
#include "swrast/s_triangle.h"
//#include "swrast_setup/swrast_setup.h"
//#include "swrast/s_context.h"
//#include "swrast/s_depth.h"
//#include "swrast/s_triangle.h"
#define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord)-1)
/**********************************************************************/
/***** Write spans of pixels *****/
@ -43,18 +46,21 @@ void GGIwrite_ci32_span(const GLcontext *ctx,
const GLuint ci[],
const GLubyte mask[] )
{
y=FLIP(y);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
y = FLIP(y);
if (mask)
{
while (n--) {
if (*mask++) ggiPutPixel(VIS,x,y,*ci);
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, x, y, *ci);
x++;
ci++;
}
}
else
{
while (n--) ggiPutPixel(VIS,x++,y,*ci++);
while (n--)
ggiPutPixel(ggi_ctx->ggi_visual, x++, y, *ci++);
}
}
@ -63,36 +69,69 @@ void GGIwrite_ci8_span(const GLcontext *ctx,
const GLubyte ci[],
const GLubyte mask[] )
{
y=FLIP(y);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
y = FLIP(y);
if (mask)
{
while (n--) {
if (*mask++) ggiPutPixel(VIS,x,y,*ci);
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, x, y, *ci);
x++;
ci++;
}
}
else
{
while (n--) ggiPutPixel(VIS,x++,y,*ci++);
while (n--)
ggiPutPixel(ggi_ctx->ggi_visual, x++, y, *ci++);
}
}
void GGIwrite_mono_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte mask[] )
void GGIwrite_mono_ci_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLuint ci, const GLubyte mask[])
{
y=FLIP(y);
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
y = FLIP(y);
if (mask)
{
while (n--) {
if (*mask++) ggiDrawPixel(VIS,x,y);
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, x, y, ci);
x++;
}
}
else
{
ggiDrawHLine(VIS,x,y,n);
while (n--)
ggiPutPixel(ggi_ctx->ggi_visual, x++, y, ci);
}
}
void GGIwrite_mono_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLchan rgba[4], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
y = FLIP(y);
rgb.r = (uint16)(rgba[RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
if (mask)
{
while (n--) {
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
x++;
}
}
else
{
ggiDrawHLine(ggi_ctx->ggi_visual, x, y, n);
}
}
@ -101,20 +140,21 @@ void GGIwrite_rgba_span( const GLcontext *ctx,
const GLubyte rgba[][4],
const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
y=FLIP(y);
y = FLIP(y);
if (mask)
{
while (n--) {
if (*mask++)
{
rgb.r=(uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g=(uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b=(uint16)(rgba[0][BCOMP]) << SHIFT;
col=ggiMapColor(VIS,&rgb);
ggiPutPixel(VIS,x,y,col);
rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
}
x++;
rgba++;
@ -124,34 +164,36 @@ void GGIwrite_rgba_span( const GLcontext *ctx,
{
while (n--)
{
rgb.r=(uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g=(uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b=(uint16)(rgba[0][BCOMP]) << SHIFT;
col=ggiMapColor(VIS,&rgb);
ggiPutPixel(VIS,x++,y,col);
rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiPutPixel(ggi_ctx->ggi_visual, x++, y, col);
rgba++;
}
}
}
void GGIwrite_rgb_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
const GLubyte rgba[][3],
const GLubyte mask[] )
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
y=FLIP(y);
y = FLIP(y);
if (mask)
{
while (n--) {
if (*mask++)
{
rgb.r=(uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g=(uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b=(uint16)(rgba[0][BCOMP]) << SHIFT;
col=ggiMapColor(VIS,&rgb);
ggiPutPixel(VIS,x,y,col);
rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
}
x++;
rgba++;
@ -161,11 +203,11 @@ void GGIwrite_rgb_span( const GLcontext *ctx,
{
while (n--)
{
rgb.r=(uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g=(uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b=(uint16)(rgba[0][BCOMP]) << SHIFT;
col=ggiMapColor(VIS,&rgb);
ggiPutPixel(VIS,x++,y,col);
rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiPutPixel(ggi_ctx->ggi_visual, x++, y, col);
rgba++;
}
}
@ -181,24 +223,26 @@ void GGIwrite_rgb_span( const GLcontext *ctx,
void GGIread_ci32_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y, GLuint ci[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
y = FLIP(y);
while (n--)
ggiGetPixel(VIS, x++, y,ci++);
ggiGetPixel(ggi_ctx->ggi_visual, x++, y, ci++);
}
void GGIread_rgba_span( const GLcontext *ctx,
GLuint n, GLint x, GLint y,
GLubyte rgba[][4])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
y=FLIP(y);
y = FLIP(y);
while (n--)
{
ggiGetPixel(VIS,x++,y,&col);
ggiUnmapPixel(VIS,col,&rgb);
ggiGetPixel(ggi_ctx->ggi_visual, x++, y, &col);
ggiUnmapPixel(ggi_ctx->ggi_visual, col, &rgb);
rgba[0][RCOMP] = (GLubyte) (rgb.r >> SHIFT);
rgba[0][GCOMP] = (GLubyte) (rgb.g >> SHIFT);
rgba[0][BCOMP] = (GLubyte) (rgb.b >> SHIFT);
@ -215,21 +259,24 @@ void GGIwrite_ci32_pixels( const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
const GLuint ci[], const GLubyte mask[] )
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
while (n--) {
if (*mask++) ggiPutPixel(VIS,*x, FLIP(*y),*ci);
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), *ci);
ci++;
x++;
y++;
}
}
void GGIwrite_mono_pixels( const GLcontext *ctx,
GLuint n,
const GLint x[], const GLint y[],
const GLubyte mask[] )
void GGIwrite_mono_ci_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLuint ci, const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
while (n--) {
if (*mask++) ggiDrawPixel(VIS,*x,FLIP(*y));
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), ci);
x++;
y++;
}
@ -240,21 +287,43 @@ void GGIwrite_rgba_pixels( const GLcontext *ctx,
const GLubyte rgba[][4],
const GLubyte mask[] )
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_pixel col;
ggi_color rgb;
while (n--) {
if (*mask++) {
rgb.r=(uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g=(uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b=(uint16)(rgba[0][BCOMP]) << SHIFT;
col=ggiMapColor(VIS,&rgb);
ggiPutPixel(VIS,*x,FLIP(*y),col);
rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), col);
}
x++;y++;
x++;
y++;
rgba++;
}
}
void GGIwrite_mono_rgba_pixels(const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
const GLchan rgba[4], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
rgb.r = (uint16)(rgba[RCOMP]) << SHIFT;
rgb.g = (uint16)(rgba[GCOMP]) << SHIFT;
rgb.b = (uint16)(rgba[BCOMP]) << SHIFT;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
while (n--) {
if (*mask++)
ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), col);
x++;
y++;
}
}
/**********************************************************************/
/***** Read arrays of pixels *****/
@ -264,9 +333,10 @@ void GGIread_ci32_pixels( const GLcontext *ctx,
GLuint n, const GLint x[], const GLint y[],
GLuint ci[], const GLubyte mask[])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
while (n--) {
if (*mask++)
ggiGetPixel(VIS, *x, FLIP(*y) ,ci);
ggiGetPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), ci);
ci++;
x++;
y++;
@ -278,6 +348,7 @@ void GGIread_rgba_pixels( const GLcontext *ctx,
GLubyte rgba[][4],
const GLubyte mask[] )
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
@ -285,47 +356,59 @@ void GGIread_rgba_pixels( const GLcontext *ctx,
{
if (*mask++)
{
ggiGetPixel(VIS,*x,FLIP(*y),&col);
ggiUnmapPixel(VIS,col,&rgb);
rgba[0][RCOMP]= rgb.r >> SHIFT;
rgba[0][GCOMP]= rgb.g >> SHIFT;
rgba[0][BCOMP]= rgb.b >> SHIFT;
rgba[0][ACOMP]=0;
ggiGetPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), &col);
ggiUnmapPixel(ggi_ctx->ggi_visual, col, &rgb);
rgba[0][RCOMP] = rgb.r >> SHIFT;
rgba[0][GCOMP] = rgb.g >> SHIFT;
rgba[0][BCOMP] = rgb.b >> SHIFT;
rgba[0][ACOMP] = 0;
}
x++; y++;
x++;
y++;
rgba++;
}
}
static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx);
int GGIsetup_driver(GGIMesaContext ggictx, struct ggi_mesa_info *info)
int GGIextend_visual(ggi_visual_t vis)
{
GLcontext *ctx = ggictx->gl_ctx;
return 0;
}
ctx->Driver.WriteRGBASpan = GGIwrite_rgba_span;
ctx->Driver.WriteRGBSpan = GGIwrite_rgb_span;
ctx->Driver.WriteRGBAPixels = GGIwrite_rgba_pixels;
//static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx);
ctx->Driver.WriteCI32Span = GGIwrite_ci32_span;
ctx->Driver.WriteCI8Span = GGIwrite_ci8_span;
ctx->Driver.WriteCI32Pixels = GGIwrite_ci32_pixels;
int GGIsetup_driver(ggi_mesa_context_t ggi_ctx)
{
struct swrast_device_driver *swdd =
_swrast_GetDeviceDriverReference(ggi_ctx->gl_ctx);
ctx->Driver.ReadCI32Span = GGIread_ci32_span;
ctx->Driver.ReadRGBASpan = GGIread_rgba_span;
ctx->Driver.ReadCI32Pixels = GGIread_ci32_pixels;
ctx->Driver.ReadRGBAPixels = GGIread_rgba_pixels;
GGIMESADPRINT_CORE("stubs: setup_driver\n");
swdd->WriteRGBASpan = GGIwrite_rgba_span;
swdd->WriteRGBSpan = GGIwrite_rgb_span;
swdd->WriteMonoRGBASpan = GGIwrite_mono_rgba_span;
swdd->WriteRGBAPixels = GGIwrite_rgba_pixels;
swdd->WriteMonoRGBAPixels = GGIwrite_mono_rgba_pixels;
swdd->WriteCI32Span = GGIwrite_ci32_span;
swdd->WriteCI8Span = GGIwrite_ci8_span;
swdd->WriteMonoCISpan = GGIwrite_mono_ci_span;
swdd->WriteCI32Pixels = GGIwrite_ci32_pixels;
swdd->WriteMonoCIPixels = GGIwrite_mono_ci_pixels;
swdd->ReadCI32Span = GGIread_ci32_span;
swdd->ReadRGBASpan = GGIread_rgba_span;
swdd->ReadCI32Pixels = GGIread_ci32_pixels;
swdd->ReadRGBAPixels = GGIread_rgba_pixels;
return 0;
}
void GGIupdate_state(GLcontext *ctx)
void GGIupdate_state(ggi_mesa_context_t *ctx)
{
ctx->Driver.TriangleFunc = _swsetup_Triangle;
//ctx->Driver.TriangleFunc = _swsetup_Triangle;
}
/*
void GGItriangle_flat(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1, const SWvertex *v2)
{
//#define INTERP_Z 1
@ -402,10 +485,10 @@ static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx)
return GGItriangle_flat;
}
*/
static int GGIopen(ggi_visual_t vis, struct ggi_dlhandle *dlh,
const char *args, void *argptr, uint32 *dlret)
{
{
LIBGGI_MESAEXT(vis)->update_state = GGIupdate_state;
LIBGGI_MESAEXT(vis)->setup_driver = GGIsetup_driver;
@ -416,15 +499,15 @@ static int GGIopen(ggi_visual_t vis, struct ggi_dlhandle *dlh,
int MesaGGIdl_stubs(int func, void **funcptr)
{
switch (func) {
case GGIFUNC_open:
*funcptr = GGIopen;
return 0;
case GGIFUNC_exit:
case GGIFUNC_close:
*funcptr = NULL;
return 0;
default:
*funcptr = NULL;
case GGIFUNC_open:
*funcptr = GGIopen;
return 0;
case GGIFUNC_exit:
case GGIFUNC_close:
*funcptr = NULL;
return 0;
default:
*funcptr = NULL;
}
return GGI_ENOTFOUND;
}

View File

@ -1,6 +1,7 @@
/* GGI-Driver for MESA
*
* Copyright (C) 1997-1998 Uwe Maurer - uwe_maurer@t-online.de
* 2002 Filip Spacek
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -33,23 +34,17 @@
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#undef VIS
#undef FLIP
#define VIS (GGIMesa->ggi_vis)
#define FLIP(y) (GGIMesa->flip_y-(y))
GGIMesaContext GGIMesa = NULL; /* the current context */
#include "tnl/t_context.h"
#include "tnl/t_pipeline.h"
#include "array_cache/acache.h"
#include "texformat.h"
#include "texstore.h"
ggi_extid ggiMesaID = -1;
static int _ggimesaLibIsUp = 0;
static void *_ggimesaConfigHandle;
/* FIXME: These should really be defined in the make system using -Dxxx */
#define GGIMESACONFFILE "/usr/local/etc/ggi/ggimesa.conf"
#define GGIMESATAGLEN 0
static char ggimesaconfstub[512] = GGIMESACONFFILE;
static char *ggimesaconffile = ggimesaconfstub + GGIMESATAGLEN;
static char ggimesaconffile[] = GGIMESACONFFILE;
int _ggimesaDebugSync = 0;
uint32 _ggimesaDebugState = 0;
@ -57,48 +52,52 @@ uint32 _ggimesaDebugState = 0;
static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state);
static int changed(ggi_visual_t vis, int whatchanged);
static void gl_ggiGetSize(GLcontext *ctx, GLuint *width, GLuint *height)
static int _ggi_error(void)
{
GGIMESADPRINT_CORE("_ggi_error() called\n");
return -1;
}
static void gl_ggiGetSize(GLframebuffer *fb, GLuint *width, GLuint *height)
{
/* FIXME: this is a hack to work around the new interface */
GLcontext *ctx;
ggi_mesa_context_t ggi_ctx;
ctx = _mesa_get_current_context();
ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiGetSize() called\n");
*width = GGIMesa->width;
*height = GGIMesa->height;
*width = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.x;
*height = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y;
printf("returning %d, %d\n", *width, *height);
}
static void gl_ggiSetIndex(GLcontext *ctx, GLuint ci)
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiSetIndex() called\n");
ggiSetGCForeground(VIS, ci);
GGICTX->color = (ggi_pixel)ci;
ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
ggi_ctx->color = (ggi_pixel)ci;
}
static void gl_ggiSetClearIndex(GLcontext *ctx, GLuint ci)
{
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiSetClearIndex() called\n");
ggiSetGCForeground(VIS, ci);
GGICTX->clearcolor = (ggi_pixel)ci;
}
static void gl_ggiSetColor(GLcontext *ctx, GLubyte red, GLubyte green,
GLubyte blue, GLubyte alpha)
{
ggi_color rgb;
ggi_pixel col;
GGIMESADPRINT_CORE("gl_ggiSetColor() called\n");
rgb.r = (uint16)red << SHIFT;
rgb.g = (uint16)green << SHIFT;
rgb.b = (uint16)blue << SHIFT;
col = ggiMapColor(VIS, &rgb);
ggiSetGCForeground(VIS, col);
GGICTX->color = col;
ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
ggi_ctx->clearcolor = (ggi_pixel)ci;
}
static void gl_ggiSetClearColor(GLcontext *ctx, const GLchan color[4])
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
ggi_color rgb;
ggi_pixel col;
@ -107,48 +106,60 @@ static void gl_ggiSetClearColor(GLcontext *ctx, const GLchan color[4])
rgb.r = (uint16)color[0] << SHIFT;
rgb.g = (uint16)color[1] << SHIFT;
rgb.b = (uint16)color[2] << SHIFT;
col = ggiMapColor(VIS, &rgb);
ggiSetGCForeground(VIS, col);
GGICTX->clearcolor = col;
col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
ggiSetGCForeground(ggi_ctx->ggi_visual, col);
ggi_ctx->clearcolor = col;
}
static GLbitfield gl_ggiClear(GLcontext *ctx,GLbitfield mask, GLboolean all,
GLint x, GLint y, GLint width, GLint height)
static void gl_ggiClear(GLcontext *ctx, GLbitfield mask, GLboolean all,
GLint x, GLint y, GLint width, GLint height)
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiClear() called\n");
if (mask & GL_COLOR_BUFFER_BIT)
if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT))
{
ggiSetGCForeground(VIS, GGICTX->clearcolor);
ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->clearcolor);
if (all)
{
ggiDrawBox(VIS, 0, GGIMesa->origin.y,
GGIMesa->width, GGIMesa->height);
int w, h;
w = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.x;
h = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y;
ggiDrawBox(ggi_ctx->ggi_visual, 0, 0, w, h);
}
else
{
ggiDrawBox(VIS, x, FLIP(y), width, height);
ggiDrawBox(ggi_ctx->ggi_visual, x, y, //FLIP(y),
width, height);
}
ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->color);
ggiSetGCForeground(VIS, GGICTX->color);
mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
}
return mask & (~GL_COLOR_BUFFER_BIT);
_swrast_Clear(ctx, mask, all, x, y, width, height);
}
/* Set the buffer used for drawing */
static GLboolean gl_ggiSetDrawBuffer(GLcontext *ctx, GLenum mode)
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
printf("set draw %d\n", mode);
GGIMESADPRINT_CORE("gl_ggiSetDrawBuffer() called\n");
if (mode == GL_FRONT_LEFT)
{
GGICTX->active_buffer = 1;
ggiSetWriteFrame(ggi_ctx->ggi_visual,
ggiGetDisplayFrame(ggi_ctx->ggi_visual));
return GL_TRUE;
}
else if (mode == GL_BACK_LEFT)
{
GGICTX->active_buffer = 0;
ggiSetWriteFrame(ggi_ctx->ggi_visual,
ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1);
return GL_TRUE;
}
else
@ -160,18 +171,27 @@ static GLboolean gl_ggiSetDrawBuffer(GLcontext *ctx, GLenum mode)
/* Set the buffer used for reading */
/* XXX support for separate read/draw buffers hasn't been tested */
static void gl_ggiSetReadBuffer(GLcontext *ctx, GLframebuffer *buffer, GLenum mode)
static GLboolean gl_ggiSetReadBuffer(GLcontext *ctx, GLframebuffer *buffer, GLenum mode)
{
GGIMESADPRINT_CORE("gl_ggiSetReadBuffer() called\n");
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
printf("set read %d\n", mode);
GGIMESADPRINT_CORE("gl_ggiSetReadBuffer() called\n");
if (mode == GL_FRONT_LEFT)
{
GGICTX->active_buffer = 1;
ggiSetReadFrame(ggi_ctx->ggi_visual,
ggiGetDisplayFrame(ggi_ctx->ggi_visual));
return GL_TRUE;
}
else if (mode == GL_BACK_LEFT)
{
GGICTX->active_buffer = 0;
ggiSetReadFrame(ggi_ctx->ggi_visual,
ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1);
return GL_TRUE;
}
else
return GL_FALSE;
}
@ -187,9 +207,11 @@ static const GLubyte * gl_ggiGetString(GLcontext *ctx, GLenum name)
static void gl_ggiFlush(GLcontext *ctx)
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiFlush() called\n");
ggiFlush(VIS);
ggiFlush(ggi_ctx->ggi_visual);
}
static void gl_ggiIndexMask(GLcontext *ctx, GLuint mask)
@ -197,7 +219,8 @@ static void gl_ggiIndexMask(GLcontext *ctx, GLuint mask)
GGIMESADPRINT_CORE("gl_ggiIndexMask() called\n");
}
static void gl_ggiColorMask(GLcontext *ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
static void gl_ggiColorMask(GLcontext *ctx, GLboolean rmask, GLboolean gmask,
GLboolean bmask, GLboolean amask)
{
GGIMESADPRINT_CORE("gl_ggiColorMask() called\n");
}
@ -209,75 +232,95 @@ static void gl_ggiEnable(GLcontext *ctx, GLenum pname, GLboolean state)
static void gl_ggiSetupPointers(GLcontext *ctx)
{
TNLcontext *tnl;
GGIMESADPRINT_CORE("gl_ggiSetupPointers() called\n");
/* Initialize all the pointers in the DD struct. Do this whenever */
/* a new context is made current or we change buffers via set_buffer! */
/* General information */
ctx->Driver.GetString = gl_ggiGetString;
ctx->Driver.UpdateState = gl_ggiUpdateState;
ctx->Driver.GetBufferSize = gl_ggiGetSize;
ctx->Driver.Finish = gl_ggiFlush;
ctx->Driver.Flush = gl_ggiFlush;
/* Software rasterizer pixel paths */
ctx->Driver.Accum = _swrast_Accum;
ctx->Driver.Bitmap = _swrast_Bitmap;
ctx->Driver.Clear = gl_ggiClear;
ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
ctx->Driver.CopyPixels = _swrast_CopyPixels;
ctx->Driver.DrawPixels = _swrast_DrawPixels;
ctx->Driver.ReadPixels = _swrast_ReadPixels;
/* Software texturing */
ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
ctx->Driver.TexImage1D = _mesa_store_teximage1d;
ctx->Driver.TexImage2D = _mesa_store_teximage2d;
ctx->Driver.TexImage3D = _mesa_store_teximage3d;
ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
ctx->Driver.BaseCompressedTexFormat = _mesa_base_compressed_texformat;
ctx->Driver.CompressedTextureSize = _mesa_compressed_texture_size;
ctx->Driver.GetCompressedTexImage = _mesa_get_compressed_teximage;
/* Imaging extensions */
ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
/* State change callbacks */
ctx->Driver.SetDrawBuffer = gl_ggiSetDrawBuffer;
ctx->Driver.ClearIndex = gl_ggiSetClearIndex;
ctx->Driver.ClearColor = gl_ggiSetClearColor;
// ctx->Driver.Clear = gl_ggiClear;
ctx->Driver.IndexMask = gl_ggiIndexMask;
ctx->Driver.ColorMask = gl_ggiColorMask;
ctx->Driver.Enable = gl_ggiEnable;
ctx->Driver.SetDrawBuffer = gl_ggiSetDrawBuffer;
ctx->Driver.SetReadBuffer = gl_ggiSetReadBuffer;
ctx->Driver.GetBufferSize = gl_ggiGetSize;
ctx->Driver.Finish = gl_ggiFlush;
ctx->Driver.Flush = gl_ggiFlush;
ctx->Driver.UpdateState = gl_ggiUpdateState;
ctx->Driver.RenderStart = 0;
ctx->Driver.RenderFinish = _swrast_flush;
ctx->Driver.PointsFunc = _swsetup_Points;
ctx->Driver.LineFunc = _swsetup_Line;
ctx->Driver.TriangleFunc = _swsetup_Triangle;
ctx->Driver.QuadFunc = _swsetup_Quad;
/* Initialize TNL driver interface */
tnl = TNL_CONTEXT(ctx);
tnl->Driver.RunPipeline = _tnl_run_pipeline;
/* Install setup for tnl */
_swsetup_Wakeup(ctx);
}
static int gl_ggiInitInfo(GGIMesaContext ctx, struct ggi_mesa_info *info)
static void get_mode_info(ggi_visual_t vis, int *r, int *g, int *b,
GLboolean *rgb, GLboolean *db, int *ci)
{
ggi_mode mode;
GGIMESADPRINT_CORE("gl_ggiInitInfo() called\n");
int i;
ggiGetMode(ctx->ggi_vis, &mode);
info->depth_bits = DEFAULT_SOFTWARE_DEPTH_BITS;
info->stencil_bits = STENCIL_BITS;
info->accum_bits = ACCUM_BITS;
*r = 0;
*g = 0;
*b = 0;
if (info->rgb_flag)
{
info->rgb_flag = GL_TRUE;
info->alpha_flag = GL_FALSE;
info->index_bits = 0;
info->red_bits = 8;
info->green_bits = 8;
info->blue_bits = 8;
info->alpha_bits = 0;
for(i = 0; i < sizeof(ggi_pixel)*8; ++i){
int mask = 1 << i;
if(LIBGGI_PIXFMT(vis)->red_mask & mask)
++(*r);
if(LIBGGI_PIXFMT(vis)->green_mask & mask)
++(*g);
if(LIBGGI_PIXFMT(vis)->blue_mask & mask)
++(*b);
}
else
{
info->alpha_flag = GL_FALSE;
info->index_bits = GT_SIZE(mode.graphtype);
info->red_bits = info->green_bits =
info->blue_bits = info->alpha_bits = 0;
}
return 0;
*rgb = GT_SCHEME(LIBGGI_MODE(vis)->graphtype) == GT_TRUECOLOR;
*db = LIBGGI_MODE(vis)->frames > 1;
*ci = GT_SIZE(LIBGGI_MODE(vis)->graphtype);
printf("rgb (%d, %d, %d) db %d, rgb %d ci %d\n",*r,*g,*b,*db,*rgb,*ci);
}
int ggiMesaInit()
{
int err;
@ -300,17 +343,19 @@ int ggiMesaInit()
_ggimesaLibIsUp++;
if (_ggimesaLibIsUp > 1)
return 0; /* Initialize only at first call */
return 0; /* Initialize only at first call */
err = ggLoadConfig(ggimesaconffile, &_ggimesaConfigHandle);
if (err != GGI_OK)
{
GGIMESADPRINT_CORE("GGIMesa: Couldn't open %s\n", ggimesaconffile);
GGIMESADPRINT_CORE("GGIMesa: Couldn't open %s\n",
ggimesaconffile);
_ggimesaLibIsUp--;
return err;
}
ggiMesaID = ggiExtensionRegister("GGIMesa", sizeof(struct mesa_ext), changed);
ggiMesaID = ggiExtensionRegister("GGIMesa",
sizeof(struct ggi_mesa_ext), changed);
if (ggiMesaID < 0)
{
@ -323,306 +368,6 @@ int ggiMesaInit()
return 0;
}
GGIMesaContext GGIMesaCreateContext(void)
{
GGIMesaContext ctx;
char *str;
GGIMESADPRINT_CORE("ggiMesaCreateContext() called\n");
if (ggiMesaInit() < 0) /* register extensions*/
{
return NULL;
}
ctx = (GGIMesaContext)calloc(1, sizeof(struct ggi_mesa_context));
if (!ctx)
return NULL;
ctx->gl_vis = (GLvisual *)calloc(1, sizeof(GLvisual));
if (!ctx->gl_vis)
return NULL;
ctx->viewport_init = GL_FALSE;
// ctx->gl_vis->DBflag = GL_FALSE;
ctx->gl_ctx = _mesa_create_context(ctx->gl_vis, NULL, (void *)ctx, GL_TRUE);
if (!ctx->gl_ctx)
return NULL;
_mesa_enable_sw_extensions(ctx->gl_ctx);
_swrast_CreateContext(ctx->gl_ctx);
_swsetup_CreateContext(ctx->gl_ctx);
_tnl_CreateContext(ctx->gl_ctx);
return ctx;
}
void GGIMesaDestroyContext(GGIMesaContext ctx)
{
GGIMESADPRINT_CORE("ggiMesaDestroyContext() called\n");
if (ctx)
{
_mesa_destroy_visual(ctx->gl_vis);
_mesa_destroy_context(ctx->gl_ctx);
_mesa_destroy_framebuffer(ctx->gl_buffer);
if (ctx == GGIMesa)
GGIMesa = NULL;
if (ctx->ggi_vis)
ggiExtensionDetach(ctx->ggi_vis, ggiMesaID);
ggiExtensionUnregister(ggiMesaID);
free(ctx);
}
}
int GGIMesaSetVisual(GGIMesaContext ctx, ggi_visual_t vis,
GLboolean rgb_flag, GLboolean db_flag)
{
struct ggi_mesa_info info;
int err;
uint16 r,g,b;
ggi_color pal[256];
int i;
void *func;
ggi_mode mode;
int num_buf;
GGIMESADPRINT_CORE("ggiMesaSetVisual() called\n");
if (!ctx) return -1;
if (!vis) return -1;
if (ctx->ggi_vis)
ggiExtensionDetach(ctx->ggi_vis, ggiMesaID);
ctx->ggi_vis=vis;
err = ggiExtensionAttach(vis, ggiMesaID);
if (err < 0)
return -1;
if (err == 0)
changed(vis, GGI_CHG_APILIST);
if (ctx->gl_vis)
_mesa_destroy_visual(ctx->gl_vis);
if (ctx->gl_buffer)
_mesa_destroy_framebuffer(ctx->gl_buffer);
info.rgb_flag = rgb_flag;
info.db_flag = db_flag;
err = gl_ggiInitInfo(ctx, &info);
if (err)
return -1;
gl_ggiSetupPointers(ctx->gl_ctx);
func = (void *)LIBGGI_MESAEXT(ctx->ggi_vis)->setup_driver;
if (!func)
{
GGIMESADPRINT_CORE("setup_driver==NULL!\n");
GGIMESADPRINT_CORE("Please check your config files!\n");
return -1;
}
err = LIBGGI_MESAEXT(ctx->ggi_vis)->setup_driver(ctx, &info);
if (err)
return -1;
ctx->gl_vis = _mesa_create_visual(info.rgb_flag,
info.db_flag,
GL_FALSE, /*stereo*/
info.red_bits, info.green_bits,
info.blue_bits, info.alpha_bits,
info.index_bits,
info.depth_bits,
info.stencil_bits,
info.accum_bits,
info.accum_bits,
info.accum_bits,
info.accum_bits,
1);
if (!ctx->gl_vis)
{
GGIMESADPRINT_CORE("Can't create gl_visual!\n");
return -1;
}
ctx->gl_buffer = _mesa_create_framebuffer(ctx->gl_vis,
// ctx->gl_vis->DepthBits > 0,
// ctx->gl_vis->StencilBits > 0,
// ctx->gl_vis->AccumRedBits > 0,
// ctx->gl_vis->AlphaBits > 0);
info.depth_bits > 0,
info.stencil_bits > 0,
info.accum_bits > 0,
info.alpha_bits > 0);
if (!ctx->gl_buffer)
{
GGIMESADPRINT_CORE("Can't create gl_buffer!\n");
return -1;
}
ggiGetMode(ctx->ggi_vis, &mode);
ctx->width = mode.visible.x;
ctx->height = mode.visible.y;
ctx->stride = mode.virt.x;
ctx->origin.x = 0;
ctx->origin.y = 0;
ctx->flip_y = ctx->origin.y + ctx->height - 1;
ctx->color = 0;
ctx->lfb[0] = ctx->lfb[1] = NULL;
num_buf = ggiDBGetNumBuffers(ctx->ggi_vis);
for (i = 0; i < num_buf; i++)
{
if (ggiDBGetBuffer(ctx->ggi_vis,i)->layout == blPixelLinearBuffer)
{
ctx->stride = ggiDBGetBuffer(ctx->ggi_vis, i)->buffer.plb.stride /
(ggiDBGetBuffer(ctx->ggi_vis, i)->buffer.plb.pixelformat->size / 8);
ctx->lfb[0] = ggiDBGetBuffer(ctx->ggi_vis, i)->write;
}
}
if (ctx->lfb[0] == NULL)
{
GGIMESADPRINT_CORE("No linear frame buffer!\n");
return -1;
}
/* FIXME: Use separate buffers */
ctx->lfb[1] = malloc(ctx->stride * ctx->height);
ctx->bufsize = (ctx->stride * ctx->height);
ctx->gl_ctx->Visual = *ctx->gl_vis;
ctx->gl_ctx->Pixel.ReadBuffer =
ctx->gl_ctx->Color.DrawBuffer = (db_flag) ? GL_BACK : GL_FRONT;
if (GGIMesa == ctx)
_mesa_make_current(ctx->gl_ctx, ctx->gl_buffer);
if (rgb_flag && mode.graphtype==GT_8BIT)
{
for (i = r = 0; r < 8; r++)
for (g = 0; g < 8; g++)
for (b = 0; b < 4; b++, i++)
{
pal[i].r = r << (GGI_COLOR_PRECISION - 3);
pal[i].g = g << (GGI_COLOR_PRECISION - 3);
pal[i].b = b << (GGI_COLOR_PRECISION - 2);
}
ggiSetPalette(ctx->ggi_vis, 0, 256, pal);
}
return 0;
}
void GGIMesaMakeCurrent(GGIMesaContext ctx)
{
GGIMESADPRINT_CORE("ggiMesaMakeCurrent(ctx = %p) called\n", ctx);
if (!ctx->ggi_vis)
return;
GGIMesa = ctx;
_mesa_make_current(ctx->gl_ctx, ctx->gl_buffer);
if (!ctx->viewport_init)
{
_mesa_set_viewport(ctx->gl_ctx, 0, 0, ctx->width, ctx->height);
ctx->viewport_init = GL_TRUE;
}
}
GGIMesaContext GGIMesaGetCurrentContext(void)
{
GGIMESADPRINT_CORE("ggiMesaGetCurrentContext() called\n");
return GGIMesa;
}
/*
* Swap front/back buffers for current context if double buffered.
*/
void GGIMesaSwapBuffers(void)
{
GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n");
_mesa_swapbuffers( GGIMesa->gl_ctx );
gl_ggiFlush(GGIMesa->gl_ctx);
// if (GGIMesa->gl_vis->DBflag)
// {
memcpy(GGIMesa->lfb[0], GGIMesa->lfb[1], GGIMesa->bufsize);
// }
}
static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state)
{
void *func;
GGIMESADPRINT_CORE("gl_ggiUpdateState() called\n");
/* Propogate statechange information to swrast and swrast_setup
* modules. The GGI driver has no internal GL-dependent state.
*/
_swrast_InvalidateState(ctx, new_state);
_swsetup_InvalidateState(ctx, new_state);
_tnl_InvalidateState(ctx, new_state);
func = (void *)CTX_OPMESA(ctx)->update_state;
if (!func) {
GGIMESADPRINT_CORE("update_state == NULL!\n");
GGIMESADPRINT_CORE("Please check your config files!\n");
ggiPanic("");
}
CTX_OPMESA(ctx)->update_state(ctx);
}
static int changed(ggi_visual_t vis, int whatchanged)
{
GGIMESADPRINT_CORE("changed() called\n");
switch (whatchanged)
{
case GGI_CHG_APILIST:
{
char api[256];
char args[256];
int i;
const char *fname;
ggi_dlhandle *lib;
for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++)
{
strcat(api, "-mesa");
fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL);
if (fname == NULL)
{
/* No special implementation for this sublib */
continue;
}
lib = ggiExtensionLoadDL(vis, fname, args, NULL, GGI_SYMNAME_PREFIX);
}
}
break;
}
return 0;
}
int ggiMesaExit(void)
{
int rc;
@ -630,7 +375,7 @@ int ggiMesaExit(void)
GGIMESADPRINT_CORE("ggiMesaExit() called\n");
if (!_ggimesaLibIsUp)
return -1;
return -1;
if (_ggimesaLibIsUp > 1)
{
@ -647,13 +392,6 @@ int ggiMesaExit(void)
return rc;
}
static int _ggi_error(void)
{
GGIMESADPRINT_CORE("_ggi_error() called\n");
return -1;
}
int ggiMesaAttach(ggi_visual_t vis)
{
int rc;
@ -663,10 +401,24 @@ int ggiMesaAttach(ggi_visual_t vis)
rc = ggiExtensionAttach(vis, ggiMesaID);
if (rc == 0)
{
int r, g, b, ci;
GLboolean rgb, db;
GLvisual *gl_visual;
GLframebuffer *gl_fb;
/* We are creating the primary instance */
memset(LIBGGI_MESAEXT(vis), 0, sizeof(mesaext));
memset(LIBGGI_MESAEXT(vis), 0, sizeof(struct ggi_mesa_ext));
LIBGGI_MESAEXT(vis)->update_state = (void *)_ggi_error;
LIBGGI_MESAEXT(vis)->setup_driver = (void *)_ggi_error;
/* Initialize default mesa visual */
get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci);
gl_visual = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
_mesa_initialize_visual(gl_visual,
rgb, db, 0 /* No stereo */,
r, g, b, 0 /* No alpha */, ci,
0 /* No depth */, 0 /* No stencil */,
0, 0, 0, 0 /* No accum */, 0);
/* Now fake an "API change" so the right libs get loaded */
changed(vis, GGI_CHG_APILIST);
@ -681,3 +433,230 @@ int ggiMesaDetach(ggi_visual_t vis)
return ggiExtensionDetach(vis, ggiMesaID);
}
int ggiMesaExtendVisual(ggi_visual_t vis, GLboolean alpha_flag,
GLboolean stereo_flag, GLint depth_size,
GLint stencil_size, GLint accum_red_size,
GLint accum_green_size, GLint accum_blue_size,
GLint accum_alpha_size, GLint num_samples)
{
GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
int r, g, b, ci;
GLboolean db, rgb;
get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci);
/* Initialize the visual with the provided information */
_mesa_initialize_visual(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual),
rgb, db, stereo_flag,
r, g, b, 0 /* FIXME */, ci,
depth_size, stencil_size,
accum_red_size, accum_green_size,
accum_blue_size, accum_alpha_size, 0);
/* Now fake an "API change" so the right libs get loaded. After all,
extending the visual by all these new buffers could be considered
a "mode change" which requires an "API change".
*/
changed(vis, GGI_CHG_APILIST);
return 0;
}
ggi_mesa_context_t ggiMesaCreateContext(ggi_visual_t vis)
{
ggi_mesa_context_t ctx;
int err;
ggi_color pal[256];
int i;
GGIMESADPRINT_CORE("ggiMesaCreateContext() called\n");
ctx = (ggi_mesa_context_t)malloc(sizeof(struct ggi_mesa_context));
if (!ctx)
return NULL;
ctx->ggi_visual = vis;
ctx->color = 0;
ctx->gl_ctx =
_mesa_create_context(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual),
NULL, (void *)ctx, GL_TRUE);
if (!ctx->gl_ctx)
goto free_context;
_mesa_enable_sw_extensions(ctx->gl_ctx);
_swrast_CreateContext(ctx->gl_ctx);
_ac_CreateContext(ctx->gl_ctx);
_tnl_CreateContext(ctx->gl_ctx);
_swsetup_CreateContext(ctx->gl_ctx);
gl_ggiSetupPointers(ctx->gl_ctx);
/* Make sure that an appropriate sublib has been loaded */
if (!LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver){
GGIMESADPRINT_CORE("setup_driver==NULL!\n");
GGIMESADPRINT_CORE("Please check your config files!\n");
goto free_context;
}
/* Set up the sublib driver */
err = LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver(ctx);
if (err){
GGIMESADPRINT_CORE("setup_driver failed (err = %d)", err);
goto free_gl_context;
}
_mesa_read_config_file(ctx->gl_ctx);
return ctx;
free_gl_context:
_mesa_destroy_context(ctx->gl_ctx);
free_context:
free(ctx);
return NULL;
}
void ggiMesaDestroyContext(ggi_mesa_context_t ctx)
{
GGIMESADPRINT_CORE("ggiMesaDestroyContext() called\n");
if(!ctx)
return;
_mesa_destroy_context(ctx->gl_ctx);
free(ctx);
}
void ggiMesaMakeCurrent(ggi_mesa_context_t ctx, ggi_visual_t vis)
{
GGIMESADPRINT_CORE("ggiMesaMakeCurrent(ctx = %p) called\n", ctx);
/* FIXME: clean up where are ggi_vis */
if (ctx->ggi_visual != vis) {
GGIMESADPRINT_CORE("Cannot migrate GL contexts\n");
return;
}
_mesa_make_current(ctx->gl_ctx, &LIBGGI_MESAEXT(vis)->mesa_buffer);
if (ctx->gl_ctx->Viewport.Width == 0)
{
_mesa_Viewport(0, 0,
LIBGGI_MODE(vis)->visible.x,
LIBGGI_MODE(vis)->visible.y);
ctx->gl_ctx->Scissor.Width = LIBGGI_MODE(vis)->visible.x;
ctx->gl_ctx->Scissor.Height = LIBGGI_MODE(vis)->visible.y;
}
}
/*
* Swap front/back buffers for current context if double buffered.
*/
void ggiMesaSwapBuffers(void)
{
GLcontext *ctx;
ggi_mesa_context_t ggi_ctx;
ctx = _mesa_get_current_context();
ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n");
_mesa_swapbuffers(ctx);
gl_ggiFlush(ctx);
ggiSetDisplayFrame(ggi_ctx->ggi_visual,
!ggiGetDisplayFrame(ggi_ctx->ggi_visual));
ggiSetWriteFrame(ggi_ctx->ggi_visual,
!ggiGetWriteFrame(ggi_ctx->ggi_visual));
ggiSetReadFrame(ggi_ctx->ggi_visual,
!ggiGetReadFrame(ggi_ctx->ggi_visual));
GGIMESADPRINT_CORE("swap disp: %d, write %d\n",
ggiGetDisplayFrame(ggi_ctx->ggi_visual),
ggiGetWriteFrame(ggi_ctx->ggi_visual));
}
static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state)
{
ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
GGIMESADPRINT_CORE("gl_ggiUpdateState() called\n");
/* Propogate statechange information to swrast and swrast_setup
* modules. The GGI driver has no internal GL-dependent state.
*/
_swrast_InvalidateState(ctx, new_state);
_swsetup_InvalidateState(ctx, new_state);
_tnl_InvalidateState(ctx, new_state);
if (!LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state) {
GGIMESADPRINT_CORE("update_state == NULL!\n");
GGIMESADPRINT_CORE("Please check your config files!\n");
ggiPanic("");
}
LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state(ggi_ctx);
}
static int changed(ggi_visual_t vis, int whatchanged)
{
GLcontext *ctx;
ctx = _mesa_get_current_context();
GGIMESADPRINT_CORE("changed() called\n");
switch (whatchanged)
{
case GGI_CHG_APILIST:
{
char api[256];
char args[256];
int i;
const char *fname;
ggi_dlhandle *lib;
GLvisual *gl_vis=&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
GLframebuffer *gl_fb = &(LIBGGI_MESAEXT(vis)->mesa_buffer);
/* Initialize the framebuffer to provide all necessary
buffers in software. The target libraries that are loaded
next are free to modify this according to their
capabilities.
*/
/* FIXME: if the target changes capabilities we'll leak
swrast's memory !!! Need to deallocate first */
_mesa_initialize_framebuffer(gl_fb, gl_vis,
gl_vis->depthBits > 0,
gl_vis->stencilBits > 0,
gl_vis->accumRedBits > 0,
gl_vis->alphaBits > 0);
for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++)
{
strcat(api, "-mesa");
fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL);
if (fname == NULL)
{
/* No special implementation for this sublib */
continue;
}
lib = ggiExtensionLoadDL(vis, fname, args, NULL,
GGI_SYMNAME_PREFIX);
}
/* The targets have cleared everything they can do from
the framebuffer structure so we provide the rest in sw
*/
_swrast_alloc_buffers(gl_fb);
break;
}
}
return 0;
}

View File

@ -45,50 +45,40 @@
#include <ggi/ggi.h>
#include "GL/ggimesa.h"
struct ggi_mesa_info;
/*
* GGIMesa visual configuration.
*
* This structure "derives" from Mesa's GLvisual and extends it by
* GGI's visual. Combination of these two structures is enough to fully
* describe the mode the application is currently running in. GGI
* visual provides information about color configuration and buffering
* method, GLvisual fills the rest.
*/
struct ggi_mesa_visual {
GLvisual gl_visual;
ggi_visual_t ggi_visual;
};
/*
* GGIMesa context.
*
* GGIMesa context expands the Mesa's context (it doesn't actualy derive
* from it, but this ability isn't needed, and it is best if GL context
* creation is left up to Mesa). It also contains a reference to the GGI
* visual it is attached to, which is very useful for all Mesa callbacks.
*/
struct ggi_mesa_context
{
GLcontext *gl_ctx;
GLvisual *gl_vis;
GLframebuffer *gl_buffer;
ggi_visual_t ggi_visual;
ggi_visual_t ggi_vis;
ggi_coord origin;
int flip_y;
int width, height, stride; /* Stride is in pixels */
ggi_pixel color; /* Current color or index*/
ggi_pixel clearcolor;
void *lfb[2]; /* Linear frame buffers */
int active_buffer;
int bufsize;
int viewport_init;
void *private;
};
struct ggi_mesa_info
{
GLboolean rgb_flag;
GLboolean db_flag;
GLboolean alpha_flag;
GLint index_bits;
GLint red_bits, green_bits, blue_bits, alpha_bits;
GLint depth_bits, stencil_bits, accum_bits;
};
extern GGIMesaContext GGIMesa; /* The current context */
#define SHIFT (GGI_COLOR_PRECISION - 8)
#define GGICTX ((GGIMesaContext)ctx->DriverCtx)
#define VIS (GGICTX->ggi_vis)
#define FLIP(y) (GGICTX->flip_y-(y))
#define LFB(type,x,y) ((type *)GGICTX->lfb[0] + (x) + (y) * GGICTX->stride)
#define CTX_OPMESA(ctx) \
((struct mesa_ext *)LIBGGI_EXT(((GGIMesaContext)ctx->DriverCtx)->ggi_vis, \
ggiMesaID))
#endif

View File

@ -11,14 +11,35 @@ extern ggi_extid ggiMesaID;
ggifunc_setmode GGIMesa_setmode;
ggifunc_getapi GGIMesa_getapi;
typedef struct mesa_ext
typedef struct ggi_mesa_ext
{
void (*update_state)(GLcontext *ctx);
int (*setup_driver)(GGIMesaContext ctx, struct ggi_mesa_info *info);
void *private;
} mesaext;
/*
* How mesa extends this visual; i.e., size of the depth buffer etc.
*
* By default (upon attaching) this structure is initialized to what
* libggi is guaranteed to handle without any help: single buffered
* visual without any ancilary buffers.
*/
struct ggi_mesa_visual mesa_visual;
#define LIBGGI_MESAEXT(vis) ((mesaext *)LIBGGI_EXT(vis,ggiMesaID))
/*
* Mesa framebuffer is a collection of all ancilary buffers required.
*
* This structure contains the ancilary buffers provided in in
* software. On each mode change it is loaded with the list of
* required buffers and the target is expected to clear the ones
* it can provide in hw. The remaining ones are then provided in sw.
*
*/
GLframebuffer mesa_buffer;
void (*update_state)(ggi_mesa_context_t ctx);
int (*setup_driver)(ggi_mesa_context_t ctx);
void *private;
} ggi_mesa_ext_t;
#define LIBGGI_MESAEXT(vis) ((ggi_mesa_ext_t *)LIBGGI_EXT(vis,ggiMesaID))
#define GGIMESA_PRIVATE(vis) ((LIBGGI_MESAEXT(vis)->private))
#endif /* _GGI_MISC_INT_H */