diff options
Diffstat (limited to 'xc/extras/Mesa/src')
26 files changed, 1302 insertions, 519 deletions
diff --git a/xc/extras/Mesa/src/FX/fxdd.c b/xc/extras/Mesa/src/FX/fxdd.c index e89545421..4f179a789 100644 --- a/xc/extras/Mesa/src/FX/fxdd.c +++ b/xc/extras/Mesa/src/FX/fxdd.c @@ -696,7 +696,7 @@ static const GLubyte *fxDDGetString(GLcontext *ctx, GLenum name) } } /* now make the GL_RENDERER string */ - sprintf(buffer, "Mesa DRI %s 20000415", hardware); + sprintf(buffer, "Mesa DRI %s 20000420", hardware); return buffer; } case GL_VENDOR: diff --git a/xc/extras/Mesa/src/FX/fxddspan.c b/xc/extras/Mesa/src/FX/fxddspan.c index 8256697c3..c7479ebb7 100644 --- a/xc/extras/Mesa/src/FX/fxddspan.c +++ b/xc/extras/Mesa/src/FX/fxddspan.c @@ -324,6 +324,7 @@ static void fxDDWriteMonoRGBASpan(const GLcontext *ctx, } +#if 0 static void fxDDReadRGBASpan(const GLcontext *ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4]) { @@ -350,6 +351,7 @@ static void fxDDReadRGBASpan(const GLcontext *ctx, rgba[i][ACOMP] = 255; } } +#endif /* diff --git a/xc/extras/Mesa/src/FX/fxddtex.c b/xc/extras/Mesa/src/FX/fxddtex.c index 374531292..01a67c49e 100644 --- a/xc/extras/Mesa/src/FX/fxddtex.c +++ b/xc/extras/Mesa/src/FX/fxddtex.c @@ -332,7 +332,7 @@ void fxDDTexDel(GLcontext *ctx, struct gl_texture_object *tObj) fprintf(stderr,"fxmesa: fxDDTexDel(%d,%x)\n",tObj->Name,(GLuint)ti); } - if(!ti) + if (!ti) return; fxTMFreeTexture(fxMesa,tObj); @@ -343,77 +343,105 @@ void fxDDTexDel(GLcontext *ctx, struct gl_texture_object *tObj) ctx->NewState|=NEW_TEXTURING; } -void fxDDTexPalette(GLcontext *ctx, struct gl_texture_object *tObj) + + +/* + * Convert gl_color_table table to Glide's format. + */ + +static void convertPalette(FxU32 data[256], const struct gl_color_table *table) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - int i; - FxU32 r,g,b,a; - tfxTexInfo *ti; + const GLubyte *tableUB = (const GLubyte *) table->Table; + GLint width = table->Size; + FxU32 r, g, b, a; + GLint i; - if(tObj) { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDTexPalette(%d,%x)\n",tObj->Name,(GLuint)tObj->DriverData); - } + ASSERT(table->TableType == GL_UNSIGNED_BYTE); - if(tObj->Palette.Format!=GL_RGBA) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: unsupported palette format in texpalette()\n"); -#endif - return; - } + switch (table->Format) { + case GL_INTENSITY: + for (i = 0; i < width; i++) { + r = tableUB[i]; + g = tableUB[i]; + b = tableUB[i]; + a = tableUB[i]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_LUMINANCE: + for (i = 0; i < width; i++) { + r = tableUB[i]; + g = tableUB[i]; + b = tableUB[i]; + a = 255; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_ALPHA: + for (i = 0; i < width; i++) { + r = g = b = 255; + a = tableUB[i]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_LUMINANCE_ALPHA: + for (i = 0; i < width; i++) { + r = g = b = tableUB[i*2+0]; + a = tableUB[i*2+1]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_RGB: + for (i = 0; i < width; i++) { + r = tableUB[i*3+0]; + g = tableUB[i*3+1]; + b = tableUB[i*3+2]; + a = 255; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + case GL_RGBA: + for (i = 0; i < width; i++) { + r = tableUB[i*4+0]; + g = tableUB[i*4+1]; + b = tableUB[i*4+2]; + a = tableUB[i*4+3]; + data[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + break; + } +} - if(tObj->Palette.Size>256) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: unsupported palette size in texpalette()\n"); -#endif - return; - } +void fxDDTexPalette(GLcontext *ctx, struct gl_texture_object *tObj) +{ + fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; + + if (tObj) { + /* per-texture palette */ + tfxTexInfo *ti; + if (MESA_VERBOSE&VERBOSE_DRIVER) { + fprintf(stderr,"fxmesa: fxDDTexPalette(%d,%x)\n", + tObj->Name,(GLuint)tObj->DriverData); + } if (!tObj->DriverData) tObj->DriverData=fxAllocTexObjData(fxMesa); - ti=fxTMGetTexInfo(tObj); - - for(i=0;i<tObj->Palette.Size;i++) { - r=tObj->Palette.Table[i*4]; - g=tObj->Palette.Table[i*4+1]; - b=tObj->Palette.Table[i*4+2]; - a=tObj->Palette.Table[i*4+3]; - ti->palette.data[i]=(a<<24)|(r<<16)|(g<<8)|b; - } - + convertPalette(ti->palette.data, &tObj->Palette); fxTexInvalidate(ctx,tObj); - } else { - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDTexPalette(global)\n"); - } - if(ctx->Texture.Palette.Format!=GL_RGBA) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: unsupported palette format in texpalette()\n"); -#endif - return; - } - - if(ctx->Texture.Palette.Size>256) { -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: unsupported palette size in texpalette()\n"); -#endif - return; - } - - for(i=0;i<ctx->Texture.Palette.Size;i++) { - r=ctx->Texture.Palette.Table[i*4]; - g=ctx->Texture.Palette.Table[i*4+1]; - b=ctx->Texture.Palette.Table[i*4+2]; - a=ctx->Texture.Palette.Table[i*4+3]; - fxMesa->glbPalette.data[i]=(a<<24)|(r<<16)|(g<<8)|b; + } + else { + /* global texture palette */ + if (MESA_VERBOSE&VERBOSE_DRIVER) { + fprintf(stderr,"fxmesa: fxDDTexPalette(global)\n"); } - + convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette); fxMesa->new_state|=FX_NEW_TEXTURING; ctx->Driver.RenderStart = fxSetupFXUnits; } } + void fxDDTexUseGlbPalette(GLcontext *ctx, GLboolean state) { fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; diff --git a/xc/extras/Mesa/src/FX/fxdrv.h b/xc/extras/Mesa/src/FX/fxdrv.h index e12a3244f..924b4a164 100644 --- a/xc/extras/Mesa/src/FX/fxdrv.h +++ b/xc/extras/Mesa/src/FX/fxdrv.h @@ -87,8 +87,8 @@ typedef struct tfxMesaContext *fxMesaContext; -#if defined(MESA_DEBUG) && 0 extern void fx_sanity_triangle( GrVertex *, GrVertex *, GrVertex * ); +#if defined(MESA_DEBUG) && 0 #define grDrawTriangle fx_sanity_triangle #endif @@ -187,9 +187,9 @@ typedef struct { } #if FX_USE_PARGB -#define GOURAUD2(v, c) { \ - GLubyte *col = c; \ - v->argb=MESACOLOR2PARGB(col); \ +#define GOURAUD2(v, c) { \ + GLubyte *col = c; \ + v->argb=MESACOLOR2PARGB(col); \ } #else #define GOURAUD2(v, c) { \ @@ -230,13 +230,13 @@ typedef struct { #define FX_UM_E0_MODULATE 0x00000002 #define FX_UM_E0_DECAL 0x00000004 #define FX_UM_E0_BLEND 0x00000008 -#define FX_UM_E0_ADD 0x00000010 +#define FX_UM_E0_ADD 0x00000010 #define FX_UM_E1_REPLACE 0x00000020 #define FX_UM_E1_MODULATE 0x00000040 #define FX_UM_E1_DECAL 0x00000080 #define FX_UM_E1_BLEND 0x00000100 -#define FX_UM_E1_ADD 0x00000200 +#define FX_UM_E1_ADD 0x00000200 #define FX_UM_E_ENVMODE 0x000003ff @@ -272,11 +272,9 @@ typedef struct MemRange_t { } MemRange; typedef struct { - GLsizei width, height; - GLint glideFormat; - - unsigned short *data; - GLboolean translated, used; + GLsizei width, height; /* image size */ + GrTextureFormat_t glideFormat; /* Glide image format */ + unsigned short *data; /* Glide-formated texture image */ } tfxMipMapLevel; typedef struct tfxTexInfo_t { @@ -534,6 +532,7 @@ typedef void (*tfxSetupFunc)(struct vertex_buffer *, GLuint, GLuint); extern GrHwConfiguration glbHWConfig; extern int glbCurrentBoard; +extern void fxPrintSetupFlags( const char *msg, GLuint flags ); extern void fxSetupFXUnits(GLcontext *); extern void fxSetupDDPointers(GLcontext *); extern void fxDDSetNearFar(GLcontext *, GLfloat, GLfloat); @@ -567,17 +566,29 @@ extern void fxUpdateDDSpanPointers(GLcontext *); extern void fxSetupDDSpanPointers(GLcontext *); extern void fxPrintTextureData(tfxTexInfo *ti); -extern void fxDDTexEnv(GLcontext *, GLenum, const GLfloat *); -extern void fxDDTexImg(GLcontext *, GLenum, struct gl_texture_object *, - GLint, GLint, const struct gl_texture_image *); +extern GLboolean fxDDTexImage2D(GLcontext *ctx, GLenum target, GLint level, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean *retainInternalCopy); +extern GLboolean fxDDTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage); +extern GLvoid *fxDDGetTexImage(GLcontext *ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum *formatOut, GLenum *typeOut, + GLboolean *freeImageOut ); +extern void fxDDTexEnv(GLcontext *, GLenum, GLenum, const GLfloat *); extern void fxDDTexParam(GLcontext *, GLenum, struct gl_texture_object *, GLenum, const GLfloat *); extern void fxDDTexBind(GLcontext *, GLenum, struct gl_texture_object *); extern void fxDDTexDel(GLcontext *, struct gl_texture_object *); extern void fxDDTexPalette(GLcontext *, struct gl_texture_object *); -extern void fxDDTexuseGlbPalette(GLcontext *, GLboolean); -extern void fxDDTexSubImg(GLcontext *, GLenum, struct gl_texture_object *, GLint, - GLint, GLint, GLint, GLint, GLint, const struct gl_texture_image *); extern void fxDDTexUseGlbPalette(GLcontext *, GLboolean); extern void fxDDEnable(GLcontext *, GLenum, GLboolean); @@ -619,6 +630,7 @@ extern void fxDDInitExtensions( GLcontext *ctx ); #define fxTMGetTexInfo(o) ((tfxTexInfo*)((o)->DriverData)) extern void fxTMInit(fxMesaContext ctx); extern void fxTMClose(fxMesaContext ctx); +extern void fxTMRestoreTextures_NoLock(fxMesaContext ctx); extern void fxTMMoveInTM(fxMesaContext, struct gl_texture_object *, GLint); extern void fxTMMoveOutTM(fxMesaContext, struct gl_texture_object *); #define fxTMMoveOutTM_NoLock fxTMMoveOutTM diff --git a/xc/extras/Mesa/src/FX/fxpipeline.c b/xc/extras/Mesa/src/FX/fxpipeline.c index fe4b76c68..cf4c9ebbc 100644 --- a/xc/extras/Mesa/src/FX/fxpipeline.c +++ b/xc/extras/Mesa/src/FX/fxpipeline.c @@ -104,7 +104,7 @@ static void fxDDRenderVB( struct vertex_buffer *VB ) GLcontext *ctx = VB->ctx; fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; - if ((fxMesa->render_index & ~FX_FLAT) || + if ((fxMesa->render_index != 0) || ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size>2) || ((ctx->Texture.ReallyEnabled & 0xf0) && VB->TexCoordPtr[1]->size>2)) gl_render_vb( VB ); @@ -281,12 +281,13 @@ void fxDDOptimizePrecalcPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) +/* unused? void fxDDOptimizeEltPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) { (void) ctx; (void) pipe; } - +*/ #else diff --git a/xc/extras/Mesa/src/FX/fxrender.c b/xc/extras/Mesa/src/FX/fxrender.c index 8ce4b0618..5935998f8 100644 --- a/xc/extras/Mesa/src/FX/fxrender.c +++ b/xc/extras/Mesa/src/FX/fxrender.c @@ -722,8 +722,8 @@ render_func **fxDDChooseRenderVBTables(GLcontext *ctx) return null_tables; switch (fxMesa->render_index) { - case FX_FLAT: - return fxDDRenderVBFlat_tables; +/* case FX_FLAT: */ +/* return fxDDRenderVBFlat_tables; */ case 0: return fxDDRenderVBSmooth_tables; default: diff --git a/xc/extras/Mesa/src/FX/fxsetup.c b/xc/extras/Mesa/src/FX/fxsetup.c index 8707aed1d..e8c75b7c4 100644 --- a/xc/extras/Mesa/src/FX/fxsetup.c +++ b/xc/extras/Mesa/src/FX/fxsetup.c @@ -69,7 +69,7 @@ static void fxSetupDepthTest(GLcontext *ctx); static void fxSetupScissor(GLcontext *ctx); static void fxSetupCull(GLcontext *ctx); static void gl_print_fx_state_flags( const char *msg, GLuint flags); -static GLboolean fxMultipassBlend(struct vertex_buffer *, GLuint); +/*static GLboolean fxMultipassBlend(struct vertex_buffer *, GLuint);*/ static GLboolean fxMultipassTexture( struct vertex_buffer *, GLuint ); static void fxTexValidate(GLcontext *ctx, struct gl_texture_object *tObj) @@ -183,7 +183,7 @@ static GLuint fxGetTexSetConfiguration(GLcontext *ctx, GLuint envmode=0; GLuint ifmt=0; - if((ctx->Light.ShadeModel==GL_SMOOTH) || + if((ctx->Light.ShadeModel==GL_SMOOTH) || 1 || (ctx->Point.SmoothFlag) || (ctx->Line.SmoothFlag) || (ctx->Polygon.SmoothFlag)) @@ -191,11 +191,13 @@ static GLuint fxGetTexSetConfiguration(GLcontext *ctx, else unitsmode|=FX_UM_ALPHA_CONSTANT; - if(ctx->Light.ShadeModel==GL_SMOOTH) + if(ctx->Light.ShadeModel==GL_SMOOTH || 1) unitsmode|=FX_UM_COLOR_ITERATED; else unitsmode|=FX_UM_COLOR_CONSTANT; + + /* OpenGL Feeds Texture 0 into Texture 1 Glide Feeds Texture 1 into Texture 0 @@ -476,8 +478,8 @@ static void fxSetupTextureSingleTMU_NoLock(GLcontext *ctx, GLuint textureset) else unitsmode=fxGetTexSetConfiguration(ctx,NULL,tObj); - if(fxMesa->lastUnitsMode==unitsmode) - return; +/* if(fxMesa->lastUnitsMode==unitsmode) */ +/* return; */ fxMesa->lastUnitsMode=unitsmode; @@ -555,9 +557,8 @@ static void fxSetupTextureSingleTMU_NoLock(GLcontext *ctx, GLuint textureset) FXTRUE); ctx->Driver.MultipassFunc = fxMultipassBlend; #else -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: GL_BLEND not yet supported\n"); -#endif + if (MESA_VERBOSE&VERBOSE_DRIVER) + fprintf(stderr,"fx Driver: GL_BLEND not yet supported\n"); #endif break; case GL_REPLACE: @@ -588,9 +589,9 @@ static void fxSetupTextureSingleTMU_NoLock(GLcontext *ctx, GLuint textureset) FXFALSE); break; default: -#ifndef FX_SILENT - fprintf(stderr,"fx Driver: %x Texture.EnvMode not yet supported\n",ctx->Texture.Unit[textureset].EnvMode); -#endif + if (MESA_VERBOSE&VERBOSE_DRIVER) + fprintf(stderr, "fx Driver: %x Texture.EnvMode not yet supported\n", + ctx->Texture.Unit[textureset].EnvMode); break; } @@ -764,8 +765,8 @@ static void fxSetupTextureDoubleTMU_NoLock(GLcontext *ctx) unitsmode=fxGetTexSetConfiguration(ctx,tObj0,tObj1); - if(fxMesa->lastUnitsMode==unitsmode) - return; +/* if(fxMesa->lastUnitsMode==unitsmode) */ +/* return; */ fxMesa->lastUnitsMode=unitsmode; @@ -1030,7 +1031,7 @@ static void fxSetupTextureNone_NoLock(GLcontext *ctx) fprintf(stderr,"fxmesa: fxSetupTextureNone(...)\n"); } - if((ctx->Light.ShadeModel==GL_SMOOTH) || + if((ctx->Light.ShadeModel==GL_SMOOTH) || 1 || (ctx->Point.SmoothFlag) || (ctx->Line.SmoothFlag) || (ctx->Polygon.SmoothFlag)) @@ -1038,7 +1039,7 @@ static void fxSetupTextureNone_NoLock(GLcontext *ctx) else locala=GR_COMBINE_LOCAL_CONSTANT; - if(ctx->Light.ShadeModel==GL_SMOOTH) + if(ctx->Light.ShadeModel==GL_SMOOTH || 1) localc=GR_COMBINE_LOCAL_ITERATED; else localc=GR_COMBINE_LOCAL_CONSTANT; @@ -1615,6 +1616,9 @@ void fxDDEnable(GLcontext *ctx, GLenum cap, GLboolean state) fxMesa->new_state |= FX_NEW_SCISSOR; ctx->Driver.RenderStart = fxSetupFXUnits; break; + case GL_SHARED_TEXTURE_PALETTE_EXT: + fxDDTexUseGlbPalette(ctx, state); + break; case GL_FOG: fxMesa->new_state |= FX_NEW_FOG; ctx->Driver.RenderStart = fxSetupFXUnits; @@ -1624,6 +1628,7 @@ void fxDDEnable(GLcontext *ctx, GLenum cap, GLboolean state) ctx->Driver.RenderStart = fxSetupFXUnits; break; case GL_LINE_SMOOTH: + case GL_LINE_STIPPLE: case GL_POINT_SMOOTH: case GL_POLYGON_SMOOTH: case GL_TEXTURE_2D: @@ -1631,7 +1636,7 @@ void fxDDEnable(GLcontext *ctx, GLenum cap, GLboolean state) ctx->Driver.RenderStart = fxSetupFXUnits; break; default: - ; /* XXX no-op??? */ + ; /* XXX no-op? */ } } @@ -1664,10 +1669,10 @@ static GLboolean fxMultipassBlend(struct vertex_buffer *VB, GLuint pass) fxDDDepthMask(ctx, FALSE); } /* Enable Cc*Ct mode */ - /* ??? Set the Constant Color ??? */ + /* XXX Set the Constant Color ? */ fxDDEnable(ctx, GL_BLEND, GL_TRUE); - fxDDBlendFunc(ctx, ???, ???); - fxSetupTextureSingleTMU(ctx, ???); + fxDDBlendFunc(ctx, XXX, XXX); + fxSetupTextureSingleTMU(ctx, XXX); fxSetupBlend(ctx); fxSetupDepthTest(ctx); break; @@ -1675,8 +1680,8 @@ static GLboolean fxMultipassBlend(struct vertex_buffer *VB, GLuint pass) case 2: /* Reset everything back to normal */ fxMesa->unitsState = fxMesa->restoreUnitsState; - fxMesa->setupdone &= ???; - fxSetupTextureSingleTMU(ctx, ???); + fxMesa->setupdone &= XXX; + fxSetupTextureSingleTMU(ctx, XXX); fxSetupBlend(ctx); fxSetupDepthTest(ctx); break; diff --git a/xc/extras/Mesa/src/FX/fxtritmp.h b/xc/extras/Mesa/src/FX/fxtritmp.h index 10bf5ca18..8e5da291f 100644 --- a/xc/extras/Mesa/src/FX/fxtritmp.h +++ b/xc/extras/Mesa/src/FX/fxtritmp.h @@ -66,7 +66,9 @@ static void TAG(fx_tri)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, GLuint GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit; GLubyte (*color)[4] = VB->Color[facing]->data; if (IND & FX_FLAT) { - FX_VB_COLOR(fxMesa, color[pv]); + GOURAUD2(v1,color[pv]); + GOURAUD2(v2,color[pv]); + GOURAUD2(v3,color[pv]); } else { GOURAUD2(v1,color[e1]); GOURAUD2(v2,color[e2]); @@ -103,7 +105,9 @@ static void TAG(fx_tri)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, GLuint } else if (IND & FX_FLAT) { GLubyte (*color)[4] = VB->Color[0]->data; - FX_VB_COLOR(fxMesa, color[pv]); + GOURAUD2(v1,color[pv]); + GOURAUD2(v2,color[pv]); + GOURAUD2(v3,color[pv]); } if (IND & FX_FRONT_BACK) { @@ -168,7 +172,10 @@ static void TAG(fx_quad)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, GLuint facing = (c<0.0) ^ ctx->Polygon.FrontBit; GLubyte (*color)[4] = VB->Color[facing]->data; if (IND & FX_FLAT) { - FX_VB_COLOR(fxMesa, color[pv]); + GOURAUD2(v1,color[pv]); + GOURAUD2(v2,color[pv]); + GOURAUD2(v3,color[pv]); + GOURAUD2(v4,color[pv]); } else { GOURAUD2(v1,color[e1]); GOURAUD2(v2,color[e2]); @@ -206,7 +213,10 @@ static void TAG(fx_quad)(GLcontext *ctx, GLuint e1, GLuint e2, GLuint e3, } else if (IND & FX_FLAT) { GLubyte (*color)[4] = VB->Color[0]->data; - FX_VB_COLOR(fxMesa, color[pv]); + GOURAUD2(v1,color[pv]); + GOURAUD2(v2,color[pv]); + GOURAUD2(v3,color[pv]); + GOURAUD2(v4,color[pv]); } if (IND & FX_FRONT_BACK) { diff --git a/xc/extras/Mesa/src/clip.c b/xc/extras/Mesa/src/clip.c index babf2ac2e..6cfd9e245 100644 --- a/xc/extras/Mesa/src/clip.c +++ b/xc/extras/Mesa/src/clip.c @@ -301,10 +301,12 @@ GLuint gl_userclip_point( GLcontext* ctx, const GLfloat v[] ) -#if defined(__i386__) +#if 0 #define NEGATIVE(x) ((*(int *)&x)<0) +#define DIFFERENT_SIGNS(a,b) ((a*b) < 0) #else #define NEGATIVE(x) (x < 0) +#define DIFFERENT_SIGNS(a,b) ((a*b) < 0) #endif diff --git a/xc/extras/Mesa/src/clip_funcs.h b/xc/extras/Mesa/src/clip_funcs.h index c348c0724..5f0591872 100644 --- a/xc/extras/Mesa/src/clip_funcs.h +++ b/xc/extras/Mesa/src/clip_funcs.h @@ -41,7 +41,6 @@ static GLuint TAG(viewclip_line)( struct vertex_buffer *VB, GLubyte mask ) { GLfloat (*coord)[4] = VB->ClipPtr->data; - GLfloat t, dx, dy, dz, dw, neww; GLuint ii = *i, jj = *j; GLuint vlist[2]; GLuint n; @@ -50,31 +49,29 @@ static GLuint TAG(viewclip_line)( struct vertex_buffer *VB, /* * We use 6 instances of this code to clip agains the 6 planes. - * For each plane, we define the OUTSIDE and COMPUTE_INTERSECTION - * macros apprpriately. */ -#define GENERAL_CLIP \ - if (mask & PLANE) { \ - GLuint flagI = INSIDE( ii ); \ - GLuint flagJ = INSIDE( jj ); \ - \ - if (!(flagI|flagJ)) \ - return 0; \ - \ - if (flagI ^ flagJ) { \ - COMPUTE_INTERSECTION( jj, ii, vb_free ); \ - interp( VB, vb_free, t, jj, ii); \ - \ - if (flagI) { \ - VB->ClipMask[jj] |= PLANE; \ - jj = vb_free; \ - } else { \ - VB->ClipMask[ii] |= PLANE; \ - ii = vb_free; \ - } \ - \ - VB->ClipMask[vb_free++] = 0; \ - } \ +#define GENERAL_CLIP \ + if (mask & PLANE) { \ + GLfloat dpI = CLIP_DOTPROD( ii ); \ + GLfloat dpJ = CLIP_DOTPROD( jj ); \ + \ + if (DIFFERENT_SIGNS(dpI, dpJ)) { \ + GLfloat t = dpI / (dpI - dpJ); \ + INTERP_SZ( t, VB->ClipPtr->data, vb_free, ii, jj, SIZE ); \ + interp( VB, vb_free, t, ii, jj); \ + \ + if (NEGATIVE(dpJ)) { \ + VB->ClipMask[jj] |= PLANE; \ + jj = vb_free; \ + VB->ClipMask[vb_free++] = 0; \ + } else { \ + VB->ClipMask[ii] |= PLANE; \ + ii = vb_free; \ + VB->ClipMask[vb_free++] = 0; \ + } \ + } \ + else if (NEGATIVE(dpI)) \ + return 0; \ } #include "general_clip.h" @@ -142,65 +139,78 @@ static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB, GLfloat (*coord)[4] = VB->ClipPtr->data; GLuint vlist2[VB_SIZE-VB_MAX]; GLuint *inlist = vlist, *outlist = vlist2; - GLdouble dx, dy, dz, dw, t = 0, neww; GLuint i; GLuint vb_free = VB->FirstFree; + GLubyte *clipmask = VB->ClipMask; clip_interp_func interp = VB->ctx->ClipInterpFunc; if (mask & CLIP_ALL_BITS) { #define GENERAL_CLIP \ if (mask & PLANE) { \ - GLuint prevj = inlist[n-1]; \ - GLuint prevflag = INSIDE(prevj); \ + GLuint idxPrev = inlist[0]; \ + GLfloat dpPrev = CLIP_DOTPROD(idxPrev); \ GLuint outcount = 0; \ - GLuint ef_state = 3; \ GLuint i; \ \ + inlist[n] = inlist[0]; \ + \ + for (i = 1; i < n+1; i++) { \ + GLuint idx = inlist[i]; \ + GLfloat dp = CLIP_DOTPROD(idx); \ + \ + clipmask[idxPrev] |= (PLANE&CLIP_ALL_BITS); \ \ - for (i = 0; i < n; i++) { \ - GLuint j = inlist[i]; \ - GLuint flag = INSIDE(j); \ + if (!NEGATIVE(dpPrev)) { \ + outlist[outcount++] = idxPrev; \ + clipmask[idxPrev] &= ~(PLANE&CLIP_ALL_BITS); \ + } \ \ - if (flag ^ prevflag) { \ - if (flag) { \ - /* Coming back in \ + if (DIFFERENT_SIGNS(dp, dpPrev)) { \ + if (NEGATIVE(dp)) { \ + /* Coming back in. Avoid division by zero as we know \ + * dp != dpPrev from DIFFERENT_SIGNS, above. \ */ \ - COMPUTE_INTERSECTION( j, prevj, vb_free ); \ - interp( VB, vb_free, t, j, prevj ); \ + GLfloat t = dp / (dp - dpPrev); \ + INTERP_SZ( t, VB->ClipPtr->data, vb_free, \ + idx, idxPrev, SIZE ); \ + interp( VB, vb_free, t, idx, idxPrev ); \ \ if (IND&CLIP_TAB_EDGEFLAG) \ VB->EdgeFlagPtr->data[vb_free] = \ - VB->EdgeFlagPtr->data[prevj] & ef_state; \ - \ - \ + VB->EdgeFlagPtr->data[idxPrev]; \ } else { \ /* Going out of bounds \ */ \ - COMPUTE_INTERSECTION( prevj, j, vb_free ); \ - interp( VB, vb_free, t, prevj, j ); \ + GLfloat t = dpPrev / (dpPrev - dp); \ + INTERP_SZ( t, VB->ClipPtr->data, vb_free, \ + idxPrev, idx, SIZE ); \ + interp( VB, vb_free, t, idxPrev, idx ); \ \ if (IND&CLIP_TAB_EDGEFLAG) \ - VB->EdgeFlagPtr->data[vb_free] = 1; \ + VB->EdgeFlagPtr->data[vb_free] = 3; \ + } \ + \ + if (IND&CLIP_TAB_EDGEFLAG) { \ + /* Demote trailing edge to internal edge. \ + */ \ + if (outcount && \ + (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2)) \ + VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1; \ } \ \ outlist[outcount++] = vb_free; \ - VB->ClipMask[vb_free++] = 0; \ + clipmask[vb_free++] = 0; \ } \ \ - if (flag) { \ - outlist[outcount++] = j; \ - } else { \ - VB->ClipMask[j] |= (PLANE&CLIP_ALL_BITS); /* don't setup */ \ - } \ - prevj = j; \ - prevflag = flag; \ - ef_state = 1; \ + idxPrev = idx; \ + dpPrev = dp; \ } \ \ if (outcount < 3) \ return 0; \ - else { \ + \ + { \ GLuint *tmp = inlist; \ inlist = outlist; \ outlist = tmp; \ @@ -340,49 +350,60 @@ static GLuint TAG(userclip_polygon)( struct vertex_buffer *VB, register float d = ctx->Transform.ClipUserPlane[p][3]; /* initialize prev to be last in the input list */ - GLuint prevj = inlist[n - 1]; + GLuint prevj = inlist[0]; GLfloat dpJ = d*W(prevj) + c*Z(prevj) + b*Y(prevj) + a*X(prevj); GLuint flagJ = INSIDE(dpJ); GLuint outcount = 0; GLuint curri; - for (curri=0;curri<n;curri++) { + inlist[n] = inlist[0]; + + + for (curri=1;curri<n+1;curri++) { GLuint currj = inlist[curri]; GLfloat dpI = d*W(currj) + c*Z(currj) + b*Y(currj) + a*X(currj); GLuint flagI = INSIDE(dpI); + if (flagJ) { + outlist[outcount++] = prevj; + } else { + VB->ClipMask[prevj] |= CLIP_USER_BIT; + } + if (flagI ^ flagJ) { GLfloat t; GLuint in; GLuint out; - + if (flagI) { out = prevj; - in = currj; - t = dpI/(dpI-dpJ); + in = currj; + t = dpI/(dpI-dpJ); - if (IND&CLIP_TAB_EDGEFLAG) - VB->EdgeFlagPtr->data[vb_free] = - VB->EdgeFlagPtr->data[prevj]; + if (IND&CLIP_TAB_EDGEFLAG) + VB->EdgeFlagPtr->data[vb_free] = + VB->EdgeFlagPtr->data[prevj]; } else { in = prevj; - out = currj; - t = dpJ/(dpJ-dpI); + out = currj; + t = dpJ/(dpJ-dpI); - if (IND&CLIP_TAB_EDGEFLAG) - VB->EdgeFlagPtr->data[vb_free] = 1; + if (IND&CLIP_TAB_EDGEFLAG) + VB->EdgeFlagPtr->data[vb_free] = 3; } + + if (IND&CLIP_TAB_EDGEFLAG) { + /* Demote trailing edge to internal edge. + */ + if (outcount && + (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2)) + VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1; + } INTERP_SZ( t, coord, vb_free, in, out, SIZE ); interp( VB, vb_free, t, in, out); outlist[outcount++] = vb_free; VB->ClipMask[vb_free++] = 0; - } - - if (flagI) { - outlist[outcount++] = currj; - } else { - VB->ClipMask[currj] |= CLIP_USER_BIT; } prevj = currj; diff --git a/xc/extras/Mesa/src/colortab.c b/xc/extras/Mesa/src/colortab.c index 82f8c782c..341ceaa25 100644 --- a/xc/extras/Mesa/src/colortab.c +++ b/xc/extras/Mesa/src/colortab.c @@ -32,6 +32,7 @@ #include "context.h" #include "image.h" #include "macros.h" +#include "mem.h" #include "mmath.h" #include "span.h" #include "teximage.h" @@ -39,6 +40,42 @@ +void +_mesa_init_colortable( struct gl_color_table *p ) +{ + p->TableType = GL_UNSIGNED_BYTE; + /* allocate a width=1 table by default */ + p->Table = CALLOC(4 * sizeof(GLubyte)); + if (p->Table) { + GLubyte *t = (GLubyte *) p->Table; + t[0] = 255; + t[1] = 255; + t[2] = 255; + t[3] = 255; + } + p->Size = 1; + p->IntFormat = GL_RGBA; + p->Format = GL_RGBA; + p->RedSize = 8; + p->GreenSize = 8; + p->BlueSize = 8; + p->AlphaSize = 8; + p->IntensitySize = 0; + p->LuminanceSize = 0; +} + + + +void +_mesa_free_colortable_data( struct gl_color_table *p ) +{ + if (p->Table) { + FREE(p->Table); + p->Table = NULL; + } +} + + /* * Examine table's format and set the component sizes accordingly. */ @@ -114,6 +151,8 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, GLint baseFormat; GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; + GLboolean floatTable = GL_FALSE; + GLint comps; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorTable"); @@ -150,6 +189,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, break; case GL_COLOR_TABLE: table = &ctx->ColorTable; + floatTable = GL_TRUE; rScale = ctx->Pixel.ColorTableScale[0]; gScale = ctx->Pixel.ColorTableScale[1]; bScale = ctx->Pixel.ColorTableScale[2]; @@ -165,6 +205,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, break; case GL_POST_CONVOLUTION_COLOR_TABLE: table = &ctx->PostConvolutionColorTable; + floatTable = GL_TRUE; rScale = ctx->Pixel.PCCTscale[0]; gScale = ctx->Pixel.PCCTscale[1]; bScale = ctx->Pixel.PCCTscale[2]; @@ -180,6 +221,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, break; case GL_POST_COLOR_MATRIX_COLOR_TABLE: table = &ctx->PostColorMatrixColorTable; + floatTable = GL_TRUE; rScale = ctx->Pixel.PCMCTscale[0]; gScale = ctx->Pixel.PCMCTscale[1]; bScale = ctx->Pixel.PCMCTscale[2]; @@ -211,9 +253,9 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, return; } - if (width < 1 || width > MAX_COLOR_TABLE_SIZE + if (width < 1 || width > ctx->Const.MaxColorTableSize || _mesa_bitcount(width) != 1) { - if (width > MAX_COLOR_TABLE_SIZE) + if (width > ctx->Const.MaxColorTableSize) gl_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); else gl_error(ctx, GL_INVALID_VALUE, "glColorTable(width)"); @@ -225,23 +267,101 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, return; } - table->Size = width; table->IntFormat = internalFormat; table->Format = (GLenum) baseFormat; set_component_sizes(table); + comps = _mesa_components_in_format(table->Format); + assert(comps > 0); /* error should have been caught sooner */ + if (!proxy) { - _mesa_unpack_ubyte_color_span(ctx, width, table->Format, - table->Table, /* dest */ - format, type, data, - &ctx->Unpack, GL_TRUE); - if (rScale != 1.0 || gScale != 1.0 || bScale != 1.0 || aScale != 1.0 || - rBias != 0.0 || gBias != 0.0 || bBias != 0.0 || aBias != 0.0) { - /* XXX apply scale and bias */ + /* free old table, if any */ + if (table->Table) { + FREE(table->Table); + } + if (floatTable) { + GLubyte tableUB[MAX_COLOR_TABLE_SIZE * 4]; + GLfloat *tableF; + GLuint i; + + _mesa_unpack_ubyte_color_span(ctx, width, table->Format, + tableUB, /* dest */ + format, type, data, + &ctx->Unpack, GL_TRUE); + + table->TableType = GL_FLOAT; + table->Table = MALLOC(comps * width * sizeof(GLfloat)); + if (!table->Table) { + gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); + return; + } + /* Apply scale and bias and convert GLubyte values to GLfloats + * in [0, 1]. Store results in the tableF[]. + */ + rScale /= 255.0; + gScale /= 255.0; + bScale /= 255.0; + aScale /= 255.0; + tableF = (GLfloat *) table->Table; + + switch (table->Format) { + case GL_INTENSITY: + for (i = 0; i < width; i++) { + tableF[i] = tableUB[i] * rScale + rBias; + } + break; + case GL_LUMINANCE: + for (i = 0; i < width; i++) { + tableF[i] = tableUB[i] * rScale + rBias; + } + break; + case GL_ALPHA: + for (i = 0; i < width; i++) { + tableF[i] = tableUB[i] * aScale + aBias; + } + break; + case GL_LUMINANCE_ALPHA: + for (i = 0; i < width; i++) { + tableF[i*2+0] = tableUB[i*2+0] * rScale + rBias; + tableF[i*2+1] = tableUB[i*2+1] * aScale + aBias; + } + break; + case GL_RGB: + for (i = 0; i < width; i++) { + tableF[i*3+0] = tableUB[i*3+0] * rScale + rBias; + tableF[i*3+1] = tableUB[i*3+1] * gScale + gBias; + tableF[i*3+2] = tableUB[i*3+2] * bScale + bBias; + } + break; + case GL_RGBA: + for (i = 0; i < width; i++) { + tableF[i*4+0] = tableUB[i*4+0] * rScale + rBias; + tableF[i*4+1] = tableUB[i*4+1] * gScale + gBias; + tableF[i*4+2] = tableUB[i*4+2] * bScale + bBias; + tableF[i*4+3] = tableUB[i*4+3] * aScale + aBias; + } + break; + default: + gl_problem(ctx, "Bad format in _mesa_ColorTable"); + return; + } } - } + else { + /* store GLubyte table */ + table->TableType = GL_UNSIGNED_BYTE; + table->Table = MALLOC(comps * width * sizeof(GLubyte)); + if (!table->Table) { + gl_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); + return; + } + _mesa_unpack_ubyte_color_span(ctx, width, table->Format, + table->Table, /* dest */ + format, type, data, + &ctx->Unpack, GL_TRUE); + } /* floatTable */ + } /* proxy */ if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { /* texture object palette, texObj==NULL means the shared palette */ @@ -249,7 +369,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat, (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); } } - } @@ -264,7 +383,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, struct gl_texture_object *texObj = NULL; struct gl_color_table *table = NULL; GLint comps; - GLubyte *dest; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorSubTable"); @@ -318,10 +436,22 @@ _mesa_ColorSubTable( GLenum target, GLsizei start, return; } - dest = table->Table + start * comps * sizeof(GLubyte); - _mesa_unpack_ubyte_color_span(ctx, count, table->Format, dest, - format, type, data, - &ctx->Unpack, GL_TRUE); + if (!table->Table) { + gl_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable"); + return; + } + + if (table->TableType == GL_UNSIGNED_BYTE) { + GLubyte *dest = (GLubyte *) table->Table + start * comps * sizeof(GLubyte); + _mesa_unpack_ubyte_color_span(ctx, count, table->Format, dest, + format, type, data, &ctx->Unpack, GL_TRUE); + } + else { + GLfloat *dest = (GLfloat *) table->Table + start * comps * sizeof(GLfloat); + ASSERT(table->TableType == GL_FLOAT); + _mesa_unpack_float_color_span(ctx, count, table->Format, dest, + format, type, data, &ctx->Unpack, GL_TRUE); + } if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { /* per-texture object palette */ @@ -433,51 +563,123 @@ _mesa_GetColorTable( GLenum target, GLenum format, switch (table->Format) { case GL_ALPHA: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = 0; - rgba[i][GCOMP] = 0; - rgba[i][BCOMP] = 0; - rgba[i][ACOMP] = table->Table[i]; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = 0; + rgba[i][GCOMP] = 0; + rgba[i][BCOMP] = 0; + rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F); + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = 0; + rgba[i][GCOMP] = 0; + rgba[i][BCOMP] = 0; + rgba[i][ACOMP] = tableUB[i]; + } } break; case GL_LUMINANCE: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = table->Table[i]; - rgba[i][GCOMP] = table->Table[i]; - rgba[i][BCOMP] = table->Table[i]; - rgba[i][ACOMP] = 255; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][ACOMP] = 255; + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = tableUB[i]; + rgba[i][GCOMP] = tableUB[i]; + rgba[i][BCOMP] = tableUB[i]; + rgba[i][ACOMP] = 255; + } } break; case GL_LUMINANCE_ALPHA: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = table->Table[i*2+0]; - rgba[i][GCOMP] = table->Table[i*2+0]; - rgba[i][BCOMP] = table->Table[i*2+0]; - rgba[i][ACOMP] = table->Table[i*2+1]; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = (GLint) (tableF[i*2+0] * 255.0F); + rgba[i][GCOMP] = (GLint) (tableF[i*2+0] * 255.0F); + rgba[i][BCOMP] = (GLint) (tableF[i*2+0] * 255.0F); + rgba[i][ACOMP] = (GLint) (tableF[i*2+1] * 255.0F); + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = tableUB[i*2+0]; + rgba[i][GCOMP] = tableUB[i*2+0]; + rgba[i][BCOMP] = tableUB[i*2+0]; + rgba[i][ACOMP] = tableUB[i*2+1]; + } } break; case GL_INTENSITY: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = table->Table[i]; - rgba[i][GCOMP] = table->Table[i]; - rgba[i][BCOMP] = table->Table[i]; - rgba[i][ACOMP] = 255; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][GCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][BCOMP] = (GLint) (tableF[i] * 255.0F); + rgba[i][ACOMP] = (GLint) (tableF[i] * 255.0F); + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = tableUB[i]; + rgba[i][GCOMP] = tableUB[i]; + rgba[i][BCOMP] = tableUB[i]; + rgba[i][ACOMP] = tableUB[i]; + } } break; case GL_RGB: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = table->Table[i*3+0]; - rgba[i][GCOMP] = table->Table[i*3+1]; - rgba[i][BCOMP] = table->Table[i*3+2]; - rgba[i][ACOMP] = 255; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = (GLint) (tableF[i*3+0] * 255.0F); + rgba[i][GCOMP] = (GLint) (tableF[i*3+1] * 255.0F); + rgba[i][BCOMP] = (GLint) (tableF[i*3+2] * 255.0F); + rgba[i][ACOMP] = 255; + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = tableUB[i*3+0]; + rgba[i][GCOMP] = tableUB[i*3+1]; + rgba[i][BCOMP] = tableUB[i*3+2]; + rgba[i][ACOMP] = 255; + } } break; case GL_RGBA: - for (i = 0; i < table->Size; i++) { - rgba[i][RCOMP] = table->Table[i*4+0]; - rgba[i][GCOMP] = table->Table[i*4+1]; - rgba[i][BCOMP] = table->Table[i*4+2]; - rgba[i][ACOMP] = table->Table[i*4+3]; + if (table->TableType == GL_FLOAT) { + const GLfloat *tableF = (const GLfloat *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = (GLint) (tableF[i*4+0] * 255.0F); + rgba[i][GCOMP] = (GLint) (tableF[i*4+1] * 255.0F); + rgba[i][BCOMP] = (GLint) (tableF[i*4+2] * 255.0F); + rgba[i][ACOMP] = (GLint) (tableF[i*4+3] * 255.0F); + } + } + else { + const GLubyte *tableUB = (const GLubyte *) table->Table; + for (i = 0; i < table->Size; i++) { + rgba[i][RCOMP] = tableUB[i*4+0]; + rgba[i][GCOMP] = tableUB[i*4+1]; + rgba[i][BCOMP] = tableUB[i*4+2]; + rgba[i][ACOMP] = tableUB[i*4+3]; + } } break; default: diff --git a/xc/extras/Mesa/src/colortab.h b/xc/extras/Mesa/src/colortab.h index 781ee1151..6a3f0cabe 100644 --- a/xc/extras/Mesa/src/colortab.h +++ b/xc/extras/Mesa/src/colortab.h @@ -32,6 +32,13 @@ extern void +_mesa_init_colortable( struct gl_color_table *p ); + +extern void +_mesa_free_colortable_data( struct gl_color_table *p ); + + +extern void _mesa_ColorTable( GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table ); diff --git a/xc/extras/Mesa/src/context.c b/xc/extras/Mesa/src/context.c index ec6e2b6d5..f72b0caa0 100644 --- a/xc/extras/Mesa/src/context.c +++ b/xc/extras/Mesa/src/context.c @@ -31,6 +31,7 @@ #include "accum.h" #include "alphabuf.h" #include "clip.h" +#include "colortab.h" #include "context.h" #include "cva.h" #include "depth.h" @@ -777,24 +778,6 @@ static void init_2d_map( struct gl_2d_map *map, int n, const float *initial ) } -static void init_color_table( struct gl_color_table *p ) -{ - p->Table[0] = 255; - p->Table[1] = 255; - p->Table[2] = 255; - p->Table[3] = 255; - p->Size = 1; - p->IntFormat = GL_RGBA; - p->Format = GL_RGBA; - p->RedSize = 8; - p->GreenSize = 8; - p->BlueSize = 8; - p->AlphaSize = 8; - p->IntensitySize = 0; - p->LuminanceSize = 0; -} - - /* * Initialize the attribute groups in a GLcontext. */ @@ -821,6 +804,7 @@ static void init_attrib_groups( GLcontext *ctx ) ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH; ctx->Const.LineWidthGranularity = LINE_WIDTH_GRANULARITY; ctx->Const.NumAuxBuffers = NUM_AUX_BUFFERS; + ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE; /* Modelview matrix */ gl_matrix_ctr( &ctx->ModelView ); @@ -1206,7 +1190,7 @@ static void init_attrib_groups( GLcontext *ctx ) ctx->Texture.Enabled = 0; for (i=0; i<MAX_TEXTURE_UNITS; i++) init_texture_unit( ctx, i ); - init_color_table(&ctx->Texture.Palette); + _mesa_init_colortable(&ctx->Texture.Palette); /* Transformation group */ ctx->Transform.MatrixMode = GL_MODELVIEW; @@ -1324,12 +1308,12 @@ static void init_attrib_groups( GLcontext *ctx ) ctx->CurrentPos = 0; /* Color tables */ - init_color_table(&ctx->ColorTable); - init_color_table(&ctx->ProxyColorTable); - init_color_table(&ctx->PostConvolutionColorTable); - init_color_table(&ctx->ProxyPostConvolutionColorTable); - init_color_table(&ctx->PostColorMatrixColorTable); - init_color_table(&ctx->ProxyPostColorMatrixColorTable); + _mesa_init_colortable(&ctx->ColorTable); + _mesa_init_colortable(&ctx->ProxyColorTable); + _mesa_init_colortable(&ctx->PostConvolutionColorTable); + _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable); + _mesa_init_colortable(&ctx->PostColorMatrixColorTable); + _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable); /* Miscellaneous */ ctx->NewState = NEW_ALL; @@ -1597,7 +1581,7 @@ void gl_free_context_data( GLcontext *ctx ) FREE( ctx->PB ); - if(ctx->input != ctx->VB->IM) + if (ctx->input != ctx->VB->IM) gl_immediate_free( ctx->input ); gl_vb_free( ctx->VB ); @@ -1660,6 +1644,11 @@ void gl_free_context_data( GLcontext *ctx ) if (ctx->EvalMap.Map2Texture4.Points) FREE( ctx->EvalMap.Map2Texture4.Points ); + _mesa_free_colortable_data( &ctx->ColorTable ); + _mesa_free_colortable_data( &ctx->PostConvolutionColorTable ); + _mesa_free_colortable_data( &ctx->PostColorMatrixColorTable ); + _mesa_free_colortable_data( &ctx->Texture.Palette ); + /* Free cache of immediate buffers. */ while (ctx->nr_im_queued-- > 0) { struct immediate * next = ctx->freed_im_queue->next; diff --git a/xc/extras/Mesa/src/copypix.c b/xc/extras/Mesa/src/copypix.c index 02b7e4381..17175644b 100644 --- a/xc/extras/Mesa/src/copypix.c +++ b/xc/extras/Mesa/src/copypix.c @@ -163,7 +163,9 @@ static void copy_rgba_pixels( GLcontext *ctx, ctx->Pixel.MapColorFlag || ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm || - ctx->Pixel.ColorTableEnabled; + ctx->Pixel.ColorTableEnabled || + ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.MinMaxEnabled; for (j = 0; j < height; j++, sy += stepy, dy += stepy) { if (overlapping) { @@ -216,14 +218,18 @@ static void copy_rgba_pixels( GLcontext *ctx, if (ctx->Pixel.MapColorFlag) { _mesa_map_rgba(ctx, width, rgbaFloat); } + /* GL_COLOR_TABLE lookup */ + if (ctx->Pixel.ColorTableEnabled) { + _mesa_lookup_rgba(&ctx->ColorTable, width, rgbaFloat); + } /* color matrix */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { _mesa_transform_rgba(ctx, width, rgbaFloat); } - /* GL_SGI_color_table lookup */ - if (ctx->Pixel.ColorTableEnabled) { - _mesa_lookup_rgba(&ctx->ColorTable, width, rgbaFloat); + /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ + if (ctx->Pixel.PostColorMatrixColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, width, rgbaFloat); } /* clamp to [0,1] and convert float back to ubyte */ for (k = 0; k < width; k++) { diff --git a/xc/extras/Mesa/src/drawpix.c b/xc/extras/Mesa/src/drawpix.c index 23c2394f1..362e30b9c 100644 --- a/xc/extras/Mesa/src/drawpix.c +++ b/xc/extras/Mesa/src/drawpix.c @@ -120,6 +120,8 @@ simple_DrawPixels( GLcontext *ctx, GLint x, GLint y, && !ctx->Pixel.ScaleOrBiasRGBApcm && ctx->ColorMatrix.type == MATRIX_IDENTITY && !ctx->Pixel.ColorTableEnabled + && !ctx->Pixel.PostColorMatrixColorTableEnabled + && !ctx->Pixel.MinMaxEnabled && ctx->Pixel.IndexShift==0 && ctx->Pixel.IndexOffset==0 && ctx->Pixel.MapColorFlag==0 && ctx->Texture.ReallyEnabled == 0 @@ -649,6 +651,8 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, pixels, width, height, format, type, 0, row, 0); _mesa_unpack_ubyte_color_span(ctx, width, GL_RGBA, (void*) rgba, format, type, source, unpack, GL_TRUE); + if (ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) + continue; if (ctx->Texture.ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH]; diff --git a/xc/extras/Mesa/src/fog_tmp.h b/xc/extras/Mesa/src/fog_tmp.h index e288a6efa..5096b0a99 100644 --- a/xc/extras/Mesa/src/fog_tmp.h +++ b/xc/extras/Mesa/src/fog_tmp.h @@ -23,6 +23,177 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/* For 3.2: Add a helper function for drivers to do fog coordinate + * calculation. Not called from standard pipelines. + */ +static void TAG(make_fog_coord)( struct vertex_buffer *VB, + const GLvector4f *eye, + GLubyte flag) +{ + const GLcontext *ctx = VB->ctx; + GLfloat end = ctx->Fog.End; + GLubyte *cullmask = VB->CullMask + VB->Start; + GLfloat *v = eye->start; + GLuint stride = eye->stride; + GLuint n = VB->Count - VB->Start; + GLubyte (*out)[4]; + GLfloat d; + GLuint i; + + (void) cullmask; + (void) flag; + + /* Use specular alpha (front side) as fog coordinate. + */ + out = VB->Spec[0] + VB->Start; + + if (VB->EyePtr->size > 2) { + switch (ctx->Fog.Mode) { + case GL_LINEAR: + d = 1.0F / (ctx->Fog.End - ctx->Fog.Start); + for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) { + CULLCHECK { + GLfloat f = (end - ABSF(v[2])) * d; + FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f); + } + } + break; + case GL_EXP: + d = -ctx->Fog.Density; + for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride)) { + CULLCHECK { + GLfloat f = exp( d*ABSF(v[2]) ); /* already clamped */ + FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f); + } + } + break; + case GL_EXP2: + d = -(ctx->Fog.Density*ctx->Fog.Density); + for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) { + CULLCHECK { + GLfloat z = v[2]; + GLfloat f = exp( d*z*z ); /* already clamped */ + FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f); + } + } + break; + default: + gl_problem(ctx, "Bad fog mode in make_fog_coord"); + return; + } + } + else + { + GLubyte r = 255; + + if (ctx->Fog.Mode == GL_LINEAR) { + GLfloat f = 1.0 - ctx->Fog.End / (ctx->Fog.End - ctx->Fog.Start); + CLAMP_FLOAT_COLOR( f ); + FLOAT_COLOR_TO_UBYTE_COLOR(r, f); + } + + for (i = 0 ; i < n ; i++) + out[i][3] = r; + } +} + + + + + +#if 0 +/* TODO : use fog coordinates as intermediate step in all fog + * calculations. + */ + +static void TAG(fog_rgba_vertices)( struct vertex_buffer *VB, + GLuint side, + GLubyte flag) +{ + const GLcontext *ctx = VB->ctx; + const GLubyte rFog = ctx->Fog.ByteColor[0]; + const GLubyte gFog = ctx->Fog.ByteColor[1]; + const GLubyte bFog = ctx->Fog.ByteColor[2]; + GLfloat end = ctx->Fog.End; + GLubyte *cullmask = VB->CullMask + VB->Start; + GLubyte (*fcoord)[4] = VB->SpecPtr[0]->start; + GLuint stride = VB->SpecPtr[0]->stride; + GLuint n = VB->Count - VB->Start; + GLubyte *in; + GLuint in_stride; + GLubyte (*out)[4]; + GLfloat d,t; + GLuint i; + + (void) cullmask; + (void) flag; + + /* Get correct source and destination for fogged colors. + */ + in_stride = VB->Color[side]->stride; + in = VB->Color[side]->start; + VB->Color[side] = VB->FoggedColor[side]; + VB->ColorPtr = VB->Color[0]; + out = (GLubyte (*)[4])VB->Color[side]->start; + + FLOAT_COLOR_TO_UBYTE_COLOR( rFog, ctx->Fog.Color[0] ); + + for ( i = 0 ; i < n ; i++, STRIDE_F(spec, sp_stride), in += in_stride) { + CULLCHECK { + GLint fc = (GLint) spec[3], ifc = 255 - fc; + + out[i][0] = (fc * in[0] + ifc * rFog) >> 8; + out[i][1] = (fc * in[1] + ifc * gFog) >> 8; + out[i][2] = (fc * in[2] + ifc * bFog) >> 8; + } + } +} + + + +static void TAG(fog_ci_vertices)( struct vertex_buffer *VB, + GLuint side, + GLubyte flag ) +{ + GLcontext *ctx = VB->ctx; + + GLubyte *cullmask = VB->CullMask + VB->Start; + + GLfloat *v = VB->EyePtr->start; + GLuint stride = VB->EyePtr->stride; + GLuint vertex_size = VB->EyePtr->size; + GLuint n = VB->EyePtr->count; + + GLuint *in; + GLuint in_stride; + GLuint *out; + GLuint i; + + (void) flag; + (void) cullmask; + + + in = VB->Index[side]->start; + in_stride = VB->Index[side]->stride; + VB->IndexPtr = VB->FoggedIndex[side]; + out = VB->IndexPtr->start; + + + /* NOTE: the use of casts generates better/faster code for MIPS */ + for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride)) + CULLCHECK { + GLfloat f = (fogend - ABSF(v[2])) * d; + f = CLAMP( f, 0.0, 1.0 ); + *out = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex); + } +} + +#endif + + + + + static void TAG(fog_rgba_vertices)( struct vertex_buffer *VB, @@ -254,6 +425,7 @@ static void TAG(init_fog_tab)(void) { fog_ci_tab[IDX] = TAG(fog_ci_vertices); fog_rgba_tab[IDX] = TAG(fog_rgba_vertices); + make_fog_coord_tab[IDX] = TAG(make_fog_coord); } #undef TAG diff --git a/xc/extras/Mesa/src/general_clip.h b/xc/extras/Mesa/src/general_clip.h index c49ec3e57..c8bc8890a 100644 --- a/xc/extras/Mesa/src/general_clip.h +++ b/xc/extras/Mesa/src/general_clip.h @@ -28,170 +28,56 @@ */ -/* - * NOTE: The tests such as this: X(in) - W(in) == dw - dx - * were added to stop a clipping problem found in Unreal Tournament. - * The patch was contributed by Andreas Ehliar <ehliar@lysator.liu.se>. - * There's some concern that this just fixes a problem which occurs - * earlier in transformation. Well, until that (unknown) problem is - * fixed, this will have to do. - */ - - - -/* - * Clip against +X - * - * The if conditions are known at compile time. - */ -#define PLANE (CLIP_RIGHT_BIT) -#define INSIDE(K) (X(K) <= W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dx = X(out) - X(in); \ - dw = W(out) - W(in); \ - if (X(in) - W(in) == dw - dx) \ - t = 1.0F; \ - else \ - t = (X(in) - W(in)) / (dw - dx); \ - neww = W(in) + t * dw; \ - X(new) = neww; \ - Y(new) = Y(in) + t * (Y(out) - Y(in)); \ - if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_RIGHT_BIT +#define CLIP_DOTPROD(K) (- X(K) + W(K)) GENERAL_CLIP -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION -/* - * Clip against -X - */ -#define PLANE (CLIP_LEFT_BIT) -#define INSIDE(K) (X(K) >= -W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dx = X(out) - X(in); \ - dw = W(out) - W(in); \ - if (X(in) + W(in) == dw + dx) \ - t = 1.0F; \ - else \ - t = -(X(in) + W(in)) / (dw + dx); \ - neww = W(in) + t * dw; \ - X(new) = -neww; \ - Y(new) = Y(in) + t * (Y(out) - Y(in)); \ - if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_LEFT_BIT +#define CLIP_DOTPROD(K) (X(K) + W(K)) GENERAL_CLIP -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION - -/* - * Clip against +Y - */ -#define PLANE (CLIP_TOP_BIT) -#define INSIDE(K) (Y(K) <= W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dy = Y(out) - Y(in); \ - dw = W(out) - W(in); \ - if (Y(in) - W(in) == dw - dy) \ - t = 1.0F; \ - else \ - t = (Y(in) - W(in)) / (dw - dy); \ - neww = W(in) + t * dw; \ - X(new) = X(in) + t * (X(out) - X(in)); \ - Y(new) = neww; \ - if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_TOP_BIT +#define CLIP_DOTPROD(K) (- Y(K) + W(K)) GENERAL_CLIP -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION - -/* - * Clip against -Y - */ -#define PLANE (CLIP_BOTTOM_BIT) -#define INSIDE(K) (Y(K) >= -W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dy = Y(out) - Y(in); \ - dw = W(out) - W(in); \ - if (Y(in) + W(in) == dw + dy) \ - t = 1.0F; \ - else \ - t = -(Y(in) + W(in)) / (dw + dy); \ - neww = W(in) + t * dw; \ - X(new) = X(in) + t * (X(out) - X(in)); \ - Y(new) = -neww; \ - if (SIZE>=3) coord[new][2] = Z(in) + t * (Z(out) - Z(in)); \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_BOTTOM_BIT +#define CLIP_DOTPROD(K) (Y(K) + W(K)) GENERAL_CLIP -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION - - -/* - * Clip against +Z - */ -#define PLANE (CLIP_FAR_BIT) -#define INSIDE(K) (Z(K) <= W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dz = Z(out) - Z(in); \ - dw = W(out) - W(in); \ - if (Z(in) - W(in) == dw - dx) \ - t = 1.0F; \ - else \ - t = (Z(in) - W(in)) / (dw - dz); \ - neww = W(in) + t * dw; \ - X(new) = X(in) + t * (X(out) - X(in)); \ - Y(new) = Y(in) + t * (Y(out) - Y(in)); \ - coord[new][2] = neww; \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_FAR_BIT +#define CLIP_DOTPROD(K) (- Z(K) + W(K)) if (SIZE >= 3) { GENERAL_CLIP } -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION - -/* - * Clip against -Z - */ -#define PLANE (CLIP_NEAR_BIT) -#define INSIDE(K) (Z(K) >= -W(K)) -#define COMPUTE_INTERSECTION( in, out, new ) \ - dz = Z(out) - Z(in); \ - dw = W(out) - W(in); \ - if (Z(in) + W(in) == dw + dz) \ - t = 1.0F; \ - else \ - t = -(Z(in) + W(in)) / (dw + dz); \ - neww = W(in) + t * dw; \ - X(new) = X(in) + t * (X(out) - X(in)); \ - Y(new) = Y(in) + t * (Y(out) - Y(in)); \ - coord[new][2] = -neww; \ - if (SIZE==4) coord[new][3] = neww; +#define PLANE CLIP_NEAR_BIT +#define CLIP_DOTPROD(K) (Z(K) + W(K)) if (SIZE >=3 ) { GENERAL_CLIP } -#undef INSIDE +#undef CLIP_DOTPROD #undef PLANE -#undef COMPUTE_INTERSECTION #undef GENERAL_CLIP diff --git a/xc/extras/Mesa/src/image.c b/xc/extras/Mesa/src/image.c index 453366814..3f0720ea0 100644 --- a/xc/extras/Mesa/src/image.c +++ b/xc/extras/Mesa/src/image.c @@ -30,6 +30,7 @@ #include "glheader.h" #include "context.h" #include "image.h" +#include "imaging.h" #include "macros.h" #include "mem.h" #include "mmath.h" @@ -601,7 +602,7 @@ _mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest, * applyTransferOps - apply scale/bias/lookup-table ops? */ void -_mesa_pack_rgba_span( const GLcontext *ctx, +_mesa_pack_rgba_span( GLcontext *ctx, GLuint n, CONST GLubyte srcRgba[][4], GLenum format, GLenum type, GLvoid *destination, const struct gl_pixelstore_attrib *packing, @@ -611,7 +612,9 @@ _mesa_pack_rgba_span( const GLcontext *ctx, ctx->Pixel.MapColorFlag || ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm || - ctx->Pixel.ColorTableEnabled); + ctx->Pixel.ColorTableEnabled || + ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.MinMaxEnabled); /* Test for optimized case first */ if (!applyTransferOps && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { @@ -657,18 +660,31 @@ _mesa_pack_rgba_span( const GLcontext *ctx, if (ctx->Pixel.ScaleOrBiasRGBA) { _mesa_scale_and_bias_rgba( ctx, n, rgba ); } - /* color table lookup */ + /* color map lookup */ if (ctx->Pixel.MapColorFlag) { _mesa_map_rgba( ctx, n, rgba ); } + /* GL_COLOR_TABLE lookup */ + if (ctx->Pixel.ColorTableEnabled) { + _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); + } + /* XXX convolution here */ + /* XXX post-convolution color table look-up here */ /* color matrix */ if (ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm) { _mesa_transform_rgba(ctx, n, rgba); } - /* GL_SGI_color_table lookup */ - if (ctx->Pixel.ColorTableEnabled) { - _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); + /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ + if (ctx->Pixel.PostColorMatrixColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); + } + /* XXX histogram here */ + /* XXX min/max here */ + if (ctx->Pixel.MinMaxEnabled) { + _mesa_update_minmax(ctx, n, (const GLfloat (*)[4]) rgba); + if (ctx->MinMax.Sink) + return; } } @@ -2118,7 +2134,7 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4], * XXX perhaps expand this to process whole images someday. */ void -_mesa_unpack_ubyte_color_span( const GLcontext *ctx, +_mesa_unpack_ubyte_color_span( GLcontext *ctx, GLuint n, GLenum dstFormat, GLubyte dest[], GLenum srcFormat, GLenum srcType, const GLvoid *source, @@ -2175,7 +2191,9 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx, ctx->Pixel.MapColorFlag || ctx->ColorMatrix.type != MATRIX_IDENTITY || ctx->Pixel.ScaleOrBiasRGBApcm || - ctx->Pixel.ColorTableEnabled); + ctx->Pixel.ColorTableEnabled || + ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.MinMaxEnabled); /* Try simple cases first */ if (!applyTransferOps && srcType == GL_UNSIGNED_BYTE) { @@ -2247,26 +2265,22 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx, extract_uint_indexes(n, indexes, srcFormat, srcType, source, unpacking); - /* shift and offset indexes */ - _mesa_shift_and_offset_ci(ctx, n, indexes); + if (applyTransferOps) { + if (ctx->Pixel.MapColorFlag) { + _mesa_map_ci(ctx, n, indexes); + } + if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { + _mesa_shift_and_offset_ci(ctx, n, indexes); + } + } if (dstFormat == GL_COLOR_INDEX) { - if (applyTransferOps) { - if (ctx->Pixel.MapColorFlag) { - /* Apply lookup table */ - _mesa_map_ci(ctx, n, indexes); - } - if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { - _mesa_shift_and_offset_ci(ctx, n, indexes); - } - } /* convert to GLubyte and return */ - { - GLuint i; - for (i = 0; i < n; i++) { - dest[i] = (GLubyte) (indexes[i] & 0xff); - } + GLuint i; + for (i = 0; i < n; i++) { + dest[i] = (GLubyte) (indexes[i] & 0xff); } + return; } else { /* Convert indexes to RGBA */ @@ -2279,20 +2293,36 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx, if (applyTransferOps) { /* scale and bias colors */ - _mesa_scale_and_bias_rgba(ctx, n, rgba); - /* color table lookup */ + if (ctx->Pixel.ScaleOrBiasRGBA) { + _mesa_scale_and_bias_rgba(ctx, n, rgba); + } + /* color map lookup */ if (ctx->Pixel.MapColorFlag) { _mesa_map_rgba(ctx, n, rgba); } - /* color matrix transform */ - if (ctx->ColorMatrix.type != MATRIX_IDENTITY || - ctx->Pixel.ScaleOrBiasRGBApcm) { - _mesa_transform_rgba(ctx, n, rgba); - } - /* GL_SGI_color_table lookup */ - if (ctx->Pixel.ColorTableEnabled) { - _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); - } + } + } + + if (applyTransferOps) { + /* GL_COLOR_TABLE lookup */ + if (ctx->Pixel.ColorTableEnabled) { + _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); + } + /* XXX convolution here */ + /* XXX post-convolution color table look-up here */ + /* color matrix transform */ + if (ctx->ColorMatrix.type != MATRIX_IDENTITY || + ctx->Pixel.ScaleOrBiasRGBApcm) { + _mesa_transform_rgba(ctx, n, rgba); + } + /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ + if (ctx->Pixel.PostColorMatrixColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); + } + /* XXX histogram here */ + /* XXX min/max here */ + if (ctx->Pixel.MinMaxEnabled) { + _mesa_update_minmax(ctx, n, (const GLfloat (*)[4]) rgba); } } @@ -2414,6 +2444,266 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx, } +void +_mesa_unpack_float_color_span( GLcontext *ctx, + GLuint n, GLenum dstFormat, GLfloat dest[], + GLenum srcFormat, GLenum srcType, + const GLvoid *source, + const struct gl_pixelstore_attrib *unpacking, + GLboolean applyTransferOps ) +{ + ASSERT(dstFormat == GL_ALPHA || + dstFormat == GL_LUMINANCE || + dstFormat == GL_LUMINANCE_ALPHA || + dstFormat == GL_INTENSITY || + dstFormat == GL_RGB || + dstFormat == GL_RGBA || + dstFormat == GL_COLOR_INDEX); + + ASSERT(srcFormat == GL_RED || + srcFormat == GL_GREEN || + srcFormat == GL_BLUE || + srcFormat == GL_ALPHA || + srcFormat == GL_LUMINANCE || + srcFormat == GL_LUMINANCE_ALPHA || + srcFormat == GL_INTENSITY || + srcFormat == GL_RGB || + srcFormat == GL_BGR || + srcFormat == GL_RGBA || + srcFormat == GL_BGRA || + srcFormat == GL_ABGR_EXT || + srcFormat == GL_COLOR_INDEX); + + ASSERT(srcType == GL_BITMAP || + srcType == GL_UNSIGNED_BYTE || + srcType == GL_BYTE || + srcType == GL_UNSIGNED_SHORT || + srcType == GL_SHORT || + srcType == GL_UNSIGNED_INT || + srcType == GL_INT || + srcType == GL_FLOAT || + srcType == GL_UNSIGNED_BYTE_3_3_2 || + srcType == GL_UNSIGNED_BYTE_2_3_3_REV || + srcType == GL_UNSIGNED_SHORT_5_6_5 || + srcType == GL_UNSIGNED_SHORT_5_6_5_REV || + srcType == GL_UNSIGNED_SHORT_4_4_4_4 || + srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || + srcType == GL_UNSIGNED_SHORT_5_5_5_1 || + srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || + srcType == GL_UNSIGNED_INT_8_8_8_8 || + srcType == GL_UNSIGNED_INT_8_8_8_8_REV || + srcType == GL_UNSIGNED_INT_10_10_10_2 || + srcType == GL_UNSIGNED_INT_2_10_10_10_REV); + + /* this is intended for RGBA mode only */ + assert(ctx->Visual->RGBAflag); + + applyTransferOps &= (ctx->Pixel.ScaleOrBiasRGBA || + ctx->Pixel.MapColorFlag || + ctx->ColorMatrix.type != MATRIX_IDENTITY || + ctx->Pixel.ScaleOrBiasRGBApcm || + ctx->Pixel.ColorTableEnabled || + ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.MinMaxEnabled); + + /* general solution, no special cases, yet */ + { + GLfloat rgba[MAX_WIDTH][4]; + GLint dstComponents; + GLint dstRedIndex, dstGreenIndex, dstBlueIndex, dstAlphaIndex; + GLint dstLuminanceIndex, dstIntensityIndex; + + dstComponents = _mesa_components_in_format( dstFormat ); + /* source & dest image formats should have been error checked by now */ + assert(dstComponents > 0); + + /* + * Extract image data and convert to RGBA floats + */ + assert(n <= MAX_WIDTH); + if (srcFormat == GL_COLOR_INDEX) { + GLuint indexes[MAX_WIDTH]; + extract_uint_indexes(n, indexes, srcFormat, srcType, source, + unpacking); + + if (applyTransferOps) { + if (ctx->Pixel.MapColorFlag) { + _mesa_map_ci(ctx, n, indexes); + } + if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { + _mesa_shift_and_offset_ci(ctx, n, indexes); + } + } + + if (dstFormat == GL_COLOR_INDEX) { + /* convert to GLubyte and return */ + GLuint i; + for (i = 0; i < n; i++) { + dest[i] = (GLubyte) (indexes[i] & 0xff); + } + return; + } + else { + /* Convert indexes to RGBA */ + _mesa_map_ci_to_rgba(ctx, n, indexes, rgba); + } + } + else { + extract_float_rgba(n, rgba, srcFormat, srcType, source, + unpacking->SwapBytes); + + if (applyTransferOps) { + /* scale and bias colors */ + if (ctx->Pixel.ScaleOrBiasRGBA) { + _mesa_scale_and_bias_rgba(ctx, n, rgba); + } + /* color map lookup */ + if (ctx->Pixel.MapColorFlag) { + _mesa_map_rgba(ctx, n, rgba); + } + } + } + + if (applyTransferOps) { + /* GL_COLOR_TABLE lookup */ + if (ctx->Pixel.ColorTableEnabled) { + _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); + } + /* XXX convolution here */ + /* XXX post-convolution color table look-up here */ + /* color matrix transform */ + if (ctx->ColorMatrix.type != MATRIX_IDENTITY || + ctx->Pixel.ScaleOrBiasRGBApcm) { + _mesa_transform_rgba(ctx, n, rgba); + } + /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ + if (ctx->Pixel.PostColorMatrixColorTableEnabled) { + _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); + } + /* XXX histogram here */ + /* XXX min/max here */ + if (ctx->Pixel.MinMaxEnabled) { + _mesa_update_minmax(ctx, n, (const GLfloat (*)[4]) rgba); + } + } + + /* clamp to [0,1] */ + { + GLuint i; + for (i = 0; i < n; i++) { + rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F); + rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F); + rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F); + rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F); + } + } + + /* Now determine which color channels we need to produce. + * And determine the dest index (offset) within each color tuple. + */ + switch (dstFormat) { + case GL_ALPHA: + dstAlphaIndex = 0; + dstRedIndex = dstGreenIndex = dstBlueIndex = -1; + dstLuminanceIndex = dstIntensityIndex = -1; + break; + case GL_LUMINANCE: + dstLuminanceIndex = 0; + dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; + dstIntensityIndex = -1; + break; + case GL_LUMINANCE_ALPHA: + dstLuminanceIndex = 0; + dstAlphaIndex = 1; + dstRedIndex = dstGreenIndex = dstBlueIndex = -1; + dstIntensityIndex = -1; + break; + case GL_INTENSITY: + dstIntensityIndex = 0; + dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; + dstLuminanceIndex = -1; + break; + case GL_RGB: + dstRedIndex = 0; + dstGreenIndex = 1; + dstBlueIndex = 2; + dstAlphaIndex = dstLuminanceIndex = dstIntensityIndex = -1; + break; + case GL_RGBA: + dstRedIndex = 0; + dstGreenIndex = 1; + dstBlueIndex = 2; + dstAlphaIndex = 3; + dstLuminanceIndex = dstIntensityIndex = -1; + break; + default: + gl_problem(ctx, "bad dstFormat in _mesa_unpack_float_span()"); + return; + } + + /* Now pack results in teh requested dstFormat */ + if (dstRedIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + for (i = 0; i < n; i++) { + dst[dstRedIndex] = rgba[i][RCOMP]; + dst += dstComponents; + } + } + + if (dstGreenIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + for (i = 0; i < n; i++) { + dst[dstGreenIndex] = rgba[i][GCOMP]; + dst += dstComponents; + } + } + + if (dstBlueIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + for (i = 0; i < n; i++) { + dst[dstBlueIndex] = rgba[i][BCOMP]; + dst += dstComponents; + } + } + + if (dstAlphaIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + for (i = 0; i < n; i++) { + dst[dstAlphaIndex] = rgba[i][ACOMP]; + dst += dstComponents; + } + } + + if (dstIntensityIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + assert(dstIntensityIndex == 0); + assert(dstComponents == 1); + for (i = 0; i < n; i++) { + /* Intensity comes from red channel */ + dst[i] = rgba[i][RCOMP]; + } + } + + if (dstLuminanceIndex >= 0) { + GLfloat *dst = dest; + GLuint i; + assert(dstLuminanceIndex == 0); + for (i = 0; i < n; i++) { + /* Luminance comes from red channel */ + dst[0] = rgba[i][RCOMP]; + dst += dstComponents; + } + } + } +} + + + /* * Unpack a row of color index data from a client buffer according to diff --git a/xc/extras/Mesa/src/image.h b/xc/extras/Mesa/src/image.h index 84f104422..25b591ec9 100644 --- a/xc/extras/Mesa/src/image.h +++ b/xc/extras/Mesa/src/image.h @@ -1,9 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 3.1 + * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -31,57 +31,63 @@ #include "types.h" -extern struct gl_pixelstore_attrib _mesa_native_packing; +extern const struct gl_pixelstore_attrib _mesa_native_packing; -extern void gl_flip_bytes( GLubyte *p, GLuint n ); +extern void +_mesa_swap2( GLushort *p, GLuint n ); +extern void +_mesa_swap4( GLuint *p, GLuint n ); -extern void gl_swap2( GLushort *p, GLuint n ); +extern GLint +_mesa_sizeof_type( GLenum type ); -extern void gl_swap4( GLuint *p, GLuint n ); +extern GLint +_mesa_sizeof_packed_type( GLenum type ); +extern GLint +_mesa_components_in_format( GLenum format ); -extern GLint gl_sizeof_type( GLenum type ); +extern GLint +_mesa_bytes_per_pixel( GLenum format, GLenum type ); -extern GLint gl_sizeof_packed_type( GLenum type ); +extern GLboolean +_mesa_is_legal_format_and_type( GLenum format, GLenum type ); -extern GLint gl_components_in_format( GLenum format ); -extern GLint gl_bytes_per_pixel( GLenum format, GLenum type ); +extern GLvoid * +_mesa_image_address( const struct gl_pixelstore_attrib *packing, + const GLvoid *image, GLsizei width, + GLsizei height, GLenum format, GLenum type, + GLint img, GLint row, GLint column ); -extern GLboolean gl_is_legal_format_and_type( GLenum format, GLenum type ); - -extern GLvoid * -gl_pixel_addr_in_image( const struct gl_pixelstore_attrib *packing, - const GLvoid *image, GLsizei width, - GLsizei height, GLenum format, GLenum type, - GLint img, GLint row, GLint column ); +extern GLint +_mesa_image_row_stride( const struct gl_pixelstore_attrib *packing, + GLint width, GLenum format, GLenum type ); extern void -gl_unpack_polygon_stipple( const GLcontext *ctx, - const GLubyte *pattern, - GLuint dest[32] ); +_mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32], + const struct gl_pixelstore_attrib *unpacking ); extern void -gl_pack_polygon_stipple( const GLcontext *ctx, - const GLuint pattern[32], - GLubyte *dest ); +_mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest, + const struct gl_pixelstore_attrib *packing ); extern void -gl_pack_rgba_span( const GLcontext *ctx, - GLuint n, CONST GLubyte rgba[][4], - GLenum format, GLenum type, GLvoid *dest, - const struct gl_pixelstore_attrib *packing, - GLboolean applyTransferOps ); +_mesa_pack_rgba_span( GLcontext *ctx, + GLuint n, CONST GLubyte rgba[][4], + GLenum format, GLenum type, GLvoid *dest, + const struct gl_pixelstore_attrib *packing, + GLboolean applyTransferOps ); extern void -_mesa_unpack_ubyte_color_span( const GLcontext *ctx, +_mesa_unpack_ubyte_color_span( GLcontext *ctx, GLuint n, GLenum dstFormat, GLubyte dest[], GLenum srcFormat, GLenum srcType, const GLvoid *source, @@ -90,6 +96,15 @@ _mesa_unpack_ubyte_color_span( const GLcontext *ctx, extern void +_mesa_unpack_float_color_span( GLcontext *ctx, + GLuint n, GLenum dstFormat, GLfloat dest[], + GLenum srcFormat, GLenum srcType, + const GLvoid *source, + const struct gl_pixelstore_attrib *unpacking, + GLboolean applyTransferOps ); + + +extern void _mesa_unpack_index_span( const GLcontext *ctx, GLuint n, GLenum dstType, GLvoid *dest, GLenum srcType, const GLvoid *source, @@ -122,5 +137,9 @@ extern GLvoid * _mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels, const struct gl_pixelstore_attrib *packing ); +extern void +_mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, + GLubyte *dest, const struct gl_pixelstore_attrib *packing ); + #endif diff --git a/xc/extras/Mesa/src/imaging.c b/xc/extras/Mesa/src/imaging.c index 4e70968e1..6710e2d3e 100644 --- a/xc/extras/Mesa/src/imaging.c +++ b/xc/extras/Mesa/src/imaging.c @@ -532,7 +532,7 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalformat, GLsizei width, GLs * Update the min/max values from an array of fragment colors. */ void -_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLchan rgba[][4]) +_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLfloat rgba[][4]) { GLuint i; for (i = 0; i < n; i++) { diff --git a/xc/extras/Mesa/src/imaging.h b/xc/extras/Mesa/src/imaging.h index 64002d39f..220a99576 100644 --- a/xc/extras/Mesa/src/imaging.h +++ b/xc/extras/Mesa/src/imaging.h @@ -85,7 +85,7 @@ extern void _mesa_SeparableFilter2D(GLenum target, GLenum internalformat, GLsize extern void -_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLchan rgba[][4]); +_mesa_update_minmax(GLcontext *ctx, GLuint n, const GLfloat rgba[][4]); extern void _mesa_update_histogram(GLcontext *ctx, GLuint n, const GLchan rgba[][4]); diff --git a/xc/extras/Mesa/src/pixel.c b/xc/extras/Mesa/src/pixel.c index b5a1c0f51..e70f98414 100644 --- a/xc/extras/Mesa/src/pixel.c +++ b/xc/extras/Mesa/src/pixel.c @@ -725,40 +725,75 @@ void _mesa_lookup_rgba(const struct gl_color_table *table, GLuint n, GLfloat rgba[][4]) { + ASSERT(table->TableType == GL_FLOAT); + if (!table->Table) + return; + switch (table->Format) { case GL_INTENSITY: - { + /* replace RGBA with I */ + if (table->TableType == GL_UNSIGNED_BYTE) { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLubyte *lut = (const GLubyte *) table->Table; GLuint i; - /* replace RGBA with I */ for (i = 0; i < n; i++) { GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); - GLubyte c = lut[j]; + GLfloat c = lut[j] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = + rgba[i][BCOMP] = rgba[i][ACOMP] = c; + } + + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j]; rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = c; } } break; case GL_LUMINANCE: - { + /* replace RGB with L */ + if (table->TableType == GL_UNSIGNED_BYTE) { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLubyte *lut = (const GLubyte *) table->Table; GLuint i; - /* replace RGB with L */ for (i = 0; i < n; i++) { GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); - GLubyte c = lut[j]; + GLfloat c = lut[j] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j]; rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; } } break; case GL_ALPHA: - { + /* replace A with A */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][ACOMP] = lut[j] * (1.0F / 255.0F); + } + } + else { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLfloat *lut = (const GLfloat *) table->Table; GLuint i; - /* replace A with A */ for (i = 0; i < n; i++) { GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F); rgba[i][ACOMP] = lut[j]; @@ -766,27 +801,53 @@ _mesa_lookup_rgba(const struct gl_color_table *table, } break; case GL_LUMINANCE_ALPHA: - { + /* replace RGBA with LLLA */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + GLfloat luminance = lut[jL * 2 + 0] * (1.0F / 255.0F); + GLfloat alpha = lut[jA * 2 + 1] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; + rgba[i][ACOMP] = alpha;; + } + } + else { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLfloat *lut = (const GLfloat *) table->Table; GLuint i; - /* replace RGBA with LLLA */ for (i = 0; i < n; i++) { GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F); GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); - GLubyte luminance = lut[jL * 2 + 0]; - GLubyte alpha = lut[jA * 2 + 1]; + GLfloat luminance = lut[jL * 2 + 0]; + GLfloat alpha = lut[jA * 2 + 1]; rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; rgba[i][ACOMP] = alpha;; } } break; case GL_RGB: - { + /* replace RGB with RGB */ + if (table->TableType == GL_UNSIGNED_BYTE) { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 3 + 0] * (1.0F / 255.0F); + rgba[i][GCOMP] = lut[jG * 3 + 1] * (1.0F / 255.0F); + rgba[i][BCOMP] = lut[jB * 3 + 2] * (1.0F / 255.0F); + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; GLuint i; - /* replace RGB with RGB */ for (i = 0; i < n; i++) { GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); @@ -798,11 +859,26 @@ _mesa_lookup_rgba(const struct gl_color_table *table, } break; case GL_RGBA: - { + /* replace RGBA with RGBA */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 4 + 0] * (1.0F / 255.0F); + rgba[i][GCOMP] = lut[jG * 4 + 1] * (1.0F / 255.0F); + rgba[i][BCOMP] = lut[jB * 4 + 2] * (1.0F / 255.0F); + rgba[i][ACOMP] = lut[jA * 4 + 3] * (1.0F / 255.0F); + } + } + else { const GLfloat scale = (GLfloat) (table->Size - 1); - const GLubyte *lut = table->Table; + const GLfloat *lut = (const GLfloat *) table->Table; GLuint i; - /* replace RGBA with RGBA */ for (i = 0; i < n; i++) { GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); diff --git a/xc/extras/Mesa/src/readpix.c b/xc/extras/Mesa/src/readpix.c index 515ee27a9..cc1823897 100644 --- a/xc/extras/Mesa/src/readpix.c +++ b/xc/extras/Mesa/src/readpix.c @@ -500,8 +500,17 @@ read_fast_rgba_pixels( GLcontext *ctx, GLvoid *pixels, const struct gl_pixelstore_attrib *packing ) { - /* can't do scale, bias or mapping */ - if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) + GLboolean applyTransferOps; + + applyTransferOps = ctx->Pixel.ScaleOrBiasRGBA || + ctx->Pixel.MapColorFlag || + ctx->ColorMatrix.type != MATRIX_IDENTITY || + ctx->Pixel.ScaleOrBiasRGBApcm || + ctx->Pixel.ColorTableEnabled || + ctx->Pixel.PostColorMatrixColorTableEnabled || + ctx->Pixel.MinMaxEnabled; + /* can't do scale, bias, mapping, etc */ + if (applyTransferOps) return GL_FALSE; /* can't do fancy pixel packing */ diff --git a/xc/extras/Mesa/src/texobj.c b/xc/extras/Mesa/src/texobj.c index e30032376..330943b57 100644 --- a/xc/extras/Mesa/src/texobj.c +++ b/xc/extras/Mesa/src/texobj.c @@ -28,6 +28,7 @@ #include "all.h" #else #include "glheader.h" +#include "colortab.h" #include "context.h" #include "enums.h" #include "hash.h" @@ -73,13 +74,7 @@ gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name, obj->BaseLevel = 0; obj->MaxLevel = 1000; obj->MinMagThresh = 0.0F; - obj->Palette.Table[0] = 255; - obj->Palette.Table[1] = 255; - obj->Palette.Table[2] = 255; - obj->Palette.Table[3] = 255; - obj->Palette.Size = 1; - obj->Palette.IntFormat = GL_RGBA; - obj->Palette.Format = GL_RGBA; + _mesa_init_colortable(&obj->Palette); /* insert into linked list */ if (shared) { @@ -143,12 +138,14 @@ void gl_free_texture_object( struct gl_shared_state *shared, _mesa_HashRemove(shared->TexObjects, t->Name); } - /* free texture image */ + _mesa_free_colortable_data(&t->Palette); + + /* free texture images */ { GLuint i; for (i=0;i<MAX_TEXTURE_LEVELS;i++) { if (t->Image[i]) { - gl_free_texture_image( t->Image[i] ); + _mesa_free_texture_image( t->Image[i] ); } } } @@ -167,7 +164,7 @@ void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_textur t->Complete = GL_TRUE; /* be optimistic */ /* Always need level zero image */ - if (!t->Image[0] || !t->Image[0]->Data) { + if (!t->Image[0]) { t->Complete = GL_FALSE; return; } @@ -206,10 +203,6 @@ void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_textur /* Test dimension-independent attributes */ for (i = minLevel; i <= maxLevel; i++) { if (t->Image[i]) { - if (!t->Image[i]->Data) { - t->Complete = GL_FALSE; - return; - } if (t->Image[i]->Format != t->Image[0]->Format) { t->Complete = GL_FALSE; return; @@ -234,10 +227,6 @@ void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_textur t->Complete = GL_FALSE; return; } - if (!t->Image[i]->Data) { - t->Complete = GL_FALSE; - return; - } if (t->Image[i]->Width2 != width ) { t->Complete = GL_FALSE; return; @@ -324,6 +313,8 @@ void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_textur } +_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock); + /* * Execute glGenTextures @@ -341,6 +332,12 @@ _mesa_GenTextures( GLsizei n, GLuint *texName ) return; } + + /* + * This must be atomic (generation and allocation of texture IDs) + */ + _glthread_LOCK_MUTEX(GenTexturesLock); + first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n); /* Return the texture names */ @@ -354,6 +351,8 @@ _mesa_GenTextures( GLsizei n, GLuint *texName ) GLuint dims = 0; (void) gl_alloc_texture_object(ctx->Shared, name, dims); } + + _glthread_UNLOCK_MUTEX(GenTexturesLock); } diff --git a/xc/extras/Mesa/src/texture.c b/xc/extras/Mesa/src/texture.c index c73171bd2..d101e2518 100644 --- a/xc/extras/Mesa/src/texture.c +++ b/xc/extras/Mesa/src/texture.c @@ -32,6 +32,7 @@ #include "macros.h" #include "mmath.h" #include "pb.h" +#include "teximage.h" #include "texture.h" #include "types.h" #include "xform.h" @@ -245,11 +246,13 @@ static void palette_sample(const struct gl_texture_object *tObj, GLenum format; if (ctx->Texture.SharedPalette) { - palette = ctx->Texture.Palette.Table; + ASSERT(ctx->Texture.Palette.TableType == GL_UNSIGNED_BYTE); + palette = (const GLubyte *) ctx->Texture.Palette.Table; format = ctx->Texture.Palette.Format; } else { - palette = tObj->Palette.Table; + ASSERT(tObj->Palette.TableType == GL_UNSIGNED_BYTE); + palette = (const GLubyte *) tObj->Palette.Table; format = tObj->Palette.Format; } @@ -532,10 +535,10 @@ static void sample_1d_linear( const struct gl_texture_object *tObj, } { - GLfloat a = myFrac(u); + const GLfloat a = myFrac(u); /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ - GLint w0 = (GLint) ((1.0F-a) * WEIGHT_SCALE + 0.5F); - GLint w1 = (GLint) ( a * WEIGHT_SCALE + 0.5F); + const GLint w0 = (GLint) ((1.0F-a) * WEIGHT_SCALE + 0.5F); + const GLint w1 = (GLint) ( a * WEIGHT_SCALE + 0.5F); GLubyte t0[4], t1[4]; /* texels */ @@ -614,7 +617,7 @@ sample_1d_nearest_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_1d_nearest( tObj, tObj->Image[level ], s, t0 ); sample_1d_nearest( tObj, tObj->Image[level+1], s, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -643,7 +646,7 @@ sample_1d_linear_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_1d_linear( tObj, tObj->Image[level ], s, t0 ); sample_1d_linear( tObj, tObj->Image[level+1], s, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -906,13 +909,13 @@ static void sample_2d_linear( const struct gl_texture_object *tObj, } { - GLfloat a = myFrac(u); - GLfloat b = myFrac(v); + const GLfloat a = myFrac(u); + const GLfloat b = myFrac(v); /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ - GLint w00 = (GLint) ((1.0F-a)*(1.0F-b) * WEIGHT_SCALE + 0.5F); - GLint w10 = (GLint) ( a *(1.0F-b) * WEIGHT_SCALE + 0.5F); - GLint w01 = (GLint) ((1.0F-a)* b * WEIGHT_SCALE + 0.5F); - GLint w11 = (GLint) ( a * b * WEIGHT_SCALE + 0.5F); + const GLint w00 = (GLint) ((1.0F-a)*(1.0F-b) * WEIGHT_SCALE + 0.5F); + const GLint w10 = (GLint) ( a *(1.0F-b) * WEIGHT_SCALE + 0.5F); + const GLint w01 = (GLint) ((1.0F-a)* b * WEIGHT_SCALE + 0.5F); + const GLint w11 = (GLint) ( a * b * WEIGHT_SCALE + 0.5F); GLubyte t00[4]; GLubyte t10[4]; GLubyte t01[4]; @@ -1008,7 +1011,7 @@ sample_2d_nearest_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; /* texels */ - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_2d_nearest( tObj, tObj->Image[level ], s, t, t0 ); sample_2d_nearest( tObj, tObj->Image[level+1], s, t, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -1037,7 +1040,7 @@ sample_2d_linear_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; /* texels */ - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_2d_linear( tObj, tObj->Image[level ], s, t, t0 ); sample_2d_linear( tObj, tObj->Image[level+1], s, t, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -1385,9 +1388,9 @@ static void sample_3d_linear( const struct gl_texture_object *tObj, } { - GLfloat a = myFrac(u); - GLfloat b = myFrac(v); - GLfloat c = myFrac(w); + const GLfloat a = myFrac(u); + const GLfloat b = myFrac(v); + const GLfloat c = myFrac(w); /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */ GLint w000 = (GLint) ((1.0F-a)*(1.0F-b)*(1.0F-c) * WEIGHT_SCALE + 0.5F); GLint w100 = (GLint) ( a *(1.0F-b)*(1.0F-c) * WEIGHT_SCALE + 0.5F); @@ -1525,7 +1528,7 @@ sample_3d_nearest_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; /* texels */ - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_3d_nearest( tObj, tObj->Image[level ], s, t, r, t0 ); sample_3d_nearest( tObj, tObj->Image[level+1], s, t, r, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -1553,7 +1556,7 @@ sample_3d_linear_mipmap_linear( const struct gl_texture_object *tObj, } else { GLubyte t0[4], t1[4]; /* texels */ - GLfloat f = myFrac(lambda); + const GLfloat f = myFrac(lambda); sample_3d_linear( tObj, tObj->Image[level ], s, t, r, t0 ); sample_3d_linear( tObj, tObj->Image[level+1], s, t, r, t1 ); rgba[RCOMP] = (GLubyte) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]); @@ -2096,9 +2099,16 @@ void gl_texture_pixels( GLcontext *ctx, GLuint texUnit, GLuint n, if (ctx->Texture.Enabled & mask) { const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit]; if (textureUnit->Current && textureUnit->Current->SampleFunc) { - GLubyte texel[PB_SIZE][4]; + if (textureUnit->LodBias != 0.0F) { + /* apply LOD bias, but don't clamp yet */ + GLuint i; + for (i=0;i<n;i++) { + lambda[i] += textureUnit->LodBias; + } + } + if (textureUnit->Current->MinLod != -1000.0 || textureUnit->Current->MaxLod != 1000.0) { /* apply LOD clamping to lambda */ @@ -2111,6 +2121,38 @@ void gl_texture_pixels( GLcontext *ctx, GLuint texUnit, GLuint n, } } + /* fetch texture images from device driver, if needed */ + { + static const GLenum targets[] = {GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D}; + struct gl_texture_object *texObj = textureUnit->Current; + GLboolean needLambda = (texObj->MinFilter != texObj->MagFilter); + GLenum target = targets[texObj->Dimensions - 1]; + if (needLambda) { + GLint level; + /* Get images for all mipmap levels. We might not need them + * all but this is easier. We're on a (slow) software path + * anyway. + */ + for (level = 0; level <= texObj->P; level++) { + struct gl_texture_image *texImg = texObj->Image[level]; + if (!texImg->Data) { + _mesa_get_teximage_from_driver(ctx, target, level, texObj); + if (!texImg->Data) + return; /* out of memory */ + } + } + } + else { + GLint level = texObj->BaseLevel; + struct gl_texture_image *texImg = texObj->Image[level]; + if (!texImg->Data) { + _mesa_get_teximage_from_driver(ctx, target, level, texObj); + if (!texImg->Data) + return; /* out of memory */ + } + } + } + /* Sample the texture. */ (*textureUnit->Current->SampleFunc)( textureUnit->Current, n, s, t, r, lambda, texel ); diff --git a/xc/extras/Mesa/src/types.h b/xc/extras/Mesa/src/types.h index cf5bebf29..78a40ace1 100644 --- a/xc/extras/Mesa/src/types.h +++ b/xc/extras/Mesa/src/types.h @@ -208,7 +208,8 @@ struct gl_texture_image { /* Data structure for color tables */ struct gl_color_table { - GLubyte Table[4 * MAX_COLOR_TABLE_SIZE]; + GLvoid *Table; + GLenum TableType; /* GL_UNSIGNED_BYTE or GL_FLOAT */ GLuint Size; /* number of entries (rows) in table */ GLenum Format; GLenum IntFormat; @@ -522,10 +523,9 @@ struct gl_histogram_attrib { struct gl_minmax_attrib { - GLenum Format; - GLboolean Sink; - GLint Min[4]; /* RGBA */ - GLint Max[4]; /* RGBA */ + GLenum Format; + GLboolean Sink; + GLfloat Min[4], Max[4]; /* RGBA */ }; @@ -1312,6 +1312,7 @@ struct gl_constants { GLfloat MinLineWidthAA, MaxLineWidthAA; /* antialiased */ GLfloat LineWidthGranularity; GLuint NumAuxBuffers; + GLuint MaxColorTableSize; }; |