Ejemplo n.º 1
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;
    GrContext_t          gc = 0;

    static unsigned short colorBuf[64][64];
    static unsigned short grabBuf[64][64];
    
    int x,y;

    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    grSstSelect( 0 );
    gc = grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1 );
    if (!gc) {
      printf("Could not allocate glide fullscreen context.\n");
      goto __errExit;
    }
    
    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f, 
              60, 15, 0xffffff );

    /* Set up Render State - disable dithering*/
    grDitherMode( GR_DITHER_DISABLE );


    /* Create Source Bitmap to be copied to framebuffer */
    for( y = 0; y < 64; y++ ) {
        for( x = 0; x < 64; x++ ) {
            FxU8 red = x << 2;
            FxU8 grn = y << 2;
            FxU8 blu = ( x + y )<<1;
            colorBuf[y][x] =  (red & 0xF8) << 8;
            colorBuf[y][x] |= (grn & 0xFC) << 3;
            colorBuf[y][x] |= (blu & 0xF8) >> 3;
        }
    }


    tlConOutput( "Press any key to quit\n" );
    while( frames-- && tlOkToRender()) {
        GrLfbInfo_t info;
        int startX, startY;

        if (hwconfig == TL_VOODOORUSH) {
          tlGetDimsByConst(resolution,
                           &scrWidth, 
                           &scrHeight );
        
          grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grBufferClear( 0x00, 0, 0 );

        /* prepare info structure */
        info.size = sizeof( GrLfbInfo_t );
        
        /* lock back buffer */
        if ( grLfbLock( GR_LFB_WRITE_ONLY,
                        GR_BUFFER_BACKBUFFER,
                        GR_LFBWRITEMODE_565,
                        GR_ORIGIN_UPPER_LEFT,
                        FXFALSE,
                        &info )==FXFALSE) {
            tlConOutput( "Error, failed to take write lock\n" );
            break;
        } 

        if ( tlScaleX(1.0f) < 64.0 ||
             tlScaleY(1.0f) < 64.0 )
            return;
        
        /* generate random start position */
        startX = (int)rRandom( 64, (int)tlScaleX(1.0f) - 65 );
        startY = (int)rRandom( 64, (int)tlScaleY(1.0f) - 65 );
        
        /* render image to back buffer */
        for( y = 0; y < 64; y++ ) {
            for( x = 0; x < 64; x++ ) {
                FxU16 *pixel = 
                    (FxU16*)(((char*)info.lfbPtr) + 
                             (y+startY)*info.strideInBytes+
                             (x+startX)*2);
                *pixel = colorBuf[y][x];
            }
        }
        /* unlock the backbuffer */
        grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );

        /* swap to front buffer */
        grBufferSwap( 1 );
        grBufferClear( 0,0,0 );

        tlSleep( 1 );
        
        /* lock the front buffer */
        if ( grLfbLock( GR_LFB_READ_ONLY,
                        GR_BUFFER_FRONTBUFFER,
                        GR_LFBWRITEMODE_ANY,
                        GR_ORIGIN_UPPER_LEFT,
                        FXFALSE,
                        &info )==FXFALSE) {
            tlConOutput( "Error, failed to take read lock\n" );
            break;
        } 
        
        /* grab the source image out of the front buffer */
        for( y = 0; y < 64; y++ ) {
            for( x = 0; x < 64; x++ ) {
                FxU16 *pixel = 
                    (FxU16*)(((char*)info.lfbPtr) + 
                             (y+startY)*info.strideInBytes+
                             (x+startX)*2);
                grabBuf[y][x] = *pixel;
            }
        }
        /* unlock the front buffer */
        grLfbUnlock( GR_LFB_READ_ONLY, GR_BUFFER_FRONTBUFFER );

        tlConClear();
        
        /* compare the source image to the readback image */
        if ( memcmp( colorBuf, grabBuf, sizeof( colorBuf ) ) ) {
            tlConOutput( "Failed readback test\n" );
        } else {
            tlConOutput( "Passed readback test\n" );
        }

        grBufferSwap( 1 );
        tlConOutput( "Press any key to quit\n" );
        tlConRender();
        grBufferSwap( 1 );

        tlSleep( 1 );

        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            default:
                frames = 0;
                break;
            }
        }
    }
    
 __errExit:    
    grGlideShutdown();
    return;
}
Ejemplo n.º 2
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;
    int doNothing = 0;

    int cycles;
    FxU32 wrange[2];

    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "Nnr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        case 'N':
            doNothing = 1;
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    grSstSelect( 0 );


    cycles = 0;
    while( frames-- && tlOkToRender()) {
        GrVertex a, b, c;
        GrContext_t context;
        char inchar;

        context = grSstWinOpen(tlGethWnd(),
                               resolution,
                               GR_REFRESH_60Hz,
                               GR_COLORFORMAT_ABGR,
                               GR_ORIGIN_UPPER_LEFT,
                               2, 1 );
        assert(context);

        /* 
         * Don't like gotos?  In the immortal words of Schwarzenegger
         * (Total Recall): "...so sue me d**khead"
         */
        if (doNothing) goto doNothing;

        grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
        grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
        grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  

        grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                        GR_COMBINE_FACTOR_NONE,
                        GR_COMBINE_LOCAL_ITERATED,
                        GR_COMBINE_OTHER_NONE,
                        FXFALSE );

        tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
                  60, 30, 0xffffff );
        
        
        /* deal with dynamic resizing */
        if (hwconfig == TL_VOODOORUSH) {
          tlGetDimsByConst(resolution, &scrWidth, &scrHeight);
          grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        tlConOutput( "Press <space> to cycle hardware\n" );
        tlConOutput( "Any other key to quit\n" );
        
        grBufferClear( 0x000000, 0, wrange[1] );

        a.r = a.g = a.b = 0.0f;
        b = c = a;

        a.x = tlScaleX(((float)rRandom( 0, 100 ))/100.0f);
        a.y = tlScaleY(((float)rRandom( 0, 100 ))/100.0f);
        a.r = 255.0f;

        b.x = tlScaleX(((float)rRandom( 0, 100 ))/100.0f);
        b.y = tlScaleY(((float)rRandom( 0, 100 ))/100.0f);
        b.g = 255.0f;

        c.x = tlScaleX(((float)rRandom( 0, 100 ))/100.0f);
        c.y = tlScaleY(((float)rRandom( 0, 100 ))/100.0f);
        c.b = 255.0f;

        grDrawTriangle( &a, &b, &c );

        tlConOutput( "Cycle: %d\r", cycles );
        tlConRender();
        grBufferSwap( 1 );

doNothing:
        inchar = tlGetCH();
        if ( inchar != ' ' ) frames = 0;
        
        grSstWinClose(context);
        cycles++;
    }
    
    grGlideShutdown();
    return;
}
Ejemplo n.º 3
0
void
main( int argc, char **argv) {
  char match; 
  char **remArgs;
  int  rv;
  
  GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
  float                scrWidth   = 640.0f;
  float                scrHeight  = 480.0f;
  int frames                      = -1;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU32                wrange[2];

  
  /* Process Command Line Arguments */
  while( rv = tlGetOpt( argc, argv, "nrd", &match, &remArgs ) ) {
    if ( rv == -1 ) {
      printf( "Unrecognized command line argument\n" );
      printf( "%s %s\n", name, usage );
      printf( "Available resolutions:\n%s\n",
             tlGetResolutionList() );
      return;
    }
    switch( match ) {
    case 'n':
      frames = atoi( remArgs[0] );
      break;
    case 'r':
      resolution = tlGetResolutionConstant( remArgs[0], 
                                           &scrWidth, 
                                           &scrHeight );
      break;
    case 'd':
      scrgrab = FXTRUE;
      frames = 1;
      strcpy(filename, remArgs[0]);
      break;
    }
  }
  
  tlSetScreen( scrWidth, scrHeight );
  
  version = grGetString( GR_VERSION );
  
  printf( "%s:\n%s\n", name, purpose );
  printf( "%s\n", version );
  printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
  if ( frames == -1 ) {
    printf( "Press A Key To Begin Test.\n" );
    tlGetCH();
  }
  
  /* Initialize Glide */
  grGlideInit();

  assert( hwconfig = tlVoodooType() );

  grSstSelect( 0 );
  assert( grSstWinOpen( 0,
                       resolution,
                       GR_REFRESH_60Hz,
                       GR_COLORFORMAT_ABGR,
                       GR_ORIGIN_UPPER_LEFT,
                       2, 1 ) );
  
  grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  
  grVertexLayout(GR_PARAM_XY, 0, GR_PARAM_ENABLE);

  tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
           60, 30, 0xffffff );
  
  /* Set up Render State - flat shading */
  grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                 GR_COMBINE_FACTOR_NONE,
                 GR_COMBINE_LOCAL_CONSTANT,
                 GR_COMBINE_OTHER_NONE,
                 FXFALSE );
  grConstantColorValue( 0xFFFFFF );
  
  
  tlConOutput( "Press a key to quit\n" );
  while( frames-- && tlOkToRender()) {
    int i;
    GrVertex vtx;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight );
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    } 
    grBufferClear(0x00000000, 0, wrange[1]);

    for( i = 0; i < 100; i++ ) {
      float pos = ((float)i)/100.0f;

      vtx.x = tlScaleX( pos ), vtx.y = tlScaleY( pos );
      grDrawPoint( &vtx );
    }


    tlConRender();
    grBufferSwap( 1 );

    /* grab the frame buffer */
    if (scrgrab) {
      if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
        printf( "Cannot open %s\n", filename);
      scrgrab = FXFALSE;
    }
    if ( tlKbHit() ) frames = 0;
  }
  
  grGlideShutdown();
  return;
}
Ejemplo n.º 4
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;
    FxBool               scrgrab = FXFALSE;
    char                 filename[256];
    int                  ftsize = 0;

    TlTexture  baseTexture;
    unsigned long baseTextureAddr;
    GrVertex vtxA, vtxB, vtxC, vtxD;
    FxBool texchroma = FXFALSE;
    char *extstr;

    GrProc grTexChromaModeExt = NULL;
    GrProc grTexChromaRangeExt = NULL;
    GrColor_t min = 0x00, max = 0x007f7f7f;
    FxU8 mincolor = 0x00;
    FxU8 maxcolor = 0x7f;
    FxFloat red = 1.7f, green = 1.7f, blue = 1.7f;

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nrd", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        case 'd':
            scrgrab = FXTRUE;
            frames = 1;
            strcpy(filename, remArgs[0]);
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    grSstSelect( 0 );
    assert( grSstWinOpen( 0,
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1 ) );
    
    tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
              60, 30, 0xffffff );

    grVertexLayout(GR_PARAM_XY,  GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                    GR_COMBINE_FACTOR_ONE,
                    GR_COMBINE_LOCAL_NONE,
                    GR_COMBINE_OTHER_TEXTURE,
                    FXFALSE );
    grTexMipMapMode( GR_TMU0,
                     GR_MIPMAP_NEAREST,
                     FXFALSE );
    grTexFilterMode( GR_TMU0,
                     GR_TEXTUREFILTER_BILINEAR,
                     GR_TEXTUREFILTER_BILINEAR );

    {
      /*
      ** texChroma extension
      */
      extension = grGetString(GR_EXTENSION);

      extstr = strstr(extension, "CHROMARANGE");
      if (!strncmp(extstr, "CHROMARANGE", 11)) {
        grTexChromaModeExt = grGetProcAddress("grTexChromaModeExt");
        grTexChromaRangeExt = grGetProcAddress("grTexChromaRangeExt");
      }
      grTexChromaModeExt(GR_TMU0, GR_TEXCHROMA_DISABLE_EXT);
      grTexChromaRangeExt(0, min, max, GR_TEXCHROMARANGE_RGB_ALL_EXT);
    }

    assert( tlLoadTexture( "miro.3df", 
                           &baseTexture.info, 
                           &baseTexture.tableType, 
                           &baseTexture.tableData ) );
    /* Download texture data to TMU */
    baseTextureAddr = grTexMinAddress( GR_TMU0 );
    grTexDownloadMipMap( GR_TMU0,
                         baseTextureAddr,
                         GR_MIPMAPLEVELMASK_BOTH,
                         &baseTexture.info );
    if ( baseTexture.tableType != NO_TABLE ) {
        grTexDownloadTable( baseTexture.tableType,
                            &baseTexture.tableData );
    }
    grTexCombine( GR_TMU0,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  GR_COMBINE_FUNCTION_LOCAL,
                  GR_COMBINE_FACTOR_NONE,
                  FXFALSE,
                  FXFALSE );
    grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ZERO,
                          GR_BLEND_ONE, GR_BLEND_ZERO );
    grTexSource( GR_TMU0,
                 baseTextureAddr,
                 GR_MIPMAPLEVELMASK_BOTH,
                 &baseTexture.info );
    grTexClampMode( GR_TMU0, GR_TEXTURECLAMP_WRAP, GR_TEXTURECLAMP_WRAP);

    {
      vtxA.x = tlScaleX( 0.2f );
      vtxA.y = tlScaleY( 0.2f );
      vtxA.oow = 1.0f;
      
      vtxB.x = tlScaleX( 0.8f );
      vtxB.y = tlScaleY( 0.2f ); 
      vtxB.oow = 1.0f;
      
      vtxC.x = tlScaleX( 0.2f );
      vtxC.y = tlScaleY( 0.8f );
      vtxC.oow = 1.0f;
      
      vtxD.x = tlScaleX( 0.8f ); 
      vtxD.y = tlScaleY( 0.8f );
      vtxD.oow = 1.0f;
      
      vtxA.tmuvtx[0].sow = 0.f;
      vtxA.tmuvtx[0].tow = 0.f;
      
      vtxB.tmuvtx[0].sow = 255.f;
      vtxB.tmuvtx[0].tow = 0.f;
      
      vtxC.tmuvtx[0].sow = 0.f;
      vtxC.tmuvtx[0].tow = 255.f;
      
      vtxD.tmuvtx[0].sow = 255.f;
      vtxD.tmuvtx[0].tow = 255.f;
    }
    
    tlConOutput( "Press a key to quit\n" );
    tlConOutput( "Press c to turn on/off texture chroma\n" );
    tlConOutput( "Press {/} to change max color range\n" );
    tlConOutput( "Press [/] to change min color range\n" );
    while( frames-- && tlOkToRender()) {
      char string[256], tmpstr[64];

      if (texchroma)
        strcpy(string, "");
      else
        strcpy(string, "");
      sprintf(tmpstr, " (%x,%x,%x) (%x,%x,%x) (%f %f %f)   \r", mincolor, mincolor, mincolor, maxcolor, maxcolor, maxcolor,red,green,blue);
      strcat(string, tmpstr);

      tlConOutput( string );

      if (hwconfig == TL_VOODOORUSH) {
        tlGetDimsByConst(resolution,
                         &scrWidth, 
                         &scrHeight );
        
        grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
      }

      grBufferClear( 0x3f3f3f, 0, 0 );
      
      grDrawTriangle( &vtxA, &vtxB, &vtxD );
      grDrawTriangle( &vtxA, &vtxD, &vtxC );
      
      tlConRender();
      grBufferSwap( 1 );
      
      /* grab the frame buffer */
      if (scrgrab) {
        if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
          printf( "Cannot open %s\n", filename);
        scrgrab = FXFALSE;
      }
      
      while( tlKbHit() ) {
        switch( tlGetCH() ) {
        case 'r':
          red -= 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'R':
          red += 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'g':
          green -= 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'G':
          green += 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'b':
          blue -= 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'B':
          blue += 0.1f;
          guGammaCorrectionRGB(red, green, blue);
          break;
        case 'c':
        case 'C':
          texchroma = !texchroma;
          if (texchroma)
            grTexChromaModeExt(GR_TMU0, GR_TEXCHROMA_ENABLE_EXT);
          else
            grTexChromaModeExt(GR_TMU0, GR_TEXCHROMA_DISABLE_EXT);
          break;
        case '{':
          if ((maxcolor > 0x00) && (maxcolor > mincolor))
            maxcolor--;
          max = (maxcolor << 16) | (maxcolor << 8) | maxcolor;
          grTexChromaRangeExt(0, min, max, GR_TEXCHROMARANGE_RGB_ALL_EXT);
          break;
        case '}':
          if (maxcolor < 0xff)
            maxcolor++;
          max = (maxcolor << 16) | (maxcolor << 8) | maxcolor;
          grTexChromaRangeExt(0, min, max, GR_TEXCHROMARANGE_RGB_ALL_EXT);
          break;
        case '[':
          if (mincolor > 0x00)
            mincolor--;
          min = (mincolor << 16) | (mincolor << 8) | mincolor;
          grTexChromaRangeExt(0, min, max, GR_TEXCHROMARANGE_RGB_ALL_EXT);
          break;
        case ']':
          if ((mincolor < 0xff) && (mincolor < maxcolor))
            mincolor++;
          min = (mincolor << 16) | (mincolor << 8) | mincolor;
          grTexChromaRangeExt(0, min, max, GR_TEXCHROMARANGE_RGB_ALL_EXT);
          break;
        default:
          frames = 0;
          break;
        }
      }
    }
    
    grGlideShutdown();
    return;
}
Ejemplo n.º 5
0
int
main(int argc, char **argv) 
{
  char match; 
  char **remArgs;
  int  rv = -1;

  GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
  float                scrWidth   = 640.0f;
  float                scrHeight  = 480.0f;
  int frames                      = -1;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU32                wrange[2];

  FxU32
    multiBaseMode = 0, 
    minTexSize = 1,
    maxTexSize = 256;

  const TlVertex3D 
    srcVerts[4] = 
  {
    { -0.5f, 0.0f,  0.5f, 1.0f, 0.0f, 0.0f },
    {  0.5f, 0.0f,  0.5f, 1.0f, 1.0f, 0.0f },
    { -0.5f, 0.0f, -0.5f, 1.0f, 0.0f, 1.0f },
    {  0.5f, 0.0f, -0.5f, 1.0f, 1.0f, 1.0f }
  };

  /* Initialize Glide */
  grGlideInit();
  if ((hwconfig = tlVoodooType()) == 0) {
    printf("Error getting 3Dfx hw type.\n");
    exit(-1);
  }
  /* Process Command Line Arguments */
  while(rv = tlGetOpt(argc, argv, "dmnrx", &match, &remArgs)) {
    if (rv == -1) {
      printf("Unrecognized command line argument\n");
      printf("%s %s\n", name, usage);
      printf("Available resolutions:\n%s\n",
              tlGetResolutionList());
      exit(-1);
    }

    switch(match) {
    case 'd':
      scrgrab = FXTRUE;
      if (scrgrab) {
        frames = 1;
        strcpy(filename, remArgs[0]);
      }
      break;
    case 'm':
      /* Do we want to test larger sizes if the hw supports it? */
      if (!grGet(GR_MAX_TEXTURE_SIZE, sizeof(maxTexSize), (FxI32 *)&maxTexSize)) {
        printf("grGet(GR_MAX_TEXTURE_SIZE) failed.\n");
        exit(-1);
      }
      break;
    case 'n':
      if (remArgs[0] != NULL) frames = atoi(remArgs[0]);
      break;
    case 'r':
      if (remArgs[0] != NULL) resolution = tlGetResolutionConstant(remArgs[0], 
                                                                   &scrWidth, 
                                                                   &scrHeight);
      break;
    }
  }

  tlSetScreen(scrWidth, scrHeight);

  version = grGetString(GR_VERSION);

  printf("%s:\n%s\n", name, purpose);
  printf("%s\n", version);
  printf("Resolution: %s\n", tlGetResolutionString(resolution));
  if (frames == -1) {
    printf("Press A Key To Begin Test.\n");
    tlGetCH();
  }
    
  grSstSelect(0);
  if (grSstWinOpen(tlGethWnd(),
                   resolution,
                   GR_REFRESH_60Hz,
                   GR_COLORFORMAT_ABGR,
                   GR_ORIGIN_UPPER_LEFT,
                   2, 1) == 0) {
    printf("grSstWinOpen failed.\n");
    goto __errExit;
  }
    
  tlConSet(0.0f, 0.0f, 1.0f, 1.0f, 
           60, 30, 0xffffff);

  /* Set up Render State */
  grGet(GR_WDEPTH_MIN_MAX, 8, (FxI32 *)wrange);  
  grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);

  grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                 GR_COMBINE_FACTOR_ONE,
                 GR_COMBINE_LOCAL_CONSTANT,
                 GR_COMBINE_OTHER_TEXTURE,
                 FXFALSE);
  grTexCombine(GR_TMU0,
               GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
               GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
               FXFALSE, FXFALSE);

  /* Generate texture */
  {
    GrLOD_t 
      largeLod, 
      smallLod;
    FxU16* 
      texData = NULL;
    FxU32 
      totalMapSize,
      curMapSize;

    /* There's some closed form of this series thing, but I forget
     * what it is and am way to lazy to actually go look it up. This
     * is only a glide test after all.  
     */
    totalMapSize = 0;
    curMapSize = maxTexSize;
    while(curMapSize > 0) {
      totalMapSize += (curMapSize * curMapSize) * sizeof(FxU16);
      curMapSize >>= 1;
    }
    texData = (FxU16*)malloc(totalMapSize * sizeof(*texData));
    if (texData == NULL) {
      printf("Unable to allocate texture data.\n");
      exit(-1);
    }

    /* Figure out the supported log2(lod size) */
    largeLod = GR_LOD_LOG2_1;
    while((0x01UL << largeLod) != maxTexSize) largeLod++;

    smallLod = GR_LOD_LOG2_1;
    while((0x01UL << smallLod) != minTexSize) smallLod++;
    
    /* Build simple texture w/ a different color for each map to help
     * distinguish the different maps when mipmapping. Additionally,
     * add a 'border' so that we can see if the start of the texture
     * gets mucked up due to an incorrect start address.
     */
    {
      FxU16 
        colorVal = 0xF800,
        *curTexPtr = texData;
      FxU32 
        i, j,
        colorShift = (16 / largeLod);

      curMapSize = maxTexSize;
      while(curMapSize > 0) {
        for(j = 0; j < curMapSize; j++) *curTexPtr++ = 0xFFFF;
        for(i = 1; i < curMapSize - 1; i++) {
          *curTexPtr++ = 0xFFFF;
          for(j = 1; j < curMapSize - 1; j++) {
            *curTexPtr++ = colorVal;
          }
          *curTexPtr++ = 0xFFFF;
        }
        for(j = 0; j < curMapSize; j++) *curTexPtr++ = 0xFFFF;
        
        curMapSize >>= 1;
        colorVal >>= colorShift;
      }
    }

    {
      GrTexInfo texInfo = {
        GR_LOD_LOG2_1,
        0,
        GR_ASPECT_LOG2_1x1,
        GR_TEXFMT_RGB_565,
        0
      };
      FxU32 
        curTexAddr = 0x00UL,
        texMultiBaseOffset;
      
      texInfo.largeLodLog2 = largeLod;
      texInfo.data = texData;
      
      /* Determine the hw texture alignment and generate some random
       * offset for the texture base addressing.  
       */
      {
        FxU32 
          texAlign,
          maxTexMem = grTexMaxAddress(GR_TMU0),
          maxTexSize = grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                               &texInfo);

        if (!grGet(GR_TEXTURE_ALIGN, sizeof(texAlign), (FxI32 *)&texAlign)) {
          printf("grGet(GR_TEXTURE_ALIGN): Failed!\n");
          exit(-1);
        }
        texAlign <<= 3UL;

        /* Get some offset that has to be smaller than the amount of
         * texxture space we have left divided by the # of times
         * that we're going to add it in.
         */
        do {
          texMultiBaseOffset = rand();
        } while ((texMultiBaseOffset < 0x1000UL) ||
                 (texMultiBaseOffset > ((maxTexMem - maxTexSize) / 4)));

        texMultiBaseOffset = (texMultiBaseOffset + texAlign) & ~(texAlign - 1UL);
      }

      /* Download the texture to the multibase address specified by
       * the current mode. We play a few games w/ offsetting the
       * texture start address by texMultiBaseOffset to try to make
       * sure that multi-base actually works inside of glide.  
       */

        /* Mmmm... multibase */
        grTexMultibase(GR_TMU0, FXTRUE);

        /* Download and set the base addresses in descending map size
         * order offsetting by some dorky amount as we go.
         */
        texInfo.smallLodLog2 = GR_LOD_LOG2_256;
        texInfo.largeLodLog2 = largeLod;
        
        grTexDownloadMipMap(GR_TMU0, 
                            curTexAddr, 
                            GR_MIPMAPLEVELMASK_BOTH, 
                            &texInfo);
        grTexMultibaseAddress(GR_TMU0, 
                              GR_TEXBASE_256, 
                              curTexAddr, 
                              GR_MIPMAPLEVELMASK_BOTH, 
                              &texInfo);

        curTexAddr += (texMultiBaseOffset +
                       grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                               &texInfo));
        texInfo.data = (void*)((FxU8*)texInfo.data + 
                               grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                                       &texInfo));

        texInfo.smallLodLog2 = GR_LOD_LOG2_128;
        texInfo.largeLodLog2 = GR_LOD_LOG2_128;

        grTexDownloadMipMap(GR_TMU0, 
                            curTexAddr, 
                            GR_MIPMAPLEVELMASK_BOTH, 
                            &texInfo);
        grTexMultibaseAddress(GR_TMU0, 
                              GR_TEXBASE_128, 
                              curTexAddr, 
                              GR_MIPMAPLEVELMASK_BOTH, 
                              &texInfo);

        curTexAddr += (texMultiBaseOffset +
                       grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                               &texInfo));
        texInfo.data = (void*)((FxU8*)texInfo.data + 
                               grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                                       &texInfo));

        texInfo.smallLodLog2 = GR_LOD_LOG2_64;
        texInfo.largeLodLog2 = GR_LOD_LOG2_64;
        
        grTexDownloadMipMap(GR_TMU0, 
                            curTexAddr, 
                            GR_MIPMAPLEVELMASK_BOTH, 
                            &texInfo);
        grTexMultibaseAddress(GR_TMU0, 
                              GR_TEXBASE_64, 
                              curTexAddr, 
                              GR_MIPMAPLEVELMASK_BOTH, 
                              &texInfo);

        curTexAddr += (texMultiBaseOffset +
                       grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                               &texInfo));
        texInfo.data = (void*)((FxU8*)texInfo.data + 
                               grTexTextureMemRequired(GR_MIPMAPLEVELMASK_BOTH, 
                                                       &texInfo));

        texInfo.smallLodLog2 = GR_LOD_LOG2_1;
        texInfo.largeLodLog2 = GR_LOD_LOG2_32;
        
        grTexDownloadMipMap(GR_TMU0, 
                            curTexAddr, 
                            GR_MIPMAPLEVELMASK_BOTH, 
                            &texInfo);
        grTexMultibaseAddress(GR_TMU0, 
                              GR_TEXBASE_32_TO_1, 
                              curTexAddr, 
                              GR_MIPMAPLEVELMASK_BOTH, 
                              &texInfo);

      /* Source the whole texture. The large map start will reset
       * baseAddr0, but that should be fine since we did not adjust
       * its address because it came first.  
       */
      texInfo.smallLodLog2 = GR_LOD_LOG2_1;
      texInfo.largeLodLog2 = largeLod;
      
      grTexSource(GR_TMU0, 
                  0x00UL, 
                  GR_MIPMAPLEVELMASK_BOTH, 
                  &texInfo);
    }

    free((void*)texData);
  }

  grTexMipMapMode(GR_TMU0,
                  GR_MIPMAP_NEAREST,
                  FXFALSE);

  tlConOutput("Press a key to quit\n");
  while(frames-- && tlOkToRender()) {
    static float 
      curOOW = 1.0f;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight);
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    }

    grBufferClear(0x808080, 0xFF, wrange[1]);

    {
      static float
        distance = 1.0f,
        dDelta   = 0.1f;
      TlVertex3D 
        xfVerts[4],
        prjVerts[4];
      GrVertex 
        vtxA, 
        vtxB, 
        vtxC,
        vtxD;

      /*---- 
        A-B
        |\|
        C-D
        -----*/
      vtxA.oow = 1.0f;
      vtxB = vtxC = vtxD = vtxA;

#define MAX_DIST 30.5f
#define MIN_DIST 1.0f

      distance += dDelta;
      if (distance > MAX_DIST || 
           distance < MIN_DIST) { 
        dDelta *= -1.0f;
        distance += dDelta;
      }

      tlSetMatrix(tlIdentity());
      tlMultMatrix(tlXRotation(-20.0f));
      tlMultMatrix(tlTranslation(0.0f, -0.3f, distance));

      tlTransformVertices(xfVerts, srcVerts, 4);
      tlProjectVertices(prjVerts, xfVerts, 4);

      vtxA.x = tlScaleX(prjVerts[0].x);
      vtxA.y = tlScaleY(prjVerts[0].y);
      vtxA.oow = 1.0f / prjVerts[0].w;
      vtxA.tmuvtx[0].sow = prjVerts[0].s * 255.0f * vtxA.oow;
      vtxA.tmuvtx[0].tow = prjVerts[0].t * 255.0f * vtxA.oow;

      vtxB.x = tlScaleX(prjVerts[1].x);
      vtxB.y = tlScaleY(prjVerts[1].y); 
      vtxB.oow = 1.0f / prjVerts[1].w;
      vtxB.tmuvtx[0].sow = prjVerts[1].s * 255.0f * vtxB.oow;
      vtxB.tmuvtx[0].tow = prjVerts[1].t * 255.0f * vtxB.oow;
        
      vtxC.x = tlScaleX(prjVerts[2].x);
      vtxC.y = tlScaleY(prjVerts[2].y);
      vtxC.oow = 1.0f / prjVerts[2].w;
      vtxC.tmuvtx[0].sow = prjVerts[2].s * 255.0f * vtxC.oow;
      vtxC.tmuvtx[0].tow = prjVerts[2].t * 255.0f * vtxC.oow;

      vtxD.x = tlScaleX(prjVerts[3].x); 
      vtxD.y = tlScaleY(prjVerts[3].y);
      vtxD.oow = 1.0f / prjVerts[3].w;
      vtxD.tmuvtx[0].sow = prjVerts[3].s * 255.0f * vtxD.oow;
      vtxD.tmuvtx[0].tow = prjVerts[3].t * 255.0f * vtxD.oow;

      grDrawTriangle(&vtxA, &vtxB, &vtxD);
      grDrawTriangle(&vtxA, &vtxD, &vtxC);
    }

    tlConRender();
    grBufferSwap(1);

    /* grab the frame buffer */
    if (scrgrab) {
      if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
        printf("Cannot open %s\n", filename);
      scrgrab = FXFALSE;
    }

    if (tlKbHit()) {
      char curKey = tlGetCH();

      switch(curKey) {
      default:
        frames = 0;
        break;
      }
    }
  }
  rv = 0;

 __errExit:    
  grGlideShutdown();

  return rv;
}
Ejemplo n.º 6
0
void
main( int argc, char **argv)
{
  char
    match, 
    **remArgs,
    *args = "nrd",
    filename[256];
  int
    frames = -1,
    rv;
  float
    scrWidth   = 640.f,
    scrHeight  = 480.f;
  FxBool
    scrgrab = FXFALSE;

  GrScreenResolution_t
    resolution = GR_RESOLUTION_640x480;

  FxI32    listType = -1;
  FxBool   aaenable = FXFALSE;
  FxBool   packedrgb = FXFALSE;
  FxBool   varraycont = FXFALSE;
  GrVertex vtxList[4];
  void     *vtxListArray[6];
  GrVertex vtxListCont[6];
  FxU32    wrange[2];
  
  /* Initialize Glide */
  grGlideInit();
  assert( hwconfig = tlVoodooType() );

  /* Process Command Line Arguments */
  while( rv = tlGetOpt( argc, argv, args, &match, &remArgs ) ) {
    if ( rv == -1 ) {
      printf( "Unrecognized command line argument\n" );
      printf( "%s %s\n", name, usage );
      printf( "Available resolutions:\n%s\n",
             tlGetResolutionList() );
      return;
    }
    switch( match ) {
    case 'n':
      frames = atoi( remArgs[0] );
      break;
    case 'r':
      resolution = tlGetResolutionConstant( remArgs[0], 
                                           &scrWidth, 
                                           &scrHeight );
      break;
    case 'd':
      scrgrab = FXTRUE;
      frames = 1;
      strcpy(filename, remArgs[0]);
      break;

    }
  }
  
  tlSetScreen( scrWidth, scrHeight );
  
  version = grGetString( GR_VERSION );
  
  printf( "%s:\n%s\n", name, purpose );
  printf( "%s\n", version );
  printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
  if ( frames == -1 ) {
    printf( "Press A Key To Begin Test.\n" );
    tlGetCH();
  }
  
  grSstSelect( 0 );
  assert( grSstWinOpen(tlGethWnd(),
                       resolution,
                       GR_REFRESH_60Hz,
                       GR_COLORFORMAT_ABGR,
                       GR_ORIGIN_UPPER_LEFT,
                       2, 1 ) );  

  tlConSet( 0.f, 0.f, 1.f, 1.f, 
           60, 30, 0xffffff );
  
  /* Set up Render State - gouraud shading */
  grVertexLayout(GR_PARAM_XY,  GR_VERTEX_X_OFFSET << 2, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
  grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  

  grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                 GR_COMBINE_FACTOR_NONE,
                 GR_COMBINE_LOCAL_ITERATED,
                 GR_COMBINE_OTHER_NONE,
                 FXFALSE );

  grCullMode(GR_CULL_DISABLE);

  if(frames == -1) {
    doHelp();
  }


  /*
  ** data 
  */
  {
    vtxList[0].x = tlScaleX( 0.3f ), vtxList[0].y = tlScaleY( 0.3f );
    vtxList[0].r = 255.f, vtxList[0].g = 0.f, vtxList[0].b = 0.f, vtxList[0].a = 255.f;
    
    vtxList[1].x = tlScaleX( 0.8f ), vtxList[1].y = tlScaleY( 0.4f );
    vtxList[1].r = 0.f, vtxList[1].g = 255.f, vtxList[1].b = 0.f, vtxList[1].a = 255.f;
    
    vtxList[2].x = tlScaleX( 0.5f ), vtxList[2].y = tlScaleY( 0.8f );
    vtxList[2].r = 0.f, vtxList[2].g = 0.f, vtxList[2].b = 255.f, vtxList[2].a = 255.f;
    
    vtxList[3].x = tlScaleX( 0.9f ), vtxList[3].y = tlScaleY( 0.8f );
    vtxList[3].r = 0.f, vtxList[3].g = 0.f, vtxList[3].b = 255.f, vtxList[3].a = 255.f;
    
    vtxListCont[0] = vtxList[0];
    vtxListCont[1] = vtxList[1];
    vtxListCont[2] = vtxList[2];
    vtxListCont[3] = vtxList[3];
  }
  
  while( frames-- && tlOkToRender()) {
      
    tlConClear();
    tlConOutput( "Press a key to quit\n" );
    if (aaenable)
      tlConOutput("Antialiasing ON\n");
    else
      tlConOutput("Antialiasing OFF\n");
    if (packedrgb)
      tlConOutput("Packed Color ON\n");
    else
      tlConOutput("Packed Color OFF\n");
    if (listType >= 0) {
      if (varraycont)
        tlConOutput("grDrawVertexArrayContiguous\n");
      else
        tlConOutput("grDrawVertexArray\n");
      switch (listType) {
      case GR_POINTS:
        tlConOutput("POINTS\n");
        break;
      case GR_LINE_STRIP:
        tlConOutput("LINE STRIP\n");
        break;
      case GR_LINES:
        tlConOutput("LINES\n");
        break;
      case GR_POLYGON:
        tlConOutput("POLYGON\n");
        break;
      case GR_TRIANGLE_STRIP:
        tlConOutput("TRIANGLE STRIP\n");
        break;
      case GR_TRIANGLE_FAN:
        tlConOutput("TRIANGLE FAN\n");
        break;
      case GR_TRIANGLES:
        tlConOutput("TRIANGLES\n");
        break;
      }
    }
    else
      tlConOutput("grDrawTriangle\n");

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight );
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    }
    grRenderBuffer( GR_BUFFER_BACKBUFFER );
    
    grBufferClear( 0x00, 0, wrange[1] );

    switch (listType) {
    case GR_POINTS:
    case GR_LINE_STRIP:
    case GR_LINES:
    case GR_POLYGON:
    case GR_TRIANGLE_STRIP:
    case GR_TRIANGLE_FAN:
      if (varraycont)
        grDrawVertexArrayContiguous(listType, 4, vtxListCont, sizeof(GrVertex));
      else
        grDrawVertexArray(listType, 4, vtxListArray);
      break;
    case GR_TRIANGLES:
      if (varraycont)
        grDrawVertexArrayContiguous(listType, 6, vtxListCont, sizeof(GrVertex));
      else
        grDrawVertexArray(listType, 6, vtxListArray);
      break;
    default:
      if (aaenable)
        grAADrawTriangle(vtxList, vtxList+1, vtxList+2, FXTRUE, FXTRUE, FXTRUE);
      else
        grDrawTriangle(vtxList, vtxList+1, vtxList+2);
    }

    tlConRender();
    grBufferSwap( 1 );
    
    /* grab the frame buffer */
    if (scrgrab) {
      if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
        printf( "Cannot open %s\n", filename);
      scrgrab = FXFALSE;
    }

    while( tlKbHit() ) {
      FxU32 key;
      switch( key = tlGetCH() ) {
      case 'c':
      case 'C':
        varraycont = !varraycont;
        break;
      case 't':
      case 'T':
        listType = -1;
        break;
      case 'a':
      case 'A':
        aaenable = !aaenable;
        if (aaenable) {
          grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL,
                          GR_COMBINE_FACTOR_NONE,
                          GR_COMBINE_LOCAL_ITERATED,
                          GR_COMBINE_OTHER_NONE,
                          FXFALSE );
          grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
                                GR_BLEND_ZERO, GR_BLEND_ZERO );
          grEnable(GR_AA_ORDERED);
          if (!packedrgb)
            grVertexLayout(GR_PARAM_A,
                           GR_VERTEX_A_OFFSET << 2,
                           GR_PARAM_ENABLE);
        }
        else {
          grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                         GR_COMBINE_FACTOR_ONE,
                         GR_COMBINE_LOCAL_NONE,
                         GR_COMBINE_OTHER_CONSTANT,
                         FXFALSE);
          grAlphaBlendFunction(GR_BLEND_ONE , GR_BLEND_ZERO, 
                               GR_BLEND_ONE, GR_BLEND_ZERO);
          grDisable(GR_AA_ORDERED);
          if (!packedrgb)
            grVertexLayout(GR_PARAM_A,
                           GR_VERTEX_A_OFFSET << 2,
                           GR_PARAM_DISABLE);
        }
        break;
      case 'p':
      case 'P':
        packedrgb = !packedrgb;
        if (packedrgb) {
          grVertexLayout(GR_PARAM_PARGB,   GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
          *(FxU32*)&vtxList[0].r = 0xff0000ff;
          *(FxU32*)&vtxList[1].r = 0xff00ff00;
          *(FxU32*)&vtxList[2].r = 0xffff0000;
          *(FxU32*)&vtxList[3].r = 0xffff0000;
          *(FxU32*)&vtxList[4].r = 0xff00ff00;
          *(FxU32*)&vtxList[5].r = 0xff0000ff;
        }
        else {
          grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);
          if (aaenable)
            grVertexLayout(GR_PARAM_A,   GR_VERTEX_A_OFFSET << 2, GR_PARAM_ENABLE);
          vtxList[0].r = 255.f, vtxList[0].g = 0.f, vtxList[0].b = 0.f, vtxList[0].a = 255.f;
          vtxList[1].r = 0.f, vtxList[1].g = 255.f, vtxList[1].b = 0.f, vtxList[1].a = 255.f;
          vtxList[2].r = 0.f, vtxList[2].g = 0.f, vtxList[2].b = 255.f, vtxList[2].a = 255.f;
          vtxList[3].r = 0.f, vtxList[3].g = 0.f, vtxList[3].b = 255.f, vtxList[3].a = 255.f;
          vtxList[4].r = 0.f, vtxList[4].g = 255.f, vtxList[4].b = 0.f, vtxList[4].a = 255.f;
          vtxList[5].r = 0.f, vtxList[5].g = 0.f, vtxList[5].b = 255.f, vtxList[5].a = 255.f;
        }
        switch (listType) {
        case 0:
        case 1:
        case 2:
        case 4:
          vtxListCont[0] = vtxList[0]; vtxListCont[1] = vtxList[1];
          vtxListCont[2] = vtxList[2]; vtxListCont[3] = vtxList[3];
          break;
        case 3:
        case 5:
          vtxListCont[0] = vtxList[1]; vtxListCont[1] = vtxList[0];
          vtxListCont[2] = vtxList[2]; vtxListCont[3] = vtxList[3];
          break;
        case 6:
          vtxListCont[0] = vtxList[1]; vtxListCont[1] = vtxList[0]; vtxListCont[2] = vtxList[2]; 
          vtxListCont[3] = vtxList[1]; vtxListCont[4] = vtxList[2]; vtxListCont[5] = vtxList[3];
          break;
        }
        break;
      case '0':
      case '1':
      case '2':
      case '4':
        listType =  key - '0';
        vtxListArray[0] = (void *)&vtxList[0]; vtxListArray[1] = (void *)&vtxList[1];
        vtxListArray[2] = (void *)&vtxList[2]; vtxListArray[3] = (void *)&vtxList[3];
        vtxListCont[0] = vtxList[0]; vtxListCont[1] = vtxList[1];
        vtxListCont[2] = vtxList[2]; vtxListCont[3] = vtxList[3];
        break;
      case '3':
      case '5':
        listType =  key - '0';
        vtxListArray[0] = (void *)&vtxList[1]; vtxListArray[1] = (void *)&vtxList[0];
        vtxListArray[2] = (void *)&vtxList[2]; vtxListArray[3] = (void *)&vtxList[3];
        vtxListCont[0] = vtxList[1]; vtxListCont[1] = vtxList[0];
        vtxListCont[2] = vtxList[2]; vtxListCont[3] = vtxList[3];
        break;
      case '6':
        listType =  key - '0';
        vtxListArray[0] = (void *)&vtxList[1]; vtxListArray[1] = (void *)&vtxList[0];
        vtxListArray[2] = (void *)&vtxList[2];
        vtxListArray[3] = (void *)&vtxList[1]; vtxListArray[4] = (void *)&vtxList[2];
        vtxListArray[5] = (void *)&vtxList[3];
        vtxListCont[0] = vtxList[1]; vtxListCont[1] = vtxList[0]; vtxListCont[2] = vtxList[2]; 
        vtxListCont[3] = vtxList[1]; vtxListCont[4] = vtxList[2]; vtxListCont[5] = vtxList[3];
        break;
      default:
        frames = 0;
        break;
      }
    }
  }
  
  grGlideShutdown();
  return;
} /* main */
Ejemplo n.º 7
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;

    TlTexture  baseTexture;
    unsigned long baseTextureAddr;
    TlTexture  lightTexture;
    unsigned long lightTextureAddr;

    int                  ftsize = 0;
    GrFog_t              *fogtable = NULL;

    TlVertex3D srcVerts[4];
    float      distance, dDelta;
    FxU32      zrange[2];

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    grSstSelect( 0 );
    assert( grSstWinOpen( 0,
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_LOWER_LEFT,
                      2, 1 ) );
    
    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f, 
              60, 15, 0xffffff );
    
    /* Set up Render State - decal - bilinear - nearest mipmapping - fogging */
    grGet(GR_ZDEPTH_MIN_MAX, 8, zrange);  
    grGet(GR_FOG_TABLE_ENTRIES, 4, &ftsize);
    fogtable = malloc(sizeof(GrFog_t)*ftsize);
    assert(fogtable);

    grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
                    GR_COMBINE_FACTOR_ONE,
                    GR_COMBINE_LOCAL_NONE,
                    GR_COMBINE_OTHER_TEXTURE,
                    FXFALSE );
    grTexMipMapMode( GR_TMU0,
                     GR_MIPMAP_NEAREST,
                     FXFALSE );
    grTexFilterMode( GR_TMU0,
                     GR_TEXTUREFILTER_BILINEAR,
                     GR_TEXTUREFILTER_BILINEAR );
    grFogColorValue( 0x404040 );
    guFogGenerateExp( fogtable, .2f );
    grFogTable( fogtable );

    /* Load texture data into system ram */
    assert( tlLoadTexture( "decal1.3df", 
                           &baseTexture.info, 
                           &baseTexture.tableType, 
                           &baseTexture.tableData ) );
    assert( tlLoadTexture( "light.3df", 
                           &lightTexture.info, 
                           &lightTexture.tableType, 
                           &lightTexture.tableData ) );

    /* Download texture data to TMU */
    baseTextureAddr = grTexMinAddress( GR_TMU0 );
    grTexDownloadMipMap( GR_TMU0,
                         baseTextureAddr,
                         GR_MIPMAPLEVELMASK_BOTH,
                         &baseTexture.info );
    if ( baseTexture.tableType != NO_TABLE ) {
        grTexDownloadTable( baseTexture.tableType,
                            &baseTexture.tableData );
    }

    lightTextureAddr = 
        baseTextureAddr +
        grTexTextureMemRequired( GR_MIPMAPLEVELMASK_BOTH,
                                 &baseTexture.info );
    grTexDownloadMipMap( GR_TMU0,
                         lightTextureAddr,
                         GR_MIPMAPLEVELMASK_BOTH,
                         &lightTexture.info );
    if ( lightTexture.tableType != NO_TABLE ) {
        grTexDownloadTable( lightTexture.tableType,
                            &lightTexture.tableData );
    }

    /* Initialize Source 3D data - Rectangle on X/Z Plane 
       Centered about Y Axis

       0--1  Z+
       |  |  |
       2--3   - X+

     */
    srcVerts[0].x = -0.5f, srcVerts[0].y = 0.0f, srcVerts[0].z =  0.5f, srcVerts[0].w = 1.0f;
    srcVerts[1].x =  0.5f, srcVerts[1].y = 0.0f, srcVerts[1].z =  0.5f, srcVerts[1].w = 1.0f;
    srcVerts[2].x = -0.5f, srcVerts[2].y = 0.0f, srcVerts[2].z = -0.5f, srcVerts[2].w = 1.0f;
    srcVerts[3].x =  0.5f, srcVerts[3].y = 0.0f, srcVerts[3].z = -0.5f, srcVerts[3].w = 1.0f;

    srcVerts[0].s = 0.0f, srcVerts[0].t = 0.0f;
    srcVerts[1].s = 1.0f, srcVerts[1].t = 0.0f;
    srcVerts[2].s = 0.0f, srcVerts[2].t = 1.0f;
    srcVerts[3].s = 1.0f, srcVerts[3].t = 1.0f;

