diff options
Diffstat (limited to 'xc/lib/GL/mesa/src')
58 files changed, 16415 insertions, 3347 deletions
diff --git a/xc/lib/GL/mesa/src/drv/common/depthtmp.h b/xc/lib/GL/mesa/src/drv/common/depthtmp.h index 0c10eae19..971401413 100644 --- a/xc/lib/GL/mesa/src/drv/common/depthtmp.h +++ b/xc/lib/GL/mesa/src/drv/common/depthtmp.h @@ -4,6 +4,7 @@ #define DBG 0 #endif + #ifndef HAVE_HW_DEPTH_SPANS #define HAVE_HW_DEPTH_SPANS 0 #endif @@ -11,13 +12,19 @@ #define HAVE_HW_DEPTH_PIXELS 0 #endif +#ifndef HW_READ_LOCK +#define HW_READ_LOCK() HW_LOCK() +#endif +#ifndef HW_READ_UNLOCK +#define HW_READ_UNLOCK() HW_UNLOCK() +#endif static void TAG(WriteDepthSpan)( GLcontext *ctx, - GLuint n, GLint x, GLint y, + GLuint n, GLint x, GLint y, const GLdepth *depth, const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint x1; GLint n1; @@ -54,7 +61,7 @@ static void TAG(WriteDepthSpan)( GLcontext *ctx, HW_ENDCLIPLOOP(); #endif } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } static void TAG(WriteDepthPixels)( GLcontext *ctx, @@ -64,7 +71,7 @@ static void TAG(WriteDepthPixels)( GLcontext *ctx, const GLdepth depth[], const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint i; LOCAL_DEPTH_VARS; @@ -89,7 +96,7 @@ static void TAG(WriteDepthPixels)( GLcontext *ctx, HW_ENDCLIPLOOP(); #endif } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } @@ -99,7 +106,7 @@ static void TAG(ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, GLdepth depth[] ) { - HW_LOCK() + HW_READ_LOCK() { GLint x1, n1; LOCAL_DEPTH_VARS; @@ -123,14 +130,14 @@ static void TAG(ReadDepthSpan)( GLcontext *ctx, HW_ENDCLIPLOOP(); #endif } - HW_UNLOCK(); + HW_READ_UNLOCK(); } static void TAG(ReadDepthPixels)( GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], GLdepth depth[] ) { - HW_LOCK() + HW_READ_LOCK() { GLint i; LOCAL_DEPTH_VARS; @@ -153,9 +160,10 @@ static void TAG(ReadDepthPixels)( GLcontext *ctx, GLuint n, HW_ENDCLIPLOOP(); #endif } - HW_UNLOCK(); + HW_READ_UNLOCK(); } + #if HAVE_HW_DEPTH_SPANS #undef WRITE_DEPTH_SPAN #undef WRITE_DEPTH_PIXELS diff --git a/xc/lib/GL/mesa/src/drv/common/spantmp.h b/xc/lib/GL/mesa/src/drv/common/spantmp.h index 1e69d7b7f..4cac09bd0 100644 --- a/xc/lib/GL/mesa/src/drv/common/spantmp.h +++ b/xc/lib/GL/mesa/src/drv/common/spantmp.h @@ -2,21 +2,45 @@ #define DBG 0 #endif -static void TAG(WriteRGBASpan)( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte rgba[][4], +#ifndef HW_WRITE_LOCK +#define HW_WRITE_LOCK() HW_LOCK() +#endif + +#ifndef HW_WRITE_UNLOCK +#define HW_WRITE_UNLOCK() HW_UNLOCK() +#endif + +#ifndef HW_READ_LOCK +#define HW_READ_LOCK() HW_LOCK() +#endif + +#ifndef HW_READ_UNLOCK +#define HW_READ_UNLOCK() HW_UNLOCK() +#endif + +#ifndef HW_READ_CLIPLOOP +#define HW_READ_CLIPLOOP() HW_CLIPLOOP() +#endif + +#ifndef HW_WRITE_CLIPLOOP +#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP() +#endif + + +static void TAG(WriteRGBASpan)( const GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint x1; GLint n1; LOCAL_VARS; - - y = Y_FLIP(y); + y = Y_FLIP(y); - HW_CLIPLOOP() + HW_WRITE_CLIPLOOP() { GLint i = 0; CLIPSPAN(x,y,n,x1,n1,i); @@ -26,31 +50,31 @@ static void TAG(WriteRGBASpan)( const GLcontext *ctx, if (mask) { - for (;i<n1;i++,x1++) + for (;n1>0;i++,x1++,n1--) if (mask[i]) - WRITE_RGBA( x1, y, - rgba[i][0], rgba[i][1], + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3] ); } else { - for (;i<n1;i++,x1++) - WRITE_RGBA( x1, y, - rgba[i][0], rgba[i][1], + for (;n1>0;i++,x1++,n1--) + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3] ); } } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } static void TAG(WriteRGBSpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLubyte rgb[][3], + const GLubyte rgb[][3], const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint x1; GLint n1; @@ -58,7 +82,7 @@ static void TAG(WriteRGBSpan)( const GLcontext *ctx, y = Y_FLIP(y); - HW_CLIPLOOP() + HW_WRITE_CLIPLOOP() { GLint i = 0; CLIPSPAN(x,y,n,x1,n1,i); @@ -68,59 +92,59 @@ static void TAG(WriteRGBSpan)( const GLcontext *ctx, if (mask) { - for (;i<n1;i++,x1++) + for (;n1>0;i++,x1++,n1--) if (mask[i]) WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); } else { - for (;i<n1;i++,x1++) + for (;n1>0;i++,x1++,n1--) WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); } } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } static void TAG(WriteRGBAPixels)( const GLcontext *ctx, - GLuint n, - const GLint x[], + GLuint n, + const GLint x[], const GLint y[], - const GLubyte rgba[][4], + const GLubyte rgba[][4], const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint i; LOCAL_VARS; if (DBG) fprintf(stderr, "WriteRGBAPixels\n"); - HW_CLIPLOOP() + HW_WRITE_CLIPLOOP() { for (i=0;i<n;i++) { if (mask[i]) { const int fy = Y_FLIP(y[i]); if (CLIPPIXEL(x[i],fy)) - WRITE_RGBA( x[i], fy, - rgba[i][0], rgba[i][1], + WRITE_RGBA( x[i], fy, + rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3] ); } } } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } -static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx, - GLuint n, GLint x, GLint y, +static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx, + GLuint n, GLint x, GLint y, const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint x1; GLint n1; @@ -131,26 +155,26 @@ static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx, if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n"); - HW_CLIPLOOP() + HW_WRITE_CLIPLOOP() { GLint i = 0; CLIPSPAN(x,y,n,x1,n1,i); - for (;i<n1;i++,x1++) + for (;n1>0;i++,x1++,n1--) if (mask[i]) WRITE_PIXEL( x1, y, p ); } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx, - GLuint n, + GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[] ) + const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint i; LOCAL_VARS; @@ -158,7 +182,7 @@ static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx, if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n"); - HW_CLIPLOOP() + HW_WRITE_CLIPLOOP() { for (i=0;i<n;i++) if (mask[i]) { @@ -168,20 +192,16 @@ static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx, } } HW_ENDCLIPLOOP(); - } - HW_UNLOCK(); + } + HW_WRITE_UNLOCK(); } - -/* - * Read a horizontal span of color pixels. - */ static void TAG(ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4]) { - HW_LOCK() + HW_READ_LOCK() { GLint x1,n1; LOCAL_VARS; @@ -190,30 +210,31 @@ static void TAG(ReadRGBASpan)( const GLcontext *ctx, if (DBG) fprintf(stderr, "ReadRGBASpan\n"); - HW_CLIPLOOP() + HW_READ_CLIPLOOP() { GLint i = 0; CLIPSPAN(x,y,n,x1,n1,i); - for (;i<n1;i++) - READ_RGBA( rgba[i], (x1+i), y ); + for (;n1>0;i++,x1++,n1--) + READ_RGBA( rgba[i], x1, y ); } - HW_ENDCLIPLOOP(); + HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_READ_UNLOCK(); } + static void TAG(ReadRGBAPixels)( const GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] ) { - HW_LOCK() + HW_READ_LOCK() { GLint i; LOCAL_VARS; if (DBG) fprintf(stderr, "ReadRGBAPixels\n"); - - HW_CLIPLOOP() + + HW_READ_CLIPLOOP() { for (i=0;i<n;i++) if (mask[i]) { @@ -224,7 +245,7 @@ static void TAG(ReadRGBAPixels)( const GLcontext *ctx, } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_READ_UNLOCK(); } diff --git a/xc/lib/GL/mesa/src/drv/common/stenciltmp.h b/xc/lib/GL/mesa/src/drv/common/stenciltmp.h index d22f6867c..2dada8da7 100644 --- a/xc/lib/GL/mesa/src/drv/common/stenciltmp.h +++ b/xc/lib/GL/mesa/src/drv/common/stenciltmp.h @@ -4,13 +4,26 @@ #define DBG 0 #endif +#ifndef HW_WRITE_LOCK +#define HW_WRITE_LOCK() HW_LOCK() +#endif +#ifndef HW_WRITE_UNLOCK +#define HW_WRITE_UNLOCK() HW_UNLOCK() +#endif + +#ifndef HW_READ_LOCK +#define HW_READ_LOCK() HW_LOCK() +#endif +#ifndef HW_READ_UNLOCK +#define HW_READ_UNLOCK() HW_UNLOCK() +#endif static void TAG(WriteStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLstencil *stencil, const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint x1; GLint n1; @@ -40,7 +53,7 @@ static void TAG(WriteStencilSpan)( GLcontext *ctx, } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } @@ -51,7 +64,7 @@ static void TAG(WriteStencilPixels)( GLcontext *ctx, const GLstencil stencil[], const GLubyte mask[] ) { - HW_LOCK() + HW_WRITE_LOCK() { GLint i; LOCAL_STENCIL_VARS; @@ -71,7 +84,7 @@ static void TAG(WriteStencilPixels)( GLcontext *ctx, } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_WRITE_UNLOCK(); } @@ -81,7 +94,7 @@ static void TAG(ReadStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, GLstencil stencil[]) { - HW_LOCK() + HW_READ_LOCK() { GLint x1,n1; LOCAL_STENCIL_VARS; @@ -99,14 +112,14 @@ static void TAG(ReadStencilSpan)( GLcontext *ctx, } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_READ_UNLOCK(); } static void TAG(ReadStencilPixels)( GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], GLstencil stencil[] ) { - HW_LOCK() + HW_READ_LOCK() { GLint i; LOCAL_STENCIL_VARS; @@ -123,7 +136,7 @@ static void TAG(ReadStencilPixels)( GLcontext *ctx, GLuint n, } HW_ENDCLIPLOOP(); } - HW_UNLOCK(); + HW_READ_UNLOCK(); } diff --git a/xc/lib/GL/mesa/src/drv/i810/i810span.c b/xc/lib/GL/mesa/src/drv/i810/i810span.c index aa4f22d0c..9e86e9b68 100644 --- a/xc/lib/GL/mesa/src/drv/i810/i810span.c +++ b/xc/lib/GL/mesa/src/drv/i810/i810span.c @@ -36,18 +36,18 @@ _y >= miny && _y < maxy) -#define CLIPSPAN(_x,_y,_n,_x1,_n1,_i) \ - if (_y < miny || _y >= maxy) _n1 = 0, _x1 = x; \ - else { \ - _n1 = _n; \ - _x1 = _x; \ - if (_x1 < minx) _i += (minx - _x1), _x1 = minx; \ - if (_x1 + _n1 >= maxx) n1 -= (_x1 + n1 - maxx) + 1; \ - } +#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \ + if ( _y < miny || _y >= maxy ) { \ + _n1 = 0, _x1 = x; \ + } else { \ + _n1 = _n; \ + _x1 = _x; \ + if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \ + if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \ + } #define Y_FLIP(_y) (height - _y - 1) - #define HW_LOCK() \ i810ContextPtr imesa = I810_CONTEXT(ctx); \ LOCK_HARDWARE_QUIESCENT(imesa); diff --git a/xc/lib/GL/mesa/src/drv/i810/i810state.c b/xc/lib/GL/mesa/src/drv/i810/i810state.c index 55f63db2e..cdccbd5ec 100644 --- a/xc/lib/GL/mesa/src/drv/i810/i810state.c +++ b/xc/lib/GL/mesa/src/drv/i810/i810state.c @@ -63,11 +63,18 @@ static void i810DDAlphaFunc(GLcontext *ctx, GLenum func, GLclampf ref) static void i810DDBlendEquation(GLcontext *ctx, GLenum mode) { + i810ContextPtr imesa = I810_CONTEXT(ctx); + if (mode != GL_FUNC_ADD_EXT) { ctx->Color.BlendEquation = GL_FUNC_ADD_EXT; if (0) fprintf(stderr, "Unsupported blend equation: %s\n", gl_lookup_enum_by_nr(mode)); } + + if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) + imesa->Fallback |= I810_FALLBACK_LOGICOP; + else + imesa->Fallback &= ~I810_FALLBACK_LOGICOP; } static void i810DDBlendFunc(GLcontext *ctx, GLenum sfactor, GLenum dfactor) @@ -244,10 +251,10 @@ static void i810DDDither(GLcontext *ctx, GLboolean enable) static void i810DDLogicOp( GLcontext *ctx, GLenum opcode ) { + i810ContextPtr imesa = I810_CONTEXT(ctx); + if (ctx->Color.ColorLogicOpEnabled) { - i810ContextPtr imesa = I810_CONTEXT(ctx); - FLUSH_BATCH( imesa ); if (opcode == GL_COPY) @@ -255,6 +262,8 @@ static void i810DDLogicOp( GLcontext *ctx, GLenum opcode ) else imesa->Fallback |= I810_FALLBACK_LOGICOP; } + else + imesa->Fallback &= ~I810_FALLBACK_LOGICOP; } static GLboolean i810DDSetDrawBuffer(GLcontext *ctx, GLenum mode ) @@ -529,6 +538,13 @@ static void i810DDEnable(GLcontext *ctx, GLenum cap, GLboolean state) imesa->Setup[I810_CTXREG_B1] &= ~B1_BLEND_ENABLE; if (state) imesa->Setup[I810_CTXREG_B1] |= B1_BLEND_ENABLE; + + /* For some reason enable(GL_BLEND) affects ColorLogicOpEnabled. + */ + if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) + imesa->Fallback |= I810_FALLBACK_LOGICOP; + else + imesa->Fallback &= ~I810_FALLBACK_LOGICOP; break; case GL_DEPTH_TEST: FLUSH_BATCH(imesa); @@ -621,7 +637,6 @@ static void i810DDEnable(GLcontext *ctx, GLenum cap, GLboolean state) } break; case GL_COLOR_LOGIC_OP: - case GL_INDEX_LOGIC_OP: FLUSH_BATCH( imesa ); imesa->Fallback &= ~I810_FALLBACK_LOGICOP; if (state && ctx->Color.LogicOp != GL_COPY) diff --git a/xc/lib/GL/mesa/src/drv/mga/Imakefile b/xc/lib/GL/mesa/src/drv/mga/Imakefile index 2630d8159..219690a8f 100644 --- a/xc/lib/GL/mesa/src/drv/mga/Imakefile +++ b/xc/lib/GL/mesa/src/drv/mga/Imakefile @@ -72,6 +72,7 @@ MESA_INCLUDES = -I. -I.. -I../../include \ mgafastpath.c \ mgaioctl.c \ mgapipeline.c \ + mgapixel.c \ mgaspan.c \ mgastate.c \ mgatex.c \ @@ -87,6 +88,7 @@ MESA_INCLUDES = -I. -I.. -I../../include \ mgafastpath.o \ mgaioctl.o \ mgapipeline.o \ + mgapixel.o \ mgaspan.o \ mgastate.o \ mgatex.o \ diff --git a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c index 23e5c0409..c803ac5b5 100644 --- a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c +++ b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.c @@ -132,7 +132,8 @@ drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa ) if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) fprintf(stderr, "\n\nflush"); - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); + + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); } buf = &(mmesa->mgaScreen->bufs->list[idx]); @@ -371,7 +372,7 @@ void mgaDDFinish( GLcontext *ctx ) fprintf(stderr, "mgaRegetLockQuiescent\n"); LOCK_HARDWARE( mmesa ); - mgaUpdateLock( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH); + UPDATE_LOCK( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH ); UNLOCK_HARDWARE( mmesa ); mmesa->sarea->last_quiescent = mmesa->sarea->last_enqueue; @@ -381,7 +382,7 @@ void mgaDDFinish( GLcontext *ctx ) void mgaWaitAgeLocked( mgaContextPtr mmesa, int age ) { if (GET_DISPATCH_AGE(mmesa) < age) { - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); } } @@ -391,7 +392,7 @@ void mgaWaitAge( mgaContextPtr mmesa, int age ) if (GET_DISPATCH_AGE(mmesa) < age) { LOCK_HARDWARE(mmesa); if (GET_DISPATCH_AGE(mmesa) < age) { - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); } UNLOCK_HARDWARE(mmesa); } @@ -581,7 +582,7 @@ void mgaFireILoadLocked( mgaContextPtr mmesa, /* HACK */ - mgaUpdateLock( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH); + UPDATE_LOCK( mmesa, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH ); mga_iload_dma_ioctl( mmesa, offset, length ); } @@ -619,7 +620,7 @@ void mgaDDFlush( GLcontext *ctx ) */ if (1 || GET_DISPATCH_AGE( mmesa ) < mmesa->sarea->last_enqueue) { LOCK_HARDWARE( mmesa ); - mgaUpdateLock( mmesa, DRM_LOCK_FLUSH ); + UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH ); UNLOCK_HARDWARE( mmesa ); } } diff --git a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.h b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.h index e34a0c65b..1f70d3dbc 100644 --- a/xc/lib/GL/mesa/src/drv/mga/mgaioctl.h +++ b/xc/lib/GL/mesa/src/drv/mga/mgaioctl.h @@ -7,10 +7,10 @@ #include "mga_xmesa.h" GLbitfield mgaClear( GLcontext *ctx, GLbitfield mask, GLboolean all, - GLint cx, GLint cy, GLint cw, GLint ch ); + GLint cx, GLint cy, GLint cw, GLint ch ); -void mgaSwapBuffers( mgaContextPtr mmesa ); +void mgaSwapBuffers( mgaContextPtr mmesa ); @@ -21,19 +21,19 @@ void mgaGetILoadBufferLocked( mgaContextPtr mmesa ); drmBufPtr mgaGetBufferLocked( mgaContextPtr mmesa ); -void mgaFireILoadLocked( mgaContextPtr mmesa, +void mgaFireILoadLocked( mgaContextPtr mmesa, GLuint offset, GLuint length ); void mgaWaitAgeLocked( mgaContextPtr mmesa, int age ); void mgaWaitAge( mgaContextPtr mmesa, int age ); int mgaUpdateLock( mgaContextPtr mmesa, drmLockFlags flags ); -void mgaFlushVertices( mgaContextPtr mmesa ); +void mgaFlushVertices( mgaContextPtr mmesa ); void mgaFlushVerticesLocked( mgaContextPtr mmesa ); -void mgaFireEltsLocked( mgaContextPtr mmesa, - GLuint start, +void mgaFireEltsLocked( mgaContextPtr mmesa, + GLuint start, GLuint end, GLuint discard ); @@ -51,7 +51,7 @@ void mgaDDFlush( GLcontext *ctx ); void mgaDDFinish( GLcontext *ctx ); void mgaDDInitIoctlFuncs( GLcontext *ctx ); - + #define FLUSH_BATCH(mmesa) do { \ if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) \ fprintf(stderr, "FLUSH_BATCH in %s\n", __FUNCTION__); \ @@ -70,12 +70,12 @@ GLuint *mgaAllocVertexDwordsInline( mgaContextPtr mmesa, int dwords ) if (!mmesa->vertex_dma_buffer) { LOCK_HARDWARE( mmesa ); - if (mmesa->first_elt != mmesa->next_elt) + if (mmesa->first_elt != mmesa->next_elt) mgaFlushEltsLocked(mmesa); mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa ); UNLOCK_HARDWARE( mmesa ); - } else if (mmesa->vertex_dma_buffer->used + bytes > + } else if (mmesa->vertex_dma_buffer->used + bytes > mmesa->vertex_dma_buffer->total) { LOCK_HARDWARE( mmesa ); mgaFlushVerticesLocked( mmesa ); @@ -83,11 +83,23 @@ GLuint *mgaAllocVertexDwordsInline( mgaContextPtr mmesa, int dwords ) UNLOCK_HARDWARE( mmesa ); } - head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address + + head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address + mmesa->vertex_dma_buffer->used); mmesa->vertex_dma_buffer->used += bytes; return head; } + +#define UPDATE_LOCK( mmesa, flags ) \ +do { \ + GLint ret = drmMGAFlushDMA( mmesa->driFd, flags ); \ + if ( ret ) { \ + drmMGAEngineReset( mmesa ); \ + UNLOCK_HARDWARE( mmesa ); \ + fprintf( stderr, "drmMGAFlushDMA: return = %d\n", ret ); \ + exit( 1 ); \ + } \ +} while (0) + #endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/BUGS b/xc/lib/GL/mesa/src/drv/tdfx/BUGS new file mode 100644 index 000000000..b15f6a91e --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/BUGS @@ -0,0 +1,64 @@ +REMOVE THIS FILE BEFORE MERGING WITH TRUNK +------------------------------------------ + +OUTSTANDING BUGS + +demos/reflect - reading back Z on Voodoo3, image offset to right + Fixed in latest Glide. + +Q3 - some polygons drawn as vertical strips, similar to bug that was + seen in demos/fire. Voodoo3 only. May be related to glDepthMask + or glColorMask. + +book/fog - not fogging + Fog in orthograph mode still not implemented. Checking with + 3dfx engineers for ideas. + +Q3 demo crashes after changing display settings + but the full Q3 game version seems OK. + + + +MORE OUTSTANDING BUGS + +private context was NULL! causing immediate failure of any glx prog. cant +reproduce after restarting the X server. putting it down as halluc. + +texture object image was NULL, causing segmentation failure. happens with +prboom. ive put a check in tdfx_texstate.c but this isn't a fix. + +prboom, wall textures near first chainsaw aren't bound properly. sideways +movements causes the wall textures to move with you. prboom busted? + +16bpp mode, quake3, windowed, q3dm1, floor under rocketlauncher bands. it +looks like multitexturing gone wrong. i'll disable a tmu and test. + +sof, polygons appear at wrong x,y,z positions, intermittent, have not yet +found reliable way of reproducing. culling? sometimes polys disappear. + +descent3 is all black in 16bpp mode - FIXED (palette problems) + +smeared pixels in quake3 - FIXED (texture memory overlapped FB) + + + +PERFORMANCE COMPARISON (Brian / Alan) + + V3/16 is Voodoo3 in 16bpp on a P3/500 + V5/16 is Voodoo5 in 16bpp on a P3/600 + V5/32 is Voodoo5 in 32bpp on a P3/600 + V5A/16 is Voodoo5 in 16bpp on an Alpha AXP/600 + V5A/32 is Voodoo5 in 32bpp on an Alpha AXP/600 + + tdfx-2-1-branch tdfx-3-0-0-branch +demo V3/16 V5/16 V5/32 V3/16 V5/16 V5/32 V5A/16 V5A/32 +------------------------------------------------------------------------ +gloss 257 183 174 320 308 177 313 167 +fire 42 39 52 41 +fire (no help) 98 80 50 106 113 73 124 80 +tunnel 61 50 70 58 +tunnel (no help) 167 142 57 138 152 113 171 122 +gears 663 554 540 881 1232 776 1484 830 +teapot 20 21 37 36 +teapot (no help) 22 14 14 24 30 30 43 42 + diff --git a/xc/lib/GL/mesa/src/drv/tdfx/Imakefile b/xc/lib/GL/mesa/src/drv/tdfx/Imakefile index 160a33da6..ebb353844 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/Imakefile +++ b/xc/lib/GL/mesa/src/drv/tdfx/Imakefile @@ -57,41 +57,43 @@ MESA_INCLUDES = -I. -I.. -I../../include ../../../../dri/drm/xf86drmRandom.o \ ../../../../dri/drm/xf86drmSL.o - TDFXSRCS = tdfx_xmesa.c \ - tdfx_init.c \ - tdfx_inithw.c \ - fxclip.c \ - fxcva.c \ - fxdd.c \ - fxddspan.c \ - fxddtex.c \ - fxfastpath.c \ - fxglidew.c \ - fxpipeline.c \ - fxrender.c \ - fxsanity.c \ - fxsetup.c \ - fxtexman.c \ - fxtrifuncs.c \ - fxvsetup.c - - TDFXOBJS = tdfx_xmesa.o \ - tdfx_init.o \ - tdfx_inithw.o \ - fxclip.o \ - fxcva.o \ - fxdd.o \ - fxddspan.o \ - fxddtex.o \ - fxfastpath.o \ - fxglidew.o \ - fxpipeline.o \ - fxrender.o \ - fxsanity.o \ - fxsetup.o \ - fxtexman.o \ - fxtrifuncs.o \ - fxvsetup.o + TDFXSRCS = tdfx_context.c \ + tdfx_dd.c \ + tdfx_pixels.c \ + tdfx_fastpath.c \ + tdfx_g3ext.c \ + tdfx_lock.c \ + tdfx_pipeline.c \ + tdfx_render.c \ + tdfx_screen.c \ + tdfx_span.c \ + tdfx_state.c \ + tdfx_tex.c \ + tdfx_texman.c \ + tdfx_texstate.c \ + tdfx_tris.c \ + tdfx_vb.c \ + tdfx_wrapper.c \ + tdfx_xmesa.c + + TDFXOBJS = tdfx_context.o \ + tdfx_dd.o \ + tdfx_pixels.o \ + tdfx_fastpath.o \ + tdfx_g3ext.o \ + tdfx_lock.o \ + tdfx_pipeline.o \ + tdfx_render.o \ + tdfx_screen.o \ + tdfx_span.o \ + tdfx_state.o \ + tdfx_tex.o \ + tdfx_texman.o \ + tdfx_texstate.o \ + tdfx_tris.o \ + tdfx_vb.o \ + tdfx_wrapper.o \ + tdfx_xmesa.o MESASRCS = ../../aatriangle.c \ ../../accum.c \ @@ -346,7 +348,6 @@ REQUIREDLIBS = -l$(GLIDE3LIBNAME) MathLibrary REQUIREDLIBS += -L../../../.. -lGL #endif - #if !GlxUseBuiltInDRIDriver #undef DoNormalLib NormalLibGlx #undef DoExtraLib SharedLibGlx diff --git a/xc/lib/GL/mesa/src/drv/tdfx/dri_glide.h b/xc/lib/GL/mesa/src/drv/tdfx/dri_glide.h new file mode 100644 index 000000000..83223b07c --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/dri_glide.h @@ -0,0 +1,63 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __DRI_GLIDE_H__ +#define __DRI_GLIDE_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include <glide.h> +#include "dri_mesaint.h" + +/* + * This is the private interface between Glide and the DRI. + */ +extern void grDRIOpen( char *pFB, char *pRegs, int deviceID, + int width, int height, + int mem, int cpp, int stride, + int fifoOffset, int fifoSize, + int fbOffset, int backOffset, int depthOffset, + int textureOffset, int textureSize, + volatile int *fifoPtr, volatile int *fifoRead ); +extern void grDRIPosition( int x, int y, int w, int h, + int numClip, XF86DRIClipRectPtr pClip ); +extern void grDRILostContext( void ); +extern void grDRIImportFifo( int fifoPtr, int fifoRead ); +extern void grDRIInvalidateAll( void ); +extern void grDRIResetSAREA( void ); +extern void grDRIBufferSwap( FxU32 swapInterval ); +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h deleted file mode 100644 index b84e3c3f2..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h +++ /dev/null @@ -1,353 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxcliptmp.h,v 1.1 2000/09/24 13:51:13 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#define V1 VARS_XYZW -#define S1 DO_SETUP_XYZW -#define T1 COPY_XYZW_STRIDE -#define Z1 4 - -#if (IND & SETUP_RGBA) -#define V2 V1 VARS_RGBA -#define S2 S1 DO_SETUP_RGBA -#define T2 T1 COPY_RGBA_STRIDE -#define Z2 (Z1 + 4) -#else -#define V2 V1 -#define S2 S1 -#define T2 T1 -#define Z2 Z1 -#endif - -#if (IND & SETUP_TMU0) -#define V3 V2 VARS_TMU0 -#define S3 S2 DO_SETUP_TMU0(Z2) -#define T3 T2 COPY_TMU0_STRIDE(Z2) -#define Z3 (Z2 + 2) -#else -#define V3 V2 -#define S3 S2 -#define T3 T2 -#define Z3 Z2 -#endif - -#if (IND & SETUP_TMU1) -#define V4 V3 VARS_TMU1 -#define S4 S3 DO_SETUP_TMU1(Z3) -#define T4 T3 COPY_TMU1_STRIDE(Z3) -#define Z4 (Z3 + 2) -#else -#define V4 V3 -#define S4 S3 -#define T4 T3 -#define Z4 Z3 -#endif - -#if (Z4 & 2) -#define SIZE (Z4+2) -#define COPY_STRIDE T4 COPY_NIL(Z4) -#else -#define SIZE Z4 -#define COPY_STRIDE T4 -#endif - -#define VARS V4 -#define SETUP S4 - -#define DRAW_LINE(fxMesa, tmp0, tmp1, width) \ - if (width <= 1.0) { \ - FX_grDrawLine(fxMesa, tmp0, tmp1); \ - } \ - else { \ - GrVertex verts[4]; \ - float dx, dy, ix, iy; \ - \ - dx = tmp0->x - tmp1->x; \ - dy = tmp0->y - tmp1->y; \ - \ - if (dx * dx > dy * dy) { \ - iy = width * .5; \ - ix = 0; \ - } \ - else { \ - iy = 0; \ - ix = width * .5; \ - } \ - \ - verts[0] = *tmp0; \ - verts[1] = *tmp0; \ - verts[2] = *tmp1; \ - verts[3] = *tmp1; \ - \ - verts[0].x = tmp0->x - ix; \ - verts[0].y = tmp0->y - iy; \ - \ - verts[1].x = tmp0->x + ix; \ - verts[1].y = tmp0->y + iy; \ - \ - verts[2].x = tmp1->x + ix; \ - verts[2].y = tmp1->y + iy; \ - \ - verts[3].x = tmp1->x - ix; \ - verts[3].y = tmp1->y - iy; \ - \ - FX_grDrawPolygonVertexList(fxMesa, 4, verts); \ - } - - - -static void TAG(fx_tri_view_clip) (struct vertex_buffer * VB, - GLuint v[], GLubyte mask) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts[VB_MAX_CLIPPED_VERTS]; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLuint i, n; - GLubyte *clipmask = VB->ClipMask; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - (void) fxMesa; - (void) tmu0_source; - (void) tc0_vec; - (void) tmu1_source; - (void) tc1_vec; - - for (i = 0; i < 3; i++) { - GLuint e = v[i]; - verts[i] = 0; - if (!clipmask[e]) - verts[i] = (GrVertex *) gWin[e].f; - vlist[i] = out; - COPY_STRIDE; - out += SIZE; - } - - if ((n = fx_view_clip_triangle(ctx, vlist, verts, SIZE, mask)) >= 3) { - GrVertex tmp[VB_MAX_CLIPPED_VERTS]; - GrVertex *v = tmp, *v2, *v3; - VARS; - - for (i = 0; i < n; i++) - if (!verts[i]) { - GLfloat *data = vlist[i]; - SETUP; - verts[i] = v++; - } - - v = verts[0]; - v2 = verts[1]; - v3 = verts[2]; - - for (i = 2; i < n; v2 = v3, v3 = verts[++i]) - FX_grDrawTriangle(fxMesa, v, v2, v3); - } -} - - - - - -static void TAG(fx_tri_clip_stride) (struct vertex_buffer * VB, - GLuint v[], GLuint mask) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GrVertex *verts[VB_MAX_CLIPPED_VERTS]; - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLuint i, n; - GLubyte *clipmask = VB->ClipMask; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - (void) fxMesa; - (void) tmu0_source; - (void) tc0_vec; - (void) tmu1_source; - (void) tc1_vec; - - for (i = 0; i < 3; i++) { - GLuint e = v[i]; - verts[i] = 0; - if (!clipmask[e]) - verts[i] = (GrVertex *) gWin[e].f; - vlist[i] = out; - COPY_STRIDE; - out += SIZE; - } - - if (VB->ClipPtr->size < 4) { - vlist[0][3] = vlist[1][3] = vlist[2][3] = 1.0; - if (VB->ClipPtr->size == 2) - vlist[0][2] = vlist[1][2] = vlist[2][2] = 0.0; - } - - if ((n = fx_clip_triangle(ctx, vlist, verts, SIZE, mask)) >= 3) { - GrVertex tmp[VB_MAX_CLIPPED_VERTS]; - GrVertex *v = tmp, *v2, *v3; - VARS; - - for (i = 0; i < n; i++) - if (!verts[i]) { - GLfloat *data = vlist[i]; - SETUP; - verts[i] = v++; - } - - v = verts[0]; - v2 = verts[1]; - v3 = verts[2]; - - for (i = 2; i < n; v2 = v3, v3 = verts[++i]) - FX_grDrawTriangle(fxMesa, v, v2, v3); - } -} - - - -static void TAG(fx_line_clip) (struct vertex_buffer * VB, - GLuint v1, GLuint v2, GLubyte mask) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLfloat data[VB_MAX_CLIPPED_VERTS * 12]; - GLfloat *vlist[VB_MAX_CLIPPED_VERTS]; - GLfloat *out = data; - GLfloat *mat = ctx->Viewport.WindowMap.m; - GLfloat w = ctx->Line.Width * .5; - GLuint e, n; - - GLuint tmu0_source = fxMesa->tmu_source[0]; - GLuint tmu1_source = fxMesa->tmu_source[1]; - GLvector4f *tc0_vec = VB->TexCoordPtr[tmu0_source]; - GLvector4f *tc1_vec = VB->TexCoordPtr[tmu1_source]; - - VARS; - - (void) fxMesa; - (void) tmu0_source; - (void) tc0_vec; - (void) tmu1_source; - (void) tc1_vec; - - vlist[0] = out; - e = v1; - COPY_STRIDE; - out += SIZE; - - vlist[1] = out; - e = v2; - COPY_STRIDE; - out += SIZE; - - if (VB->ClipPtr->size < 4) { - vlist[0][3] = vlist[1][3] = 1.0; - if (VB->ClipPtr->size == 2) - vlist[0][2] = vlist[1][2] = 0.0; - } - - if ((n = fx_clip_line(ctx, vlist, SIZE, mask)) != 0) { - GrVertex gWin[2]; - GrVertex *v; - GLfloat *data; - - v = gWin; - data = vlist[0]; - SETUP; - - v++; - data = vlist[1]; - SETUP; - - DRAW_LINE(fxMesa, gWin, v, w); - } -} - - - -#undef V1 -#undef S1 -#undef C1 -#undef Z1 -#undef T1 - -#undef V2 -#undef S2 -#undef C2 -#undef Z2 -#undef T2 - -#undef V3 -#undef S3 -#undef C3 -#undef Z3 -#undef T3 - -#undef V4 -#undef S4 -#undef C4 -#undef Z4 -#undef T4 - -#undef VARS -#undef SETUP -#undef COPY -#undef COPY_STRIDE -#undef SIZE -#undef IND -#undef TAG diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxcva.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcva.h deleted file mode 100644 index 98ae5f075..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxcva.h +++ /dev/null @@ -1,64 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxcva.h,v 1.1 2000/09/24 13:51:14 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#ifndef _FXCVA_H_ -#define _FXCVA_H_ - - - -extern GLboolean fxMergeAndRenderCVA(struct vertex_buffer *VB, - struct vertex_buffer *cvaVB); - -extern void fxRenderCVAElements(struct vertex_buffer *VB, - GLenum mode, GLuint * elts, GLuint n); - -extern GLboolean fxCheckCVA(GLcontext * ctx); - -extern void fxPrecalcCVA(struct vertex_buffer *VB); - -extern void fxDDCheckMergeAndRender(GLcontext * ctx, - struct gl_pipeline_stage *d); - - -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h deleted file mode 100644 index 20523e33e..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h +++ /dev/null @@ -1,278 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxcvatmp.h,v 1.1 2000/09/24 13:51:14 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -static void TAG(cva_render_points) (struct vertex_buffer * cvaVB, - struct vertex_buffer * VB, - const struct gl_prim_state * state, - GLuint start, GLuint count) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - const GLubyte *clip = cvaVB->ClipMask; - for (i = start; i < count; i++ INCR) { - GLuint e = elt[i]; - if (!clip[e]) { - GLfloat *v = gWin[e].f; - (void) v; - if (!DIRECT) { - MERGE_VB; - } - MERGE_RAST; - DRAW_POINT; - } - } - } - else { - for (i = start; i < count; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; - (void) v; - if (!DIRECT) { - MERGE_VB; - } - MERGE_RAST; - DRAW_POINT; - } - } -} - -static void TAG(cva_render_lines) (struct vertex_buffer * cvaVB, - struct vertex_buffer * VB, - const struct gl_prim_state * state, - GLuint start, GLuint count) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - const GLubyte *clip = cvaVB->ClipMask; - GLuint prev = 0; - GLfloat *prev_v = 0; - - (void) ctx; - - for (i = start; i < count; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; - - MERGE_VB; - - if (!clip[e]) - MERGE_RAST; - - if (state->draw) { - if (clip[e] | clip[prev]) - CLIP_LINE; - else - DRAW_LINE; - } - - prev = e; - prev_v = v; - state = state->next; - } - if (state->finish_loop) { - GLuint e = elt[start]; - GLfloat *v = gWin[e].f; - (void) v; - - if (!DIRECT) { - MERGE_VB; - } - MERGE_RAST; - - if (clip[e] | clip[prev]) - CLIP_LINE; - else - DRAW_LINE; - } - } - else { - GLuint prev = 0; - GLfloat *prev_v = 0; - - for (i = start; i < count; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[e].f; - - if (!DIRECT) { - MERGE_VB; - } - MERGE_RAST; - if (state->draw) - DRAW_LINE; - prev = e; - prev_v = v; - state = state->next; - } - if (state->finish_loop) { - GLuint e = elt[start]; - GLfloat *v = gWin[e].f; - (void) v; - - if (!DIRECT) { - MERGE_VB; - } - MERGE_RAST; - DRAW_LINE; - } - } -} - - -static void TAG(cva_render_tris) (struct vertex_buffer * cvaVB, - struct vertex_buffer * VB, - const struct gl_prim_state * state, - GLuint start, GLuint count) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - fxVertex *gWin = FX_DRIVER_DATA(cvaVB)->verts; - const GLuint *elt = VB->EltPtr->data; - GLuint i; - VARS; - INIT; - (void) fxMesa; - - if (cvaVB->ClipOrMask) { - GLuint vlist[VB_MAX_CLIPPED_VERTS]; - GLuint l[3]; - const GLubyte *clip = cvaVB->ClipMask; - - (void) vlist; - - for (i = start; i < count; i++ INCR) { - GLuint e = l[2] = elt[i]; - GLfloat *v = gWin[e].f; - (void) v; - - MERGE_VB; /* needed for clip-interp */ - - if (!clip[e]) { - MERGE_RAST; - } - - if (state->draw) - CLIP_OR_DRAW_TRI; - - - l[0] = l[state->v0]; - l[1] = l[state->v1]; - state = state->next; - } - } - else if (DIRECT) { - GrVertex *vl[3]; - for (i = start; i < count; i++ INCR) { - GLuint e = elt[i]; - GLfloat *v = gWin[elt[i]].f; - - vl[2] = (GrVertex *) v; - - (void) v; - (void) e; - - MERGE_RAST; - - if (state->draw) - DRAW_TRI2; - - vl[0] = vl[state->v0]; - vl[1] = vl[state->v1]; - state = state->next; - } - } - else { - GLuint l[3]; - for (i = start; i < count; i++ INCR) { - GLuint e = l[2] = elt[i]; - GLfloat *v = gWin[e].f; - (void) v; - - MERGE_VB; /* needed for ctx->trianglefunc? */ - MERGE_RAST; - - if (state->draw) - DRAW_TRI; - - l[0] = l[state->v0]; - l[1] = l[state->v1]; - state = state->next; - } - } -} - - -static void TAG(init_cva) (void) -{ - merge_and_render_tab[DIRECT][IDX][PRIM_POINTS] = TAG(cva_render_points); - merge_and_render_tab[DIRECT][IDX][PRIM_LINES] = TAG(cva_render_lines); - merge_and_render_tab[DIRECT][IDX][PRIM_TRIS] = TAG(cva_render_tris); - merge_and_render_tab[DIRECT][IDX][PRIM_CULLED] = fxCvaRenderNoop; -} - - -#undef IDX -#undef MERGE_RAST -#undef MERGE_VB -#undef VARS -#undef INIT -#undef INCR -#undef TAG diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c deleted file mode 100644 index eaa2ab962..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c +++ /dev/null @@ -1,293 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.c,v 1.1 2000/09/24 13:51:16 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#include "fxdrv.h" -#include "fxcva.h" -#include "fxpipeline.h" -#include "vbindirect.h" - - -/* We don't handle texcoord-4 in the safe clip routines - maybe we should. - */ -static void -fxDDRenderElements(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - - if (fxMesa->render_index != 0 || - ((ctx->Texture.ReallyEnabled & 0xf) && VB->TexCoordPtr[0]->size > 2) - || ((ctx->Texture.ReallyEnabled & 0xf0) - && VB->TexCoordPtr[1]->size > 2) || (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ - gl_render_elts(VB); - else - fxDDRenderElementsDirect(VB); -} - -static void -fxDDCheckRenderVBIndirect(GLcontext * ctx, struct gl_pipeline_stage *d) -{ - d->type = 0; - - if ((ctx->IndirectTriangles & DD_SW_SETUP) == 0 && - ctx->Driver.MultipassFunc == 0) { - d->type = PIPE_IMMEDIATE; - d->inputs = VERT_SETUP_FULL | VERT_ELT | VERT_PRECALC_DATA; - } -} - -static void -fxDDRenderVBIndirect(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - struct vertex_buffer *cvaVB = ctx->CVA.VB; - - if (fxMesa->render_index != 0 || ((ctx->Texture.ReallyEnabled & 0xf) - && cvaVB->TexCoordPtr[0]->size > 2) - || ((ctx->Texture.ReallyEnabled & 0xf0) - && cvaVB->TexCoordPtr[1]->size > 2) || (VB->ClipPtr->size != 4)) /* Brokes clipping otherwise */ - gl_render_vb_indirect(VB); - else - fxDDRenderVBIndirectDirect(VB); -} - - -static void -fxDDRenderVB(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - - 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); - else - fxDDDoRenderVB(VB); -} - - - - -/* This sort of driver-based reconfiguration of the pipeline could be - * used to support accelerated transformation and lighting on capable - * hardware. - * - */ -GLuint -fxDDRegisterPipelineStages(struct gl_pipeline_stage *out, - const struct gl_pipeline_stage *in, GLuint nr) -{ - GLuint i, o; - - for (i = o = 0; i < nr; i++) { - switch (in[i].ops) { - case PIPE_OP_RAST_SETUP_1 | PIPE_OP_RENDER: - out[o] = in[i]; - out[o].state_change = NEW_CLIENT_STATE; - out[o].check = fxDDCheckMergeAndRender; - out[o].run = fxDDMergeAndRender; - o++; - break; - case PIPE_OP_RAST_SETUP_0: - out[o] = in[i]; - out[o].cva_state_change = - NEW_LIGHTING | NEW_TEXTURING | NEW_RASTER_OPS; - out[o].state_change = ~0; - out[o].check = fxDDCheckPartialRasterSetup; - out[o].run = fxDDPartialRasterSetup; - o++; - break; - case PIPE_OP_RAST_SETUP_0 | PIPE_OP_RAST_SETUP_1: - out[o] = in[i]; - out[o].run = fxDDDoRasterSetup; - o++; - break; - case PIPE_OP_RENDER: - out[o] = in[i]; - if (in[i].run == gl_render_elts) { - out[o].run = fxDDRenderElements; - } - else if (in[i].run == gl_render_vb_indirect) { - out[o].check = fxDDCheckRenderVBIndirect; - out[o].run = fxDDRenderVBIndirect; - } - else if (in[i].run == gl_render_vb) { - out[o].run = fxDDRenderVB; - } - - o++; - break; - default: - out[o++] = in[i]; - break; - } - } - - return o; -} - -#define ILLEGAL_ENABLES (TEXTURE0_3D| \ - TEXTURE1_3D| \ - ENABLE_TEXMAT0 | \ - ENABLE_TEXMAT1 | \ - ENABLE_TEXGEN0 | \ - ENABLE_TEXGEN1 | \ - ENABLE_USERCLIP | \ - ENABLE_LIGHT | \ - ENABLE_FOG) - - - -/* Because this is slotted in by the OptimizePipeline function, most - * of the information here is just for gl_print_pipeline(). Only the - * run member is required. - */ -static struct gl_pipeline_stage fx_fast_stage = { - "FX combined vertex transform, setup and rasterization stage", - PIPE_OP_VERT_XFORM | PIPE_OP_RAST_SETUP_0 | PIPE_OP_RAST_SETUP_1 | - PIPE_OP_RENDER, - PIPE_PRECALC, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* never called */ - fxDDFastPath -}; - - - - -/* Better than optimizing the pipeline, we can do the whole build very - * quickly with the aid of a new flags member. - */ -GLboolean -fxDDBuildPrecalcPipeline(GLcontext * ctx) -{ - struct gl_pipeline *pipe = &ctx->CVA.pre; - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - - if (fxMesa->is_in_hardware && - fxMesa->render_index == 0 && - (ctx->Enabled & ILLEGAL_ENABLES) == 0 && - (ctx->Array.Flags & (VERT_OBJ_234 | - VERT_TEX0_4 | - VERT_TEX1_4 | - VERT_ELT)) == (VERT_OBJ_23 | VERT_ELT)) { - if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) - if (!fxMesa->using_fast_path) - fprintf(stderr, "fxMesa: using fast path\n"); - - pipe->stages[0] = &fx_fast_stage; - pipe->stages[1] = 0; - pipe->new_inputs = ctx->RenderFlags & VERT_DATA; - pipe->ops = pipe->stages[0]->ops; - fxMesa->using_fast_path = 1; - return 1; - } - - if (fxMesa->using_fast_path) { - if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) - fprintf(stderr, - "fxMesa: fall back to full pipeline %x %x %x %x %x\n", - fxMesa->is_in_hardware, fxMesa->render_index, - (ctx->Enabled & ILLEGAL_ENABLES), - (ctx->Array.Summary & (VERT_OBJ_23)), - (ctx->Array.Summary & (VERT_OBJ_4 | VERT_TEX0_4 | - VERT_TEX1_4))); - - fxMesa->using_fast_path = 0; - ctx->CVA.VB->ClipOrMask = 0; - ctx->CVA.VB->ClipAndMask = CLIP_ALL_BITS; - ctx->Array.NewArrayState |= ctx->Array.Summary; - return 0; - } - - return 0; -} - - - - - - -/* Perform global optimizations to the pipeline. The fx driver - * implements a single such fast path, which corresponds to the standard - * quake3 cva pipeline. - * - * This is now handled by the 'build' function above. - */ -void -fxDDOptimizePrecalcPipeline(GLcontext * ctx, struct gl_pipeline *pipe) -{ - fxMesaContext fxMesa = FX_CONTEXT(ctx); - - if (fxMesa->is_in_hardware && - fxMesa->render_index == 0 && - (ctx->Enabled & ILLEGAL_ENABLES) == 0 && - (ctx->Array.Summary & VERT_ELT)) { - pipe->stages[0] = &fx_fast_stage; - pipe->stages[1] = 0; - } -} - - - -/* unused? -void -fxDDOptimizeEltPipeline( GLcontext *ctx, struct gl_pipeline *pipe ) -{ - (void) ctx; - (void) pipe; -} -*/ - diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h b/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h deleted file mode 100644 index 49a98320d..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h +++ /dev/null @@ -1,16 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxpipeline.h,v 1.1 2000/09/24 13:51:16 alanh Exp $ */ -#ifndef FXPIPELINE_H -#define FXPIPELINE_H - - -extern GLuint fxDDRegisterPipelineStages(struct gl_pipeline_stage *out, - const struct gl_pipeline_stage *in, - GLuint nr); - -extern GLboolean fxDDBuildPrecalcPipeline(GLcontext * ctx); - -extern void fxDDOptimizePrecalcPipeline(GLcontext * ctx, - struct gl_pipeline *pipe); - - -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxrender.c b/xc/lib/GL/mesa/src/drv/tdfx/fxrender.c deleted file mode 100644 index 2ec5fa4b3..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxrender.c +++ /dev/null @@ -1,780 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxrender.c,v 1.2 2000/11/13 23:31:32 dawes Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxrender.c - 3Dfx VooDoo RenderVB driver function support */ - -#include "fxdrv.h" -#include "vbcull.h" -#include "fxsetup.h" - - - -/* - * Render a line segment from VB[v1] to VB[v2] when either one or both - * endpoints must be clipped. - */ -#if !defined(__MWERKS__) -INLINE -#endif - void -fxRenderClippedLine(struct vertex_buffer *VB, GLuint v1, GLuint v2) -{ - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; - - if (!mask || (VB->ctx->line_clip_tab[VB->ClipPtr->size]) (VB, &v1, &v2, - mask)) - FX_grDrawLine(fxMesa, (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v2].f); -} - - - - -/* This is legal for Quads as well as triangles, hence the 'n' parameter. - */ -INLINE void -fxRenderClippedTriangle(struct vertex_buffer *VB, GLuint n, GLuint vlist[]) -{ - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - GLubyte mask = 0; - GLuint i; - - for (i = 0; i < n; i++) - mask |= VB->ClipMask[vlist[i]]; - - if (mask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[vlist[0]] & userclipmask[vlist[1]] & - userclipmask[vlist[2]]) - return; - } - - n = (VB->ctx->poly_clip_tab[VB->ClipPtr->size]) (VB, n, vlist, mask); - if (n >= 3) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GrVertex *i0 = (GrVertex *) gWin[vlist[0]].f; - GrVertex *i1 = (GrVertex *) gWin[vlist[1]].f; - GrVertex *i2 = (GrVertex *) gWin[vlist[2]].f; - GLuint i; - - for (i = 2; i < n; i++, i1 = i2, i2 = (GrVertex *) gWin[vlist[i]].f) { - FX_grDrawTriangle(fxMesa, i0, i1, i2); - } - } -} - - - - - -static INLINE void -fxSafeClippedLine(struct vertex_buffer *VB, GLuint v1, GLuint v2) -{ - GLubyte mask = VB->ClipMask[v1] | VB->ClipMask[v2]; - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - - if (!mask) { - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - FX_grDrawLine(fxMesa, (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v2].f); - } - else { - fxMesaContext fxMesa = (fxMesaContext) VB->ctx->DriverCtx; - fxLineClipTab[fxMesa->setupindex & 0x7] (VB, v1, v2, mask); - } -} - - -static INLINE void -fxSafeClippedTriangle(struct vertex_buffer *VB, - fxVertex * gWin, - tfxTriClipFunc cliptri, GLuint v2, GLuint v1, GLuint v) -{ - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - - if (!mask) { - FX_grDrawTriangle(fxMesa, (GrVertex *) gWin[v2].f, - (GrVertex *) gWin[v1].f, (GrVertex *) gWin[v].f); - return; - } - - if (!(clipmask[v2] & clipmask[v1] & clipmask[v] & CLIP_ALL_BITS)) { - GLuint vl[3]; - GLuint imask = mask; - - if (imask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) - return; - imask |= - (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; - } - - ASSIGN_3V(vl, v2, v1, v); - cliptri(VB, vl, imask); - } -} - - -static INLINE void -fxSafeClippedTriangle2(struct vertex_buffer *VB, - fxVertex * gWin, - tfxTriViewClipFunc cliptri, - GLuint v2, GLuint v1, GLuint v) -{ - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - - if (!mask) { - FX_grDrawTriangle(fxMesa, - (GrVertex *) gWin[v2].f, (GrVertex *) gWin[v1].f, - (GrVertex *) gWin[v].f); - } - else if (!(clipmask[v2] & clipmask[v1] & clipmask[v])) { - GLuint vl[3]; - ASSIGN_3V(vl, v2, v1, v); - cliptri(VB, vl, mask); - } -} - - -static INLINE void -fxSafeClippedTriangle3(struct vertex_buffer *VB, - fxVertex * gWin, - tfxTriClipFunc cliptri, GLuint v2, GLuint v1, GLuint v) -{ - GLubyte *clipmask = VB->ClipMask; - GLubyte mask = clipmask[v2] | clipmask[v1] | clipmask[v]; - GLuint imask = mask; - - if (imask & CLIP_USER_BIT) { - GLubyte *userclipmask = VB->UserClipMask; - if (userclipmask[v2] & userclipmask[v1] & userclipmask[v]) - return; - imask |= (userclipmask[v2] | userclipmask[v1] | userclipmask[v]) << 8; - } - - { - GLuint vl[3]; - ASSIGN_3V(vl, v2, v1, v); - cliptri(VB, vl, imask); - } -} - - - - - -/************************************************************************/ -/************************ RenderVB functions ****************************/ -/************************************************************************/ - - -/* Render front-facing, non-clipped primitives. - */ - -#define RENDER_POINTS( start, count ) \ - (void) gWin; \ - (void) VB; \ - (VB->ctx->Driver.PointsFunc)( VB->ctx, start, count ) - -#define RENDER_LINE( i1, i ) \ - do { \ - RVB_COLOR(i); \ - FX_grDrawLine(fxMesa, (GrVertex *)gWin[i1].f, \ - (GrVertex *)gWin[i].f); \ - } while (0) - -#define RENDER_TRI( i2, i1, i, pv, parity ) \ - do { \ - RVB_COLOR(pv); \ - if (parity) { \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i1].f, \ - (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i].f); \ - } else { \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i1].f, \ - (GrVertex *)gWin[i].f); \ - } \ - } while (0) - -#define RENDER_QUAD( i3, i2, i1, i, pv ) \ - do { \ - RVB_COLOR(pv); \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i3].f, \ - (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i].f); \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i1].f, \ - (GrVertex *)gWin[i].f); \ - } while (0) - - - -#define LOCAL_VARS \ - fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - (void) fxMesa; - -#define INIT(x) - -#define TAG(x) x##_fx_flat_raw -#undef RVB_COLOR -#define RVB_COLOR(pv) FX_VB_COLOR(fxMesa, VB->ColorPtr->data[pv]) -#define PRESERVE_VB_DEFS - -#include "render_tmp.h" - -#define TAG(x) x##_fx_smooth_raw -#undef RVB_COLOR -#define RVB_COLOR(x) - -#include "render_tmp.h" - - - -/* Render with clipped and/or culled primitives with cullmask information. - */ -#define RENDER_POINTS( start, count ) \ - (void) gWin; \ - (void) cullmask; \ - (VB->ctx->Driver.PointsFunc)( VB->ctx, start, count ) - - -#define RENDER_LINE( i1, i ) \ - do { \ - const GLubyte flags = cullmask[i]; \ - \ - if (!(flags & PRIM_NOT_CULLED)) \ - continue; \ - \ - RVB_COLOR(i); \ - if (flags & PRIM_ANY_CLIP) \ - fxRenderClippedLine( VB, i1, i ); \ - else \ - FX_grDrawLine( fxMesa, (GrVertex *)gWin[i1].f, (GrVertex *)gWin[i].f ); \ - } while (0) - - -#define RENDER_TRI( i2, i1, i, pv, parity) \ - do { \ - const GLubyte flags = cullmask[i]; \ - GLuint e2,e1; \ - \ - if (!(flags & PRIM_NOT_CULLED)) \ - continue; \ - \ - e2=i2, e1=i1; \ - if (parity) { e2=i1; e1=i2; } \ - \ - RVB_COLOR(pv); \ - if (flags & PRIM_ANY_CLIP) { \ - fxSafeClippedTriangle3(VB,gWin,cliptri,e2,e1,i); \ - } else { \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e1].f, \ - (GrVertex *)gWin[i].f); \ - } \ - } while (0) - - -#define RENDER_QUAD(i3, i2, i1, i, pv) \ - do { \ - const GLubyte flags = cullmask[i]; \ - \ - if (!(flags & PRIM_NOT_CULLED)) \ - continue; \ - \ - RVB_COLOR(pv); \ - if (flags&PRIM_ANY_CLIP) { \ - fxSafeClippedTriangle3(VB,gWin,cliptri,i3,i2,i); \ - fxSafeClippedTriangle3(VB,gWin,cliptri,i2,i1,i); \ - } else { \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i3].f, \ - (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i].f); \ - FX_grDrawTriangle(fxMesa, (GrVertex *)gWin[i2].f, \ - (GrVertex *)gWin[i1].f, \ - (GrVertex *)gWin[i].f); \ - } \ - } while (0) - - - - - -#define LOCAL_VARS \ - fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - const GLubyte *cullmask = VB->CullMask; \ - tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - - - - -#define INIT(x) (void) cliptri; (void) fxMesa; - -#define TAG(x) x##_fx_smooth_culled -#undef RVB_COLOR -#define RVB_COLOR(x) -#define PRESERVE_VB_DEFS -#include "render_tmp.h" - -#define TAG(x) x##_fx_flat_culled -#undef RVB_COLOR -#define RVB_COLOR(pv) FX_VB_COLOR(fxMesa, VB->ColorPtr->data[pv]) - -#include "render_tmp.h" - - - - -/* Direct, with the possibility of clipping. - */ -#define RENDER_POINTS( start, count ) \ - do { \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - GLubyte *clipmask = VB->ClipMask; \ - GLuint i; \ - for (i = start ; i < count ; i++) \ - if (clipmask[i] == 0) { \ - RVB_COLOR(i); \ - FX_grDrawPoint( fxMesa, (GrVertex *)gWin[i].f );\ - } \ - } while (0) - -#define RENDER_LINE( i1, i ) \ - do { \ - RVB_COLOR(i); \ - fxSafeClippedLine( VB, i1, i ); \ - } while (0) - -#define RENDER_TRI( i2, i1, i, pv, parity) \ - do { \ - GLuint e2=i2, e1=i1; \ - if (parity) { GLuint t=e2; e2=e1; e1=t; } \ - RVB_COLOR(pv); \ - fxSafeClippedTriangle(VB,gWin,cliptri,e2,e1,i); \ - } while (0) - -#define RENDER_QUAD( i3, i2, i1, i, pv) \ - do { \ - RVB_COLOR(pv); \ - fxSafeClippedTriangle(VB,gWin,cliptri,i3,i2,i); \ - fxSafeClippedTriangle(VB,gWin,cliptri,i2,i1,i); \ - } while (0) - -#define LOCAL_VARS \ - fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - -#define INIT(x) (void) cliptri; (void) gWin; - -#define TAG(x) x##_fx_smooth_clipped -#undef RVB_COLOR -#define RVB_COLOR(x) -#define PRESERVE_VB_DEFS -#include "render_tmp.h" - - -#define TAG(x) x##_fx_flat_clipped -#undef RVB_COLOR -#define RVB_COLOR(pv) FX_VB_COLOR(fxMesa, VB->ColorPtr->data[pv]) -#include "render_tmp.h" - - - - - - -/* Indirect, with the possibility of clipping. - */ -#define RENDER_POINTS( start, count ) \ - do { \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - GLuint e; \ - GLubyte *clipmask = VB->ClipMask; \ - for(e=start;e<count;e++) \ - if(clipmask[elt[e]]==0) { \ - FX_grDrawPoint(fxMesa, (GrVertex *)gWin[elt[e]].f); \ - } \ - } while (0) - -#define RENDER_LINE( i1, i ) \ - do { \ - GLuint e1 = elt[i1], e = elt[i]; \ - RVB_COLOR(e); \ - fxSafeClippedLine( VB, e1, e ); \ - } while (0) - -#define RENDER_TRI( i2, i1, i, pv, parity) \ - do { \ - GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ - if (parity) { GLuint t=e2; e2=e1; e1=t; } \ - fxSafeClippedTriangle(VB,gWin,cliptri,e2,e1,e); \ - } while (0) - -#define RENDER_QUAD( i3, i2, i1, i, pv) \ - do { \ - GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];\ - fxSafeClippedTriangle(VB,gWin,cliptri,e3,e2,e); \ - fxSafeClippedTriangle(VB,gWin,cliptri,e2,e1,e); \ - } while (0) - -#define LOCAL_VARS const GLuint *elt = VB->EltPtr->data; \ - fxMesaContext fxMesa = (fxMesaContext)VB->ctx->DriverCtx; \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - -#define INIT(x) (void) cliptri; (void) gWin; - -#define TAG(x) x##_fx_smooth_indirect_clipped -#undef RVB_COLOR -#define RVB_COLOR(x) -#include "render_tmp.h" - - -/* Indirect, clipped, but no user clip. - */ -#define RENDER_POINTS( start, count ) \ - do { \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - GLuint e; \ - GLubyte *clipmask = VB->ClipMask; \ - for(e=start;e<count;e++) \ - if(clipmask[elt[e]]==0) { \ - FX_grDrawPoint(fxMesa, (GrVertex *)gWin[elt[e]].f); \ - } \ - } while (0) - -#define RENDER_LINE( i1, i ) \ - do { \ - GLuint e1 = elt[i1], e = elt[i]; \ - RVB_COLOR(e); \ - fxSafeClippedLine( VB, e1, e ); \ - } while (0) - -#define RENDER_TRI( i2, i1, i, pv, parity) \ - do { \ - GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ - if (parity) { GLuint t=e2; e2=e1; e1=t; } \ - fxSafeClippedTriangle2(VB,gWin,cliptri,e2,e1,e); \ - } while (0) - -#define RENDER_QUAD( i3, i2, i1, i, pv) \ - do { \ - GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];\ - fxSafeClippedTriangle2(VB,gWin,cliptri,e3,e2,e); \ - fxSafeClippedTriangle2(VB,gWin,cliptri,e2,e1,e); \ - } while (0) - -#define LOCAL_VARS const GLuint *elt = VB->EltPtr->data; \ - fxMesaContext fxMesa = (fxMesaContext)VB->ctx->DriverCtx; \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - tfxTriViewClipFunc cliptri = fxMesa->view_clip_tri; - -#define INIT(x) (void) cliptri; (void) gWin; - -#define TAG(x) x##_fx_smooth_indirect_view_clipped -#undef RVB_COLOR -#define RVB_COLOR(x) -#include "render_tmp.h" - - - - - - - -/* Indirect, and no clipping required. - */ -#define RENDER_POINTS( start, count ) \ - do { \ - GLuint e; \ - for(e=start;e<count;e++) { \ - FX_grDrawPoint_NoLock((GrVertex *)gWin[elt[e]].f);\ - } \ - } while (0) - -#define RENDER_LINE( i1, i ) \ - do { \ - GLuint e1 = elt[i1], e = elt[i]; \ - FX_grDrawLine_NoLock((GrVertex *)gWin[e1].f, (GrVertex *)gWin[e].f);\ - } while (0) - - -#define RENDER_TRI( i2, i1, i, pv, parity) \ - do { \ - GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ - if (parity) {GLuint tmp = e2; e2 = e1; e1 = tmp;} \ - FX_grDrawTriangle_NoLock((GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e1].f, \ - (GrVertex *)gWin[e].f); \ - } while (0) - - -#define RENDER_QUAD( i3, i2, i1, i, pv) \ - do { \ - GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];\ - FX_grDrawTriangle_NoLock((GrVertex *)gWin[e3].f, \ - (GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e].f); \ - FX_grDrawTriangle_NoLock((GrVertex *)gWin[e2].f, \ - (GrVertex *)gWin[e1].f, \ - (GrVertex *)gWin[e].f); \ - } while (0) - -#define LOCAL_VARS \ - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; \ - const GLuint *elt = VB->EltPtr->data; \ - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - -#define INIT(x) BEGIN_CLIP_LOOP(fxMesa); -#define POSTFIX END_CLIP_LOOP(fxMesa); - -#define TAG(x) x##_fx_smooth_indirect -#undef RVB_COLOR -#define RVB_COLOR(x) -#include "render_tmp.h" - - - - - -/* Direct in this context means that triangles, lines, points can be - * rendered simply by calling grDrawTriangle, etc., without any - * additional setup (such as calling grConstantColor). We also use a - * 'safe' set of clipping routines which don't require write-access to - * the arrays in the vertex buffer, and don't care about array - * stride. - * - * Thus there is no call to gl_import_arrays() in this function. - * - * This safe clipping should be generalized to call driver->trianglefunc - * under the appropriate conditions. - * - * We don't handle texcoord-4 in the safe clip routines - maybe we should. - * - */ -void -fxDDRenderElementsDirect(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - struct vertex_buffer *saved_vb = ctx->VB; - GLenum prim = ctx->CVA.elt_mode; - GLuint nr = VB->EltPtr->count; - render_func func = render_tab_fx_smooth_indirect[prim]; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLuint p = 0; - - if (!nr) - return; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - if (!nr) - return; - - if (VB->ClipOrMask) { - func = render_tab_fx_smooth_indirect_view_clipped[prim]; - if (VB->ClipOrMask & CLIP_USER_BIT) - func = render_tab_fx_smooth_indirect_clipped[prim]; - } - - ctx->VB = VB; /* kludge */ - - do { - func(VB, 0, nr, 0); - } while (ctx->Driver.MultipassFunc && ctx->Driver.MultipassFunc(VB, ++p)); - - - ctx->VB = saved_vb; -} - - -void -fxDDRenderVBIndirectDirect(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - struct vertex_buffer *cvaVB = ctx->CVA.VB; - struct vertex_buffer *saved_vb = ctx->VB; - GLuint i, next, count = VB->Count; - render_func *tab = render_tab_fx_smooth_indirect; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLuint p = 0; - - if (cvaVB->ClipOrMask) - tab = render_tab_fx_smooth_indirect_clipped; - - if (!VB->CullDone) - gl_fast_copy_vb(VB); - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - ctx->VB = cvaVB; - cvaVB->EltPtr = VB->EltPtr; - - do { - GLuint parity = VB->Parity; - - for (i = VB->CopyStart; i < count; parity = 0, i = next) { - GLuint prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - tab[prim] (cvaVB, i, next, parity); - } - /* loop never taken */ - } while (ctx->Driver.MultipassFunc && - ctx->Driver.MultipassFunc(cvaVB, ++p)); - - cvaVB->EltPtr = 0; - ctx->VB = saved_vb; -} - - -static render_func *fxDDRenderVBSmooth_tables[3] = { - render_tab_fx_smooth_clipped, - render_tab_fx_smooth_culled, - render_tab_fx_smooth_raw -}; - -static render_func *fxDDRenderVBFlat_tables[3] = { - render_tab_fx_flat_clipped, - render_tab_fx_flat_culled, - render_tab_fx_flat_raw -}; - - -static render_func *null_tables[3] = { - 0, - 0, - 0 -}; - -#if defined(FX_GLIDE3) -#include "fxstripdet.c" -#endif - -void -fxDDRenderInit(GLcontext * ctx) -{ - render_init_fx_smooth_indirect_view_clipped(); - render_init_fx_smooth_indirect_clipped(); - render_init_fx_smooth_indirect(); - render_init_fx_smooth_raw(); - render_init_fx_smooth_culled(); - render_init_fx_smooth_clipped(); - render_init_fx_flat_raw(); - render_init_fx_flat_culled(); - render_init_fx_flat_clipped(); -#if defined(FX_GLIDE3) - fxDDRenderInitGlide3(ctx); -#endif -} - - -/* Now used to set an internal var in fxMesa - we hook out at the - * level of gl_render_vb() instead. - */ -render_func ** -fxDDChooseRenderVBTables(GLcontext * ctx) -{ - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - - if (ctx->IndirectTriangles & DD_SW_SETUP) - return null_tables; - - switch (fxMesa->render_index) { -/* case FX_FLAT: */ -/* return fxDDRenderVBFlat_tables; */ - case 0: - return fxDDRenderVBSmooth_tables; - default: - return null_tables; - } -} - - -void -fxDDDoRenderVB(struct vertex_buffer *VB) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLuint i, next, prim; - GLuint parity = VB->Parity; - render_func *tab; - GLuint count = VB->Count; - GLint p = 0; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - if (VB->Indirect) { - return; - } - else if (VB->CullMode & CLIP_MASK_ACTIVE) { - tab = fxMesa->RenderVBClippedTab; - } - else { - tab = fxMesa->RenderVBRawTab; - } - - if (!VB->CullDone) - gl_fast_copy_vb(VB); - - do { - for (i = VB->CopyStart; i < count; parity = 0, i = next) { - prim = VB->Primitive[i]; - next = VB->NextPrimitive[i]; - tab[prim] (VB, i, next, parity); - } - - } while (ctx->Driver.MultipassFunc && ctx->Driver.MultipassFunc(VB, ++p)); -} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h deleted file mode 100644 index 95794538c..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h +++ /dev/null @@ -1,154 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxsdettmp.h,v 1.1 2000/09/24 13:51:19 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* - * Notes: the folowing code works only if count is > start. - * Corrently we are looking for the pattern: - * v0,v1,v2 v2,v1,v3, v2,v3,v4.... - * - * For this: - * #define STRIP0 ((u1 == v1) && (u2 == v0)) - * #define STRIP1 ((u0 == v0) && (u2 == v1)) - * - */ - - -static void TAG(render_vb_triangles_smooth_indirect_sd) - (struct vertex_buffer * VB, GLuint start, GLuint count, GLuint parity) -{ - GLint u0, u1, u2; - GLint v0, v1, v2; - GLuint *elt = VB->EltPtr->data; - - int i; - LOCAL_VARS INIT(GL_TRIANGLES); - - elt = &elt[start - 1]; - u0 = *(++elt); - u1 = *(++elt); - u2 = *(++elt); - i = start + 3; - while (i < count) { - v0 = *(++elt); - v1 = *(++elt); - v2 = *(++elt); - - if (CLIPPED(u0, u1, u2)) { - if (!CULLED(u0, u1, u2)) - SENDCLIPTRI(u0, u1, u2); - } - else { - if (STRIP0(u, v)) { - int is_strips = 1; - int parity = 0; - STRIPSLOCAL_VAR FLUSHTRI(); - STARTSTRIPS(u0, u1, u2); - while (is_strips && i < count) { - SENDSTRIPS(v2); - - u0 = v0; - u1 = v1; - u2 = v2; - i += 3; - v0 = *(++elt); - v1 = *(++elt); - v2 = *(++elt); - - if (parity) { - is_strips = STRIP0(u, v); - parity = 0; - } - else { - is_strips = STRIP1(u, v); - parity = 1; - } - } - FLUSHSTRIPS(); - - if (i >= count) - return; - } - else { - SENDTRI(u0, u1, u2); - } - } - u0 = v0; - u1 = v1; - u2 = v2; - i += 3; - } - if (CLIPPED(u0, u1, u2)) { - if (!CULLED(u0, u1, u2)) - SENDCLIPTRI(u0, u1, u2); - } - else { - SENDTRI(u0, u1, u2); - } - FLUSHTRI(); - -} - -#ifndef PRESERVE_VB_DEFS -#undef SENDTRI -#undef STRIP0 -#undef STRIP1 -#undef LOCAL_VARS -#undef STRIPSLOCAL_VAR -#undef INIT -#undef SENDTRI -#undef FLUSHTRI -#undef STARTSTRIPS -#undef SENDSTRIPS -#undef FLUSHSTRIPS -#undef CLIPPED -#undef CULLED -#undef SENDCLIPTRI -#endif - -#ifndef PRESERVE_TAG -#undef TAG -#endif - -#undef PRESERVE_VB_DEFS -#undef PRESERVE_TAG diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c b/xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c deleted file mode 100644 index 98e62b1ff..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c +++ /dev/null @@ -1,161 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxstripdet.c,v 1.1 2000/09/24 13:51:19 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#include "fxdrv.h" -#include "vbcull.h" - - -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) -#define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) - -#define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ - GrVertex** sb = FX_DRIVER_DATA(VB)->strips_b;\ - fxMesaContext fxMesa = FX_CONTEXT(VB->ctx); - - -#define STRIPSLOCAL_VAR int sc = 0; - -#define INIT(a) - -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ -#define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } -#define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) - -#define CLIPPED(a,b,c) 0 -#define CULLED(a,b,c) 0 -#define SENDCLIPTRI(a,b,c) /* NoOp */ - -#define TAG(x) x##_fx - -#include "fxsdettmp.h" - - -/* Clipped but no userclip */ -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] -#define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) && !clipmask[v2] - -#define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ - GrVertex** sb = FX_DRIVER_DATA(VB)->strips_b; \ - const GLubyte *const clipmask = VB->ClipMask; \ - const fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ - const tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - -#define STRIPSLOCAL_VAR int sc = 0; - -#define INIT(a) - -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ -#define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } -#define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) - -#define CLIPPED(u0,u1,u2) (clipmask[u0] | clipmask[u1] | clipmask[u2]) -#define CULLED(u0,u1,u2) (clipmask[u0] & clipmask[u1] & clipmask[u2]) -#define SENDCLIPTRI(u0,u1,u2) { \ - GLuint vl[3]; \ - ASSIGN_3V(vl, u0, u1, u2 ); \ - cliptri(VB,vl,clipmask[u0] | clipmask[u1] | clipmask[u2]); \ - } - -#define TAG(x) x##_fx_view_clipped - -#include "fxsdettmp.h" - -/* Clipped and might be userclip */ -#define STRIP0(u,v) ((u1 == v1) && (u2 == v0)) && !clipmask[v2] -#define STRIP1(u,v) ((u0 == v0) && (u2 == v1)) && !clipmask[v2] - -#define LOCAL_VARS fxVertex* gWin = FX_DRIVER_DATA(VB)->verts; \ - GrVertex** sb = FX_DRIVER_DATA(VB)->strips_b; \ - const GLubyte *const clipmask = VB->ClipMask; \ - const GLubyte *userclipmask = VB->UserClipMask; \ - const fxMesaContext fxMesa=(fxMesaContext)VB->ctx->DriverCtx; \ - const tfxTriClipFunc cliptri = fxMesa->clip_tri_stride; - -#define STRIPSLOCAL_VAR int sc = 0; - -#define INIT(a) - -#define SENDTRI(u0,u1,u2) FX_grDrawTriangle(fxMesa, (GrVertex*)&(gWin[u0].f),(GrVertex*)&(gWin[u1].f),(GrVertex*)&(gWin[u2].f)) -#define FLUSHTRI() /* No-Op */ -#define STARTSTRIPS(u0,u1,u2) { sb[sc++] = (GrVertex*)&(gWin[u0].f); sb[sc++] = (GrVertex*)&(gWin[u1].f); sb[sc++] = (GrVertex*)&(gWin[u2].f); } -#define SENDSTRIPS(v2) { sb[sc++] = (GrVertex*)&(gWin[v2].f); } -#define FLUSHSTRIPS() FX_grDrawVertexArray(fxMesa, GR_TRIANGLE_STRIP,sc,sb) - -#define CLIPPED(u0,u1,u2) (clipmask[u0] | clipmask[u1] | clipmask[u2]) -#define CULLED(u0,u1,u2) (clipmask[u0] & clipmask[u1] & clipmask[u2] & CLIP_ALL_BITS) -#define SENDCLIPTRI(u0,u1,u2) { \ - GLuint vl[3]; \ - GLuint imask = (clipmask[u0] | clipmask[u1] | clipmask[u2]); \ - \ - if (imask & CLIP_USER_BIT) { \ - if (!(userclipmask[u2] & userclipmask[u1] & userclipmask[u0])) \ - { ASSIGN_3V(vl, u2, u1, u0 ); \ - imask |= (userclipmask[u2] | userclipmask[u1] | userclipmask[u0]) << 8; \ - cliptri( VB, vl, imask );} \ - } \ - else { ASSIGN_3V(vl, u2, u1, u0 ); \ - cliptri( VB, vl, imask ); } \ - } - -#define TAG(x) x##_fx_clipped - -#include "fxsdettmp.h" - - -void -fxDDRenderInitGlide3(GLcontext * ctx) -{ -#if 0 - render_tab_fx_smooth_indirect[GL_TRIANGLES] = - render_vb_triangles_smooth_indirect_sd_fx; - render_tab_fx_smooth_indirect_view_clipped[GL_TRIANGLES] = - render_vb_triangles_smooth_indirect_sd_fx_view_clipped; - render_tab_fx_smooth_indirect_clipped[GL_TRIANGLES] = - render_vb_triangles_smooth_indirect_sd_fx_clipped; -#endif -} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c b/xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c deleted file mode 100644 index 0980a7ad7..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c +++ /dev/null @@ -1,365 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxtrifuncs.c,v 1.1 2000/09/24 13:51:20 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -/* fxtris.c - 3Dfx VooDoo triangle functions */ - - -#include "fxdrv.h" -#include "../mmath.h" - - - -/* Is this enough? Do we need more triangle funcs? - */ -static triangle_func tri_tab[0x40]; /* only 0x20 actually used */ -static quad_func quad_tab[0x40]; /* only 0x20 actually used */ -static line_func line_tab[0x40]; /* less than 0x20 used */ -static points_func points_tab[0x40]; /* less than 0x20 used */ - -#define IND (0) -#define TAG(x) x -#include "fxtritmp.h" - -#define IND (FX_OFFSET) -#define TAG(x) x##_offset -#include "fxtritmp.h" - -#define IND (FX_TWOSIDE) -#define TAG(x) x##_twoside -#include "fxtritmp.h" - -#define IND (FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_FRONT_BACK) -#define TAG(x) x##_front_back -#include "fxtritmp.h" - -#define IND (FX_FRONT_BACK|FX_OFFSET) -#define TAG(x) x##_front_back_offset -#include "fxtritmp.h" - -#define IND (FX_FRONT_BACK|FX_TWOSIDE) -#define TAG(x) x##_front_back_twoside -#include "fxtritmp.h" - -#define IND (FX_FRONT_BACK|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_front_back_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_FLAT) -#define TAG(x) x##_flat -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_OFFSET) -#define TAG(x) x##_flat_offset -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_TWOSIDE) -#define TAG(x) x##_flat_twoside -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_flat_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_FRONT_BACK) -#define TAG(x) x##_flat_front_back -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_FRONT_BACK|FX_OFFSET) -#define TAG(x) x##_flat_front_back_offset -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_FRONT_BACK|FX_TWOSIDE) -#define TAG(x) x##_flat_front_back_twoside -#include "fxtritmp.h" - -#define IND (FX_FLAT|FX_FRONT_BACK|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_flat_front_back_twoside_offset -#include "fxtritmp.h" - -/* We don't actually do antialiasing correctly. Geometry has to be - sorted for glide's antialiasing to operate */ -#if 0 -#define IND (FX_ANTIALIAS) -#define TAG(x) x##_aa -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_OFFSET) -#define TAG(x) x##_aa_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_TWOSIDE) -#define TAG(x) x##_aa_twoside -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_aa_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FRONT_BACK) -#define TAG(x) x##_aa_front_back -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FRONT_BACK|FX_OFFSET) -#define TAG(x) x##_aa_front_back_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FRONT_BACK|FX_TWOSIDE) -#define TAG(x) x##_aa_front_back_twoside -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FRONT_BACK|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_aa_front_back_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT) -#define TAG(x) x##_aa_flat -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_OFFSET) -#define TAG(x) x##_aa_flat_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_TWOSIDE) -#define TAG(x) x##_aa_flat_twoside -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_aa_flat_twoside_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_FRONT_BACK) -#define TAG(x) x##_aa_flat_front_back -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_FRONT_BACK|FX_OFFSET) -#define TAG(x) x##_aa_flat_front_back_offset -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_FRONT_BACK|FX_TWOSIDE) -#define TAG(x) x##_aa_flat_front_back_twoside -#include "fxtritmp.h" - -#define IND (FX_ANTIALIAS|FX_FLAT|FX_FRONT_BACK|FX_TWOSIDE|FX_OFFSET) -#define TAG(x) x##_aa_flat_front_back_twoside_offset -#include "fxtritmp.h" -#endif - -void -fxDDTrifuncInit() -{ - init(); - init_offset(); - init_twoside(); - init_twoside_offset(); - init_front_back(); - init_front_back_offset(); - init_front_back_twoside(); - init_front_back_twoside_offset(); - init_flat(); - init_flat_offset(); - init_flat_twoside(); - init_flat_twoside_offset(); - init_flat_front_back(); - init_flat_front_back_offset(); - init_flat_front_back_twoside(); - init_flat_front_back_twoside_offset(); -#if 0 - init_aa(); - init_aa_offset(); - init_aa_twoside(); - init_aa_twoside_offset(); - init_aa_front_back(); - init_aa_front_back_offset(); - init_aa_front_back_twoside(); - init_aa_front_back_twoside_offset(); - init_aa_flat(); - init_aa_flat_offset(); - init_aa_flat_twoside(); - init_aa_flat_twoside_offset(); - init_aa_flat_front_back(); - init_aa_flat_front_back_offset(); - init_aa_flat_front_back_twoside(); - init_aa_flat_front_back_twoside_offset(); -#endif -} - -void -fxPrintRenderState(const char *msg, GLuint state) -{ - fprintf(stderr, "%s: (%x) %s%s%s%s%s%s\n", - msg, state, - (state & FX_ANTIALIAS) ? "antialias, " : "", - (state & FX_FLAT) ? "flat, " : "", - (state & FX_TWOSIDE) ? "twoside, " : "", - (state & FX_OFFSET) ? "offset, " : "", - (state & FX_FRONT_BACK) ? "front-back, " : "", - (state & FX_FALLBACK) ? "fallback" : ""); -} - - -void -fxPrintHintState(const char *msg, GLuint state) -{ - fprintf(stderr, "%s: (%x) %s %s%s %s%s\n", - msg, state, - (state & GR_STWHINT_W_DIFF_FBI) ? "w-fbi, " : "", - (state & GR_STWHINT_W_DIFF_TMU0) ? "w-tmu0, " : "", - (state & GR_STWHINT_ST_DIFF_TMU0) ? "st-tmu0, " : "", - (state & GR_STWHINT_W_DIFF_TMU1) ? "w-tmu1, " : "", - (state & GR_STWHINT_ST_DIFF_TMU1) ? "st-tmu1, " : ""); - -} - - -void -fxDDChooseRenderState(GLcontext * ctx) -{ - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - GLuint ind = 0; - GLuint flags = ctx->TriangleCaps; - - ctx->IndirectTriangles &= ~DD_SW_RASTERIZE; - - if (flags) { - if (fxMesa->render_index & FX_OFFSET) - FX_grDepthBiasLevel(fxMesa, 0); - - if (flags & (DD_SELECT | DD_FEEDBACK)) { - fxMesa->PointsFunc = 0; - fxMesa->LineFunc = 0; - fxMesa->TriangleFunc = 0; - fxMesa->QuadFunc = 0; - fxMesa->render_index = FX_FALLBACK; - ctx->IndirectTriangles |= DD_SW_RASTERIZE; -#if 0 - fprintf(stderr, "Fallback select|feeback\n"); -#endif - return; - } - - if (flags & DD_FLATSHADE) - ind |= FX_FLAT; - if (flags & DD_TRI_LIGHT_TWOSIDE) - ind |= FX_TWOSIDE; -#if 000 - /* XXX this is rather broken, don't use it. */ - if (flags & DD_MULTIDRAW) - ind |= FX_FRONT_BACK; -#else - if (flags & DD_MULTIDRAW) - ctx->IndirectTriangles |= DD_SW_RASTERIZE; -#endif - - if (flags & (DD_POINT_ATTEN | DD_POINT_SMOOTH)) { - ind |= FX_FALLBACK; -#if 0 - if (flags & DD_POINT_ATTEN) - fprintf(stderr, "Fallback point atten\n"); - if (flags & DD_POINT_SMOOTH) - fprintf(stderr, "Fallback point smooth\n"); -#endif - } - - fxMesa->render_index = ind; - fxMesa->PointsFunc = points_tab[ind]; - if (ind & FX_FALLBACK) - ctx->IndirectTriangles |= DD_POINT_SW_RASTERIZE; - ind &= ~(FX_ANTIALIAS | FX_FALLBACK); - - if (flags & (DD_LINE_STIPPLE | DD_LINE_SMOOTH)) { - ind |= FX_FALLBACK; -#if 0 - if (flags & DD_LINE_STIPPLE) - fprintf(stderr, "Fallback line stipple\n"); - if (flags & DD_LINE_SMOOTH) - fprintf(stderr, "Fallback line smooth\n"); -#endif - } - - fxMesa->render_index |= ind; - fxMesa->LineFunc = line_tab[ind]; - if (ind & FX_FALLBACK) - ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE; - ind &= ~(FX_ANTIALIAS | FX_FALLBACK); - - if (flags & DD_TRI_OFFSET) - ind |= FX_OFFSET; - if (flags & (DD_TRI_UNFILLED | DD_TRI_STIPPLE | DD_TRI_SMOOTH)) { - ind |= FX_FALLBACK; -#if 0 - if (flags & DD_TRI_UNFILLED) - fprintf(stderr, "Fallback tri unfilled\n"); - if (flags & DD_TRI_STIPPLE) - fprintf(stderr, "Fallback tri stippled\n"); - if (flags & DD_TRI_SMOOTH) - fprintf(stderr, "Fallback tri smooth\n"); -#endif - } - - fxMesa->render_index |= ind; - fxMesa->TriangleFunc = tri_tab[ind]; - fxMesa->QuadFunc = quad_tab[ind]; - - if (ind & FX_FALLBACK) - ctx->IndirectTriangles |= - DD_TRI_SW_RASTERIZE | DD_QUAD_SW_RASTERIZE; - } - else if (fxMesa->render_index) { - if (fxMesa->render_index & FX_OFFSET) - FX_grDepthBiasLevel(fxMesa, 0); - - fxMesa->render_index = 0; - fxMesa->PointsFunc = points_tab[0]; - fxMesa->LineFunc = line_tab[0]; - fxMesa->TriangleFunc = tri_tab[0]; - fxMesa->QuadFunc = quad_tab[0]; - } - - if (MESA_VERBOSE & (VERBOSE_STATE | VERBOSE_DRIVER)) - fxPrintRenderState("fxmesa: Render state", fxMesa->render_index); -} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h b/xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h deleted file mode 100644 index bc7621aa1..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h +++ /dev/null @@ -1,215 +0,0 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/fxvs_tmp.h,v 1.1 2000/09/24 13:51:20 alanh Exp $ */ -/* - * Mesa 3-D graphics library - * Version: 3.3 - * - * 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the - * terms stated above. - * - * Thank you for your contribution, David! - * - * Please make note of the above copyright/license statement. If you - * contributed code or bug fixes to this code under the previous (GNU - * Library) license and object to the new license, your code will be - * removed at your request. Please see the Mesa docs/COPYRIGHT file - * for more information. - * - * Additional Mesa/3Dfx driver developers: - * Daryll Strauss <daryll@precisioninsight.com> - * Keith Whitwell <keith@precisioninsight.com> - * - * See fxapi.h for more revision/author details. - */ - - -#if (IND & (SETUP_XY|SETUP_W|SETUP_Z)) -#define V1 VARS_XY -#define I1 , INCR_XY -#else -#define V1 -#define I1 -#endif - -#if (IND & SETUP_XY) -#define S1 DO_SETUP_XY -#else -#define S1 -#endif - -#if (IND & SETUP_W) -#define S2 S1 DO_SETUP_W -#define V2 V1 VARS_W -#else -#define S2 S1 -#define V2 V1 -#endif - -#if (IND & SETUP_Z) -#define S3 S2 DO_SETUP_Z -#else -#define S3 S2 -#endif - -#if (IND & SETUP_RGBA) -#define V4 V2 VARS_RGBA -#define S4 S3 DO_SETUP_RGBA -#define I4 I1 , INCR_RGBA -#else -#define V4 V2 -#define S4 S3 -#define I4 I1 -#endif - -#if (IND & SETUP_TMU0) -#define V5 V4 VARS_TMU0 -#define S5 S4 DO_SETUP_TMU0 -#define I5 I4 , INCR_TMU0 -#define F5 FIXUP_TMU0 -#else -#define V5 V4 -#define S5 S4 -#define I5 I4 -#define F5 -#endif - -#if (IND & SETUP_TMU1) -#define V6 V5 VARS_TMU1 -#define S6 S5 DO_SETUP_TMU1 -#define I6 I5 , INCR_TMU1 -#define F6 F5 FIXUP_TMU1 -#else -#define V6 V5 -#define S6 S5 -#define I6 I5 -#define F6 F5 -#endif - -#if (IND & SETUP_TMU0) && (IND & SETUP_TMU1) -#define F7 FIXUP_TMU01 -#else -#define F7 F6 -#endif - -#define VARS V6 -#define DO_SETUP S6 -#define INCR I6 -#define FIXUP F7 - -static void -NAME(struct vertex_buffer *VB, GLuint start, GLuint end) -{ - GLcontext *ctx = VB->ctx; - fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx; - - if (fxMesa->new_state) - fxSetupFXUnits(ctx); - - { - const float snapper = (3L << 18); - fxVertex *gWin = FX_DRIVER_DATA(VB)->verts; - GLfloat *v = gWin[start].f; - GLfloat *vend = gWin[end].f; - VARS; - - (void) gWin; - (void) fxMesa; - (void) snapper; - - if (VB->ClipOrMask) { - GLubyte *clipmask = &VB->ClipMask[start]; - for (; v != vend; v += 16, clipmask++ INCR) { - if (*clipmask == 0) { - DO_SETUP; - } - } - } - else { - for (; v != vend; v += 16 INCR) { - DO_SETUP; - } - } - - if (ctx->FogMode == FOG_FRAGMENT - && ctx->ProjectionMatrix.m[15] != 0.0F) { - /* need to compute W values for fogging purposes */ - const GLfloat m10 = ctx->ProjectionMatrix.m[10]; - const GLfloat m14 = ctx->ProjectionMatrix.m[14]; - const GLfloat v10 = ctx->Viewport.WindowMap.m[10]; - const GLfloat v14 = ctx->Viewport.WindowMap.m[14]; - GLfloat *v = gWin[start].f; - GLfloat *win = VB->Win.data[start]; - if (VB->ClipOrMask) { - GLubyte *clipmask = &VB->ClipMask[start]; - for (; v != vend; v += 16, clipmask++, win += 4) { - if (*clipmask == 0) { - GLfloat zNDC = (win[2] - v14) / v10; - GLfloat zEye = (zNDC - m14) / m10; - v[OOWCOORD] = -1.0F / zEye; - } - } - } - else { - for (; v != vend; v += 16, win += 4) { - GLfloat zNDC = (win[2] - v14) / v10; - GLfloat zEye = (zNDC - m14) / m10; - v[OOWCOORD] = -1.0F / zEye; - } - } - } - - /* rare - I hope */ - FIXUP; - } -} - - -#undef V1 -#undef V2 -#undef V3 -#undef V4 -#undef V5 -#undef V6 -#undef VARS - -#undef S1 -#undef S2 -#undef S3 -#undef S4 -#undef S5 -#undef S6 -#undef DO_SETUP - -#undef I1 -#undef I4 -#undef I5 -#undef I6 -#undef INCR - -#undef F5 -#undef F6 -#undef F7 -#undef FIXUP - - -#undef IND -#undef NAME diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.c new file mode 100644 index 000000000..1d6d41724 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.c @@ -0,0 +1,470 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "dri_glide.h" +#include "tdfx_context.h" +#include "tdfx_dd.h" +#include "tdfx_state.h" +#include "tdfx_vb.h" +#include "tdfx_render.h" +#include "tdfx_pipeline.h" +#include "tdfx_span.h" +#include "tdfx_texman.h" +#include "extensions.h" + + + +#if 0 +/* Example extension function */ +static void +fxFooBarEXT(GLint i) +{ + printf("You called glFooBarEXT(%d)\n", i); +} +#endif + + +/* + * Enable/Disable the extensions for this context. + */ +static void tdfxDDInitExtensions( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + gl_extensions_disable( ctx, "GL_EXT_blend_logic_op" ); + gl_extensions_disable( ctx, "GL_EXT_blend_minmax" ); + gl_extensions_disable( ctx, "GL_EXT_blend_subtract" ); + gl_extensions_disable( ctx, "GL_EXT_blend_color" ); + gl_extensions_disable( ctx, "GL_EXT_blend_func_separate" ); + gl_extensions_disable( ctx, "GL_EXT_point_parameters" ); + gl_extensions_disable( ctx, "GL_EXT_shared_texture_palette" ); + gl_extensions_disable( ctx, "GL_INGR_blend_func_separate" ); + gl_extensions_enable( ctx, "GL_HP_occlusion_test" ); + + if ( !fxMesa->haveTwoTMUs ) { + gl_extensions_disable( ctx, "GL_EXT_texture_env_add" ); + gl_extensions_disable( ctx, "GL_ARB_multitexture" ); + } + + if ( TDFX_IS_NAPALM( fxMesa ) ) { + gl_extensions_enable( ctx, "GL_ARB_texture_compression" ); + gl_extensions_enable( ctx, "GL_EXT_texture_env_combine" ); + gl_extensions_enable( ctx, "GL_3DFX_texture_compression_FXT1" ); + } + + if (fxMesa->haveHwStencil) { + gl_extensions_enable( ctx, "GL_EXT_stencil_wrap" ); + } + + /* Example of hooking in an extension function. + * For DRI-based drivers, also see __driRegisterExtensions in the + * tdfx_xmesa.c file. + */ +#if 0 + { + void **dispatchTable = (void **) ctx->Exec; + const int _gloffset_FooBarEXT = 555; /* just an example number! */ + const int tabSize = _glapi_get_dispatch_table_size(); + assert(_gloffset_FooBarEXT < tabSize); + dispatchTable[_gloffset_FooBarEXT] = (void *) tdfxFooBarEXT; + /* XXX You would also need to hook into the display list dispatch + * table. Really, the implementation of extensions might as well + * be in the core of Mesa since core Mesa and the device driver + * is one big shared lib. + */ + } +#endif +} + + + +GLboolean tdfxCreateContext( Display *dpy, GLvisual *mesaVis, + __DRIcontextPrivate *driContextPriv ) +{ + tdfxContextPtr fxMesa; + GLcontext *ctx = driContextPriv->mesaContext; + __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; + tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private; + TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) ((char *) sPriv->pSAREA + + sizeof(XF86DRISAREARec)); + + + fxMesa = (tdfxContextPtr) Xmalloc( sizeof(tdfxContextRec) ); + if ( !fxMesa ) { + return GL_FALSE; + } + BZERO(fxMesa, sizeof(tdfxContextRec)); + + /* Mirror some important DRI state + */ + fxMesa->hHWContext = driContextPriv->hHWContext; + fxMesa->driHwLock = &sPriv->pSAREA->lock; + fxMesa->driFd = sPriv->fd; + + fxMesa->driScreen = sPriv; + fxMesa->driContext = driContextPriv; + fxMesa->fxScreen = fxScreen; + fxMesa->sarea = saPriv; + + + + fxMesa->haveHwStencil = ( TDFX_IS_NAPALM( fxMesa ) && + mesaVis->StencilBits && + mesaVis->DepthBits == 24 ); + + fxMesa->screen_width = fxScreen->width; + fxMesa->screen_height = fxScreen->height; + + fxMesa->new_state = ~0; + fxMesa->dirty = ~0; + + fxMesa->vertexFormat = 0; + + fxMesa->glCtx = driContextPriv->mesaContext; + fxMesa->glVis = mesaVis; + + grDRIOpen( sPriv->pFB, fxScreen->regs.map, fxScreen->deviceID, + fxScreen->width, fxScreen->height, fxScreen->mem, fxScreen->cpp, + fxScreen->stride, fxScreen->fifoOffset, fxScreen->fifoSize, + fxScreen->fbOffset, fxScreen->backOffset, fxScreen->depthOffset, + fxScreen->textureOffset, fxScreen->textureSize, &saPriv->fifoPtr, + &saPriv->fifoRead ); + + if ( getenv( "FX_GLIDE_SWAPINTERVAL" ) ) { + fxMesa->Glide.SwapInterval = atoi( getenv( "FX_GLIDE_SWAPINTERVAL" ) ); + } else { + fxMesa->Glide.SwapInterval = 1; + } + if ( getenv( "FX_MAX_PENDING_SWAPS" ) ) { + fxMesa->Glide.MaxPendingSwaps = atoi( getenv( "FX_MAX_PENDING_SWAPS" ) ); + } else { + fxMesa->Glide.MaxPendingSwaps = 2; + } + + fxMesa->Glide.Initialized = GL_FALSE; + fxMesa->Glide.Board = 0; + + + if (getenv("FX_EMULATE_SINGLE_TMU")) { + fxMesa->haveTwoTMUs = GL_FALSE; + } + else { + if ( TDFX_IS_BANSHEE( fxMesa ) ) { + fxMesa->haveTwoTMUs = GL_FALSE; + } else { + fxMesa->haveTwoTMUs = GL_TRUE; + } + } + + fxMesa->stats.swapBuffer = 0; + fxMesa->stats.reqTexUpload = 0; + fxMesa->stats.texUpload = 0; + fxMesa->stats.memTexUpload = 0; + + fxMesa->tmuSrc = TDFX_TMU_NONE; + + if ( TDFX_IS_NAPALM( fxMesa ) ) { + ctx->Const.MaxTextureLevels = 12; + ctx->Const.MaxTextureSize = 2048; + ctx->Const.NumCompressedTextureFormats = 1; + } else { + ctx->Const.MaxTextureLevels = 9; + ctx->Const.MaxTextureSize = 256; + ctx->Const.NumCompressedTextureFormats = 0; + } + ctx->Const.MaxTextureUnits = TDFX_IS_BANSHEE( fxMesa ) ? 1 : 2; + ctx->NewState |= NEW_DRVSTATE1; + + + ctx->DriverCtx = (void *) fxMesa; + + tdfxDDInitExtensions( ctx ); + + tdfxDDInitDriverFuncs( ctx ); + tdfxDDInitStateFuncs( ctx ); + tdfxDDInitRenderFuncs( ctx ); + tdfxDDInitSpanFuncs( ctx ); + + ctx->Driver.TriangleCaps = (DD_TRI_CULL | + DD_TRI_LIGHT_TWOSIDE | + DD_TRI_STIPPLE | + DD_TRI_OFFSET); + + if ( ctx->VB ) + tdfxDDRegisterVB( ctx->VB ); + + if ( ctx->NrPipelineStages ) + ctx->NrPipelineStages = + tdfxDDRegisterPipelineStages( ctx->PipelineStage, + ctx->PipelineStage, + ctx->NrPipelineStages ); + + /* Run the config file */ + gl_context_initialize( ctx ); + +#if 0 + /* HACK: Allocate buffer for vertex data. + */ + if ( fxMesa->buffer ) { + ALIGN_FREE( fxMesa->buffer ); + } + fxMesa->buffer = ALIGN_MALLOC( 2048, 32 ); + fxMesa->buffer_total = 2048; + fxMesa->buffer_used = 0; +#endif + + tdfxInitState( fxMesa ); + + driContextPriv->driverPrivate = (void *) fxMesa; + + return GL_TRUE; +} + + +static GLboolean tdfxInitVertexFormats( tdfxContextPtr fxMesa ) +{ + FxI32 result; + int i; + + LOCK_HARDWARE( fxMesa ); + + grGet( GR_GLIDE_VERTEXLAYOUT_SIZE, sizeof(FxI32), &result ); + for ( i = 0 ; i < TDFX_NUM_LAYOUTS ; i++ ) { + fxMesa->layout[i] = MALLOC( result ); + if ( !fxMesa->layout[i] ) { + UNLOCK_HARDWARE( fxMesa ); + return GL_FALSE; + } + } + + /* Single textured vertex format - 32 bytes. + */ + grReset( GR_VERTEX_PARAMETER ); + + grCoordinateSpace( GR_WINDOW_COORDS ); + grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE ); +#if 0 + grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE ); +#endif + + grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_SINGLE] ); + + /* Multitextured vertex format - 40 bytes. + */ + grReset( GR_VERTEX_PARAMETER ); + + grCoordinateSpace( GR_WINDOW_COORDS ); + grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE ); +#if 0 + grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE ); +#endif + + grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_MULTI] ); + + /* Projected texture vertex format - 48 bytes. + */ + grReset( GR_VERTEX_PARAMETER ); + + grCoordinateSpace( GR_WINDOW_COORDS ); + grVertexLayout( GR_PARAM_XY, TDFX_XY_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Z, TDFX_Z_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Q, TDFX_Q_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_PARGB, TDFX_ARGB_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_ST0, TDFX_ST0_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_ST1, TDFX_ST1_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Q0, TDFX_Q0_OFFSET, GR_PARAM_ENABLE ); + grVertexLayout( GR_PARAM_Q1, TDFX_Q1_OFFSET, GR_PARAM_ENABLE ); +#if 0 + grVertexLayout( GR_PARAM_FOG_EXT, TDFX_FOG_OFFSET, GR_PARAM_ENABLE ); +#endif + + grGlideGetVertexLayout( fxMesa->layout[TDFX_LAYOUT_PROJECT] ); + + UNLOCK_HARDWARE( fxMesa ); + + return GL_TRUE; +} + + +/* + * Initialize the state in an tdfxContextPtr struct. + */ +GLboolean tdfxInitContext( __DRIdrawablePrivate *driDrawPriv, + tdfxContextPtr fxMesa ) +{ + /* KW: Would be nice to make one of these a member of the other. + */ + FxI32 result[2]; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, fxMesa ); + } + +#if DEBUG_LOCKING + fprintf(stderr, "Debug locking enabled\n"); +#endif + + if ( fxMesa->Glide.Initialized ) + return GL_TRUE; + + fxMesa->width = driDrawPriv->w; + fxMesa->height = driDrawPriv->h; + + /* We have to use a light lock here, because we can't do any glide + * operations yet. No use of FX_* functions in this function. + */ + DRM_LIGHT_LOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); + + grGlideInit(); + grSstSelect( fxMesa->Glide.Board ); + + fxMesa->Glide.Context = grSstWinOpen( (FxU32) -1, + GR_RESOLUTION_NONE, + GR_REFRESH_NONE, + fxMesa->Glide.ColorFormat, + fxMesa->Glide.Origin, + 2, 1 ); + + grDRIResetSAREA(); + + DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); + + if ( !fxMesa->Glide.Context ) + return GL_FALSE; + + + /* Perform the Glide-dependant part of the context initialization. + */ + FX_grColorMaskv( fxMesa->glCtx, true4 ); + + tdfxTMInit( fxMesa ); + + LOCK_HARDWARE( fxMesa ); + + if ( fxMesa->glVis->DepthBits > 0 ) { + grDepthBufferMode(GR_DEPTHBUFFER_ZBUFFER); + } else { + grDepthBufferMode(GR_DEPTHBUFFER_DISABLE); + } + + grLfbWriteColorFormat( GR_COLORFORMAT_ABGR ); + + grGet( GR_TEXTURE_ALIGN, sizeof(FxI32), result ); + fxMesa->Glide.TextureAlign = result[0]; + + fxMesa->Glide.State = NULL; + grGet( GR_GLIDE_STATE_SIZE, sizeof(FxI32), result ); + fxMesa->Glide.State = MALLOC( result[0] ); + + fxMesa->Fog.Table = NULL; + grGet( GR_FOG_TABLE_ENTRIES, sizeof(FxI32), result ); + fxMesa->Fog.Table = MALLOC( result[0] * sizeof(GrFog_t) ); + + UNLOCK_HARDWARE( fxMesa ); + + if ( !fxMesa->Glide.State || !fxMesa->Fog.Table ) { + if ( fxMesa->Glide.State ) + FREE( fxMesa->Glide.State ); + if ( fxMesa->Fog.Table ) + FREE( fxMesa->Fog.Table ); + return GL_FALSE; + } + + if ( !tdfxInitVertexFormats( fxMesa ) ) { + return GL_FALSE; + } + + LOCK_HARDWARE( fxMesa ); + + grGlideGetState( fxMesa->Glide.State ); + + if ( getenv( "FX_GLIDE_INFO" ) ) { + printf( "GR_RENDERER = %s\n", (char *) grGetString( GR_RENDERER ) ); + printf( "GR_VERSION = %s\n", (char *) grGetString( GR_VERSION ) ); + printf( "GR_VENDOR = %s\n", (char *) grGetString( GR_VENDOR ) ); + printf( "GR_HARDWARE = %s\n", (char *) grGetString( GR_HARDWARE ) ); + printf( "GR_EXTENSION = %s\n", (char *) grGetString( GR_EXTENSION ) ); + } + + UNLOCK_HARDWARE( fxMesa ); + + fxMesa->numClipRects = 0; + fxMesa->pClipRects = NULL; + fxMesa->scissoredClipRects = GL_FALSE; + + fxMesa->Glide.Initialized = GL_TRUE; + + return GL_TRUE; +} + + +void tdfxDestroyContext( tdfxContextPtr fxMesa ) +{ + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, fxMesa ); + } + + if ( fxMesa ) { + if (fxMesa->glCtx->Shared->RefCount == 1) { + /* This share group is about to go away, free our private + * texture object data. + */ + struct gl_texture_object *tObj; + tObj = fxMesa->glCtx->Shared->TexObjectList; + while (tObj) { + tdfxTMFreeTexture(fxMesa, tObj); + tObj = tObj->Next; + } + } + + tdfxTMClose(fxMesa); /* free texture memory */ + XFree( fxMesa ); + } + +#if 0 + glx_fini_prof(); +#endif +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.h new file mode 100644 index 000000000..d630184bd --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_context.h @@ -0,0 +1,774 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_CONTEXT_H__ +#define __TDFX_CONTEXT_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include <sys/time.h> +#include "dri_tmm.h" +#include "dri_mesaint.h" +#include "dri_mesa.h" +#include "dri_xmesaapi.h" +#ifdef XFree86Server +#include "GL/xf86glx.h" +#else +#include "glheader.h" +#endif +#if defined(__linux__) +#include <signal.h> +#endif +#include "clip.h" +#include "context.h" + +#include "macros.h" +#include "matrix.h" +#include "mem.h" +#include "texture.h" +#include "types.h" +#include "vb.h" +#include "vbrender.h" +#include "xform.h" + +#include "tdfx_wrapper.h" +#include "tdfx_screen.h" +#include "tdfx_lock.h" +#include "tdfx_g3ext.h" + + + +/* Mergable items first + */ +#define SETUP_RGBA 0x1 +#define SETUP_TMU0 0x2 +#define SETUP_TMU1 0x4 +#define SETUP_XY 0x8 +#define SETUP_Z 0x10 +#define SETUP_W 0x20 + +#define MAX_MERGABLE 0x8 + + +#define TDFX_TMU0 GR_TMU0 +#define TDFX_TMU1 GR_TMU1 +#define TDFX_TMU_SPLIT 98 +#define TDFX_TMU_BOTH 99 +#define TDFX_TMU_NONE 100 + + + +/* Flags for fxMesa->new_state + */ +#define TDFX_NEW_COLOR 0x0001 +#define TDFX_NEW_ALPHA 0x0002 +#define TDFX_NEW_DEPTH 0x0004 +#define TDFX_NEW_FOG 0x0008 +#define TDFX_NEW_STENCIL 0x0010 +#define TDFX_NEW_CLIP 0x0020 +#define TDFX_NEW_VIEWPORT 0x0040 +#define TDFX_NEW_CULL 0x0080 +#define TDFX_NEW_GLIDE 0x0100 +#define TDFX_NEW_TEXTURE 0x0200 +#define TDFX_NEW_CONTEXT 0x0400 +#define TDFX_NEW_LINE 0x0800 +#define TDFX_NEW_RENDER 0x1000 +#define TDFX_NEW_STIPPLE 0x2000 +#define TDFX_NEW_TEXTURE_BIND 0x4000 /* experimental */ + + +/* Flags for fxMesa->dirty + */ +#define TDFX_UPLOAD_COLOR_COMBINE 0x00000001 +#define TDFX_UPLOAD_ALPHA_COMBINE 0x00000002 +#define TDFX_UPLOAD_RENDER_BUFFER 0x00000004 +#define TDFX_UPLOAD_ALPHA_TEST 0x00000008 +#define TDFX_UPLOAD_ALPHA_REF 0x00000010 +#define TDFX_UPLOAD_BLEND_FUNC 0x00000020 +#define TDFX_UPLOAD_DEPTH_MODE 0x00000040 +#define TDFX_UPLOAD_DEPTH_BIAS 0x00000080 +#define TDFX_UPLOAD_DEPTH_FUNC 0x00000100 +#define TDFX_UPLOAD_DEPTH_MASK 0x00000200 +#define TDFX_UPLOAD_FOG_MODE 0x00000400 +#define TDFX_UPLOAD_FOG_COLOR 0x00000800 +#define TDFX_UPLOAD_FOG_TABLE 0x00001000 + +#define TDFX_UPLOAD_CLIP 0x00002000 +#define TDFX_UPLOAD_CULL 0x00004000 +#define TDFX_UPLOAD_VERTEX_LAYOUT 0x00008000 +#define TDFX_UPLOAD_COLOR_MASK 0x00010000 +#define TDFX_UPLOAD_CONSTANT_COLOR 0x00020000 +#define TDFX_UPLOAD_DITHER 0x00040000 +#define TDFX_UPLOAD_STENCIL 0x00080000 + +#define TDFX_UPLOAD_TEXTURE_SOURCE 0x00100000 +#define TDFX_UPLOAD_TEXTURE_PARAMS 0x00200000 +#define TDFX_UPLOAD_TEXTURE_PALETTE 0x00400000 +#define TDFX_UPLOAD_TEXTURE_ENV 0x00800000 +#define TDFX_UPLOAD_TEXTURE_IMAGES 0x01000000 + +#define TDFX_UPLOAD_LINE 0x02000000 + +#define TDFX_UPLOAD_STIPPLE 0x04000000 + +/* Flags for software fallback cases + */ +#define TDFX_FALLBACK_TEXTURE 0x0001 +#define TDFX_FALLBACK_BUFFER 0x0002 +#define TDFX_FALLBACK_SPECULAR 0x0004 +#define TDFX_FALLBACK_STENCIL 0x0008 +#define TDFX_FALLBACK_RENDER_MODE 0x0010 +#define TDFX_FALLBACK_MULTIDRAW 0x0020 +#define TDFX_FALLBACK_LOGICOP 0x0040 +#define TDFX_FALLBACK_WIDE_AA_LINE 0x0080 +#define TDFX_FALLBACK_TEXTURE_ENV 0x0100 +#define TDFX_FALLBACK_TEXTURE_BORDER 0x0200 +#define TDFX_FALLBACK_COLORMASK 0x0400 +#define TDFX_FALLBACK_BLEND 0x0800 + +/* Different Glide vertex layouts + */ +#define TDFX_LAYOUT_SINGLE 0 +#define TDFX_LAYOUT_MULTI 1 +#define TDFX_LAYOUT_PROJECT 2 +#define TDFX_NUM_LAYOUTS 3 + +#define TDFX_XY_OFFSET 0 +#define TDFX_Z_OFFSET 8 +#define TDFX_Q_OFFSET 12 +#define TDFX_ARGB_OFFSET 16 +#define TDFX_PAD_OFFSET 20 +#define TDFX_FOG_OFFSET 20 /* experimental */ +#define TDFX_ST0_OFFSET 24 +#define TDFX_ST1_OFFSET 32 +#define TDFX_Q0_OFFSET 40 +#define TDFX_Q1_OFFSET 44 + + +/* Flags for buffer clears + */ +#define TDFX_FRONT 0x1 +#define TDFX_BACK 0x2 +#define TDFX_DEPTH 0x4 +#define TDFX_STENCIL 0x8 + +/* + * Subpixel offsets to adjust Mesa's (true) window coordinates to + * Glide coordinates. We need these to ensure precise rasterization. + * Otherwise, we'll fail a bunch of conformance tests. + */ +#define TRI_X_OFFSET ( 0.0F) +#define TRI_Y_OFFSET ( 0.0F) +#define LINE_X_OFFSET ( 0.0F) +#define LINE_Y_OFFSET ( 0.125F) +#define PNT_X_OFFSET ( 0.375F) +#define PNT_Y_OFFSET ( 0.375F) + + +#define TDFX_DEPTH_BIAS_SCALE 128 + +/* Including xf86PciInfo.h causes a bunch of errors + */ +#ifndef PCI_CHIP_BANSHEE +#define PCI_CHIP_BANSHEE 0x0003 +#define PCI_CHIP_VOODOO3 0x0005 +#define PCI_CHIP_VOODOO4 0x0009 +#define PCI_CHIP_VOODOO5 0x0009 +#endif + +#define TDFX_IS_BANSHEE( fxMesa ) \ + ( fxMesa->fxScreen->deviceID == PCI_CHIP_BANSHEE ) +#define TDFX_IS_VOODOO3( fxMesa ) \ + ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO3 ) +#define TDFX_IS_VOODOO4( fxMesa ) \ + ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4 ) +#define TDFX_IS_VOODOO5( fxMesa ) \ + ( fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5 ) +#define TDFX_IS_NAPALM( fxMesa ) \ + ( (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO4) || \ + (fxMesa->fxScreen->deviceID == PCI_CHIP_VOODOO5) ) + + +#define PACK_BGRA32(R, G, B, A) \ + ( (((GLuint) (R)) << 16) | \ + (((GLuint) (G)) << 8) | \ + (((GLuint) (B)) ) | \ + (((GLuint) (A)) << 24) ) + +#define PACK_RGBA32(R, G, B, A) \ + ( (((GLuint) (R)) ) | \ + (((GLuint) (G)) << 8) | \ + (((GLuint) (B)) << 16) | \ + (((GLuint) (A)) << 24) ) + +/* + * The first two macros are to pack 8 bit color + * channel values into a 565 format. + */ +#define PACK_RGB16(R, G, B) \ + ((((GLuint) (R) & 0xF8) << 8) | \ + (((GLuint) (G) & 0xFC) << 3) | \ + (((GLuint) (B) & 0xFF) >> 3)) +#define PACK_BGR16(R, G, B) \ + ((((GLuint) (B) & 0xF8) << 8) | \ + (((GLuint) (G) & 0xFC) << 3) | \ + (((GLuint) (R) & 0xFF) >> 3)) +/* + * The second two macros pack 8 bit color channel values + * into 1555 values. + */ +#define PACK_RGBA16(R, G, B, A) \ + (((((GLuint) (A) & 0xFF) > 0) << 15)| \ + (((GLuint) (R) & 0xF8) << 7) | \ + (((GLuint) (G) & 0xF8) << 2) | \ + (((GLuint) (B) & 0xF8) >> 3)) +#define PACK_BGRA16(R, G, B, A) \ + (((((GLuint) (A) & 0xFF) > 0) << 15)| \ + (((GLuint) (B) & 0xF8) << 7) | \ + (((GLuint) (G) & 0xF8) << 2) | \ + (((GLuint) (R) & 0xF8) >> 3)) + +typedef void (*tdfxRenderEltsFunc)( struct vertex_buffer * ); + +/* Used in calls to grColorMaskv()... + */ +extern const GLboolean false4[4]; +extern const GLboolean true4[4]; + + +typedef void (*tdfx_interp_func)( GLfloat t, + GLfloat *result, + const GLfloat *in, + const GLfloat *out ); + +typedef struct { + volatile int fifoPtr; + volatile int fifoRead; + volatile int fifoOwner; + volatile int ctxOwner; + volatile int texOwner; +} +TDFXSAREAPriv; + + +typedef struct { + GLuint swapBuffer; + GLuint reqTexUpload; + GLuint texUpload; + GLuint memTexUpload; + GLuint texSwaps; +} tdfxStats; + + + +/* + * Memory range from startAddr to endAddr-1 + */ +typedef struct mem_range { + struct mem_range *next; + FxU32 startAddr, endAddr; +} +tdfxMemRange; + + +typedef struct { + GLsizei width, height; /* image size */ + GLint texelSize; /* How many bytes to a texel */ + GrTextureFormat_t glideFormat; /* Glide image format */ + void *data; /* Glide-formated texture image */ + FxU32 dataSize; /* image size in bytes */ +} +tdfxMipMapLevel; + + +#define TDFX_NUM_TMU 2 + + +typedef struct tdfxTexInfo_t +{ + GLboolean isInTM; + GLboolean reloadImages; /* if true, resend images to Glide */ + GLuint lastTimeUsed; + FxU32 whichTMU; + + GrTexInfo info; + GrAspectRatio_t aspectRatio; + tdfxMipMapLevel mipmapLevel[MAX_TEXTURE_LEVELS]; + tdfxMemRange *tm[TDFX_NUM_TMU]; + + GLint minLevel, maxLevel; + GrTextureFilterMode_t minFilt; + GrTextureFilterMode_t magFilt; + GrTextureClampMode_t sClamp; + GrTextureClampMode_t tClamp; + FxBool LODblend; + GrMipMapMode_t mmMode; + + GLfloat sScale, tScale; /* texcoord scale factor */ + + GuTexPalette palette; +} +tdfxTexInfo; + + +#define TDFX_TEXTURE_DATA(mesaObj) ((tdfxTexInfo *)((mesaObj)->DriverData)) + + + +/* + * This is state which may be shared by several tdfx contexts. + * It hangs off of Mesa's gl_shared_state object (ctx->Shared->DriverData). + */ +struct tdfxSharedState { + GLboolean umaTexMemory; + GLuint totalTexMem[TDFX_NUM_TMU]; /* constant */ + GLuint freeTexMem[TDFX_NUM_TMU]; /* changes as we go */ + tdfxMemRange *tmPool; + tdfxMemRange *tmFree[TDFX_NUM_TMU]; +}; + + + + +/* ================================================================ + * + * We want to keep a mirror of the Glide function call parameters so we + * can avoid updating our state too often. + * + * Each of these broad groups will typically have a new state flag + * associated with it, and will be updated together. The individual + * Glide function calls each have a dirty flag and will only be called + * when absolutely necessary. + */ + +/* for grTexSource() */ +struct tdfx_texsource { + FxU32 StartAddress; + FxU32 EvenOdd; + GrTexInfo *Info; +}; + +/* Texture object params */ +struct tdfx_texparams { + GrTextureClampMode_t sClamp; + GrTextureClampMode_t tClamp; + GrTextureFilterMode_t minFilt; + GrTextureFilterMode_t magFilt; + GrMipMapMode_t mmMode; + FxBool LODblend; + GLfloat LodBias; +}; + +/* for grTexDownloadTable() texture palettes */ +struct tdfx_texpalette { + GrTexTable_t Type; + void *Data; +}; + +/* for Voodoo3/Banshee's grColorCombine() and grAlphaCombine() */ +struct tdfx_combine { + GrCombineFunction_t Function; /* Combine function */ + GrCombineFactor_t Factor; /* Combine scale factor */ + GrCombineLocal_t Local; /* Local combine source */ + GrCombineOther_t Other; /* Other combine source */ + FxBool Invert; /* Combine result inversion flag */ +}; + +/* for Voodoo3's grTexCombine() */ +struct tdfx_texcombine { + GrCombineFunction_t FunctionRGB; + GrCombineFactor_t FactorRGB; + GrCombineFunction_t FunctionAlpha; + GrCombineFactor_t FactorAlpha; + FxBool InvertRGB; + FxBool InvertAlpha; +}; + + +/* for Voodoo5's grColorCombineExt() */ +struct tdfx_combine_color_ext { + GrCCUColor_t SourceA; + GrCombineMode_t ModeA; + GrCCUColor_t SourceB; + GrCombineMode_t ModeB; + GrCCUColor_t SourceC; + FxBool InvertC; + GrCCUColor_t SourceD; + FxBool InvertD; + FxU32 Shift; + FxBool Invert; +}; + +/* for Voodoo5's grAlphaCombineExt() */ +struct tdfx_combine_alpha_ext { + GrACUColor_t SourceA; + GrCombineMode_t ModeA; + GrACUColor_t SourceB; + GrCombineMode_t ModeB; + GrACUColor_t SourceC; + FxBool InvertC; + GrACUColor_t SourceD; + FxBool InvertD; + FxU32 Shift; + FxBool Invert; +}; + +/* for Voodoo5's grTexColorCombineExt() */ +struct tdfx_color_texenv { + GrTCCUColor_t SourceA; + GrCombineMode_t ModeA; + GrTCCUColor_t SourceB; + GrCombineMode_t ModeB; + GrTCCUColor_t SourceC; + FxBool InvertC; + GrTCCUColor_t SourceD; + FxBool InvertD; + FxU32 Shift; + FxBool Invert; +}; + +/* for Voodoo5's grTexAlphaCombineExt() */ +struct tdfx_alpha_texenv { + GrTACUColor_t SourceA; + GrCombineMode_t ModeA; + GrTACUColor_t SourceB; + GrCombineMode_t ModeB; + GrTACUColor_t SourceC; + FxBool InvertC; + GrTCCUColor_t SourceD; + FxBool InvertD; + FxU32 Shift; + FxBool Invert; +}; + +/* Voodoo5's texture combine environment */ +struct tdfx_texcombine_ext { + struct tdfx_alpha_texenv Alpha; + struct tdfx_color_texenv Color; + GrColor_t EnvColor; +}; + +/* Used to track changes between Glide's state and Mesa's */ +struct tdfx_texstate { + GLuint Enabled; /* bitmask of all units */ + GLenum EnvMode[TDFX_NUM_TMU]; /* index is Glide index, not OpenGL */ + GLenum TexFormat[TDFX_NUM_TMU]; /* index is Glide index, not OpenGL */ +}; + +struct tdfx_color { + GrColor_t ClearColor; /* Buffer clear color value */ + GrAlpha_t ClearAlpha; /* Buffer clear alpha value */ + FxBool ColorMask[4]; /* Per-channel write enable flags */ + + GrColor_t MonoColor; /* Constant color value */ + + /* Alpha testing */ + GrCmpFnc_t AlphaFunc; /* Alpha test function */ + GrAlpha_t AlphaRef; /* Alpha ref value in range [0,255] */ + + /* Blending */ + GrAlphaBlendFnc_t BlendSrcRGB; /* Blend source RGB factor */ + GrAlphaBlendFnc_t BlendDstRGB; /* Blend destination RGB factor */ + GrAlphaBlendFnc_t BlendSrcA; /* Blend source alpha factor */ + GrAlphaBlendFnc_t BlendDstA; /* Blend destination alpha factor */ + + GrDitherMode_t Dither; /* Dither enable */ +}; + +struct tdfx_depth { + GrDepthBufferMode_t Mode; /* Fixed-point Z or floating-point W */ + FxI32 Bias; /* Polygon offset factor */ + GrCmpFnc_t Func; /* Depth test function */ + FxU32 Clear; /* Buffer clear value */ + FxBool Mask; /* Write enable flag */ +}; + +struct tdfx_stipple { + GrStippleMode_t Mode; /* Stipple enable/disable */ + FxU32 Pattern; /* 8x4 Stipple Pattern */ +}; + +struct tdfx_fog { + GrFogMode_t Mode; /* Glide fog mode */ + GrColor_t Color; /* Fog color value */ + GLenum TableMode; /* GL fog mode currently in table */ + GrFog_t *Table; /* Fog value table */ + FxFloat Density; /* Density >= 0 */ + FxFloat Near; /* Start distance in eye coords */ + FxFloat Far; /* End distance in eye coords */ +}; + +struct tdfx_stencil { + GrCmpFnc_t Function; /* Stencil function */ + GrStencil_t RefValue; /* Stencil reference value */ + GrStencil_t ValueMask; /* Value mask */ + GrStencil_t WriteMask; /* Write mask */ + GrStencil_t FailFunc; /* Stencil fail function */ + GrStencil_t ZFailFunc; /* Stencil pass, depth fail function */ + GrStencil_t ZPassFunc; /* Stencil pass, depth pass function */ + GrStencil_t Clear; /* Buffer clear value */ +}; + +struct tdfx_scissor { + FxU32 minX, minY; /* Lower left corner */ + FxU32 maxX, maxY; /* Upper right corner */ +}; + +struct tdfx_viewport { + GrCoordinateSpaceMode_t Mode; /* Coordinate space */ + FxI32 X, Y; /* Position */ + FxI32 Width, Height; /* Size */ + FxFloat Near, Far; /* Depth buffer range */ +}; + +struct tdfx_glide { + void *State; /* Mirror of internal Glide state */ + GrContext_t Context; /* Glide context identifier */ + FxI32 Board; /* Current graphics subsystem */ + GrColorFormat_t ColorFormat; /* Framebuffer format */ + GrOriginLocation_t Origin; /* Location of screen space origin */ + + FxBool Initialized; /* Glide initialization done? */ + + FxI32 SwapInterval; /* SwapBuffers interval */ + FxI32 MaxPendingSwaps; /* Maximum outstanding SwapBuffers */ + FxI32 TextureAlign; + + /* Extensions */ + FxBool HaveCombineExt; /* COMBINE */ + FxBool HaveCommandTransportExt; /* COMMAND_TRANSPORT */ + FxBool HaveFogCoordExt; /* FOGCOORD */ + FxBool HavePixelExt; /* PIXEXT */ + FxBool HaveTextureBufferExt; /* TEXTUREBUFFER */ + FxBool HaveTexFmtExt; /* TEXFMT */ + FxBool HaveTexUMAExt; /* TEXUMA */ + FxBool HaveTexus2; /* Texus 2 - FXT1 */ +}; + + +struct tdfx_context { + /* Set once and never changed: + */ + GLcontext *glCtx; /* The core Mesa context */ + GLvisual *glVis; /* Describes the color buffer */ + + GLuint new_state; + GLuint dirty; + + /* Mirror of hardware state, Glide parameters + */ + struct tdfx_texsource TexSource[TDFX_NUM_TMU]; + struct tdfx_texparams TexParams[TDFX_NUM_TMU]; + struct tdfx_texpalette TexPalette; + + /* Voodoo3 texture/color combine state */ + struct tdfx_combine ColorCombine; + struct tdfx_combine AlphaCombine; + struct tdfx_texcombine TexCombine[TDFX_NUM_TMU]; + + /* Voodoo5 texture/color combine state */ + struct tdfx_combine_color_ext ColorCombineExt; + struct tdfx_combine_alpha_ext AlphaCombineExt; + struct tdfx_texcombine_ext TexCombineExt[TDFX_NUM_TMU]; + + /* Tracks tex state difference between Glide and Mesa */ + struct tdfx_texstate TexState; + + GrBuffer_t DrawBuffer; /* Current draw buffer */ + GrBuffer_t ReadBuffer; /* Current read buffer */ + + struct tdfx_color Color; + struct tdfx_depth Depth; + struct tdfx_fog Fog; + struct tdfx_stencil Stencil; + struct tdfx_scissor Scissor; + struct tdfx_viewport Viewport; + struct tdfx_stipple Stipple; + + GrCullMode_t CullMode; + + struct tdfx_glide Glide; + + /* Variable-size Glide vertex formats + */ + GLuint vertsize; /* bytes per vertex */ + GLuint vertexFormat; /* the current format */ + void *layout[TDFX_NUM_LAYOUTS]; + + GLuint tmu_source[TDFX_NUM_TMU]; + GLuint tex_dest[MAX_TEXTURE_UNITS]; + + GLuint SetupIndex; + GLuint SetupDone; + GLuint RenderIndex; + + GLuint IndirectTriangles; + GLuint Fallback; + + GLfloat sScale0, tScale0; + GLfloat sScale1, tScale1; + +#if 0 + GLuint last_tri_caps; + GLuint stw_hint_state; /* for grHints */ +#endif + GLuint using_fast_path, passes, multipass; + GLuint texBindNumber; + GLint tmuSrc; + + int screen_width; + int screen_height; + +#if 0 + void *state; /* Glide state buffer */ + + GLint textureAlign; + GLboolean verbose; +#endif + GLboolean haveTwoTMUs; /* True if we have 2 tmu's */ + GLboolean haveHwStencil; + + GLint maxPendingSwapBuffers; + + /* stuff added for DRI */ + __DRIscreenPrivate *driScreen; + __DRIcontextPrivate *driContext; + __DRIdrawablePrivate *driDrawable; + drmContext hHWContext; + drmLock *driHwLock; + int driFd; + tdfxScreenPrivate *fxScreen; + TDFXSAREAPriv *sarea; + + + /* + * Changes during execution: + */ + int width, height; /* size of window */ + int x_offset; /* distance from window left to screen left */ + int y_offset; /* distance from window top to screen top */ + int y_delta; /* distance from window bottom to screen bottom */ + + int numClipRects; + XF86DRIClipRectPtr pClipRects; + GLboolean scissoredClipRects; /* if true, pClipRects is private storage */ + + + GuTexPalette glbPalette; /* global texture palette */ + + tdfx_interp_func interp; + + points_func PointsFunc; + line_func LineFunc; + triangle_func TriangleFunc; + quad_func QuadFunc; + render_func *RenderVBRawTab; + tdfxRenderEltsFunc RenderElementsRaw; + + + tdfxStats stats; + + /* HACK: Let's get some buffering of vertices happening... + */ + GLuint *buffer; + GLuint buffer_total; + GLuint buffer_used; +}; + +#define TDFX_CONTEXT(ctx) ((tdfxContextPtr)((ctx)->DriverCtx)) + + +extern GLboolean tdfxCreateContext( Display *dpy, GLvisual *mesaVis, + __DRIcontextPrivate *driContextPriv ); +extern void tdfxDestroyContext( tdfxContextPtr fxMesa ); + +extern GLboolean tdfxInitContext( __DRIdrawablePrivate *driDrawPriv, + tdfxContextPtr fxMesa ); + + +/* Color packing utilities + */ +#define TDFXPACKCOLOR332( r, g, b ) \ + (((b) & 0xe0) | (((g) & 0xe0) >> 3) | (((r) & 0xc0) >> 6)) + +#define TDFXPACKCOLOR1555( r, g, b, a ) \ + ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \ + ((a) ? 0x8000 : 0)) + +#define TDFXPACKCOLOR565( r, g, b ) \ + ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3)) + +#define TDFXPACKCOLOR888( r, g, b ) \ + (((b) << 16) | ((g) << 8) | (r)) + +#define TDFXPACKCOLOR8888( r, g, b, a ) \ + (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) + +#define TDFXPACKCOLOR4444( r, g, b, a ) \ + ((((a) & 0xf0) << 8) | (((b) & 0xf0) << 4) | ((g) & 0xf0) | ((r) >> 4)) + +static __inline__ GrColor_t tdfxPackColor( GLuint cpp, + GLubyte r, GLubyte g, + GLubyte b, GLubyte a ) +{ + switch ( cpp ) { + case 2: + return TDFXPACKCOLOR565( r, g, b ); + case 4: + return TDFXPACKCOLOR8888( r, g, b, a ); + default: + return 0; + } +} + +#define DO_DEBUG 0 +#if DO_DEBUG +extern int TDFX_DEBUG; +#else +#define TDFX_DEBUG 0 +#endif + +#define DEBUG_ALWAYS_SYNC 0x01 +#define DEBUG_VERBOSE_API 0x02 +#define DEBUG_VERBOSE_MSG 0x04 +#define DEBUG_VERBOSE_LRU 0x08 +#define DEBUG_VERBOSE_DRI 0x10 +#define DEBUG_VERBOSE_IOCTL 0x20 +#define DEBUG_VERBOSE_2D 0x40 + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* __TDFX_CONTEXT_H__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c new file mode 100644 index 000000000..ec5b25871 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.c @@ -0,0 +1,273 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_dd.h" +#include "tdfx_vb.h" +#include "tdfx_pipeline.h" +#include "tdfx_pixels.h" + +#include "enums.h" +#include "pb.h" + + +#define TDFX_DATE "20010104" + + +/* These are used in calls to FX_grColorMaskv() */ +const GLboolean false4[4] = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE }; +const GLboolean true4[4] = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE }; + + + +/* KW: Put the word Mesa in the render string because quakeworld + * checks for this rather than doing a glGet(GL_MAX_TEXTURE_SIZE). + * Why? + */ +static const GLubyte *tdfxDDGetString( GLcontext *ctx, GLenum name ) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + + switch ( name ) { + case GL_RENDERER: + { + static char buffer[100]; + char hardware[100]; + + strcpy( hardware, FX_grGetString( fxMesa, GR_HARDWARE ) ); + + if ( strcmp( hardware, "Voodoo3 (tm)" ) == 0 ) { + strcpy( hardware, "Voodoo3" ); + } + else if ( strcmp( hardware, "Voodoo Banshee (tm)" ) == 0 ) { + strcpy( hardware, "VoodooBanshee" ); + } + else if ( strcmp( hardware, "Voodoo4 (tm)" ) == 0 ) { + strcpy( hardware, "Voodoo4" ); + } + else if ( strcmp( hardware, "Voodoo5 (tm)" ) == 0 ) { + strcpy( hardware, "Voodoo5" ); + } + else { + /* unexpected result: replace spaces with hyphens */ + int i; + for ( i = 0 ; hardware[i] ; i++ ) { + if ( hardware[i] == ' ' || hardware[i] == '\t' ) + hardware[i] = '-'; + } + } + /* now make the GL_RENDERER string */ + sprintf( buffer, "Mesa DRI %s " TDFX_DATE, hardware ); + return buffer; + } + case GL_VENDOR: + return "VA Linux Systems, Inc."; + default: + return NULL; + } +} + + +/* Return buffer size information. + */ +static void tdfxDDGetBufferSize( GLcontext *ctx, + GLuint *width, GLuint *height ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + *width = fxMesa->width; + *height = fxMesa->height; +} + + +static GLint tdfxDDGetParameteri( const GLcontext *ctx, GLint param ) +{ + switch ( param ) { + case DD_HAVE_HARDWARE_FOG: + return 1; + default: + return 0; + } +} + +/* + * Return the current value of the occlusion test flag and + * reset the flag (hardware counters) to false. + */ +static GLboolean get_occlusion_result( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GLboolean result; + + LOCK_HARDWARE( fxMesa ); + + if (ctx->Depth.OcclusionTest) { + if (ctx->OcclusionResult) { + result = GL_TRUE; /* result of software rendering */ + } + else { + FxI32 zfail, in; + zfail = FX_grGetInteger_NoLock(GR_STATS_PIXELS_DEPTHFUNC_FAIL); + in = FX_grGetInteger_NoLock(GR_STATS_PIXELS_IN); + if (in == zfail) + result = GL_FALSE; /* geom was completely occluded */ + else + result = GL_TRUE; /* all or part of geom was visible */ + } + } + else { + result = ctx->OcclusionResultSaved; + } + + /* reset results now */ + grReset(GR_STATS_PIXELS); + ctx->OcclusionResult = GL_FALSE; + ctx->OcclusionResultSaved = GL_FALSE; + + UNLOCK_HARDWARE( fxMesa ); + + return result; +} + + +/* + * We're only implementing this function to handle the + * GL_OCCLUSTION_TEST_RESULT_HP case. It's special because it + * has a side-effect: resetting the occlustion result flag. + */ +static GLboolean tdfxDDGetBooleanv( GLcontext *ctx, GLenum pname, + GLboolean *result ) +{ + if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) { + *result = get_occlusion_result( ctx ); + return GL_TRUE; + } + return GL_FALSE; +} + +static GLboolean tdfxDDGetDoublev( GLcontext *ctx, GLenum pname, + GLdouble *result ) +{ + if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) { + *result = (GLdouble) get_occlusion_result( ctx ); + return GL_TRUE; + } + return GL_FALSE; +} + +static GLboolean tdfxDDGetFloatv( GLcontext *ctx, GLenum pname, + GLfloat *result ) +{ + if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) { + *result = (GLfloat) get_occlusion_result( ctx ); + return GL_TRUE; + } + return GL_FALSE; +} + +static GLboolean tdfxDDGetIntegerv( GLcontext *ctx, GLenum pname, + GLint *result ) +{ + if ( pname == GL_OCCLUSION_TEST_RESULT_HP ) { + *result = (GLint) get_occlusion_result( ctx ); + return GL_TRUE; + } + return GL_FALSE; +} + + + +#define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \ + ((vis->RedBits == r) && \ + (vis->GreenBits == g) && \ + (vis->BlueBits == b) && \ + (vis->AlphaBits == a)) + +void tdfxDDInitDriverFuncs( GLcontext *ctx ) +{ + if ( MESA_VERBOSE & VERBOSE_DRIVER ) { + fprintf( stderr, "tdfx: %s()\n", __FUNCTION__ ); + } + + ctx->Driver.GetString = tdfxDDGetString; + ctx->Driver.GetBufferSize = tdfxDDGetBufferSize; + ctx->Driver.Error = NULL; + ctx->Driver.GetParameteri = tdfxDDGetParameteri; + + if ( VISUAL_EQUALS_RGBA(ctx->Visual, 8, 8, 8, 8) ) + { + ctx->Driver.DrawPixels = tdfx_drawpixels_R8G8B8A8; + ctx->Driver.ReadPixels = tdfx_readpixels_R8G8B8A8; + ctx->Driver.CopyPixels = NULL; + ctx->Driver.Bitmap = NULL; + } + else if ( VISUAL_EQUALS_RGBA(ctx->Visual, 5, 6, 5, 0) ) + { + ctx->Driver.DrawPixels = NULL; + ctx->Driver.ReadPixels = tdfx_readpixels_R5G6B5; + ctx->Driver.CopyPixels = NULL; + ctx->Driver.Bitmap = NULL; + } + else + { + ctx->Driver.DrawPixels = NULL; + ctx->Driver.ReadPixels = NULL; + ctx->Driver.CopyPixels = NULL; + ctx->Driver.Bitmap = NULL; + } + + ctx->Driver.RegisterVB = tdfxDDRegisterVB; + ctx->Driver.UnregisterVB = tdfxDDUnregisterVB; + ctx->Driver.ResetVB = NULL; + ctx->Driver.ResetCvaVB = NULL; + + if ( !getenv( "TDFX_NO_FAST" ) ) { + ctx->Driver.BuildPrecalcPipeline = tdfxDDBuildPrecalcPipeline; + } else { + ctx->Driver.BuildPrecalcPipeline = NULL; + } + ctx->Driver.BuildEltPipeline = NULL; + + ctx->Driver.OptimizeImmediatePipeline = NULL; + ctx->Driver.OptimizePrecalcPipeline = NULL; + + ctx->Driver.GetBooleanv = tdfxDDGetBooleanv; + ctx->Driver.GetDoublev = tdfxDDGetDoublev; + ctx->Driver.GetFloatv = tdfxDDGetFloatv; + ctx->Driver.GetIntegerv = tdfxDDGetIntegerv; + ctx->Driver.GetPointerv = NULL; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.h new file mode 100644 index 000000000..1bb037a0f --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_dd.h @@ -0,0 +1,47 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_DD_H__ +#define __TDFX_DD_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "context.h" + +extern void tdfxDDInitDriverFuncs( GLcontext *ctx ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fastpath.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fastpath.c new file mode 100644 index 000000000..f41d86b3c --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fastpath.c @@ -0,0 +1,594 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#include "types.h" +#include "enums.h" +#include "cva.h" +#include "vertices.h" +#include "mmath.h" + +#include "tdfx_context.h" +#include "tdfx_state.h" +#include "tdfx_vb.h" +#include "tdfx_tris.h" +#include "tdfx_pipeline.h" + + +struct tdfx_fast_tab { + void (*build_vertices)( struct vertex_buffer *VB, GLuint do_cliptest ); + void (*interp)( GLfloat t, GLfloat *O, const GLfloat *I, const GLfloat *J ); + void (*project_vertices)( struct vertex_buffer *VB ); + void (*project_clipped_vertices)( struct vertex_buffer *VB ); +}; + + +#define POINT(x) tdfx_draw_point( fxMesa, &vert[x], psize ) +#define LINE(x,y) tdfx_draw_line( fxMesa, &vert[x], &vert[y], lwidth ) +#define TRI(x,y,z) grDrawTriangle( &vert[x], &vert[y], &vert[z] ); + + +#define INDIRECT_TRI(x,y,z) \ +do { \ + out[next_elt + 0] = &vert[x]; \ + out[next_elt + 1] = &vert[y]; \ + out[next_elt + 2] = &vert[z]; \ + next_elt += 3; \ +} while (0) + + + +/* Direct, and no clipping required. The clip funcs have not been + * written yet, so this is only useful for the fast path. + */ +#define RENDER_POINTS( start, count ) \ +do { \ + GLuint e; \ + for ( e = start ; e < count ; e++ ) \ + POINT( elt[e] ); \ +} while (0) + +#define RENDER_LINE( i1, i ) \ +do { \ + GLuint e1 = elt[i1], e = elt[i]; \ + LINE( e1, e ); \ +} while (0) + +#define RENDER_TRI( i2, i1, i, pv, parity ) \ +do { \ + GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ + if ( parity ) { \ + GLuint tmp = e2; e2 = e1; e1 = tmp; \ + } \ + TRI( e2, e1, e ); \ +} while (0) + +#define RENDER_QUAD( i3, i2, i1, i, pv ) \ +do { \ + GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ + TRI( e3, e2, e ); \ + TRI( e2, e1, e ); \ +} while (0) + +#define LOCAL_VARS \ + tdfxVertexPtr vert = TDFX_DRIVER_DATA(VB)->verts; \ + const GLuint *elt = VB->EltPtr->data; \ + GLcontext *ctx = VB->ctx; \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \ + const GLfloat lwidth = ctx->Line.Width; \ + const GLfloat psize = ctx->Point.Size; \ + (void) lwidth; (void) psize; (void) vert; (void) fxMesa; + +#define TAG(x) tdfx_##x##_smooth_direct +#include "render_tmp.h" + + + +/* Indirect, and no clipping required. The clip funcs have not been + * written yet, so this is only useful for the fast path. + */ +#define RENDER_POINTS( start, count ) \ +do { \ + GLuint e; \ + for ( e = start ; e < count ; e++ ) \ + POINT( elt[e] ); \ +} while (0) + +#define RENDER_LINE( i1, i ) \ +do { \ + GLuint e1 = elt[i1], e = elt[i]; \ + LINE( e1, e ); \ +} while (0) + +#define RENDER_TRI( i2, i1, i, pv, parity ) \ +do { \ + GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ + if ( parity ) { \ + GLuint tmp = e2; e2 = e1; e1 = tmp; \ + } \ + INDIRECT_TRI( e2, e1, e ); \ +} while (0) + +#define RENDER_QUAD( i3, i2, i1, i, pv ) \ +do { \ + GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i]; \ + TRI( e3, e2, e ); \ + TRI( e2, e1, e ); \ +} while (0) + +#define LOCAL_VARS \ + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); \ + tdfxVertexPtr vert = fxVB->verts; \ + GLuint next_elt = fxVB->last_elt; \ + tdfxVertexPtr *out = fxVB->elts; \ + const GLuint *elt = VB->EltPtr->data; \ + GLcontext *ctx = VB->ctx; \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \ + const GLfloat lwidth = ctx->Line.Width; \ + const GLfloat psize = ctx->Point.Size; \ + (void) lwidth; (void) psize; (void) vert; (void) out; (void) fxMesa; + +#define POSTFIX \ + fxVB->last_elt = next_elt; + +#define TAG(x) tdfx_##x##_smooth_indirect +#include "render_tmp.h" + + + +#define NEGATIVE(f) (f < 0) +#define DIFFERENT_SIGNS(a,b) ((a*b) < 0) +#define LINTERP(T, A, B) ((A) + (T) * ((B) - (A))) + +#define INTERP_RGBA( t, out, a, b ) \ +do { \ + int i; \ + for ( i = 0 ; i < 4 ; i++ ) { \ + GLfloat fa = UBYTE_COLOR_TO_FLOAT_COLOR( a[i] ); \ + GLfloat fb = UBYTE_COLOR_TO_FLOAT_COLOR( b[i] ); \ + GLfloat fo = LINTERP( t, fa, fb ); \ + FLOAT_COLOR_TO_UBYTE_COLOR( out[i], fo ); \ + } \ +} while (0) + +#define CLIP( SGN, V, PLANE ) \ +do { \ + if ( mask & PLANE ) { \ + GLuint *indata = inlist[in]; \ + GLuint *outdata = inlist[in ^= 1]; \ + GLuint nr = n; \ + GLfloat *J = verts[indata[nr-1]].f; \ + GLfloat dpJ = (SGN J[V]) + J[3]; \ + \ + inlist[0] = vlist1; \ + for ( i = n = 0 ; i < nr ; i++ ) { \ + GLuint elt_i = indata[i]; \ + GLfloat *I = verts[elt_i].f; \ + GLfloat dpI = (SGN I[V]) + I[3]; \ + \ + if ( DIFFERENT_SIGNS( dpI, dpJ ) ) { \ + GLfloat *O = verts[next_vert].f; \ + GLfloat t, *in, *out; \ + \ + if ( NEGATIVE( dpI ) ) { \ + t = dpI / (dpI - dpJ); \ + in = I; \ + out = J; \ + } else { \ + t = dpJ / (dpJ - dpI); \ + in = J; \ + out = I; \ + } \ + \ + interp( t, O, in, out ); \ + \ + clipmask[next_vert] = 0; \ + outdata[n++] = next_vert++; \ + } \ + \ + clipmask[elt_i] |= PLANE; /* don't set up */ \ + \ + if ( !NEGATIVE( dpI ) ) { \ + outdata[n++] = elt_i; \ + clipmask[elt_i] &= ~PLANE; /* set up after all */ \ + } \ + \ + J = I; \ + dpJ = dpI; \ + } \ + \ + if ( n < 3 ) return; \ + } \ +} while (0) + +#define LINE_CLIP( x, y, z, w, PLANE ) \ +do { \ + if ( mask & PLANE ) { \ + GLfloat dpI = DOT4V( I, x, y, z, w ); \ + GLfloat dpJ = DOT4V( J, x, y, z, w ); \ + \ + if ( DIFFERENT_SIGNS( dpI, dpJ ) ) { \ + GLfloat *O = verts[next_vert].f; \ + GLfloat t = dpI / (dpI - dpJ); \ + \ + interp( t, O, I, J ); \ + \ + clipmask[next_vert] = 0; \ + \ + if ( NEGATIVE( dpI ) ) { \ + clipmask[elts[0]] |= PLANE; \ + I = O; \ + elts[0] = next_vert++; \ + } else { \ + clipmask[elts[1]] |= PLANE; \ + J = O; \ + elts[1] = next_vert++; \ + } \ + } else if ( NEGATIVE( dpI ) ) { \ + return; \ + } \ + } \ +} while (0) + + +static __inline void tdfx_tri_clip( GLuint **p_elts, + tdfxVertex *verts, + GLubyte *clipmask, + GLuint *p_next_vert, + GLubyte mask, + tdfx_interp_func interp ) +{ + GLuint *elts = *p_elts; + GLuint next_vert = *p_next_vert; + GLuint in = 0; + GLuint n = 3; + GLuint vlist1[VB_MAX_CLIPPED_VERTS]; + GLuint vlist2[VB_MAX_CLIPPED_VERTS]; + GLuint *inlist[2]; + GLuint *out; + GLuint i; + + inlist[0] = elts; + inlist[1] = vlist2; + + CLIP( -, 0, CLIP_RIGHT_BIT ); + CLIP( +, 0, CLIP_LEFT_BIT ); + CLIP( -, 1, CLIP_TOP_BIT ); + CLIP( +, 1, CLIP_BOTTOM_BIT ); + CLIP( -, 2, CLIP_FAR_BIT ); + CLIP( +, 2, CLIP_NEAR_BIT ); + + /* Convert the planar polygon to a list of triangles */ + out = inlist[in]; + + for ( i = 2 ; i < n ; i++ ) { + elts[0] = out[0]; + elts[1] = out[i-1]; + elts[2] = out[i]; + elts += 3; + } + + *p_next_vert = next_vert; + *p_elts = elts; +} + + +static __inline void tdfx_line_clip( GLuint **p_elts, + tdfxVertex *verts, + GLubyte *clipmask, + GLuint *p_next_vert, + GLubyte mask, + tdfx_interp_func interp ) +{ + GLuint *elts = *p_elts; + GLfloat *I = verts[elts[0]].f; + GLfloat *J = verts[elts[1]].f; + GLuint next_vert = *p_next_vert; + + LINE_CLIP( 1, 0, 0, -1, CLIP_LEFT_BIT ); + LINE_CLIP( -1, 0, 0, 1, CLIP_RIGHT_BIT ); + LINE_CLIP( 0, 1, 0, -1, CLIP_TOP_BIT ); + LINE_CLIP( 0, -1, 0, 1, CLIP_BOTTOM_BIT ); + LINE_CLIP( 0, 0, 1, -1, CLIP_FAR_BIT ); + LINE_CLIP( 0, 0, -1, 1, CLIP_NEAR_BIT ); + + *p_next_vert = next_vert; + *p_elts += 2; +} + + +#define CLIP_POINT( e ) \ +do { \ + if ( mask[e] ) *out++ = e; \ +} while (0) + +#define CLIP_LINE( e1, e0 ) \ +do { \ + GLubyte ormask = mask[e0] | mask[e1]; \ + out[0] = e1; \ + out[1] = e0; \ + out += 2; \ + if ( ormask ) { \ + out-=2; \ + if ( !(mask[e0] & mask[e1]) ) { \ + tdfx_line_clip( &out, verts, mask, \ + &next_vert, ormask, interp ); \ + } \ + } \ +} while (0) + +#define CLIP_TRIANGLE( e2, e1, e0 ) \ +do { \ + GLubyte ormask; \ + out[0] = e2; \ + out[1] = e1; \ + out[2] = e0; \ + out += 3; \ + ormask = mask[e2] | mask[e1] | mask[e0]; \ + if ( ormask ) { \ + out -= 3; \ + if ( !(mask[e2] & mask[e1] & mask[e0]) ) { \ + tdfx_tri_clip( &out, verts, mask, \ + &next_vert, ormask, interp ); \ + } \ + } \ +} while (0) + + + +/* Build a table of functions to clip each primitive type. These + * produce a list of elements in the appropriate 'reduced' primitive, + * ie (points, lines, triangles) containing all the clipped and + * unclipped primitives from the original list. + */ +#define LOCAL_VARS \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(VB->ctx); \ + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); \ + GLuint *elt = VB->EltPtr->data; \ + tdfxVertexPtr verts = fxVB->verts; \ + GLuint next_vert = fxVB->last_vert; \ + GLuint *out = fxVB->clipped_elements.data; \ + GLubyte *mask = VB->ClipMask; \ + tdfx_interp_func interp = fxMesa->interp; \ + (void) interp; (void) verts; + +#define POSTFIX \ + fxVB->clipped_elements.count = out - fxVB->clipped_elements.data; \ + fxVB->last_vert = next_vert; + + +#define INIT( x ) + +#define RENDER_POINTS( start, count ) \ +do { \ + GLuint i; \ + for ( i = start ; i < count ; i++ ) \ + CLIP_POINT( elt[i] ); \ +} while (0) + +#define RENDER_LINE( i1, i0 ) \ +do { \ + CLIP_LINE( elt[i1], elt[i0] ); \ +} while (0) + +#define RENDER_TRI( i2, i1, i0, pv, parity ) \ +do { \ + GLuint e2 = elt[i2], e1 = elt[i1], e0 = elt[i0]; \ + if ( parity ) e2 = elt[i1], e1 = elt[i2]; \ + CLIP_TRIANGLE( e2, e1, e0 ); \ +} while (0) + +#define RENDER_QUAD( i3, i2, i1, i0, pv ) \ +do { \ + CLIP_TRIANGLE( elt[i3], elt[i2], elt[i0] ); \ + CLIP_TRIANGLE( elt[i2], elt[i1], elt[i0] ); \ +} while (0) + +#define TAG(x) tdfx_##x##_clip_elt +#include "render_tmp.h" + + + + +/* Pack rgba and/or texture into the remaining half of a 32 byte vertex. + */ +#define CLIP_UBYTE_COLOR 4 +#define CLIP_UBYTE_B 0 +#define CLIP_UBYTE_G 1 +#define CLIP_UBYTE_R 2 +#define CLIP_UBYTE_A 3 +#define CLIP_S0 6 +#define CLIP_T0 7 +#define CLIP_S1 8 +#define CLIP_T1 9 + +#define TYPE (0) +#define TAG(x) x +#include "tdfx_fasttmp.h" + +#define TYPE (TDFX_RGBA_BIT) +#define TAG(x) x##_RGBA +#include "tdfx_fasttmp.h" + +#define TYPE (TDFX_TEX0_BIT) +#define TAG(x) x##_TEX0 +#include "tdfx_fasttmp.h" + +#define TYPE (TDFX_RGBA_BIT | TDFX_TEX0_BIT) +#define TAG(x) x##_RGBA_TEX0 +#include "tdfx_fasttmp.h" + +#define TYPE (TDFX_RGBA_BIT | TDFX_TEX0_BIT | TDFX_TEX1_BIT) +#define TAG(x) x##_RGBA_TEX0_TEX1 +#include "tdfx_fasttmp.h" + +/* This one *could* get away with sneaking TEX1 into the color and + * specular slots, thus fitting inside a cache line. Would be even + * better to switch to a smaller vertex. + */ +#define TYPE (TDFX_TEX0_BIT | TDFX_TEX1_BIT) +#define TAG(x) x##_TEX0_TEX1 +#include "tdfx_fasttmp.h" + + + +/* Render elements directly from original list of vertices. + */ +static void tdfx_render_elements_direct( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GLenum prim = ctx->CVA.elt_mode; + GLuint nr = VB->EltPtr->count; + render_func func = tdfx_render_tab_smooth_direct[prim]; + GLuint p = 0; + + if ( fxMesa->new_state ) + tdfxDDUpdateHwState( ctx ); + + BEGIN_CLIP_LOOP( fxMesa ); + do { + func( VB, 0, nr, 0 ); + } while ( ctx->Driver.MultipassFunc && + ctx->Driver.MultipassFunc( VB, ++p ) ); + END_CLIP_LOOP( fxMesa ); +} + +/* Render elements indirectly from original list of vertices. + */ +#if 0 +static void tdfx_render_elements_indirect( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + GLenum prim = ctx->CVA.elt_mode; + GLuint nr = VB->EltPtr->count; + render_func func = tdfx_render_tab_smooth_indirect[prim]; + GLuint p = 0; + + if ( fxMesa->new_state ) + tdfxDDUpdateHwState( ctx ); + + do { + func( VB, 0, nr, 0 ); + } while ( ctx->Driver.MultipassFunc && + ctx->Driver.MultipassFunc( VB, ++p ) ); + + BEGIN_CLIP_LOOP( fxMesa ); + grDrawVertexArray( GR_TRIANGLES, fxVB->last_elt, fxVB->elts ); + END_CLIP_LOOP( fxMesa ); + + fxVB->last_elt = 0; +} +#endif + +/* Very sparsely popluated array - fix the indices. + */ +static struct tdfx_fast_tab fxFastTab[0x80]; + +void tdfxDDFastPathInit( void ) +{ + tdfx_render_init_clip_elt(); + tdfx_render_init_smooth_direct(); + tdfx_render_init_smooth_indirect(); + + tdfx_init_fastpath( &fxFastTab[0] ); + tdfx_init_fastpath_RGBA( &fxFastTab[TDFX_RGBA_BIT] ); + tdfx_init_fastpath_TEX0( &fxFastTab[TDFX_TEX0_BIT] ); + tdfx_init_fastpath_RGBA_TEX0( &fxFastTab[TDFX_RGBA_BIT|TDFX_TEX0_BIT] ); + tdfx_init_fastpath_TEX0_TEX1( &fxFastTab[TDFX_TEX0_BIT|TDFX_TEX1_BIT] ); + tdfx_init_fastpath_RGBA_TEX0_TEX1( &fxFastTab[TDFX_RGBA_BIT|TDFX_TEX0_BIT| + TDFX_TEX1_BIT] ); +} + + +#define VALID_SETUP (TDFX_RGBA_BIT | TDFX_TEX0_BIT | TDFX_TEX1_BIT) + + +void tdfxDDFastPath( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + GLenum prim = ctx->CVA.elt_mode; + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + struct tdfx_fast_tab *tab = &fxFastTab[fxMesa->SetupIndex & VALID_SETUP]; + + if ( fxMesa->new_state ) { + tdfxDDUpdateHwState( ctx ); + } + else if ( fxMesa->dirty & TDFX_UPLOAD_VERTEX_LAYOUT ) { + /* After extensive debugging I discovered that the vertex layout + * may need to be updated at this point. Not sure how this works + * in the other drivers. -BP + */ + LOCK_HARDWARE( fxMesa ); + grGlideSetVertexLayout( fxMesa->layout[fxMesa->vertexFormat] ); + fxMesa->dirty &= ~TDFX_UPLOAD_VERTEX_LAYOUT; + UNLOCK_HARDWARE( fxMesa ); + } + + gl_prepare_arrays_cva( VB ); /* still need this */ + + /* Reserve enough space for the pathological case */ + if ( VB->EltPtr->count * 12 > fxVB->size ) + tdfxDDResizeVB( VB, VB->EltPtr->count * 12 ); + + tab->build_vertices( VB, 1 ); /* object->clip space */ + + if ( VB->ClipOrMask ) { + if ( !VB->ClipAndMask ) { + render_func *clip = tdfx_render_tab_clip_elt; + + fxMesa->interp = tab->interp; + + clip[prim]( VB, 0, VB->EltPtr->count, 0 ); /* build new elts */ + + ctx->CVA.elt_mode = gl_reduce_prim[prim]; + VB->EltPtr = &(fxVB->clipped_elements); + + tab->project_clipped_vertices( VB ); /* clip->device space */ + tdfx_render_elements_direct( VB ); /* render using new list */ + } + } else { + tab->project_vertices( VB ); /* clip->device space */ + tdfx_render_elements_direct( VB ); /* render using orig list */ + } + + /* This indicates that there is no cached data to reuse */ + VB->pipeline->data_valid = 0; + VB->pipeline->new_state = 0; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fasttmp.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fasttmp.h new file mode 100644 index 000000000..24abcb4eb --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fasttmp.h @@ -0,0 +1,293 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +/* The first part of setup is applied to all vertices, clipped or + * unclipped. This data will be used for clipping, and then all + * vertices with a zero clipmask will be projected to device space. + * + * This could be split into several loops, but - it seems that the + * large stride of the fxVertices makes cache issues the big + * performance factor, and that multiple loops mean multiple cache + * misses.... + */ + +static void TAG(tdfx_setup_full)( struct vertex_buffer *VB, + GLuint do_cliptest ) +{ + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + const GLfloat * const m = ctx->ModelProjectMatrix.m; + GLuint start = VB->CopyStart; + GLuint count = VB->Count; + + if (0) fprintf(stderr, "%s\n", __FUNCTION__); + + gl_xform_points3_v16_general( TDFX_DRIVER_DATA(VB)->verts[start].f, + m, + VB->ObjPtr->start, + VB->ObjPtr->stride, + count - start ); + + if ( do_cliptest ) { + VB->ClipAndMask = ~0; + VB->ClipOrMask = 0; + gl_cliptest_points4_v16( fxVB->verts[start].f, + fxVB->verts[count].f, + &(VB->ClipOrMask), + &(VB->ClipAndMask), + VB->ClipMask + start ); + } + + /* These branches are all resolved at compile time. Hopefully all + * the pointers are valid addresses even when not enabled. + */ + if ( TYPE ) { + GLubyte *color = VB->ColorPtr->start; + GLfloat *tex0_data = VB->TexCoordPtr[fxMesa->tmu_source[0]]->start; + GLfloat *tex1_data = VB->TexCoordPtr[fxMesa->tmu_source[1]]->start; + + const GLuint color_stride = VB->ColorPtr->stride; + const GLuint tex0_stride = VB->TexCoordPtr[fxMesa->tmu_source[0]]->stride; + const GLuint tex1_stride = VB->TexCoordPtr[fxMesa->tmu_source[1]]->stride; + + GLfloat *f = fxVB->verts[start].f; + GLfloat *end = f + (16 * (count - start)); + + while ( f != end ) { + if ( TYPE & TDFX_RGBA_BIT ) { +#if defined(USE_X86_ASM) + __asm__ ( + "movl (%%edx),%%eax \n" + "bswap %%eax \n" + "rorl $8,%%eax \n" + "movl %%eax,16(%%edi) \n" + : + : "d" (color), "D" (f) + : "%eax" ); +#else + GLubyte *col = color; + GLubyte *b = (GLubyte *)&f[CLIP_UBYTE_COLOR]; + b[CLIP_UBYTE_B] = col[2]; + b[CLIP_UBYTE_G] = col[1]; + b[CLIP_UBYTE_R] = col[0]; + b[CLIP_UBYTE_A] = col[3]; +#endif + } + if (TYPE & TDFX_TEX0_BIT) { +#if defined (USE_X86_ASM) + __asm__ ( + "movl (%%ecx), %%eax \n" + "movl %%eax, 24(%%edi) \n" + "movl 4(%%ecx), %%eax \n" + "movl %%eax, 28(%%edi)" + : + : "c" (tex0_data), "D" (f) + : "%eax"); +#else + *(unsigned int *)(f+CLIP_S0) = *(unsigned int *)tex0_data; + *(unsigned int *)(f+CLIP_T0) = *(unsigned int *)(tex0_data+1); +#endif + } + if (TYPE & TDFX_TEX1_BIT) { + /* Hits a second cache line. + */ +#if defined (USE_X86_ASM) + __asm__ ( + "movl (%%esi), %%eax \n" + "movl %%eax, 32(%%edi) \n" + "movl 4(%%esi), %%eax \n" + "movl %%eax, 36(%%edi)" + : + : "S" (tex1_data), "D" (f) + : "%eax"); +#else + *(unsigned int *)(f+CLIP_S1) = *(unsigned int *)tex1_data; + *(unsigned int *)(f+CLIP_T1) = *(unsigned int *)(tex1_data+1); +#endif + } + if ( TYPE & TDFX_RGBA_BIT ) color += color_stride; + if ( TYPE & TDFX_TEX0_BIT ) STRIDE_F( tex0_data, tex0_stride ); + if ( TYPE & TDFX_TEX1_BIT ) STRIDE_F( tex1_data, tex1_stride ); + f += 16; + } + } + + fxVB->clipped_elements.count = start; + fxVB->last_vert = count; +} + + +/* Changed to just put the interp func instead of the whole clip + * routine into the header. Less code and better chance of doing some + * of this stuff in assembly. + */ +static void TAG(tdfx_interp_vert)( GLfloat t, + GLfloat *O, + const GLfloat *I, + const GLfloat *J ) +{ + O[0] = LINTERP( t, I[0], J[0] ); + O[1] = LINTERP( t, I[1], J[1] ); + O[2] = LINTERP( t, I[2], J[2] ); + O[3] = LINTERP( t, I[3], J[3] ); + + if ( TYPE & TDFX_RGBA_BIT ) { + INTERP_RGBA( t, + ((GLubyte *)&(O[4])), + ((GLubyte *)&(I[4])), + ((GLubyte *)&(J[4])) ); + } + + if ( TYPE & TDFX_TEX0_BIT ) { + O[6] = LINTERP( t, I[6], J[6] ); + O[7] = LINTERP( t, I[7], J[7] ); + } + + if ( TYPE & TDFX_TEX1_BIT ) { + O[8] = LINTERP( t, I[8], J[8] ); + O[9] = LINTERP( t, I[9], J[9] ); + } +} + + + +static void TAG(tdfx_project_vertices)( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + GLmatrix *mat = &ctx->Viewport.WindowMap; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + GLfloat *first = fxVB->verts[VB->CopyStart].f; + GLfloat *last = fxVB->verts[fxVB->last_vert].f; + GLfloat m[16]; + GLfloat *f; + + m[MAT_SX] = mat->m[MAT_SX]; + m[MAT_TX] = mat->m[MAT_TX] + fxMesa->x_offset + TRI_X_OFFSET; + m[MAT_SY] = mat->m[MAT_SY]; + m[MAT_TY] = mat->m[MAT_TY] + fxMesa->y_delta + TRI_Y_OFFSET; + m[MAT_SZ] = mat->m[MAT_SZ]; + m[MAT_TZ] = mat->m[MAT_TZ]; + + gl_project_v16( first, last, m, 16 * 4 ); + + /* V3 at least requires texcoords to be multiplied by 1/w: + */ + if ( TYPE & (TDFX_TEX0_BIT|TDFX_TEX1_BIT) ) { + + const GLfloat sScale0 = fxMesa->sScale0; + const GLfloat tScale0 = fxMesa->tScale0; + const GLfloat sScale1 = fxMesa->sScale1; + const GLfloat tScale1 = fxMesa->tScale1; + + + for ( f = first ; f != last ; f += 16) { + const GLfloat oow = f[3]; + + if (TYPE & TDFX_TEX0_BIT) { + f[CLIP_S0] *= sScale0 * oow; + f[CLIP_T0] *= tScale0 * oow; + } + + if (TYPE & TDFX_TEX1_BIT) { + f[CLIP_S1] *= sScale1 * oow; + f[CLIP_T1] *= tScale1 * oow; + } + } + } +} + +static void TAG(tdfx_project_clipped_vertices)( struct vertex_buffer *VB ) +{ + GLfloat *f; + + GLcontext *ctx = VB->ctx; + GLmatrix *mat = &ctx->Viewport.WindowMap; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + GLfloat *first = fxVB->verts[VB->CopyStart].f; + GLfloat *last = fxVB->verts[fxVB->last_vert].f; + const GLubyte *mask = VB->ClipMask + VB->CopyStart; + GLfloat m[16]; + + m[MAT_SX] = mat->m[MAT_SX]; + m[MAT_TX] = mat->m[MAT_TX] + fxMesa->x_offset + TRI_X_OFFSET; + m[MAT_SY] = mat->m[MAT_SY]; + m[MAT_TY] = mat->m[MAT_TY] + fxMesa->y_delta + TRI_Y_OFFSET; + m[MAT_SZ] = mat->m[MAT_SZ]; + m[MAT_TZ] = mat->m[MAT_TZ]; + + gl_project_clipped_v16( first, last, m, 16 * 4, mask ); + + /* V3 at least requires texcoords to be multiplied by 1/w: + */ + if ( TYPE & (TDFX_TEX0_BIT|TDFX_TEX1_BIT) ) { + + const GLfloat sScale0 = fxMesa->sScale0; + const GLfloat tScale0 = fxMesa->tScale0; + const GLfloat sScale1 = fxMesa->sScale1; + const GLfloat tScale1 = fxMesa->tScale1; + + for ( f = first ; f != last ; f += 16, mask++) { + if (!*mask) { + const GLfloat oow = f[3]; + if (TYPE & TDFX_TEX0_BIT) { + f[CLIP_S0] *= sScale0 * oow; + f[CLIP_T0] *= tScale0 * oow; + } + + if (TYPE & TDFX_TEX1_BIT) { + f[CLIP_S1] *= sScale1 * oow; + f[CLIP_T1] *= tScale1 * oow; + } + } + } + } +} + +static void TAG(tdfx_init_fastpath)( struct tdfx_fast_tab *tab ) +{ + tab->build_vertices = TAG(tdfx_setup_full); + tab->interp = TAG(tdfx_interp_vert); + tab->project_vertices = TAG(tdfx_project_vertices); + tab->project_clipped_vertices = TAG(tdfx_project_clipped_vertices); +} + +#undef TYPE +#undef TAG +#undef SIZE diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.c new file mode 100644 index 000000000..1f49142be --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.c @@ -0,0 +1,122 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> + +#include "tdfx_context.h" +#include "tdfx_g3ext.h" + + +/* STENCIL extension + */ +GrProc grStencilFuncProc = NULL; +GrProc grStencilMaskProc = NULL; +GrProc grStencilOpProc = NULL; +GrProc grBufferClearExtProc = NULL; +GrProc grColorMaskExtProc = NULL; + +/* COMBINE extension + */ +GrProc grColorCombineExtProc = NULL; +GrProc grTexColorCombineExtProc = NULL; +GrProc grAlphaCombineExtProc = NULL; +GrProc grTexAlphaCombineExtProc = NULL; +GrProc grAlphaBlendFunctionExtProc = NULL; +GrProc grConstantColorValueExtProc = NULL; + +/* Texus 2 + */ +GrProc txImgQuantizeProc = NULL; +GrProc txImgDequantizeFXT1Proc = NULL; +GrProc txErrorSetCallbackProc = NULL; + + +/* Initialize the Glide extensions not exported in the Glide headers. + * This is just plain evil stuff... + */ +void tdfxDDGlideExtensionsInit( void ) +{ + void *handle; + + /* Get Glide3 extension function pointers */ + handle = dlopen( NULL, RTLD_NOW | RTLD_GLOBAL ); + + if ( handle ) { + /* PIXEXT extension */ + grStencilFuncProc = dlsym( handle, "grStencilFunc" ); + grStencilMaskProc = dlsym( handle, "grStencilMask" ); + grStencilOpProc = dlsym( handle, "grStencilOp" ); + grBufferClearExtProc = dlsym( handle, "grBufferClearExt" ); + grColorMaskExtProc = dlsym( handle, "grColorMaskExt" ); + + /* COMBINE extension */ + grColorCombineExtProc = dlsym( handle, "grColorCombineExt" ); + grTexColorCombineExtProc = dlsym( handle, "grTexColorCombineExt" ); + grAlphaCombineExtProc = dlsym( handle, "grAlphaCombineExt" ); + grTexAlphaCombineExtProc = dlsym( handle, "grTexAlphaCombineExt" ); + grAlphaBlendFunctionExtProc = dlsym( handle, "grAlphaBlendFunctionExt" ); + grConstantColorValueExtProc = dlsym( handle, "grConstantColorValueExt" ); + + /* Texus 2 */ + txImgQuantizeProc = dlsym( handle, "txImgQuantize" ); + txImgDequantizeFXT1Proc = dlsym( handle, "_txImgDequantizeFXT1" ); + txErrorSetCallbackProc = dlsym( handle, "txErrorSetCallback" ); + } else { + /* PIXEXT extension */ + grStencilFuncProc = NULL; + grStencilMaskProc = NULL; + grStencilOpProc = NULL; + grBufferClearExtProc = NULL; + grColorMaskExtProc = NULL; + + /* COMBINE extension */ + grColorCombineExtProc = NULL; + grTexColorCombineExtProc = NULL; + grAlphaCombineExtProc = NULL; + grTexAlphaCombineExtProc = NULL; + grAlphaBlendFunctionExtProc = NULL; + grConstantColorValueExtProc = NULL; + + /* Texus 2 */ + txImgQuantizeProc = NULL; + txImgDequantizeFXT1Proc = NULL; + txErrorSetCallbackProc = NULL; + } + + dlclose( handle ); +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.h new file mode 100644 index 000000000..29cfc0907 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_g3ext.h @@ -0,0 +1,145 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_G3EXT_H__ +#define __TDFX_G3EXT_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include <glide.h> +#include <g3ext.h> + +/* + * These are glide extension definitions. These are not + * defined in glide.h. They should really be defined in + * g3ext.h, but they are not. + */ +typedef void (*grStencilFunc_t)( GrCmpFnc_t fnc, GrStencil_t ref, + GrStencil_t mask ); +typedef void (*grStencilMask_t)( GrStencil_t write_mask ); +typedef void (*grStencilOp_t)( GrStencilOp_t stencil_fail, + GrStencilOp_t depth_fail, + GrStencilOp_t depth_pass ); +typedef void (*grBufferClearExt_t)( GrColor_t color, GrAlpha_t alpha, + FxU32 depth, GrStencil_t stencil ); +typedef void (*grColorMaskExt_t)( FxBool r, FxBool g, FxBool b, FxBool a ); + +/* + * "COMBINE" extension for Napalm + */ +typedef void (*grColorCombineExt_t)( GrCCUColor_t a, GrCombineMode_t a_mode, + GrCCUColor_t b, GrCombineMode_t b_mode, + GrCCUColor_t c, FxBool c_invert, + GrCCUColor_t d, FxBool d_invert, + FxU32 shift, FxBool invert ); +typedef void (*grTexColorCombineExt_t)( FxU32 tmu, + GrTCCUColor_t a, + GrCombineMode_t a_mode, + GrTCCUColor_t b, + GrCombineMode_t b_mode, + GrTCCUColor_t c, FxBool c_invert, + GrTCCUColor_t d, FxBool d_invert, + FxU32 shift, FxBool invert ); +typedef void (*grAlphaCombineExt_t)( GrACUColor_t a, GrCombineMode_t a_mode, + GrACUColor_t b, GrCombineMode_t b_mode, + GrACUColor_t c, FxBool c_invert, + GrACUColor_t d, FxBool d_invert, + FxU32 shift, FxBool invert ); +typedef void (*grTexAlphaCombineExt_t)( FxU32 tmu, + GrTACUColor_t a, + GrCombineMode_t a_mode, + GrTACUColor_t b, + GrCombineMode_t b_mode, + GrTACUColor_t c, FxBool c_invert, + GrTACUColor_t d, FxBool d_invert, + FxU32 shift, FxBool invert ); +typedef void (*grAlphaBlendFunctionExt_t)( GrAlphaBlendFnc_t rgb_sf, + GrAlphaBlendFnc_t rgb_df, + GrAlphaBlendOp_t rgb_op, + GrAlphaBlendFnc_t alpha_sf, + GrAlphaBlendFnc_t alpha_df, + GrAlphaBlendOp_t alpha_op); +typedef void (*grConstantColorValueExt_t)( FxU32 tmu, GrColor_t value ); + + + +/* + * These are functions to compress and decompress images. + * The types of the first and second parameters are not exactly + * right. The texus library declares them to be "char *", not + * "void *". However, "void *" is more correct, and more convenient. + */ +typedef void (*txImgQuantize_t)( void *dst, void *src, + int w, int h, + FxU32 format, FxU32 dither ); +typedef void (*txImgDeQuantize_t)( void *dst, void *src, int w, int h ); + +/* + * These next three declarations should probably be taken from + * texus.h. However, there are duplicate declarations in g3ext.h + * and texus.h which make it hard to include them both. + */ +typedef void (*TxErrorCallbackFnc_t)( const char *string, FxBool fatal ); +typedef void (*txErrorSetCallback_t)( TxErrorCallbackFnc_t fnc, + TxErrorCallbackFnc_t *old_fnc ); + +/* PIXEXT extension + */ +GrProc grStencilFuncProc; +GrProc grStencilMaskProc; +GrProc grStencilOpProc; +GrProc grBufferClearExtProc; +GrProc grColorMaskExtProc; + +/* COMBINE extension + */ +GrProc grColorCombineExtProc; +GrProc grTexColorCombineExtProc; +GrProc grAlphaCombineExtProc; +GrProc grTexAlphaCombineExtProc; +GrProc grAlphaBlendFunctionExtProc; +GrProc grConstantColorValueExtProc; + +/* Texus extensions??? + */ +GrProc txImgQuantizeProc; +GrProc txImgDequantizeFXT1Proc; +GrProc txErrorSetCallbackProc; + +extern void tdfxDDGlideExtensionsInit( void ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c deleted file mode 100644 index 0c0ae8b0c..000000000 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -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"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_init.c,v 1.5 2000/09/26 15:56:50 tsi Exp $ */ - -/* - * Authors: - * Daryll Strauss <daryll@precisioninsight.com> - * - */ - -#ifdef GLX_DIRECT_RENDERING - -#include <X11/Xlibint.h> -#include "xf86dri.h" -#include "tdfx_dri.h" -#include "fxdrv.h" - - -#ifdef DEBUG_LOCKING -char *prevLockFile = 0; -int prevLockLine = 0; -#endif - -static void -performMagic(__DRIscreenPrivate * driScrnPriv) -{ - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; - TDFXDRIPtr gDRIPriv = (TDFXDRIPtr) driScrnPriv->pDevPriv; - - gPriv->regs.handle = gDRIPriv->regs; - gPriv->regs.size = gDRIPriv->regsSize; - gPriv->deviceID = gDRIPriv->deviceID; - gPriv->width = gDRIPriv->width; - gPriv->height = gDRIPriv->height; - gPriv->mem = gDRIPriv->mem; - gPriv->cpp = gDRIPriv->cpp; - gPriv->stride = gDRIPriv->stride; - gPriv->fifoOffset = gDRIPriv->fifoOffset; - gPriv->fifoSize = gDRIPriv->fifoSize; - gPriv->fbOffset = gDRIPriv->fbOffset; - gPriv->backOffset = gDRIPriv->backOffset; - gPriv->depthOffset = gDRIPriv->depthOffset; - gPriv->textureOffset = gDRIPriv->textureOffset; - gPriv->textureSize = gDRIPriv->textureSize; -} - -GLboolean -tdfxMapAllRegions(__DRIscreenPrivate * driScrnPriv) -{ - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; - - /* First, pick apart pDevPriv & friends */ - performMagic(driScrnPriv); - - if (drmMap(driScrnPriv->fd, gPriv->regs.handle, gPriv->regs.size, - &gPriv->regs.map)) { - return GL_FALSE; - } - - return GL_TRUE; -} - -void -tdfxUnmapAllRegions(__DRIscreenPrivate * driScrnPriv) -{ - tdfxScreenPrivate *gPriv = (tdfxScreenPrivate *) driScrnPriv->private; - - drmUnmap(gPriv->regs.map, gPriv->regs.size); -} - - -#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.c new file mode 100644 index 000000000..f63541be9 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.c @@ -0,0 +1,96 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#include "dri_glide.h" + +#include "tdfx_context.h" +#include "tdfx_lock.h" +#include "tdfx_state.h" +#include "tdfx_texman.h" +#include "tdfx_tris.h" + + +void tdfxGetLock( tdfxContextPtr fxMesa ) +{ + __DRIcontextPrivate *cPriv = fxMesa->driContext; + __DRIdrawablePrivate *dPriv = cPriv->driDrawablePriv; + __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; + TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) + + sizeof(XF86DRISAREARec)); + int stamp = dPriv->lastStamp; + int one_rect = (fxMesa->numClipRects <= 1); + + drmGetLock( fxMesa->driFd, fxMesa->hHWContext, 0 ); + + /* This macro will update dPriv's cliprects if needed */ + XMESA_VALIDATE_DRAWABLE_INFO( cPriv->display, sPriv, dPriv ); + + if ( saPriv->fifoOwner != fxMesa->hHWContext ) { + grDRIImportFifo( saPriv->fifoPtr, saPriv->fifoRead ); + } + + if ( saPriv->ctxOwner != fxMesa->hHWContext ) { + /* This sequence looks a little odd. Glide mirrors the state, and + * when you get the state you are forcing the mirror to be up to + * date, and then getting a copy from the mirror. You can then force + * that state onto the hardware when you set the state. + */ + void *state; + state = malloc( FX_grGetInteger_NoLock( FX_GLIDE_STATE_SIZE ) ); + FX_grGlideGetState_NoLock( state ); + FX_grGlideSetState_NoLock( state ); + free( state ); + } + +#if 0 + if ( saPriv->texOwner != fxMesa->hHWContext ) { + tdfxTMRestoreTextures_NoLock( fxMesa ); + } +#endif + + if ( *dPriv->pStamp != stamp || saPriv->ctxOwner != fxMesa->hHWContext ) { + tdfxUpdateClipping(fxMesa->glCtx); + tdfxUploadClipping(fxMesa); + } + + /* Detect if we have swapped between 1 and >1 cliprects, and change + * triangle funcs if necessary. + */ + if (one_rect != (fxMesa->numClipRects <= 1)) + tdfxDDToggleTriCliprects( fxMesa->glCtx ); + + DEBUG_LOCK(); +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.h new file mode 100644 index 000000000..3cfa52c0e --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_lock.h @@ -0,0 +1,149 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_LOCK_H__ +#define __TDFX_LOCK_H__ + +#ifdef GLX_DIRECT_RENDERING + +/* You can turn this on to find locking conflicts. + */ +#define DEBUG_LOCKING 0 + +#if DEBUG_LOCKING +extern char *prevLockFile; +extern int prevLockLine; + +#define DEBUG_LOCK() \ + do { \ + prevLockFile = (__FILE__); \ + prevLockLine = (__LINE__); \ + } while (0) + +#define DEBUG_RESET() \ + do { \ + prevLockFile = 0; \ + prevLockLine = 0; \ + } while (0) + +#define DEBUG_CHECK_LOCK() \ + do { \ + if ( prevLockFile ) { \ + fprintf( stderr, \ + "LOCK SET!\n\tPrevious %s:%d\n\tCurrent: %s:%d\n", \ + prevLockFile, prevLockLine, __FILE__, __LINE__ ); \ + exit( 1 ); \ + } \ + } while (0) + +#else + +#define DEBUG_LOCK() +#define DEBUG_RESET() +#define DEBUG_CHECK_LOCK() + +#endif /* DEBUG_LOCKING */ + + +extern void tdfxGetLock( tdfxContextPtr fxMesa ); + + +/* !!! We may want to separate locks from locks with validation. + This could be used to improve performance for those things + commands that do not do any drawing !!! */ + +#define DRM_LIGHT_LOCK_RETURN(fd,lock,context,__ret) \ + do { \ + DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ + if (__ret) drmGetLock(fd,context,0); \ + } while(0) + +#define LOCK_HARDWARE( fxMesa ) \ + do { \ + char __ret = 0; \ + \ + DEBUG_CHECK_LOCK(); \ + DRM_CAS( fxMesa->driHwLock, fxMesa->hHWContext, \ + DRM_LOCK_HELD | fxMesa->hHWContext, __ret ); \ + if ( __ret ) { \ + tdfxGetLock( fxMesa ); \ + } \ + DEBUG_LOCK(); \ + } while (0) + +/* Unlock the hardware using the global current context */ +#define UNLOCK_HARDWARE( fxMesa ) \ + do { \ + DRM_UNLOCK( fxMesa->driFd, fxMesa->driHwLock, fxMesa->hHWContext ); \ + DEBUG_RESET(); \ + } while (0) + +/* + * This pair of macros makes a loop over the drawing operations + * so it is not self contained and doesn't have the nice single + * statement semantics of most macros. + */ +#define BEGIN_CLIP_LOOP(fxMesa) \ + do { \ + LOCK_HARDWARE( fxMesa ); \ + BEGIN_CLIP_LOOP_LOCKED( fxMesa ) + +#define BEGIN_CLIP_LOOP_LOCKED(fxMesa) \ + do { \ + int _nc = fxMesa->numClipRects; \ + while (_nc--) { \ + if (fxMesa->numClipRects > 1) { \ + int _height = fxMesa->screen_height; \ + grClipWindow(fxMesa->pClipRects[_nc].x1, \ + _height - fxMesa->pClipRects[_nc].y2, \ + fxMesa->pClipRects[_nc].x2, \ + _height - fxMesa->pClipRects[_nc].y1); \ + } + + +#define END_CLIP_LOOP_LOCKED( fxMesa ) \ + } \ + } while (0) + +#define END_CLIP_LOOP( fxMesa ) \ + END_CLIP_LOOP_LOCKED( fxMesa ); \ + UNLOCK_HARDWARE( fxMesa ); \ + } while (0) + + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* __TDFX_LOCK_H__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.c new file mode 100644 index 000000000..b26e174c8 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.c @@ -0,0 +1,177 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_pipeline.h" +#include "tdfx_vb.h" +#include "tdfx_tris.h" + +#include "vbindirect.h" + +static struct gl_pipeline_stage tdfx_fast_stage = { + "TDFX Fast Path", + (PIPE_OP_VERT_XFORM | + PIPE_OP_RAST_SETUP_0 | + PIPE_OP_RAST_SETUP_1 | + PIPE_OP_RENDER), + PIPE_PRECALC, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + tdfxDDFastPath +}; + +#define ILLEGAL_ENABLES (TEXTURE0_3D | \ + TEXTURE1_3D | \ + ENABLE_TEXMAT0 | \ + ENABLE_TEXMAT1 | \ + ENABLE_TEXGEN0 | \ + ENABLE_TEXGEN1 | \ + ENABLE_USERCLIP | \ + ENABLE_LIGHT | \ + ENABLE_FOG) + +/* Build the PRECALC pipeline with our stage, if possible. Otherwise, + * return GL_FALSE. + */ +GLboolean tdfxDDBuildPrecalcPipeline( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + struct gl_pipeline *pipe = &ctx->CVA.pre; + + if ( (fxMesa->RenderIndex & ~TDFX_CLIPRECT_BIT) == 0 && + (ctx->Enabled & ILLEGAL_ENABLES) == 0 && +#ifdef VAO + (ctx->Array.Current->Flags & (VERT_OBJ_234 | +#else + (ctx->Array.Flags & (VERT_OBJ_234 | +#endif + VERT_TEX0_4 | + VERT_TEX1_4 | + VERT_ELT)) == (VERT_OBJ_23 | VERT_ELT) ) + { + pipe->stages[0] = &tdfx_fast_stage; + pipe->stages[1] = 0; + pipe->new_inputs = ctx->RenderFlags & VERT_DATA; + pipe->ops = pipe->stages[0]->ops; + + fxMesa->using_fast_path = GL_TRUE; + return GL_TRUE; + } + + if ( fxMesa->using_fast_path ) { + fxMesa->using_fast_path = GL_FALSE; + + ctx->CVA.VB->ClipOrMask = 0; + ctx->CVA.VB->ClipAndMask = CLIP_ALL_BITS; +#ifdef VAO + ctx->Array.NewArrayState |= ctx->Array.Current->Summary; +#else + ctx->Array.NewArrayState |= ctx->Array.Summary; +#endif + } + + return GL_FALSE; +} + + +static void tdfxDDCheckRasterSetup( GLcontext *ctx, + struct gl_pipeline_stage *d ) +{ + d->type = PIPE_IMMEDIATE | PIPE_PRECALC; + d->inputs = ctx->RenderFlags; + + d->outputs = VERT_SETUP_FULL; + + if ( ctx->IndirectTriangles & DD_SW_SETUP ) + d->type = PIPE_IMMEDIATE; +} + + +static void tdfxDDRenderElements(struct vertex_buffer *VB) +{ + if (VB->ClipOrMask) { + gl_render_elts( VB ); + } else { + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + fxMesa->RenderElementsRaw( VB ); + } +} + + +/* Register the pipeline with our stages included */ +GLuint tdfxDDRegisterPipelineStages( struct gl_pipeline_stage *out, + const struct gl_pipeline_stage *in, + GLuint nr ) +{ + int i, o; + + for ( i = o = 0 ; i < nr ; i++ ) { + switch ( in[i].ops ) { + + case PIPE_OP_RAST_SETUP_0: + out[o] = in[i]; + out[o].cva_state_change = (NEW_LIGHTING | + NEW_TEXTURING | + NEW_RASTER_OPS); + out[o].state_change = ~0; + out[o].check = tdfxDDCheckPartialRasterSetup; + out[o].run = tdfxDDPartialRasterSetup; + o++; + break; + + case PIPE_OP_RAST_SETUP_0 | PIPE_OP_RAST_SETUP_1: + out[o] = in[i]; + out[o].check = tdfxDDCheckRasterSetup; + out[o].run = tdfxDDDoRasterSetup; + o++; + break; + + case PIPE_OP_RENDER: + out[o] = in[i]; + if (in[i].type == PIPE_PRECALC) + out[o].run = tdfxDDRenderElements; + o++; + break; + + default: + out[o++] = in[i]; + break; + } + } + + return o; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.h new file mode 100644 index 000000000..a87a8cf74 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pipeline.h @@ -0,0 +1,54 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#ifndef __TDFX_PIPELINE_H__ +#define __TDFX_PIPELINE_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "context.h" + +extern GLboolean tdfxDDBuildPrecalcPipeline( GLcontext *ctx ); +extern GLuint tdfxDDRegisterPipelineStages( struct gl_pipeline_stage *out, + const struct gl_pipeline_stage *in, + GLuint nr ); + +extern void tdfxDDFastPathInit( void ); +extern void tdfxDDFastPath( struct vertex_buffer *VB ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.c new file mode 100644 index 000000000..e650e6615 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.c @@ -0,0 +1,638 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Nathan Hand <nhand@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_dd.h" +#include "tdfx_vb.h" +#include "tdfx_pipeline.h" +#include "tdfx_pixels.h" +#include "tdfx_render.h" + +#include "../../image.h" + +#if 0 +/* test if window coord (px,py) is visible */ +static GLboolean +inClipRects(tdfxContextPtr fxMesa, int px, int py) +{ + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + if ((px >= fxMesa->pClipRects[i].x1) && + (px < fxMesa->pClipRects[i].x2) && + (py >= fxMesa->pClipRects[i].y1) && + (py < fxMesa->pClipRects[i].y2)) return GL_TRUE; + } + return GL_FALSE; +} +#endif + +/* test if rectangle of pixels (px,py) (px+width,py+height) is visible */ +static GLboolean +inClipRects_Region(tdfxContextPtr fxMesa, int x, int y, int width, int height) +{ + int i; + int x1, y1, x2, y2; + int xmin, xmax, ymin, ymax, pixelsleft; + + y1 = y - height + 1; y2 = y; + x1 = x; x2 = x + width - 1; + pixelsleft = width * height; + + for (i = 0; i < fxMesa->numClipRects; i++) + { + /* algorithm requires x1 < x2 and y1 < y2 */ + if ((fxMesa->pClipRects[i].x1 < fxMesa->pClipRects[i].x2)) { + xmin = fxMesa->pClipRects[i].x1; + xmax = fxMesa->pClipRects[i].x2-1; + } else { + xmin = fxMesa->pClipRects[i].x2; + xmax = fxMesa->pClipRects[i].x1-1; + } + if ((fxMesa->pClipRects[i].y1 < fxMesa->pClipRects[i].y2)) { + ymin = fxMesa->pClipRects[i].y1; + ymax = fxMesa->pClipRects[i].y2-1; + } else { + ymin = fxMesa->pClipRects[i].y2; + ymax = fxMesa->pClipRects[i].y1-1; + } + + /* reject trivial cases */ + if (xmax < x1) continue; + if (ymax < y1) continue; + if (xmin > x2) continue; + if (ymin > y2) continue; + + /* find the intersection */ + if (xmin < x1) xmin = x1; + if (ymin < y1) ymin = y1; + if (xmax > x2) xmax = x2; + if (ymax > y2) ymax = y2; + + pixelsleft -= (xmax-xmin+1) * (ymax-ymin+1); + } + + return pixelsleft == 0; +} + +#if 0 +GLboolean +tdfx_bitmap_R5G6B5(GLcontext * ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte * bitmap) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + TdfxU16 color; + const struct gl_pixelstore_attrib *finalUnpack; + struct gl_pixelstore_attrib scissoredUnpack; + + /* check if there's any raster operations enabled which we can't handle */ + if (ctx->RasterMask & (ALPHATEST_BIT | + BLEND_BIT | + DEPTH_BIT | + FOG_BIT | + LOGIC_OP_BIT | + SCISSOR_BIT | + STENCIL_BIT | + MASKING_BIT | + ALPHABUF_BIT | MULTI_DRAW_BIT)) return GL_FALSE; + + if (ctx->Scissor.Enabled) { + /* This is a bit tricky, but by carefully adjusting the px, py, + * width, height, skipPixels and skipRows values we can do + * scissoring without special code in the rendering loop. + */ + + /* we'll construct a new pixelstore struct */ + finalUnpack = &scissoredUnpack; + scissoredUnpack = *unpack; + if (scissoredUnpack.RowLength == 0) + scissoredUnpack.RowLength = width; + + /* clip left */ + if (px < ctx->Scissor.X) { + scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); + width -= (ctx->Scissor.X - px); + px = ctx->Scissor.X; + } + /* clip right */ + if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { + width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); + } + /* clip bottom */ + if (py < ctx->Scissor.Y) { + scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); + height -= (ctx->Scissor.Y - py); + py = ctx->Scissor.Y; + } + /* clip top */ + if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { + height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); + } + + if (width <= 0 || height <= 0) + return GL_TRUE; /* totally scissored away */ + } + else { + finalUnpack = unpack; + } + + /* compute pixel value */ + { + GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); + GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); + GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); + /*GLint a = (GLint)(ctx->Current.RasterColor[3]*255.0f); */ + if (fxMesa->bgrOrder) { + color = (TdfxU16) + (((TdfxU16) 0xf8 & b) << (11 - 3)) | + (((TdfxU16) 0xfc & g) << (5 - 3 + 1)) | + (((TdfxU16) 0xf8 & r) >> 3); + } + else + color = (TdfxU16) + (((TdfxU16) 0xf8 & r) << (11 - 3)) | + (((TdfxU16) 0xfc & g) << (5 - 3 + 1)) | + (((TdfxU16) 0xf8 & b) >> 3); + } + + info.size = sizeof(info); + if (!TDFX_grLfbLock(fxMesa, + GR_LFB_WRITE_ONLY, + fxMesa->currentFB, + GR_LFBWRITEMODE_565, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifndef TDFX_SILENT + fprintf(stderr, "tdfx Driver: error locking the linear frame buffer\n"); +#endif + return GL_TRUE; + } + + { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + /* The dest stride depends on the hardware and whether we're drawing + * to the front or back buffer. This compile-time test seems to do + * the job for now. + */ + const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 2); + GLint row; + /* compute dest address of bottom-left pixel in bitmap */ + GLushort *dst = (GLushort *) info.lfbPtr + + (winY - py) * dstStride + (winX + px); + + for (row = 0; row < height; row++) { + const GLubyte *src = + (const GLubyte *) _mesa_image_address(finalUnpack, + bitmap, width, height, + GL_COLOR_INDEX, + GL_BITMAP, 0, row, 0); + if (finalUnpack->LsbFirst) { + /* least significan bit first */ + GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (inClipRects(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + if (mask != 1) + src++; + } + else { + /* most significan bit first */ + GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (inClipRects(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + if (mask != 128) + src++; + } + dst -= dstStride; + } + } + + TDFX_grLfbUnlock(fxMesa, GR_LFB_WRITE_ONLY, fxMesa->currentFB); + return GL_TRUE; +} +#endif + +#if 0 +GLboolean +tdfx_bitmap_R8G8B8A8(GLcontext * ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte * bitmap) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GLuint color; + const struct gl_pixelstore_attrib *finalUnpack; + struct gl_pixelstore_attrib scissoredUnpack; + + /* check if there's any raster operations enabled which we can't handle */ + if (ctx->RasterMask & (ALPHATEST_BIT | + BLEND_BIT | + DEPTH_BIT | + FOG_BIT | + LOGIC_OP_BIT | + SCISSOR_BIT | + STENCIL_BIT | + MASKING_BIT | + ALPHABUF_BIT | MULTI_DRAW_BIT)) return GL_FALSE; + + if (ctx->Scissor.Enabled) { + /* This is a bit tricky, but by carefully adjusting the px, py, + * width, height, skipPixels and skipRows values we can do + * scissoring without special code in the rendering loop. + */ + + /* we'll construct a new pixelstore struct */ + finalUnpack = &scissoredUnpack; + scissoredUnpack = *unpack; + if (scissoredUnpack.RowLength == 0) + scissoredUnpack.RowLength = width; + + /* clip left */ + if (px < ctx->Scissor.X) { + scissoredUnpack.SkipPixels += (ctx->Scissor.X - px); + width -= (ctx->Scissor.X - px); + px = ctx->Scissor.X; + } + /* clip right */ + if (px + width >= ctx->Scissor.X + ctx->Scissor.Width) { + width -= (px + width - (ctx->Scissor.X + ctx->Scissor.Width)); + } + /* clip bottom */ + if (py < ctx->Scissor.Y) { + scissoredUnpack.SkipRows += (ctx->Scissor.Y - py); + height -= (ctx->Scissor.Y - py); + py = ctx->Scissor.Y; + } + /* clip top */ + if (py + height >= ctx->Scissor.Y + ctx->Scissor.Height) { + height -= (py + height - (ctx->Scissor.Y + ctx->Scissor.Height)); + } + + if (width <= 0 || height <= 0) + return GL_TRUE; /* totally scissored away */ + } + else { + finalUnpack = unpack; + } + + /* compute pixel value */ + { + GLint r = (GLint) (ctx->Current.RasterColor[0] * 255.0f); + GLint g = (GLint) (ctx->Current.RasterColor[1] * 255.0f); + GLint b = (GLint) (ctx->Current.RasterColor[2] * 255.0f); + GLint a = (GLint) (ctx->Current.RasterColor[3] * 255.0f); + color = PACK_BGRA32(r, g, b, a); + } + + info.size = sizeof(info); + if (!TDFX_grLfbLock(fxMesa, GR_LFB_WRITE_ONLY, + fxMesa->currentFB, GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { +#ifndef TDFX_SILENT + fprintf(stderr, "tdfx Driver: error locking the linear frame buffer\n"); +#endif + return GL_TRUE; + } + + { + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + GLint dstStride; + GLuint *dst; + GLint row; + + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + dstStride = fxMesa->screen_width; + dst = + (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + + px); + } + else { + dstStride = info.strideInBytes / 4; + dst = + (GLuint *) info.lfbPtr + (winY - py) * dstStride + (winX + + px); + } + + /* compute dest address of bottom-left pixel in bitmap */ + for (row = 0; row < height; row++) { + const GLubyte *src = + (const GLubyte *) _mesa_image_address(finalUnpack, + bitmap, width, height, + GL_COLOR_INDEX, + GL_BITMAP, 0, row, 0); + if (finalUnpack->LsbFirst) { + /* least significan bit first */ + GLubyte mask = 1U << (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (inClipRects(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + if (mask != 1) + src++; + } + else { + /* most significan bit first */ + GLubyte mask = 128U >> (finalUnpack->SkipPixels & 0x7); + GLint col; + for (col = 0; col < width; col++) { + if (*src & mask) { + if (inClipRects(fxMesa, winX + px + col, winY - py - row)) + dst[col] = color; + } + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + if (mask != 128) + src++; + } + dst -= dstStride; + } + } + + TDFX_grLfbUnlock(fxMesa, GR_LFB_WRITE_ONLY, fxMesa->currentFB); + return GL_TRUE; +} +#endif + +GLboolean +tdfx_readpixels_R5G6B5(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid * dstImage) +{ + if (!(format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5)) { + return GL_FALSE; /* format/type not recognised */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + { + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + LOCK_HARDWARE( fxMesa ); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->ReadBuffer, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) { + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == + GL_FRONT) ? (fxMesa->screen_width) : (info.strideInBytes / 2); + const GLushort *src = (const GLushort *) info.lfbPtr + + scrY * srcStride + scrX; + const GLubyte *dst = (GLubyte *) _mesa_image_address(packing, + dstImage, width, height, format, type, 0, 0, 0); + const GLint dstStride = _mesa_image_row_stride(packing, + width, format, type); + + if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { + /* directly memcpy 5R6G5B pixels into client's buffer */ + const GLint widthInBytes = width * 2; + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } + + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->ReadBuffer); + } + UNLOCK_HARDWARE( fxMesa ); + return result; + } +} + +GLboolean +tdfx_readpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid * dstImage) +{ + if (!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) && + !(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + return GL_FALSE; /* format/type not optimised */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + { + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + LOCK_HARDWARE(fxMesa); + info.size = sizeof(info); + if (grLfbLock(GR_LFB_READ_ONLY, + fxMesa->ReadBuffer, + GR_LFBWRITEMODE_ANY, + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info)) + { + const GLint srcStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width) : (info.strideInBytes / 4); + const GLuint *src = (const GLuint *) info.lfbPtr + + scrY * srcStride + scrX; + const GLint dstStride = + _mesa_image_row_stride(packing, width, format, type); + const GLubyte *dst = (GLubyte *) _mesa_image_address(packing, + dstImage, width, height, format, type, 0, 0, 0); + const GLint widthInBytes = width * 4; + + if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) || + (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst += dstStride; + src -= srcStride; + } + result = GL_TRUE; + } + + grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->ReadBuffer); + } + UNLOCK_HARDWARE(fxMesa); + return result; + } +} + +GLboolean +tdfx_drawpixels_R8G8B8A8(GLcontext * ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid * pixels) +{ + if (!(format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) && + !(format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + return GL_FALSE; /* format/type not optimised */ + } + + if (ctx->Pixel.ZoomX!=1.0F || ctx->Pixel.ZoomY!=1.0F) { + return GL_FALSE; /* can't scale pixels */ + } + + if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag) { + return GL_FALSE; /* can't do this */ + } + + if (ctx->RasterMask & (~BLEND_BIT)) { + return GL_FALSE; /* can't do any raster ops, except blend */ + } + + { + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GLboolean result = GL_FALSE; + + const GLint winX = fxMesa->x_offset; + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + + /* lock early to make sure cliprects are right */ + LOCK_HARDWARE(fxMesa); + + /* make sure hardware has latest blend funcs */ + if (ctx->RasterMask & BLEND_BIT) { + fxMesa->dirty |= TDFX_UPLOAD_BLEND_FUNC; + tdfxEmitHwStateLocked( fxMesa ); + } + + /* look for clipmasks, giveup if region obscured */ + if (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) { + if (!inClipRects_Region(fxMesa, scrX, scrY, width, height)) { + UNLOCK_HARDWARE(fxMesa); + return GL_FALSE; + } + } + + info.size = sizeof(info); + if (grLfbLock(GR_LFB_WRITE_ONLY, + fxMesa->DrawBuffer, + GR_LFBWRITEMODE_8888, + GR_ORIGIN_UPPER_LEFT, FXTRUE, &info)) + { + const GLint dstStride = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) + ? (fxMesa->screen_width * 4) : (info.strideInBytes); + const GLubyte *dst = (const GLubyte *) info.lfbPtr + + scrY * dstStride + scrX * 4; + const GLint srcStride = + _mesa_image_row_stride(unpack, width, format, type); + const GLubyte *src = (GLubyte *) _mesa_image_address(unpack, + pixels, width, height, format, type, 0, 0, 0); + const GLint widthInBytes = width * 4; + + if ((format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) || + (format == GL_BGRA && type == GL_UNSIGNED_BYTE)) { + GLint row; + for (row = 0; row < height; row++) { + MEMCPY(dst, src, widthInBytes); + dst -= dstStride; + src += srcStride; + } + result = GL_TRUE; + } + + grLfbUnlock(GR_LFB_WRITE_ONLY, fxMesa->DrawBuffer); + } + UNLOCK_HARDWARE(fxMesa); + return result; + } +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.h new file mode 100644 index 000000000..655f03bd1 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_pixels.h @@ -0,0 +1,80 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Nathan Hand <nhand@valinux.com> + * + */ + +#ifndef __TDFX_PIXELS_H__ +#define __TDFX_PIXELS_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "context.h" + +extern GLboolean +tdfx_bitmap_R5G6B5( GLcontext *ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap ); + +extern GLboolean +tdfx_bitmap_R8G8B8A8( GLcontext *ctx, GLint px, GLint py, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap ); + +extern GLboolean +tdfx_readpixels_R5G6B5( GLcontext *ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid *dstImage ); + +extern GLboolean +tdfx_readpixels_R8G8B8A8( GLcontext *ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *packing, + GLvoid *dstImage ); + +extern GLboolean +tdfx_drawpixels_R8G8B8A8( GLcontext *ctx, GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.c new file mode 100644 index 000000000..97931a351 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.c @@ -0,0 +1,864 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "dri_glide.h" +#include "tdfx_context.h" +#include "tdfx_render.h" +#include "tdfx_state.h" +#include "tdfx_texman.h" + +/* Clear the color and/or depth buffers. + */ +static GLbitfield tdfxDDClear( GLcontext *ctx, + GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height ) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + GLbitfield softwareMask = mask & (DD_ACCUM_BIT); + const GLuint stencil_size = + fxMesa->haveHwStencil ? fxMesa->glVis->StencilBits : 0; + +#if 0 + GLuint flags; + + FLUSH_BATCH( fxMesa ); + + if ( mask & DD_FRONT_LEFT_BIT ) { + flags |= TDFX_FRONT; + mask &= ~DD_FRONT_LEFT_BIT; + } + + if ( mask & DD_BACK_LEFT_BIT ) { + flags |= TDFX_BACK; + mask &= ~DD_BACK_LEFT_BIT; + } + + if ( (mask & DD_DEPTH_BIT) && ctx->Depth.Mask ) { + flags |= TDFX_DEPTH; + mask &= ~DD_DEPTH_BIT; + } + + if ( (mask & DD_STENCIL_BIT) && fxMesa->haveHwStencil ) { + clear.flags |= TDFX_STENCIL; + mask &= ~DD_STENCIL_BIT; + } + + if ( !flags ) + return mask; + + LOCK_HARDWARE( fxMesa ); + + + if ( flags & TDFX_FRONT ) { + + } + + if ( flags & TDFX_BACK ) { + + } + + if ( flags & TDFX_DEPTH ) { + + } + + if ( flags & TDFX_STENCIL ) { + grStencilMask( fxMesa->Stencil.WriteMask ); + /* set stencil ref value = desired clear value */ + grStencilFunc( GR_CMP_ALWAYS, fxMesa->Stencil.Clear, 0xff ); + grStencilOp( GR_STENCILOP_REPLACE, + GR_STENCILOP_REPLACE, + GR_STENCILOP_REPLACE ); + grEnable( GR_STENCIL_MODE_EXT ); + + if ( ctx->Stencil.Enabled ) { + grStencilOp( fxMesa->Stencil.FailFunc, + fxMesa->Stencil.ZFailFunc, + fxMesa->Stencil.ZPassFunc ); + grStencilMask( fxMesa->Stencil.WriteMask ); + grStencilFunc( fxMesa->Stencil.Function, + fxMesa->Stencil.RefValue, + fxMesa->Stencil.ValueMask ); + grEnable_NoLock( GR_STENCIL_MODE_EXT ); + } else { + grDisable( GR_STENCIL_MODE_EXT ); + } + + } + UNLOCK_HARDWARE( fxMesa ); + +#else + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s( %d, %d, %d, %d )\n", + __FUNCTION__, (int) x, (int) y, (int) width, (int) height ); + } + + /* Need this check to respond to glScissor and clipping updates */ + if ((fxMesa->new_state & (TDFX_NEW_CLIP | TDFX_NEW_DEPTH)) || + (fxMesa->dirty & TDFX_UPLOAD_COLOR_MASK)) { + tdfxDDUpdateHwState(ctx); + } + + /* we can't clear accum buffers */ + mask &= ~(DD_ACCUM_BIT); + + if (mask & DD_STENCIL_BIT) { + if (!fxMesa->haveHwStencil || ctx->Stencil.WriteMask != 0xff) { + /* Napalm seems to have trouble with stencil write masks != 0xff */ + /* do stencil clear in software */ + mask &= ~(DD_STENCIL_BIT); + softwareMask |= DD_STENCIL_BIT; + } + } + + if (fxMesa->glVis->RedBits != 8) { + /* can only do color masking if running in 24/32bpp on Napalm */ + if (ctx->Color.ColorMask[RCOMP] != ctx->Color.ColorMask[GCOMP] || + ctx->Color.ColorMask[GCOMP] != ctx->Color.ColorMask[BCOMP]) { + softwareMask |= (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)); + mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); + } + } + + if (fxMesa->haveHwStencil) { + /* + * If we want to clear stencil, it must be enabled + * in the HW, even if the stencil test is not enabled + * in the OGL state. + */ + LOCK_HARDWARE(fxMesa); + if (mask & DD_STENCIL_BIT) { + FX_grStencilMask_NoLock(/*ctx->Stencil.WriteMask*/ 0xff); + /* set stencil ref value = desired clear value */ + FX_grStencilFunc_NoLock(GR_CMP_ALWAYS, ctx->Stencil.Clear, 0xff); + FX_grStencilOp_NoLock(GR_STENCILOP_REPLACE, + GR_STENCILOP_REPLACE, GR_STENCILOP_REPLACE); + FX_grEnable_NoLock(GR_STENCIL_MODE_EXT); + } + else { + FX_grDisable_NoLock(GR_STENCIL_MODE_EXT); + } + UNLOCK_HARDWARE(fxMesa); + } + + /* + * FIXME: This is just plain ugly... + */ + BEGIN_CLIP_LOOP(fxMesa); + { + /* + * This could probably be done fancier but doing each possible case + * explicitly is less error prone. + */ + switch (mask & ~DD_STENCIL_BIT) { + case DD_BACK_LEFT_BIT | DD_DEPTH_BIT: + /* back buffer & depth */ + FX_grColorMaskv_NoLock(ctx, true4); /* work around Voodoo3 bug */ + FX_grDepthMask_NoLock(FXTRUE); + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) { + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + } + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (!ctx->Depth.Mask || !ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXFALSE); + } + break; + case DD_FRONT_LEFT_BIT | DD_DEPTH_BIT: + /* XXX it appears that the depth buffer isn't cleared when + * glRenderBuffer(GR_BUFFER_FRONTBUFFER) is set. + * This is a work-around/ + */ + /* clear depth */ + FX_grDepthMask_NoLock(FXTRUE); + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + FX_grColorMaskv_NoLock(ctx, false4); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + /* clear front */ + FX_grColorMaskv_NoLock(ctx, true4); + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (!ctx->Depth.Mask || !ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXFALSE); + } + break; + case DD_BACK_LEFT_BIT: + /* back buffer only */ + FX_grDepthMask_NoLock(FXFALSE); + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT: + /* front buffer only */ + FX_grDepthMask_NoLock(FXFALSE); + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT: + /* front and back */ + FX_grDepthMask_NoLock(FXFALSE); + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXTRUE); + } + break; + case DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT: + /* clear front */ + FX_grDepthMask_NoLock(FXFALSE); + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + /* clear back and depth */ + FX_grDepthMask_NoLock(FXTRUE); + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + if (!ctx->Depth.Mask || !ctx->Depth.Mask) { + FX_grDepthMask_NoLock(FXFALSE); + } + break; + case DD_DEPTH_BIT: + /* just the depth buffer */ + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + FX_grColorMaskv_NoLock(ctx, false4); + FX_grDepthMask_NoLock(FXTRUE); + if (stencil_size > 0) + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + else + FX_grBufferClear_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear); + FX_grColorMaskv_NoLock(ctx, true4); + if (ctx->Color.DrawDestMask & FRONT_LEFT_BIT) + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + if (!ctx->Depth.Test || !ctx->Depth.Mask) + FX_grDepthMask_NoLock(FXFALSE); + break; + default: + /* clear no color buffers or depth buffer but might clear stencil */ + if (stencil_size > 0 && (mask & DD_STENCIL_BIT)) { + /* XXX need this RenderBuffer call to work around Glide bug */ + FX_grRenderBuffer_NoLock(GR_BUFFER_BACKBUFFER); + FX_grDepthMask_NoLock(FXFALSE); + FX_grColorMaskv_NoLock(ctx, false4); + FX_grBufferClearExt_NoLock(fxMesa->Color.ClearColor, + fxMesa->Color.ClearAlpha, + fxMesa->Depth.Clear, + (FxU32) ctx->Stencil.Clear); + if (ctx->Depth.Mask && ctx->Depth.Test) { + FX_grDepthMask_NoLock(FXTRUE); + } + FX_grColorMaskv_NoLock(ctx, true4); + if (ctx->Color.DrawDestMask & FRONT_LEFT_BIT) + FX_grRenderBuffer_NoLock(GR_BUFFER_FRONTBUFFER); + } + } + } + END_CLIP_LOOP(fxMesa); + + if (fxMesa->haveHwStencil && (mask & DD_STENCIL_BIT)) { + /* We changed the stencil state above. Signal that we need to + * upload it again. + */ + fxMesa->dirty |= TDFX_UPLOAD_STENCIL; + } + +#endif + return softwareMask; +} + + + +static void tdfxDDFinish( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + + LOCK_HARDWARE( fxMesa ); + grFinish(); + UNLOCK_HARDWARE( fxMesa ); +} + +static void tdfxDDFlush( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + + LOCK_HARDWARE( fxMesa ); + grFlush(); + UNLOCK_HARDWARE( fxMesa ); +} + + + +static const char *texSource(int k) +{ + switch (k) { + case GR_CMBX_ZERO: + return "GR_CMBX_ZERO"; + case GR_CMBX_TEXTURE_ALPHA: + return "GR_CMBX_TEXTURE_ALPHA"; + case GR_CMBX_ALOCAL: + return "GR_CMBX_ALOCAL"; + case GR_CMBX_AOTHER: + return "GR_CMBX_AOTHER"; + case GR_CMBX_B: + return "GR_CMBX_B"; + case GR_CMBX_CONSTANT_ALPHA: + return "GR_CMBX_CONSTANT_ALPHA"; + case GR_CMBX_CONSTANT_COLOR: + return "GR_CMBX_CONSTANT_COLOR"; + case GR_CMBX_DETAIL_FACTOR: + return "GR_CMBX_DETAIL_FACTOR"; + case GR_CMBX_ITALPHA: + return "GR_CMBX_ITALPHA"; + case GR_CMBX_ITRGB: + return "GR_CMBX_ITRGB"; + case GR_CMBX_LOCAL_TEXTURE_ALPHA: + return "GR_CMBX_LOCAL_TEXTURE_ALPHA"; + case GR_CMBX_LOCAL_TEXTURE_RGB: + return "GR_CMBX_LOCAL_TEXTURE_RGB"; + case GR_CMBX_LOD_FRAC: + return "GR_CMBX_LOD_FRAC"; + case GR_CMBX_OTHER_TEXTURE_ALPHA: + return "GR_CMBX_OTHER_TEXTURE_ALPHA"; + case GR_CMBX_OTHER_TEXTURE_RGB: + return "GR_CMBX_OTHER_TEXTURE_RGB"; + case GR_CMBX_TEXTURE_RGB: + return "GR_CMBX_TEXTURE_RGB"; + case GR_CMBX_TMU_CALPHA: + return "GR_CMBX_TMU_CALPHA"; + case GR_CMBX_TMU_CCOLOR: + return "GR_CMBX_TMU_CCOLOR"; + default: + return ""; + } +} + +static const char *texMode(int k) +{ + switch (k) { + case GR_FUNC_MODE_ZERO: + return "GR_FUNC_MODE_ZERO"; + case GR_FUNC_MODE_X: + return "GR_FUNC_MODE_X"; + case GR_FUNC_MODE_ONE_MINUS_X: + return "GR_FUNC_MODE_ONE_MINUS_X"; + case GR_FUNC_MODE_NEGATIVE_X: + return "GR_FUNC_MODE_NEGATIVE_X"; + case GR_FUNC_MODE_X_MINUS_HALF: + return "GR_FUNC_MODE_X_MINUS_HALF"; + default: + return ""; + } +} + +static const char *texInvert(int k) +{ + return k ? "FXTRUE" : "FXFALSE"; +} + +static void uploadTextureEnv( tdfxContextPtr fxMesa ) +{ + if (TDFX_IS_NAPALM(fxMesa)) { + int unit; + for (unit = 0; unit < TDFX_NUM_TMU; unit++) { +#if 0 + printf("upload env %d\n", unit); + printf(" cSourceA = %s\t", texSource(fxMesa->TexCombineExt[unit].Color.SourceA)); + printf(" cModeA = %s\n", texMode(fxMesa->TexCombineExt[unit].Color.ModeA)); + printf(" cSourceB = %s\t", texSource(fxMesa->TexCombineExt[unit].Color.SourceB)); + printf(" cModeB = %s\n", texMode(fxMesa->TexCombineExt[unit].Color.ModeB)); + printf(" cSourceC = %s\t", texSource(fxMesa->TexCombineExt[unit].Color.SourceC)); + printf(" cInvertC = %s\n", texInvert(fxMesa->TexCombineExt[unit].Color.InvertC)); + printf(" cSourceD = %s\t", texSource(fxMesa->TexCombineExt[unit].Color.SourceD)); + printf(" cInvertD = %s\n", texInvert(fxMesa->TexCombineExt[unit].Color.InvertD)); + printf(" cShift = %d\t", fxMesa->TexCombineExt[unit].Color.Shift); + printf(" cInvert = %d\n", fxMesa->TexCombineExt[unit].Color.Invert); + printf(" aSourceA = %s\t", texSource(fxMesa->TexCombineExt[unit].Alpha.SourceA)); + printf(" aModeA = %s\n", texMode(fxMesa->TexCombineExt[unit].Alpha.ModeA)); + printf(" aSourceB = %s\t", texSource(fxMesa->TexCombineExt[unit].Alpha.SourceB)); + printf(" aModeB = %s\n", texMode(fxMesa->TexCombineExt[unit].Alpha.ModeB)); + printf(" aSourceC = %s\t", texSource(fxMesa->TexCombineExt[unit].Alpha.SourceC)); + printf(" aInvertC = %s\n", texInvert(fxMesa->TexCombineExt[unit].Alpha.InvertC)); + printf(" aSourceD = %s\t", texSource(fxMesa->TexCombineExt[unit].Alpha.SourceD)); + printf(" aInvertD = %s\n", texInvert(fxMesa->TexCombineExt[unit].Alpha.InvertD)); + printf(" aShift = %d\t", fxMesa->TexCombineExt[unit].Alpha.Shift); + printf(" aInvert = %d\n", fxMesa->TexCombineExt[unit].Alpha.Invert); + printf(" Color = 0x%08x\n", fxMesa->TexCombineExt[unit].EnvColor); +#endif + (*grTexColorCombineExtProc)(TDFX_TMU0 + unit, + fxMesa->TexCombineExt[unit].Color.SourceA, + fxMesa->TexCombineExt[unit].Color.ModeA, + fxMesa->TexCombineExt[unit].Color.SourceB, + fxMesa->TexCombineExt[unit].Color.ModeB, + fxMesa->TexCombineExt[unit].Color.SourceC, + fxMesa->TexCombineExt[unit].Color.InvertC, + fxMesa->TexCombineExt[unit].Color.SourceD, + fxMesa->TexCombineExt[unit].Color.InvertD, + fxMesa->TexCombineExt[unit].Color.Shift, + fxMesa->TexCombineExt[unit].Color.Invert); + (*grTexAlphaCombineExtProc)(TDFX_TMU0 + unit, + fxMesa->TexCombineExt[unit].Alpha.SourceA, + fxMesa->TexCombineExt[unit].Alpha.ModeA, + fxMesa->TexCombineExt[unit].Alpha.SourceB, + fxMesa->TexCombineExt[unit].Alpha.ModeB, + fxMesa->TexCombineExt[unit].Alpha.SourceC, + fxMesa->TexCombineExt[unit].Alpha.InvertC, + fxMesa->TexCombineExt[unit].Alpha.SourceD, + fxMesa->TexCombineExt[unit].Alpha.InvertD, + fxMesa->TexCombineExt[unit].Alpha.Shift, + fxMesa->TexCombineExt[unit].Alpha.Invert); + (*grConstantColorValueExtProc)(TDFX_TMU0 + unit, + fxMesa->TexCombineExt[unit].EnvColor); + } + } + else { + /* Voodoo3 */ + int unit; + for (unit = 0; unit < TDFX_NUM_TMU; unit++) { + struct tdfx_texcombine *comb = &fxMesa->TexCombine[unit]; + FX_grTexCombine_NoLock(TDFX_TMU0 + unit, + comb->FunctionRGB, + comb->FactorRGB, + comb->FunctionAlpha, + comb->FactorAlpha, + comb->InvertRGB, + comb->InvertAlpha); + } + } +} + + +static void uploadTextureParams( tdfxContextPtr fxMesa ) +{ + int unit; + for (unit = 0; unit < TDFX_NUM_TMU; unit++) { + const struct tdfx_texparams *p = &fxMesa->TexParams[unit]; + /* + printf("upload params %d\n", unit); + printf(" clamp %x %x\n", env->sClamp, env->tClamp); + printf(" filter %x %x\n", env->minFilt, env->magFilt); + printf(" mipmap %x %x\n", env->mmMode, env->LODblend); + printf(" lod bias %f\n", env->LodBias); + */ + FX_grTexClampMode_NoLock(GR_TMU0 + unit, p->sClamp, p->tClamp); + FX_grTexFilterMode_NoLock(GR_TMU0 + unit, p->minFilt, p->magFilt); + FX_grTexMipMapMode_NoLock(GR_TMU0 + unit, p->mmMode, p->LODblend); + FX_grTexLodBiasValue_NoLock(GR_TMU0 + unit, p->LodBias); + } +} + + +static void uploadTextureSource( tdfxContextPtr fxMesa ) +{ + int unit; + for (unit = 0; unit < TDFX_NUM_TMU; unit++) { + const struct tdfx_texsource *src = &fxMesa->TexSource[unit]; + /* + printf("upload source %d @ %d %p\n", unit, src->StartAddress, src->Info); + */ + if (src->Info) { + /* + printf(" smallLodLog2=%d largeLodLog2=%d ar=%d format=%d data=%p\n", + src->Info->smallLodLog2, src->Info->largeLodLog2, + src->Info->aspectRatioLog2, src->Info->format, + src->Info->data); + */ + FX_grTexSource_NoLock(GR_TMU0 + unit, + src->StartAddress, + src->EvenOdd, + src->Info); + } + } +} + + +static void uploadTextureImages( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + int unit; + for (unit = 0; unit < TDFX_NUM_TMU; unit++) { + if (ctx->Texture.Unit[unit].ReallyEnabled == TEXTURE0_2D) { + struct gl_texture_object *tObj = ctx->Texture.Unit[unit].CurrentD[2]; + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + if (ti && ti->reloadImages) { + /* + printf("download texture image on unit %d\n", unit); + */ + tdfxTMDownloadTexture(fxMesa, tObj); + ti->reloadImages = GL_FALSE; + } + } + } +} + + + +/* + * If scissoring is enabled, compute intersection of scissor region + * with all X clip rects, resulting in new cliprect list. + * If number of cliprects is zero or one, call grClipWindow to setup + * the clip region. Otherwise we'll call grClipWindow inside the + * BEGIN_CLIP_LOOP macro. + */ +void tdfxUploadClipping( tdfxContextPtr fxMesa ) +{ + __DRIdrawablePrivate *dPriv = fxMesa->driDrawable; + + assert(dPriv); + + if (fxMesa->numClipRects == 0) { + /* all drawing clipped away */ + grClipWindow(0, 0, 0, 0); + } + else if (fxMesa->numClipRects == 1) { + grClipWindow(fxMesa->pClipRects[0].x1, + fxMesa->screen_height - fxMesa->pClipRects[0].y2, + fxMesa->pClipRects[0].x2, + fxMesa->screen_height - fxMesa->pClipRects[0].y1); + } + /* else, we'll do a cliprect loop around all drawing */ + + grDRIPosition( dPriv->x, dPriv->y, dPriv->w, dPriv->h, + fxMesa->numClipRects, fxMesa->pClipRects ); +} + + +void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa ) +{ + if ( !fxMesa->dirty ) + return; + + if ( fxMesa->dirty & TDFX_UPLOAD_COLOR_COMBINE ) { + if (TDFX_IS_NAPALM(fxMesa)) { + (*grColorCombineExtProc)(fxMesa->ColorCombineExt.SourceA, + fxMesa->ColorCombineExt.ModeA, + fxMesa->ColorCombineExt.SourceB, + fxMesa->ColorCombineExt.ModeB, + fxMesa->ColorCombineExt.SourceC, + fxMesa->ColorCombineExt.InvertC, + fxMesa->ColorCombineExt.SourceD, + fxMesa->ColorCombineExt.InvertD, + fxMesa->ColorCombineExt.Shift, + fxMesa->ColorCombineExt.Invert); + } + else { + /* Voodoo 3 */ + grColorCombine( fxMesa->ColorCombine.Function, + fxMesa->ColorCombine.Factor, + fxMesa->ColorCombine.Local, + fxMesa->ColorCombine.Other, + fxMesa->ColorCombine.Invert ); + } + fxMesa->dirty &= ~TDFX_UPLOAD_COLOR_COMBINE; + } + if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_COMBINE ) { + if (TDFX_IS_NAPALM(fxMesa)) { + (*grAlphaCombineExtProc)(fxMesa->AlphaCombineExt.SourceA, + fxMesa->AlphaCombineExt.ModeA, + fxMesa->AlphaCombineExt.SourceB, + fxMesa->AlphaCombineExt.ModeB, + fxMesa->AlphaCombineExt.SourceC, + fxMesa->AlphaCombineExt.InvertC, + fxMesa->AlphaCombineExt.SourceD, + fxMesa->AlphaCombineExt.InvertD, + fxMesa->AlphaCombineExt.Shift, + fxMesa->AlphaCombineExt.Invert); + } + else { + /* Voodoo 3 */ + grAlphaCombine( fxMesa->AlphaCombine.Function, + fxMesa->AlphaCombine.Factor, + fxMesa->AlphaCombine.Local, + fxMesa->AlphaCombine.Other, + fxMesa->AlphaCombine.Invert ); + } + fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_COMBINE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_RENDER_BUFFER ) { + grRenderBuffer( fxMesa->DrawBuffer ); + fxMesa->dirty &= ~TDFX_UPLOAD_RENDER_BUFFER; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE) { + grStipplePattern( fxMesa->Stipple.Pattern ); + grStippleMode( fxMesa->Stipple.Mode ); + fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_TEST ) { + grAlphaTestFunction( fxMesa->Color.AlphaFunc ); + fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_TEST; + } + if ( fxMesa->dirty & TDFX_UPLOAD_ALPHA_REF ) { + grAlphaTestReferenceValue( fxMesa->Color.AlphaRef ); + fxMesa->dirty &= ~TDFX_UPLOAD_ALPHA_REF; + } + if ( fxMesa->dirty & TDFX_UPLOAD_BLEND_FUNC ) { + if (grAlphaBlendFunctionExtProc) { + (*grAlphaBlendFunctionExtProc)( fxMesa->Color.BlendSrcRGB, + fxMesa->Color.BlendDstRGB, + GR_BLEND_OP_ADD, + fxMesa->Color.BlendSrcA, + fxMesa->Color.BlendDstA, + GR_BLEND_OP_ADD ); + } + else { + grAlphaBlendFunction( fxMesa->Color.BlendSrcRGB, + fxMesa->Color.BlendDstRGB, + fxMesa->Color.BlendSrcA, + fxMesa->Color.BlendDstA ); + } + fxMesa->dirty &= ~TDFX_UPLOAD_BLEND_FUNC; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_MODE ) { + grDepthBufferMode( fxMesa->Depth.Mode ); + fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_MODE; + } + if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_BIAS ) { + grDepthBiasLevel( fxMesa->Depth.Bias ); + fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_BIAS; + } + if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_FUNC ) { + grDepthBufferFunction( fxMesa->Depth.Func ); + fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_FUNC; + } + if ( fxMesa->dirty & TDFX_UPLOAD_DEPTH_MASK ) { + grDepthMask( fxMesa->Depth.Mask ); + fxMesa->dirty &= ~TDFX_UPLOAD_DEPTH_MASK; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_DITHER) { + grDitherMode( fxMesa->Color.Dither ); + } + + if ( fxMesa->dirty & TDFX_UPLOAD_FOG_MODE ) { + grFogMode( fxMesa->Fog.Mode ); + fxMesa->dirty &= ~TDFX_UPLOAD_FOG_MODE; + } + if ( fxMesa->dirty & TDFX_UPLOAD_FOG_COLOR ) { + grFogColorValue( fxMesa->Fog.Color ); + fxMesa->dirty &= ~TDFX_UPLOAD_FOG_COLOR; + } + if ( fxMesa->dirty & TDFX_UPLOAD_FOG_TABLE ) { + grFogTable( fxMesa->Fog.Table ); + fxMesa->dirty &= ~TDFX_UPLOAD_FOG_TABLE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) { + grCullMode( fxMesa->CullMode ); + fxMesa->dirty &= ~TDFX_UPLOAD_CULL; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_CLIP ) { + tdfxUploadClipping( fxMesa ); + fxMesa->dirty &= ~TDFX_UPLOAD_CLIP; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_COLOR_MASK ) { + if ( grColorMaskExtProc && fxMesa->glCtx->Visual->RedBits == 8) { + grColorMaskExtProc( fxMesa->Color.ColorMask[RCOMP], + fxMesa->Color.ColorMask[GCOMP], + fxMesa->Color.ColorMask[BCOMP], + fxMesa->Color.ColorMask[ACOMP] ); + } else { + grColorMask( fxMesa->Color.ColorMask[RCOMP] || + fxMesa->Color.ColorMask[GCOMP] || + fxMesa->Color.ColorMask[BCOMP], + fxMesa->Color.ColorMask[ACOMP] ); + } + fxMesa->dirty &= ~TDFX_UPLOAD_COLOR_MASK; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_CONSTANT_COLOR ) { + grConstantColorValue( fxMesa->Color.MonoColor ); + fxMesa->dirty &= ~TDFX_UPLOAD_CONSTANT_COLOR; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_LINE ) { + if (fxMesa->glCtx->Line.SmoothFlag && fxMesa->glCtx->Line.Width == 1.0) + grEnable(GR_AA_ORDERED); + else + grDisable(GR_AA_ORDERED); + fxMesa->dirty &= ~TDFX_UPLOAD_LINE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_STENCIL ) { + if (fxMesa->glCtx->Stencil.Enabled) { + grEnable(GR_STENCIL_MODE_EXT); + FX_grStencilOp_NoLock(fxMesa->Stencil.FailFunc, + fxMesa->Stencil.ZFailFunc, + fxMesa->Stencil.ZPassFunc); + FX_grStencilFunc_NoLock(fxMesa->Stencil.Function, + fxMesa->Stencil.RefValue, + fxMesa->Stencil.ValueMask); + FX_grStencilMask_NoLock(fxMesa->Stencil.WriteMask); + } + else { + grDisable(GR_STENCIL_MODE_EXT); + } + fxMesa->dirty &= ~TDFX_UPLOAD_STENCIL; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_VERTEX_LAYOUT ) { + grGlideSetVertexLayout( fxMesa->layout[fxMesa->vertexFormat] ); + fxMesa->dirty &= ~TDFX_UPLOAD_VERTEX_LAYOUT; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_ENV ) { + uploadTextureEnv(fxMesa); + fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_ENV; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_PARAMS ) { + uploadTextureParams(fxMesa); + fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_PARAMS; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_PALETTE ) { + if (fxMesa->TexPalette.Data) { + grTexDownloadTable(fxMesa->TexPalette.Type, fxMesa->TexPalette.Data); + } + fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_PALETTE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_SOURCE ) { + uploadTextureSource(fxMesa); + fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_SOURCE; + } + + if ( fxMesa->dirty & TDFX_UPLOAD_TEXTURE_IMAGES ) { + uploadTextureImages(fxMesa); + fxMesa->dirty &= ~TDFX_UPLOAD_TEXTURE_IMAGES; + } + + fxMesa->dirty = 0; +} + + + +void tdfxDDInitRenderFuncs( GLcontext *ctx ) +{ + ctx->Driver.Clear = tdfxDDClear; + ctx->Driver.Finish = tdfxDDFinish; + ctx->Driver.Flush = tdfxDDFlush; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.h new file mode 100644 index 000000000..9d1c25069 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_render.h @@ -0,0 +1,54 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_RENDER_H__ +#define __TDFX_RENDER_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "tdfx_context.h" + +extern void tdfxDDInitRenderFuncs( GLcontext *ctx ); + +extern void tdfxEmitHwStateLocked( tdfxContextPtr fxMesa ); + +extern void tdfxUploadClipping( tdfxContextPtr fxMesa ); + +#define FLUSH_BATCH( fxMesa ) + + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.c new file mode 100644 index 000000000..801cf42e0 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.c @@ -0,0 +1,106 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#include <X11/Xlibint.h> + +#include "tdfx_dri.h" +#include "tdfx_context.h" +#include "tdfx_vb.h" +#include "tdfx_tris.h" +#include "tdfx_pipeline.h" + + +#ifdef DEBUG_LOCKING +char *prevLockFile = 0; +int prevLockLine = 0; +#endif + + +GLboolean tdfxCreateScreen( __DRIscreenPrivate *sPriv ) +{ + tdfxScreenPrivate *fxScreen; + TDFXDRIPtr fxDRIPriv = (TDFXDRIPtr) sPriv->pDevPriv; + + /* Allocate the private area */ + fxScreen = (tdfxScreenPrivate *) Xmalloc( sizeof(tdfxScreenPrivate) ); + if ( !fxScreen ) + return GL_FALSE; + + fxScreen->driScrnPriv = sPriv; + sPriv->private = (void *) fxScreen; + + fxScreen->regs.handle = fxDRIPriv->regs; + fxScreen->regs.size = fxDRIPriv->regsSize; + fxScreen->deviceID = fxDRIPriv->deviceID; + fxScreen->width = fxDRIPriv->width; + fxScreen->height = fxDRIPriv->height; + fxScreen->mem = fxDRIPriv->mem; + fxScreen->cpp = fxDRIPriv->cpp; + fxScreen->stride = fxDRIPriv->stride; + fxScreen->fifoOffset = fxDRIPriv->fifoOffset; + fxScreen->fifoSize = fxDRIPriv->fifoSize; + fxScreen->fbOffset = fxDRIPriv->fbOffset; + fxScreen->backOffset = fxDRIPriv->backOffset; + fxScreen->depthOffset = fxDRIPriv->depthOffset; + fxScreen->textureOffset = fxDRIPriv->textureOffset; + fxScreen->textureSize = fxDRIPriv->textureSize; + + + if ( drmMap( sPriv->fd, fxScreen->regs.handle, + fxScreen->regs.size, &fxScreen->regs.map ) ) { + return GL_FALSE; + } + + tdfxDDSetupInit(); + tdfxDDTriangleFuncsInit(); + tdfxDDFastPathInit(); + + tdfxDDGlideExtensionsInit(); + + return GL_TRUE; +} + +void tdfxDestroyScreen( __DRIscreenPrivate *sPriv ) +{ + tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private; + + if ( fxScreen ) { + drmUnmap( fxScreen->regs.map, fxScreen->regs.size ); + + Xfree( fxScreen ); + sPriv->private = NULL; + } +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.h new file mode 100644 index 000000000..330c394a6 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.h @@ -0,0 +1,77 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * + */ + +#ifndef __TDFX_SCREEN_H__ +#define __TDFX_SCREEN_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "dri_mesaint.h" + +typedef struct { + drmHandle handle; + drmSize size; + drmAddress map; +} tdfxRegion, *tdfxRegionPtr; + +typedef struct { + tdfxRegion regs; + + int deviceID; + int width; + int height; + int mem; + int cpp; + int stride; + + int fifoOffset; + int fifoSize; + + int fbOffset; + int backOffset; + int depthOffset; + int textureOffset; + int textureSize; + + __DRIscreenPrivate *driScrnPriv; +} tdfxScreenPrivate; + + +extern GLboolean tdfxCreateScreen( __DRIscreenPrivate *driScrnPriv ); +extern void tdfxDestroyScreen( __DRIscreenPrivate *driScrnPriv ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.c new file mode 100644 index 000000000..61dafe3a8 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.c @@ -0,0 +1,1335 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_span.h" +#include "tdfx_render.h" + + +#define DBG 0 + + +#define LOCAL_VARS \ + __DRIdrawablePrivate *dPriv = fxMesa->driDrawable; \ + tdfxScreenPrivate *fxPriv = fxMesa->fxScreen; \ + GLuint pitch = (fxMesa->glCtx->Color.DrawBuffer == GL_FRONT) \ + ? (fxMesa->screen_width * BYTESPERPIXEL) : \ + (info.strideInBytes); \ + GLuint height = fxMesa->height; \ + char *buf = (char *)((char *)info.lfbPtr + \ + dPriv->x * fxPriv->cpp + \ + dPriv->y * pitch); \ + GLuint p; \ + (void) buf; (void) p; + + +#define INIT_MONO_PIXEL( p ) p = fxMesa->Color.MonoColor; + +#define CLIPPIXEL( _x, _y ) ( _x >= minx && _x < maxx && \ + _y >= miny && _y < maxy ) + +#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \ + if ( _y < miny || _y >= maxy ) { \ + _n1 = 0, _x1 = x; \ + } else { \ + _n1 = _n; \ + _x1 = _x; \ + if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \ + if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \ + } + +#define Y_FLIP(_y) (height - _y - 1) + + +#define HW_WRITE_LOCK() \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \ + GrLfbInfo_t info; \ + FLUSH_BATCH( fxMesa ); \ + UNLOCK_HARDWARE( fxMesa ); \ + LOCK_HARDWARE( fxMesa ); \ + info.size = sizeof(GrLfbInfo_t); \ + if ( grLfbLock( GR_LFB_WRITE_ONLY, fxMesa->DrawBuffer, LFB_MODE, \ + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) \ + { + +#define HW_WRITE_UNLOCK() \ + grLfbUnlock( GR_LFB_WRITE_ONLY, fxMesa->DrawBuffer ); \ + } + + +#define HW_READ_LOCK() \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); \ + GrLfbInfo_t info; \ + FLUSH_BATCH( fxMesa ); \ + UNLOCK_HARDWARE( fxMesa ); \ + LOCK_HARDWARE( fxMesa ); \ + info.size = sizeof(GrLfbInfo_t); \ + if ( grLfbLock( GR_LFB_READ_ONLY, fxMesa->ReadBuffer, LFB_MODE, \ + GR_ORIGIN_UPPER_LEFT, FXFALSE, &info ) ) \ + { + +#define HW_READ_UNLOCK() \ + grLfbUnlock( GR_LFB_READ_ONLY, fxMesa->ReadBuffer ); \ + } + + +#define HW_WRITE_CLIPLOOP() \ + do { \ + int _nc = fxMesa->numClipRects; \ + while (_nc--) { \ + int minx = fxMesa->pClipRects[_nc].x1 - fxMesa->x_offset; \ + int miny = fxMesa->pClipRects[_nc].y1 - fxMesa->y_offset; \ + int maxx = fxMesa->pClipRects[_nc].x2 - fxMesa->x_offset; \ + int maxy = fxMesa->pClipRects[_nc].y2 - fxMesa->y_offset; + +#define HW_READ_CLIPLOOP() \ + do { \ + const __DRIdrawablePrivate *dPriv = fxMesa->driDrawable; \ + XF86DRIClipRectPtr rect = dPriv->pClipRects; \ + int _nc = dPriv->numClipRects; \ + while (_nc--) { \ + const int minx = rect->x1 - fxMesa->x_offset; \ + const int miny = rect->y1 - fxMesa->y_offset; \ + const int maxx = rect->x2 - fxMesa->x_offset; \ + const int maxy = rect->y2 - fxMesa->y_offset; \ + rect++; + +#define HW_ENDCLIPLOOP() \ + } \ + } while (0) + + + +#define LFB_MODE GR_LFBWRITEMODE_565 + + +/* 16 bit, RGB565 color spanline and pixel functions */ \ + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) | \ + (((int)g & 0xfc) << 3) | \ + (((int)b & 0xf8) >> 3)) + +#define WRITE_PIXEL( _x, _y, p ) \ + *(GLushort *)(buf + _x*2 + _y*pitch) = p + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \ + rgba[0] = (((p >> 11) & 0x1f) * 255) / 31; \ + rgba[1] = (((p >> 5) & 0x3f) * 255) / 63; \ + rgba[2] = (((p >> 0) & 0x1f) * 255) / 31; \ + rgba[3] = 0xff; \ + } while (0) + +#define TAG(x) tdfx##x##_RGB565 +#define BYTESPERPIXEL 2 +#include "spantmp.h" +#undef BYTESPERPIXEL + + +/* 16 bit, BGR565 color spanline and pixel functions */ \ +#if 0 + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)b & 0xf8) << 8) | \ + (((int)g & 0xfc) << 3) | \ + (((int)r & 0xf8) >> 3)) + +#define WRITE_PIXEL( _x, _y, p ) \ + *(GLushort *)(buf + _x*2 + _y*pitch) = p + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \ + rgba[0] = (p << 3) & 0xf8; \ + rgba[1] = (p >> 3) & 0xfc; \ + rgba[2] = (p >> 8) & 0xf8; \ + rgba[3] = 0xff; \ + } while (0) + +#define TAG(x) tdfx##x##_BGR565 +#define BYTESPERPIXEL 2 +#include "spantmp.h" +#undef BYTESPERPIXEL +#endif + + +#undef LFB_MODE +#define LFB_MODE GR_LFBWRITEMODE_888 + + +/* 24 bit, RGB888 color spanline and pixel functions */ +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + *(GLuint *)(buf + _x*3 + _y*pitch) = ((b << 0) | \ + (g << 8) | \ + (r << 16)) + +#define WRITE_PIXEL( _x, _y, p ) \ + *(GLuint *)(buf + _x*3 + _y*pitch) = p + +#define READ_RGBA( rgba, _x, _y ) \ +do { \ + GLuint p = *(GLuint *)(buf + _x*3 + _y*pitch); \ + rgba[0] = (p >> 16) & 0xff; \ + rgba[1] = (p >> 8) & 0xff; \ + rgba[2] = (p >> 0) & 0xff; \ + rgba[3] = 0xff; \ +} while (0) + +#define TAG(x) tdfx##x##_RGB888 +#define BYTESPERPIXEL 4 +#include "spantmp.h" +#undef BYTESPERPIXEL + + +#undef LFB_MODE +#define LFB_MODE GR_LFBWRITEMODE_8888 + + +/* 32 bit, ARGB8888 color spanline and pixel functions */ +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + *(GLuint *)(buf + _x*4 + _y*pitch) = ((b << 0) | \ + (g << 8) | \ + (r << 16) | \ + (a << 24) ) + +#define WRITE_PIXEL( _x, _y, p ) \ + *(GLuint *)(buf + _x*4 + _y*pitch) = p + +#define READ_RGBA( rgba, _x, _y ) \ +do { \ + GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \ + rgba[0] = (p >> 16) & 0xff; \ + rgba[1] = (p >> 8) & 0xff; \ + rgba[2] = (p >> 0) & 0xff; \ + rgba[3] = (p >> 24) & 0xff; \ +} while (0) + +#define TAG(x) tdfx##x##_ARGB8888 +#define BYTESPERPIXEL 4 +#include "spantmp.h" +#undef BYTESPERPIXEL + + + +/* ================================================================ + * Old span functions below... + */ + + +/* + * Examine the cliprects to generate an array of flags to indicate + * which pixels in a span are visible. Note: (x,y) is a screen + * coordinate. + */ +static void +generate_vismask(const tdfxContextPtr fxMesa, GLint x, GLint y, GLint n, + GLubyte vismask[]) +{ + GLboolean initialized = GL_FALSE; + GLint i, j; + + /* Ensure we clear the visual mask */ + MEMSET(vismask, 0, n); + + /* turn on flags for all visible pixels */ + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + + if (y >= rect->y1 && y < rect->y2) { + if (x >= rect->x1 && x + n <= rect->x2) { + /* common case, whole span inside cliprect */ + MEMSET(vismask, 1, n); + return; + } + if (x < rect->x2 && x + n >= rect->x1) { + /* some of the span is inside the rect */ + GLint start, end; + if (!initialized) { + MEMSET(vismask, 0, n); + initialized = GL_TRUE; + } + if (x < rect->x1) + start = rect->x1 - x; + else + start = 0; + if (x + n > rect->x2) + end = rect->x2 - x; + else + end = n; + assert(start >= 0); + assert(end <= n); + for (j = start; j < end; j++) + vismask[j] = 1; + } + } + } +} + +/* + * Examine cliprects and determine if the given screen pixel is visible. + */ +static GLboolean +visible_pixel(const tdfxContextPtr fxMesa, int scrX, int scrY) +{ + int i; + for (i = 0; i < fxMesa->numClipRects; i++) { + const XF86DRIClipRectPtr rect = &fxMesa->pClipRects[i]; + if (scrX >= rect->x1 && + scrX < rect->x2 && + scrY >= rect->y1 && scrY < rect->y2) return GL_TRUE; + } + return GL_FALSE; +} + + + +/* + * Depth buffer read/write functions. + */ +/* + * To read the frame buffer, we need to lock and unlock it. The + * four macros {READ,WRITE}_FB_SPAN_{LOCK,UNLOCK} + * do this for us. + * + * Note that the lock must be matched with an unlock. These + * macros include a spare curly brace, so they must + * be syntactically matched. + * + * Note, also, that you can't lock a buffer twice with different + * modes. That is to say, you can't lock a buffer in both read + * and write modes. The strideInBytes and LFB pointer will be + * the same with read and write locks, so you can use either. + * o The HW has different state for reads and writes, so + * locking it twice may give screwy results. + * o The DRM won't let you lock twice. It hangs. This is probably + * because of the LOCK_HARDWARE IN THE *_FB_SPAN_LOCK macros, + * and could be eliminated with nonlocking lock routines. But + * what's the point after all. + */ +#define READ_FB_SPAN_LOCK(fxMesa, info, target_buffer) \ + UNLOCK_HARDWARE(fxMesa); \ + LOCK_HARDWARE(fxMesa); \ + (info).size=sizeof(info); \ + if (grLfbLock(GR_LFB_READ_ONLY, \ + target_buffer, \ + GR_LFBWRITEMODE_ANY, \ + GR_ORIGIN_UPPER_LEFT, \ + FXFALSE, \ + &(info))) { + +#define READ_FB_SPAN_UNLOCK(fxMesa, target_buffer) \ + grLfbUnlock(GR_LFB_READ_ONLY, target_buffer); \ + } else { \ + fprintf(stderr, "tdfxDriver: Can't get %s (%d) read lock\n", \ + (target_buffer == GR_BUFFER_BACKBUFFER) \ + ? "back buffer" \ + : ((target_buffer == GR_BUFFER_AUXBUFFER) \ + ? "depth buffer" \ + : "unknown buffer"), \ + target_buffer); \ + } + +#define WRITE_FB_SPAN_LOCK(fxMesa, info, target_buffer, write_mode) \ + UNLOCK_HARDWARE(fxMesa); \ + LOCK_HARDWARE(fxMesa); \ + info.size=sizeof(info); \ + if (grLfbLock(GR_LFB_WRITE_ONLY, \ + target_buffer, \ + write_mode, \ + GR_ORIGIN_UPPER_LEFT, \ + FXFALSE, \ + &info)) { + +#define WRITE_FB_SPAN_UNLOCK(fxMesa, target_buffer) \ + grLfbUnlock(GR_LFB_WRITE_ONLY, target_buffer); \ + } else { \ + fprintf(stderr, "tdfxDriver: Can't get %s (%d) write lock\n", \ + (target_buffer == GR_BUFFER_BACKBUFFER) \ + ? "back buffer" \ + : ((target_buffer == GR_BUFFER_AUXBUFFER) \ + ? "depth buffer" \ + : "unknown buffer"), \ + target_buffer); \ + } + +/* + * Because the Linear Frame Buffer is not necessarily aligned + * with the depth buffer, we have to do some fiddling + * around to get the right addresses. + * + * Perhaps a picture is in order. The Linear Frame Buffer + * looks like this: + * + * |<----------------------info.strideInBytes------------->| + * |<-----physicalStrideInBytes------->| + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * | | | + * | Legal Memory | Forbidden Zone | + * | | | + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * + * You can only reliably read and write legal locations. Reads + * and writes from the Forbidden Zone will return undefined values, + * and may cause segmentation faults. + * + * Now, the depth buffer may not end up in a location such each + * scan line is an LFB line. For example, the depth buffer may + * look like this: + * + * wrapped ordinary. + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * |0000000000000000000000 | | back + * |1111111111111111111111 | | buffer + * |2222222222222222222222 | | + * |4096b align. padxx00000000000000000| Forbidden Zone | depth + * |0000 11111111111111111| | buffer + * |1111 22222222222222222| | + * |2222 | | + * +-----------------------------------+xxxxxxxxxxxxxxxxxxx+ + * where each number is the scan line number. We know it will + * be aligned on 128 byte boundaries, at least. Aligning this + * on a scanline boundary causes the back and depth buffers to + * thrash in the SST1 cache. (Note that the back buffer is always + * allocated at the beginning of LFB memory, and so it is always + * properly aligned with the LFB stride.) + * + * We call the beginning of the line (which is the rightmost + * part of the depth line in the picture above) the *ordinary* part + * of the scanline, and the end of the line (which is the + * leftmost part, one line below) the *wrapped* part of the scanline. + * a.) We need to know what x value to subtract from the screen + * x coordinate to index into the wrapped part. + * b.) We also need to figure out if we need to read from the ordinary + * part scan line, or from the wrapped part of the scan line. + * + * [ad a] + * The first wrapped x coordinate is that coordinate such that + * depthBufferOffset&(info.strideInBytes) + x*elmentSize {*} + * > physicalStrideInBytes + * where depthBufferOffset is the LFB distance in bytes + * from the back buffer to the depth buffer. The expression + * depthBufferOffset&(info.strideInBytes) + * is then the offset (in bytes) from the beginining of (any) + * depth buffer line to first element in the line. + * Simplifying inequation {*} above we see that x is the smallest + * value such that + * x*elementSize > physicalStrideInBytes {**} + * - depthBufferOffset&(info.strideInBytes) + * Now, we know that both the summands on the right are multiples of + * 128, and elementSize <= 4, so if equality holds in {**}, x would + * be a multiple of 32. Thus we can set x to + * xwrapped = (physicalStrideInBytes + * - depthBufferOffset&(info.strideInBytes))/elementSize + * + 1 + * + * [ad b] + * Question b is now simple. We read from the wrapped scan line if + * x is greater than xwrapped. + */ +#define TILE_WIDTH_IN_BYTES 128 +#define TILE_WIDTH_IN_ZOXELS(bpz) (TILE_WIDTH_IN_BYTES/(bpz)) +#define TILE_HEIGHT_IN_LINES 32 +typedef struct +{ + void *lfbPtr; + void *lfbWrapPtr; + FxU32 LFBStrideInElts; + GLint firstWrappedX; +} +LFBParameters; + +/* + * We need information about the back buffer. Note that + * this function *cannot be called* while the aux buffer + * is locked, or the caller will hang. + * + * Only Glide knows the LFB address of the back and depth + * offsets. The upper levels of Mesa know the depth offset, + * but that is not in LFB space, it is tiled memory space, + * and is not useable for us. + */ +static void +GetBackBufferInfo(tdfxContextPtr fxMesa, GrLfbInfo_t * backBufferInfo) +{ + READ_FB_SPAN_LOCK(fxMesa, *backBufferInfo, GR_BUFFER_BACKBUFFER); + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_BACKBUFFER); +} + +static void +GetFbParams(tdfxContextPtr fxMesa, + GrLfbInfo_t * info, + GrLfbInfo_t * backBufferInfo, + LFBParameters * ReadParamsp, FxU32 elementSize) +{ + FxU32 physicalStrideInBytes, bufferOffset; + FxU32 strideInBytes = info->strideInBytes; + char *lfbPtr = (char *) (info->lfbPtr); /* For arithmetic, use char * */ + + /* + * These two come directly from the info structure. + */ + ReadParamsp->lfbPtr = (void *) lfbPtr; + ReadParamsp->LFBStrideInElts = strideInBytes / elementSize; + /* + * Now, calculate the value of firstWrappedX. + * + * The physical stride is the screen width in bytes rounded up to + * the next highest multiple of 128 bytes. Note that this fails + * when TILE_WIDTH_IN_BYTES is not a power of two. + * + * The buffer Offset is the distance between the beginning of + * the LFB space, which is the beginning of the back buffer, + * and the buffer we are gathering information about. + * We want to make this routine usable for operations on the + * back buffer, though we don't actually use it on the back + * buffer. Note, then, that if bufferOffset == 0, the firstWrappedX + * is in the forbidden zone, and is therefore never reached. + * + * Note that if + * physicalStrideInBytes + * < bufferOffset&(info->strideInBytes-1) + * the buffer begins in the forbidden zone. We assert for this. + */ + bufferOffset = (FxU32)(lfbPtr - (char *) backBufferInfo->lfbPtr); + physicalStrideInBytes + = (fxMesa->screen_width * elementSize + TILE_WIDTH_IN_BYTES - 1) + & ~(TILE_WIDTH_IN_BYTES - 1); + assert(physicalStrideInBytes > (bufferOffset & (strideInBytes - 1))); + ReadParamsp->firstWrappedX + = (physicalStrideInBytes + - (bufferOffset & (strideInBytes - 1))) / elementSize; + /* + * This is the address of the next physical line. + */ + ReadParamsp->lfbWrapPtr + = (void *) ((char *) backBufferInfo->lfbPtr + + (bufferOffset & ~(strideInBytes - 1)) + + (TILE_HEIGHT_IN_LINES) * strideInBytes); +} + +/* + * These macros fetch data from the frame buffer. The type is + * the type of data we want to fetch. It should match the type + * whose size was used with GetFbParams to fill in the structure + * in *ReadParamsp. We have a macro to read the ordinary + * part, a second macro to read the wrapped part, and one which + * will do either. When we are reading a span, we will know + * when the ordinary part ends, so there's no need to test for + * it. However, when reading and writing pixels, we don't + * necessarily know. I suppose it's a matter of taste whether + * it's better in the macro or in the call. + * + * Recall that x and y are screen coordinates. + */ +#define GET_FB_DATA(ReadParamsp, type, x, y) \ + (((x) < (ReadParamsp)->firstWrappedX) \ + ? (((type *)((ReadParamsp)->lfbPtr)) \ + [(y) * ((ReadParamsp)->LFBStrideInElts) \ + + (x)]) \ + : (((type *)((ReadParamsp)->lfbWrapPtr)) \ + [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + + ((x) - (ReadParamsp)->firstWrappedX)])) +#define GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) \ + (((type *)((ReadParamsp)->lfbPtr)) \ + [(y) * ((ReadParamsp)->LFBStrideInElts) \ + + (x)]) +#define GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) \ + (((type *)((ReadParamsp)->lfbWrapPtr)) \ + [((y)) * ((ReadParamsp)->LFBStrideInElts) \ + + ((x) - (ReadParamsp)->firstWrappedX)]) +#define PUT_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) +#define PUT_ORDINARY_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_ORDINARY_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) +#define PUT_WRAPPED_FB_DATA(ReadParamsp, type, x, y, value) \ + (GET_WRAPPED_FB_DATA(ReadParamsp, type, x, y) = (type)(value)) + +static void +tdfxDDWriteDepthSpan(GLcontext * ctx, + GLuint n, GLint x, GLint y, const GLdepth depth[], + const GLubyte mask[]) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + GLint bottom = fxMesa->y_offset + fxMesa->height - 1; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GrLfbInfo_t info; + GLubyte visMask[MAX_WIDTH]; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "tdfxmesa: tdfxDDWriteDepthSpan(...)\n"); + } + + assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); + /* + * Convert x and y to screen coordinates. + */ + x += fxMesa->x_offset; + y = bottom - y; + if (mask) { + GLint i; + GLushort d16; + GrLfbInfo_t backBufferInfo; + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, + GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + int wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (mask[i] && visMask[i]) { + d16 = depth[i]; + PUT_ORDINARY_FB_DATA(&ReadParams, GLushort, x + i, y, d16); + } + } + for (; i < n; i++) { + if (mask[i] && visMask[i]) { + d16 = depth[i]; + PUT_WRAPPED_FB_DATA(&ReadParams, GLushort, x + i, y, d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, + GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + int wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + GLuint d32; + if (mask[i] && visMask[i]) { + if (stencil_size > 0) { + d32 = + GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + for (; i < n; i++) { + GLuint d32; + if (mask[i] && visMask[i]) { + if (stencil_size > 0) { + d32 = + GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } + else { + GLint i; + GLuint d32; + GLushort d16; + GrLfbInfo_t backBufferInfo; + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + GLuint wrappedPartStart; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i]) { + d16 = depth[i]; + PUT_ORDINARY_FB_DATA(&ReadParams, + GLushort, + x + i, y, + d16); + } + } + for (; i < n; i++) { + if (visMask[i]) { + d16 = depth[i]; + PUT_WRAPPED_FB_DATA(&ReadParams, + GLushort, + x + i, y, + d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + generate_vismask(fxMesa, x, y, n, visMask); + { + LFBParameters ReadParams; + GLuint wrappedPartStart; + + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i]) { + if (stencil_size > 0) { + d32 = GET_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + for (; i < n; i++) { + if (visMask[i]) { + if (stencil_size > 0) { + d32 = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y); + d32 = + (d32 & 0xFF000000) | (depth[i] & 0x00FFFFFF); + } + else { + d32 = depth[i]; + } + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y, d32); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } +} + +static void +tdfxDDReadDepthSpan(GLcontext * ctx, + GLuint n, GLint x, GLint y, GLdepth depth[]) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLuint i; + GLuint depth_size = fxMesa->glVis->DepthBits; + GrLfbInfo_t info; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "tdfxmesa: tdfxDDReadDepthSpan(...)\n"); + } + + /* + * Convert to screen coordinates. + */ + x += fxMesa->x_offset; + y = bottom - y; + switch (depth_size) { + case 16: + { + LFBParameters ReadParams; + GrLfbInfo_t backBufferInfo; + int wrappedPartStart; + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + /* + * Read the line. + */ + for (i = 0; i < wrappedPartStart; i++) { + depth[i] = + GET_ORDINARY_FB_DATA(&ReadParams, GLushort, x + i, y); + } + for (; i < n; i++) { + depth[i] = GET_WRAPPED_FB_DATA(&ReadParams, GLushort, + x + i, y); + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + case 24: + case 32: + { + LFBParameters ReadParams; + GrLfbInfo_t backBufferInfo; + int wrappedPartStart; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + /* + * Read the line. + */ + for (i = 0; i < wrappedPartStart; i++) { + const GLuint mask = + (stencil_size > 0) ? 0x00FFFFFF : 0xFFFFFFFF; + depth[i] = + GET_ORDINARY_FB_DATA(&ReadParams, GLuint, x + i, y); + depth[i] &= mask; + } + for (; i < n; i++) { + const GLuint mask = + (stencil_size > 0) ? 0x00FFFFFF : 0xFFFFFFFF; + depth[i] = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, x + i, y); + depth[i] &= mask; + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } + } +} + + +static void +tdfxDDWriteDepthPixels(GLcontext * ctx, + GLuint n, const GLint x[], const GLint y[], + const GLdepth depth[], const GLubyte mask[]) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLuint i; + GLushort d16; + GLuint d32; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLuint stencil_size = fxMesa->glVis->StencilBits; + GrLfbInfo_t info; + int xpos; + int ypos; + GrLfbInfo_t backBufferInfo; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "tdfxmesa: tdfxDDWriteDepthPixels(...)\n"); + } + + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + for (i = 0; i < n; i++) { + if (mask[i] && visible_pixel(fxMesa, x[i], y[i])) { + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d16 = depth[i]; + PUT_FB_DATA(&ReadParams, GLushort, xpos, ypos, d16); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, + GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + for (i = 0; i < n; i++) { + if (mask[i]) { + if (visible_pixel(fxMesa, x[i], y[i])) { + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + if (stencil_size > 0) { + d32 = + GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); + d32 = (d32 & 0xFF000000) | (depth[i] & 0xFFFFFF); + } + else { + d32 = depth[i]; + } + PUT_FB_DATA(&ReadParams, GLuint, xpos, ypos, d32); + } + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + } +} + + +static void +tdfxDDReadDepthPixels(GLcontext * ctx, GLuint n, + const GLint x[], const GLint y[], GLdepth depth[]) +{ + tdfxContextPtr fxMesa = (tdfxContextPtr) ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; + GLuint i; + GLuint depth_size = fxMesa->glVis->DepthBits; + GLushort d16; + int xpos; + int ypos; + GrLfbInfo_t info; + GLuint stencil_size; + GrLfbInfo_t backBufferInfo; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "tdfxmesa: tdfxDDReadDepthPixels(...)\n"); + } + + assert((depth_size == 16) || (depth_size == 24) || (depth_size == 32)); + switch (depth_size) { + case 16: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLushort)); + for (i = 0; i < n; i++) { + /* + * Convert to screen coordinates. + */ + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d16 = GET_FB_DATA(&ReadParams, GLushort, xpos, ypos); + depth[i] = d16; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + case 24: + case 32: + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + stencil_size = fxMesa->glVis->StencilBits; + { + LFBParameters ReadParams; + GetFbParams(fxMesa, &info, &backBufferInfo, + &ReadParams, sizeof(GLuint)); + for (i = 0; i < n; i++) { + GLuint d32; + + /* + * Convert to screen coordinates. + */ + xpos = x[i] + fxMesa->x_offset; + ypos = bottom - y[i]; + d32 = GET_FB_DATA(&ReadParams, GLuint, xpos, ypos); + if (stencil_size > 0) { + d32 &= 0x00FFFFFF; + } + depth[i] = d32; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); + break; + default: + assert(0); + } +} + +/* + * Stencil buffer read/write functions. + */ +#define EXTRACT_S_FROM_ZS(zs) (((zs) >> 24) & 0xFF) +#define EXTRACT_Z_FROM_ZS(zs) ((zs) & 0xffffff) +#define BUILD_ZS(z, s) (((s) << 24) | (z)) + +static void +write_stencil_span(GLcontext * ctx, GLuint n, GLint x, GLint y, + const GLstencil stencil[], const GLubyte mask[]) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + const GLint scrX = winX + x; + const GLint scrY = winY - y; + LFBParameters ReadParams; + GLubyte visMask[MAX_WIDTH]; + GLuint i; + int wrappedPartStart; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + generate_vismask(fxMesa, scrX, scrY, n, visMask); + for (i = 0; i < wrappedPartStart; i++) { + if (visMask[i] && (!mask || mask[i])) { + GLuint z = GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + scrX + i, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_ORDINARY_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); + } + } + for (; i < n; i++) { + if (visMask[i] && (!mask || mask[i])) { + GLuint z = GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + scrX + i, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_WRAPPED_FB_DATA(&ReadParams, GLuint, scrX + i, scrY, z); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +read_stencil_span(GLcontext * ctx, GLuint n, GLint x, GLint y, + GLstencil stencil[]) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + GLuint i; + LFBParameters ReadParams; + int wrappedPartStart; + + /* + * Convert to screen coordinates. + */ + x += winX; + y = winY - y; + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + if (ReadParams.firstWrappedX <= x) { + wrappedPartStart = 0; + } + else if (n <= (ReadParams.firstWrappedX - x)) { + wrappedPartStart = n; + } + else { + wrappedPartStart = (ReadParams.firstWrappedX - x); + } + for (i = 0; i < wrappedPartStart; i++) { + stencil[i] = (GET_ORDINARY_FB_DATA(&ReadParams, GLuint, + x + i, y) >> 24) & 0xFF; + } + for (; i < n; i++) { + stencil[i] = (GET_WRAPPED_FB_DATA(&ReadParams, GLuint, + x + i, y) >> 24) & 0xFF; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +write_stencil_pixels(GLcontext * ctx, GLuint n, + const GLint x[], const GLint y[], + const GLstencil stencil[], const GLubyte mask[]) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + WRITE_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER, GR_LFBWRITEMODE_ANY); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + LFBParameters ReadParams; + GLuint i; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + for (i = 0; i < n; i++) { + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + if ((!mask || mask[i]) && visible_pixel(fxMesa, scrX, scrY)) { + GLuint z = + GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) & 0x00FFFFFF; + z |= (stencil[i] & 0xFF) << 24; + PUT_FB_DATA(&ReadParams, GLuint, scrX, scrY, z); + } + } + } + WRITE_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + + +static void +read_stencil_pixels(GLcontext * ctx, GLuint n, const GLint x[], + const GLint y[], GLstencil stencil[]) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrLfbInfo_t info; + GrLfbInfo_t backBufferInfo; + + GetBackBufferInfo(fxMesa, &backBufferInfo); + /* + * Note that the _LOCK macro adds a curly brace, + * and the UNLOCK macro removes it. + */ + READ_FB_SPAN_LOCK(fxMesa, info, GR_BUFFER_AUXBUFFER); + { + const GLint winY = fxMesa->y_offset + fxMesa->height - 1; + const GLint winX = fxMesa->x_offset; + GLuint i; + LFBParameters ReadParams; + + GetFbParams(fxMesa, &info, &backBufferInfo, &ReadParams, + sizeof(GLuint)); + for (i = 0; i < n; i++) { + const GLint scrX = winX + x[i]; + const GLint scrY = winY - y[i]; + stencil[i] = + (GET_FB_DATA(&ReadParams, GLuint, scrX, scrY) >> 24) & 0xFF; + } + } + READ_FB_SPAN_UNLOCK(fxMesa, GR_BUFFER_AUXBUFFER); +} + +#define VISUAL_EQUALS_RGBA(vis, r, g, b, a) \ + ((vis->RedBits == r) && \ + (vis->GreenBits == g) && \ + (vis->BlueBits == b) && \ + (vis->AlphaBits == a)) + +void tdfxDDInitSpanFuncs( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( VISUAL_EQUALS_RGBA(ctx->Visual, 5, 6, 5, 0) ) + { + /* 16bpp mode */ + ctx->Driver.WriteRGBASpan = tdfxWriteRGBASpan_RGB565; + ctx->Driver.WriteRGBSpan = tdfxWriteRGBSpan_RGB565; + ctx->Driver.WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_RGB565; + ctx->Driver.WriteRGBAPixels = tdfxWriteRGBAPixels_RGB565; + ctx->Driver.WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_RGB565; + ctx->Driver.ReadRGBASpan = tdfxReadRGBASpan_RGB565; + ctx->Driver.ReadRGBAPixels = tdfxReadRGBAPixels_RGB565; + } + else if ( VISUAL_EQUALS_RGBA(ctx->Visual, 8, 8, 8, 0) ) + { + /* 24bpp mode */ + ctx->Driver.WriteRGBASpan = tdfxWriteRGBASpan_RGB888; + ctx->Driver.WriteRGBSpan = tdfxWriteRGBSpan_RGB888; + ctx->Driver.WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_RGB888; + ctx->Driver.WriteRGBAPixels = tdfxWriteRGBAPixels_RGB888; + ctx->Driver.WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_RGB888; + ctx->Driver.ReadRGBASpan = tdfxReadRGBASpan_RGB888; + ctx->Driver.ReadRGBAPixels = tdfxReadRGBAPixels_RGB888; + } + else if ( VISUAL_EQUALS_RGBA(ctx->Visual, 8, 8, 8, 8) ) + { + /* 32bpp mode */ + ctx->Driver.WriteRGBASpan = tdfxWriteRGBASpan_ARGB8888; + ctx->Driver.WriteRGBSpan = tdfxWriteRGBSpan_ARGB8888; + ctx->Driver.WriteMonoRGBASpan = tdfxWriteMonoRGBASpan_ARGB8888; + ctx->Driver.WriteRGBAPixels = tdfxWriteRGBAPixels_ARGB8888; + ctx->Driver.WriteMonoRGBAPixels = tdfxWriteMonoRGBAPixels_ARGB8888; + ctx->Driver.ReadRGBAPixels = tdfxReadRGBAPixels_ARGB8888; + ctx->Driver.ReadRGBASpan = tdfxReadRGBASpan_ARGB8888; + } + else + { + abort(); + } + + if ( fxMesa->haveHwStencil ) { + ctx->Driver.WriteStencilSpan = write_stencil_span; + ctx->Driver.ReadStencilSpan = read_stencil_span; + ctx->Driver.WriteStencilPixels = write_stencil_pixels; + ctx->Driver.ReadStencilPixels = read_stencil_pixels; + } + + ctx->Driver.WriteDepthSpan = tdfxDDWriteDepthSpan; + ctx->Driver.WriteDepthPixels = tdfxDDWriteDepthPixels; + ctx->Driver.ReadDepthSpan = tdfxDDReadDepthSpan; + ctx->Driver.ReadDepthPixels = tdfxDDReadDepthPixels; + + ctx->Driver.WriteCI8Span = NULL; + ctx->Driver.WriteCI32Span = NULL; + ctx->Driver.WriteMonoCISpan = NULL; + ctx->Driver.WriteCI32Pixels = NULL; + ctx->Driver.WriteMonoCIPixels = NULL; + ctx->Driver.ReadCI32Span = NULL; + ctx->Driver.ReadCI32Pixels = NULL; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.h new file mode 100644 index 000000000..47303c600 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_span.h @@ -0,0 +1,48 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#ifndef __TDFX_SPAN_H__ +#define __TDFX_SPAN_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "context.h" + +extern void tdfxDDInitSpanFuncs( GLcontext *ctx ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.c new file mode 100644 index 000000000..eb9a6a98b --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.c @@ -0,0 +1,1558 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "types.h" +#include "pb.h" + +#include "dri_glide.h" + +#include "tdfx_context.h" +#include "tdfx_state.h" +#include "tdfx_vb.h" +#include "tdfx_tex.h" +#include "tdfx_texman.h" +#include "tdfx_texstate.h" +#include "tdfx_tris.h" +#include "tdfx_render.h" + + + +/* ============================================================= + * Alpha blending + */ + +static void tdfxUpdateAlphaMode( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrCmpFnc_t func; + GrAlphaBlendFnc_t srcRGB, dstRGB, srcA, dstA; + GrAlpha_t ref = ctx->Color.AlphaRef; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + if ( ctx->Color.AlphaEnabled ) { + switch ( ctx->Color.AlphaFunc ) { + case GL_NEVER: + func = GR_CMP_NEVER; + break; + case GL_LESS: + func = GR_CMP_LESS; + break; + case GL_LEQUAL: + func = GR_CMP_LEQUAL; + break; + case GL_EQUAL: + func = GR_CMP_EQUAL; + break; + case GL_GEQUAL: + func = GR_CMP_GEQUAL; + break; + case GL_GREATER: + func = GR_CMP_GREATER; + break; + case GL_NOTEQUAL: + func = GR_CMP_NOTEQUAL; + break; + case GL_ALWAYS: + default: + func = GR_CMP_ALWAYS; + break; + } + } else { + func = GR_CMP_ALWAYS; + } + + if ( ctx->Color.BlendEnabled + && (fxMesa->Fallback & TDFX_FALLBACK_BLEND) == 0 ) { + switch ( ctx->Color.BlendSrcRGB ) { + case GL_ZERO: + srcRGB = GR_BLEND_ZERO; + break; + case GL_ONE: + srcRGB = GR_BLEND_ONE; + break; + case GL_DST_COLOR: + srcRGB = GR_BLEND_DST_COLOR; + break; + case GL_ONE_MINUS_DST_COLOR: + srcRGB = GR_BLEND_ONE_MINUS_DST_COLOR; + break; + case GL_SRC_ALPHA: + srcRGB = GR_BLEND_SRC_ALPHA; + break; + case GL_ONE_MINUS_SRC_ALPHA: + srcRGB = GR_BLEND_ONE_MINUS_SRC_ALPHA; + break; + case GL_DST_ALPHA: + srcRGB = GR_BLEND_DST_ALPHA; + break; + case GL_ONE_MINUS_DST_ALPHA: + srcRGB = GR_BLEND_ONE_MINUS_DST_ALPHA; + break; + case GL_SRC_ALPHA_SATURATE: + srcRGB = GR_BLEND_ALPHA_SATURATE; + break; + default: + srcRGB = GR_BLEND_ONE; + } + + switch ( ctx->Color.BlendSrcA ) { + case GL_ZERO: + srcA = GR_BLEND_ZERO; + break; + case GL_ONE: + srcA = GR_BLEND_ONE; + break; + case GL_DST_COLOR: + srcA = GR_BLEND_DST_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_DST_COLOR: + srcA = GR_BLEND_ONE_MINUS_DST_ALPHA; /* Napalm only */ + break; + case GL_SRC_ALPHA: + srcA = GR_BLEND_SRC_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_SRC_ALPHA: + srcA = GR_BLEND_ONE_MINUS_SRC_ALPHA; /* Napalm only */ + break; + case GL_DST_ALPHA: + srcA = GR_BLEND_DST_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_DST_ALPHA: + srcA = GR_BLEND_ONE_MINUS_DST_ALPHA; /* Napalm only */ + break; + case GL_SRC_ALPHA_SATURATE: + srcA = GR_BLEND_ONE; + break; + default: + srcA = GR_BLEND_ONE; + } + + switch ( ctx->Color.BlendDstRGB ) { + case GL_ZERO: + dstRGB = GR_BLEND_ZERO; + break; + case GL_ONE: + dstRGB = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + dstRGB = GR_BLEND_SRC_COLOR; + break; + case GL_ONE_MINUS_SRC_COLOR: + dstRGB = GR_BLEND_ONE_MINUS_SRC_COLOR; + break; + case GL_SRC_ALPHA: + dstRGB = GR_BLEND_SRC_ALPHA; + break; + case GL_ONE_MINUS_SRC_ALPHA: + dstRGB = GR_BLEND_ONE_MINUS_SRC_ALPHA; + break; + case GL_DST_ALPHA: + dstRGB = GR_BLEND_DST_ALPHA; + break; + case GL_ONE_MINUS_DST_ALPHA: + dstRGB = GR_BLEND_ONE_MINUS_DST_ALPHA; + break; + default: + dstRGB = GR_BLEND_ZERO; + } + + switch ( ctx->Color.BlendDstA ) { + case GL_ZERO: + dstA = GR_BLEND_ZERO; + break; + case GL_ONE: + dstA = GR_BLEND_ONE; + break; + case GL_SRC_COLOR: + dstA = GR_BLEND_SRC_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_SRC_COLOR: + dstA = GR_BLEND_ONE_MINUS_SRC_ALPHA; /* Napalm only */ + break; + case GL_SRC_ALPHA: + dstA = GR_BLEND_SRC_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_SRC_ALPHA: + dstA = GR_BLEND_ONE_MINUS_SRC_ALPHA; /* Napalm only */ + break; + case GL_DST_ALPHA: + dstA = GR_BLEND_DST_ALPHA; /* Napalm only */ + break; + case GL_ONE_MINUS_DST_ALPHA: + dstA = GR_BLEND_ONE_MINUS_DST_ALPHA; /* Napalm only */ + break; + default: + dstA = GR_BLEND_ZERO; + } + } else { + /* blend disabled */ + srcRGB = GR_BLEND_ONE; + dstRGB = GR_BLEND_ZERO; + srcA = GR_BLEND_ONE; + dstA = GR_BLEND_ZERO; + } + + if ( fxMesa->Color.AlphaFunc != func ) { + fxMesa->Color.AlphaFunc = func; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_TEST; + } + if ( fxMesa->Color.AlphaRef != ref ) { + fxMesa->Color.AlphaRef = ref; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_REF; + } + + if ( fxMesa->Color.BlendSrcRGB != srcRGB || + fxMesa->Color.BlendDstRGB != dstRGB || + fxMesa->Color.BlendSrcA != srcA || + fxMesa->Color.BlendDstA != dstA ) + { + fxMesa->Color.BlendSrcRGB = srcRGB; + fxMesa->Color.BlendDstRGB = dstRGB; + fxMesa->Color.BlendSrcA = srcA; + fxMesa->Color.BlendDstA = dstA; + fxMesa->dirty |= TDFX_UPLOAD_BLEND_FUNC; + } +} + +static void tdfxDDAlphaFunc( GLcontext *ctx, GLenum func, GLclampf ref ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; +} + +static void tdfxDDBlendEquation( GLcontext *ctx, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; + + if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) + fxMesa->Fallback |= TDFX_FALLBACK_LOGICOP; + else + fxMesa->Fallback &= ~TDFX_FALLBACK_LOGICOP; +} + +static void tdfxDDBlendFunc( GLcontext *ctx, GLenum sfactor, GLenum dfactor ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; + + /* + * XXX - Voodoo5 seems to suffer from precision problems in some + * blend modes. To pass all the conformance tests we'd have to + * fall back to software for many modes. Revisit someday. + */ +} + +static void tdfxDDBlendFuncSeparate( GLcontext *ctx, + GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorA, GLenum dfactorA ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; +} + +/* ============================================================= + * Stipple + */ + +static void tdfxUpdateStipple( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + GrStippleMode_t mode = GR_STIPPLE_DISABLE; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + FLUSH_BATCH( fxMesa ); + + if (ctx->Polygon.StippleFlag) { + mode = GR_STIPPLE_PATTERN; + } + + if ( fxMesa->Stipple.Mode != mode ) { + fxMesa->Stipple.Mode = mode; + fxMesa->dirty |= TDFX_UPLOAD_STIPPLE; + } +} + + +/* ============================================================= + * Depth testing + */ + +static void tdfxUpdateZMode( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + GrCmpFnc_t func; + FxI32 bias; + FxBool mask; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + bias = (FxI32) (ctx->Polygon.OffsetUnits * TDFX_DEPTH_BIAS_SCALE); + + if ( ctx->Depth.Test ) { + switch ( ctx->Depth.Func ) { + case GL_NEVER: + func = GR_CMP_NEVER; + break; + case GL_LESS: + func = GR_CMP_LESS; + break; + case GL_LEQUAL: + func = GR_CMP_LEQUAL; + break; + case GL_EQUAL: + func = GR_CMP_EQUAL; + break; + case GL_GEQUAL: + func = GR_CMP_GEQUAL; + break; + case GL_GREATER: + func = GR_CMP_GREATER; + break; + case GL_NOTEQUAL: + func = GR_CMP_NOTEQUAL; + break; + case GL_ALWAYS: + default: + func = GR_CMP_ALWAYS; + break; + } + + if ( ctx->Depth.Mask ) { + mask = FXTRUE; + } + else { + mask = FXFALSE; + } + } + else { + /* depth testing disabled */ + func = GR_CMP_ALWAYS; /* fragments always pass */ + mask = FXFALSE; /* zbuffer is not touched */ + } + + fxMesa->Depth.Clear = (FxU32) (((1 << fxMesa->glVis->DepthBits) - 1) + * ctx->Depth.Clear); + + if ( fxMesa->Depth.Bias != bias ) { + fxMesa->Depth.Bias = bias; + fxMesa->dirty |= TDFX_UPLOAD_DEPTH_BIAS; + } + if ( fxMesa->Depth.Func != func ) { + fxMesa->Depth.Func = func; + fxMesa->dirty |= TDFX_UPLOAD_DEPTH_FUNC | TDFX_UPLOAD_DEPTH_MASK; + } + if ( fxMesa->Depth.Mask != mask ) { + fxMesa->Depth.Mask = mask; + fxMesa->dirty |= TDFX_UPLOAD_DEPTH_MASK; + } +} + +static void tdfxDDDepthFunc( GLcontext *ctx, GLenum func ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_DEPTH; +} + +static void tdfxDDDepthMask( GLcontext *ctx, GLboolean flag ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_DEPTH; +} + +static void tdfxDDClearDepth( GLcontext *ctx, GLclampd d ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_DEPTH; +} + + + +/* ============================================================= + * Stencil + */ + + +/* Evaluate all stencil state and make the Glide calls. + */ +static GrStencil_t convertGLStencilOp( GLenum op ) +{ + switch ( op ) { + case GL_KEEP: + return GR_STENCILOP_KEEP; + case GL_ZERO: + return GR_STENCILOP_ZERO; + case GL_REPLACE: + return GR_STENCILOP_REPLACE; + case GL_INCR: + return GR_STENCILOP_INCR_CLAMP; + case GL_DECR: + return GR_STENCILOP_DECR_CLAMP; + case GL_INVERT: + return GR_STENCILOP_INVERT; + case GL_INCR_WRAP_EXT: + return GR_STENCILOP_INCR_WRAP; + case GL_DECR_WRAP_EXT: + return GR_STENCILOP_DECR_WRAP; + default: + gl_problem( NULL, "bad stencil op in convertGLStencilOp" ); + } + return GR_STENCILOP_KEEP; /* never get, silence compiler warning */ +} + + +static void tdfxUpdateStencil( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + if (fxMesa->haveHwStencil) { + if (ctx->Stencil.Enabled) { + fxMesa->Stencil.Function = ctx->Stencil.Function - GL_NEVER; + fxMesa->Stencil.RefValue = ctx->Stencil.Ref; + fxMesa->Stencil.ValueMask = ctx->Stencil.ValueMask; + fxMesa->Stencil.WriteMask = ctx->Stencil.WriteMask; + fxMesa->Stencil.FailFunc = convertGLStencilOp(ctx->Stencil.FailFunc); + fxMesa->Stencil.ZFailFunc =convertGLStencilOp(ctx->Stencil.ZFailFunc); + fxMesa->Stencil.ZPassFunc =convertGLStencilOp(ctx->Stencil.ZPassFunc); + fxMesa->Stencil.Clear = ctx->Stencil.Clear & 0xff; + } + fxMesa->dirty |= TDFX_UPLOAD_STENCIL; + } +} + + +static void tdfxDDStencilFunc( GLcontext *ctx, GLenum func, + GLint ref, GLuint mask ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_STENCIL; +} + +static void tdfxDDStencilMask( GLcontext *ctx, GLuint mask ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_STENCIL; +} + +static void tdfxDDStencilOp( GLcontext *ctx, GLenum sfail, + GLenum zfail, GLenum zpass ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_STENCIL; +} + + +/* ============================================================= + * Fog - orthographic fog still not working + */ + +static void tdfxUpdateFogAttrib( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrFogMode_t mode; + GrColor_t color; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + if ( ctx->Fog.Enabled ) { + mode = GR_FOG_WITH_TABLE_ON_Q; + } else { + mode = GR_FOG_DISABLE; + } + + color = TDFXPACKCOLOR888((GLubyte)(ctx->Fog.Color[0]*255.0F), + (GLubyte)(ctx->Fog.Color[1]*255.0F), + (GLubyte)(ctx->Fog.Color[2]*255.0F)); + + if ( fxMesa->Fog.Mode != mode ) { + fxMesa->Fog.Mode = mode; + fxMesa->dirty |= TDFX_UPLOAD_FOG_MODE; + } + if ( fxMesa->Fog.Color != color ) { + fxMesa->Fog.Color = color; + fxMesa->dirty |= TDFX_UPLOAD_FOG_COLOR; + } + if ( fxMesa->Fog.TableMode != ctx->Fog.Mode || + fxMesa->Fog.Density != ctx->Fog.Density || + fxMesa->Fog.Near != ctx->Fog.Start || + fxMesa->Fog.Far != ctx->Fog.End ) + { + switch( ctx->Fog.Mode ) { + case GL_EXP: + guFogGenerateExp( fxMesa->Fog.Table, ctx->Fog.Density ); + break; + case GL_EXP2: + guFogGenerateExp2( fxMesa->Fog.Table, ctx->Fog.Density ); + break; + case GL_LINEAR: + guFogGenerateLinear( fxMesa->Fog.Table, + ctx->Fog.Start, ctx->Fog.End ); + break; + } + + fxMesa->Fog.TableMode = ctx->Fog.Mode; + fxMesa->Fog.Density = ctx->Fog.Density; + fxMesa->Fog.Near = ctx->Fog.Start; + fxMesa->Fog.Far = ctx->Fog.End; + fxMesa->dirty |= TDFX_UPLOAD_FOG_TABLE; + } +} + +static void tdfxDDFogfv( GLcontext *ctx, GLenum pname, const GLfloat *param ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_FOG; +} + + +/* ============================================================= + * Clipping + */ + +static int intersect_rect( XF86DRIClipRectPtr out, + const XF86DRIClipRectPtr a, + const XF86DRIClipRectPtr b) +{ + *out = *a; + if (b->x1 > out->x1) out->x1 = b->x1; + if (b->y1 > out->y1) out->y1 = b->y1; + if (b->x2 < out->x2) out->x2 = b->x2; + if (b->y2 < out->y2) out->y2 = b->y2; + if (out->x1 >= out->x2) return 0; + if (out->y1 >= out->y2) return 0; + return 1; +} + + +/* + * Examine XF86 cliprect list and scissor state to recompute our + * cliprect list. + */ +void tdfxUpdateClipping( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + __DRIdrawablePrivate *dPriv = fxMesa->driDrawable; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + assert(ctx); + assert(fxMesa); + assert(dPriv); + + if ( dPriv->x != fxMesa->x_offset || dPriv->y != fxMesa->y_offset || + dPriv->w != fxMesa->width || dPriv->h != fxMesa->height ) { + fxMesa->x_offset = dPriv->x; + fxMesa->y_offset = dPriv->y; + fxMesa->width = dPriv->w; + fxMesa->height = dPriv->h; + fxMesa->y_delta = + fxMesa->screen_height - fxMesa->y_offset - fxMesa->height; + } + + if (fxMesa->scissoredClipRects && fxMesa->pClipRects) { + free(fxMesa->pClipRects); + } + + if (ctx->Scissor.Enabled) { + /* intersect OpenGL scissor box with all cliprects to make a new + * list of cliprects. + */ + XF86DRIClipRectRec scissor; + int x1 = ctx->Scissor.X + fxMesa->x_offset; + int y1 = fxMesa->screen_height - fxMesa->y_delta + - ctx->Scissor.Y - ctx->Scissor.Height; + int x2 = x1 + ctx->Scissor.Width; + int y2 = y1 + ctx->Scissor.Height; + scissor.x1 = MAX2(x1, 0); + scissor.y1 = MAX2(y1, 0); + scissor.x2 = MAX2(x2, 0); + scissor.y2 = MAX2(y2, 0); + + assert(scissor.x2 >= scissor.x1); + assert(scissor.y2 >= scissor.y1); + + fxMesa->pClipRects = malloc(dPriv->numClipRects + * sizeof(XF86DRIClipRectRec)); + if (fxMesa->pClipRects) { + int i; + fxMesa->numClipRects = 0; + for (i = 0; i < dPriv->numClipRects; i++) { + if (intersect_rect(&fxMesa->pClipRects[fxMesa->numClipRects], + &scissor, &dPriv->pClipRects[i])) { + fxMesa->numClipRects++; + } + } + fxMesa->scissoredClipRects = GL_TRUE; + } + else { + /* out of memory, forgo scissor */ + fxMesa->numClipRects = dPriv->numClipRects; + fxMesa->pClipRects = dPriv->pClipRects; + fxMesa->scissoredClipRects = GL_FALSE; + } + } + else { + fxMesa->numClipRects = dPriv->numClipRects; + fxMesa->pClipRects = dPriv->pClipRects; + fxMesa->scissoredClipRects = GL_FALSE; + } + + fxMesa->dirty |= TDFX_UPLOAD_CLIP; +} + + + +/* ============================================================= + * Culling + */ + +static void tdfxUpdateCull( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrCullMode_t mode = GR_CULL_DISABLE; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + if ( ctx->Polygon.CullFlag && + (ctx->PB->primitive == GL_POLYGON || + ctx->PB->primitive == GL_BITMAP) ) { + switch ( ctx->Polygon.CullFaceMode ) { + case GL_FRONT: + if ( ctx->Polygon.FrontFace == GL_CCW ) { + mode = GR_CULL_POSITIVE; + } else { + mode = GR_CULL_NEGATIVE; + } + break; + + case GL_BACK: + if ( ctx->Polygon.FrontFace == GL_CCW ) { + mode = GR_CULL_NEGATIVE; + } else { + mode = GR_CULL_POSITIVE; + } + break; + + case GL_FRONT_AND_BACK: + default: + mode = GR_CULL_DISABLE; + break; + } + } + + if ( fxMesa->CullMode != mode ) { + fxMesa->CullMode = mode; + fxMesa->dirty |= TDFX_UPLOAD_CULL; + } +} + +static void tdfxDDCullFace( GLcontext *ctx, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_CULL; +} + +static void tdfxDDFrontFace( GLcontext *ctx, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_CULL; +} + + +/* ============================================================= + * Line drawing. + */ + +static void tdfxUpdateLine( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + FLUSH_BATCH( fxMesa ); + fxMesa->dirty |= TDFX_UPLOAD_LINE; +} + + +static void tdfxDDLineWidth( GLcontext *ctx, GLfloat width ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_LINE; +} + + + +/* ============================================================= + * Color Attributes + */ + +static void tdfxDDLogicOp( GLcontext *ctx, GLenum opcode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if (ctx->Color.ColorLogicOpEnabled) + { + FLUSH_BATCH( fxMesa ); + + if (opcode == GL_COPY) + fxMesa->Fallback &= ~TDFX_FALLBACK_LOGICOP; + else + fxMesa->Fallback |= TDFX_FALLBACK_LOGICOP; + } + else + fxMesa->Fallback &= ~TDFX_FALLBACK_LOGICOP; +} + + +static GLboolean tdfxDDColorMask( GLcontext *ctx, + GLboolean r, GLboolean g, + GLboolean b, GLboolean a ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + + if ( fxMesa->Color.ColorMask[RCOMP] != r || + fxMesa->Color.ColorMask[GCOMP] != g || + fxMesa->Color.ColorMask[BCOMP] != b || + fxMesa->Color.ColorMask[ACOMP] != a ) { + fxMesa->Color.ColorMask[RCOMP] = r; + fxMesa->Color.ColorMask[GCOMP] = g; + fxMesa->Color.ColorMask[BCOMP] = b; + fxMesa->Color.ColorMask[ACOMP] = a; + fxMesa->dirty |= TDFX_UPLOAD_COLOR_MASK; + + if (ctx->Visual->RedBits < 8) { + /* Can't do RGB colormasking in 16bpp mode. */ + /* We can completely ignore the alpha mask. */ + if (r != g || g != b) { + fxMesa->Fallback |= TDFX_FALLBACK_COLORMASK; + } + else { + fxMesa->Fallback &= ~TDFX_FALLBACK_COLORMASK; + } + } + } + + return GL_FALSE; /* This forces the software paths to do colormasking. */ + /* This function will return void when we use Mesa 3.5 */ +} + +static void tdfxDDColor( GLcontext *ctx, + GLubyte r, GLubyte g, GLubyte b, GLubyte a ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrColor_t color; + + FLUSH_BATCH( fxMesa ); + + color = tdfxPackColor( fxMesa->fxScreen->cpp, r, g, b, a ); + + if ( fxMesa->Color.MonoColor != color ) { + fxMesa->Color.MonoColor = color; + fxMesa->dirty |= TDFX_UPLOAD_CONSTANT_COLOR; + } +} + +static void tdfxDDClearColor( GLcontext *ctx, + GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + FLUSH_BATCH( fxMesa ); + + fxMesa->Color.ClearColor = TDFXPACKCOLOR888( red, green, blue ); + fxMesa->Color.ClearAlpha = alpha; +} + + +/* ============================================================= + * Light Model + */ + +static void tdfxDDLightModelfv( GLcontext *ctx, GLenum pname, + const GLfloat *param ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( pname == GL_LIGHT_MODEL_COLOR_CONTROL ) { + FLUSH_BATCH( fxMesa ); + + fxMesa->Fallback &= ~TDFX_FALLBACK_SPECULAR; + + if ( ctx->Light.Enabled && + ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR ) { + fxMesa->Fallback |= TDFX_FALLBACK_SPECULAR; + } + } +} + +static void tdfxDDShadeModel( GLcontext *ctx, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + /* FIXME: Can we implement native flat shading? */ + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_TEXTURE; +} + + +/* ============================================================= + * Scissor + */ + +static void +tdfxDDScissor(GLcontext * ctx, GLint x, GLint y, GLsizei w, GLsizei h) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_CLIP; +} + +/* ============================================================= + * Render + */ + +static void tdfxUpdateRenderAttrib( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + FLUSH_BATCH( fxMesa ); + fxMesa->dirty |= TDFX_UPLOAD_RENDER_BUFFER; +} + +/* ============================================================= + * Viewport + */ + +static void tdfxUpdateViewport( GLcontext *ctx ) +{ + /* XXX: Implement this when we're doing clip coordinates */ + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } +} + + +static void tdfxDDViewport( GLcontext *ctx, GLint x, GLint y, + GLsizei w, GLsizei h ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_VIEWPORT; +} + + +static void tdfxDDNearFar( GLcontext *ctx, GLfloat nearVal, GLfloat farVal ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_VIEWPORT; +} + + +/* ============================================================= + * State enable/disable + */ + +static void tdfxDDEnable( GLcontext *ctx, GLenum cap, GLboolean state ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + switch ( cap ) { + case GL_ALPHA_TEST: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; + break; + + case GL_BLEND: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_ALPHA; + + if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) + fxMesa->Fallback |= TDFX_FALLBACK_LOGICOP; + else + fxMesa->Fallback &= ~TDFX_FALLBACK_LOGICOP; + break; + + case GL_CULL_FACE: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_CULL; + break; + + case GL_DEPTH_TEST: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_DEPTH; + break; + + case GL_DITHER: + FLUSH_BATCH( fxMesa ); + if ( state ) { + fxMesa->Color.Dither = GR_DITHER_2x2; + } else { + fxMesa->Color.Dither = GR_DITHER_DISABLE; + } + fxMesa->dirty |= TDFX_UPLOAD_DITHER; + break; + + case GL_FOG: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_FOG; + break; + + case GL_COLOR_LOGIC_OP: + FLUSH_BATCH( fxMesa ); + if ( state && ctx->Color.LogicOp != GL_COPY ) { + fxMesa->Fallback |= TDFX_FALLBACK_LOGICOP; + } else { + fxMesa->Fallback &= ~TDFX_FALLBACK_LOGICOP; + } + break; + + case GL_LINE_SMOOTH: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_LINE; + break; + + case GL_POLYGON_STIPPLE: + FLUSH_BATCH(fxMesa); + fxMesa->new_state |= TDFX_NEW_STIPPLE; + break; + + case GL_SCISSOR_TEST: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_CLIP; + break; + + case GL_STENCIL_TEST: + FLUSH_BATCH( fxMesa ); + if (fxMesa->haveHwStencil) + fxMesa->new_state |= TDFX_NEW_STENCIL; + else if (state) + fxMesa->Fallback |= TDFX_FALLBACK_STENCIL; + else + fxMesa->Fallback &= ~TDFX_FALLBACK_STENCIL; + break; + + case GL_TEXTURE_1D: + case GL_TEXTURE_3D: + if (state) + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE; + else + fxMesa->Fallback &= ~TDFX_FALLBACK_TEXTURE; + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + case GL_TEXTURE_2D: + FLUSH_BATCH( fxMesa ); + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + default: + return; + } +} + + + +/* Set the buffer used for drawing */ +/* XXX support for separate read/draw buffers hasn't been tested */ +static GLboolean tdfxDDSetDrawBuffer( GLcontext *ctx, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + FLUSH_BATCH( fxMesa ); + + fxMesa->Fallback &= ~TDFX_FALLBACK_BUFFER; + + switch ( mode ) { + case GL_FRONT_LEFT: + fxMesa->DrawBuffer = GR_BUFFER_FRONTBUFFER; + fxMesa->new_state |= TDFX_NEW_RENDER; + return GL_TRUE; + + case GL_BACK_LEFT: + fxMesa->DrawBuffer = GR_BUFFER_BACKBUFFER; + fxMesa->new_state |= TDFX_NEW_RENDER; + return GL_TRUE; + + case GL_NONE: + FX_grColorMaskv( ctx, false4 ); + return GL_TRUE; + + default: + fxMesa->Fallback |= TDFX_FALLBACK_BUFFER; + return GL_FALSE; + } +} + + +/* Set the buffer used for reading */ +/* XXX support for separate read/draw buffers hasn't been tested */ +static void tdfxDDSetReadBuffer( GLcontext *ctx, + GLframebuffer *buffer, GLenum mode ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + (void) buffer; + + FLUSH_BATCH( fxMesa ); + + fxMesa->Fallback &= ~TDFX_FALLBACK_BUFFER; + + switch ( mode ) { + case GL_FRONT_LEFT: + fxMesa->ReadBuffer = GR_BUFFER_FRONTBUFFER; + break; + + case GL_BACK_LEFT: + fxMesa->ReadBuffer = GR_BUFFER_BACKBUFFER; + break; + + default: + fxMesa->Fallback |= TDFX_FALLBACK_BUFFER; + break; + } +} + +/* ============================================================= + * Polygon stipple + */ + +static void tdfxDDPolygonStipple( GLcontext *ctx, const GLubyte *mask ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + const GLubyte *m = mask; + GLubyte q[4]; + int i,j,k; + int active = (ctx->Polygon.StippleFlag && ctx->PB->primitive == GL_POLYGON); + + FLUSH_BATCH(fxMesa); + + if (active) { + ctx->Driver.TriangleCaps |= DD_TRI_STIPPLE; + } + + q[0] = mask[0]; + q[1] = mask[4]; + q[2] = mask[8]; + q[3] = mask[12]; + + for (k = 0 ; k < 8 ; k++) + for (j = 0 ; j < 4; j++) + for (i = 0 ; i < 4 ; i++,m++) { + if (*m != q[j]) { + ctx->Driver.TriangleCaps &= ~DD_TRI_STIPPLE; + fxMesa->Stipple.Pattern = 0xffffffff; /* ensure all pixels on */ + return; + } + } + + /* We can do it, so flag an upload of the stipple pattern */ + fxMesa->Stipple.Pattern = ( (q[0] << 0) | + (q[1] << 8) | + (q[2] << 16) | + (q[3] << 24) ); + fxMesa->dirty |= TDFX_UPLOAD_STIPPLE; +} + +/* Always called between RenderStart and RenderFinish --> We already + * hold the lock. + */ +static void tdfxDDReducedPrimitiveChange( GLcontext *ctx, GLenum prim ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + + FLUSH_BATCH( fxMesa ); + + tdfxUpdateCull(ctx); + if ( fxMesa->dirty & TDFX_UPLOAD_CULL ) { + grCullMode( fxMesa->CullMode ); + fxMesa->dirty &= ~TDFX_UPLOAD_CULL; + } + + tdfxUpdateStipple(ctx); + if ( fxMesa->dirty & TDFX_UPLOAD_STIPPLE ) { + grStipplePattern ( fxMesa->Stipple.Pattern ); + grStippleMode ( fxMesa->Stipple.Mode ); + fxMesa->dirty &= ~TDFX_UPLOAD_STIPPLE; + } +} + + + +static void tdfxDDPrintState( const char *msg, GLuint flags ) +{ + fprintf( stderr, + "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s\n", + msg, + flags, + (flags & TDFX_NEW_COLOR) ? "color, " : "", + (flags & TDFX_NEW_ALPHA) ? "alpha, " : "", + (flags & TDFX_NEW_DEPTH) ? "depth, " : "", + (flags & TDFX_NEW_RENDER) ? "render, " : "", + (flags & TDFX_NEW_FOG) ? "fog, " : "", + (flags & TDFX_NEW_STENCIL) ? "stencil, " : "", + (flags & TDFX_NEW_STIPPLE) ? "stipple, " : "", + (flags & TDFX_NEW_CLIP) ? "clip, " : "", + (flags & TDFX_NEW_VIEWPORT) ? "viewport, " : "", + (flags & TDFX_NEW_CULL) ? "cull, " : "", + (flags & TDFX_NEW_GLIDE) ? "glide, " : "", + (flags & TDFX_NEW_TEXTURE) ? "texture, " : "", + (flags & TDFX_NEW_CONTEXT) ? "context, " : ""); +} + + + +void tdfxDDUpdateHwState( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + int new_state = fxMesa->new_state; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + if ( new_state ) + { + FLUSH_BATCH( fxMesa ); + + fxMesa->new_state = 0; + + if ( 0 ) + tdfxDDPrintState( "tdfxUpdateHwState", new_state ); + + /* Update the various parts of the context's state. + */ + if ( new_state & TDFX_NEW_ALPHA ) { + tdfxUpdateAlphaMode( ctx ); + } + + if ( new_state & TDFX_NEW_DEPTH ) + tdfxUpdateZMode( ctx ); + + if ( new_state & TDFX_NEW_FOG ) + tdfxUpdateFogAttrib( ctx ); + + if ( new_state & TDFX_NEW_CLIP ) + tdfxUpdateClipping( ctx ); + + if ( new_state & TDFX_NEW_STIPPLE ) + tdfxUpdateStipple( ctx ); + + if ( new_state & TDFX_NEW_CULL ) + tdfxUpdateCull( ctx ); + + if ( new_state & TDFX_NEW_LINE ) + tdfxUpdateLine( ctx ); + + if ( new_state & TDFX_NEW_VIEWPORT ) + tdfxUpdateViewport( ctx ); + + if ( new_state & TDFX_NEW_RENDER ) + tdfxUpdateRenderAttrib( ctx ); + + if ( new_state & TDFX_NEW_STENCIL ) + tdfxUpdateStencil( ctx ); + + if ( new_state & TDFX_NEW_TEXTURE ) { + tdfxUpdateTextureState( ctx ); + } + else if ( new_state & TDFX_NEW_TEXTURE_BIND ) { + tdfxUpdateTextureBinding( ctx ); + } + } + + if ( 0 ) { + FxI32 bias = (FxI32) (ctx->Polygon.OffsetUnits * TDFX_DEPTH_BIAS_SCALE); + + if ( fxMesa->Depth.Bias != bias ) { + fxMesa->Depth.Bias = bias; + fxMesa->dirty |= TDFX_UPLOAD_DEPTH_BIAS; + } + } + + if ( fxMesa->dirty ) { + LOCK_HARDWARE( fxMesa ); + tdfxEmitHwStateLocked( fxMesa ); + UNLOCK_HARDWARE( fxMesa ); + } +} + + +static void tdfxDDRenderStart( GLcontext *ctx ) +{ + tdfxDDUpdateHwState( ctx ); + LOCK_HARDWARE( TDFX_CONTEXT(ctx) ); +} + +static void tdfxDDRenderFinish( GLcontext *ctx ) +{ + UNLOCK_HARDWARE( TDFX_CONTEXT(ctx) ); +} + +#define INTERESTED (~(NEW_MODELVIEW | \ + NEW_PROJECTION | \ + NEW_TEXTURE_MATRIX | \ + NEW_USER_CLIP | \ + NEW_CLIENT_STATE | \ + NEW_TEXTURE_ENABLE)) + +static void tdfxDDUpdateState( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + fprintf( stderr, "%s()\n", __FUNCTION__ ); + } + + /* Have to do this here to detect texture, line fallbacks in time: + */ + if ( fxMesa->new_state & (TDFX_NEW_TEXTURE | TDFX_NEW_LINE) ) + tdfxDDUpdateHwState( ctx ); + + if ( ctx->NewState & INTERESTED ) { + tdfxDDChooseRenderState( ctx ); + } + + /* The choise of vertex setup function only depends on whether fog + * and/or texturing is enabled. + */ + if ( ctx->NewState & (NEW_FOG | NEW_TEXTURE_ENABLE | NEW_TEXTURING)) { + tdfxDDChooseRasterSetupFunc( ctx ); + } + + if ( 0 ) + fprintf( stderr, "fallback %x indirect %x\n", + fxMesa->Fallback, fxMesa->IndirectTriangles ); + + if ( fxMesa->Fallback ) { + ctx->IndirectTriangles |= ctx->TriangleCaps; + } + else { + ctx->IndirectTriangles &= ~DD_SW_RASTERIZE; + ctx->IndirectTriangles |= fxMesa->IndirectTriangles; + + ctx->Driver.PointsFunc = fxMesa->PointsFunc; + ctx->Driver.LineFunc = fxMesa->LineFunc; + ctx->Driver.TriangleFunc = fxMesa->TriangleFunc; + ctx->Driver.QuadFunc = fxMesa->QuadFunc; + ctx->Driver.RenderVBRawTab = fxMesa->RenderVBRawTab; + } +} + + + +/* Initialize the context's Glide state mirror. These values will be + * used as Glide function call parameters when the time comes. + */ +void tdfxInitState( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + GLint i; + + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->ColorCombine.Local = GR_COMBINE_LOCAL_ITERATED; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->ColorCombine.Invert = FXFALSE; + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->AlphaCombine.Local = GR_COMBINE_LOCAL_ITERATED; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->AlphaCombine.Invert = FXFALSE; + + fxMesa->ColorCombineExt.SourceA = GR_CMBX_ITRGB; + fxMesa->ColorCombineExt.ModeA = GR_FUNC_MODE_X; + fxMesa->ColorCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.ModeB = GR_FUNC_MODE_ZERO; + fxMesa->ColorCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertC = FXTRUE; + fxMesa->ColorCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertD = FXFALSE; + fxMesa->ColorCombineExt.Shift = 0; + fxMesa->ColorCombineExt.Invert = FXFALSE; + fxMesa->AlphaCombineExt.SourceA = GR_CMBX_ITALPHA; + fxMesa->AlphaCombineExt.ModeA = GR_FUNC_MODE_X; + fxMesa->AlphaCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.ModeB = GR_FUNC_MODE_ZERO; + fxMesa->AlphaCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertC = FXTRUE; + fxMesa->AlphaCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertD = FXFALSE; + fxMesa->AlphaCombineExt.Shift = 0; + fxMesa->AlphaCombineExt.Invert = FXFALSE; + + fxMesa->sScale0 = fxMesa->tScale0 = 1.0; + fxMesa->sScale1 = fxMesa->tScale1 = 1.0; + + fxMesa->TexPalette.Type = 0; + fxMesa->TexPalette.Data = NULL; + + for ( i = 0 ; i < TDFX_NUM_TMU ; i++ ) { + fxMesa->TexSource[i].StartAddress = 0; + fxMesa->TexSource[i].EvenOdd = GR_MIPMAPLEVELMASK_EVEN; + fxMesa->TexSource[i].Info = NULL; + + fxMesa->TexCombine[i].FunctionRGB = 0; + fxMesa->TexCombine[i].FactorRGB = 0; + fxMesa->TexCombine[i].FunctionAlpha = 0; + fxMesa->TexCombine[i].FactorAlpha = 0; + fxMesa->TexCombine[i].InvertRGB = FXFALSE; + fxMesa->TexCombine[i].InvertAlpha = FXFALSE; + + fxMesa->TexCombineExt[i].Alpha.SourceA = 0; + /* XXX more state to init here */ + fxMesa->TexCombineExt[i].Color.SourceA = 0; + fxMesa->TexCombineExt[i].EnvColor = 0x0; + + fxMesa->TexParams[i].sClamp = GR_TEXTURECLAMP_WRAP; + fxMesa->TexParams[i].tClamp = GR_TEXTURECLAMP_WRAP; + fxMesa->TexParams[i].minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + fxMesa->TexParams[i].magFilt = GR_TEXTUREFILTER_BILINEAR; + fxMesa->TexParams[i].mmMode = GR_MIPMAP_DISABLE; + fxMesa->TexParams[i].LODblend = FXFALSE; + fxMesa->TexParams[i].LodBias = 0.0; + + fxMesa->TexState.EnvMode[i] = ~0; + fxMesa->TexState.TexFormat[i] = ~0; + fxMesa->TexState.Enabled = 0; + } + + if ( ctx->Visual->DBflag) { + fxMesa->DrawBuffer = GR_BUFFER_BACKBUFFER; + fxMesa->ReadBuffer = GR_BUFFER_BACKBUFFER; + } else { + fxMesa->DrawBuffer = GR_BUFFER_FRONTBUFFER; + fxMesa->ReadBuffer = GR_BUFFER_FRONTBUFFER; + } + + fxMesa->Color.ClearColor = 0x00000000; + fxMesa->Color.ClearAlpha = 0x00; + fxMesa->Color.ColorMask[RCOMP] = FXTRUE; + fxMesa->Color.ColorMask[BCOMP] = FXTRUE; + fxMesa->Color.ColorMask[GCOMP] = FXTRUE; + fxMesa->Color.ColorMask[ACOMP] = FXTRUE; + fxMesa->Color.MonoColor = 0xffffffff; + + fxMesa->Color.AlphaFunc = GR_CMP_ALWAYS; + fxMesa->Color.AlphaRef = 0x00; + fxMesa->Color.BlendSrcRGB = GR_BLEND_ONE; + fxMesa->Color.BlendDstRGB = GR_BLEND_ZERO; + fxMesa->Color.BlendSrcA = GR_BLEND_ONE; + fxMesa->Color.BlendSrcA = GR_BLEND_ZERO; + + fxMesa->Color.Dither = GR_DITHER_2x2; + + if ( fxMesa->glVis->DepthBits > 0 ) { + fxMesa->Depth.Mode = GR_DEPTHBUFFER_ZBUFFER; + } else { + fxMesa->Depth.Mode = GR_DEPTHBUFFER_DISABLE; + } + fxMesa->Depth.Bias = 0; + fxMesa->Depth.Func = GR_CMP_LESS; + fxMesa->Depth.Clear = 0; /* computed later */ + fxMesa->Depth.Mask = FXTRUE; + + + fxMesa->Fog.Mode = GR_FOG_DISABLE; + fxMesa->Fog.Color = 0x00000000; + fxMesa->Fog.Table = NULL; + fxMesa->Fog.Density = 1.0; + fxMesa->Fog.Near = 1.0; + fxMesa->Fog.Far = 1.0; + + fxMesa->Stencil.Function = GR_CMP_ALWAYS; + fxMesa->Stencil.RefValue = 0; + fxMesa->Stencil.ValueMask = 0xff; + fxMesa->Stencil.WriteMask = 0xff; + fxMesa->Stencil.FailFunc = 0; + fxMesa->Stencil.ZFailFunc = 0; + fxMesa->Stencil.ZPassFunc = 0; + fxMesa->Stencil.Clear = 0; + + fxMesa->Stipple.Mode = GR_STIPPLE_DISABLE; + fxMesa->Stipple.Pattern = 0xffffffff; + + fxMesa->Scissor.minX = 0; + fxMesa->Scissor.minY = 0; + fxMesa->Scissor.maxX = 0; + fxMesa->Scissor.maxY = 0; + + fxMesa->Viewport.Mode = GR_WINDOW_COORDS; + fxMesa->Viewport.X = 0; + fxMesa->Viewport.Y = 0; + fxMesa->Viewport.Width = 0; + fxMesa->Viewport.Height = 0; + fxMesa->Viewport.Near = 0.0; + fxMesa->Viewport.Far = 0.0; + + fxMesa->CullMode = GR_CULL_DISABLE; + + fxMesa->Glide.ColorFormat = GR_COLORFORMAT_ABGR; + fxMesa->Glide.Origin = GR_ORIGIN_LOWER_LEFT; + fxMesa->Glide.Initialized = FXFALSE; +} + + + +void tdfxDDInitStateFuncs( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + ctx->Driver.UpdateState = tdfxDDUpdateState; + + ctx->Driver.ClearIndex = NULL; + ctx->Driver.ClearColor = tdfxDDClearColor; + ctx->Driver.Index = NULL; + ctx->Driver.Color = tdfxDDColor; + ctx->Driver.SetDrawBuffer = tdfxDDSetDrawBuffer; + ctx->Driver.SetReadBuffer = tdfxDDSetReadBuffer; + + ctx->Driver.IndexMask = NULL; + ctx->Driver.ColorMask = tdfxDDColorMask; + + ctx->Driver.NearFar = tdfxDDNearFar; + + ctx->Driver.RenderStart = tdfxDDRenderStart; + ctx->Driver.RenderFinish = tdfxDDRenderFinish; + ctx->Driver.RasterSetup = NULL; + + ctx->Driver.RenderVBClippedTab = NULL; + ctx->Driver.RenderVBCulledTab = NULL; + ctx->Driver.RenderVBRawTab = NULL; + + ctx->Driver.ReducedPrimitiveChange = tdfxDDReducedPrimitiveChange; + ctx->Driver.MultipassFunc = NULL; + + ctx->Driver.AlphaFunc = tdfxDDAlphaFunc; + ctx->Driver.BlendEquation = tdfxDDBlendEquation; + ctx->Driver.BlendFunc = tdfxDDBlendFunc; + ctx->Driver.BlendFuncSeparate = tdfxDDBlendFuncSeparate; + ctx->Driver.ClearDepth = tdfxDDClearDepth; + ctx->Driver.ClearStencil = NULL; + ctx->Driver.CullFace = tdfxDDCullFace; + ctx->Driver.FrontFace = tdfxDDFrontFace; + ctx->Driver.DepthFunc = tdfxDDDepthFunc; + ctx->Driver.DepthMask = tdfxDDDepthMask; + ctx->Driver.DepthRange = NULL; + ctx->Driver.Enable = tdfxDDEnable; + ctx->Driver.Fogfv = tdfxDDFogfv; + ctx->Driver.Hint = NULL; + ctx->Driver.Lightfv = NULL; + ctx->Driver.LightModelfv = tdfxDDLightModelfv; + ctx->Driver.LineStipple = NULL; + ctx->Driver.LineWidth = tdfxDDLineWidth; + ctx->Driver.LogicOpcode = tdfxDDLogicOp; +#if 0 + ctx->Driver.PolygonMode = NULL; +#endif + ctx->Driver.PolygonStipple = tdfxDDPolygonStipple; + ctx->Driver.Scissor = tdfxDDScissor; + ctx->Driver.ShadeModel = tdfxDDShadeModel; + + ctx->Driver.BindTexture = tdfxDDBindTexture; + ctx->Driver.DeleteTexture = tdfxDDDeleteTexture; + ctx->Driver.TexEnv = tdfxDDTexEnv; + ctx->Driver.TexParameter = tdfxDDTexParameter; + ctx->Driver.TexImage2D = tdfxDDTexImage2D; + ctx->Driver.TexSubImage2D = tdfxDDTexSubImage2D; + ctx->Driver.GetTexImage = tdfxDDGetTexImage; + ctx->Driver.UpdateTexturePalette = tdfxDDTexturePalette; + + if ( fxMesa->haveHwStencil ) { + ctx->Driver.StencilFunc = tdfxDDStencilFunc; + ctx->Driver.StencilMask = tdfxDDStencilMask; + ctx->Driver.StencilOp = tdfxDDStencilOp; + } else { + ctx->Driver.StencilFunc = NULL; + ctx->Driver.StencilMask = NULL; + ctx->Driver.StencilOp = NULL; + } + + ctx->Driver.Viewport = tdfxDDViewport; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.h new file mode 100644 index 000000000..735c858b4 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_state.h @@ -0,0 +1,55 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#ifndef __TDFX_STATE_H__ +#define __TDFX_STATE_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "context.h" +#include "tdfx_context.h" + +extern void tdfxDDInitStateFuncs( GLcontext *ctx ); + +extern void tdfxDDUpdateHwState( GLcontext *ctx ); + +extern void tdfxInitState( tdfxContextPtr fxMesa ); + +extern void tdfxUpdateClipping( GLcontext *ctx ); + +#endif +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c new file mode 100644 index 000000000..fbdf9a612 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c @@ -0,0 +1,1603 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "image.h" +#include "texutil.h" +#include "tdfx_context.h" +#include "tdfx_tex.h" +#include "tdfx_texman.h" + + + +static int +logbase2(int n) +{ + GLint i = 1; + GLint log2 = 0; + + if (n < 0) { + return -1; + } + + while (n > i) { + i *= 2; + log2++; + } + if (i != n) { + return -1; + } + else { + return log2; + } +} + + +/* + * Compute various texture image parameters. + * Input: w, h - source texture width and height + * Output: lodlevel - Glide lod level token for the larger texture dimension + * aspectratio - Glide aspect ratio token + * sscale - S scale factor used during triangle setup + * tscale - T scale factor used during triangle setup + * wscale - OpenGL -> Glide image width scale factor + * hscale - OpenGL -> Glide image height scale factor + * + * Sample results: + * w h lodlevel aspectRatio + * 128 128 GR_LOD_LOG2_128 (=7) GR_ASPECT_LOG2_1x1 (=0) + * 64 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x1 (=0) + * 64 32 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_2x1 (=1) + * 32 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x2 (=-1) + * 32 32 GR_LOD_LOG2_32 (=5) GR_ASPECT_LOG2_1x1 (=0) + */ +static void +tdfxTexGetInfo(const GLcontext *ctx, int w, int h, + GrLOD_t *lodlevel, GrAspectRatio_t *aspectratio, + float *sscale, float *tscale, + int *wscale, int *hscale) +{ + int logw, logh, ar, lod, ws, hs; + float s, t; + + ASSERT(w >= 1); + ASSERT(h >= 1); + + logw = logbase2(w); + logh = logbase2(h); + ar = logw - logh; /* aspect ratio = difference in log dimensions */ + + /* Hardware only allows a maximum aspect ratio of 8x1, so handle + |ar| > 3 by scaling the image and using an 8x1 aspect ratio */ + if (ar >= 0) { + ASSERT(width >= height); + lod = logw; + s = 256.0; + ws = 1; + if (ar <= GR_ASPECT_LOG2_8x1) { + t = 256 >> ar; + hs = 1; + } + else { + /* have to stretch image height */ + t = 32.0; + hs = 1 << (ar - 3); + } + } + else { + ASSERT(width < height); + lod = logh; + t = 256.0; + hs = 1; + if (ar >= GR_ASPECT_LOG2_1x8) { + s = 256 >> -ar; + ws = 1; + } + else { + /* have to stretch image width */ + s = 32.0; + ws = 1 << (-ar - 3); + } + } + + if (ar < GR_ASPECT_LOG2_1x8) + ar = GR_ASPECT_LOG2_1x8; + else if (ar > GR_ASPECT_LOG2_8x1) + ar = GR_ASPECT_LOG2_8x1; + + if (lodlevel) + *lodlevel = (GrLOD_t) lod; + if (aspectratio) + *aspectratio = (GrAspectRatio_t) ar; + if (sscale) + *sscale = s; + if (tscale) + *tscale = t; + if (wscale) + *wscale = ws; + if (hscale) + *hscale = hs; +} + + +/* + * We need to call this when a texture object's minification filter + * or texture image sizes change. + */ +static void RevalidateTexture(GLcontext *ctx, struct gl_texture_object *tObj) +{ + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + GLint minl, maxl; + + if (!ti) + return; + + minl = maxl = tObj->BaseLevel; + + if (tObj->Image[minl]) { + maxl = MIN2(tObj->MaxLevel, tObj->Image[minl]->MaxLog2); + + /* compute largeLodLog2, aspect ratio and texcoord scale factors */ + tdfxTexGetInfo(ctx, tObj->Image[minl]->Width, tObj->Image[minl]->Height, + &ti->info.largeLodLog2, + &ti->info.aspectRatioLog2, + &(ti->sScale), &(ti->tScale), NULL, NULL); + } + + if (tObj->Image[maxl] && (tObj->MinFilter != GL_NEAREST) && (tObj->MinFilter != GL_LINEAR)) { + /* mipmapping: need to compute smallLodLog2 */ + tdfxTexGetInfo(ctx, tObj->Image[maxl]->Width, + tObj->Image[maxl]->Height, + &ti->info.smallLodLog2, NULL, + NULL, NULL, NULL, NULL); + } + else { + /* not mipmapping: smallLodLog2 = largeLodLog2 */ + ti->info.smallLodLog2 = ti->info.largeLodLog2; + } + + ti->minLevel = minl; + ti->maxLevel = maxl; + ti->info.data = NULL; +} + + +static tdfxTexInfo * +fxAllocTexObjData(tdfxContextPtr fxMesa) +{ + tdfxTexInfo *ti; + int i; + + if (!(ti = CALLOC(sizeof(tdfxTexInfo)))) { + gl_problem(NULL, "tdfx driver: out of memory"); + return NULL; + } + + ti->isInTM = GL_FALSE; + + ti->whichTMU = TDFX_TMU_NONE; + + ti->tm[TDFX_TMU0] = NULL; + ti->tm[TDFX_TMU1] = NULL; + + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->magFilt = GR_TEXTUREFILTER_BILINEAR; + + ti->sClamp = GR_TEXTURECLAMP_WRAP; + ti->tClamp = GR_TEXTURECLAMP_WRAP; + + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXFALSE; + + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + ti->mipmapLevel[i].data = NULL; + } + + return ti; +} + + +/* + * Called via glBindTexture. + */ + +void +tdfxDDBindTexture(GLcontext * ctx, GLenum target, + struct gl_texture_object *tObj) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTexInfo *ti; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexBind(%d,%p)\n", tObj->Name, + tObj->DriverData); + } + + if (target != GL_TEXTURE_2D) + return; + + if (!tObj->DriverData) { + tObj->DriverData = fxAllocTexObjData(fxMesa); + } + + ti = TDFX_TEXTURE_DATA(tObj); + ti->lastTimeUsed = fxMesa->texBindNumber++; + + fxMesa->new_state |= TDFX_NEW_TEXTURE; +} + + +/* + * Called via glTexEnv. + */ +void +tdfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, + const GLfloat * param) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) { + if (param) + fprintf(stderr, "fxmesa: texenv(%x,%x)\n", pname, + (GLint) (*param)); + else + fprintf(stderr, "fxmesa: texenv(%x)\n", pname); + } + + fxMesa->new_state |= TDFX_NEW_TEXTURE; +} + + +/* + * Called via glTexParameter. + */ +void +tdfxDDTexParameter(GLcontext * ctx, GLenum target, + struct gl_texture_object *tObj, + GLenum pname, const GLfloat * params) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GLenum param = (GLenum) (GLint) params[0]; + tdfxTexInfo *ti; + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDTexParam(%d,%p,%x,%x)\n", tObj->Name, + tObj->DriverData, pname, param); + } + + if (target != GL_TEXTURE_2D) + return; + + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = TDFX_TEXTURE_DATA(tObj); + + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + switch (param) { + case GL_NEAREST: + ti->mmMode = GR_MIPMAP_DISABLE; + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->LODblend = FXFALSE; + break; + case GL_LINEAR: + ti->mmMode = GR_MIPMAP_DISABLE; + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + ti->LODblend = FXFALSE; + break; + case GL_NEAREST_MIPMAP_LINEAR: + if (TDFX_IS_NAPALM(fxMesa)) { + if (fxMesa->haveTwoTMUs) { + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXTRUE; + } + else { + ti->mmMode = GR_MIPMAP_NEAREST_DITHER; + ti->LODblend = FXFALSE; + } + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + break; + } + /* XXX Voodoo3/Banshee mipmap blending seems to produce + * incorrectly filtered colors for the smallest mipmap levels. + * To work-around we fall-through here and use a different filter. + */ + case GL_NEAREST_MIPMAP_NEAREST: + ti->mmMode = GR_MIPMAP_NEAREST; + ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + ti->LODblend = FXFALSE; + break; + case GL_LINEAR_MIPMAP_LINEAR: + if (TDFX_IS_NAPALM(fxMesa)) { + if (fxMesa->haveTwoTMUs) { + ti->mmMode = GR_MIPMAP_NEAREST; + ti->LODblend = FXTRUE; + } + else { + ti->mmMode = GR_MIPMAP_NEAREST_DITHER; + ti->LODblend = FXFALSE; + } + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + break; + } + /* XXX Voodoo3/Banshee mipmap blending seems to produce + * incorrectly filtered colors for the smallest mipmap levels. + * To work-around we fall-through here and use a different filter. + */ + case GL_LINEAR_MIPMAP_NEAREST: + ti->mmMode = GR_MIPMAP_NEAREST; + ti->minFilt = GR_TEXTUREFILTER_BILINEAR; + ti->LODblend = FXFALSE; + break; + default: + break; + } + RevalidateTexture(ctx, tObj); + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + case GL_TEXTURE_MAG_FILTER: + switch (param) { + case GL_NEAREST: + ti->magFilt = GR_TEXTUREFILTER_POINT_SAMPLED; + break; + case GL_LINEAR: + ti->magFilt = GR_TEXTUREFILTER_BILINEAR; + break; + default: + break; + } + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + case GL_TEXTURE_WRAP_S: + switch (param) { + case GL_CLAMP: + ti->sClamp = GR_TEXTURECLAMP_CLAMP; + break; + case GL_REPEAT: + ti->sClamp = GR_TEXTURECLAMP_WRAP; + break; + default: + break; + } + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + case GL_TEXTURE_WRAP_T: + switch (param) { + case GL_CLAMP: + ti->tClamp = GR_TEXTURECLAMP_CLAMP; + break; + case GL_REPEAT: + ti->tClamp = GR_TEXTURECLAMP_WRAP; + break; + default: + break; + } + fxMesa->new_state |= TDFX_NEW_TEXTURE; + break; + + case GL_TEXTURE_BORDER_COLOR: + /* TO DO */ + break; + case GL_TEXTURE_MIN_LOD: + /* TO DO */ + break; + case GL_TEXTURE_MAX_LOD: + /* TO DO */ + break; + case GL_TEXTURE_BASE_LEVEL: + RevalidateTexture(ctx, tObj); + break; + case GL_TEXTURE_MAX_LEVEL: + RevalidateTexture(ctx, tObj); + break; + + default: + break; + } +} + + +/* + * Called via glDeleteTextures to delete a texture object. + * Here, we delete the Glide data associated with the texture. + */ +void +tdfxDDDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTMFreeTexture(fxMesa, tObj); + fxMesa->new_state |= TDFX_NEW_TEXTURE; +} + + +/* + * Return true if texture is resident, false otherwise. + */ +GLboolean +tdfxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj) +{ + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + return (GLboolean) (ti && ti->isInTM); +} + + + +/* + * Convert a gl_color_table texture palette to Glide's format. + */ +static void +convertPalette(FxU32 data[256], const struct gl_color_table *table) +{ + const GLubyte *tableUB = (const GLubyte *) table->Table; + GLint width = table->Size; + FxU32 r, g, b, a; + GLint i; + + ASSERT(table->TableType == GL_UNSIGNED_BYTE); + + 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; + } +} + + + +void +tdfxDDTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + + if (tObj) { + /* per-texture palette */ + tdfxTexInfo *ti; + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + ti = TDFX_TEXTURE_DATA(tObj); + convertPalette(ti->palette.data, &tObj->Palette); + /*tdfxTexInvalidate(ctx, tObj);*/ + } + else { + /* global texture palette */ + convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette); + } + fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX too heavy-handed */ +} + + +/* + * Given an OpenGL internal texture format, return the corresponding + * Glide internal texture format and MesaIntTexFormat. + * If allow32bpp is true, we'll return 32-bit texel formats when + * appropriate. + */ +static void +tdfxTexGetFormat(GLenum intFormatHint, GLboolean allow32bpp, + GrTextureFormat_t *glideFormat, + MesaIntTexFormat *mesaFormat, + GLint *texelSize) +{ + switch (intFormatHint) { + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + if (glideFormat) + *glideFormat = GR_TEXFMT_INTENSITY_8; + if (mesaFormat) + *mesaFormat = MESA_L8; + if (texelSize) + *texelSize = 1; + break; + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_INTENSITY_88; + if (mesaFormat) + *mesaFormat = MESA_A8_L8; + if (texelSize) + *texelSize = 2; + break; + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_8; + if (mesaFormat) + *mesaFormat = MESA_I8; + if (texelSize) + *texelSize = 1; + break; + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + if (glideFormat) + *glideFormat = GR_TEXFMT_ALPHA_8; + if (mesaFormat) + *mesaFormat = MESA_A8; + if (texelSize) + *texelSize = 1; + break; + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + if (glideFormat) + *glideFormat = GR_TEXFMT_RGB_565; + if (mesaFormat) + *mesaFormat = MESA_R5_G6_B5; + if (texelSize) + *texelSize = 2; + break; + case 3: + case GL_RGB: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + if (allow32bpp) { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_8888; + if (mesaFormat) + *mesaFormat = MESA_FF_R8_G8_B8; + if (texelSize) + *texelSize = 4; + } + else { + if (glideFormat) + *glideFormat = GR_TEXFMT_RGB_565; + if (mesaFormat) + *mesaFormat = MESA_R5_G6_B5; + if (texelSize) + *texelSize = 2; + } + break; + case GL_RGBA2: + case GL_RGBA4: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_4444; + if (mesaFormat) + *mesaFormat = MESA_A4_R4_G4_B4; + if (texelSize) + *texelSize = 2; + break; + case 4: + case GL_RGBA: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + if (allow32bpp) { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_8888; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + } + else { + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_4444; + if (mesaFormat) + *mesaFormat = MESA_A4_R4_G4_B4; + if (texelSize) + *texelSize = 2; + } + break; + case GL_RGB5_A1: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_1555; + if (mesaFormat) + *mesaFormat = MESA_A1_R5_G5_B5; + if (texelSize) + *texelSize = 2; + break; + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + if (glideFormat) + *glideFormat = GR_TEXFMT_P_8; + if (mesaFormat) + *mesaFormat = MESA_C8; + if (texelSize) + *texelSize = 1; + break; + case GL_COMPRESSED_RGB_FXT1_3DFX: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_CMP_FXT1; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + break; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + if (glideFormat) + *glideFormat = GR_TEXFMT_ARGB_CMP_FXT1; + if (mesaFormat) + *mesaFormat = MESA_A8_R8_G8_B8; + if (texelSize) + *texelSize = 4; + break; + default: + fprintf(stderr, "bad texture format in fxTexGetFormat() %d", intFormatHint); + break; + } +} + + +/**********************************************************************/ +/**** NEW TEXTURE IMAGE FUNCTIONS ****/ +/**********************************************************************/ + +static FxBool TexusFatalError = FXFALSE; +static FxBool TexusError = FXFALSE; + +#define TX_DITHER_NONE 0x00000000 + +static void +fxTexusError(const char *string, FxBool fatal) +{ + gl_problem(NULL, string); + /* + * Just propagate the fatal value up. + */ + TexusError = FXTRUE; + TexusFatalError = fatal; +} + +GLboolean +tdfxDDTexImage2D(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) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + const GLboolean allow32bpt = 0 /*TDFX_IS_NAPALM(fxMesa)*/; + GrTextureFormat_t gldformat; + tdfxTexInfo *ti; + tdfxMipMapLevel *mml; + GLint dstWidth, dstHeight, wScale, hScale, texelSize, dstStride; + MesaIntTexFormat intFormat; + GLboolean isCompressedFormat; + GLint texsize; + void *uncompressedImage; + + /* + printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n", + texObj->Name, texImage->IntFormat, format, type, + texImage->Width, texImage->Height); + */ + + isCompressedFormat = texImage->IsCompressed; + if (target != GL_TEXTURE_2D || texImage->Border > 0) + return GL_FALSE; + + if (!texObj->DriverData) + texObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[level]; + + /* Determine the appropriate GL internal texel format, Mesa internal + * texel format, and texelSize (bytes) given the user's internal + * texture format hint. + */ + tdfxTexGetFormat(texImage->IntFormat, allow32bpt, + &gldformat, &intFormat, &texelSize); + + /* Determine width and height scale factors for texture. + * Remember, Glide is limited to 8:1 aspect ratios. + */ + tdfxTexGetInfo(ctx, + texImage->Width, texImage->Height, + NULL, /* lod level */ + NULL, /* aspect ratio */ + NULL, NULL, /* sscale, tscale */ + &wScale, &hScale); + dstWidth = texImage->Width * wScale; + dstHeight = texImage->Height * hScale; + if (isCompressedFormat) { + texsize = tdfxDDCompressedImageSize(ctx, + texImage->IntFormat, + 2, + texImage->Width, + texImage->Height, + 1); + } + else { + texsize = dstWidth * dstHeight * texelSize; + } + + /* + * If the image is not compressed, this doesn't + * matter, but it might as well have a sensible + * value, and it might save a failure later on. + */ + texImage->CompressedSize = texsize; + /* housekeeping */ + _mesa_set_teximage_component_sizes(intFormat, texImage); + + /* + * allocate new storage for texture image, if needed. + * This conditional wants to set uncompressedImage to + * point to the uncompressed image, and mml->data to + * the texture data. If the image is uncompressed, + * these are identical. If the image is not compressed, + * these are different. + */ + if (!mml->data || mml->glideFormat != gldformat || + mml->width != dstWidth || mml->height != dstHeight || + texsize != mml->dataSize ) { + if (mml->data) { + FREE(mml->data); + } + uncompressedImage + = (void *)MALLOC(dstWidth * dstHeight * texelSize); + if (!uncompressedImage) { + return GL_FALSE; + } + if (isCompressedFormat) { + mml->data = MALLOC(texsize); + if (!mml->data) { + FREE(uncompressedImage); + return GL_FALSE; + } + } else { + mml->data = uncompressedImage; + } + mml->texelSize = texelSize; + mml->glideFormat = gldformat; + mml->width = dstWidth; + mml->height = dstHeight; + mml->dataSize = texsize; + ti->info.format = gldformat; + tdfxTMMoveOutTM(fxMesa, texObj); + /*tdfxTexInvalidate(ctx, texObj);*/ + } + else { + /* + * Here we don't have to allocate anything, but we + * do have to point uncompressedImage to the uncompressed + * data. + */ + if (isCompressedFormat) { + uncompressedImage + = (void *)MALLOC(dstWidth * dstHeight * texelSize); + if (!uncompressedImage) { + return GL_FALSE; + } + } else { + uncompressedImage = mml->data; + } + } + + dstStride = dstWidth * texelSize; + + /* store the texture image into uncompressedImage */ + if (!_mesa_convert_teximage(intFormat, + dstWidth, dstHeight, + uncompressedImage, + dstStride, + texImage->Width, texImage->Height, + format, type, pixels, packing)) { + /*printf("convert failed\n");*/ + return GL_FALSE; /* not necessarily an error */ + } + + /* + * Now compress it if necessary. + */ + if (isCompressedFormat) { + TxErrorCallbackFnc_t oldErrorCallback; + (*txErrorSetCallbackProc)(fxTexusError, &oldErrorCallback); + (*txImgQuantizeProc)((char *)mml->data, + (char *)uncompressedImage, + texImage->Width, + texImage->Height, + gldformat, + TX_DITHER_NONE); + (*txErrorSetCallbackProc)(oldErrorCallback, NULL); + if (uncompressedImage != mml->data) { + /* + * We do not need this any more, errors or no. + */ + FREE(uncompressedImage); + } + TexusError = FXFALSE; + if (TexusFatalError) { + FREE(mml->data); + mml->data = NULL; + TexusFatalError = FXFALSE; + return GL_FALSE; + } + } + + + RevalidateTexture(ctx, texObj); + + ti->reloadImages = GL_TRUE; + fxMesa->new_state |= TDFX_NEW_TEXTURE; + + *retainInternalCopy = GL_FALSE; + return GL_TRUE; +} + + +GLboolean +tdfxDDTexSubImage2D(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) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTexInfo *ti; + GLint wscale, hscale, dstStride = 0; + tdfxMipMapLevel *mml; + GLboolean result; + void *uncompressedImage = (void *)0; + FxU32 uncompressedSize; + TxErrorCallbackFnc_t oldErrorCallback; + + if (target != GL_TEXTURE_2D) + return GL_FALSE; + + if (!texObj->DriverData) + return GL_FALSE; + + /* + printf("TexSubImage id=%d lvl=%d int=0x%x format=0x%x type=0x%x x=%d y=%d w=%d h=%d fullW=%d fullH=%d\n", + texObj->Name, level, + texImage->IntFormat, format, type, xoffset, yoffset, width, height, + texImage->Width, texImage->Height); + */ + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[level]; + + tdfxTexGetInfo(ctx, texImage->Width, texImage->Height, NULL, NULL, + NULL, NULL, &wscale, &hscale); + + /* + * Must have an existing texture image! + */ + assert(mml->data); + + switch (mml->glideFormat) { + case GR_TEXFMT_INTENSITY_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_I8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ALPHA_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_A8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_P_8: + dstStride = mml->width; + result = _mesa_convert_texsubimage(MESA_C8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A8_L8, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_RGB_565: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_R5_G6_B5, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ARGB_4444: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A4_R4_G4_B4, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + /* + * There are some special legality constraints for compressed + * textures. + */ + if ((xoffset != texImage->Border) + || (yoffset != texImage->Border)) { + gl_error( ctx, + GL_INVALID_OPERATION, + "glTexSubImage2D(offset)" ); + return GL_FALSE; + } + if ((width != texImage->Width) + || (height != texImage->Height)) { + gl_error( ctx, + GL_INVALID_VALUE, + "glTexSubImage2D(image size)" ); + return GL_FALSE; + } + /* + * The width and height have to be multiples of + * 8 and 4 respectively. + */ + width = (mml->width + 0x7) &~ 0x7; + height = (mml->height + 0x3) &~ 0x3; + /* + * A texel is 8888 for this format. + */ + uncompressedSize = mml->width * mml->height * 4; + uncompressedImage = (void *)MALLOC(uncompressedSize); + /* + * Convert the data. + */ + dstStride = mml->width * 4; + result = _mesa_convert_texsubimage(MESA_A8_R8_G8_B8, xoffset, yoffset, + mml->width, mml->height, uncompressedImage, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + if (!result) { + FREE(uncompressedImage); + printf("TexSubImage convert failed\n"); + return GL_FALSE; + } + /* + * Now that we have converted the data, then compress it. + */ + (*txErrorSetCallbackProc)(fxTexusError, &oldErrorCallback); + (*txImgQuantizeProc)((char *)mml->data, + (char *)uncompressedImage, + mml->width, + mml->height, + mml->glideFormat, + TX_DITHER_NONE); + (*txErrorSetCallbackProc)(oldErrorCallback, NULL); + result = TexusFatalError; + TexusFatalError = TexusError = FXFALSE; + /* + * We don't need this any more. + */ + FREE(uncompressedImage); + break; + case GR_TEXFMT_ARGB_8888: + { + MesaIntTexFormat intFormat; + if (texImage->Format == GL_RGB) { + /* An RGB image padded out to 4 bytes/texel */ + intFormat = MESA_FF_R8_G8_B8; + } + else { + intFormat = MESA_A8_R8_G8_B8; + } + dstStride = mml->width * 4; + result = _mesa_convert_texsubimage(intFormat, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + } + break; + case GR_TEXFMT_ARGB_1555: + dstStride = mml->width * 2; + result = _mesa_convert_texsubimage(MESA_A1_R5_G5_B5, xoffset, yoffset, + mml->width, mml->height, mml->data, + dstStride, width, height, + texImage->Width, texImage->Height, + format, type, pixels, packing); + break; + default: + gl_problem(NULL, "tdfx driver: fxTexBuildSubImageMap() bad format"); + result = GL_FALSE; + } + + if (!result) { + return GL_FALSE; + } + + ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */ + fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX this might be a bit much */ + + return GL_TRUE; +} + + +/**********************************************************************/ +/**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/ +/**********************************************************************/ + +GLboolean +tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, + GLint level, GLsizei imageSize, + const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean *retainInternalCopy) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + const GLboolean allow32bpt = TDFX_IS_NAPALM(fxMesa); + GrTextureFormat_t gldformat; + tdfxTexInfo *ti; + tdfxMipMapLevel *mml; + GLint dstWidth, dstHeight, wScale, hScale, texelSize; + MesaIntTexFormat intFormat; + GLboolean isCompressedFormat; + GLsizei texsize; + + if (target != GL_TEXTURE_2D || texImage->Border > 0) + return GL_FALSE; + + if (!texObj->DriverData) + texObj->DriverData = fxAllocTexObjData(fxMesa); + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[level]; + + isCompressedFormat = tdfxDDIsCompressedGlideFormatMacro(texImage->IntFormat); + if (!isCompressedFormat) { + gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(format)" ); + return GL_FALSE; + } + /* Determine the apporpriate GL internal texel format, Mesa internal + * texel format, and texelSize (bytes) given the user's internal + * texture format hint. + */ + tdfxTexGetFormat(texImage->IntFormat, allow32bpt, + &gldformat, &intFormat, &texelSize); + + /* Determine width and height scale factors for texture. + * Remember, Glide is limited to 8:1 aspect ratios. + */ + tdfxTexGetInfo(ctx, + texImage->Width, texImage->Height, + NULL, /* lod level */ + NULL, /* aspect ratio */ + NULL, NULL, /* sscale, tscale */ + &wScale, &hScale); + dstWidth = texImage->Width * wScale; + dstHeight = texImage->Height * hScale; + /* housekeeping */ + _mesa_set_teximage_component_sizes(intFormat, texImage); + + texsize = tdfxDDCompressedImageSize(ctx, + texImage->IntFormat, + 2, + texImage->Width, + texImage->Height, + 1); + if (texsize != imageSize) { + gl_error(ctx, + GL_INVALID_VALUE, + "glCompressedTexImage2D(texsize)"); + return GL_FALSE; + } + + /* allocate new storage for texture image, if needed */ + if (!mml->data || mml->glideFormat != gldformat || + mml->width != dstWidth || mml->height != dstHeight || + texsize != mml->dataSize) { + if (mml->data) { + FREE(mml->data); + } + mml->data = MALLOC(texsize); + if (!mml->data) { + return GL_FALSE; + } + mml->texelSize = texelSize; + mml->glideFormat = gldformat; + mml->width = dstWidth; + mml->height = dstHeight; + tdfxTMMoveOutTM(fxMesa, texObj); + /*tdfxTexInvalidate(ctx, texObj);*/ + } + + /* save the texture data */ + MEMCPY(mml->data, data, imageSize); + + RevalidateTexture(ctx, texObj); + + ti->reloadImages = GL_TRUE; + fxMesa->new_state |= TDFX_NEW_TEXTURE; + + *retainInternalCopy = GL_FALSE; + return GL_TRUE; +} + +GLboolean +tdfxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, + GLint level, GLint xoffset, + GLint yoffset, GLsizei width, + GLint height, GLenum format, + GLsizei imageSize, const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTexInfo *ti; + tdfxMipMapLevel *mml; + + /* + * We punt if we are not replacing the entire image. This + * is allowed by the spec. + */ + if ((xoffset != 0) && (yoffset != 0) + && (width != texImage->Width) + && (height != texImage->Height)) { + return GL_FALSE; + } + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[level]; + if (imageSize != mml->dataSize) { + return GL_FALSE; + } + MEMCPY(data, mml->data, imageSize); + + ti->reloadImages = GL_TRUE; + fxMesa->new_state |= TDFX_NEW_TEXTURE; + + return GL_TRUE; +} + + +#if 0 +static void +PrintTexture(int w, int h, int c, const GLubyte * data) +{ + int i, j; + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + if (c == 2) + printf("%02x %02x ", data[0], data[1]); + else if (c == 3) + printf("%02x %02x %02x ", data[0], data[1], data[2]); + data += c; + } + printf("\n"); + } +} +#endif + + +GLboolean +tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, + GLint level, GLint internalFormat, + GLenum format, GLenum type, + GLint width, GLint height, + GLint depth, GLint border) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + + switch (target) { + case GL_PROXY_TEXTURE_1D: + return GL_TRUE; /* software rendering */ + case GL_PROXY_TEXTURE_2D: + { + struct gl_texture_object *tObj; + tdfxTexInfo *ti; + int memNeeded; + + tObj = ctx->Texture.Proxy2D; + if (!tObj->DriverData) + tObj->DriverData = fxAllocTexObjData(fxMesa); + ti = TDFX_TEXTURE_DATA(tObj); + + /* assign the parameters to test against */ + tObj->Image[level]->Width = width; + tObj->Image[level]->Height = height; + tObj->Image[level]->Border = border; + tObj->Image[level]->IntFormat = internalFormat; + if (level == 0) { + /* don't use mipmap levels > 0 */ + tObj->MinFilter = tObj->MagFilter = GL_NEAREST; + } + else { + /* test with all mipmap levels */ + tObj->MinFilter = GL_LINEAR_MIPMAP_LINEAR; + tObj->MagFilter = GL_NEAREST; + } + RevalidateTexture(ctx, tObj); + + /* + printf("small lodlog2 0x%x\n", ti->info.smallLodLog2); + printf("large lodlog2 0x%x\n", ti->info.largeLodLog2); + printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2); + printf("glide format 0x%x\n", ti->info.format); + printf("data %p\n", ti->info.data); + printf("lodblend %d\n", (int) ti->LODblend); + */ + + /* determine where texture will reside */ + if (ti->LODblend && !shared->umaTexMemory) { + /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */ + memNeeded = FX_grTexTextureMemRequired_NoLock( + GR_MIPMAPLEVELMASK_BOTH, &(ti->info)); + } + else { + /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */ + memNeeded = FX_grTexTextureMemRequired_NoLock( + GR_MIPMAPLEVELMASK_BOTH, &(ti->info)); + } + /* + printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]); + */ + if (memNeeded > shared->totalTexMem[0]) + return GL_FALSE; + else + return GL_TRUE; + } + case GL_PROXY_TEXTURE_3D: + return GL_TRUE; /* software rendering */ + default: + return GL_TRUE; /* never happens, silence compiler */ + } +} + + +/* + * Return a texture image to Mesa. This is either to satisfy + * a glGetTexImage() call or to prepare for software texturing. + */ +GLvoid * +tdfxDDGetTexImage(GLcontext * ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum * formatOut, GLenum * typeOut, + GLboolean * freeImageOut) +{ + tdfxTexInfo *ti; + tdfxMipMapLevel *mml; + + if (target != GL_TEXTURE_2D) + return NULL; + + if (!texObj->DriverData) + return NULL; + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[level]; + if (mml->data) { + MesaIntTexFormat mesaFormat; + GLenum glFormat; + struct gl_texture_image *texImage = texObj->Image[level]; + GLint srcStride; + void *uncompressedImage = NULL; + + GLubyte *data = + (GLubyte *) MALLOC(texImage->Width * texImage->Height * 4); + if (!data) + return NULL; + + uncompressedImage = (void *)mml->data; + switch (mml->glideFormat) { + case GR_TEXFMT_INTENSITY_8: + mesaFormat = MESA_I8; + glFormat = GL_INTENSITY; + srcStride = mml->width; + break; + case GR_TEXFMT_ALPHA_INTENSITY_88: + mesaFormat = MESA_A8_L8; + glFormat = GL_LUMINANCE_ALPHA; + srcStride = mml->width; + break; + case GR_TEXFMT_ALPHA_8: + if (texImage->Format == GL_INTENSITY) { + mesaFormat = MESA_I8; + glFormat = GL_INTENSITY; + } + else { + mesaFormat = MESA_A8; + glFormat = GL_ALPHA; + } + srcStride = mml->width; + break; + case GR_TEXFMT_RGB_565: + mesaFormat = MESA_R5_G6_B5; + glFormat = GL_RGB; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_ARGB_8888: + mesaFormat = MESA_A8_R8_G8_B8; + glFormat = GL_RGBA; + srcStride = mml->width * 4; + break; + case GR_TEXFMT_ARGB_4444: + mesaFormat = MESA_A4_R4_G4_B4; + glFormat = GL_RGBA; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_ARGB_1555: + mesaFormat = MESA_A1_R5_G5_B5; + glFormat = GL_RGBA; + srcStride = mml->width * 2; + break; + case GR_TEXFMT_P_8: + mesaFormat = MESA_C8; + glFormat = GL_COLOR_INDEX; + srcStride = mml->width; + break; + case GR_TEXFMT_ARGB_CMP_FXT1: + mesaFormat = MESA_A8_R8_G8_B8; + glFormat = GL_RGBA; + srcStride = mml->width * 4; + /* + * Allocate data for the uncompressed image, + * decompress the image. The data will be deallocated + * after it is converted to the mesa format. + */ + uncompressedImage = MALLOC(mml->width * mml->height * 4); + if (!uncompressedImage) { + gl_problem(NULL, "can't get memory in tdfxDDGetTexImage"); + return NULL; + } + (*txImgDequantizeFXT1Proc)((FxU32 *)uncompressedImage, + (FxU32 *)mml->data, + mml->width, + mml->height); + break; + default: + gl_problem(NULL, "Bad glideFormat in tdfxDDGetTexImage"); + return NULL; + } + _mesa_unconvert_teximage(mesaFormat, mml->width, mml->height, + uncompressedImage, srcStride, texImage->Width, + texImage->Height, glFormat, data); + if (uncompressedImage != mml->data) { + FREE(uncompressedImage); + } + *formatOut = glFormat; + *typeOut = GL_UNSIGNED_BYTE; + *freeImageOut = GL_TRUE; + return data; + } + else { + return NULL; + } +} + +/* + * This is called from _mesa_GetCompressedTexImage. We just + * copy out the compressed data. + */ +void +tdfxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, + GLint lod, void *image, + const struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) +{ + tdfxTexInfo *ti; + tdfxMipMapLevel *mml; + + if (target != GL_TEXTURE_2D) + return; + + if (!texObj->DriverData) + return; + + ti = TDFX_TEXTURE_DATA(texObj); + mml = &ti->mipmapLevel[lod]; + if (mml->data) { + MEMCPY(image, mml->data, mml->dataSize); + } +} + +/* + * Calculate a specific texture format given a generic + * texture format. + */ +GLint +tdfxDDSpecificCompressedTexFormat(GLcontext *ctx, + GLint internalFormat, + GLint numDimensions) +{ + if (numDimensions != 2) { + return internalFormat; + } + /* + * If we don't have pointers to the functions, then + * we drop back to uncompressed format. The logic + * in Mesa proper handles this for us. + * + * This is just to ease the transition to a Glide with + * the texus2 library. + */ + if (!txImgQuantizeProc || !txImgDequantizeFXT1Proc) { + return internalFormat; + } + switch (internalFormat) { + case GL_COMPRESSED_RGB_ARB: + return GL_COMPRESSED_RGB_FXT1_3DFX; + case GL_COMPRESSED_RGBA_ARB: + return GL_COMPRESSED_RGBA_FXT1_3DFX; + } + return internalFormat; +} + +/* + * Calculate a specific texture format given a generic + * texture format. + */ +GLint +tdfxDDBaseCompressedTexFormat(GLcontext *ctx, + GLint internalFormat) +{ + switch (internalFormat) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + return GL_RGB; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return GL_RGBA; + } + return -1; +} + +/* + * Tell us if an image is compressed. The real work is done + * in a macro, but we need to have a function to create a + * function pointer. + */ +GLboolean +tdfxDDIsCompressedFormat(GLcontext *ctx, GLint internalFormat) +{ + return tdfxDDIsCompressedFormatMacro(internalFormat); +} + + +/* + * Calculate the image size of a compressed texture. + * + * The current compressed format, the FXT1 family, all + * map 8x32 texel blocks into 128 bits. + * + * We return 0 if we can't calculate the size. + * + * Glide would report this out to us, but we don't have + * exactly the right parameters. + */ +GLsizei +tdfxDDCompressedImageSize(GLcontext *ctx, + GLenum intFormat, + GLuint numDimensions, + GLuint width, + GLuint height, + GLuint depth) +{ + if (numDimensions != 2) { + return 0; + } + switch (intFormat) { + case GL_COMPRESSED_RGB_FXT1_3DFX: + case GL_COMPRESSED_RGBA_FXT1_3DFX: + /* + * Round height and width to multiples of 4 and 8, + * divide the resulting product by 32 to get the number + * of blocks, and multiply by 32 = 128/8 to get the. + * number of bytes required. That is to say, just + * return the product. Remember that we are returning + * bytes, not texels, so we have shrunk the texture + * by a factor of the texel size. + */ + width = (width + 0x7) &~ 0x7; + height = (height + 0x3) &~ 0x3; + return width * height; + } + return 0; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.h new file mode 100644 index 000000000..95ef3b018 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.h @@ -0,0 +1,157 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#ifndef _TDFX_TEX_H_ +#define _TDFX_TEX_H_ + + +#include "texutil.h" + + +#define tdfxDDIsCompressedFormatMacro(internalFormat) \ + (((internalFormat) == GL_COMPRESSED_RGB_FXT1_3DFX) || \ + ((internalFormat) == GL_COMPRESSED_RGBA_FXT1_3DFX)) +#define tdfxDDIsCompressedGlideFormatMacro(internalFormat) \ + ((internalFormat) == GR_TEXFMT_ARGB_CMP_FXT1) + + + +extern void +tdfxTexValidate(GLcontext * ctx, struct gl_texture_object *tObj); + +extern void +tdfxDDBindTexture(GLcontext * ctx, GLenum target, + struct gl_texture_object *tObj); + +extern void +tdfxDDDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj); + +extern GLboolean +tdfxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj); + +extern void +tdfxDDTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj); + +#if 000 /* DEAD? */ +extern void +fxDDTexUseGlobalPalette(GLcontext * ctx, GLboolean state); +#endif + +extern void +tdfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname, + const GLfloat * param); + +extern void +tdfxDDTexParameter(GLcontext * ctx, GLenum target, + struct gl_texture_object *tObj, + GLenum pname, const GLfloat * params); + +extern GLboolean +tdfxDDTexImage2D(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 +tdfxDDTexSubImage2D(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 GLboolean +tdfxDDCompressedTexImage2D( GLcontext *ctx, GLenum target, + GLint level, GLsizei imageSize, + const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLboolean *retainInternalCopy); + +extern GLboolean +tdfxDDCompressedTexSubImage2D( GLcontext *ctx, GLenum target, + GLint level, GLint xoffset, + GLint yoffset, GLsizei width, + GLint height, GLenum format, + GLsizei imageSize, const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ); + +extern GLboolean +tdfxDDTestProxyTexImage(GLcontext *ctx, GLenum target, + GLint level, GLint internalFormat, + GLenum format, GLenum type, + GLint width, GLint height, + GLint depth, GLint border); + +extern GLvoid * +tdfxDDGetTexImage(GLcontext * ctx, GLenum target, GLint level, + const struct gl_texture_object *texObj, + GLenum * formatOut, GLenum * typeOut, + GLboolean * freeImageOut); + +extern void +tdfxDDGetCompressedTexImage( GLcontext *ctx, GLenum target, + GLint lod, void *image, + const struct gl_texture_object *texObj, + struct gl_texture_image *texImage ); + +extern GLint +tdfxDDSpecificCompressedTexFormat(GLcontext *ctx, + GLint internalFormat, + GLint numDimensions); + +extern GLint +tdfxDDBaseCompressedTexFormat(GLcontext *ctx, + GLint internalFormat); + +extern GLboolean +tdfxDDIsCompressedFormat(GLcontext *ctx, GLint internalFormat); + +extern GLsizei +tdfxDDCompressedImageSize(GLcontext *ctx, + GLenum intFormat, + GLuint numDimensions, + GLuint width, + GLuint height, + GLuint depth); + + +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c new file mode 100644 index 000000000..97fe9d4c6 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.c @@ -0,0 +1,968 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_tex.h" +#include "tdfx_texman.h" + + +#define BAD_ADDRESS ((FxU32) -1) + + +#if 0 /* DEBUG use */ +/* + * Verify the consistancy of the texture memory manager. + * This involves: + * Traversing all texture objects and computing total memory used. + * Traverse the free block list and computing total memory free. + * Compare the total free and total used amounts to the total memory size. + * Make various assertions about the results. + */ +static void +VerifyFreeList(tdfxContextPtr fxMesa, FxU32 tmu) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + tdfxMemRange *block; + int prevStart = -1, prevEnd = -1; + int totalFree = 0; + int numObj = 0, numRes = 0; + int totalUsed = 0; + + for (block = shared->tmFree[tmu]; block; block = block->next) { + assert( block->endAddr > 0 ); + assert( block->startAddr <= shared->totalTexMem[tmu] ); + assert( block->endAddr <= shared->totalTexMem[tmu] ); + assert( (int) block->startAddr > prevStart ); + assert( (int) block->startAddr >= prevEnd ); + prevStart = (int) block->startAddr; + prevEnd = (int) block->endAddr; + totalFree += (block->endAddr - block->startAddr); + } + assert(totalFree == shared->freeTexMem[tmu]); + + { + struct gl_texture_object *obj; + for (obj = mesaShared->TexObjectList; obj; obj = obj->Next) { + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(obj); + numObj++; + if (ti) { + if (ti->isInTM) { + numRes++; + assert(ti->tm[0]); + if (ti->tm[tmu]) + totalUsed += (ti->tm[tmu]->endAddr - ti->tm[tmu]->startAddr); + } + else { + assert(!ti->tm[0]); + } + } + } + } + + printf("totalFree: %d totalUsed: %d totalMem: %d #objs=%d #res=%d\n", + shared->freeTexMem[tmu], totalUsed, shared->totalTexMem[tmu], + numObj, numRes); + + assert(totalUsed + totalFree == shared->totalTexMem[tmu]); +} + + +static void +dump_texmem(tdfxContextPtr fxMesa) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + struct gl_texture_object *oldestObj, *obj, *lowestPriorityObj; + tdfxMemRange *r; + FxU32 prev; + + printf("DUMP Objects:\n"); + for (obj = mesaShared->TexObjectList; obj; obj = obj->Next) { + tdfxTexInfo *info = TDFX_TEXTURE_DATA(obj); + + if (info && info->isInTM) { + printf("Obj %8p: %4d info = %p\n", obj, obj->Name, info); + + printf(" isInTM=%d whichTMU=%d lastTimeUsed=%d\n", + info->isInTM, info->whichTMU, info->lastTimeUsed); + printf(" tm[0] = %p", info->tm[0]); + assert(info->tm[0]); + if (info->tm[0]) { + printf(" tm startAddr = %d endAddr = %d", + info->tm[0]->startAddr, + info->tm[0]->endAddr); + } + printf("\n"); + printf(" tm[1] = %p", info->tm[1]); + if (info->tm[1]) { + printf(" tm startAddr = %d endAddr = %d", + info->tm[1]->startAddr, + info->tm[1]->endAddr); + } + printf("\n"); + } + } + + VerifyFreeList(fxMesa, 0); + VerifyFreeList(fxMesa, 1); + + printf("Free memory unit 0: %d bytes\n", shared->freeTexMem[0]); + prev = 0; + for (r = shared->tmFree[0]; r; r = r->next) { + printf("%8p: start %8d end %8d size %8d gap %8d\n", r, r->startAddr, r->endAddr, r->endAddr - r->startAddr, r->startAddr - prev); + prev = r->endAddr; + } + + printf("Free memory unit 1: %d bytes\n", shared->freeTexMem[1]); + prev = 0; + for (r = shared->tmFree[1]; r; r = r->next) { + printf("%8p: start %8d end %8d size %8d gap %8d\n", r, r->startAddr, r->endAddr, r->endAddr - r->startAddr, r->startAddr - prev); + prev = r->endAddr; + } + +} +#endif + + + +#ifdef TEXSANITY +static void +fubar(void) +{ +} + +/* + * Sanity Check + */ +static void +sanity(tdfxContextPtr fxMesa) +{ + tdfxMemRange *tmp, *prev, *pos; + + prev = 0; + tmp = fxMesa->tmFree[0]; + while (tmp) { + if (!tmp->startAddr && !tmp->endAddr) { + fprintf(stderr, "Textures fubar\n"); + fubar(); + } + if (tmp->startAddr >= tmp->endAddr) { + fprintf(stderr, "Node fubar\n"); + fubar(); + } + if (prev && (prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr)) { + fprintf(stderr, "Sorting fubar\n"); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } + prev = 0; + tmp = fxMesa->tmFree[1]; + while (tmp) { + if (!tmp->startAddr && !tmp->endAddr) { + fprintf(stderr, "Textures fubar\n"); + fubar(); + } + if (tmp->startAddr >= tmp->endAddr) { + fprintf(stderr, "Node fubar\n"); + fubar(); + } + if (prev && (prev->startAddr >= tmp->startAddr || + prev->endAddr > tmp->startAddr)) { + fprintf(stderr, "Sorting fubar\n"); + fubar(); + } + prev = tmp; + tmp = tmp->next; + } +} +#endif + + + + + +/* + * Allocate and initialize a new MemRange struct. + * Try to allocate it from the pool of free MemRange nodes rather than malloc. + */ +static tdfxMemRange * +NewRangeNode(tdfxContextPtr fxMesa, FxU32 start, FxU32 end) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + tdfxMemRange *result; + + _glthread_LOCK_MUTEX(mesaShared->Mutex); + if (shared && shared->tmPool) { + result = shared->tmPool; + shared->tmPool = shared->tmPool->next; + } + else { + result = MALLOC(sizeof(tdfxMemRange)); + + } + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); + + if (!result) { + /*fprintf(stderr, "fxDriver: out of memory!\n");*/ + return NULL; + } + + result->startAddr = start; + result->endAddr = end; + result->next = NULL; + + return result; +} + + +/* + * Initialize texture memory. + * We take care of one or both TMU's here. + */ +void +tdfxTMInit(tdfxContextPtr fxMesa) +{ + if (!fxMesa->glCtx->Shared->DriverData) { + const char *extensions; + struct tdfxSharedState *shared = CALLOC_STRUCT(tdfxSharedState); + if (!shared) + return; + + extensions = FX_grGetString(fxMesa, GR_EXTENSION); + if (strstr(extensions, "TEXUMA")) { + FxU32 start, end; + shared->umaTexMemory = GL_TRUE; + FX_grEnable(fxMesa, GR_TEXTURE_UMA_EXT); + start = FX_grTexMinAddress(fxMesa, 0); + end = FX_grTexMaxAddress(fxMesa, 0); + shared->totalTexMem[0] = end - start; + shared->totalTexMem[1] = 0; + shared->freeTexMem[0] = end - start; + shared->freeTexMem[1] = 0; + shared->tmFree[0] = NewRangeNode(fxMesa, start, end); + shared->tmFree[1] = NULL; + /*printf("UMA tex memory: %d\n", (int) (end - start));*/ + } + else { + const int numTMUs = fxMesa->haveTwoTMUs ? 2 : 1; + int tmu; + shared->umaTexMemory = GL_FALSE; + for (tmu = 0; tmu < numTMUs; tmu++) { + FxU32 start = FX_grTexMinAddress(fxMesa, tmu); + FxU32 end = FX_grTexMaxAddress(fxMesa, tmu); + shared->totalTexMem[tmu] = end - start; + shared->freeTexMem[tmu] = end - start; + shared->tmFree[tmu] = NewRangeNode(fxMesa, start, end); + /*printf("Split tex memory: %d\n", (int) (end - start));*/ + } + } + + shared->tmPool = NULL; + fxMesa->glCtx->Shared->DriverData = shared; + /*printf("Texture memory init UMA: %d\n", shared->umaTexMemory);*/ + } +} + + +/* + * Clean-up texture memory before destroying context. + */ +void +tdfxTMClose(tdfxContextPtr fxMesa) +{ + if (fxMesa->glCtx->Shared->RefCount == 1) { + /* refcount will soon go to zero, free our 3dfx stuff */ + struct tdfxSharedState *shared = (struct tdfxSharedState *) fxMesa->glCtx->Shared->DriverData; + + const int numTMUs = fxMesa->haveTwoTMUs ? 2 : 1; + int tmu; + tdfxMemRange *tmp, *next; + + /* Deallocate the pool of free tdfxMemRange nodes */ + tmp = shared->tmPool; + while (tmp) { + next = tmp->next; + FREE(tmp); + tmp = next; + } + + /* Delete the texture memory block tdfxMemRange nodes */ + for (tmu = 0; tmu < numTMUs; tmu++) { + tmp = shared->tmFree[tmu]; + while (tmp) { + next = tmp->next; + FREE(tmp); + tmp = next; + } + } + + FREE(shared); + fxMesa->glCtx->Shared->DriverData = NULL; + } +} + + + +/* + * Delete a tdfxMemRange struct. + * We keep a linked list of free/available tdfxMemRange structs to + * avoid extra malloc/free calls. + */ +#if 0 +static void +DeleteRangeNode_NoLock(struct TdfxSharedState *shared, tdfxMemRange *range) +{ + /* insert at head of list */ + range->next = shared->tmPool; + shared->tmPool = range; +} +#endif + +#define DELETE_RANGE_NODE(shared, range) \ + (range)->next = (shared)->tmPool; \ + (shared)->tmPool = (range) + + + +/* + * When we've run out of texture memory we have to throw out an + * existing texture to make room for the new one. This function + * determins the texture to throw out. + */ +static struct gl_texture_object * +FindOldestObject(tdfxContextPtr fxMesa, FxU32 tmu) +{ + const GLuint bindnumber = fxMesa->texBindNumber; + struct gl_texture_object *oldestObj, *obj, *lowestPriorityObj; + GLfloat lowestPriority; + GLuint oldestAge; + + oldestObj = NULL; + oldestAge = 0; + + lowestPriority = 1.0F; + lowestPriorityObj = NULL; + + for (obj = fxMesa->glCtx->Shared->TexObjectList; obj; obj = obj->Next) { + tdfxTexInfo *info = TDFX_TEXTURE_DATA(obj); + + if (info && info->isInTM && + ((info->whichTMU == tmu) || (info->whichTMU == TDFX_TMU_BOTH) || + (info->whichTMU == TDFX_TMU_SPLIT))) { + GLuint age, lasttime; + + assert(info->tm[0]); + lasttime = info->lastTimeUsed; + + if (lasttime > bindnumber) + age = bindnumber + (UINT_MAX - lasttime + 1); /* TO DO: check wrap around */ + else + age = bindnumber - lasttime; + + if (age >= oldestAge) { + oldestAge = age; + oldestObj = obj; + } + + /* examine priority */ + if (obj->Priority < lowestPriority) { + lowestPriority = obj->Priority; + lowestPriorityObj = obj; + } + } + } + + if (lowestPriority < 1.0) { + ASSERT(lowestPriorityObj); + /* + printf("discard %d pri=%f\n", lowestPriorityObj->Name, lowestPriority); + */ + return lowestPriorityObj; + } + else { + /* + printf("discard %d age=%d\n", oldestObj->Name, oldestAge); + */ + return oldestObj; + } +} + + +#if 0 +static void +FlushTexMemory(tdfxContextPtr fxMesa) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + struct gl_texture_object *obj; + + for (obj = mesaShared->TexObjectList; obj; obj = obj->Next) { + if (obj->RefCount < 2) { + /* don't flush currently bound textures */ + tdfxTMMoveOutTM_NoLock(fxMesa, obj); + } + } +} +#endif + + +/* + * Find the address (offset?) at which we can store a new texture. + * <tmu> is the texture unit. + * <size> is the texture size in bytes. + */ +static FxU32 +FindStartAddr(tdfxContextPtr fxMesa, FxU32 tmu, FxU32 size) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + tdfxMemRange *prev, *block; + FxU32 result; +#if 0 + int discardedCount = 0; +#define MAX_DISCARDS 10 +#endif + + if (shared->umaTexMemory) { + assert(tmu == TDFX_TMU0); + } + + _glthread_LOCK_MUTEX(mesaShared->Mutex); + while (1) { + prev = NULL; + block = shared->tmFree[tmu]; + while (block) { + if (block->endAddr - block->startAddr >= size) { + /* The texture will fit here */ + result = block->startAddr; + block->startAddr += size; + if (block->startAddr == block->endAddr) { + /* Remove this node since it's empty */ + if (prev) { + prev->next = block->next; + } + else { + shared->tmFree[tmu] = block->next; + } + DELETE_RANGE_NODE(shared, block); + } + shared->freeTexMem[tmu] -= size; + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); + return result; + } + prev = block; + block = block->next; + } + /* We failed to find a block large enough to accomodate <size> bytes. + * Find the oldest texObject and free it. + */ +#if 0 + discardedCount++; + if (discardedCount > MAX_DISCARDS + 1) { + gl_problem(NULL, "tdfx driver: extreme texmem fragmentation"); + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); + return BAD_ADDRESS; + } + else if (discardedCount > MAX_DISCARDS) { + /* texture memory is probably really fragmented, flush it */ + FlushTexMemory(fxMesa); + } + else +#endif + { + struct gl_texture_object *obj = FindOldestObject(fxMesa, tmu); + if (obj) { + tdfxTMMoveOutTM_NoLock(fxMesa, obj); + fxMesa->stats.texSwaps++; + } + else { + gl_problem(NULL, "tdfx driver: extreme texmem fragmentation"); + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); + return BAD_ADDRESS; + } + } + } + + /* never get here, but play it safe */ + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); + return BAD_ADDRESS; +} + + +/* + * Remove the given tdfxMemRange node from hardware texture memory. + */ +static void +RemoveRange_NoLock(tdfxContextPtr fxMesa, FxU32 tmu, tdfxMemRange *range) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + tdfxMemRange *block, *prev; + + if (shared->umaTexMemory) { + assert(tmu == TDFX_TMU0); + } + + if (!range) + return; + + if (range->startAddr == range->endAddr) { + DELETE_RANGE_NODE(shared, range); + return; + } + shared->freeTexMem[tmu] += range->endAddr - range->startAddr; + + /* find position in linked list to insert this tdfxMemRange node */ + prev = NULL; + block = shared->tmFree[tmu]; + while (block) { + assert(range->startAddr != block->startAddr); + if (range->startAddr > block->startAddr) { + prev = block; + block = block->next; + } + else { + break; + } + } + + /* Insert the free block, combine with adjacent blocks when possible */ + range->next = block; + if (block) { + if (range->endAddr == block->startAddr) { + /* Combine */ + block->startAddr = range->startAddr; + DELETE_RANGE_NODE(shared, range); + range = block; + } + } + if (prev) { + if (prev->endAddr == range->startAddr) { + /* Combine */ + prev->endAddr = range->endAddr; + prev->next = range->next; + DELETE_RANGE_NODE(shared, range); + } + else { + prev->next = range; + } + } + else { + shared->tmFree[tmu] = range; + } +} + + +#if 0 /* NOT USED */ +static void +RemoveRange(tdfxContextPtr fxMesa, FxU32 tmu, tdfxMemRange *range) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + _glthread_LOCK_MUTEX(mesaShared->Mutex); + RemoveRange_NoLock(fxMesa, tmu, range); + _glthread_UNLOCK_MUTEX(mesaShared->Mutex); +} +#endif + + +/* + * Allocate space for a texture image. + * <tmu> is the texture unit + * <texmemsize> is the number of bytes to allocate + */ +static tdfxMemRange * +AllocTexMem(tdfxContextPtr fxMesa, FxU32 tmu, FxU32 texmemsize) +{ + FxU32 startAddr; + startAddr = FindStartAddr(fxMesa, tmu, texmemsize); + if (startAddr == BAD_ADDRESS) { + printf("AllocTexMem returned NULL! tmu=%d texmemsize=%d\n", + tmu, texmemsize); + return NULL; + } + else { + tdfxMemRange *range; + range = NewRangeNode(fxMesa, startAddr, startAddr + texmemsize); + return range; + } +} + + +/* + * Download (copy) the given texture data (all mipmap levels) into the + * Voodoo's texture memory. + * The texture memory must have already been allocated. + */ +void +tdfxTMDownloadTexture(tdfxContextPtr fxMesa, struct gl_texture_object *tObj) +{ + tdfxTexInfo *ti; + GLint l; + FxU32 targetTMU; + + assert(tObj); + ti = TDFX_TEXTURE_DATA(tObj); + assert(ti); + targetTMU = ti->whichTMU; + + switch (targetTMU) { + case TDFX_TMU0: + case TDFX_TMU1: + if (ti->tm[targetTMU]) { + for (l = ti->minLevel; l <= ti->maxLevel + && ti->mipmapLevel[l].data; l++) { + GrLOD_t glideLod = ti->info.largeLodLog2 - l + tObj->BaseLevel; + FX_grTexDownloadMipMapLevel_NoLock(targetTMU, + ti->tm[targetTMU]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + } + } + break; + case TDFX_TMU_SPLIT: + if (ti->tm[TDFX_TMU0] && ti->tm[TDFX_TMU1]) { + for (l = ti->minLevel; l <= ti->maxLevel + && ti->mipmapLevel[l].data; l++) { + GrLOD_t glideLod = ti->info.largeLodLog2 - l + tObj->BaseLevel; + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, + ti->tm[TDFX_TMU0]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_ODD, + ti->mipmapLevel[l].data); + + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, + ti->tm[TDFX_TMU1]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_EVEN, + ti->mipmapLevel[l].data); + } + } + break; + case TDFX_TMU_BOTH: + if (ti->tm[TDFX_TMU0] && ti->tm[TDFX_TMU1]) { + for (l = ti->minLevel; l <= ti->maxLevel + && ti->mipmapLevel[l].data; l++) { + GrLOD_t glideLod = ti->info.largeLodLog2 - l + tObj->BaseLevel; + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU0, + ti->tm[TDFX_TMU0]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + + FX_grTexDownloadMipMapLevel_NoLock(GR_TMU1, + ti->tm[TDFX_TMU1]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[l].data); + } + } + break; + default: + gl_problem(NULL, "error in tdfxTMDownloadTexture: bad tmu"); + return; + } +} + + +void +tdfxTMReloadMipMapLevel(GLcontext *ctx, struct gl_texture_object *tObj, + GLint level) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + GrLOD_t glideLod; + FxU32 tmu; + + tmu = ti->whichTMU; + glideLod = ti->info.largeLodLog2 - level + tObj->BaseLevel; + ASSERT(ti->isInTM); + + switch (tmu) { + case TDFX_TMU0: + case TDFX_TMU1: + FX_grTexDownloadMipMapLevel(fxMesa, tmu, + ti->tm[tmu]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + break; + case TDFX_TMU_SPLIT: + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU0, + ti->tm[GR_TMU0]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_ODD, + ti->mipmapLevel[level].data); + + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU1, + ti->tm[GR_TMU1]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_EVEN, + ti->mipmapLevel[level].data); + break; + case TDFX_TMU_BOTH: + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU0, + ti->tm[GR_TMU0]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + + FX_grTexDownloadMipMapLevel(fxMesa, GR_TMU1, + ti->tm[GR_TMU1]->startAddr, + glideLod, + ti->info.largeLodLog2, + ti->info.aspectRatioLog2, + ti->info.format, + GR_MIPMAPLEVELMASK_BOTH, + ti->mipmapLevel[level].data); + break; + + default: + gl_problem(ctx, "error in tdfxTMReloadMipMapLevel(): wrong tmu"); + break; + } +} + + +/* + * Allocate space for the given texture in texture memory then + * download (copy) it into that space. + */ +void +tdfxTMMoveInTM_NoLock( tdfxContextPtr fxMesa, struct gl_texture_object *tObj, + FxU32 targetTMU ) +{ + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + FxU32 texmemsize; + + fxMesa->stats.reqTexUpload++; + + if (ti->isInTM) { + if (ti->whichTMU == targetTMU) + return; + if (targetTMU == TDFX_TMU_SPLIT || ti->whichTMU == TDFX_TMU_SPLIT) { + tdfxTMMoveOutTM_NoLock(fxMesa, tObj); + } + else { + if (ti->whichTMU == TDFX_TMU_BOTH) + return; + targetTMU = TDFX_TMU_BOTH; + } + } + + ti->whichTMU = targetTMU; + + switch (targetTMU) { + case TDFX_TMU0: + case TDFX_TMU1: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[targetTMU] = AllocTexMem(fxMesa, targetTMU, texmemsize); + break; + case TDFX_TMU_SPLIT: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_ODD, + &(ti->info)); + ti->tm[TDFX_TMU0] = AllocTexMem(fxMesa, TDFX_TMU0, texmemsize); + if (ti->tm[TDFX_TMU0]) + fxMesa->stats.memTexUpload += texmemsize; + + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_EVEN, + &(ti->info)); + ti->tm[TDFX_TMU1] = AllocTexMem(fxMesa, TDFX_TMU1, texmemsize); + break; + case TDFX_TMU_BOTH: + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[TDFX_TMU0] = AllocTexMem(fxMesa, TDFX_TMU0, texmemsize); + if (ti->tm[TDFX_TMU0]) + fxMesa->stats.memTexUpload += texmemsize; + + texmemsize = FX_grTexTextureMemRequired_NoLock(GR_MIPMAPLEVELMASK_BOTH, + &(ti->info)); + ti->tm[TDFX_TMU1] = AllocTexMem(fxMesa, TDFX_TMU1, texmemsize); + break; + default: + gl_problem(NULL, "error in tdfxTMMoveInTM() -> bad tmu (%d)"); + return; + } + + ti->reloadImages = GL_TRUE; + ti->isInTM = GL_TRUE; + + fxMesa->stats.texUpload++; +} + + +/* + * Move the given texture out of hardware texture memory. + * This deallocates the texture's memory space. + */ +void +tdfxTMMoveOutTM_NoLock( tdfxContextPtr fxMesa, struct gl_texture_object *tObj ) +{ + struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxTMMoveOutTM(%p (%d))\n", tObj, tObj->Name); + } + + /* + VerifyFreeList(fxMesa, 0); + VerifyFreeList(fxMesa, 1); + */ + + if (!ti || !ti->isInTM) + return; + + switch (ti->whichTMU) { + case TDFX_TMU0: + case TDFX_TMU1: + RemoveRange_NoLock(fxMesa, ti->whichTMU, ti->tm[ti->whichTMU]); + break; + case TDFX_TMU_SPLIT: + case TDFX_TMU_BOTH: + assert(!shared->umaTexMemory); + RemoveRange_NoLock(fxMesa, TDFX_TMU0, ti->tm[TDFX_TMU0]); + RemoveRange_NoLock(fxMesa, TDFX_TMU1, ti->tm[TDFX_TMU1]); + break; + default: + gl_problem(NULL, "tdfx driver: bad tmu in tdfxTMMOveOutTM()"); + return; + } + + ti->isInTM = GL_FALSE; + ti->tm[0] = NULL; + ti->tm[1] = NULL; + ti->whichTMU = TDFX_TMU_NONE; + + /* + VerifyFreeList(fxMesa, 0); + VerifyFreeList(fxMesa, 1); + */ +} + + +/* + * Called via glDeleteTexture to delete a texture object. + */ +void +tdfxTMFreeTexture(tdfxContextPtr fxMesa, struct gl_texture_object *tObj) +{ + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + if (ti) { + int i; + tdfxTMMoveOutTM(fxMesa, tObj); + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + if (ti->mipmapLevel[i].data) { + FREE(ti->mipmapLevel[i].data); + ti->mipmapLevel[i].data = NULL; + } + } + FREE(ti); + tObj->DriverData = NULL; + } + /* + VerifyFreeList(fxMesa, 0); + VerifyFreeList(fxMesa, 1); + */ +} + + + +/* + * After a context switch this function will be called to restore + * texture memory for the new context. + */ +void tdfxTMRestoreTextures_NoLock( tdfxContextPtr fxMesa ) +{ + GLcontext *ctx = fxMesa->glCtx; + struct gl_texture_object *tObj; + int i; + + for ( tObj = ctx->Shared->TexObjectList ; tObj ; tObj = tObj->Next ) { + tdfxTexInfo *ti = TDFX_TEXTURE_DATA( tObj ); + if ( ti && ti->isInTM ) { + for ( i = 0 ; i < MAX_TEXTURE_UNITS ; i++ ) { + if ( ctx->Texture.Unit[i].Current == tObj ) { + tdfxTMDownloadTexture( fxMesa, tObj ); + break; + } + } + if ( i == MAX_TEXTURE_UNITS ) { + tdfxTMMoveOutTM_NoLock( fxMesa, tObj ); + } + } + } + /* + VerifyFreeList(fxMesa, 0); + VerifyFreeList(fxMesa, 1); + */ +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.h new file mode 100644 index 000000000..1965aaa84 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texman.h @@ -0,0 +1,84 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#ifndef __TDFX_TEXMAN_H__ +#define __TDFX_TEXMAN_H__ + + +#include "tdfx_lock.h" + + +extern void tdfxTMInit( tdfxContextPtr fxMesa ); + +extern void tdfxTMClose( tdfxContextPtr fxMesa ); + +extern void tdfxTMDownloadTexture(tdfxContextPtr fxMesa, + struct gl_texture_object *tObj); + +extern void tdfxTMReloadMipMapLevel( GLcontext *ctx, + struct gl_texture_object *tObj, + GLint level ); + +extern void tdfxTMMoveInTM_NoLock( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj, + FxU32 targetTMU ); + +extern void tdfxTMMoveOutTM_NoLock( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj ); + +extern void tdfxTMFreeTexture( tdfxContextPtr fxMesa, + struct gl_texture_object *tObj ); + +extern void tdfxTMRestoreTextures_NoLock( tdfxContextPtr fxMesa ); + + +#define tdfxTMMoveInTM( fxMesa, tObj, targetTMU ) \ + do { \ + LOCK_HARDWARE( fxMesa ); \ + tdfxTMMoveInTM_NoLock( fxMesa, tObj, targetTMU ); \ + UNLOCK_HARDWARE( fxMesa ); \ + } while (0) + +#define tdfxTMMoveOutTM( fxMesa, tObj ) \ + do { \ + LOCK_HARDWARE( fxMesa ); \ + tdfxTMMoveOutTM_NoLock( fxMesa, tObj ); \ + UNLOCK_HARDWARE( fxMesa ); \ + } while (0) + + +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.c new file mode 100644 index 000000000..5493eea8a --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.c @@ -0,0 +1,2102 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include "tdfx_state.h" +#include "tdfx_tex.h" +#include "tdfx_texman.h" +#include "tdfx_texstate.h" + + +/* ============================================================= + * Texture + */ + +/* + * These macros are used below when handling COMBINE_EXT. + */ +#define TEXENV_OPERAND_INVERTED(operand) \ + (((operand) == GL_ONE_MINUS_SRC_ALPHA) \ + || ((operand) == GL_ONE_MINUS_SRC_COLOR)) +#define TEXENV_OPERAND_ALPHA(operand) \ + (((operand) == GL_SRC_ALPHA) || ((operand) == GL_ONE_MINUS_SRC_ALPHA)) +#define TEXENV_SETUP_ARG_A(param, source, operand, iteratedAlpha) \ + switch (source) { \ + case GL_TEXTURE: \ + param = GR_CMBX_LOCAL_TEXTURE_ALPHA; \ + break; \ + case GL_CONSTANT_EXT: \ + param = GR_CMBX_TMU_CALPHA; \ + break; \ + case GL_PRIMARY_COLOR_EXT: \ + param = GR_CMBX_ITALPHA; \ + break; \ + case GL_PREVIOUS_EXT: \ + param = iteratedAlpha; \ + break; \ + default: \ + /* \ + * This is here just to keep from getting \ + * compiler warnings. \ + */ \ + param = GR_CMBX_ZERO; \ + break; \ + } + +#define TEXENV_SETUP_ARG_RGB(param, source, operand, iteratedColor, iteratedAlpha) \ + if (!TEXENV_OPERAND_ALPHA(operand)) { \ + switch (source) { \ + case GL_TEXTURE: \ + param = GR_CMBX_LOCAL_TEXTURE_RGB; \ + break; \ + case GL_CONSTANT_EXT: \ + param = GR_CMBX_TMU_CCOLOR; \ + break; \ + case GL_PRIMARY_COLOR_EXT: \ + param = GR_CMBX_ITRGB; \ + break; \ + case GL_PREVIOUS_EXT: \ + param = iteratedColor; \ + break; \ + default: \ + /* \ + * This is here just to keep from getting \ + * compiler warnings. \ + */ \ + param = GR_CMBX_ZERO; \ + break; \ + } \ + } else { \ + switch (source) { \ + case GL_TEXTURE: \ + param = GR_CMBX_LOCAL_TEXTURE_ALPHA; \ + break; \ + case GL_CONSTANT_EXT: \ + param = GR_CMBX_TMU_CALPHA; \ + break; \ + case GL_PRIMARY_COLOR_EXT: \ + param = GR_CMBX_ITALPHA; \ + break; \ + case GL_PREVIOUS_EXT: \ + param = iteratedAlpha; \ + break; \ + default: \ + /* \ + * This is here just to keep from getting \ + * compiler warnings. \ + */ \ + param = GR_CMBX_ZERO; \ + break; \ + } \ + } + +#define TEXENV_SETUP_MODE_RGB(param, operand) \ + switch (operand) { \ + case GL_SRC_COLOR: \ + case GL_SRC_ALPHA: \ + param = GR_FUNC_MODE_X; \ + break; \ + case GL_ONE_MINUS_SRC_ALPHA: \ + case GL_ONE_MINUS_SRC_COLOR: \ + param = GR_FUNC_MODE_ONE_MINUS_X; \ + break; \ + default: \ + param = GR_FUNC_MODE_ZERO; \ + break; \ + } + +#define TEXENV_SETUP_MODE_A(param, operand) \ + switch (operand) { \ + case GL_SRC_ALPHA: \ + param = GR_FUNC_MODE_X; \ + break; \ + case GL_ONE_MINUS_SRC_ALPHA: \ + param = GR_FUNC_MODE_ONE_MINUS_X; \ + break; \ + default: \ + param = GR_FUNC_MODE_ZERO; \ + break; \ + } + + + +/* + * Setup a texture environment on Voodoo5. + * Return GL_TRUE for success, GL_FALSE for failure. + * If we fail, we'll have to use software rendering. + */ +static GLboolean +SetupTexEnvNapalm(GLcontext *ctx, GLboolean useIteratedRGBA, + const struct gl_texture_unit *texUnit, GLenum baseFormat, + struct tdfx_texcombine_ext *env) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrTCCUColor_t incomingRGB, incomingAlpha; + const GLenum envMode = texUnit->EnvMode; + + if (useIteratedRGBA) { + incomingRGB = GR_CMBX_ITRGB; + incomingAlpha = GR_CMBX_ITALPHA; + } + else { + incomingRGB = GR_CMBX_OTHER_TEXTURE_RGB; + incomingAlpha = GR_CMBX_OTHER_TEXTURE_ALPHA; + } + + /* invariant: */ + env->Color.Shift = 0; + env->Color.Invert = FXFALSE; + env->Alpha.Shift = 0; + env->Alpha.Invert = FXFALSE; + + switch (envMode) { + case GL_REPLACE: + /* -- Setup RGB combiner */ + if (baseFormat == GL_ALPHA) { + /* Rv = Rf */ + env->Color.SourceA = incomingRGB; + } + else { + /* Rv = Rt */ + env->Color.SourceA = GR_CMBX_LOCAL_TEXTURE_RGB; + } + env->Color.ModeA = GR_FUNC_MODE_X; + env->Color.SourceB = GR_CMBX_ZERO; + env->Color.ModeB = GR_FUNC_MODE_ZERO; + env->Color.SourceC = GR_CMBX_ZERO; + env->Color.InvertC = FXTRUE; + env->Color.SourceD = GR_CMBX_ZERO; + env->Color.InvertD = FXFALSE; + /* -- Setup Alpha combiner */ + if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* Av = Af */ + env->Alpha.SourceD = incomingAlpha; + } + else { + /* Av = At */ + env->Alpha.SourceD = GR_CMBX_LOCAL_TEXTURE_ALPHA; + } + env->Alpha.SourceA = GR_CMBX_ITALPHA; + env->Alpha.ModeA = GR_FUNC_MODE_ZERO; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXFALSE; + env->Alpha.InvertD = FXFALSE; + break; + + case GL_MODULATE: + /* -- Setup RGB combiner */ + if (baseFormat == GL_ALPHA) { + /* Rv = Rf */ + env->Color.SourceC = GR_CMBX_ZERO; + env->Color.InvertC = FXTRUE; + } + else { + /* Result = Frag * Tex */ + env->Color.SourceC = GR_CMBX_LOCAL_TEXTURE_RGB; + env->Color.InvertC = FXFALSE; + } + env->Color.SourceA = incomingRGB; + env->Color.ModeA = GR_FUNC_MODE_X; + env->Color.SourceB = GR_CMBX_ZERO; + env->Color.ModeB = GR_FUNC_MODE_ZERO; + env->Color.SourceD = GR_CMBX_ZERO; + env->Color.InvertD = FXFALSE; + /* -- Setup Alpha combiner */ + if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* Av = Af */ + env->Alpha.SourceA = incomingAlpha; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXTRUE; + } + else { + /* Av = Af * At */ + env->Alpha.SourceA = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Alpha.SourceC = incomingAlpha; + env->Alpha.InvertC = FXFALSE; + } + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceD = GR_CMBX_ZERO; + env->Alpha.InvertD = FXFALSE; + break; + + case GL_DECAL: + /* -- Setup RGB combiner */ + if (baseFormat == GL_RGB) { + /* Rv = Rt */ + env->Color.SourceB = GR_CMBX_ZERO; + env->Color.ModeB = GR_FUNC_MODE_X; + env->Color.SourceC = GR_CMBX_ZERO; + env->Color.InvertC = FXTRUE; + env->Color.SourceD = GR_CMBX_ZERO; + env->Color.InvertD = FXFALSE; + } + else { + /* Rv = Rf * (1 - At) + Rt * At */ + env->Color.SourceB = incomingRGB; + env->Color.ModeB = GR_FUNC_MODE_NEGATIVE_X; + env->Color.SourceC = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Color.InvertC = FXFALSE; + env->Color.SourceD = GR_CMBX_B; + env->Color.InvertD = FXFALSE; + } + env->Color.SourceA = GR_CMBX_LOCAL_TEXTURE_RGB; + env->Color.ModeA = GR_FUNC_MODE_X; + /* -- Setup Alpha combiner */ + /* Av = Af */ + env->Alpha.SourceA = incomingAlpha; + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXTRUE; + env->Alpha.SourceD = GR_CMBX_ZERO; + env->Alpha.InvertD = FXFALSE; + break; + + case GL_BLEND: + /* -- Setup RGB combiner */ + if (baseFormat == GL_ALPHA) { + /* Rv = Rf */ + env->Color.SourceA = incomingRGB; + env->Color.ModeA = GR_FUNC_MODE_X; + env->Color.SourceB = GR_CMBX_ZERO; + env->Color.ModeB = GR_FUNC_MODE_ZERO; + env->Color.SourceC = GR_CMBX_ZERO; + env->Color.InvertC = FXTRUE; + env->Color.SourceD = GR_CMBX_ZERO; + env->Color.InvertD = FXFALSE; + } + else { + /* Rv = Rf * (1 - Rt) + Rc * Rt */ + env->Color.SourceA = GR_CMBX_TMU_CCOLOR; + env->Color.ModeA = GR_FUNC_MODE_X; + env->Color.SourceB = incomingRGB; + env->Color.ModeB = GR_FUNC_MODE_NEGATIVE_X; + env->Color.SourceC = GR_CMBX_LOCAL_TEXTURE_RGB; + env->Color.InvertC = FXFALSE; + env->Color.SourceD = GR_CMBX_B; + env->Color.InvertD = FXFALSE; + } + /* -- Setup Alpha combiner */ + if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* Av = Af */ + env->Alpha.SourceA = incomingAlpha; + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceB = GR_CMBX_ZERO; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXTRUE; + env->Alpha.SourceD = GR_CMBX_ZERO; + env->Alpha.InvertD = FXFALSE; + } + else if (baseFormat == GL_INTENSITY) { + /* Av = Af * (1 - It) + Ac * It */ + env->Alpha.SourceA = GR_CMBX_TMU_CALPHA; + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceB = incomingAlpha; + env->Alpha.ModeB = GR_FUNC_MODE_NEGATIVE_X; + env->Alpha.SourceC = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Alpha.InvertC = FXFALSE; + env->Alpha.SourceD = GR_CMBX_B; + env->Alpha.InvertD = FXFALSE; + } + else { + /* Av = Af * At */ + env->Alpha.SourceA = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = incomingAlpha; + env->Alpha.InvertC = FXFALSE; + env->Alpha.SourceD = GR_CMBX_ZERO; + env->Alpha.InvertD = FXFALSE; + } + /* Also have to set up the tex env constant color */ + env->EnvColor = PACK_RGBA32(texUnit->EnvColor[0] * 255.0F, + texUnit->EnvColor[1] * 255.0F, + texUnit->EnvColor[2] * 255.0F, + texUnit->EnvColor[3] * 255.0F); + break; + case GL_ADD: + /* -- Setup RGB combiner */ + if (baseFormat == GL_ALPHA) { + /* Rv = Rf */ + env->Color.SourceB = GR_CMBX_ZERO; + env->Color.ModeB = GR_FUNC_MODE_ZERO; + } + else { + /* Rv = Rf + Tt */ + env->Color.SourceB = GR_CMBX_LOCAL_TEXTURE_RGB; + env->Color.ModeB = GR_FUNC_MODE_X; + } + env->Color.SourceA = incomingRGB; + env->Color.ModeA = GR_FUNC_MODE_X; + env->Color.SourceC = GR_CMBX_ZERO; + env->Color.InvertC = FXTRUE; + env->Color.SourceD = GR_CMBX_ZERO; + env->Color.InvertD = FXFALSE; + /* -- Setup Alpha combiner */ + if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* Av = Af */ + env->Alpha.SourceA = incomingAlpha; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXTRUE; + + } + else if (baseFormat == GL_INTENSITY) { + /* Av = Af + It */ + env->Alpha.SourceA = incomingAlpha; + env->Alpha.SourceB = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_X; + env->Alpha.SourceC = GR_CMBX_ZERO; + env->Alpha.InvertC = FXTRUE; + } + else { + /* Av = Af * At */ + env->Alpha.SourceA = GR_CMBX_LOCAL_TEXTURE_ALPHA; + env->Alpha.SourceB = GR_CMBX_ITALPHA; + env->Alpha.ModeB = GR_FUNC_MODE_ZERO; + env->Alpha.SourceC = incomingAlpha; + env->Alpha.InvertC = FXFALSE; + } + env->Alpha.ModeA = GR_FUNC_MODE_X; + env->Alpha.SourceD = GR_CMBX_ZERO; + env->Alpha.InvertD = FXFALSE; + break; + + case GL_COMBINE_EXT: + { + FxU32 A_RGB, B_RGB, C_RGB, D_RGB; + FxU32 Amode_RGB, Bmode_RGB; + FxBool Cinv_RGB, Dinv_RGB, Ginv_RGB; + FxU32 Shift_RGB; + FxU32 A_A, B_A, C_A, D_A; + FxU32 Amode_A, Bmode_A; + FxBool Cinv_A, Dinv_A, Ginv_A; + FxU32 Shift_A; + + /* + * + * In the formulas below, we write: + * o "1(x)" for the identity function applied to x, + * so 1(x) = x. + * o "0(x)" for the constant function 0, so + * 0(x) = 0 for all values of x. + * + * Calculate the color combination. + */ + Shift_RGB = texUnit->CombineScaleShiftRGB; + Shift_A = texUnit->CombineScaleShiftA; + switch (texUnit->CombineModeRGB) { + case GL_REPLACE: + /* + * The formula is: Arg0 + * We implement this by the formula: + * (Arg0 + 0(0))*(1-0) + 0 + */ + TEXENV_SETUP_ARG_RGB(A_RGB, + texUnit->CombineSourceRGB[0], + texUnit->CombineOperandRGB[0], + incomingRGB, incomingAlpha); + TEXENV_SETUP_MODE_RGB(Amode_RGB, + texUnit->CombineOperandRGB[0]); + B_RGB = C_RGB = D_RGB = GR_CMBX_ZERO; + Bmode_RGB = GR_FUNC_MODE_ZERO; + Cinv_RGB = FXTRUE; + Dinv_RGB = Ginv_RGB = FXFALSE; + break; + case GL_MODULATE: + /* + * The formula is: Arg0 * Arg1 + * + * We implement this by the formula + * (Arg0 + 0(0)) * Arg1 + 0(0) + */ + TEXENV_SETUP_ARG_RGB(A_RGB, + texUnit->CombineSourceRGB[0], + texUnit->CombineOperandRGB[0], + incomingRGB, incomingAlpha); + TEXENV_SETUP_MODE_RGB(Amode_RGB, + texUnit->CombineOperandRGB[0]); + B_RGB = GR_CMBX_ZERO; + Bmode_RGB = GR_CMBX_ZERO; + TEXENV_SETUP_ARG_RGB(C_RGB, + texUnit->CombineSourceRGB[1], + texUnit->CombineOperandRGB[1], + incomingRGB, incomingAlpha); + Cinv_RGB = TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandRGB[1]); + D_RGB = GR_CMBX_ZERO; + Dinv_RGB = Ginv_RGB = FXFALSE; + break; + case GL_ADD: + /* + * The formula is Arg0 + Arg1 + */ + TEXENV_SETUP_ARG_RGB(A_RGB, + texUnit->CombineSourceRGB[0], + texUnit->CombineOperandRGB[0], + incomingRGB, incomingAlpha); + TEXENV_SETUP_MODE_RGB(Amode_RGB, + texUnit->CombineOperandRGB[0]); + TEXENV_SETUP_ARG_RGB(B_RGB, + texUnit->CombineSourceRGB[1], + texUnit->CombineOperandRGB[1], + incomingRGB, incomingAlpha); + TEXENV_SETUP_MODE_RGB(Bmode_RGB, + texUnit->CombineOperandRGB[1]); + C_RGB = D_RGB = GR_CMBX_ZERO; + Cinv_RGB = FXTRUE; + Dinv_RGB = Ginv_RGB = FXFALSE; + break; + case GL_ADD_SIGNED_EXT: + /* + * The formula is: Arg0 + Arg1 - 0.5. + * We compute this by calculating: + * (Arg0 - 1/2) + Arg1 if op0 is SRC_{COLOR,ALPHA} + * Arg0 + (Arg1 - 1/2) if op1 is SRC_{COLOR,ALPHA} + * If both op0 and op1 are ONE_MINUS_SRC_{COLOR,ALPHA} + * we cannot implement the formula properly. + */ + TEXENV_SETUP_ARG_RGB(A_RGB, + texUnit->CombineSourceRGB[0], + texUnit->CombineOperandRGB[0], + incomingRGB, incomingAlpha); + TEXENV_SETUP_ARG_RGB(B_RGB, + texUnit->CombineSourceRGB[1], + texUnit->CombineOperandRGB[1], + incomingRGB, incomingAlpha); + if (!TEXENV_OPERAND_INVERTED(texUnit->CombineOperandRGB[0])) { + /* + * A is not inverted. So, choose it. + */ + Amode_RGB = GR_FUNC_MODE_X_MINUS_HALF; + if (!TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandRGB[1])) { + Bmode_RGB = GR_FUNC_MODE_X; + } + else { + Bmode_RGB = GR_FUNC_MODE_ONE_MINUS_X; + } + } + else { + /* + * A is inverted, so try to subtract 1/2 + * from B. + */ + Amode_RGB = GR_FUNC_MODE_ONE_MINUS_X; + if (!TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandRGB[1])) { + Bmode_RGB = GR_FUNC_MODE_X_MINUS_HALF; + } + else { + /* + * Both are inverted. This is the case + * we cannot handle properly. We just + * choose to not add the - 1/2. + */ + Bmode_RGB = GR_FUNC_MODE_ONE_MINUS_X; + return GL_FALSE; + } + } + C_RGB = D_RGB = GR_CMBX_ZERO; + Cinv_RGB = FXTRUE; + Dinv_RGB = Ginv_RGB = FXFALSE; + break; + case GL_INTERPOLATE_EXT: + /* + * The formula is: Arg0 * Arg2 + Arg1 * (1 - Arg2). + * We compute this by the formula: + * (Arg0 - Arg1) * Arg2 + Arg1 + * == Arg0 * Arg2 - Arg1 * Arg2 + Arg1 + * == Arg0 * Arg2 + Arg1 * (1 - Arg2) + * However, if both Arg1 is ONE_MINUS_X, the HW does + * not support it properly. + */ + TEXENV_SETUP_ARG_RGB(A_RGB, + texUnit->CombineSourceRGB[0], + texUnit->CombineOperandRGB[0], + incomingRGB, incomingAlpha); + TEXENV_SETUP_MODE_RGB(Amode_RGB, + texUnit->CombineOperandRGB[0]); + TEXENV_SETUP_ARG_RGB(B_RGB, + texUnit->CombineSourceRGB[1], + texUnit->CombineOperandRGB[1], + incomingRGB, incomingAlpha); + if (TEXENV_OPERAND_INVERTED(texUnit->CombineOperandRGB[1])) { + /* + * This case is wrong. + */ + Bmode_RGB = GR_FUNC_MODE_NEGATIVE_X; + return GL_FALSE; + } + else { + Bmode_RGB = GR_FUNC_MODE_NEGATIVE_X; + } + /* + * The Source/Operand for the C value must + * specify some kind of alpha value. + */ + TEXENV_SETUP_ARG_A(C_RGB, + texUnit->CombineSourceRGB[2], + texUnit->CombineOperandRGB[2], + incomingAlpha); + Cinv_RGB = FXFALSE; + D_RGB = GR_CMBX_B; + Dinv_RGB = Ginv_RGB = FXFALSE; + break; + default: + /* + * This is here mostly to keep from getting + * a compiler warning about these not being set. + * However, this should set all the texture values + * to zero. + */ + A_RGB = B_RGB = C_RGB = D_RGB = GR_CMBX_ZERO; + Amode_RGB = Bmode_RGB = GR_FUNC_MODE_X; + Cinv_RGB = Dinv_RGB = Ginv_RGB = FXFALSE; + break; + } + /* + * Calculate the alpha combination. + */ + switch (texUnit->CombineModeA) { + case GL_REPLACE: + /* + * The formula is: Arg0 + * We implement this by the formula: + * (Arg0 + 0(0))*(1-0) + 0 + */ + TEXENV_SETUP_ARG_A(A_A, + texUnit->CombineSourceA[0], + texUnit->CombineOperandA[0], + incomingAlpha); + TEXENV_SETUP_MODE_A(Amode_A, + texUnit->CombineOperandA[0]); + B_A = GR_CMBX_ITALPHA; + Bmode_A = GR_FUNC_MODE_ZERO; + C_A = D_A = GR_CMBX_ZERO; + Cinv_A = FXTRUE; + Dinv_A = Ginv_A = FXFALSE; + break; + case GL_MODULATE: + /* + * The formula is: Arg0 * Arg1 + * + * We implement this by the formula + * (Arg0 + 0(0)) * Arg1 + 0(0) + */ + TEXENV_SETUP_ARG_A(A_A, + texUnit->CombineSourceA[0], + texUnit->CombineOperandA[0], + incomingAlpha); + TEXENV_SETUP_MODE_A(Amode_A, + texUnit->CombineOperandA[0]); + B_A = GR_CMBX_ZERO; + Bmode_A = GR_CMBX_ZERO; + TEXENV_SETUP_ARG_A(C_A, + texUnit->CombineSourceA[1], + texUnit->CombineOperandA[1], + incomingAlpha); + Cinv_A = TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandA[1]); + D_A = GR_CMBX_ZERO; + Dinv_A = Ginv_A = FXFALSE; + break; + case GL_ADD: + /* + * The formula is Arg0 + Arg1 + */ + TEXENV_SETUP_ARG_A(A_A, + texUnit->CombineSourceA[0], + texUnit->CombineOperandA[0], + incomingAlpha); + TEXENV_SETUP_MODE_A(Amode_A, + texUnit->CombineOperandA[0]); + TEXENV_SETUP_ARG_A(B_A, + texUnit->CombineSourceA[1], + texUnit->CombineOperandA[1], + incomingAlpha); + TEXENV_SETUP_MODE_A(Bmode_A, + texUnit->CombineOperandA[0]); + C_A = D_A = GR_CMBX_ZERO; + Cinv_A = FXTRUE; + Dinv_A = Ginv_A = FXFALSE; + break; + case GL_ADD_SIGNED_EXT: + /* + * The formula is: Arg0 + Arg1 - 0.5. + * We compute this by calculating: + * (Arg0 - 1/2) + Arg1 if op0 is SRC_{COLOR,ALPHA} + * Arg0 + (Arg1 - 1/2) if op1 is SRC_{COLOR,ALPHA} + * If both op0 and op1 are ONE_MINUS_SRC_{COLOR,ALPHA} + * we cannot implement the formula properly. + */ + TEXENV_SETUP_ARG_A(A_A, + texUnit->CombineSourceA[0], + texUnit->CombineOperandA[0], + incomingAlpha); + TEXENV_SETUP_ARG_A(B_A, + texUnit->CombineSourceA[1], + texUnit->CombineOperandA[1], + incomingAlpha); + if (!TEXENV_OPERAND_INVERTED(texUnit->CombineOperandA[0])) { + /* + * A is not inverted. So, choose it. + */ + Amode_A = GR_FUNC_MODE_X_MINUS_HALF; + if (!TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandA[1])) { + Bmode_A = GR_FUNC_MODE_X; + } else { + Bmode_A = GR_FUNC_MODE_ONE_MINUS_X; + } + } else { + /* + * A is inverted, so try to subtract 1/2 + * from B. + */ + Amode_A = GR_FUNC_MODE_ONE_MINUS_X; + if (!TEXENV_OPERAND_INVERTED + (texUnit->CombineOperandA[1])) { + Bmode_A = GR_FUNC_MODE_X_MINUS_HALF; + } else { + /* + * Both are inverted. This is the case + * we cannot handle properly. We just + * choose to not add the - 1/2. + */ + Bmode_A = GR_FUNC_MODE_ONE_MINUS_X; + return GL_FALSE; + } + } + C_A = D_A = GR_CMBX_ZERO; + Cinv_A = FXTRUE; + Dinv_A = Ginv_A = FXFALSE; + break; + case GL_INTERPOLATE_EXT: + /* + * The formula is: Arg0 * Arg2 + Arg1 * (1 - Arg2). + * We compute this by the formula: + * (Arg0 - Arg1) * Arg2 + Arg1 + * == Arg0 * Arg2 - Arg1 * Arg2 + Arg1 + * == Arg0 * Arg2 + Arg1 * (1 - Arg2) + * However, if both Arg1 is ONE_MINUS_X, the HW does + * not support it properly. + */ + TEXENV_SETUP_ARG_A(A_A, + texUnit->CombineSourceA[0], + texUnit->CombineOperandA[0], + incomingAlpha); + TEXENV_SETUP_MODE_A(Amode_A, + texUnit->CombineOperandA[0]); + TEXENV_SETUP_ARG_A(B_A, + texUnit->CombineSourceA[1], + texUnit->CombineOperandA[1], + incomingAlpha); + if (!TEXENV_OPERAND_INVERTED(texUnit->CombineOperandA[1])) { + Bmode_A = GR_FUNC_MODE_NEGATIVE_X; + } + else { + /* + * This case is wrong. + */ + Bmode_A = GR_FUNC_MODE_NEGATIVE_X; + return GL_FALSE; + } + /* + * The Source/Operand for the C value must + * specify some kind of alpha value. + */ + TEXENV_SETUP_ARG_A(C_A, + texUnit->CombineSourceA[2], + texUnit->CombineOperandA[2], + incomingAlpha); + Cinv_A = FXFALSE; + D_A = GR_CMBX_ZERO; + Dinv_A = Ginv_A = FXFALSE; + break; + default: + /* + * This is here mostly to keep from getting + * a compiler warning about these not being set. + * However, this should set all the alpha values + * to one. + */ + A_A = B_A = C_A = D_A = GR_CMBX_ZERO; + Amode_A = Bmode_A = GR_FUNC_MODE_X; + Cinv_A = Dinv_A = FXFALSE; + Ginv_A = FXTRUE; + break; + } + /* + * Save the parameters. + */ + env->Color.SourceA = A_RGB; + env->Color.ModeA = Amode_RGB; + env->Color.SourceB = B_RGB; + env->Color.ModeB = Bmode_RGB; + env->Color.SourceC = C_RGB; + env->Color.InvertC = Cinv_RGB; + env->Color.SourceD = D_RGB; + env->Color.InvertD = Dinv_RGB; + env->Color.Shift = Shift_RGB; + env->Color.Invert = Ginv_RGB; + env->Alpha.SourceA = A_A; + env->Alpha.ModeA = Amode_A; + env->Alpha.SourceB = B_A; + env->Alpha.ModeB = Bmode_A; + env->Alpha.SourceC = C_A; + env->Alpha.InvertC = Cinv_A; + env->Alpha.SourceD = D_A; + env->Alpha.InvertD = Dinv_A; + env->Alpha.Shift = Shift_A; + env->Alpha.Invert = Ginv_A; + env->EnvColor = PACK_RGBA32(texUnit->EnvColor[0] * 255.0F, + texUnit->EnvColor[1] * 255.0F, + texUnit->EnvColor[2] * 255.0F, + texUnit->EnvColor[3] * 255.0F); + } + break; + + default: + gl_problem(ctx, "Bad envMode in SetupTexEnvNapalm"); + } + + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_ENV; + + fxMesa->ColorCombineExt.SourceA = GR_CMBX_TEXTURE_RGB; + fxMesa->ColorCombineExt.ModeA = GR_FUNC_MODE_X, + fxMesa->ColorCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.ModeB = GR_FUNC_MODE_X; + fxMesa->ColorCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertC = FXTRUE; + fxMesa->ColorCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertD = FXFALSE; + fxMesa->ColorCombineExt.Shift = 0; + fxMesa->ColorCombineExt.Invert = FXFALSE; + fxMesa->dirty |= TDFX_UPLOAD_COLOR_COMBINE; + fxMesa->AlphaCombineExt.SourceA = GR_CMBX_TEXTURE_ALPHA; + fxMesa->AlphaCombineExt.ModeA = GR_FUNC_MODE_X; + fxMesa->AlphaCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.ModeB = GR_FUNC_MODE_X; + fxMesa->AlphaCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertC = FXTRUE; + fxMesa->AlphaCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertD = FXFALSE; + fxMesa->AlphaCombineExt.Shift = 0; + fxMesa->AlphaCombineExt.Invert = FXFALSE; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_COMBINE; + return GL_TRUE; /* success */ +} + + + +/* + * Setup the Voodoo3 texture environment for a single texture unit. + * Return GL_TRUE for success, GL_FALSE for failure. + * If failure, we'll use software rendering. + */ +static GLboolean +SetupSingleTexEnvVoodoo3(GLcontext *ctx, int unit, + GLenum envMode, GLenum baseFormat) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GrCombineLocal_t localc, locala; + struct tdfx_combine alphaComb, colorComb; + + if (1 /*iteratedRGBA*/) + localc = locala = GR_COMBINE_LOCAL_ITERATED; + else + localc = locala = GR_COMBINE_LOCAL_CONSTANT; + + switch (envMode) { + case GL_DECAL: + alphaComb.Function = GR_COMBINE_FUNCTION_LOCAL; + alphaComb.Factor = GR_COMBINE_FACTOR_NONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_NONE; + alphaComb.Invert = FXFALSE; + colorComb.Function = GR_COMBINE_FUNCTION_BLEND; + colorComb.Factor = GR_COMBINE_FACTOR_TEXTURE_ALPHA; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_TEXTURE; + colorComb.Invert = FXFALSE; + break; + case GL_MODULATE: + alphaComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + alphaComb.Factor = GR_COMBINE_FACTOR_LOCAL; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_TEXTURE; + alphaComb.Invert = FXFALSE; + if (baseFormat == GL_ALPHA) { + colorComb.Function = GR_COMBINE_FUNCTION_LOCAL; + colorComb.Factor = GR_COMBINE_FACTOR_NONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_NONE; + colorComb.Invert = FXFALSE; + } + else { + colorComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + colorComb.Factor = GR_COMBINE_FACTOR_LOCAL; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_TEXTURE; + colorComb.Invert = FXFALSE; + } + break; + + case GL_BLEND: + /* + * XXX we can't do real GL_BLEND mode. These settings assume that + * the TexEnv color is black and incoming fragment color is white. + */ + if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* Av = Af */ + alphaComb.Function = GR_COMBINE_FUNCTION_LOCAL; + alphaComb.Factor = GR_COMBINE_FACTOR_NONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_NONE; + alphaComb.Invert = FXFALSE; + } + else if (baseFormat == GL_INTENSITY) { + /* Av = Af * (1 - It) + Ac * It */ + /* XXX this is wrong */ + alphaComb.Function = GR_COMBINE_FUNCTION_LOCAL; + alphaComb.Factor = GR_COMBINE_FACTOR_NONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_NONE; + alphaComb.Invert = FXFALSE; + } + else { + /* Av = Af * At */ + alphaComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + alphaComb.Factor = GR_COMBINE_FACTOR_LOCAL; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_TEXTURE; + alphaComb.Invert = FXFALSE; + } + if (baseFormat == GL_ALPHA) { + colorComb.Function = GR_COMBINE_FUNCTION_LOCAL; + colorComb.Factor = GR_COMBINE_FACTOR_NONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_NONE; + colorComb.Invert = FXFALSE; + } + else { + colorComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + colorComb.Factor = GR_COMBINE_FACTOR_ONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_TEXTURE; + colorComb.Invert = FXTRUE; + } + /* XXX return GL_FALSE for modes we don't support */ + break; + + case GL_REPLACE: + if ((baseFormat == GL_RGB) || (baseFormat == GL_LUMINANCE)) { + alphaComb.Function = GR_COMBINE_FUNCTION_LOCAL; + alphaComb.Factor = GR_COMBINE_FACTOR_NONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_NONE; + alphaComb.Invert = FXFALSE; + } + else { + alphaComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + alphaComb.Factor = GR_COMBINE_FACTOR_ONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_TEXTURE; + alphaComb.Invert = FXFALSE; + } + if (baseFormat == GL_ALPHA) { + colorComb.Function = GR_COMBINE_FUNCTION_LOCAL; + colorComb.Factor = GR_COMBINE_FACTOR_NONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_NONE; + colorComb.Invert = FXFALSE; + } + else { + colorComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + colorComb.Factor = GR_COMBINE_FACTOR_ONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_TEXTURE; + colorComb.Invert = FXFALSE; + } + break; + + case GL_ADD: + if (baseFormat == GL_ALPHA || + baseFormat == GL_LUMINANCE_ALPHA || + baseFormat == GL_RGBA) { + /* product of texel and fragment alpha */ + alphaComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + alphaComb.Factor = GR_COMBINE_FACTOR_LOCAL; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_TEXTURE; + alphaComb.Invert = FXFALSE; + } + else if (baseFormat == GL_LUMINANCE || baseFormat == GL_RGB) { + /* fragment alpha is unchanged */ + alphaComb.Function = GR_COMBINE_FUNCTION_LOCAL; + alphaComb.Factor = GR_COMBINE_FACTOR_NONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_NONE; + alphaComb.Invert = FXFALSE; + } + else { + ASSERT(baseFormat == GL_INTENSITY); + /* sum of texel and fragment alpha */ + alphaComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + alphaComb.Factor = GR_COMBINE_FACTOR_ONE; + alphaComb.Local = locala; + alphaComb.Other = GR_COMBINE_OTHER_TEXTURE; + alphaComb.Invert = FXFALSE; + } + if (baseFormat == GL_ALPHA) { + /* rgb unchanged */ + colorComb.Function = GR_COMBINE_FUNCTION_LOCAL; + colorComb.Factor = GR_COMBINE_FACTOR_NONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_NONE; + colorComb.Invert = FXFALSE; + } + else { + /* sum of texel and fragment rgb */ + colorComb.Function = GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL, + colorComb.Factor = GR_COMBINE_FACTOR_ONE; + colorComb.Local = localc; + colorComb.Other = GR_COMBINE_OTHER_TEXTURE; + colorComb.Invert = FXFALSE; + } + break; + + default: + gl_problem(NULL, "bad texture env mode in SetupSingleTexEnvVoodoo3"); + } + + if (colorComb.Function != fxMesa->ColorCombine.Function || + colorComb.Factor != fxMesa->ColorCombine.Factor || + colorComb.Local != fxMesa->ColorCombine.Local || + colorComb.Other != fxMesa->ColorCombine.Other || + colorComb.Invert != fxMesa->ColorCombine.Invert) { + fxMesa->ColorCombine = colorComb; + fxMesa->dirty |= TDFX_UPLOAD_COLOR_COMBINE; + } + + if (alphaComb.Function != fxMesa->AlphaCombine.Function || + alphaComb.Factor != fxMesa->AlphaCombine.Factor || + alphaComb.Local != fxMesa->AlphaCombine.Local || + alphaComb.Other != fxMesa->AlphaCombine.Other || + alphaComb.Invert != fxMesa->AlphaCombine.Invert) { + fxMesa->AlphaCombine = alphaComb; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_COMBINE; + } + return GL_TRUE; +} + + +/* + * Setup the Voodoo3 texture environment for dual texture units. + * Return GL_TRUE for success, GL_FALSE for failure. + * If failure, we'll use software rendering. + */ +static GLboolean +SetupDoubleTexEnvVoodoo3(GLcontext *ctx, int tmu0, + GLenum envMode0, GLenum baseFormat0, + GLenum envMode1, GLenum baseFormat1) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + const GrCombineLocal_t locala = GR_COMBINE_LOCAL_ITERATED; + const GrCombineLocal_t localc = GR_COMBINE_LOCAL_ITERATED; + const int tmu1 = 1 - tmu0; + + if (envMode0 == GL_MODULATE && envMode1 == GL_MODULATE) { + GLboolean isalpha[TDFX_NUM_TMU]; + + if (baseFormat0 == GL_ALPHA) + isalpha[tmu0] = GL_TRUE; + else + isalpha[tmu0] = GL_FALSE; + + if (baseFormat1 == GL_ALPHA) + isalpha[tmu1] = GL_TRUE; + else + isalpha[tmu1] = GL_FALSE; + + if (isalpha[TDFX_TMU1]) { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_ZERO; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXTRUE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + } + if (isalpha[TDFX_TMU0]) { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_LOCAL; + fxMesa->ColorCombine.Local = localc; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->ColorCombine.Invert = FXFALSE; + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_LOCAL; + fxMesa->AlphaCombine.Local = locala; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + else if (envMode0 == GL_REPLACE && envMode1 == GL_BLEND) { /* Quake */ + if (tmu1 == TDFX_TMU1) { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXTRUE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE_MINUS_LOCAL; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE_MINUS_LOCAL; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_ONE; + fxMesa->ColorCombine.Local = localc; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->ColorCombine.Invert = FXFALSE; + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->AlphaCombine.Local = locala; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + else if (envMode0 == GL_REPLACE && envMode1 == GL_MODULATE) { + /* Quake 2/3 */ + if (tmu1 == TDFX_TMU1) { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_ZERO; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXTRUE; + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_LOCAL; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND_OTHER; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_ONE; + fxMesa->ColorCombine.Local = localc; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->ColorCombine.Invert = FXFALSE; + if (baseFormat0 == GL_RGB) { + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->AlphaCombine.Local = locala; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + else { + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_ONE; + fxMesa->AlphaCombine.Local = locala; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + } + else if (envMode0 == GL_MODULATE && envMode1 == GL_ADD) { + /* Quake 3 sky */ + GLboolean isalpha[TDFX_NUM_TMU]; + if (baseFormat0 == GL_ALPHA) + isalpha[tmu0] = GL_TRUE; + else + isalpha[tmu0] = GL_FALSE; + if (baseFormat1 == GL_ALPHA) + isalpha[tmu1] = GL_TRUE; + else + isalpha[tmu1] = GL_FALSE; + + if (isalpha[TDFX_TMU1]) { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_ZERO; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXTRUE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + } + if (isalpha[TDFX_TMU0]) { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + else { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + } + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_LOCAL; + fxMesa->ColorCombine.Local = localc; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->ColorCombine.Invert = FXFALSE; + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_SCALE_OTHER; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_LOCAL; + fxMesa->AlphaCombine.Local = locala; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_TEXTURE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + else { + /*gl_problem(ctx, "Unexpected dual texture mode encountered\n");*/ + return GL_FALSE; + } + + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_ENV; + fxMesa->dirty |= TDFX_UPLOAD_COLOR_COMBINE; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_COMBINE; + return GL_TRUE; +} + + +/* + * This function makes sure that the correct mipmap levels are loaded + * in the right places in memory and then makes the Glide calls to + * setup the texture source pointers. + */ +static void +setupSingleTMU(tdfxContextPtr fxMesa, struct gl_texture_object *tObj) +{ + struct tdfxSharedState *shared = (struct tdfxSharedState *) fxMesa->glCtx->Shared->DriverData; + tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj); + const GLcontext *ctx = fxMesa->glCtx; + + /* Make sure we're not loaded incorrectly */ + if (ti->isInTM && !shared->umaTexMemory) { + /* if doing filtering between mipmap levels, alternate mipmap levels + * must be in alternate TMUs. + */ + if (ti->LODblend) { + if (ti->whichTMU != TDFX_TMU_SPLIT) + tdfxTMMoveOutTM_NoLock(fxMesa, tObj); + } + else { + if (ti->whichTMU == TDFX_TMU_SPLIT) + tdfxTMMoveOutTM_NoLock(fxMesa, tObj); + } + } + + /* Make sure we're loaded correctly */ + if (!ti->isInTM) { + /* Have to download the texture */ + if (shared->umaTexMemory) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj, TDFX_TMU0); + } + else { + /* Voodoo3 (split texture memory) */ + if (ti->LODblend) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj, TDFX_TMU_SPLIT); + } + else { +#if 0 + /* XXX putting textures into the second memory bank when the + * first bank is full is not working at this time. + */ + if (fxMesa->haveTwoTMUs) { + GLint memReq = FX_grTexTextureMemRequired_NoLock( + GR_MIPMAPLEVELMASK_BOTH, &(ti->info)); + if (shared->freeTexMem[TDFX_TMU0] > memReq) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj, TDFX_TMU0); + } + else { + tdfxTMMoveInTM_NoLock(fxMesa, tObj, TDFX_TMU1); + } + } + else +#endif + { + tdfxTMMoveInTM_NoLock(fxMesa, tObj, TDFX_TMU0); + } + } + } + } + + if (ti->LODblend && ti->whichTMU == TDFX_TMU_SPLIT) { + /* mipmap levels split between texture banks */ + GLint u; + + if (ti->info.format == GR_TEXFMT_P_8 && !ctx->Texture.SharedPalette) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + + for (u = 0; u < 2; u++) { + fxMesa->TexParams[u].sClamp = ti->sClamp; + fxMesa->TexParams[u].tClamp = ti->tClamp; + fxMesa->TexParams[u].minFilt = ti->minFilt; + fxMesa->TexParams[u].magFilt = ti->magFilt; + fxMesa->TexParams[u].mmMode = ti->mmMode; + fxMesa->TexParams[u].LODblend = ti->LODblend; + fxMesa->TexParams[u].LodBias = ctx->Texture.Unit[u].LodBias; + } + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PARAMS; + + fxMesa->TexSource[0].StartAddress = ti->tm[TDFX_TMU0]->startAddr; + fxMesa->TexSource[0].EvenOdd = GR_MIPMAPLEVELMASK_ODD; + fxMesa->TexSource[0].Info = &(ti->info); + fxMesa->TexSource[1].StartAddress = ti->tm[TDFX_TMU1]->startAddr; + fxMesa->TexSource[1].EvenOdd = GR_MIPMAPLEVELMASK_EVEN; + fxMesa->TexSource[1].Info = &(ti->info); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_SOURCE; + } + else { + FxU32 tmu; + + if (ti->whichTMU == TDFX_TMU_BOTH) + tmu = TDFX_TMU0; + else + tmu = ti->whichTMU; + + if (shared->umaTexMemory) { + assert(ti->whichTMU == TDFX_TMU0); + assert(tmu == TDFX_TMU0); + } + + if (ti->info.format == GR_TEXFMT_P_8 && !ctx->Texture.SharedPalette) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + + /* KW: The alternative is to do the download to the other tmu. If + * we get to this point, I think it means we are thrashing the + * texture memory, so perhaps it's not a good idea. + */ + + if (fxMesa->TexParams[tmu].sClamp != ti->sClamp || + fxMesa->TexParams[tmu].tClamp != ti->tClamp || + fxMesa->TexParams[tmu].minFilt != ti->minFilt || + fxMesa->TexParams[tmu].magFilt != ti->magFilt || + fxMesa->TexParams[tmu].mmMode != ti->mmMode || + fxMesa->TexParams[tmu].LODblend != FXFALSE || + fxMesa->TexParams[tmu].LodBias != ctx->Texture.Unit[tmu].LodBias) { + fxMesa->TexParams[tmu].sClamp = ti->sClamp; + fxMesa->TexParams[tmu].tClamp = ti->tClamp; + fxMesa->TexParams[tmu].minFilt = ti->minFilt; + fxMesa->TexParams[tmu].magFilt = ti->magFilt; + fxMesa->TexParams[tmu].mmMode = ti->mmMode; + fxMesa->TexParams[tmu].LODblend = FXFALSE; + fxMesa->TexParams[tmu].LodBias = ctx->Texture.Unit[tmu].LodBias; + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PARAMS; + } + + /* Glide texture source info */ + fxMesa->TexSource[0].Info = NULL; + fxMesa->TexSource[1].Info = NULL; + if (ti->tm[tmu]) { + fxMesa->TexSource[tmu].StartAddress = ti->tm[tmu]->startAddr; + fxMesa->TexSource[tmu].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu].Info = &(ti->info); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_SOURCE; + } + } + + fxMesa->sScale0 = ti->sScale; + fxMesa->tScale0 = ti->tScale; +} + +static void +selectSingleTMUSrc(tdfxContextPtr fxMesa, GLint tmu, FxBool LODblend) +{ + if (LODblend) { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE_MINUS_LOD_FRACTION; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + + if (fxMesa->haveTwoTMUs) { + const struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + const struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + int tmu; + + if (shared->umaTexMemory) + tmu = GR_TMU0; + else + tmu = GR_TMU1; + + fxMesa->TexCombine[tmu].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[tmu].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[tmu].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[tmu].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[tmu].InvertRGB = FXFALSE; + fxMesa->TexCombine[tmu].InvertAlpha = FXFALSE; + } + fxMesa->tmuSrc = TDFX_TMU_SPLIT; + } + else { + if (tmu != TDFX_TMU1) { + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + if (fxMesa->haveTwoTMUs) { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_ZERO; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_ZERO; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + } + fxMesa->tmuSrc = TDFX_TMU0; + } + else { + fxMesa->TexCombine[1].FunctionRGB = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorRGB = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].FunctionAlpha = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->TexCombine[1].FactorAlpha = GR_COMBINE_FACTOR_NONE; + fxMesa->TexCombine[1].InvertRGB = FXFALSE; + fxMesa->TexCombine[1].InvertAlpha = FXFALSE; + /* GR_COMBINE_FUNCTION_SCALE_OTHER doesn't work ?!? */ + fxMesa->TexCombine[0].FunctionRGB = GR_COMBINE_FUNCTION_BLEND; + fxMesa->TexCombine[0].FactorRGB = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].FunctionAlpha = GR_COMBINE_FUNCTION_BLEND; + fxMesa->TexCombine[0].FactorAlpha = GR_COMBINE_FACTOR_ONE; + fxMesa->TexCombine[0].InvertRGB = FXFALSE; + fxMesa->TexCombine[0].InvertAlpha = FXFALSE; + fxMesa->tmuSrc = TDFX_TMU1; + } + } + + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_ENV; +} + +static void print_state(tdfxContextPtr fxMesa) +{ + GLcontext *ctx = fxMesa->glCtx; + struct gl_texture_object *tObj0 = ctx->Texture.Unit[0].CurrentD[2]; + struct gl_texture_object *tObj1 = ctx->Texture.Unit[1].CurrentD[2]; + GLenum base0 = tObj0->Image[tObj0->BaseLevel] ? tObj0->Image[tObj0->BaseLevel]->Format : 99; + GLenum base1 = tObj1->Image[tObj1->BaseLevel] ? tObj1->Image[tObj1->BaseLevel]->Format : 99; + + printf("Unit 0: Enabled: GL=%d Gr=%d\n", ctx->Texture.Unit[0].ReallyEnabled, + fxMesa->TexState.Enabled); + printf(" EnvMode: GL=0x%x Gr=0x%x\n", ctx->Texture.Unit[0].EnvMode, + fxMesa->TexState.EnvMode[0]); + printf(" BaseFmt: GL=0x%x Gr=0x%x\n", base0, fxMesa->TexState.TexFormat[0]); + + + printf("Unit 1: Enabled: GL=%d Gr=%d\n", ctx->Texture.Unit[1].ReallyEnabled, + fxMesa->TexState.Enabled); + printf(" EnvMode: GL=0x%x Gr:0x%x\n", ctx->Texture.Unit[1].EnvMode, + fxMesa->TexState.EnvMode[1]); + printf(" BaseFmt: GL=0x%x Gr:0x%x\n", base1, fxMesa->TexState.TexFormat[1]); +} + + +/* + * When we're only using a single texture unit, we always use the 0th + * Glide/hardware unit, regardless if it's GL_TEXTURE0_ARB or GL_TEXTURE1_ARB + * that's enalbed. + * Input: ctx - the context + * unit - the OpenGL texture unit to use. + */ +static void setupTextureSingleTMU(GLcontext * ctx, GLuint unit) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxTexInfo *ti; + struct gl_texture_object *tObj; + int tmu; + GLenum envMode, baseFormat; + + tObj = ctx->Texture.Unit[unit].CurrentD[2]; + + if (!tObj->Image[tObj->BaseLevel]) { + fprintf(stderr, "tObj->Image[BaseLevel] is nil, how did this happen?!?\n"); + return; + } + + if (tObj->Image[tObj->BaseLevel]->Border > 0) { + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_BORDER; + return; + } + + setupSingleTMU(fxMesa, tObj); + + ti = TDFX_TEXTURE_DATA(tObj); + if (ti->whichTMU == TDFX_TMU_BOTH) + tmu = TDFX_TMU0; + else + tmu = ti->whichTMU; + + if (fxMesa->tmuSrc != tmu) { + selectSingleTMUSrc(fxMesa, tmu, ti->LODblend); + } + + if (ti->reloadImages) + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_IMAGES; + + /* Some texture environments not supported */ + fxMesa->Fallback &= ~TDFX_FALLBACK_TEXTURE_ENV; + + /* Check if we really need to update the texenv state */ + envMode = ctx->Texture.Unit[unit].EnvMode; + baseFormat = tObj->Image[tObj->BaseLevel]->Format; + + if (TDFX_IS_NAPALM(fxMesa)) { + /* see if we really need to update the unit */ + if (fxMesa->TexState.Enabled != ctx->Texture.ReallyEnabled || + envMode != fxMesa->TexState.EnvMode[0] || + envMode == GL_COMBINE_EXT || + baseFormat != fxMesa->TexState.TexFormat[0]) { + struct tdfx_texcombine_ext *otherEnv; + if (!SetupTexEnvNapalm(ctx, GL_TRUE, + &ctx->Texture.Unit[unit], baseFormat, + &fxMesa->TexCombineExt[0])) { + /* software fallback */ + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_ENV; + } + /* disable other unit */ + otherEnv = &fxMesa->TexCombineExt[1]; + otherEnv->Color.SourceA = GR_CMBX_ZERO; + otherEnv->Color.ModeA = GR_FUNC_MODE_ZERO; + otherEnv->Color.SourceB = GR_CMBX_ZERO; + otherEnv->Color.ModeB = GR_FUNC_MODE_ZERO; + otherEnv->Color.SourceC = GR_CMBX_ZERO; + otherEnv->Color.InvertC = FXFALSE; + otherEnv->Color.SourceD = GR_CMBX_ZERO; + otherEnv->Color.InvertD = FXFALSE; + otherEnv->Color.Shift = 0; + otherEnv->Color.Invert = FXFALSE; + otherEnv->Alpha.SourceA = GR_CMBX_ITALPHA; + otherEnv->Alpha.ModeA = GR_FUNC_MODE_ZERO; + otherEnv->Alpha.SourceB = GR_CMBX_ITALPHA; + otherEnv->Alpha.ModeB = GR_FUNC_MODE_ZERO; + otherEnv->Alpha.SourceC = GR_CMBX_ZERO; + otherEnv->Alpha.InvertC = FXFALSE; + otherEnv->Alpha.SourceD = GR_CMBX_ZERO; + otherEnv->Alpha.InvertD = FXFALSE; + otherEnv->Alpha.Shift = 0; + otherEnv->Alpha.Invert = FXFALSE; + + fxMesa->TexState.Enabled = ctx->Texture.ReallyEnabled; + fxMesa->TexState.EnvMode[0] = envMode; + fxMesa->TexState.TexFormat[0] = baseFormat; + fxMesa->TexState.EnvMode[1] = 0; + fxMesa->TexState.TexFormat[1] = 0; + } + } + else { + /* Voodoo3 */ + + /* see if we really need to update the unit */ + if (fxMesa->TexState.Enabled != ctx->Texture.ReallyEnabled || + envMode != fxMesa->TexState.EnvMode[0] || + envMode == GL_COMBINE_EXT || + baseFormat != fxMesa->TexState.TexFormat[0]) { + if (!SetupSingleTexEnvVoodoo3(ctx, tmu, envMode, baseFormat)) { + /* software fallback */ + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_ENV; + } + fxMesa->TexState.Enabled = ctx->Texture.ReallyEnabled; + fxMesa->TexState.EnvMode[0] = envMode; + fxMesa->TexState.TexFormat[0] = baseFormat; + fxMesa->TexState.EnvMode[1] = 0; + fxMesa->TexState.TexFormat[1] = 0; + } + } +} + + +static void +setupDoubleTMU(tdfxContextPtr fxMesa, + struct gl_texture_object *tObj0, + struct gl_texture_object *tObj1) +{ +#define T0_NOT_IN_TMU 0x01 +#define T1_NOT_IN_TMU 0x02 +#define T0_IN_TMU0 0x04 +#define T1_IN_TMU0 0x08 +#define T0_IN_TMU1 0x10 +#define T1_IN_TMU1 0x20 + + const struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + const struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + const GLcontext *ctx = fxMesa->glCtx; + tdfxTexInfo *ti0 = TDFX_TEXTURE_DATA(tObj0); + tdfxTexInfo *ti1 = TDFX_TEXTURE_DATA(tObj1); + GLuint tstate = 0; + int tmu0 = 0, tmu1 = 1; + + if (shared->umaTexMemory) { + if (!ti0->isInTM) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj0, TDFX_TMU0); + assert(ti0->isInTM); + } + if (!ti1->isInTM) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj1, TDFX_TMU0); + assert(ti1->isInTM); + } + } + else { + /* We shouldn't need to do this. There is something wrong with + multitexturing when the TMUs are swapped. So, we're forcing + them to always be loaded correctly. !!! */ + if (ti0->whichTMU == TDFX_TMU1) + tdfxTMMoveOutTM_NoLock(fxMesa, tObj0); + if (ti1->whichTMU == TDFX_TMU0) + tdfxTMMoveOutTM_NoLock(fxMesa, tObj1); + + if (ti0->isInTM) { + switch (ti0->whichTMU) { + case TDFX_TMU0: + tstate |= T0_IN_TMU0; + break; + case TDFX_TMU1: + tstate |= T0_IN_TMU1; + break; + case TDFX_TMU_BOTH: + tstate |= T0_IN_TMU0 | T0_IN_TMU1; + break; + case TDFX_TMU_SPLIT: + tstate |= T0_NOT_IN_TMU; + break; + } + } + else + tstate |= T0_NOT_IN_TMU; + + if (ti1->isInTM) { + switch (ti1->whichTMU) { + case TDFX_TMU0: + tstate |= T1_IN_TMU0; + break; + case TDFX_TMU1: + tstate |= T1_IN_TMU1; + break; + case TDFX_TMU_BOTH: + tstate |= T1_IN_TMU0 | T1_IN_TMU1; + break; + case TDFX_TMU_SPLIT: + tstate |= T1_NOT_IN_TMU; + break; + } + } + else + tstate |= T1_NOT_IN_TMU; + + /* Move texture maps into TMUs */ + + if (!(((tstate & T0_IN_TMU0) && (tstate & T1_IN_TMU1)) || + ((tstate & T0_IN_TMU1) && (tstate & T1_IN_TMU0)))) { + if (tObj0 == tObj1) { + tdfxTMMoveInTM_NoLock(fxMesa, tObj1, TDFX_TMU_BOTH); + } + else { + /* Find the minimal way to correct the situation */ + if ((tstate & T0_IN_TMU0) || (tstate & T1_IN_TMU1)) { + /* We have one in the standard order, setup the other */ + if (tstate & T0_IN_TMU0) { + /* T0 is in TMU0, put T1 in TMU1 */ + tdfxTMMoveInTM_NoLock(fxMesa, tObj1, TDFX_TMU1); + } + else { + tdfxTMMoveInTM_NoLock(fxMesa, tObj0, TDFX_TMU0); + } + /* tmu0 and tmu1 are setup */ + } + else if ((tstate & T0_IN_TMU1) || (tstate & T1_IN_TMU0)) { + /* we have one in the reverse order, setup the other */ + if (tstate & T1_IN_TMU0) { + /* T1 is in TMU0, put T0 in TMU1 */ + tdfxTMMoveInTM_NoLock(fxMesa, tObj0, TDFX_TMU1); + } + else { + tdfxTMMoveInTM_NoLock(fxMesa, tObj1, TDFX_TMU0); + } + tmu0 = 1; + tmu1 = 0; + } + else { /* Nothing is loaded */ + tdfxTMMoveInTM_NoLock(fxMesa, tObj0, TDFX_TMU0); + tdfxTMMoveInTM_NoLock(fxMesa, tObj1, TDFX_TMU1); + /* tmu0 and tmu1 are setup */ + } + } + } + } + + ti0->lastTimeUsed = fxMesa->texBindNumber; + ti1->lastTimeUsed = fxMesa->texBindNumber; + + + if (!ctx->Texture.SharedPalette) { + if (ti0->info.format == GR_TEXFMT_P_8) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti0->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + else if (ti1->info.format == GR_TEXFMT_P_8) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti1->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + else { + fxMesa->TexPalette.Data = NULL; + } + } + + /* + * Setup Unit 0 + */ + assert(ti0->isInTM); + assert(ti0->tm[tmu0]); + fxMesa->TexSource[tmu0].StartAddress = ti0->tm[tmu0]->startAddr; + fxMesa->TexSource[tmu0].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu0].Info = &(ti0->info); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_SOURCE; + + if (fxMesa->TexParams[tmu0].sClamp != ti0->sClamp || + fxMesa->TexParams[tmu0].tClamp != ti0->tClamp || + fxMesa->TexParams[tmu0].minFilt != ti0->minFilt || + fxMesa->TexParams[tmu0].magFilt != ti0->magFilt || + fxMesa->TexParams[tmu0].mmMode != ti0->mmMode || + fxMesa->TexParams[tmu0].LODblend != FXFALSE || + fxMesa->TexParams[tmu0].LodBias != ctx->Texture.Unit[tmu0].LodBias) { + fxMesa->TexParams[tmu0].sClamp = ti0->sClamp; + fxMesa->TexParams[tmu0].tClamp = ti0->tClamp; + fxMesa->TexParams[tmu0].minFilt = ti0->minFilt; + fxMesa->TexParams[tmu0].magFilt = ti0->magFilt; + fxMesa->TexParams[tmu0].mmMode = ti0->mmMode; + fxMesa->TexParams[tmu0].LODblend = FXFALSE; + fxMesa->TexParams[tmu0].LodBias = ctx->Texture.Unit[tmu0].LodBias; + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PARAMS; + } + + /* + * Setup Unit 1 + */ + if (shared->umaTexMemory) { + ASSERT(ti1->isInTM); + ASSERT(ti1->tm[0]); + fxMesa->TexSource[tmu1].StartAddress = ti1->tm[0]->startAddr; + fxMesa->TexSource[tmu1].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu1].Info = &(ti1->info); + } + else { + ASSERT(ti1->isInTM); + ASSERT(ti1->tm[tmu1]); + fxMesa->TexSource[tmu1].StartAddress = ti1->tm[tmu1]->startAddr; + fxMesa->TexSource[tmu1].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu1].Info = &(ti1->info); + } + + if (fxMesa->TexParams[tmu1].sClamp != ti1->sClamp || + fxMesa->TexParams[tmu1].tClamp != ti1->tClamp || + fxMesa->TexParams[tmu1].minFilt != ti1->minFilt || + fxMesa->TexParams[tmu1].magFilt != ti1->magFilt || + fxMesa->TexParams[tmu1].mmMode != ti1->mmMode || + fxMesa->TexParams[tmu1].LODblend != FXFALSE || + fxMesa->TexParams[tmu1].LodBias != ctx->Texture.Unit[tmu1].LodBias) { + fxMesa->TexParams[tmu1].sClamp = ti1->sClamp; + fxMesa->TexParams[tmu1].tClamp = ti1->tClamp; + fxMesa->TexParams[tmu1].minFilt = ti1->minFilt; + fxMesa->TexParams[tmu1].magFilt = ti1->magFilt; + fxMesa->TexParams[tmu1].mmMode = ti1->mmMode; + fxMesa->TexParams[tmu1].LODblend = FXFALSE; + fxMesa->TexParams[tmu1].LodBias = ctx->Texture.Unit[tmu1].LodBias; + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PARAMS; + } + + fxMesa->sScale0 = ti0->sScale; + fxMesa->tScale0 = ti0->tScale; + fxMesa->sScale1 = ti1->sScale; + fxMesa->tScale1 = ti1->tScale; + +#undef T0_NOT_IN_TMU +#undef T1_NOT_IN_TMU +#undef T0_IN_TMU0 +#undef T1_IN_TMU0 +#undef T0_IN_TMU1 +#undef T1_IN_TMU1 +} + +static void setupTextureDoubleTMU(GLcontext * ctx) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + struct gl_texture_object *tObj0 = ctx->Texture.Unit[0].CurrentD[2]; + struct gl_texture_object *tObj1 = ctx->Texture.Unit[1].CurrentD[2]; + tdfxTexInfo *ti0 = TDFX_TEXTURE_DATA(tObj0); + tdfxTexInfo *ti1 = TDFX_TEXTURE_DATA(tObj1); + struct gl_texture_image *baseImage0 = tObj0->Image[tObj0->BaseLevel]; + struct gl_texture_image *baseImage1 = tObj1->Image[tObj1->BaseLevel]; + const GLenum envMode0 = ctx->Texture.Unit[0].EnvMode; + const GLenum envMode1 = ctx->Texture.Unit[1].EnvMode; + + if (baseImage0->Border > 0 || baseImage1->Border >0) { + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_BORDER; + return; + } + + setupDoubleTMU(fxMesa, tObj0, tObj1); + + if (ti0->reloadImages || ti1->reloadImages) + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_IMAGES; + + fxMesa->tmuSrc = TDFX_TMU_BOTH; + + /* Some texture environments not supported */ + fxMesa->Fallback &= ~TDFX_FALLBACK_TEXTURE_ENV; + + if (TDFX_IS_NAPALM(fxMesa)) { + /* Remember, Glide has its texture units numbered in backward + * order compared to OpenGL. + */ + GLboolean hw1 = GL_TRUE, hw2 = GL_TRUE; + + /* check if we really need to update glide unit 1 */ + if (fxMesa->TexState.Enabled != ctx->Texture.ReallyEnabled || + envMode0 != fxMesa->TexState.EnvMode[1] || + envMode0 == GL_COMBINE_EXT || + baseImage0->Format != fxMesa->TexState.TexFormat[1] || + (fxMesa->Fallback & TDFX_FALLBACK_TEXTURE_ENV)) { + hw1 = SetupTexEnvNapalm(ctx, GL_TRUE, &ctx->Texture.Unit[0], + baseImage0->Format, &fxMesa->TexCombineExt[1]); + fxMesa->TexState.EnvMode[1] = envMode0; + fxMesa->TexState.TexFormat[1] = baseImage0->Format; + } + + /* check if we really need to update glide unit 0 */ + if (fxMesa->TexState.Enabled != ctx->Texture.ReallyEnabled || + envMode1 != fxMesa->TexState.EnvMode[0] || + envMode1 == GL_COMBINE_EXT || + baseImage1->Format != fxMesa->TexState.TexFormat[0] || + (fxMesa->Fallback & TDFX_FALLBACK_TEXTURE_ENV)) { + hw2 = SetupTexEnvNapalm(ctx, GL_FALSE, &ctx->Texture.Unit[1], + baseImage1->Format, &fxMesa->TexCombineExt[0]); + fxMesa->TexState.EnvMode[0] = envMode1; + fxMesa->TexState.TexFormat[0] = baseImage1->Format; + } + + fxMesa->TexState.Enabled = ctx->Texture.ReallyEnabled; + + if (!hw1 || !hw2) { + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_ENV; + } + } + else { + int unit0, unit1; + if ((ti0->whichTMU == TDFX_TMU1) || (ti1->whichTMU == TDFX_TMU0)) + unit0 = 1; + else + unit0 = 0; + unit1 = 1 - unit0; + + if (fxMesa->TexState.Enabled != ctx->Texture.ReallyEnabled || + envMode0 != fxMesa->TexState.EnvMode[unit0] || + envMode0 == GL_COMBINE_EXT || + envMode1 != fxMesa->TexState.EnvMode[unit1] || + envMode1 == GL_COMBINE_EXT || + baseImage0->Format != fxMesa->TexState.TexFormat[unit0] || + baseImage1->Format != fxMesa->TexState.TexFormat[unit1] || + (fxMesa->Fallback & TDFX_FALLBACK_TEXTURE_ENV)) { + + if (!SetupDoubleTexEnvVoodoo3(ctx, unit0, + ctx->Texture.Unit[0].EnvMode, baseImage0->Format, + ctx->Texture.Unit[1].EnvMode, baseImage1->Format)) { + fxMesa->Fallback |= TDFX_FALLBACK_TEXTURE_ENV; + } + + fxMesa->TexState.EnvMode[unit0] = envMode0; + fxMesa->TexState.TexFormat[unit0] = baseImage0->Format; + fxMesa->TexState.EnvMode[unit1] = envMode1; + fxMesa->TexState.TexFormat[unit1] = baseImage1->Format; + fxMesa->TexState.Enabled = ctx->Texture.ReallyEnabled; + } + } +} + + +void +tdfxUpdateTextureState( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + GLuint tex2Denabled = ctx->Texture.ReallyEnabled; + + if (!fxMesa->haveTwoTMUs) + tex2Denabled &= TEXTURE0_2D; + + switch (tex2Denabled) { + case TEXTURE0_2D: + LOCK_HARDWARE( fxMesa ); /* XXX remove locking eventually */ + setupTextureSingleTMU(ctx, 0); + UNLOCK_HARDWARE( fxMesa ); + break; + case TEXTURE1_2D: + LOCK_HARDWARE( fxMesa ); + setupTextureSingleTMU(ctx, 1); + UNLOCK_HARDWARE( fxMesa ); + break; + case (TEXTURE0_2D | TEXTURE1_2D): + LOCK_HARDWARE( fxMesa ); + setupTextureDoubleTMU(ctx); + UNLOCK_HARDWARE( fxMesa ); + break; + default: + /* disable hardware texturing */ + if (TDFX_IS_NAPALM(fxMesa)) { + fxMesa->ColorCombineExt.SourceA = GR_CMBX_ITRGB; + fxMesa->ColorCombineExt.ModeA = GR_FUNC_MODE_X; + fxMesa->ColorCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.ModeB = GR_FUNC_MODE_ZERO; + fxMesa->ColorCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertC = FXTRUE; + fxMesa->ColorCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->ColorCombineExt.InvertD = FXFALSE; + fxMesa->ColorCombineExt.Shift = 0; + fxMesa->ColorCombineExt.Invert = FXFALSE; + fxMesa->AlphaCombineExt.SourceA = GR_CMBX_ITALPHA; + fxMesa->AlphaCombineExt.ModeA = GR_FUNC_MODE_X; + fxMesa->AlphaCombineExt.SourceB = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.ModeB = GR_FUNC_MODE_ZERO; + fxMesa->AlphaCombineExt.SourceC = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertC = FXTRUE; + fxMesa->AlphaCombineExt.SourceD = GR_CMBX_ZERO; + fxMesa->AlphaCombineExt.InvertD = FXFALSE; + fxMesa->AlphaCombineExt.Shift = 0; + fxMesa->AlphaCombineExt.Invert = FXFALSE; + } + else { + /* Voodoo 3*/ + fxMesa->ColorCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->ColorCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->ColorCombine.Local = GR_COMBINE_LOCAL_ITERATED; + fxMesa->ColorCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->ColorCombine.Invert = FXFALSE; + fxMesa->AlphaCombine.Function = GR_COMBINE_FUNCTION_LOCAL; + fxMesa->AlphaCombine.Factor = GR_COMBINE_FACTOR_NONE; + fxMesa->AlphaCombine.Local = GR_COMBINE_LOCAL_ITERATED; + fxMesa->AlphaCombine.Other = GR_COMBINE_OTHER_NONE; + fxMesa->AlphaCombine.Invert = FXFALSE; + } + + fxMesa->TexState.Enabled = 0; + fxMesa->TexState.EnvMode[0] = 0; + fxMesa->TexState.EnvMode[1] = 0; + + fxMesa->dirty |= TDFX_UPLOAD_COLOR_COMBINE; + fxMesa->dirty |= TDFX_UPLOAD_ALPHA_COMBINE; + } +} + + + +/* + * This is a special case of texture state update. + * It's used when we've simply bound a new texture to a texture + * unit and the new texture has the exact same attributes as the + * previously bound texture. + * This is very common in Quake3. + */ +void +tdfxUpdateTextureBinding( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + struct gl_texture_object *tObj0 = ctx->Texture.Unit[0].CurrentD[2]; + struct gl_texture_object *tObj1 = ctx->Texture.Unit[1].CurrentD[2]; + tdfxTexInfo *ti0 = TDFX_TEXTURE_DATA(tObj0); + tdfxTexInfo *ti1 = TDFX_TEXTURE_DATA(tObj1); + + const struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared; + const struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData; + + if (ti0) { + fxMesa->sScale0 = ti0->sScale; + fxMesa->tScale0 = ti0->tScale; + if (ti0->info.format == GR_TEXFMT_P_8) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti0->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + else if (ti1 && ti1->info.format == GR_TEXFMT_P_8) { + fxMesa->TexPalette.Type = GR_TEXTABLE_PALETTE_6666_EXT; + fxMesa->TexPalette.Data = &(ti1->palette); + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE; + } + } + if (ti1) { + fxMesa->sScale1 = ti1->sScale; + fxMesa->tScale1 = ti1->tScale; + } + + if (ctx->Texture.ReallyEnabled == TEXTURE0_2D) { + if (shared->umaTexMemory) { + fxMesa->TexSource[0].StartAddress = ti0->tm[0]->startAddr; + fxMesa->TexSource[0].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[0].Info = &(ti0->info); + } + else { + if (ti0->LODblend && ti0->whichTMU == TDFX_TMU_SPLIT) { + fxMesa->TexSource[0].StartAddress = ti0->tm[TDFX_TMU0]->startAddr; + fxMesa->TexSource[0].EvenOdd = GR_MIPMAPLEVELMASK_ODD; + fxMesa->TexSource[0].Info = &(ti0->info); + fxMesa->TexSource[1].StartAddress = ti0->tm[TDFX_TMU1]->startAddr; + fxMesa->TexSource[1].EvenOdd = GR_MIPMAPLEVELMASK_EVEN; + fxMesa->TexSource[1].Info = &(ti0->info); + } + else { + FxU32 tmu; + if (ti0->whichTMU == TDFX_TMU_BOTH) + tmu = TDFX_TMU0; + else + tmu = ti0->whichTMU; + fxMesa->TexSource[0].Info = NULL; + fxMesa->TexSource[1].Info = NULL; + if (ti0->tm[tmu]) { + fxMesa->TexSource[tmu].StartAddress = ti0->tm[tmu]->startAddr; + fxMesa->TexSource[tmu].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu].Info = &(ti0->info); + } + } + } + } + else if (ctx->Texture.ReallyEnabled == TEXTURE1_2D) { + if (shared->umaTexMemory) { + fxMesa->TexSource[0].StartAddress = ti1->tm[0]->startAddr; + fxMesa->TexSource[0].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[0].Info = &(ti1->info); + } + } + else if (ctx->Texture.ReallyEnabled == (TEXTURE0_2D | TEXTURE1_2D)) { + if (shared->umaTexMemory) { + const FxU32 tmu0 = 0, tmu1 = 1; + fxMesa->TexSource[tmu0].StartAddress = ti0->tm[0]->startAddr; + fxMesa->TexSource[tmu0].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu0].Info = &(ti0->info); + + fxMesa->TexSource[tmu1].StartAddress = ti1->tm[0]->startAddr; + fxMesa->TexSource[tmu1].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu1].Info = &(ti1->info); + } + else { + const FxU32 tmu0 = 0, tmu1 = 1; + fxMesa->TexSource[tmu0].StartAddress = ti0->tm[tmu0]->startAddr; + fxMesa->TexSource[tmu0].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu0].Info = &(ti0->info); + + fxMesa->TexSource[tmu1].StartAddress = ti1->tm[tmu1]->startAddr; + fxMesa->TexSource[tmu1].EvenOdd = GR_MIPMAPLEVELMASK_BOTH; + fxMesa->TexSource[tmu1].Info = &(ti1->info); + } + } + + + fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_SOURCE; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.h new file mode 100644 index 000000000..0c0d4adcb --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_texstate.h @@ -0,0 +1,44 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#ifndef __TDFX_TEXSTATE_H__ +#define __TDFX_TEXSTATE_H__ + +extern void tdfxUpdateTextureState( GLcontext *ctx ); +extern void tdfxUpdateTextureBinding( GLcontext *ctx ); + +#endif diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.c new file mode 100644 index 000000000..21f7cdad3 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.c @@ -0,0 +1,508 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_tris.h" + +#include "pipeline.h" +#include "vbindirect.h" + +static struct { + points_func points; + line_func line; + triangle_func triangle; + quad_func quad; + render_func *render_tab; +} rast_tab[TDFX_MAX_TRIFUNC]; + +#define TDFX_COLOR( to, from ) \ + do { \ + (to)[0] = (from)[2]; \ + (to)[1] = (from)[1]; \ + (to)[2] = (from)[0]; \ + (to)[3] = (from)[3]; \ + } while (0) + + +static void tdfxPrintRenderState( const char *msg, GLuint state ) +{ + fprintf( stderr, "%s: (0x%x) %s%s%s%s\n", + msg, state, + (state & TDFX_FLAT_BIT) ? "flat, " : "", + (state & TDFX_OFFSET_BIT) ? "offset, " : "", + (state & TDFX_TWOSIDE_BIT) ? "twoside, " : "", + (state & TDFX_CLIPRECT_BIT) ? "cliprects, " : ""); +} + + +#define IND (0) +#define TAG(x) x +#include "tdfx_tritmp.h" + +#define IND (TDFX_FLAT_BIT) +#define TAG(x) x##_flat +#include "tdfx_tritmp.h" + +#define IND (TDFX_OFFSET_BIT) +#define TAG(x) x##_offset +#include "tdfx_tritmp.h" + +#define IND (TDFX_OFFSET_BIT | TDFX_FLAT_BIT) +#define TAG(x) x##_offset_flat +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT) +#define TAG(x) x##_twoside +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT) +#define TAG(x) x##_twoside_flat +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT) +#define TAG(x) x##_twoside_offset +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT | TDFX_FLAT_BIT) +#define TAG(x) x##_twoside_offset_flat +#include "tdfx_tritmp.h" + +#define IND (TDFX_CLIPRECT_BIT) +#define TAG(x) x##_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_FLAT_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_flat_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_OFFSET_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_offset_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_OFFSET_BIT | TDFX_FLAT_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_offset_flat_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_twoside_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_twoside_flat_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_twoside_offset_cliprect +#include "tdfx_tritmp.h" + +#define IND (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT | TDFX_FLAT_BIT | TDFX_CLIPRECT_BIT) +#define TAG(x) x##_twoside_offset_flat_cliprect +#include "tdfx_tritmp.h" + +static void tdfx_render_vb_points( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + GLint i; + (void) parity; + /* Adjust point coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x += PNT_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y += PNT_Y_OFFSET - TRI_Y_OFFSET; + } + grDrawVertexArrayContiguous( GR_POINTS, count-start, fxVB+start, + sizeof(*fxVB)); + /* restore point coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x -= PNT_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET; + } +} + +static void tdfx_render_vb_line_strip( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + GLint i; + (void) parity; + /* adjust line coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x += LINE_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; + } + grDrawVertexArrayContiguous( GR_LINE_STRIP, count-start, fxVB+start, + sizeof(*fxVB)); + /* restore line coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x -= LINE_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; + } +} + +static void tdfx_render_vb_lines( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + GLint i; + (void) parity; + /* adjust line coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x += LINE_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; + } + grDrawVertexArrayContiguous( GR_LINES, count-start, fxVB+start, + sizeof(*fxVB)); + /* restore line coords */ + for (i = start; i < count; i++) { + fxVB[i].v.x -= LINE_X_OFFSET - TRI_X_OFFSET; + fxVB[i].v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; + } +} + +static void tdfx_render_vb_triangles( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + grDrawVertexArrayContiguous( GR_TRIANGLES, count-start, fxVB+start, + sizeof(*fxVB)); + (void) parity; +} + + +static void tdfx_render_vb_tri_strip( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + grDrawVertexArrayContiguous( GR_TRIANGLE_STRIP, count-start, fxVB+start, + sizeof(*fxVB)); + (void) parity; +} + + +static void tdfx_render_vb_tri_fan( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + grDrawVertexArrayContiguous( GR_TRIANGLE_FAN, count-start, fxVB+start, + sizeof(*fxVB) ); + (void) parity; +} + + +static void tdfx_render_vb_poly( struct vertex_buffer *VB, + GLuint start, + GLuint count, + GLuint parity ) +{ + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + grDrawVertexArrayContiguous( GR_POLYGON, count-start, fxVB+start, + sizeof(*fxVB)); + (void) parity; +} + + +#define RENDER_POINTS( start, count ) \ +do { \ + int i; \ + for (i = start ; i < count ; i++) { \ + v[elt[i]].v.x += PNT_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i]].v.y += PNT_Y_OFFSET - TRI_Y_OFFSET; \ + grDrawPoint(&v[elt[i]]); \ + v[elt[i]].v.x -= PNT_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i]].v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET; \ + } \ +} while (0) + +#define RENDER_LINE( i0, i1 ) \ +do { \ + v[elt[i0]].v.x += LINE_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i0]].v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; \ + v[elt[i1]].v.x += LINE_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i1]].v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; \ + grDrawLine( &v[elt[i0]], &v[elt[i1]] ); \ + v[elt[i0]].v.x -= LINE_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i0]].v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \ + v[elt[i1]].v.x -= LINE_X_OFFSET - TRI_X_OFFSET; \ + v[elt[i1]].v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET; \ +} while (0) + +#define RENDER_TRI( i2, i1, i, pv, parity ) \ +do { \ + if (parity) grDrawTriangle( &v[elt[i1]], &v[elt[i2]], &v[elt[i]] ); \ + else grDrawTriangle( &v[elt[i2]], &v[elt[i1]], &v[elt[i]] ); \ +} while (0) + +#define RENDER_QUAD( i3, i2, i1, i, pv ) \ +do { \ + grDrawTriangle( &v[elt[i3]], &v[elt[i2]], &v[elt[i]] ); \ + grDrawTriangle( &v[elt[i2]], &v[elt[i1]], &v[elt[i]] ); \ +} while (0) + + +#define LOCAL_VARS \ + GLcontext *ctx = VB->ctx; \ + const GLuint *elt = VB->EltPtr->data; \ + tdfxVertexPtr v = TDFX_DRIVER_DATA(VB)->verts; \ + (void) v; (void) ctx; + +#define TAG(x) tdfx_##x##_elts +#include "render_tmp.h" + + +static void tdfxDDRenderEltsRaw( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + struct vertex_buffer *OldVB = ctx->VB; + GLenum prim = ctx->CVA.elt_mode; + GLuint nr = VB->EltPtr->count; + render_func func = tdfx_render_tab_elts[prim]; + GLuint p = 0; + + ctx->VB = VB; + ctx->Driver.RenderStart( ctx ); + + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); + do { + func( VB, 0, nr, 0 ); + } while ( ctx->Driver.MultipassFunc && + ctx->Driver.MultipassFunc( VB, ++p ) ); + END_CLIP_LOOP_LOCKED( fxMesa ); + + ctx->Driver.RenderFinish( ctx ); + ctx->VB = OldVB; +} + + +void tdfxDDTriangleFuncsInit( void ) +{ + init(); + init_flat(); + init_offset(); + init_offset_flat(); + init_twoside(); + init_twoside_flat(); + init_twoside_offset(); + init_twoside_offset_flat(); + + init_cliprect(); + init_flat_cliprect(); + init_offset_cliprect(); + init_offset_flat_cliprect(); + init_twoside_cliprect(); + init_twoside_flat_cliprect(); + init_twoside_offset_cliprect(); + init_twoside_offset_flat_cliprect(); + + rast_tab[0].render_tab[GL_POINTS] = tdfx_render_vb_points; + rast_tab[0].render_tab[GL_LINE_STRIP] = tdfx_render_vb_line_strip; + rast_tab[0].render_tab[GL_LINES] = tdfx_render_vb_lines; + rast_tab[0].render_tab[GL_TRIANGLES] = tdfx_render_vb_triangles; + rast_tab[0].render_tab[GL_TRIANGLE_STRIP] = tdfx_render_vb_tri_strip; + rast_tab[0].render_tab[GL_TRIANGLE_FAN] = tdfx_render_vb_tri_fan; + rast_tab[0].render_tab[GL_POLYGON] = tdfx_render_vb_poly; + + tdfx_render_init_elts(); +} + + +#define ALL_FALLBACK (DD_SELECT | DD_FEEDBACK) +#define POINT_FALLBACK (ALL_FALLBACK | DD_POINT_SMOOTH | DD_POINT_ATTEN) +#define LINE_FALLBACK (ALL_FALLBACK | DD_LINE_STIPPLE) +#define TRI_FALLBACK (ALL_FALLBACK | DD_TRI_SMOOTH | DD_TRI_UNFILLED) +#define ANY_FALLBACK (POINT_FALLBACK | LINE_FALLBACK | TRI_FALLBACK | DD_TRI_STIPPLE | DD_LINE_SMOOTH | DD_LINE_WIDTH | DD_POINT_SIZE ) +#define ANY_RENDER_FLAGS (DD_FLATSHADE | DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET) + +/* Setup the Point, Line, Triangle and Quad functions based on the + * current rendering state. Wherever possible, use the hardware to + * render the primitive. Otherwise, fallback to software rendering. + */ +void tdfxDDChooseRenderState( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + GLuint flags = ctx->TriangleCaps; + CARD32 index = 0; + fxMesa->RenderElementsRaw = tdfxDDRenderEltsRaw; + + if ( fxMesa->Fallback ) { + fxMesa->RenderElementsRaw = gl_render_elts; + fxMesa->RenderIndex = TDFX_FALLBACK_BIT; + return; + } + + if ( flags & ANY_RENDER_FLAGS ) { + if ( flags & DD_FLATSHADE ) index |= TDFX_FLAT_BIT; + if ( flags & DD_TRI_LIGHT_TWOSIDE ) index |= TDFX_TWOSIDE_BIT; + if ( flags & DD_TRI_OFFSET ) index |= TDFX_OFFSET_BIT; + fxMesa->RenderElementsRaw = gl_render_elts; + } + + if ( fxMesa->numClipRects > 1 ) + index |= TDFX_CLIPRECT_BIT; + + fxMesa->PointsFunc = rast_tab[index].points; + fxMesa->LineFunc = rast_tab[index].line; + fxMesa->TriangleFunc = rast_tab[index].triangle; + fxMesa->QuadFunc = rast_tab[index].quad; + fxMesa->RenderVBRawTab = rast_tab[index].render_tab; + fxMesa->RenderIndex = index; + fxMesa->IndirectTriangles = 0; + + if ( flags & ANY_FALLBACK ) { + if ( flags & POINT_FALLBACK ) { + fxMesa->PointsFunc = 0; + fxMesa->RenderVBRawTab = 0; + fxMesa->IndirectTriangles |= DD_POINT_SW_RASTERIZE; + fxMesa->RenderIndex |= TDFX_FALLBACK_BIT; + } + + if ( flags & LINE_FALLBACK ) { + fxMesa->LineFunc = 0; + fxMesa->RenderVBRawTab = 0; + fxMesa->IndirectTriangles |= DD_LINE_SW_RASTERIZE; + fxMesa->RenderIndex |= TDFX_FALLBACK_BIT; + } + + if ( flags & TRI_FALLBACK ) { + fxMesa->TriangleFunc = 0; + fxMesa->QuadFunc = 0; + fxMesa->RenderVBRawTab = 0; + fxMesa->IndirectTriangles |= (DD_TRI_SW_RASTERIZE | + DD_QUAD_SW_RASTERIZE); + fxMesa->RenderIndex |= TDFX_FALLBACK_BIT; + } + + /* Special case: wide, AA lines must be done in software */ + if (flags & DD_LINE_SMOOTH) { + if (ctx->Line.Width != 1.0) { + fxMesa->RenderVBRawTab = 0; + fxMesa->LineFunc = 0; + fxMesa->IndirectTriangles |= DD_LINE_SW_RASTERIZE; + fxMesa->RenderIndex |= TDFX_FALLBACK_BIT; + } + } + + /* Special case: we can do polygon stipples, but otherwise */ + if ((flags & DD_TRI_STIPPLE) && + (ctx->IndirectTriangles & DD_TRI_STIPPLE)) { + fxMesa->TriangleFunc = 0; + fxMesa->QuadFunc = 0; + fxMesa->RenderVBRawTab = 0; + fxMesa->IndirectTriangles |= (DD_TRI_SW_RASTERIZE | + DD_QUAD_SW_RASTERIZE); + fxMesa->RenderIndex |= TDFX_FALLBACK_BIT; + } + + if (flags & (DD_LINE_WIDTH | DD_POINT_SIZE)) + fxMesa->RenderVBRawTab = 0; + + fxMesa->RenderElementsRaw = gl_render_elts; + } + + + if ( 0 ) { + gl_print_tri_caps( "tricaps", ctx->TriangleCaps ); + tdfxPrintRenderState( "tdfx render state", fxMesa->RenderIndex ); + } +} + + +void tdfxDDToggleTriCliprects( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + int oldidx = fxMesa->RenderIndex; + int newidx; + + if (fxMesa->Fallback) + return; + + if (fxMesa->numClipRects > 1) + newidx = (fxMesa->RenderIndex |= TDFX_CLIPRECT_BIT); + else + newidx = (fxMesa->RenderIndex &= ~TDFX_CLIPRECT_BIT); + + if (ctx->Driver.TriangleFunc == rast_tab[oldidx].triangle) + ctx->Driver.TriangleFunc = rast_tab[newidx].triangle; + + if (ctx->Driver.QuadFunc == rast_tab[oldidx].quad) + ctx->Driver.QuadFunc = rast_tab[newidx].quad; + + if (ctx->Driver.LineFunc == rast_tab[oldidx].line) + ctx->Driver.LineFunc = rast_tab[newidx].line; + + if (ctx->Driver.PointsFunc == rast_tab[oldidx].points) + ctx->Driver.PointsFunc = rast_tab[newidx].points; + + if (ctx->Driver.RenderVBRawTab == rast_tab[oldidx].render_tab) + ctx->Driver.RenderVBRawTab = rast_tab[newidx].render_tab; + + if (ctx->TriangleFunc == rast_tab[oldidx].triangle) + ctx->TriangleFunc = rast_tab[newidx].triangle; + + if (ctx->QuadFunc == rast_tab[oldidx].quad) + ctx->QuadFunc = rast_tab[newidx].quad; + + fxMesa->PointsFunc = rast_tab[newidx].points; + fxMesa->LineFunc = rast_tab[newidx].line; + fxMesa->TriangleFunc = rast_tab[newidx].triangle; + fxMesa->QuadFunc = rast_tab[newidx].quad; + fxMesa->RenderVBRawTab = rast_tab[newidx].render_tab; + + if (newidx == 0 && + (ctx->IndirectTriangles & (DD_LINE_WIDTH|DD_POINT_SIZE)) == 0) + fxMesa->RenderElementsRaw = tdfxDDRenderEltsRaw; + else + fxMesa->RenderElementsRaw = gl_render_elts; + + if (0) + tdfxPrintRenderState( "toggle tdfx render state", fxMesa->RenderIndex ); +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.h new file mode 100644 index 000000000..1de26cefa --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tris.h @@ -0,0 +1,176 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#ifndef __TDFX_TRIS_H__ +#define __TDFX_TRIS_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "tdfx_vb.h" +#include "tdfx_render.h" + +extern void tdfxDDChooseRenderState( GLcontext *ctx ); +extern void tdfxDDTriangleFuncsInit( void ); + + +#define TDFX_FLAT_BIT 0x01 +#define TDFX_OFFSET_BIT 0x02 +#define TDFX_TWOSIDE_BIT 0x04 +#define TDFX_CLIPRECT_BIT 0x10 +#define TDFX_FALLBACK_BIT 0x20 +#define TDFX_MAX_TRIFUNC 0x40 + + +static __inline void tdfx_draw_triangle( tdfxContextPtr fxMesa, + tdfxVertex *v0, + tdfxVertex *v1, + tdfxVertex *v2 ) +{ + grDrawTriangle( v0, v1, v2 ); +} + + +static __inline void tdfx_draw_point( tdfxContextPtr fxMesa, + tdfxVertex *tmp, float sz ) +{ + if ( sz <= 1.0 ) { + /* Save and restore original x,y rather than copying whole + * vertex. + */ + GLfloat x = tmp->v.x, y = tmp->v.y; + tmp->v.x += PNT_X_OFFSET - TRI_X_OFFSET; + tmp->v.y += PNT_Y_OFFSET - TRI_Y_OFFSET; + grDrawPoint( tmp ); + tmp->v.x = x; + tmp->v.y = y; + } + else { + const GLfloat xLeft = tmp->v.x - 0.5 * sz - TRI_X_OFFSET + PNT_X_OFFSET; + const GLfloat xRight = tmp->v.x + 0.5 * sz - TRI_X_OFFSET + PNT_X_OFFSET; + const GLfloat yBot = tmp->v.y - 0.5 * sz - TRI_Y_OFFSET + PNT_Y_OFFSET; + const GLfloat yTop = tmp->v.y + 0.5 * sz - TRI_Y_OFFSET + PNT_Y_OFFSET; + tdfxVertex verts[4]; + + verts[0] = *tmp; + verts[1] = *tmp; + verts[2] = *tmp; + verts[3] = *tmp; + + verts[0].v.x = xLeft; + verts[0].v.y = yBot; + + verts[1].v.x = xRight; + verts[1].v.y = yBot; + + verts[2].v.x = xRight; + verts[2].v.y = yTop; + + verts[3].v.x = xLeft; + verts[3].v.y = yTop; + + grDrawVertexArrayContiguous( GR_TRIANGLE_FAN, 4, verts, + sizeof(tdfxVertex) ); + } +} + + +static __inline void tdfx_draw_line( tdfxContextPtr fxMesa, + tdfxVertex *tmp0, + tdfxVertex *tmp1, + float width ) +{ + if ( width <= 1.0 ) + { + /* Faster to save and restore 4 dwords than to copy 32 dwords. + */ + GLfloat x0 = tmp0->v.x, y0 = tmp0->v.y; + GLfloat x1 = tmp1->v.x, y1 = tmp1->v.y; + tmp0->v.x += LINE_X_OFFSET - TRI_X_OFFSET; + tmp0->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; + tmp1->v.x += LINE_X_OFFSET - TRI_X_OFFSET; + tmp1->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET; + grDrawLine(tmp0, tmp1); + tmp0->v.x = x0; + tmp0->v.y = y0; + tmp1->v.x = x1; + tmp1->v.y = y1; + } + else + { + tdfxVertex verts[4]; + float dx, dy, ix, iy; + + dx = tmp0->v.x - tmp1->v.x; + dy = tmp0->v.y - tmp1->v.y; + + if (dx * dx > dy * dy) { + iy = width * .5; + ix = 0; + } else { + iy = 0; + ix = width * .5; + } + + verts[0] = *tmp0; + verts[1] = *tmp0; + verts[2] = *tmp1; + verts[3] = *tmp1; + + verts[0].v.x = tmp0->v.x - ix; + verts[0].v.y = tmp0->v.y - iy; + + verts[1].v.x = tmp0->v.x + ix; + verts[1].v.y = tmp0->v.y + iy; + + verts[2].v.x = tmp1->v.x + ix; + verts[2].v.y = tmp1->v.y + iy; + + verts[3].v.x = tmp1->v.x - ix; + verts[3].v.y = tmp1->v.y - iy; + + grDrawVertexArrayContiguous( GR_TRIANGLE_FAN, 4, verts, + sizeof(tdfxVertex) ); + } +} + +void tdfxDDToggleTriCliprects( GLcontext *ctx ); + + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* __TDFX_TRIS_H__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tritmp.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tritmp.h new file mode 100644 index 000000000..a1039c99c --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_tritmp.h @@ -0,0 +1,422 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +static __inline void TAG(triangle)( GLcontext *ctx, + GLuint e0, GLuint e1, GLuint e2, + GLuint pv ) +{ + struct vertex_buffer *VB = ctx->VB; + tdfxVertexPtr fxverts = TDFX_DRIVER_DATA(VB)->verts; + tdfxVertex *v[3]; + +#if (IND & TDFX_OFFSET_BIT) + GLfloat offset; + GLfloat z[3]; +#endif + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT)) + GLuint c[3]; +#endif + +#if (IND & TDFX_CLIPRECT_BIT) + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); +#endif + + v[0] = &fxverts[e0]; + v[1] = &fxverts[e1]; + v[2] = &fxverts[e2]; + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT)) + c[0] = v[0]->ui[4]; + c[1] = v[1]->ui[4]; + c[2] = v[2]->ui[4]; +#endif + + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT)) + { + GLfloat ex = v[0]->v.x - v[2]->v.x; + GLfloat ey = v[0]->v.y - v[2]->v.y; + GLfloat fx = v[1]->v.x - v[2]->v.x; + GLfloat fy = v[1]->v.y - v[2]->v.y; + GLfloat cc = ex*fy - ey*fx; + +#if (IND & TDFX_TWOSIDE_BIT) + { + GLuint facing = ( cc < 0.0 ) ^ ctx->Polygon.FrontBit; + GLubyte (*vbcolor)[4] = VB->Color[facing]->data; + if (IND & TDFX_FLAT_BIT) { + TDFX_COLOR( (char *)&v[0]->ui[4], vbcolor[pv] ); + v[2]->ui[4] = v[1]->ui[4] = v[0]->ui[4]; + } else { + TDFX_COLOR( (char *)&v[0]->ui[4], vbcolor[e0] ); + TDFX_COLOR( (char *)&v[1]->ui[4], vbcolor[e1] ); + TDFX_COLOR( (char *)&v[2]->ui[4], vbcolor[e2] ); + } + } +#endif + +#if (IND & TDFX_OFFSET_BIT) + { + offset = ctx->Polygon.OffsetUnits; + z[0] = v[0]->v.z; + z[1] = v[1]->v.z; + z[2] = v[2]->v.z; + if (cc * cc > 1e-16) { + GLfloat ez = z[0] - z[2]; + GLfloat fz = z[1] - z[2]; + GLfloat a = ey*fz - ez*fy; + GLfloat b = ez*fx - ex*fz; + GLfloat ic = 1.0 / cc; + GLfloat ac = a * ic; + GLfloat bc = b * ic; + if ( ac < 0.0f ) ac = -ac; + if ( bc < 0.0f ) bc = -bc; + offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor; + + } + v[0]->v.z += offset; + v[1]->v.z += offset; + v[2]->v.z += offset; + } +#endif + } +#elif (IND & TDFX_FLAT_BIT) + { + GLuint color = fxverts[pv].ui[4]; + v[0]->ui[4] = color; + v[1]->ui[4] = color; + v[2]->ui[4] = color; + } +#endif + +#if (IND & TDFX_CLIPRECT_BIT) + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); + grDrawTriangle( v[0], v[1], v[2] ); + END_CLIP_LOOP_LOCKED( fxMesa ); +#else + grDrawTriangle( v[0], v[1], v[2] ); +#endif + +#if (IND & TDFX_OFFSET_BIT) + v[0]->v.z = z[0]; + v[1]->v.z = z[1]; + v[2]->v.z = z[2]; +#endif + +#if (IND & (TDFX_FLAT_BIT | TDFX_TWOSIDE_BIT)) + v[0]->ui[4] = c[0]; + v[1]->ui[4] = c[1]; + v[2]->ui[4] = c[2]; +#endif + +} + + + +static __inline void TAG(quad)( GLcontext *ctx, GLuint e0, + GLuint e1, GLuint e2, GLuint e3, + GLuint pv ) +{ + struct vertex_buffer *VB = ctx->VB; + tdfxVertexPtr fxverts = TDFX_DRIVER_DATA(VB)->verts; + tdfxVertex *v[4]; + +#if (IND & TDFX_OFFSET_BIT) + GLfloat offset; + GLfloat z[4]; +#endif + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT)) + GLuint c[4]; +#endif + +#if (IND & TDFX_CLIPRECT_BIT) + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); +#endif + + + v[0] = &fxverts[e0]; + v[1] = &fxverts[e1]; + v[2] = &fxverts[e2]; + v[3] = &fxverts[e3]; + + +/* fprintf(stderr, "%s\n", __FUNCTION__); */ + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_FLAT_BIT)) + c[0] = v[0]->ui[4]; + c[1] = v[1]->ui[4]; + c[2] = v[2]->ui[4]; + c[3] = v[3]->ui[4]; +#endif + + +#if (IND & (TDFX_TWOSIDE_BIT | TDFX_OFFSET_BIT)) + { + GLfloat ex = v[0]->v.x - v[2]->v.x; + GLfloat ey = v[0]->v.y - v[2]->v.y; + GLfloat fx = v[1]->v.x - v[2]->v.x; + GLfloat fy = v[1]->v.y - v[2]->v.y; + GLfloat cc = ex*fy - ey*fx; + +#if (IND & TDFX_TWOSIDE_BIT) + { + GLuint facing = ( cc < 0.0 ) ^ ctx->Polygon.FrontBit; + GLubyte (*vbcolor)[4] = VB->Color[facing]->data; + if (IND & TDFX_FLAT_BIT) { + TDFX_COLOR( (char *)&v[0]->ui[4], vbcolor[pv] ); + v[3]->ui[4] = v[2]->ui[4] = v[1]->ui[4] = v[0]->ui[4]; + } else { + TDFX_COLOR( (char *)&v[0]->ui[4], vbcolor[e0] ); + TDFX_COLOR( (char *)&v[1]->ui[4], vbcolor[e1] ); + TDFX_COLOR( (char *)&v[2]->ui[4], vbcolor[e2] ); + TDFX_COLOR( (char *)&v[3]->ui[4], vbcolor[e3] ); + } + } +#endif + +#if (IND & TDFX_OFFSET_BIT) + { + offset = ctx->Polygon.OffsetUnits; + z[0] = v[0]->v.z; + z[1] = v[1]->v.z; + z[2] = v[2]->v.z; + z[3] = v[3]->v.z; + if (cc * cc > 1e-16) { + GLfloat ez = z[0] - z[2]; + GLfloat fz = z[1] - z[2]; + GLfloat a = ey*fz - ez*fy; + GLfloat b = ez*fx - ex*fz; + GLfloat ic = 1.0 / cc; + GLfloat ac = a * ic; + GLfloat bc = b * ic; + if ( ac < 0.0f ) ac = -ac; + if ( bc < 0.0f ) bc = -bc; + offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor; + + } + v[0]->v.z += offset; + v[1]->v.z += offset; + v[2]->v.z += offset; + v[3]->v.z += offset; + } +#endif + } +#elif (IND & TDFX_FLAT_BIT) + { + GLuint color = fxverts[pv].ui[4]; + v[0]->ui[4] = color; + v[1]->ui[4] = color; + v[2]->ui[4] = color; + v[3]->ui[4] = color; + } +#endif + +/* Marginally faster to call grDrawTriangle twice + * than calling grDrawVertexArray. + */ +#if (IND & TDFX_CLIPRECT_BIT) + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); +/* grDrawVertexArray( GR_TRIANGLE_FAN, 4, v ); */ + grDrawTriangle( v[0], v[1], v[3] ); + grDrawTriangle( v[1], v[2], v[3] ); + END_CLIP_LOOP_LOCKED( fxMesa ); +#else +/* grDrawVertexArray( GR_TRIANGLE_FAN, 4, v ); */ + grDrawTriangle( v[0], v[1], v[3] ); + grDrawTriangle( v[1], v[2], v[3] ); +#endif + +#if (IND & TDFX_OFFSET_BIT) + v[0]->v.z = z[0]; + v[1]->v.z = z[1]; + v[2]->v.z = z[2]; + v[3]->v.z = z[3]; +#endif + +#if (IND & (TDFX_FLAT_BIT | TDFX_TWOSIDE_BIT)) + v[0]->ui[4] = c[0]; + v[1]->ui[4] = c[1]; + v[2]->ui[4] = c[2]; + v[3]->ui[4] = c[3]; +#endif +} + + + + + +static __inline void TAG(line)( GLcontext *ctx, GLuint v0, GLuint v1, + GLuint pv ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(ctx->VB)->verts; + float width = ctx->Line.Width; + GLfloat z0, z1; + GLuint c0, c1; + tdfxVertex *vert0 = &fxVB[v0]; + tdfxVertex *vert1 = &fxVB[v1]; + + if ( IND & TDFX_TWOSIDE_BIT ) { + GLubyte (*vbcolor)[4] = ctx->VB->ColorPtr->data; + + if ( IND & TDFX_FLAT_BIT ) { + TDFX_COLOR( (char *)&vert0->v.color,vbcolor[pv] ); + *(int *)&vert1->v.color = *(int *)&vert0->v.color; + } else { + TDFX_COLOR( (char *)&vert0->v.color,vbcolor[v0] ); + TDFX_COLOR( (char *)&vert1->v.color,vbcolor[v1] ); + } + } else if ( IND & TDFX_FLAT_BIT ) { + c0 = *(GLuint *) &(vert0->v.color); + c1 = *(GLuint *) &(vert1->v.color); + *(int *)&vert0->v.color = + *(int *)&vert1->v.color = *(int *)&fxVB[pv].v.color; + } + + if ( IND & TDFX_OFFSET_BIT ) { + GLfloat offset = ctx->LineZoffset; + z0 = vert0->v.z; + z1 = vert1->v.z; + vert0->v.z += offset; + vert1->v.z += offset; + } + + if (IND & TDFX_CLIPRECT_BIT) { + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); + tdfx_draw_line( fxMesa, &fxVB[v0], &fxVB[v1], width ); + END_CLIP_LOOP_LOCKED( fxMesa ); + } else + tdfx_draw_line( fxMesa, &fxVB[v0], &fxVB[v1], width ); + + if ( IND & TDFX_OFFSET_BIT ) { + vert0->v.z = z0; + vert1->v.z = z1; + } + + if ( (IND & TDFX_FLAT_BIT) && !(IND & TDFX_TWOSIDE_BIT) ) { + *(GLuint *) &(vert0->v.color) = c0; + *(GLuint *) &(vert1->v.color) = c1; + } +} + + +static __inline void TAG(points)( GLcontext *ctx, GLuint first, GLuint last ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + struct vertex_buffer *VB = ctx->VB; + tdfxVertexPtr fxVB = TDFX_DRIVER_DATA(VB)->verts; + GLfloat sz = ctx->Point.Size; + int i; + + for ( i = first ; i < last ; i++ ) { + if ( VB->ClipMask[i] == 0 ) { + if ( IND & (TDFX_TWOSIDE_BIT|TDFX_OFFSET_BIT) ) + { + tdfxVertex tmp0 = fxVB[i]; + + if ( IND & TDFX_TWOSIDE_BIT ) { + GLubyte (*vbcolor)[4] = VB->ColorPtr->data; + TDFX_COLOR( (char *)&tmp0.v.color, vbcolor[i] ); + } + + if ( IND & TDFX_OFFSET_BIT ) { + GLfloat offset = ctx->PointZoffset; + tmp0.v.z += offset; + } + + if (IND & TDFX_CLIPRECT_BIT) { + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); + tdfx_draw_point( fxMesa, &tmp0, sz ); + END_CLIP_LOOP_LOCKED( fxMesa ); + } else + tdfx_draw_point( fxMesa, &tmp0, sz ); + } + else if (IND & TDFX_CLIPRECT_BIT) + { + BEGIN_CLIP_LOOP_LOCKED( fxMesa ); + tdfx_draw_point( fxMesa, &fxVB[i], sz ); + END_CLIP_LOOP_LOCKED( fxMesa ); + } + else + tdfx_draw_point( fxMesa, &fxVB[i], sz ); + } + } +} + + + + +/* Accelerate unclipped VB rendering when fxMesa->renderIndex != 0 + * + * The versions for renderIndex == 0 are further optimized and appear + * in tdfx_tris.c + */ +#if (TYPE == 0) +#define RENDER_POINTS( start, count ) TAG(points)( ctx, start, count ) +#define RENDER_LINE( i1, i ) TAG(line)( ctx, i1, i, i ) +#define RENDER_TRI( i2, i1, i, pv, parity ) \ + do { \ + if (parity) TAG(triangle)( ctx, i1, i2, i, pv ); \ + else TAG(triangle)( ctx, i2, i1, i, pv ); \ + } while (0) +#define RENDER_QUAD( i3, i2, i1, i, pv ) TAG(quad)( ctx, i3, i2, i1, i, pv ) +#define LOCAL_VARS GLcontext *ctx = VB->ctx; +#define PRESERVE_TAG +#include "render_tmp.h" +#endif + + + +static void TAG(init)( void ) +{ + rast_tab[IND].triangle = TAG(triangle); + rast_tab[IND].quad = TAG(quad); + rast_tab[IND].line = TAG(line); + rast_tab[IND].points = TAG(points); +#if (TYPE == 0) + rast_tab[IND].render_tab = TAG(render_tab); +#else + rast_tab[IND].render_tab = 0; +#endif + TAG(render_init)(); +} + + +#undef IND +#undef TAG diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.c new file mode 100644 index 000000000..a5cb9b6bc --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.c @@ -0,0 +1,498 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#include "tdfx_context.h" +#include "tdfx_vb.h" + +#include "stages.h" +#include "mem.h" + + +#define COORD \ +do { \ + v->v.x = winCoord[0] + xoffset; \ + v->v.y = winCoord[1] + yoffset; \ + v->v.z = winCoord[2]; \ + v->v.rhw = w; \ +} while (0) + + +/* The assembly is slower... + */ +#if 0 && defined(USE_X86_ASM) +#define COL \ +do { \ + __asm__ ( \ + "movl (%%edx),%%eax \n" \ + "bswap %%eax \n" \ + "rorl $8,%%eax \n" \ + "movl %%eax,16(%%edi) \n" \ + : \ + : "d" (color), "D" (v) \ + : "%eax" ); \ +} while (0) +#else +#define COL \ +do { \ + v->v.color.blue = color[2]; \ + v->v.color.green = color[1]; \ + v->v.color.red = color[0]; \ + v->v.color.alpha = color[3]; \ +} while (0) +#endif + + +#define TEX0 \ +do { \ + v->v.tu0 = tc0[i][0] * sScale0 * w; \ + v->v.tv0 = tc0[i][1] * tScale0 * w; \ +} while (0) + +#define TEX1 \ +do { \ + v->v.tu1 = tc1[i][0] * sScale1 * w; \ + v->v.tv1 = tc1[i][1] * tScale1 * w; \ +} while (0) + + +#define TEX0_4 \ + if ( VB->TexCoordPtr[0]->size == 4 ) { \ + GLfloat (*tc)[4] = VB->TexCoordPtr[0]->data; \ + winCoord = VB->Win.data[start]; \ + v = &(TDFX_DRIVER_DATA(VB)->verts[start]); \ + for ( i = start ; i < end ; i++, v++, winCoord+=4 ) { \ + v->v.tq0 = tc[i][3] * winCoord[3]; \ + } \ + } + +#define TEX1_4 \ + if ( VB->TexCoordPtr[1]->size == 4 ) { \ + GLfloat (*tc)[4] = VB->TexCoordPtr[1]->data; \ + winCoord = VB->Win.data[start]; \ + v = &(TDFX_DRIVER_DATA(VB)->verts[start]); \ + for ( i = start ; i < end ; i++, v++, winCoord+=4 ) { \ + v->v.tq1 = tc[i][3] * winCoord[3]; \ + } \ + } + + +#define FOG + + +#define NOP + + + +#define SETUPFUNC(name,win,col,tex0,tex1,tex0_4,tex1_4,fog) \ +static void name( struct vertex_buffer *VB, GLuint start, GLuint end ) \ +{ \ + tdfxContextPtr fxMesa = TDFX_CONTEXT(VB->ctx); \ + tdfxVertexPtr v; \ + const GLfloat *winCoord; \ + GLfloat (*tc0)[4]; \ + GLfloat (*tc1)[4]; \ + const GLfloat xoffset = fxMesa->x_offset + TRI_X_OFFSET; \ + const GLfloat yoffset = fxMesa->y_delta + TRI_Y_OFFSET; \ + const GLfloat sScale0 = fxMesa->sScale0; \ + const GLfloat tScale0 = fxMesa->tScale0; \ + const GLfloat sScale1 = fxMesa->sScale1; \ + const GLfloat tScale1 = fxMesa->tScale1; \ + const GLubyte *color; \ + int i; \ + \ + (void) xoffset; (void) yoffset; \ + (void) sScale0; (void) tScale0; \ + (void) sScale1; (void) tScale1; \ + \ + if (0) fprintf(stderr, "%s\n", __FUNCTION__); \ + gl_import_client_data( VB, VB->ctx->RenderFlags, \ + (VB->ClipOrMask \ + ? VEC_WRITABLE|VEC_GOOD_STRIDE \ + : VEC_GOOD_STRIDE)); \ + \ + tc0 = VB->TexCoordPtr[fxMesa->tmu_source[0]]->data; \ + tc1 = VB->TexCoordPtr[fxMesa->tmu_source[1]]->data; \ + color = VB->Color[0]->data[start]; \ + winCoord = VB->Win.data[start]; \ + \ + v = &(TDFX_DRIVER_DATA(VB)->verts[start]); \ + \ + if ( VB->ClipOrMask == 0 ) { \ + for ( i = start ; i < end ; i++, v++, color+=4, winCoord+=4 ) { \ + const GLfloat w = winCoord[3]; \ + (void) w; \ + win; \ + col; \ + fog; \ + tex0; \ + tex1; \ + } \ + } else { \ + for ( i = start ; i < end ; i++, v++, color+=4, winCoord+=4 ) { \ + if ( VB->ClipMask[i] == 0 ) { \ + const GLfloat w = winCoord[3]; \ + (void) w; \ + win; \ + fog; \ + tex0; \ + tex1; \ + } \ + col; \ + } \ + } \ + tex0_4; \ + tex1_4; \ +} + + +SETUPFUNC(rs_wt0, COORD, NOP, TEX0, NOP, TEX0_4, NOP, NOP) +SETUPFUNC(rs_wt0t1, COORD, NOP, TEX0, TEX1, TEX0_4, TEX1_4, NOP) +SETUPFUNC(rs_wft0, COORD, NOP, TEX0, NOP, TEX0_4, NOP, FOG) +SETUPFUNC(rs_wft0t1, COORD, NOP, TEX0, TEX1, TEX0_4, TEX1_4, FOG) +SETUPFUNC(rs_wg, COORD, COL, NOP, NOP, NOP, NOP, NOP) +SETUPFUNC(rs_wgt0, COORD, COL, TEX0, NOP, TEX0_4, NOP, NOP) +SETUPFUNC(rs_wgt0t1, COORD, COL, TEX0, TEX1, TEX0_4, TEX1_4, NOP) +SETUPFUNC(rs_wgf, COORD, COL, NOP, NOP, NOP, NOP, FOG) +SETUPFUNC(rs_wgft0, COORD, COL, TEX0, NOP, TEX0_4, NOP, FOG) +SETUPFUNC(rs_wgft0t1, COORD, COL, TEX0, TEX1, TEX0_4, TEX1_4, FOG) + +SETUPFUNC(rs_t0, NOP, NOP, TEX0, NOP, TEX0_4, NOP, NOP) +SETUPFUNC(rs_t0t1, NOP, NOP, TEX0, TEX1, TEX0_4, TEX1_4, NOP) +SETUPFUNC(rs_f, NOP, NOP, NOP, NOP, NOP, NOP, FOG) +SETUPFUNC(rs_ft0, NOP, NOP, TEX0, NOP, TEX0_4, NOP, FOG) +SETUPFUNC(rs_ft0t1, NOP, NOP, TEX0, TEX1, TEX0_4, TEX1_4, FOG) +SETUPFUNC(rs_g, NOP, COL, NOP, NOP, NOP, NOP, NOP) +SETUPFUNC(rs_gt0, NOP, COL, TEX0, NOP, TEX0_4, NOP, NOP) +SETUPFUNC(rs_gt0t1, NOP, COL, TEX0, TEX1, TEX0_4, TEX1_4, NOP) +SETUPFUNC(rs_gf, NOP, COL, NOP, NOP, NOP, NOP, FOG) +SETUPFUNC(rs_gft0, NOP, COL, TEX0, NOP, TEX0_4, NOP, FOG) +SETUPFUNC(rs_gft0t1, NOP, COL, TEX0, TEX1, TEX0_4, TEX1_4, FOG) + + + +static void rs_invalid( struct vertex_buffer *VB, GLuint start, GLuint end ) +{ + fprintf( stderr, "tdfxRasterSetup(): invalid setup function\n" ); +} + +typedef void (*setupFunc)( struct vertex_buffer *, GLuint, GLuint ); + +static setupFunc setup_func[0x40]; + + +void tdfxDDSetupInit( void ) +{ + int i; + + for (i = 0; i < Elements(setup_func); i++) + setup_func[i] = rs_invalid; + + /* Functions to build vertices from scratch */ + setup_func[TDFX_WIN_BIT|TDFX_TEX0_BIT] = rs_wt0; + setup_func[TDFX_WIN_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_wt0t1; + setup_func[TDFX_WIN_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT] = rs_wft0; + setup_func[TDFX_WIN_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_wft0t1; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT] = rs_wg; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT|TDFX_TEX0_BIT] = rs_wgt0; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_wgt0t1; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT|TDFX_FOG_BIT] = rs_wgf; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT] = rs_wgft0; + setup_func[TDFX_WIN_BIT|TDFX_RGBA_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_wgft0t1; + + /* Repair functions */ + setup_func[TDFX_TEX0_BIT] = rs_t0; + setup_func[TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_t0t1; + setup_func[TDFX_FOG_BIT] = rs_f; + setup_func[TDFX_FOG_BIT|TDFX_TEX0_BIT] = rs_ft0; + setup_func[TDFX_FOG_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_ft0t1; + setup_func[TDFX_RGBA_BIT] = rs_g; + setup_func[TDFX_RGBA_BIT|TDFX_TEX0_BIT] = rs_gt0; + setup_func[TDFX_RGBA_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_gt0t1; + setup_func[TDFX_RGBA_BIT|TDFX_FOG_BIT] = rs_gf; + setup_func[TDFX_RGBA_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT] = rs_gft0; + setup_func[TDFX_RGBA_BIT|TDFX_FOG_BIT|TDFX_TEX0_BIT|TDFX_TEX1_BIT] = rs_gft0t1; +} + + +void tdfxPrintSetupFlags( char *msg, GLuint flags ) +{ + fprintf( stderr, "%s: 0x%x %s%s%s%s%s\n", + msg, + (int)flags, + (flags & TDFX_WIN_BIT) ? " xyzw," : "", + (flags & TDFX_RGBA_BIT) ? " rgba," : "", + (flags & TDFX_FOG_BIT) ? " fog," : "", + (flags & TDFX_TEX0_BIT) ? " tex-0," : "", + (flags & TDFX_TEX1_BIT) ? " tex-1," : "" ); +} + + +/* ================================================================ + * Raster Setup + */ + +void tdfxDDChooseRasterSetupFunc( GLcontext *ctx ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( ctx ); + int index = TDFX_WIN_BIT | TDFX_RGBA_BIT; + int vertexFormat = fxMesa->vertexFormat; + + fxMesa->vertsize = 8; + fxMesa->tmu_source[0] = 0; + fxMesa->tmu_source[1] = 1; + fxMesa->tex_dest[0] = TDFX_TEX0_BIT; + fxMesa->tex_dest[1] = TDFX_TEX1_BIT; + fxMesa->vertexFormat = TDFX_LAYOUT_SINGLE; + + if ( ctx->Texture.ReallyEnabled & ENABLE_TEX0 ) { + index |= TDFX_TEX0_BIT; + } + + if ( ctx->Texture.ReallyEnabled & ENABLE_TEX1 ) { + if ( ctx->Texture.ReallyEnabled & ENABLE_TEX0 ) { + fxMesa->vertexFormat = TDFX_LAYOUT_MULTI; + fxMesa->vertsize = 10; + index |= TDFX_TEX1_BIT; + } else { + /* Just a funny way of doing single texturing. + */ + fxMesa->tmu_source[0] = 1; + fxMesa->tex_dest[1] = TDFX_TEX0_BIT; + index |= TDFX_TEX0_BIT; + } + } + + if (ctx->Texture.ReallyEnabled & (ENABLE_TEX0 | ENABLE_TEX1)) { + if ((ctx->VB->TexCoordPtr[0] && ctx->VB->TexCoordPtr[0]->size == 4) || + (ctx->VB->TexCoordPtr[1] && ctx->VB->TexCoordPtr[1]->size == 4)) { + fxMesa->vertexFormat = TDFX_LAYOUT_PROJECT; + } + } + + if ( ctx->Fog.Enabled ) + index |= TDFX_FOG_BIT; + + fxMesa->SetupIndex = index; + ctx->Driver.RasterSetup = setup_func[index]; + + if ( fxMesa->vertexFormat != vertexFormat ) { + fxMesa->dirty |= TDFX_UPLOAD_VERTEX_LAYOUT; + } + + if (0) { + tdfxPrintSetupFlags( "full setup function", index ); + fprintf(stderr, "full setup function %p\n", ctx->Driver.RasterSetup); + } +} + +/* Check to see if vertices need repairing. + */ +void tdfxDDCheckPartialRasterSetup( GLcontext *ctx, + struct gl_pipeline_stage *d ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + int tmp = fxMesa->SetupDone; + + d->type = 0; + fxMesa->SetupDone = 0; /* cleared if we return */ + + if ( (ctx->Array.Summary & VERT_OBJ_ANY) == 0 ) + return; + if ( ctx->IndirectTriangles ) + return; + + fxMesa->SetupDone = tmp; +} + +/* Repair existing precalculated vertices with new data. + */ +void tdfxDDPartialRasterSetup( struct vertex_buffer *VB ) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT( VB->ctx ); + GLuint new = VB->pipeline->new_outputs; + GLuint available = VB->pipeline->outputs; + GLuint index = 0; + + if ( new & VERT_WIN ) { + new = available; + index |= TDFX_WIN_BIT | TDFX_FOG_BIT; + } + + if ( new & VERT_RGBA ) + index |= TDFX_RGBA_BIT; + + if ( new & VERT_TEX0_ANY ) + index |= TDFX_TEX0_BIT; + + if ( new & VERT_TEX1_ANY ) + index |= fxMesa->tex_dest[1]; + + if ( new & VERT_FOG_COORD ) + index |= TDFX_FOG_BIT; + + fxMesa->SetupDone &= ~index; + index &= fxMesa->SetupIndex; + fxMesa->SetupDone |= index; + + if ( 0 ) + tdfxPrintSetupFlags( "partial setup function", index ); + + if ( index ) + setup_func[index]( VB, VB->Start, VB->Count ); +} + +void tdfxDDDoRasterSetup( struct vertex_buffer *VB ) +{ + GLcontext *ctx = VB->ctx; + + if ( VB->Type == VB_CVA_PRECALC ) { + tdfxDDPartialRasterSetup( VB ); + } else if ( ctx->Driver.RasterSetup ) { + ctx->Driver.RasterSetup( VB, VB->CopyStart, VB->Count ); + } +} + + +/* ================================================================ + * Device-specific Vertex Buffers + */ + +void tdfxDDResizeVB( struct vertex_buffer *VB, GLuint size ) +{ + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + + while ( fxVB->size < size ) + fxVB->size *= 2; + + ALIGN_FREE( fxVB->vert_store ); + fxVB->vert_store = ALIGN_MALLOC( sizeof(tdfxVertex) * fxVB->size, 32 ); + if ( !fxVB->vert_store ) { + fprintf( stderr, "Cannot allocate vertex store! Exiting...\n" ); + exit( 1 ); + } + + fxVB->verts = (tdfxVertexPtr)fxVB->vert_store; + + gl_vector1ui_free( &fxVB->clipped_elements ); + gl_vector1ui_alloc( &fxVB->clipped_elements, + VEC_WRITABLE, fxVB->size, 32 ); + if ( !fxVB->clipped_elements.start ) { + fprintf( stderr, "Cannot allocate clipped elements! Exiting...\n" ); + exit( 1 ); + } + + ALIGN_FREE( VB->ClipMask ); + VB->ClipMask = (GLubyte *)ALIGN_MALLOC( sizeof(GLubyte) * fxVB->size, 32 ); + if ( !VB->ClipMask ) { + fprintf( stderr, "Cannot allocate clipmask! Exiting...\n" ); + exit( 1 ); + } +} + +void tdfxDDResizeElts( struct vertex_buffer *VB, GLuint size ) +{ +#if 0 + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + + FREE(fxVB->elts); + + while (fxVB->elt_size < size) + fxVB->elt_size *= 2; + + FREE(fxVB->elts); + fxVB->elts = MALLOC( sizeof(tdfxVertex *) * fxVB->elt_size ); + if ( !fxVB->elts ) { + fprintf( stderr, "Cannot allocate vertex indirection! Exiting...\n" ); + exit( 1 ); + } +#endif +} + +void tdfxDDRegisterVB( struct vertex_buffer *VB ) +{ + tdfxVertexBufferPtr fxVB; + + fxVB = (tdfxVertexBufferPtr) CALLOC( sizeof(*fxVB) ); + + fxVB->elt_size = fxVB->size = VB->Size * 2; + fxVB->vert_store = ALIGN_MALLOC( sizeof(tdfxVertex) * fxVB->size, 32 ); + if ( !fxVB->vert_store ) { + fprintf( stderr, "Cannot allocate vertex store! Exiting...\n" ); + exit( 1 ); + } + + fxVB->verts = (tdfxVertexPtr)fxVB->vert_store; + +#if 0 + fxVB->elts = MALLOC( sizeof(tdfxVertex *) * fxVB->elt_size ); + if ( !fxVB->elts ) { + fprintf( stderr, "Cannot allocate vertex indirection! Exiting...\n" ); + exit( 1 ); + } +#endif + + gl_vector1ui_alloc( &fxVB->clipped_elements, + VEC_WRITABLE, fxVB->size, 32 ); + if ( !fxVB->clipped_elements.start ) { + fprintf( stderr, "Cannot allocate clipped elements! Exiting...\n" ); + exit( 1 ); + } + + + ALIGN_FREE( VB->ClipMask ); + VB->ClipMask = (GLubyte *)ALIGN_MALLOC( sizeof(GLubyte) * fxVB->size, 32 ); + if ( !VB->ClipMask ) { + fprintf( stderr, "Cannot allocate clipmask! Exiting...\n" ); + exit( 1 ); + } + + VB->driver_data = fxVB; +} + +void tdfxDDUnregisterVB( struct vertex_buffer *VB ) +{ + tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB); + + if ( fxVB ) { + if ( fxVB->vert_store ) ALIGN_FREE( fxVB->vert_store ); + if ( fxVB->elts ) ALIGN_FREE( fxVB->elts ); + gl_vector1ui_free( &fxVB->clipped_elements ); + FREE( fxVB ); + VB->driver_data = NULL; + } +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.h new file mode 100644 index 000000000..1f928ea2d --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_vb.h @@ -0,0 +1,127 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * Keith Whitwell <keithw@valinux.com> + * + */ + +#ifndef __TDFX_VB_H__ +#define __TDFX_VB_H__ + +#ifdef GLX_DIRECT_RENDERING + +#include "types.h" +#include "vb.h" + +/* + * Color type for the vertex data + */ +typedef struct { + GLubyte blue; + GLubyte green; + GLubyte red; + GLubyte alpha; +} tdfx_color_t; + + +/* The vertex structure. The final tu1/tv1 values only used in + * multitexture modes, and tq0/tq1 in projected texture modes. + */ +typedef struct { + GLfloat x, y, z; /* Coordinates in screen space */ + GLfloat rhw; /* Reciprocal homogeneous w */ + tdfx_color_t color; /* Diffuse color */ + GLuint padding; /* ... */ + GLfloat tu0, tv0; /* Texture 0 coordinates */ + GLfloat tu1, tv1; /* Texture 1 coordinates */ + GLfloat tq0, tq1; /* Projected texture coordinates */ +} tdfx_vertex; + + +/* The fastpath code still expects a 16-float stride vertex. + */ +union tdfx_vertex_t { + tdfx_vertex v; + GLfloat f[16]; + GLuint ui[16]; +}; + +typedef union tdfx_vertex_t tdfxVertex; +typedef union tdfx_vertex_t *tdfxVertexPtr; + +/* Vertex buffer for use when on the fast path */ +struct tdfx_vertex_buffer { + tdfxVertexPtr verts; + GLvector1ui clipped_elements; + GLuint size; + int last_vert; + void *vert_store; + + tdfxVertexPtr *elts; + GLuint elt_size; + GLuint last_elt; +}; + +typedef struct tdfx_vertex_buffer *tdfxVertexBufferPtr; + +#define TDFX_DRIVER_DATA(vb) ((tdfxVertexBufferPtr)((vb)->driver_data)) + + +#define TDFX_WIN_BIT 0x01 +#define TDFX_RGBA_BIT 0x02 +#define TDFX_FOG_BIT 0x04 +#define TDFX_SPEC_BIT 0x08 +#define TDFX_TEX0_BIT 0x10 +#define TDFX_TEX1_BIT 0x20 + + +extern void tdfxDDSetupInit( void ); + +extern void tdfxDDChooseRasterSetupFunc( GLcontext *ctx ); +extern void tdfxPrintSetupFlags( char *msg, GLuint flags ); + +extern void tdfxDDCheckPartialRasterSetup( GLcontext *ctx, + struct gl_pipeline_stage *s ); +extern void tdfxDDPartialRasterSetup( struct vertex_buffer *VB ); +extern void tdfxDDDoRasterSetup( struct vertex_buffer *VB ); + +extern void tdfxDDResizeVB( struct vertex_buffer *VB, GLuint size ); +extern void tdfxDDResizeElts( struct vertex_buffer *VB, GLuint size ); +extern void tdfxDDRegisterVB( struct vertex_buffer *VB ); +extern void tdfxDDUnregisterVB( struct vertex_buffer *VB ); + + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* __TDFX_VB_H__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.c new file mode 100644 index 000000000..e2abe0800 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.c @@ -0,0 +1,382 @@ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ + +/* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * + * Authors: + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * + */ + +#include <stdlib.h> +#include <string.h> + +#include "tdfx_context.h" + + +FxI32 +FX_grGetInteger_NoLock(FxU32 pname) +{ + switch (pname) { + case FX_FOG_TABLE_ENTRIES: + case FX_GLIDE_STATE_SIZE: + case FX_LFB_PIXEL_PIPE: + case FX_PENDING_BUFFERSWAPS: + case FX_TEXTURE_ALIGN: + case GR_STATS_PIXELS_DEPTHFUNC_FAIL: + case GR_STATS_PIXELS_IN: + case GR_STATS_PIXELS_OUT: + { + FxI32 result; + FxU32 grname = pname; + grGet(grname, 4, &result); + return result; + } + case FX_ZDEPTH_MAX: + { + FxI32 zvals[2]; + grGet(GR_ZDEPTH_MIN_MAX, 8, zvals); + return zvals[0]; + } + default: + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "Wrong parameter in FX_grGetInteger!\n"); + } + } + + return 0; +} + + +FxI32 +FX_grGetInteger(tdfxContextPtr fxMesa, FxU32 pname) +{ + int result; + LOCK_HARDWARE(fxMesa); + result = FX_grGetInteger_NoLock(pname); + UNLOCK_HARDWARE(fxMesa); + return result; +} + + +const char * +FX_grGetString(tdfxContextPtr fxMesa, FxU32 pname) +{ + const char *s; + LOCK_HARDWARE(fxMesa); + s = grGetString(pname); + UNLOCK_HARDWARE(fxMesa); + return s; +} + + + +/* Wrapper for grColorMask() and grColorMaskExt(). + */ +void +FX_grColorMask(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + LOCK_HARDWARE(fxMesa); + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT( grColorMaskExtProc ); + grColorMaskExtProc(r, g, b, a); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(r || g || b, GL_FALSE); + } + UNLOCK_HARDWARE(fxMesa); +} + + +void +FX_grColorMask_NoLock(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a) +{ + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT( grColorMaskExtProc ); + grColorMaskExtProc(r, g, b, a); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(r || g || b, GL_FALSE); + } +} + + +/* As above, but pass the mask as an array + */ +void +FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4]) +{ + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + LOCK_HARDWARE(fxMesa); + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT( grColorMaskExtProc ); + grColorMaskExtProc(rgba[RCOMP], rgba[GCOMP], + rgba[BCOMP], rgba[ACOMP]); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP], GL_FALSE); + } + UNLOCK_HARDWARE(fxMesa); +} + +void +FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4]) +{ + if (ctx->Visual->RedBits == 8) { + /* 32bpp mode */ + ASSERT( grColorMaskExtProc ); + grColorMaskExtProc(rgba[RCOMP], rgba[GCOMP], + rgba[BCOMP], rgba[ACOMP]); + } + else { + /* 16 bpp mode */ + /* we never have an alpha buffer */ + grColorMask(rgba[RCOMP] || rgba[GCOMP] || rgba[BCOMP], GL_FALSE); + } +} + + + +FxBool +FX_grLfbLock(tdfxContextPtr fxMesa, GrLock_t type, GrBuffer_t buffer, + GrLfbWriteMode_t writeMode, GrOriginLocation_t origin, + FxBool pixelPipeline, GrLfbInfo_t * info) +{ + FxBool result; + + LOCK_HARDWARE(fxMesa); + result = grLfbLock(type, buffer, writeMode, origin, pixelPipeline, info); + UNLOCK_HARDWARE(fxMesa); + return result; +} + +FxU32 +FX_grTexTextureMemRequired(tdfxContextPtr fxMesa, FxU32 evenOdd, GrTexInfo * info) +{ + FxU32 result; + + LOCK_HARDWARE(fxMesa); + result = grTexTextureMemRequired(evenOdd, info); + UNLOCK_HARDWARE(fxMesa); + return result; +} + +FxU32 +FX_grTexMinAddress(tdfxContextPtr fxMesa, GrChipID_t tmu) +{ + FxU32 result; + + LOCK_HARDWARE(fxMesa); + result = grTexMinAddress(tmu); + UNLOCK_HARDWARE(fxMesa); + return result; +} + +extern FxU32 +FX_grTexMaxAddress(tdfxContextPtr fxMesa, GrChipID_t tmu) +{ + FxU32 result; + + LOCK_HARDWARE(fxMesa); + result = grTexMaxAddress(tmu); + UNLOCK_HARDWARE(fxMesa); + return result; +} + + +int +FX_getFogTableSize(tdfxContextPtr fxMesa) +{ + int result; + LOCK_HARDWARE(fxMesa); + grGet(GR_FOG_TABLE_ENTRIES, sizeof(int), (void *) &result); + UNLOCK_HARDWARE(fxMesa); + return result; +} + +int +FX_getGrStateSize(tdfxContextPtr fxMesa) +{ + int result; + LOCK_HARDWARE(fxMesa); + grGet(GR_GLIDE_STATE_SIZE, sizeof(int), (void *) &result); + UNLOCK_HARDWARE(fxMesa); + return result; +} + +void +FX_grAADrawLine(tdfxContextPtr fxMesa, GrVertex * a, GrVertex * b) +{ + /* ToDo */ + BEGIN_CLIP_LOOP(fxMesa); + grDrawLine(a, b); + END_CLIP_LOOP(fxMesa); +} + +void +FX_grAADrawPoint(tdfxContextPtr fxMesa, GrVertex * a) +{ + BEGIN_CLIP_LOOP(fxMesa); + grDrawPoint(a); + END_CLIP_LOOP(fxMesa); +} + +void +FX_grDrawPolygonVertexList(tdfxContextPtr fxMesa, int n, GrVertex * verts) +{ + BEGIN_CLIP_LOOP(fxMesa); + grDrawVertexArrayContiguous(GR_POLYGON, n, verts, sizeof(GrVertex)); + END_CLIP_LOOP(fxMesa); +} + +#if TDFX_USE_PARGB +void +FX_setupGrVertexLayout(tdfxContextPtr fxMesa) +{ + LOCK_HARDWARE(fxMesa); + grReset(GR_VERTEX_PARAMETER); + + grCoordinateSpace(GR_WINDOW_COORDS); + grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_PARGB, GR_VERTEX_PARGB_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); + UNLOCK_HARDWARE(fxMesa); +} +#else /* TDFX_USE_PARGB */ +void +FX_setupGrVertexLayout(tdfxContextPtr fxMesa) +{ + LOCK_HARDWARE(fxMesa); + grReset(GR_VERTEX_PARAMETER); + + grCoordinateSpace(GR_WINDOW_COORDS); + grVertexLayout(GR_PARAM_XY, GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_A, GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q, GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Z, GR_VERTEX_OOZ_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE); + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, GR_PARAM_DISABLE); + UNLOCK_HARDWARE(fxMesa); +} +#endif /* TDFX_USE_PARGB */ + +void +FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask) +{ + switch (hintType) { + case GR_HINT_STWHINT: + { + if (hintMask & GR_STWHINT_W_DIFF_TMU0) + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_Q0, GR_VERTEX_OOW_TMU0_OFFSET << 2, + GR_PARAM_DISABLE); + + if (hintMask & GR_STWHINT_ST_DIFF_TMU1) + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + + if (hintMask & GR_STWHINT_W_DIFF_TMU1) + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_ENABLE); + else + grVertexLayout(GR_PARAM_Q1, GR_VERTEX_OOW_TMU1_OFFSET << 2, + GR_PARAM_DISABLE); + + } + } +} + +void +FX_grHints(tdfxContextPtr fxMesa, GrHint_t hintType, FxU32 hintMask) +{ + LOCK_HARDWARE(fxMesa); + FX_grHints_NoLock(hintType, hintMask); + UNLOCK_HARDWARE(fxMesa); +} + +/* It appears to me that this function is needed either way. */ +FX_GrContext_t +FX_grSstWinOpen(tdfxContextPtr fxMesa, + FxU32 hWnd, + GrScreenResolution_t screen_resolution, + GrScreenRefresh_t refresh_rate, + GrColorFormat_t color_format, + GrOriginLocation_t origin_location, + int nColBuffers, int nAuxBuffers) +{ + FX_GrContext_t i; + LOCK_HARDWARE(fxMesa); + i = grSstWinOpen(hWnd, + screen_resolution, + refresh_rate, + color_format, origin_location, nColBuffers, nAuxBuffers); + + /* + fprintf(stderr, + "grSstWinOpen( win %d res %d ref %d fmt %d\n" + " org %d ncol %d naux %d )\n" + " ==> %d\n", + hWnd, + screen_resolution, + refresh_rate, + color_format, + origin_location, + nColBuffers, + nAuxBuffers, + i); + */ + UNLOCK_HARDWARE(fxMesa); + return i; +} diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.h b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.h new file mode 100644 index 000000000..20e5530c5 --- /dev/null +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_wrapper.h @@ -0,0 +1,675 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the + * terms stated above. + * + * Thank you for your contribution, David! + * + * Please make note of the above copyright/license statement. If you + * contributed code or bug fixes to this code under the previous (GNU + * Library) license and object to the new license, your code will be + * removed at your request. Please see the Mesa docs/COPYRIGHT file + * for more information. + * + * Additional Mesa/3Dfx driver developers: + * Daryll Strauss <daryll@precisioninsight.com> + * Keith Whitwell <keith@precisioninsight.com> + * + * See fxapi.h for more revision/author details. + */ + + +#ifndef __FX_GLIDE_WARPER__ +#define __FX_GLIDE_WARPER__ + +#include <glide.h> +#include <g3ext.h> + +typedef struct tdfx_context tdfxContextRec; +typedef struct tdfx_context *tdfxContextPtr; + +/* + * General context: + */ +typedef GrContext_t FX_GrContext_t; + +#define FX_FOG_TABLE_ENTRIES GR_FOG_TABLE_ENTRIES +#define FX_GLIDE_STATE_SIZE GR_GLIDE_STATE_SIZE +#define FX_LFB_PIXEL_PIPE GR_LFB_PIXEL_PIPE +#define FX_PENDING_BUFFERSWAPS GR_PENDING_BUFFERSWAPS +#define FX_TEXTURE_ALIGN GR_TEXTURE_ALIGN + +#define FX_ZDEPTH_MAX 0x100 + + +#define GR_ASPECT_1x1 GR_ASPECT_LOG2_1x1 +#define GR_ASPECT_2x1 GR_ASPECT_LOG2_2x1 +#define GR_ASPECT_4x1 GR_ASPECT_LOG2_4x1 +#define GR_ASPECT_8x1 GR_ASPECT_LOG2_8x1 +#define GR_ASPECT_1x2 GR_ASPECT_LOG2_1x2 +#define GR_ASPECT_1x4 GR_ASPECT_LOG2_1x4 +#define GR_ASPECT_1x8 GR_ASPECT_LOG2_1x8 + +#define GR_LOD_256 GR_LOD_LOG2_256 +#define GR_LOD_128 GR_LOD_LOG2_128 +#define GR_LOD_64 GR_LOD_LOG2_64 +#define GR_LOD_32 GR_LOD_LOG2_32 +#define GR_LOD_16 GR_LOD_LOG2_16 +#define GR_LOD_8 GR_LOD_LOG2_8 +#define GR_LOD_4 GR_LOD_LOG2_4 +#define GR_LOD_2 GR_LOD_LOG2_2 +#define GR_LOD_1 GR_LOD_LOG2_1 + +#define GR_FOG_WITH_TABLE GR_FOG_WITH_TABLE_ON_Q + + +typedef FxU32 GrHint_t; +#define GR_HINTTYPE_MIN 0 +#define GR_HINT_STWHINT 0 + +typedef FxU32 GrSTWHint_t; +#define GR_STWHINT_W_DIFF_FBI FXBIT(0) +#define GR_STWHINT_W_DIFF_TMU0 FXBIT(1) +#define GR_STWHINT_ST_DIFF_TMU0 FXBIT(2) +#define GR_STWHINT_W_DIFF_TMU1 FXBIT(3) +#define GR_STWHINT_ST_DIFF_TMU1 FXBIT(4) +#define GR_STWHINT_W_DIFF_TMU2 FXBIT(5) +#define GR_STWHINT_ST_DIFF_TMU2 FXBIT(6) + +#define GR_CONTROL_ACTIVATE 1 +#define GR_CONTROL_DEACTIVATE 0 + +#define GrState void + +/* +** move the vertex layout defintion to application +*/ +typedef struct +{ + GLfloat sow; /* s texture ordinate (s over w) */ + GLfloat tow; /* t texture ordinate (t over w) */ + GLfloat oow; /* 1/w (used mipmapping - really 0xfff/w) */ +} +GrTmuVertex; + + +#if FX_USE_PARGB + +/* standard vertex, packed argb, double texture, 12 dwords */ +typedef struct +{ + GLfloat x, y; /* X and Y in screen space */ + GLfloat ooz; /* 65535/Z (used for Z-buffering) */ + GLfloat oow; /* 1/W (used for W-buffering, texturing) */ + FxU32 argb; /* R, G, B, A [0..255.0] */ + GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; + GLfloat z; /* Z is ignored */ +} +GrVertex; + +/* optimised vertex, packed argb, single texture, 8 dwords = 1 cacheline */ +typedef struct +{ + GLfloat x, y; /* X and Y in screen space */ + GLfloat ooz; /* 65535/Z (used for Z-buffering) */ + GLfloat oow; /* 1/W (used for W-buffering, texturing) */ + FxU32 argb; /* R, G, B, A [0..255.0] */ + GrTmuVertex tmuvtx; /* only 1 TMU used to keep vertex size down */ +} +GrVertex_Fast; + +/* following offsets work for both vertex layouts */ +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 1 +#define GR_VERTEX_OOZ_OFFSET 2 +#define GR_VERTEX_OOW_OFFSET 3 +#define GR_VERTEX_PARGB_OFFSET 4 +#define GR_VERTEX_SOW_TMU0_OFFSET 5 +#define GR_VERTEX_TOW_TMU0_OFFSET 6 +#define GR_VERTEX_OOW_TMU0_OFFSET 7 +#define GR_VERTEX_SOW_TMU1_OFFSET 8 +#define GR_VERTEX_TOW_TMU1_OFFSET 9 +#define GR_VERTEX_OOW_TMU1_OFFSET 10 +#define GR_VERTEX_Z_OFFSET 11 + +#if GLIDE_ENDIAN == GLIDE_ENDIAN_BIG +#define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+3] +#define GET_PR(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+2] +#define GET_PG(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+1] +#define GET_PB(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+0] +#else +#define GET_PA(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+0] +#define GET_PR(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+1] +#define GET_PG(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+2] +#define GET_PB(v) ((FxU8*)(v))[GR_VERTEX_PARGB_OFFSET*4+3] +#endif + +#define GET_PARGB(v) ((FxU32*)(v))[GR_VERTEX_PARGB_OFFSET] +#define PACK_4F_ARGB(dest, a, r, g, b) { \ + const GLuint cr = (int)r; \ + const GLuint cg = (int)g; \ + const GLuint ca = (int)a; \ + const GLuint cb = (int)b; \ + dest = ca << 24 | cr << 16 | cg << 8 | cb; \ +} + +#else /* FX_USE_PARGB */ + +typedef struct +{ + float x, y, z; /* X, Y, and Z of scrn space -- Z is ignored */ + float r, g, b; /* R, G, B, ([0..255.0]) */ + float ooz; /* 65535/Z (used for Z-buffering) */ + float a; /* Alpha [0..255.0] */ + float oow; /* 1/W (used for W-buffering, texturing) */ + GrTmuVertex tmuvtx[GLIDE_NUM_TMU]; +} +GrVertex; + +#define GR_VERTEX_X_OFFSET 0 +#define GR_VERTEX_Y_OFFSET 1 +#define GR_VERTEX_Z_OFFSET 2 +#define GR_VERTEX_R_OFFSET 3 +#define GR_VERTEX_G_OFFSET 4 +#define GR_VERTEX_B_OFFSET 5 +#define GR_VERTEX_OOZ_OFFSET 6 +#define GR_VERTEX_A_OFFSET 7 +#define GR_VERTEX_OOW_OFFSET 8 +#define GR_VERTEX_SOW_TMU0_OFFSET 9 +#define GR_VERTEX_TOW_TMU0_OFFSET 10 +#define GR_VERTEX_OOW_TMU0_OFFSET 11 +#define GR_VERTEX_SOW_TMU1_OFFSET 12 +#define GR_VERTEX_TOW_TMU1_OFFSET 13 +#define GR_VERTEX_OOW_TMU1_OFFSET 14 +#endif /* FX_USE_PARGB */ + + + +extern FxI32 FX_grGetInteger_NoLock(FxU32 pname); + +extern FxI32 FX_grGetInteger(tdfxContextPtr fxMesa, FxU32 pname); + +extern const char *FX_grGetString(tdfxContextPtr fxMesa, FxU32 pname); + + +#define FX_grTexDownloadTable(fxMesa, type, data) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexDownloadTable(type,data); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0); + +#define FX_grTexDownloadTable_NoLock(type, data) \ + grTexDownloadTable(type, data) + + +#define FX_grFlush(fxMesa) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grFlush(); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grFinish(fxMesa) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grFinish(); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + + +#define FX_grLfbWriteRegion(fxMesa,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,FXFALSE,src_stride,src_data); \ + UNLOCK_HARDWARE(fxMesa); \ + } while(0) + + +#define FX_grLfbReadRegion(fxMesa,src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grLfbReadRegion(src_buffer,src_x,src_y,src_width,src_height,dst_stride,dst_data); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0); + + +#define FX_grDrawTriangle_NoLock(a,b,c) grDrawTriangle(a,b,c) +#define FX_grDrawTriangle(fxMesa, a,b,c) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawTriangle_NoLock(a,b,c); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + + + +extern void FX_grHints_NoLock(GrHint_t hintType, FxU32 hintMask); +extern void FX_grHints(tdfxContextPtr fxMesa, GrHint_t hintType, FxU32 hintMask); + + +extern void FX_grAADrawLine(tdfxContextPtr fxMesa, GrVertex * a, GrVertex * b); + +extern void FX_grAADrawPoint(tdfxContextPtr fxMesa, GrVertex * a); + + +extern void FX_setupGrVertexLayout(tdfxContextPtr fxMesa); + + +extern FX_GrContext_t FX_grSstWinOpen(tdfxContextPtr fxMesa, + FxU32 hWnd, + GrScreenResolution_t screen_resolution, + GrScreenRefresh_t refresh_rate, + GrColorFormat_t color_format, + GrOriginLocation_t origin_location, + int nColBuffers, int nAuxBuffers); + + +#define FX_grDrawLine_NoLock(v1, v2) grDrawLine(v1, v2) +#define FX_grDrawLine(fxMesa, v1, v2) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawLine_NoLock(v1, v2); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grDrawPoint_NoLock(p) grDrawPoint(p) +#define FX_grDrawPoint(fxMesa, p) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + FX_grDrawPoint_NoLock(p); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +extern void FX_grDrawPolygonVertexList(tdfxContextPtr fxMesa, + int n, GrVertex * v); + +#define FX_grDitherMode(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDitherMode(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grRenderBuffer(fxMesa, b) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grRenderBuffer(b); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grRenderBuffer_NoLock(b) grRenderBuffer(b) + +#define FX_grBufferClear(fxMesa, c, a, d) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grBufferClear(c, a, d); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grBufferClear_NoLock(c, a, d) grBufferClear(c, a, d) + + +#define FX_grBufferClearExt_NoLock(c, a, d, s) grBufferClearExtProc(c, a, d, s) + +#define FX_grBufferClearExt(fxMesa, c, a, d, s) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grBufferClearExtProc(c, a, d, s); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grEnable(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grEnable(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grEnable_NoLock(m) grEnable(m) + +#define FX_grDisable(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDisable(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grDisable_NoLock(m) grDisable(m) + + +#define FX_grStencilFunc(fxMesa, fnc, ref, mask) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grStencilFuncProc((fnc), (ref), (mask)); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grStencilFunc_NoLock(f, r, m) grStencilFuncProc(f, r, m) + +#define FX_grStencilMask(fxMesa, write_mask) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grStencilMaskProc(write_mask); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grStencilMask_NoLock(m) grStencilMaskProc(m) + +#define FX_grStencilOp(fxMesa, stencil_fail, depth_fail, depth_pass) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grStencilOpProc((stencil_fail), (depth_fail), (depth_pass)); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grStencilOp_NoLock(sf, df, dp) grStencilOpProc(sf, df, dp) + +#define FX_grDepthMask(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDepthMask(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grDepthMask_NoLock(m) grDepthMask(m) + + +extern void FX_grColorMask(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a); + +extern void FX_grColorMask_NoLock(GLcontext *ctx, GLboolean r, GLboolean g, + GLboolean b, GLboolean a); + +extern void FX_grColorMaskv(GLcontext *ctx, const GLboolean rgba[4]); + +extern void FX_grColorMaskv_NoLock(GLcontext *ctx, const GLboolean rgba[4]); + + +extern FxBool FX_grLfbLock(tdfxContextPtr fxMesa, + GrLock_t type, GrBuffer_t buffer, + GrLfbWriteMode_t writeMode, + GrOriginLocation_t origin, FxBool pixelPipeline, + GrLfbInfo_t * info); + +#define FX_grLfbUnlock(fxMesa, t, b) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grLfbUnlock(t, b); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grConstantColorValue(fxMesa, v) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grConstantColorValue(v); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grConstantColorValue_NoLock grConstantColorValue + +#define FX_grAADrawTriangle(fxMesa, a, b, c, ab, bc, ca) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grAADrawTriangle(a, b, c, ab, bc, ca); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grAlphaBlendFunction(rs, rd, as, ad) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grAlphaBlendFunction(rs, rd, as, ad); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grAlphaCombine(func, fact, loc, oth, inv) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grAlphaCombine(func, fact, loc, oth, inv); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grAlphaCombine_NoLock grAlphaCombine + +#define FX_grAlphaTestFunction(fxMesa, f) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grAlphaTestFunction(f); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grAlphaTestReferenceValue(fxMesa, v) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grAlphaTestReferenceValue(v); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grClipWindow(fxMesa, minx, miny, maxx, maxy) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grClipWindow(minx, miny, maxx, maxy); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grClipWindow_NoLock grClipWindow + +#define FX_grColorCombine(fxMesa, func, fact, loc, oth, inv) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grColorCombine(func, fact, loc, oth, inv); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grColorCombine_NoLock grColorCombine + +#define FX_grCullMode(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grCullMode(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grDepthBiasLevel(fxMesa, lev) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDepthBiasLevel(lev); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grDepthBufferFunction(fxMesa, func) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDepthBufferFunction(func); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grFogColorValue(fxMesa, c) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grFogColorValue(c); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grFogMode(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grFogMode(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grFogTable(fxMesa, t)\ + do { \ + LOCK_HARDWARE(fxMesa); \ + grFogTable(t); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexClampMode(fxMesa, t, sc, tc) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexClampMode(t, sc, tc); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexClampMode_NoLock grTexClampMode + +#define FX_grTexCombine(fxMesa, t, rfunc, rfact, afunc, afact, rinv, ainv) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexCombine(t, rfunc, rfact, afunc, afact, rinv, ainv); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexCombine_NoLock grTexCombine + +#define FX_grTexDownloadMipMapLevel(fxMesa, t, sa, tlod, llod, ar, f, eo, d) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexDownloadMipMapLevel(t, sa, tlod, llod, ar, f, eo, d); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexDownloadMipMapLevel_NoLock grTexDownloadMipMapLevel + +#define FX_grTexDownloadMipMapLevelPartial(fxMesa, t, sa, tlod, llod, ar, f, eo, d, s, e); \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexDownloadMipMapLevelPartial(t, sa, tlod, llod, ar, f, eo, d, s, e); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexFilterMode(fxMesa, t, minf, magf) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexFilterMode(t, minf, magf); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexFilterMode_NoLock grTexFilterMode + +extern FxU32 FX_grTexMinAddress(tdfxContextPtr fxMesa, GrChipID_t tmu); +extern FxU32 FX_grTexMaxAddress(tdfxContextPtr fxMesa, GrChipID_t tmu); + +#define FX_grTexMipMapMode(t, m, lod) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexMipMapMode(t, m, lod); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexMipMapMode_NoLock grTexMipMapMode + +#define FX_grTexSource(t, sa, eo, i) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexSource(t, sa, eo, i); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexSource_NoLock grTexSource + +extern FxU32 FX_grTexTextureMemRequired(tdfxContextPtr fxMesa, + FxU32 evenOdd, GrTexInfo * info); + +#define FX_grTexTextureMemRequired_NoLock grTexTextureMemRequired + +#define FX_grGlideGetState(fxMesa, s) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grGlideGetState(s); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) +#define FX_grGlideGetState_NoLock(s) grGlideGetState(s); + +#define FX_grDRIBufferSwap(fxMesa, i) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDRIBufferSwap(i); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grSstSelect(fxMesa, b) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grSstSelect(b); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grSstSelect_NoLock grSstSelect + +#define FX_grGlideSetState(fxMesa, s) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grGlideSetState(s); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) +#define FX_grGlideSetState_NoLock(s) grGlideSetState(s); + +#define FX_grDepthBufferMode(fxMesa, m) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grDepthBufferMode(m); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grLfbWriteColorFormat(fxMesa, f) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grLfbWriteColorFormat(f); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grDrawVertexArray(fxMesa, m, c, p) \ + do { \ + BEGIN_CLIP_LOOP(fxMesa); \ + grDrawVertexArray(m, c, p); \ + END_CLIP_LOOP(fxMesa); \ + } while (0) + +#define FX_grGlideShutdown(fxMesa) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grGlideShutdown(); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grTexLodBiasValue_NoLock(t, v) grTexLodBiasValue(t, v) + +#define FX_grTexLodBiasValue(t, v) \ + do { \ + LOCK_HARDWARE(fxMesa); \ + grTexLodBiasValue(t, v); \ + UNLOCK_HARDWARE(fxMesa); \ + } while (0) + +#define FX_grGlideInit_NoLock grGlideInit +#define FX_grSstWinOpen_NoLock grSstWinOpen + +extern int FX_getFogTableSize(tdfxContextPtr fxMesa); + +extern int FX_getGrStateSize(tdfxContextPtr fxMesa); + +#endif /* __FX_GLIDE_WARPER__ */ diff --git a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c index 206953dec..06930691d 100644 --- a/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c +++ b/xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c @@ -1,139 +1,153 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -Copyright 2000 VA Linux Systems, Inc. -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"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ -/* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_xmesa.c,v 1.10 2000/12/08 19:36:24 alanh Exp $ */ +/* -*- mode: c; c-basic-offset: 3 -*- + * + * Copyright 2000 VA Linux Systems Inc., Fremont, California. + * + * 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* $XFree86$ */ /* + * Original rewrite: + * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000 + * * Authors: - * Daryll Strauss <daryll@valinux.com> - * Brian E. Paul <brianp@valinux.com> + * Gareth Hughes <gareth@valinux.com> + * Brian Paul <brianp@valinux.com> + * */ #ifdef GLX_DIRECT_RENDERING #include <X11/Xlibint.h> -#include <glide.h> -#include "fxdrv.h" + #include "context.h" #include "matrix.h" #include "mmath.h" #include "vbxform.h" -#include "fxtexman.h" +#include "dri_glide.h" + +#include "tdfx_context.h" +#include "tdfx_render.h" +#include "tdfx_state.h" +#include "tdfx_texman.h" -/* including xf86PciInfo.h causes a bunch of errors */ -#ifndef PCI_CHIP_VOODOO5 -#define PCI_CHIP_VOODOO5 0x0009 + +#ifndef TDFX_DEBUG +int TDFX_DEBUG = (0 +/* | DEBUG_ALWAYS_SYNC */ +/* | DEBUG_VERBOSE_API */ +/* | DEBUG_VERBOSE_MSG */ +/* | DEBUG_VERBOSE_LRU */ +/* | DEBUG_VERBOSE_DRI */ +/* | DEBUG_VERBOSE_IOCTL */ +/* | DEBUG_VERBOSE_2D */ + ); #endif GLboolean -XMesaInitDriver(__DRIscreenPrivate * sPriv) +XMesaInitDriver( __DRIscreenPrivate *sPriv ) { - tdfxScreenPrivate *gsp; - - /* Check the DRI version */ - { - int major, minor, patch; - if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { - if (major != 3 || minor != 0 || patch < 0) { - char msg[1000]; - sprintf(msg, - "3dfx DRI driver expected DRI version 3.0.x but got version %d.%d.%d", - major, minor, patch); - __driMesaMessage(msg); - return GL_FALSE; - } - } - } - - /* Check that the DDX driver version is compatible */ - if (sPriv->ddxMajor != 1 || sPriv->ddxMinor != 0 || sPriv->ddxPatch < 0) { - char msg[1000]; - sprintf(msg, - "3dfx DRI driver expected DDX driver version 1.0.x but got version %d.%d.%d", - sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); - __driMesaMessage(msg); - return GL_FALSE; - } - - /* Check that the DRM driver version is compatible */ - if (sPriv->drmMajor != 1 || sPriv->drmMinor != 0 || sPriv->drmPatch < 0) { - char msg[1000]; - sprintf(msg, - "3dfx DRI driver expected DRM driver version 1.0.x but got version %d.%d.%d", - sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); - __driMesaMessage(msg); - return GL_FALSE; - } - - /* Allocate the private area */ - gsp = (tdfxScreenPrivate *) Xmalloc(sizeof(tdfxScreenPrivate)); - if (!gsp) - return GL_FALSE; - - gsp->driScrnPriv = sPriv; - - sPriv->private = (void *) gsp; - - if (!tdfxMapAllRegions(sPriv)) { - Xfree(gsp); - sPriv->private = NULL; - return GL_FALSE; - } - - return GL_TRUE; + int major, minor, patch; + char msg[1024]; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, sPriv ); + } + + /* Check the DRI version */ + if ( XF86DRIQueryVersion( sPriv->display, &major, &minor, &patch ) ) { + if ( major != 3 || + minor != 0 || + patch < 0 ) { + sprintf( msg, + "3dfx DRI driver expected DRI version 3.0.x " + "but got version %d.%d.%d", + major, minor, patch ); + __driMesaMessage( msg ); + return GL_FALSE; + } + } + + /* Check that the DDX driver version is compatible */ + if ( sPriv->ddxMajor != 1 || + sPriv->ddxMinor != 0 || + sPriv->ddxPatch < 0 ) { + sprintf( msg, + "3dfx DRI driver expected DDX driver version 1.0.x " + "but got version %d.%d.%d", + sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch ); + __driMesaMessage( msg ); + return GL_FALSE; + } + + /* Check that the DRM driver version is compatible */ + if ( sPriv->drmMajor != 1 || + sPriv->drmMinor != 0 || + sPriv->drmPatch < 0 ) { + sprintf( msg, + "3dfx DRI driver expected DRM driver version 1.0.x " + "but got version %d.%d.%d", + sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch ); + __driMesaMessage( msg ); + return GL_FALSE; + } + + if ( !tdfxCreateScreen( sPriv ) ) { + tdfxDestroyScreen( sPriv ); + return GL_FALSE; + } + + return GL_TRUE; } void -XMesaResetDriver(__DRIscreenPrivate * sPriv) +XMesaResetDriver( __DRIscreenPrivate *sPriv ) { - tdfxUnmapAllRegions(sPriv); - Xfree(sPriv->private); - sPriv->private = NULL; + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, sPriv ); + } + + tdfxDestroyScreen( sPriv ); } GLvisual * -XMesaCreateVisual(Display * dpy, - __DRIscreenPrivate * driScrnPriv, - const XVisualInfo * visinfo, - const __GLXvisualConfig * config) +XMesaCreateVisual( Display * dpy, + __DRIscreenPrivate *driScrnPriv, + const XVisualInfo *visinfo, + const __GLXvisualConfig *config ) { - /* Drivers may change the args to _mesa_create_visual() in order to - * setup special visuals. - */ - return _mesa_create_visual(config->rgba, + /* Drivers may change the args to _mesa_create_visual() in order to + * setup special visuals. + */ + return _mesa_create_visual( config->rgba, config->doubleBuffer, config->stereo, - _mesa_bitcount(visinfo->red_mask), - _mesa_bitcount(visinfo->green_mask), - _mesa_bitcount(visinfo->blue_mask), + _mesa_bitcount( visinfo->red_mask ), + _mesa_bitcount( visinfo->green_mask ), + _mesa_bitcount( visinfo->blue_mask ), config->alphaSize, 0, /* index bits */ config->depthSize, @@ -142,216 +156,247 @@ XMesaCreateVisual(Display * dpy, config->accumGreenSize, config->accumBlueSize, config->accumAlphaSize, - 0 /* num samples */ - ); + 0 /* num samples */ ); } GLboolean -XMesaCreateContext(Display * dpy, GLvisual * mesaVis, - __DRIcontextPrivate * driContextPriv) +XMesaCreateContext( Display *dpy, GLvisual *mesaVis, + __DRIcontextPrivate *driContextPriv ) { - fxMesaContext fxMesa; - __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; - tdfxScreenPrivate *sPriv = (tdfxScreenPrivate *) driScrnPriv->private; - TDFXSAREAPriv *saPriv; - - fxMesa = (fxMesaContext) Xmalloc(sizeof(struct tfxMesaContext)); - if (!fxMesa) { - return GL_FALSE; - } - - fxMesa->hHWContext = driContextPriv->hHWContext; - fxMesa->tdfxScrnPriv = sPriv; - /* deviceID = 0x05 = Voodoo3 */ - /* deviceID = 0x09 = Voodoo5 (and Voodoo4?) */ - fxMesa->isNapalm = sPriv->deviceID == PCI_CHIP_VOODOO5; - fxMesa->haveHwStencil = fxMesa->isNapalm && sPriv->cpp == 4; - - - fxMesa->glVis = mesaVis; - fxMesa->screen_width = sPriv->width; - fxMesa->screen_height = sPriv->height; - fxMesa->new_state = ~0; - fxMesa->driContextPriv = driContextPriv; - fxMesa->glCtx = driContextPriv->mesaContext; - fxMesa->initDone = GL_FALSE; - - saPriv = - (TDFXSAREAPriv *) ((char *) driScrnPriv->pSAREA + - sizeof(XF86DRISAREARec)); - grDRIOpen(driScrnPriv->pFB, sPriv->regs.map, sPriv->deviceID, - sPriv->width, sPriv->height, sPriv->mem, sPriv->cpp, - sPriv->stride, sPriv->fifoOffset, sPriv->fifoSize, - sPriv->fbOffset, sPriv->backOffset, sPriv->depthOffset, - sPriv->textureOffset, sPriv->textureSize, &saPriv->fifoPtr, - &saPriv->fifoRead); - - driContextPriv->driverPrivate = (void *) fxMesa; + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, driContextPriv ); + } - return GL_TRUE; + return tdfxCreateContext( dpy, mesaVis, driContextPriv ); } void -XMesaDestroyContext(__DRIcontextPrivate * driContextPriv) +XMesaDestroyContext( __DRIcontextPrivate *driContextPriv ) { - fxMesaContext fxMesa = (fxMesaContext) driContextPriv->driverPrivate; - if (fxMesa) { - if (fxMesa->glCtx->Shared->RefCount == 1) { - /* This share group is about to go away, free our private - * texture object data. - */ - struct gl_texture_object *tObj; - tObj = fxMesa->glCtx->Shared->TexObjectList; - while (tObj) { - fxTMFreeTexture(fxMesa, tObj); - tObj = tObj->Next; - } - } - XFree(fxMesa); - driContextPriv->driverPrivate = NULL; - } + tdfxContextPtr fxMesa; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, driContextPriv ); + } + + fxMesa = (tdfxContextPtr) driContextPriv->driverPrivate; + tdfxDestroyContext( fxMesa ); + driContextPriv->driverPrivate = NULL; } GLframebuffer * -XMesaCreateWindowBuffer(Display * dpy, - __DRIscreenPrivate * driScrnPriv, - __DRIdrawablePrivate * driDrawPriv, - GLvisual * mesaVis) +XMesaCreateWindowBuffer( Display *dpy, + __DRIscreenPrivate *driScrnPriv, + __DRIdrawablePrivate *driDrawPriv, + GLvisual *mesaVis ) { - return gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0, - mesaVis->AccumRedBits > 0, - GL_FALSE /* software alpha channel? */ - ); + return gl_create_framebuffer( mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->StencilBits > 0, + mesaVis->AccumRedBits > 0, + GL_FALSE /* software alpha channel? */ ); } GLframebuffer * -XMesaCreatePixmapBuffer(Display * dpy, - __DRIscreenPrivate * driScrnPriv, - __DRIdrawablePrivate * driDrawPriv, - GLvisual * mesaVis) +XMesaCreatePixmapBuffer( Display *dpy, + __DRIscreenPrivate *driScrnPriv, + __DRIdrawablePrivate *driDrawPriv, + GLvisual *mesaVis ) { #if 0 - /* Different drivers may have different combinations of hardware and - * software ancillary buffers. - */ - return gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0, - mesaVis->AccumRedBits > 0, - mesaVis->AlphaBits > 0); + /* Different drivers may have different combinations of hardware and + * software ancillary buffers. + */ + return gl_create_framebuffer( mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->StencilBits > 0, + mesaVis->AccumRedBits > 0, + mesaVis->AlphaBits > 0 ); #else - return NULL; /* not implemented yet */ + return NULL; /* not implemented yet */ #endif } - void -XMesaSwapBuffers(__DRIdrawablePrivate * driDrawPriv) +XMesaSwapBuffers( __DRIdrawablePrivate *driDrawPriv ) { - GET_CURRENT_CONTEXT(ctx); - fxMesaContext fxMesa = 0; - - if (!driDrawPriv->mesaBuffer->Visual->DBflag) - return; /* can't swap a single-buffered window */ - - /* If the current context's drawable matches the given drawable - * we have to do a glFinish (per the GLX spec). - */ - if (ctx) { - __DRIdrawablePrivate *curDrawPriv; - fxMesa = FX_CONTEXT(ctx); - curDrawPriv = fxMesa->driContextPriv->driDrawablePriv; - if (curDrawPriv == driDrawPriv) { - /* swapping window bound to current context, flush first */ - FLUSH_VB(ctx, "swap buffers"); - BEGIN_BOARD_LOCK(fxMesa); - } - else { - /* make fxMesa context current */ - grGlideGetState((GrState *) fxMesa->state); - fxMesa = (fxMesaContext) driDrawPriv->driContextPriv->driverPrivate; - BEGIN_BOARD_LOCK(fxMesa); - grSstSelect(fxMesa->board); - grGlideSetState((GrState *) fxMesa->state); - } - } - + GET_CURRENT_CONTEXT(ctx); + tdfxContextPtr fxMesa = 0; + + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, driDrawPriv ); + } + + if ( !driDrawPriv->mesaBuffer->Visual->DBflag ) + return; /* can't swap a single-buffered window */ + + /* If the current context's drawable matches the given drawable + * we have to do a glFinish (per the GLX spec). + */ + if ( ctx ) { + __DRIdrawablePrivate *curDrawPriv; + fxMesa = TDFX_CONTEXT(ctx); + curDrawPriv = fxMesa->driContext->driDrawablePriv; + + if ( curDrawPriv == driDrawPriv ) { + /* swapping window bound to current context, flush first */ + FLUSH_VB( ctx, "swap buffers" ); + LOCK_HARDWARE( fxMesa ); + } + else { + /* find the fxMesa context previously bound to the window */ + fxMesa = (tdfxContextPtr) driDrawPriv->driContextPriv->driverPrivate; + if (!fxMesa) + return; + LOCK_HARDWARE( fxMesa ); + grSstSelect( fxMesa->Glide.Board ); + grGlideSetState( (GrState *) fxMesa->Glide.State ); + } + } #ifdef STATS - { - int stalls; - static int prevStalls = 0; - stalls = grFifoGetStalls(); - if (stalls != prevStalls) { - fprintf(stderr, "%d stalls occurred\n", stalls - prevStalls); - prevStalls = stalls; - } - if (fxMesa && fxMesa->texSwaps) { - fprintf(stderr, "%d texture swaps occurred\n", fxMesa->texSwaps); - fxMesa->texSwaps = 0; - } - } + { + int stalls; + static int prevStalls = 0; + + stalls = grFifoGetStalls(); + + fprintf( stderr, "%s:\n", __FUNCTION__ ); + if ( stalls != prevStalls ) { + fprintf( stderr, " %d stalls occurred\n", + stalls - prevStalls ); + prevStalls = stalls; + } + if ( fxMesa && fxMesa->texSwaps ) { + fprintf( stderr, " %d texture swaps occurred\n", + fxMesa->texSwaps ); + fxMesa->texSwaps = 0; + } + } #endif + if (fxMesa->scissoredClipRects) { + /* restore clip rects without scissor box */ + grDRIPosition( driDrawPriv->x, driDrawPriv->y, + driDrawPriv->w, driDrawPriv->h, + driDrawPriv->numClipRects, driDrawPriv->pClipRects ); + } - /* XXX prototype grDRISwapClipRects() function may not be - * needed after all - */ -#if 0 - FX_grDRIBufferSwap(fxMesa, fxMesa->swapInterval); -#elif 1 - grDRIBufferSwap(fxMesa->swapInterval); -#else - grDRISwapClipRects(fxMesa->swapInterval, - driDrawPriv->numClipRects, - driDrawPriv->pClipRects); -#endif + grDRIBufferSwap( fxMesa->Glide.SwapInterval ); + + if (fxMesa->scissoredClipRects) { + /* restore clip rects WITH scissor box */ + grDRIPosition( driDrawPriv->x, driDrawPriv->y, + driDrawPriv->w, driDrawPriv->h, + fxMesa->numClipRects, fxMesa->pClipRects ); + } #if 0 - { - FxI32 result; - do { - result = FX_grGetInteger(FX_PENDING_BUFFERSWAPS); - } while (result > fxMesa->maxPendingSwapBuffers); - } + { + FxI32 result; + do { + result = FX_grGetInteger( FX_PENDING_BUFFERSWAPS ); + } while ( result > fxMesa->maxPendingSwapBuffers ); + } #endif - fxMesa->stats.swapBuffer++; - - - if (ctx) { - if (ctx->DriverCtx != fxMesa) { - /* restore original context */ - fxMesa = FX_CONTEXT(ctx); - grSstSelect(fxMesa->board); - grGlideSetState((GrState *) fxMesa->state); - } - END_BOARD_LOCK(fxMesa); - } + + fxMesa->stats.swapBuffer++; + + if (ctx) { + if (ctx->DriverCtx != fxMesa) { + fxMesa = TDFX_CONTEXT(ctx); + grSstSelect( fxMesa->Glide.Board ); + grGlideSetState( (GrState *) fxMesa->Glide.State ); + } + UNLOCK_HARDWARE( fxMesa ); + } } GLboolean -XMesaUnbindContext(__DRIcontextPrivate * driContextPriv) +XMesaUnbindContext( __DRIcontextPrivate *driContextPriv ) { - GET_CURRENT_CONTEXT(ctx); - if (driContextPriv && driContextPriv->mesaContext == ctx) { - fxMesaContext fxMesa = FX_CONTEXT(ctx); - FX_grGlideGetState(fxMesa, (GrState *) fxMesa->state); - } - return GL_TRUE; + GET_CURRENT_CONTEXT(ctx); + + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, driContextPriv ); + } + + if ( driContextPriv && driContextPriv->mesaContext == ctx ) { + tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx); + FX_grGlideGetState( fxMesa, (GrState *) fxMesa->Glide.State ); + } + return GL_TRUE; } + +GLboolean +XMesaMakeCurrent( __DRIcontextPrivate *driContextPriv, + __DRIdrawablePrivate *driDrawPriv, + __DRIdrawablePrivate *driReadPriv ) +{ + if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) { + fprintf( stderr, "%s( %p )\n", __FUNCTION__, driContextPriv ); + } + + if ( driContextPriv ) { + tdfxContextPtr fxMesa = (tdfxContextPtr) driContextPriv->driverPrivate; + GLcontext *ctx = fxMesa->glCtx; + + if ( fxMesa->driDrawable != driDrawPriv ) { + fxMesa->driDrawable = driDrawPriv; + fxMesa->dirty = ~0; + } + + if ( !fxMesa->Glide.Initialized ) { + if ( !tdfxInitContext( driDrawPriv, fxMesa ) ) + return GL_FALSE; + + LOCK_HARDWARE( fxMesa ); + + /* FIXME: Force loading of window information */ + fxMesa->width = 0; + tdfxUpdateClipping(ctx); + tdfxUploadClipping(fxMesa); + + UNLOCK_HARDWARE( fxMesa ); + } else { + LOCK_HARDWARE( fxMesa ); + + grSstSelect( fxMesa->Glide.Board ); + grGlideSetState( fxMesa->Glide.State ); + + tdfxUpdateClipping(ctx); + tdfxUploadClipping(fxMesa); + + UNLOCK_HARDWARE( fxMesa ); + } + + assert( ctx == driContextPriv->mesaContext ); + + gl_make_current2( ctx, driDrawPriv->mesaBuffer, + driReadPriv->mesaBuffer ); + + if ( !ctx->Viewport.Width ) { + gl_Viewport( ctx, 0, 0, driDrawPriv->w, driDrawPriv->h ); + } + } else { + gl_make_current( 0, 0 ); + } + + return GL_TRUE; +} + + GLboolean XMesaOpenFullScreen(__DRIcontextPrivate *driContextPriv) { - fprintf(stderr,"XMesaOpenFullScreen\n"); + fprintf(stderr,"***** XMesaOpenFullScreen *****\n"); #if 0 /* When new glide3 calls exist */ return((GLboolean)grDRISetupFullScreen(GL_TRUE)); #else @@ -359,6 +404,7 @@ XMesaOpenFullScreen(__DRIcontextPrivate *driContextPriv) #endif } + GLboolean XMesaCloseFullScreen(__DRIcontextPrivate *driContextPriv) { @@ -371,182 +417,24 @@ XMesaCloseFullScreen(__DRIcontextPrivate *driContextPriv) } -/* - * This function sends the window position and cliprect list to - * Glide for the given context. - */ -static void -XMesaWindowMoved(fxMesaContext fxMesa) -{ - __DRIdrawablePrivate *dPriv = fxMesa->driContextPriv->driDrawablePriv; - GLcontext *ctx = fxMesa->glCtx; - - grDRIPosition(dPriv->x, dPriv->y, dPriv->w, dPriv->h, - dPriv->numClipRects, dPriv->pClipRects); - fxMesa->numClipRects = dPriv->numClipRects; - fxMesa->pClipRects = dPriv->pClipRects; - if (dPriv->x != fxMesa->x_offset || dPriv->y != fxMesa->y_offset || - dPriv->w != fxMesa->width || dPriv->h != fxMesa->height) { - fxMesa->x_offset = dPriv->x; - fxMesa->y_offset = dPriv->y; - fxMesa->width = dPriv->w; - fxMesa->height = dPriv->h; - fxMesa->y_delta = - fxMesa->screen_height - fxMesa->y_offset - fxMesa->height; - } - switch (dPriv->numClipRects) { - case 0: - fxMesa->clipMinX = dPriv->x; - fxMesa->clipMaxX = dPriv->x + dPriv->w; - fxMesa->clipMinY = dPriv->y; - fxMesa->clipMaxY = dPriv->y + dPriv->h; - fxSetScissorValues(ctx); - fxMesa->needClip = 0; - break; - case 1: - fxMesa->clipMinX = dPriv->pClipRects[0].x1; - fxMesa->clipMaxX = dPriv->pClipRects[0].x2; - fxMesa->clipMinY = dPriv->pClipRects[0].y1; - fxMesa->clipMaxY = dPriv->pClipRects[0].y2; - fxSetScissorValues(ctx); - fxMesa->needClip = 0; - break; - default: - fxMesa->needClip = 1; - } -} - - -GLboolean -XMesaMakeCurrent(__DRIcontextPrivate * driContextPriv, - __DRIdrawablePrivate * driDrawPriv, - __DRIdrawablePrivate * driReadPriv) -{ - if (driContextPriv) { - fxMesaContext fxMesa; - - fxMesa = (fxMesaContext) driContextPriv->driverPrivate; - - if (!fxMesa->initDone) { - if (!tdfxInitHW(driDrawPriv, fxMesa)) - return GL_FALSE; - fxMesa->width = 0; - XMesaWindowMoved(fxMesa); - FX_grGlideGetState(fxMesa, (GrState *) fxMesa->state); - } - else { - FX_grSstSelect(fxMesa, fxMesa->board); - FX_grGlideSetState(fxMesa, (GrState *) fxMesa->state); - XMesaWindowMoved(fxMesa); - } - - assert(fxMesa->glCtx == driContextPriv->mesaContext); - - gl_make_current2(fxMesa->glCtx, driDrawPriv->mesaBuffer, - driReadPriv->mesaBuffer); - - if (!fxMesa->glCtx->Viewport.Width) - gl_Viewport(fxMesa->glCtx, 0, 0, driDrawPriv->w, driDrawPriv->h); - } - else { - gl_make_current(0, 0); - } - return GL_TRUE; -} - - -/* This is called from within the LOCK_HARDWARE routine */ -void -XMesaUpdateState(fxMesaContext fxMesa) -{ - __DRIcontextPrivate *cPriv = fxMesa->driContextPriv; - __DRIdrawablePrivate *dPriv = cPriv->driDrawablePriv; - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; - TDFXSAREAPriv *saPriv = (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) + - sizeof(XF86DRISAREARec)); - int stamp; - char ret; - - DEBUG_CHECK_LOCK(); - DRM_CAS(&sPriv->pSAREA->lock, dPriv->driContextPriv->hHWContext, - DRM_LOCK_HELD | dPriv->driContextPriv->hHWContext, ret); - if (!ret) { - DEBUG_LOCK(); - return; - } - drmGetLock(sPriv->fd, dPriv->driContextPriv->hHWContext, 0); - stamp = dPriv->lastStamp; - /* This macro will update dPriv's cliprects if needed */ - XMESA_VALIDATE_DRAWABLE_INFO(cPriv->display, sPriv, dPriv); - /* fprintf(stderr, "In FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ - if (saPriv->fifoOwner != dPriv->driContextPriv->hHWContext) { - grDRIImportFifo(saPriv->fifoPtr, saPriv->fifoRead); - } - if (saPriv->ctxOwner != dPriv->driContextPriv->hHWContext) { - /* This sequence looks a little odd. Glide mirrors the state, and - when you get the state you are forcing the mirror to be up to - date, and then getting a copy from the mirror. You can then force - that state onto the hardware when you set the state. */ - void *state; - state = malloc(FX_grGetInteger_NoLock(FX_GLIDE_STATE_SIZE)); - FX_grGlideGetState_NoLock(state); - FX_grGlideSetState_NoLock(state); - free(state); - } - if (saPriv->texOwner != dPriv->driContextPriv->hHWContext) { - fxTMRestoreTextures_NoLock(fxMesa); - } -#if 0 - if (*dPriv->pStamp != stamp) -#else - if (*dPriv->pStamp != stamp || - saPriv->ctxOwner != dPriv->driContextPriv->hHWContext) -#endif - XMesaWindowMoved(fxMesa); - DEBUG_LOCK(); -} - - -/* - * XXX is this used by anyone? +/* Silence compiler warnings. */ -#if 000 -static void -XMesaSetSAREA(void) -{ - __DRIdrawablePrivate *dPriv = gCC->driDrawablePriv; - __DRIscreenPrivate *sPriv = dPriv->driScreenPriv; - TDFXSAREAPriv *saPriv = - (TDFXSAREAPriv *) (((char *) sPriv->pSAREA) + - sizeof(XF86DRISAREARec)); - - saPriv->fifoOwner = dPriv->driContextPriv->hHWContext; - saPriv->ctxOwner = dPriv->driContextPriv->hHWContext; - saPriv->texOwner = dPriv->driContextPriv->hHWContext; - grDRIResetSAREA(); - /* fprintf(stderr, "Out FifoPtr=%d FifoRead=%d\n", saPriv->fifoPtr, saPriv->fifoRead); */ -} -#endif - - - -extern void __driRegisterExtensions(void); /* silence compiler warning */ +extern void __driRegisterExtensions( void ); /* This function is called by libGL.so as soon as libGL.so is loaded. * This is where we'd register new extension functions with the dispatcher. */ -void -__driRegisterExtensions(void) +void __driRegisterExtensions( void ) { #if 0 - /* Example. Also look in fxdd.c for more details. */ - { - const int _gloffset_FooBarEXT = 555; /* just an example number! */ - if (_glapi_add_entrypoint("glFooBarEXT", _gloffset_FooBarEXT)) { - void *f = glXGetProcAddressARB("glFooBarEXT"); - assert(f); - } - } + /* Example. Also look in tdfx_dd.c for more details. */ + { + const int _gloffset_FooBarEXT = 555; /* just an example number! */ + if ( _glapi_add_entrypoint( "glFooBarEXT", _gloffset_FooBarEXT ) ) { + void *f = glXGetProcAddressARB( "glFooBarEXT" ); + assert( f ); + } + } #endif } |