예제 #1
0
파일: sis_tex.c 프로젝트: Ionic/nx-libs
static void
sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
		  const struct gl_texture_image *image )
{
   char *addr;
   int size, texel_size;

   if (t->format == 0) {
      t->format = image->Format;
      switch (t->format)
      {
      case GL_RGBA:
         t->hwformat = TEXEL_ARGB_8888_32;
         break;
      case GL_INTENSITY:
         t->hwformat = TEXEL_I8;
         break;
      case GL_ALPHA:
         t->hwformat = TEXEL_A8;
         break;
      case GL_LUMINANCE:
         t->hwformat = TEXEL_L8;
         break;
      case GL_LUMINANCE_ALPHA:
         t->hwformat = TEXEL_AL88;
         break;
      case GL_RGB:
         t->hwformat = TEXEL_ARGB_0888_32;
         break;
      default:
         sis_fatal_error("Bad texture format.\n");
      }
   }
   assert(t->format == image->Format);

   texel_size = image->TexFormat->TexelBytes;
   size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS;

   addr = sisAllocFB( smesa, size, &t->image[level].handle );
   if (addr == NULL) {
      addr = sisAllocAGP( smesa, size, &t->image[level].handle );
      if (addr == NULL)
         sis_fatal_error("Failure to allocate texture memory.\n");
      t->image[level].memType = AGP_TYPE;
   }
   else
      t->image[level].memType = VIDEO_TYPE;
   
   t->image[level].Data = ALIGN(addr, TEXTURE_HW_ALIGNMENT);
   t->image[level].pitch = image->Width * texel_size;
   t->image[level].size = image->Width * image->Height * texel_size;
   t->numImages++;
}
예제 #2
0
static void
sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
                  const struct gl_texture_image *image )
{
    char *addr;
    int size, texel_size;

    if (t->format == 0) {
        t->format = image->_BaseFormat;
        switch (image->TexFormat)
        {
        case MESA_FORMAT_ARGB8888:
            t->hwformat = TEXEL_ARGB_8888_32;
            break;
        case MESA_FORMAT_ARGB4444:
            t->hwformat = TEXEL_ARGB_4444_16;
            break;
        case MESA_FORMAT_ARGB1555:
            t->hwformat = TEXEL_ARGB_1555_16;
            break;
        case MESA_FORMAT_RGB565:
            t->hwformat = TEXEL_RGB_565_16;
            break;
        case MESA_FORMAT_RGB332:
            t->hwformat = TEXEL_RGB_332_8;
            break;
        case MESA_FORMAT_I8:
            t->hwformat = TEXEL_I8;
            break;
        case MESA_FORMAT_A8:
            t->hwformat = TEXEL_A8;
            break;
        case MESA_FORMAT_L8:
            t->hwformat = TEXEL_L8;
            break;
        case MESA_FORMAT_AL88:
            t->hwformat = TEXEL_AL88;
            break;
        case MESA_FORMAT_YCBCR:
            t->hwformat = TEXEL_YUV422;
            break;
        case MESA_FORMAT_YCBCR_REV:
            t->hwformat = TEXEL_VUY422;
            break;
        default:
            sis_fatal_error("Bad texture format 0x%x.\n", image->TexFormat);
        }
    }
    assert(t->format == image->_BaseFormat);

    texel_size = _mesa_get_format_bytes(image->TexFormat);
    size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS;

    addr = sisAllocFB( smesa, size, &t->image[level].handle );
    if (addr == NULL) {
        addr = sisAllocAGP( smesa, size, &t->image[level].handle );
        if (addr == NULL)
            sis_fatal_error("Failure to allocate texture memory.\n");
        t->image[level].memType = AGP_TYPE;
    }
    else
        t->image[level].memType = VIDEO_TYPE;

    t->image[level].Data = ALIGN(addr, TEXTURE_HW_ALIGNMENT);
    t->image[level].pitch = image->Width * texel_size;
    t->image[level].size = image->Width * image->Height * texel_size;
    t->numImages++;
}
예제 #3
0
GLboolean
sisCreateContext( const __GLcontextModes *glVisual,
		  __DRIcontextPrivate *driContextPriv,
                  void *sharedContextPrivate )
{
   GLcontext *ctx, *shareCtx;
   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
   sisContextPtr smesa;
   sisScreenPtr sisScreen;
   int i;
   struct dd_function_table functions;

   smesa = (sisContextPtr)CALLOC( sizeof(*smesa) );
   if (smesa == NULL)
      return GL_FALSE;

   /* Init default driver functions then plug in our SIS-specific functions
    * (the texture functions are especially important)
    */
   _mesa_init_driver_functions(&functions);
   sisInitDriverFuncs(&functions);
   sisInitTextureFuncs(&functions);

   /* Allocate the Mesa context */
   if (sharedContextPrivate)
      shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx;
   else 
      shareCtx = NULL;
   smesa->glCtx = _mesa_create_context( glVisual, shareCtx,
                                        &functions, (void *) smesa);
   if (!smesa->glCtx) {
      FREE(smesa);
      return GL_FALSE;
   }
   driContextPriv->driverPrivate = smesa;
   ctx = smesa->glCtx;

   sisScreen = smesa->sisScreen = (sisScreenPtr)(sPriv->private);

   smesa->driContext = driContextPriv;
   smesa->driScreen = sPriv;
   smesa->driDrawable = NULL;
   smesa->hHWContext = driContextPriv->hHWContext;
   smesa->driHwLock = &sPriv->pSAREA->lock;
   smesa->driFd = sPriv->fd;
  
   smesa->virtualX = sisScreen->screenX;
   smesa->virtualY = sisScreen->screenY;
   smesa->bytesPerPixel = sisScreen->cpp;
   smesa->IOBase = sisScreen->mmio.map;
   smesa->Chipset = sisScreen->deviceID;
   smesa->irqEnabled = sisScreen->irqEnabled;

   smesa->FbBase = sPriv->pFB;
   smesa->displayWidth = sPriv->fbWidth;
   smesa->frontPitch = sPriv->fbStride;

   smesa->sarea = (SISSAREAPriv *)((char *)sPriv->pSAREA +
				   sisScreen->sarea_priv_offset);

#if defined(SIS_DUMP)
   IOBase4Debug = GET_IOBase (smesa);
#endif

   /* support ARGB8888 and RGB565 */
   switch (smesa->bytesPerPixel)
   {
   case 4:
      smesa->redMask = 0x00ff0000;
      smesa->greenMask = 0x0000ff00;
      smesa->blueMask = 0x000000ff;
      smesa->alphaMask = 0xff000000;
      smesa->colorFormat = DST_FORMAT_ARGB_8888;
      break;
   case 2:
      smesa->redMask = 0xf800;
      smesa->greenMask = 0x07e0;
      smesa->blueMask = 0x001f;
      smesa->alphaMask = 0;
      smesa->colorFormat = DST_FORMAT_RGB_565;
      break;
   default:
      sis_fatal_error("Bad bytesPerPixel.\n");
   }

   /* Parse configuration files */
   driParseConfigFiles (&smesa->optionCache, &sisScreen->optionCache,
			sisScreen->driScreen->myNum, "sis");

   /* TODO: index mode */

   smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength);
   smesa->FrameCountPtr = &(smesa->sarea->FrameCount);

   /* set AGP */
   smesa->AGPSize = sisScreen->agp.size;
   smesa->AGPBase = sisScreen->agp.map;
   smesa->AGPAddr = sisScreen->agp.handle;

   /* Create AGP command buffer */
   if (smesa->AGPSize != 0 && 
      !driQueryOptionb(&smesa->optionCache, "agp_disable"))
   {
      smesa->vb = sisAllocAGP(smesa, 64 * 1024, &smesa->vb_agp_handle);
      if (smesa->vb != NULL) {
	 smesa->using_agp = GL_TRUE;
	 smesa->vb_cur = smesa->vb;
	 smesa->vb_last = smesa->vb;
	 smesa->vb_end = smesa->vb + 64 * 1024;
	 smesa->vb_agp_offset = ((long)smesa->vb - (long)smesa->AGPBase +
	    (long)smesa->AGPAddr);
      }
   }
   if (!smesa->using_agp) {
      smesa->vb = malloc(64 * 1024);
      if (smesa->vb == NULL) {
	 FREE(smesa);
	 return GL_FALSE;
      }
      smesa->vb_cur = smesa->vb;
      smesa->vb_last = smesa->vb;
      smesa->vb_end = smesa->vb + 64 * 1024;
   }

   smesa->GlobalFlag = 0L;

   smesa->Fallback = 0;

   /* Initialize the software rasterizer and helper modules.
    */
   _swrast_CreateContext( ctx );
   _ac_CreateContext( ctx );
   _tnl_CreateContext( ctx );
   _swsetup_CreateContext( ctx );

   _swrast_allow_pixel_fog( ctx, GL_TRUE );
   _swrast_allow_vertex_fog( ctx, GL_FALSE );
   _tnl_allow_pixel_fog( ctx, GL_TRUE );
   _tnl_allow_vertex_fog( ctx, GL_FALSE );

   /* XXX these should really go right after _mesa_init_driver_functions() */
   sisDDInitStateFuncs( ctx );
   sisDDInitState( smesa );	/* Initializes smesa->zFormat, important */
   sisInitTriFuncs( ctx );
   sisDDInitSpanFuncs( ctx );
   sisDDInitStencilFuncs( ctx );

   driInitExtensions( ctx, card_extensions, GL_FALSE );

   /* TODO */
   /* smesa->blockWrite = SGRAMbw = IsBlockWrite (); */
   smesa->blockWrite = GL_FALSE;

   for (i = 0; i < SIS_MAX_TEXTURES; i++) {
      smesa->TexStates[i] = 0;
      smesa->PrevTexFormat[i] = 0;
   }

   return GL_TRUE;
}