#define RED  0x000000ff
#define BLUE 0x00ff0000

#define MAX_DIST 10.0f
#define MIN_DIST 1.0f

    distance = 1.0f;
    dDelta   = 0.05f;

    tlConOutput( "Press any key to quit\n\n" );
    while( frames-- && tlOkToRender()) {
        GrVertex vtxA, vtxB, vtxC, vtxD;
        TlVertex3D xfVerts[4];
        TlVertex3D prjVerts[4];

        if (hwconfig == TL_VOODOORUSH) {
          tlGetDimsByConst(resolution,
                           &scrWidth, 
                           &scrHeight );
        
          grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grBufferClear( 0x00404040, 0, zrange[1] );

        /* 3D Transformations */
        /*---- 
          A-B
          |\|
          C-D
          -----*/
        vtxA.oow = 1.0f;
        vtxB = vtxC = vtxD = vtxA;

        distance += dDelta;
        if ( distance > MAX_DIST || 
             distance < MIN_DIST ) { 
            dDelta *= -1.0f;
            distance += dDelta;
        }

        tlSetMatrix( tlIdentity() );
        tlMultMatrix( tlXRotation( -90.0f ) );
        tlMultMatrix( tlTranslation( 0.0f, 0.0f, distance ) );

        tlTransformVertices( xfVerts, srcVerts, 4 );
        tlProjectVertices( prjVerts, xfVerts, 4 );

        vtxA.x = tlScaleX( prjVerts[0].x );
        vtxA.y = tlScaleY( prjVerts[0].y );
        vtxA.oow = 1.0f / prjVerts[0].w;

        vtxB.x = tlScaleX( prjVerts[1].x );
        vtxB.y = tlScaleY( prjVerts[1].y ); 
        vtxB.oow = 1.0f / prjVerts[1].w;
        
        vtxC.x = tlScaleX( prjVerts[2].x );
        vtxC.y = tlScaleY( prjVerts[2].y );
        vtxC.oow = 1.0f / prjVerts[2].w;

        vtxD.x = tlScaleX( prjVerts[3].x ); 
        vtxD.y = tlScaleY( prjVerts[3].y );
        vtxD.oow = 1.0f / prjVerts[3].w;

        vtxA.tmuvtx[0].sow = prjVerts[0].s * 255.0f * vtxA.oow;
        vtxA.tmuvtx[0].tow = prjVerts[0].t * 255.0f * vtxA.oow;

        vtxB.tmuvtx[0].sow = prjVerts[1].s * 255.0f * vtxB.oow;
        vtxB.tmuvtx[0].tow = prjVerts[1].t * 255.0f * vtxB.oow;

        vtxC.tmuvtx[0].sow = prjVerts[2].s * 255.0f * vtxC.oow;
        vtxC.tmuvtx[0].tow = prjVerts[2].t * 255.0f * vtxC.oow;

        vtxD.tmuvtx[0].sow = prjVerts[3].s * 255.0f * vtxD.oow;
        vtxD.tmuvtx[0].tow = prjVerts[3].t * 255.0f * vtxD.oow;

        /* Render First Pass */
        grTexCombine( GR_TMU0,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_NONE,
                      GR_COMBINE_FUNCTION_LOCAL,
                      GR_COMBINE_FACTOR_NONE,
                      FXFALSE,
                      FXFALSE );
        grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ZERO,
                              GR_BLEND_ONE, GR_BLEND_ZERO );
        grTexSource( GR_TMU0,
                     baseTextureAddr,
                     GR_MIPMAPLEVELMASK_BOTH,
                     &baseTexture.info );

        grFogMode( GR_FOG_ADD2 | GR_FOG_WITH_TABLE_ON_W );

        grDrawTriangle( &vtxA, &vtxB, &vtxD );
        grDrawTriangle( &vtxA, &vtxD, &vtxC );

        /* Render Second Pass */
        grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_PREFOG_COLOR,
                              GR_BLEND_ZERO, GR_BLEND_ZERO );
        grTexSource( GR_TMU0,
                     lightTextureAddr,
                     GR_MIPMAPLEVELMASK_BOTH,
                     &lightTexture.info );

        grFogMode( GR_FOG_MULT2 | GR_FOG_WITH_TABLE_ON_W );

        grDrawTriangle( &vtxA, &vtxB, &vtxD );
        grDrawTriangle( &vtxA, &vtxD, &vtxC );

        tlConRender();
        grBufferSwap( 1 );
        grFinish();
        
        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            default:
                frames = 0;
                break;
            }
        }
    }
    
    grGlideShutdown();
    free(fogtable);
    return;
}
Ejemplo n.º 8
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
#define NVERT 5
    GrVertex vtx[NVERT];
    int index[NVERT];
    int frames                      = -1;
    int i, idx;
#define NHUE 360
    RGB hues[NHUE];
    FxU32 wrange[2];
    GrContext_t          gc = 0;
    
    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    grSstSelect( 0 );
    gc = grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1 );
    if (!gc) {
      printf("Could not allocate glide fullscreen context.\n");
      goto __errExit;
    }
    
    tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
              60, 30, 0xffffff );

    /* Set up Render State - gouraud shading */
    grGet(GR_WDEPTH_MIN_MAX, 8, (FxI32 *)wrange);  
    grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_ITERATED,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );

    tlConOutput( "Press a key to quit\n" );

    /* init a table of hues */
    for (i=0; i<NHUE; i++) {
      const float theta = i * 360.0f / NHUE;
      hlsToRGB( theta, 0.4f, 0.5f, &hues[i]);
    }

    /* assign hues to vertices */
    for (i=0; i<NVERT; i++) {
        vtx[i].r = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].r;
        vtx[i].g = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].g;
        vtx[i].b = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].b;
    }
#if 1
    /*
     * Force polygon RGB values to be planar... note overflow!
     * this is deliberate as a sanity check
     */
    vtx[3].r = 235.519f; vtx[3].g = 51.001f; vtx[3].b = 115.721f;
    vtx[4].r = 298.559f; vtx[4].g = -12.039f; vtx[4].b = 91.0f;
#endif

    while( frames-- && tlOkToRender()) {

        tlGetDimsByConst(resolution,
                         &scrWidth, 
                         &scrHeight );
        
        grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);

        grBufferClear( 0x00, 0, wrange[1] );

        /* generate a equilateral polygon */
        for (i=0; i<NVERT; i++) {
          double theta = 2.0 * PI * i / (double) NVERT;
          
          vtx[i].x = tlScaleX((float)((cos(theta) / 4.0) + 0.5));
          vtx[i].y = tlScaleY((float)((sin(theta) / 4.0) + 0.5));
          
          index[i] = i;
        }

        idx = 30 /* (-frames) % NHUE */;

#if 1
        /* cyclical permutation: turn off to see just one set of triangles */
        for (i=0; i<NVERT; i++) {
            index[i] = (index[i] + 1) % NVERT;
        }
#endif

        grDrawVertexArrayContiguous(GR_POLYGON, NVERT, vtx, sizeof(GrVertex));

        tlConRender();
        grBufferSwap( 1 );
        if ( tlKbHit() ) frames = 0;
    }

 __errExit:    
    grGlideShutdown();
    return;
}
Ejemplo n.º 9
0
void main( int argc, char **argv) {
    char match;
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;
    FxBool               scrgrab = FXFALSE;
    char                 filename[256];

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nrd", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0],
                                                  &scrWidth,
                                                  &scrHeight );
            break;
        case 'd':
            scrgrab = FXTRUE;
            frames = 1;
            strcpy(filename, remArgs[0]);
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    grGlideGetVersion( version );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }

    /* Initialize Glide */
    grGlideInit();
    assert( grSstQueryHardware( &hwconfig ) );
    grSstSelect( 0 );
    assert( grSstWinOpen( 0,
                          resolution,
                          GR_REFRESH_60Hz,
                          GR_COLORFORMAT_ABGR,
                          GR_ORIGIN_UPPER_LEFT,
                          2, 1 ) );

    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f,
              60, 15, 0xffffff );

    /* Set up Render State - iterated alpha + constant color */
    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_CONSTANT,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );
    grAlphaCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_ITERATED,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );
    grAlphaBlendFunction( GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
                          GR_BLEND_ZERO, GR_BLEND_ZERO );

#define RED  0x000000ff
#define BLUE 0x00ff0000

    tlConOutput( "Press any key to quit\n" );
    while( frames-- && tlOkToRender()) {
        GrVertex vtxA, vtxB, vtxC;

        if (hwconfig.SSTs[0].type == GR_SSTTYPE_SST96) {
            tlGetDimsByConst(resolution,
                             &scrWidth,
                             &scrHeight );

            grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grBufferClear( 0x00, 0, 0 );

        vtxA.x = tlScaleX( 0.5f ), vtxA.y = tlScaleY( 0.1f );
        vtxB.x = tlScaleX( 0.8f ), vtxB.y = tlScaleY( 0.9f );
        vtxC.x = tlScaleX( 0.2f ), vtxC.y = tlScaleY( 0.9f );
        vtxA.a = vtxB.a = vtxC.a = 255.0f;

        grConstantColorValue( RED );
        grDrawTriangle( &vtxA, &vtxB, &vtxC );

        grSstOrigin( GR_ORIGIN_LOWER_LEFT );

        vtxA.a = 0.0f;
        grConstantColorValue( BLUE );
        grDrawTriangle( &vtxA, &vtxB, &vtxC );

        grSstOrigin( GR_ORIGIN_UPPER_LEFT );

        tlConRender();
        grBufferSwap( 1 );

        /* grab the frame buffer */
        if (scrgrab) {
            if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
                printf( "Cannot open %s\n", filename);
            scrgrab = FXFALSE;
        }

        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            default:
                frames = 0;
                break;
            }
        }
    }

    grGlideShutdown();
    return;
}
Ejemplo n.º 10
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
    int frames                      = -1;

    float clipX, clipY, clipSize, clipSizeDelta, clipPosDelta;
    FxU32 zrange[2];

    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    grSstSelect( 0 );
    assert( grSstWinOpen(tlGethWnd(),
                         resolution,
                         GR_REFRESH_60Hz,
                         GR_COLORFORMAT_ABGR,
                         GR_ORIGIN_UPPER_LEFT,
                         2, 1 ) );
    
    tlConSet( 0.0f, 0.0f, 1.0f, 0.5f, 
              60, 15, 0xffffff );

    /* Set up Render State - iterated alpha + z buffering */
    grGet(GR_ZDEPTH_MIN_MAX, 8, zrange);  
    grVertexLayout(GR_PARAM_XY, 0, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_CONSTANT,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );
    
    clipX    = 0.2f;
    clipY    = 0.5f;
    clipSize = 0.3f;
    
    clipSizeDelta = 0.005f;
    clipPosDelta = 0.01f;

#define CLIPSIZE_MIN 0.05f
#define CLIPSIZE_MAX 0.6f

#define GRAY  0x00808080
#define BLACK 0x00000000

    tlConOutput( "+/- - grow/shrink clip rectangle\n" );
    tlConOutput( "a/d - clip window left/right \n" );
    tlConOutput( "w/s - clip window up/down \n" );
    tlConOutput( "Press any other key to quit\n" );
    while( frames-- && tlOkToRender()) {
        int x, y;
        GrVertex vtxA, vtxB, vtxC;
        int minx, miny, maxx, maxy;

        if (hwconfig == TL_VOODOORUSH) {
          tlGetDimsByConst(resolution,
                           &scrWidth, 
                           &scrHeight );
        
          grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
        }

        grClipWindow( (int)tlScaleX(0.0f),(int)tlScaleY(0.0f),
                      (int)tlScaleX(1.0f),(int)tlScaleY(1.0f) );
        grBufferClear( BLACK, 0, zrange[1] );

        /* Set Clipping Rectangle */
        minx = (int)tlScaleX(clipX);
        miny = (int)tlScaleY(clipY);
        if ( (clipX+clipSize)>1.0f ) 
            maxx = (int)tlScaleX( 1.0f );
        else 
            maxx = (int)tlScaleX( clipX + clipSize );
        if ( (clipY+clipSize)>1.0f ) 
            maxy = (int)tlScaleY( 1.0f );
        else 
            maxy = (int)tlScaleY( clipY + clipSize );
        grClipWindow( minx, miny, maxx, maxy );

        /* Draw 10x10 grid of triangles */
        for( y = 0; y < 10; y++ ) {
            for( x = 0; x < 10; x++ ) {
                /* 
                   A
                   |\
                   B-C
                 */
                vtxA.x = vtxB.x = tlScaleX( ((float)x)/10.0f );
                vtxA.y = tlScaleY( ((float)y)/10.0f );
                vtxB.y = vtxC.y = tlScaleY( (((float)y)/10.0f) + 0.1f );
                vtxC.x = tlScaleX( (((float)x)/10.0f) + 0.1f );
                
                grConstantColorValue( GRAY );
                grDrawTriangle( &vtxA, &vtxB, &vtxC );
            }
        }

        tlConRender();
        grBufferSwap( 1 );
        grFinish();
        
        while( tlKbHit() ) {
            switch( tlGetCH() ) {
            case '+':
                if ( clipSize < CLIPSIZE_MAX )
                    clipSize += clipSizeDelta;
                break;
            case '-':
                if ( clipSize > CLIPSIZE_MIN )
                    clipSize -= clipSizeDelta;
                break;
            case 'a':
            case 'A':
                if ( clipX > 0.0f )
                    clipX -= clipPosDelta;
                if ( clipX < 0.0f ) clipX = 0.0f;
                break;
            case 'd':
            case 'D':
                if ( clipX < 1.0f )
                    clipX += clipPosDelta;
                break;
            case 'w':
            case 'W':
                if ( clipY > 0.0f ) 
                    clipY -= clipPosDelta;
                if ( clipY < 0.0f ) clipY = 0.0f;
                break;
            case 's':
            case 'S':
                if ( clipY < 1.0f ) 
                    clipY += clipPosDelta;
                break;
            default:
                frames = 0;
                break;
            }
        }
    }
    
    grGlideShutdown();
    return;
}
Ejemplo n.º 11
0
void main(int argc, char **argv) {
  char match; 
  char **remArgs;
  int  rv;

  GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
  float                scrWidth   = 640.0f;
  float                scrHeight  = 480.0f;
  int frames                      = -1;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU32                wrange[2];

  GrLOD_t              largeLod   = GR_LOD_LOG2_256;
  GrLOD_t              smallLod   = GR_LOD_LOG2_1;
  GrTexTable_t         curPalType = GR_TEXTABLE_PALETTE;
  FxU32                compBits   = 0x08UL;
  FxBool               singleTexP = FXFALSE;
  FxBool               extMirrorP = FXFALSE;
  FxBool               extPalP    = FXFALSE;
  float                minTexCoor = 0.0f;
  float                maxTexCoor = 256.0f;

  /* Initialize Glide */
  grGlideInit();
  assert(hwconfig = tlVoodooType());

  /* Process Command Line Arguments */
  while(rv = tlGetOpt(argc, argv, "dlmnprs", &match, &remArgs)) {
    if (rv == -1) {
      printf("Unrecognized command line argument\n");
      printf("%s %s\n", name, usage);
      printf("Available resolutions:\n%s\n",
              tlGetResolutionList());
      return;
    }
    switch(match) {
    case 'd':
      scrgrab = FXTRUE;
      frames = 1;
      strcpy(filename, remArgs[0]);
      break;
    case 'l':
      if (sscanf(remArgs[0], "%d,%d", &smallLod, &largeLod) != 2) {
        largeLod = GR_LOD_LOG2_256;
        smallLod = GR_LOD_LOG2_1;
      } else {
        GrLOD_t
          maxLod,
          lodShift;

        if (grGet(GR_MAX_TEXTURE_SIZE, sizeof(maxLod), &maxLod) == 0) {
          largeLod = GR_LOD_LOG2_256;
          smallLod = GR_LOD_LOG2_1;
        } else {
          lodShift = 0;
          while((0x01 << lodShift) != maxLod) lodShift++;
          if (largeLod > lodShift) largeLod = lodShift;
        }
      }
      break;
    case 'm':
      extMirrorP = FXTRUE;
      break;
    case 'n':
      frames = atoi(remArgs[0]);
      break;
    case 'p':
      extPalP = FXTRUE;
      break;
    case 'r':
      resolution = tlGetResolutionConstant(remArgs[0], 
                                           &scrWidth, 
                                           &scrHeight);
      break;
    case 's':
      singleTexP = FXTRUE;
      break;
    }
  }

  tlSetScreen(scrWidth, scrHeight);

  version = grGetString(GR_VERSION);

  printf("%s:\n%s\n", name, purpose);
  printf("%s\n", version);
  printf("Resolution: %s\n", tlGetResolutionString(resolution));
  if (frames == -1) {
    printf("Press A Key To Begin Test.\n");
    tlGetCH();
  }
    
  grSstSelect(0);
  assert(grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1));
    
  tlConSet(0.0f, 0.0f, 1.0f, 1.0f, 
            60, 30, 0xffffff);

  /* Set up Render State */
  grGet(GR_WDEPTH_MIN_MAX, 8, wrange);  
  grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_Q,   GR_VERTEX_OOW_OFFSET << 2, GR_PARAM_ENABLE);
  grVertexLayout(GR_PARAM_ST0, GR_VERTEX_SOW_TMU0_OFFSET << 2, GR_PARAM_ENABLE);

  grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                 GR_COMBINE_FACTOR_ONE,
                 GR_COMBINE_LOCAL_CONSTANT,
                 GR_COMBINE_OTHER_TEXTURE,
                 FXFALSE);
  grTexCombine(GR_TMU0,
               GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
               GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
               FXFALSE, FXFALSE);

  /* Load texture data into system ram */
  if (!singleTexP) {
    FxI32 numTmu = 0;

    if (grGet(GR_NUM_TMU, sizeof(numTmu), &numTmu) && (numTmu > 1)) {
      TlTexture  texture;
      
      assert(tlLoadTexture("decal1.3df", 
                           &texture.info, 
                           &texture.tableType, 
                           &texture.tableData));
      /* Download texture data to TMU */
      grTexDownloadMipMap(GR_TMU1,
                          grTexMinAddress(GR_TMU1),
                          GR_MIPMAPLEVELMASK_BOTH,
                          &texture.info);
      if (texture.tableType != NO_TABLE) {
        grTexDownloadTable(texture.tableType,
                           &texture.tableData);
      }
      grTexSource(GR_TMU1,
                  grTexMinAddress(GR_TMU1),
                  GR_MIPMAPLEVELMASK_BOTH,
                  &texture.info);

      grVertexLayout(GR_PARAM_ST1, GR_VERTEX_SOW_TMU1_OFFSET << 2, GR_PARAM_ENABLE);

      grTexCombine(GR_TMU1,
                   GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
                   GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE,
                   FXFALSE, FXFALSE);
      grTexCombine(GR_TMU0,
                   GR_COMBINE_FUNCTION_BLEND_OTHER, GR_COMBINE_FACTOR_LOCAL,
                   GR_COMBINE_FUNCTION_BLEND_OTHER, GR_COMBINE_FACTOR_LOCAL,
                   FXFALSE, FXFALSE);
    }    
  }

  if (extMirrorP || extPalP) {
    const char* extString = grGetString(GR_EXTENSION);
    const char* tempStr = extString;
    
    while(tempStr != NULL) {
      const char* keyList[] = {
        "TEXMIRROR",
        "PALETTE6666"
      };
      
      if (extMirrorP && 
          !singleTexP && 
          (strncmp(tempStr, keyList[0], strlen(keyList[0])) == 0)) {
        grTexClampMode(GR_TMU0, 
                       GR_TEXTURECLAMP_MIRROR_EXT, 
                       GR_TEXTURECLAMP_MIRROR_EXT);
        minTexCoor = -256.0f;
        maxTexCoor =  512.0f;
      }
      
      if (extPalP && 
          (strncmp(tempStr, keyList[1], strlen(keyList[1])) == 0)) {
        curPalType = GR_TEXTABLE_PALETTE_6666_EXT;
        compBits = 0x06UL;
      }
      
      tempStr = strchr(tempStr, ' ');
      if (tempStr != NULL) tempStr++;
    }
  }
  
  {
    GuTexPalette texPal;
    GrTexInfo texInfo;
    unsigned char* texData = NULL, *tmp;
    int i, j, k;

    i = 0;
    while(i < 256) {
      const FxU32 compVal = (FxU32)(i * (0x01UL << compBits) / 256.0f);

      texPal.data[i] = ((compVal << (compBits * 2)) |
                        (compVal << (compBits * 1)) |
                        (compVal << (compBits * 0)));
      i++;
    }

    /* Download this in a sequential way to test the palette download */
    i = 0;
    while(i < 256) {
      const int max = i + (rand() % 10);
      const int end = MIN(max, 255);

      grTexDownloadTablePartial(curPalType, &texPal, i, end);
      i = end + 1;
    }

    i = 0;
    for(k = largeLod; k >= smallLod; k--) {
      i += ((0x01 << k) * (0x01 << k));
    }
    texData = (unsigned char*)malloc(i * 2);
    if (texData == NULL) {
      printf("Unable to allocate texture data.\n");
      goto __errExit;
    }

    /* Download dumb palettized texture */
    texInfo.smallLodLog2 = smallLod;
    texInfo.largeLodLog2 = largeLod;
    texInfo.aspectRatioLog2 = GR_ASPECT_LOG2_1x1;
    texInfo.format = GR_TEXFMT_P_8;
    texInfo.data = (void*)texData;
    
    for(k = texInfo.largeLodLog2; k >= texInfo.smallLodLog2; k--) {
      const int texDim = (0x01 << k);
      const float levelStep = (256.0f / texDim);
      tmp=texData;

      for(i = 0; i < texDim; i++) {
        for(j = 0; j < texDim; j++) {
          *tmp++ = (FxU8)(levelStep * i); 
        }
      }
    }

    grTexDownloadMipMap(GR_TMU0, 0, GR_MIPMAPLEVELMASK_BOTH, &texInfo);
    grTexSource(GR_TMU0, 0, GR_MIPMAPLEVELMASK_BOTH, &texInfo);

    free((void*)texData);
  }
  
  tlConOutput("Press a key to quit\n");
  while(frames-- && tlOkToRender()) {
    GrVertex vtxA, vtxB, vtxC;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight);
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    }

    grBufferClear(0xFF00FF00, 0xFF, wrange[1]);

    /* Triangle w/ texture ramp going across and down. */
    vtxA.oow = 
    vtxB.oow =
    vtxC.oow = 1.0f;

    {
      vtxA.x = tlScaleX(0.2f), vtxA.y = tlScaleY(0.2f);
      vtxA.tmuvtx[0].sow = minTexCoor;
      vtxA.tmuvtx[0].tow = minTexCoor;
      vtxA.tmuvtx[1].sow = 0.0f;
      vtxA.tmuvtx[1].tow = 0.0f;
      
      vtxB.x = tlScaleX(0.8f), vtxB.y = tlScaleY(0.2f);
      vtxB.tmuvtx[0].sow = maxTexCoor;
      vtxB.tmuvtx[0].tow = minTexCoor;
      vtxB.tmuvtx[1].sow = 255.0f;
      vtxB.tmuvtx[1].tow = 0.0f;
      
      vtxC.x = tlScaleX(0.8f), vtxC.y = tlScaleY(0.8f);
      vtxC.tmuvtx[0].sow = maxTexCoor;
      vtxC.tmuvtx[0].tow = maxTexCoor;
      vtxC.tmuvtx[1].sow = 255.0f;
      vtxC.tmuvtx[1].tow = 255.0f;

      grDrawTriangle(&vtxA, &vtxB, &vtxC);
    }

    {
      vtxA.x = tlScaleX(0.2f), vtxA.y = tlScaleY(0.2f);
      vtxA.tmuvtx[0].sow = minTexCoor;
      vtxA.tmuvtx[0].tow = minTexCoor;
      vtxA.tmuvtx[1].sow = 0.0f;
      vtxA.tmuvtx[1].tow = 0.0f;
      
      vtxB.x = tlScaleX(0.8f), vtxB.y = tlScaleY(0.8f);
      vtxB.tmuvtx[0].sow = maxTexCoor;
      vtxB.tmuvtx[0].tow = maxTexCoor;
      vtxB.tmuvtx[1].sow = 255.0f;
      vtxB.tmuvtx[1].tow = 255.0f;
      
      vtxC.x = tlScaleX(0.2f), vtxC.y = tlScaleY(0.8f);
      vtxC.tmuvtx[0].sow = minTexCoor;
      vtxC.tmuvtx[0].tow = maxTexCoor;
      vtxC.tmuvtx[1].sow = 0.0f;
      vtxC.tmuvtx[1].tow = 255.0f;
      
      grDrawTriangle(&vtxA, &vtxB, &vtxC);
    }

    tlConRender();
    grBufferSwap(1);

    /* grab the frame buffer */
    if (scrgrab) {
      if (!tlScreenDump(filename, (FxU16)scrWidth, (FxU16)scrHeight))
        printf("Cannot open %s\n", filename);
      scrgrab = FXFALSE;
    }

    if (tlKbHit()) frames = 0;
  }

__errExit:    
  grGlideShutdown();
}
Ejemplo n.º 12
0
void 
main(int argc, char **argv) 
{
  char match; 
  char **remArgs;
  int  rv;

  GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
  float                scrWidth   = 640.0f;
  float                scrHeight  = 480.0f;
  int frames                      = -1;
  FxBool               scrgrab = FXFALSE;
  char                 filename[256];
  FxU8                 subframe = 0;

  TlTexture            texture;
  FxU32                zrange[2];
  GrContext_t          gc = 0;
  FxU32                pixelformat = 0x0003; /* 16 bit 565 */
  static FxBool        useCCExt = 1;
  char                 textureFile[256];
  int                  bigTex = 0;
  FxBool               needToLoadNewTexture = FXFALSE;
  FxBool               umaIsEnabled = FXFALSE;

  float 
    xLeft,
    xRight,
    yTop,
    yBottom;

  /* Process Command Line Arguments */
  while(rv = tlGetOpt(argc, argv, "nrdxp", &match, &remArgs)) {
    if (rv == -1) {
      printf("Unrecognized command line argument\n");
      printf("%s %s\n", name, usage);
      printf("Available resolutions:\n%s\n",
             tlGetResolutionList());
      return;
    }
    switch(match) {
    case 'n':
      frames = atoi(remArgs[0]);
      break;
    case 'r':
      resolution = tlGetResolutionConstant(remArgs[0], 
                                           &scrWidth, 
                                           &scrHeight);
      break;
    case 'd':
      scrgrab = FXTRUE;
      frames = 5;      
      strcpy(filename, remArgs[0]);
      break;

    case 'p':
      pixelformat = tlGetPixelFormat( remArgs[0] );
      break;
    }
  }

  tlSetScreen(scrWidth, scrHeight);

  version = grGetString(GR_VERSION);

  printf("%s:\n%s\n", name, purpose);
  printf("%s\n", version);
  printf("Resolution: %s\n", tlGetResolutionString(resolution));
  if (frames == -1) {
    printf("Press A Key To Begin Test.\n");
    tlGetCH();
  }
    
  /* Initialize Glide */
  grGlideInit();
  assert(hwconfig = tlVoodooType());

  grGet(GR_ZDEPTH_MIN_MAX, 8, (FxI32 *)zrange);

  grSstSelect(0);

  tlInitGlideExt(&glideext);
  
  if (!glideext.combineext) {
    printf("Could not use COMBINE extension.\n");
    useCCExt = 0;
  }

  if (glideext.canDo32BitTexture) {
    printf("Using TEXFMT 32-bit extension.\n");
    strcpy(textureFile, "t256x32.3df"); /* 32 bits deep */
  } else {
    printf("Could not use TEXFMT 32-bit extension.\n");
    strcpy(textureFile, "miro.3df");    /* 16 bits deep */
  }

  if (glideext.umaExt) {
    printf("Using TEXUMA extension.\n");
    grEnable(GR_TEXTURE_UMA_EXT);
    umaIsEnabled = FXTRUE;
  } else {
    printf("Could not use TEXUMA extension.\n");
    grDisable(GR_TEXTURE_UMA_EXT);
    umaIsEnabled = FXFALSE;
  }

  if (glideext.grSstWinOpen) {
    gc = glideext.grSstWinOpen(tlGethWnd(),
                               resolution,
                               GR_REFRESH_60Hz,
                               GR_COLORFORMAT_ABGR,
                               GR_ORIGIN_UPPER_LEFT,
                               pixelformat,
                               2, 1);
  } else {
    gc = grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1);
  }
  if (!gc) {
    printf("Could not allocate glide fullscreen context.\n");
    goto __errExit;
  }
  
  tlVertexLayout();
  tlConSet(0.0f, 0.0f, 1.0f, 0.5f, 
           60, 15, 0xffffff);
    
  /* Load texture data into system ram */
  assert(tlLoadTexture(textureFile,
                       &texture.info, 
                       &texture.tableType, 
                       &texture.tableData));
  /* Download texture data to TMU */
  grTexDownloadMipMap(GR_TMU0,
                      grTexMinAddress(GR_TMU0),
                      GR_MIPMAPLEVELMASK_BOTH,
                      &texture.info);
  if (texture.tableType != NO_TABLE) {
    grTexDownloadTable(texture.tableType,
                       &texture.tableData);
  }

  /* Select Texture As Source of all texturing operations */
  grTexSource(GR_TMU0,
              grTexMinAddress(GR_TMU0),
              GR_MIPMAPLEVELMASK_BOTH,
              &texture.info);


  /* Enable Bilinear Filtering + Mipmapping */
  grTexFilterMode(GR_TMU0,
                  GR_TEXTUREFILTER_BILINEAR,
                  GR_TEXTUREFILTER_BILINEAR);
  grTexMipMapMode(GR_TMU0,
                  GR_MIPMAP_NEAREST,
                  FXFALSE);

  xLeft   = tlScaleX( 0.2f );
  xRight  = tlScaleX( 0.8f );
  yTop    = tlScaleY( 0.2f );
  yBottom = tlScaleY( 0.8f );

  while(frames-- && tlOkToRender()) {
    GrVertex vtxA, vtxB, vtxC, vtxD;
    static TextureMode textureMode;

    if (hwconfig == TL_VOODOORUSH) {
      tlGetDimsByConst(resolution,
                       &scrWidth, 
                       &scrHeight);
        
      grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);
    }

    grBufferClear(0x00, 0, zrange[1]);

    tlConOutput(  "m   : change lighting mode\n");
    tlConOutput(  "e   : toggle combine extension\n");
    tlConOutput(  "b   : big textures (if TEXFMT extension is available)\n");
    tlConOutput(  "u   : toggle UMA (if TEXUMA extension is available)\n");
    tlConOutput("Press any other key to quit\n");
    tlConOutput("Current Texture Mode: %s\n", textureModeNames[textureMode]);
    tlConOutput("COMBINE extension %s\n", cmodeName[useCCExt]);

    if (needToLoadNewTexture) {
      /*
       * This is only true if TEXFMT extension is available, which
       * implies 2k texture capability.  Also, this is only true if
       * the user has just hit 'b' for big texture testing.
       */
      assert(bigTex <= TEX_MAX);
      strcpy(textureFile, texFileNames[bigTex]);

      /* Redo all the texture loading stuff. */
      /* Load texture data into system ram */
      assert(tlLoadTexture(textureFile, &texture.info, &texture.tableType, 
                           &texture.tableData));
      /* Download texture data to TMU */
      grTexDownloadMipMap(GR_TMU0, grTexMinAddress(GR_TMU0),
                          GR_MIPMAPLEVELMASK_BOTH, &texture.info);
      if (texture.tableType != NO_TABLE) {
        grTexDownloadTable(texture.tableType, &texture.tableData);
      }
      
      /* Select Texture As Source of all texturing operations */
      grTexSource(GR_TMU0, grTexMinAddress(GR_TMU0), 
                  GR_MIPMAPLEVELMASK_BOTH, &texture.info);

      needToLoadNewTexture = FXFALSE;
    }

    if (useCCExt) {
#ifdef FX_GLIDE_NAPALM
      glideext.grTexColorCombineExt(GR_TMU0,
                                    GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                    GR_CMBX_LOCAL_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                    GR_CMBX_ZERO, FXFALSE,
                                    GR_CMBX_B, FXFALSE,
                                    0, FXFALSE);
      switch(textureMode) {
      case DECAL:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE, 
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case FLATLIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_CONSTANT_COLOR, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case RGBLIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITRGB, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        break;
      case WHITELIT:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITALPHA, GR_FUNC_MODE_ZERO, 
                                   GR_CMBX_B, FXFALSE,
                                   GR_CMBX_ZERO, FXFALSE,
                                   0, FXFALSE);
        glideext.grAlphaCombineExt(GR_CMBX_ITALPHA, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE,
                                   GR_CMBX_ALOCAL, FXFALSE,
                                   0, FXFALSE);
        break;
      case SPECALPHA:
        glideext.grColorCombineExt(GR_CMBX_TEXTURE_RGB, GR_FUNC_MODE_X, 
                                   GR_CMBX_ITALPHA, GR_FUNC_MODE_ZERO,
                                   GR_CMBX_ITRGB, FXFALSE,
                                   GR_CMBX_B, FXFALSE,
                                   0, FXFALSE);
        glideext.grAlphaCombineExt(GR_CMBX_ITALPHA, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, GR_FUNC_MODE_X, 
                                   GR_CMBX_ZERO, FXTRUE,
                                   GR_CMBX_ALOCAL, FXFALSE,
                                   0, FXFALSE);
        break;
      }
#endif
    }
    else {
      /* Set up Render State - Decal Texture - color combine set in render loop */
      grTexCombine(GR_TMU0,
                   GR_COMBINE_FUNCTION_LOCAL,
                   GR_COMBINE_FACTOR_NONE,
                   GR_COMBINE_FUNCTION_NONE,
                   GR_COMBINE_FACTOR_NONE,
                   FXFALSE, FXFALSE);

      switch(textureMode) {
      case DECAL:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_ONE,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case FLATLIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_CONSTANT,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case RGBLIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case WHITELIT:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER,
                       GR_COMBINE_FACTOR_LOCAL_ALPHA,
                       GR_COMBINE_LOCAL_NONE,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL,
                       GR_COMBINE_FACTOR_NONE,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      case SPECALPHA:
        grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER_ADD_LOCAL_ALPHA,
                       GR_COMBINE_FACTOR_LOCAL,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        grAlphaCombine(GR_COMBINE_FUNCTION_LOCAL,
                       GR_COMBINE_FACTOR_NONE,
                       GR_COMBINE_LOCAL_ITERATED,
                       GR_COMBINE_OTHER_TEXTURE,
                       FXFALSE);
        break;
      }
    }
        
    /*---- 
      A-B
      |\|
      C-D
      -----*/
    vtxA.oow = 1.0f;
    vtxB = vtxC = vtxD = vtxA;

    vtxA.x = vtxC.x = xLeft;
    vtxB.x = vtxD.x = xRight;
    vtxA.y = vtxB.y = yTop;
    vtxC.y = vtxD.y = yBottom;

    vtxA.tmuvtx[0].sow = vtxC.tmuvtx[0].sow = 0.0f;
    vtxB.tmuvtx[0].sow = vtxD.tmuvtx[0].sow = 255.0f;
    vtxA.tmuvtx[0].tow = vtxB.tmuvtx[0].tow = 0.0f;
    vtxC.tmuvtx[0].tow = vtxD.tmuvtx[0].tow = 255.0f;

    vtxA.r = 255.0f, vtxA.g =   0.0f, vtxA.b =   0.0f, vtxA.a = 255.0f;
    vtxB.r =   0.0f, vtxB.g = 255.0f, vtxB.b =   0.0f, vtxB.a = 128.0f;
    vtxC.r =   0.0f, vtxC.g =   0.0f, vtxC.b = 255.0f, vtxC.a = 128.0f;
    vtxD.r =   0.0f, vtxD.g =   0.0f, vtxD.b =   0.0f, vtxD.a =   0.0f;

    grConstantColorValue(0xFF0000FFUL);
    grTexSource(GR_TMU0,
                grTexMinAddress(GR_TMU0),
                GR_MIPMAPLEVELMASK_BOTH,
                &texture.info);

    grDrawTriangle(&vtxA, &vtxD, &vtxC);
    grDrawTriangle(&vtxA, &vtxB, &vtxD);

    tlConRender();
    tlConClear();
    grBufferSwap(1);
    grFinish();

    /* grab the frame buffer */
    if (scrgrab) {
      char fname[256], tmp[32];
      FxU16 cnt;

      cnt = strcspn(filename, ".");
      strncpy(fname, filename, cnt);
      fname[cnt] = 0;
      sprintf(tmp,"_%d\0", subframe);
      strcat(fname, tmp);
      strcat(fname, filename+cnt);
      if (!tlScreenDump(fname, (FxU16)scrWidth, (FxU16)scrHeight))
        printf("Cannot open %s\n", filename);

      /* cycle through all mode */
      textureMode++;
      if (textureMode > SPECALPHA) textureMode = DECAL;

      subframe++;
    }
        
    while(tlKbHit()) {
      const char curKey = tlGetCH();

      switch(curKey) {
      case 'e':
      case 'E':
        useCCExt = (!useCCExt);
        if (!glideext.combineext)
          useCCExt = 0;
        break;
      case 'm':
      case 'M':
        textureMode++;
        if (textureMode > SPECALPHA) textureMode = DECAL;
        break;
      case 'b':
      case 'B':
        /* Cycle through some texture sizes */
        if (glideext.canDo2kTexture) {
          needToLoadNewTexture = FXTRUE;
          bigTex = (bigTex + 1) % (TEX_MAX + 1); /* [0,...,TEX_MAX] */
          printf ("%s", texWidthString[bigTex]);
        }
        break;
      case 'u':
      case 'U':
        if (glideext.umaExt) {
          /* Toggle UMA on/off */
          if (umaIsEnabled) {
            grDisable(GR_TEXTURE_UMA_EXT);
            printf ("UMA extension is disabled.\n");
            umaIsEnabled = FXFALSE;
          } else {
            grEnable(GR_TEXTURE_UMA_EXT);
            printf ("UMA extension is enabled.\n");
            umaIsEnabled = FXTRUE;
          }
        }
        break;
      default:
        frames = 0;
        break;
      }
    }
  }
    
 __errExit:    
  grGlideShutdown();
}