⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 savagetex.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
 * the current tileInfo. */static void savageMarkDirtyTiles (savageTexObjPtr t, GLuint level,				  GLuint totalWidth, GLuint totalHeight,				  GLint xoffset, GLint yoffset,				  GLsizei width, GLsizei height){   GLuint wInTiles, hInTiles;   GLuint x0, y0, x1, y1;   GLuint x, y;   if (!t->tileInfo)      return;   wInTiles = (totalWidth + t->tileInfo->width - 1) / t->tileInfo->width;   hInTiles = (totalHeight + t->tileInfo->height - 1) / t->tileInfo->height;   if (wInTiles * hInTiles != t->image[level].nTiles)      return;   x0 = xoffset / t->tileInfo->width;   y0 = yoffset / t->tileInfo->height;   x1 = (xoffset + width - 1) / t->tileInfo->width;   y1 = (yoffset + height - 1) / t->tileInfo->height;   for (y = y0; y <= y1; ++y) {      GLuint *ptr = t->image[level].dirtyTiles + (y * wInTiles + x0) / 32;      GLuint mask = 1 << (y * wInTiles + x0) % 32;      for (x = x0; x <= x1; ++x) {	 *ptr |= mask;	 if (mask == (1<<31)) {	    ptr++;	    mask = 1;	 } else {	    mask <<= 1;	 }      }   }}/** \brief Mark all tiles as dirty */static void savageMarkAllTiles (savageTexObjPtr t, GLuint level){   GLuint words = (t->image[level].nTiles + 31) / 32;   if (words)      memset(t->image[level].dirtyTiles, ~0, words*sizeof(GLuint));}static void savageSetTexWrapping(savageTexObjPtr tex, GLenum s, GLenum t){    tex->setup.sWrapMode = s;    tex->setup.tWrapMode = t;}static void savageSetTexFilter(savageTexObjPtr t, GLenum minf, GLenum magf){   t->setup.minFilter = minf;   t->setup.magFilter = magf;}/* Need a fallback ? */static void savageSetTexBorderColor(savageTexObjPtr t, GLubyte color[4]){/*    t->Setup[SAVAGE_TEXREG_TEXBORDERCOL] =  */    /*t->setup.borderColor = SAVAGEPACKCOLOR8888(color[0],color[1],color[2],color[3]); */}static savageTexObjPtrsavageAllocTexObj( struct gl_texture_object *texObj ) {   savageTexObjPtr t;   t = (savageTexObjPtr) calloc(1,sizeof(*t));   texObj->DriverData = t;   if ( t != NULL ) {      GLuint i;      /* Initialize non-image-dependent parts of the state:       */      t->base.tObj = texObj;      t->base.dirty_images[0] = 0;      t->dirtySubImages = 0;      t->tileInfo = NULL;      /* Initialize dirty tiles bit vectors       */      for (i = 0; i < SAVAGE_TEX_MAXLEVELS; ++i)	 t->image[i].nTiles = 0;      /* FIXME Something here to set initial values for other parts of       * FIXME t->setup?       */        make_empty_list( &t->base );      savageSetTexWrapping(t,texObj->WrapS,texObj->WrapT);      savageSetTexFilter(t,texObj->MinFilter,texObj->MagFilter);      savageSetTexBorderColor(t,texObj->_BorderChan);   }   return t;}/* Mesa texture formats for alpha-images on Savage3D/IX/MX * * Promoting texture images to ARGB888 or ARGB4444 doesn't work * because we can't tell the hardware to ignore the color components * and only use the alpha component. So we define our own texture * formats that promote to ARGB8888 or ARGB4444 and set the color * components to white. This way we get the correct result. */static GLboolean_savage_texstore_a1114444(TEXSTORE_PARAMS);static GLboolean_savage_texstore_a1118888(TEXSTORE_PARAMS);static struct gl_texture_format _savage_texformat_a1114444 = {    MESA_FORMAT_ARGB4444,		/* MesaFormat */    GL_RGBA,				/* BaseFormat */    GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */    4,					/* RedBits */    4,					/* GreenBits */    4,					/* BlueBits */    4,					/* AlphaBits */    0,					/* LuminanceBits */    0,					/* IntensityBits */    0,					/* IndexBits */    0,					/* DepthBits */    0,					/* StencilBits */    2,					/* TexelBytes */    _savage_texstore_a1114444,		/* StoreTexImageFunc */    NULL, NULL, NULL, NULL, NULL, NULL  /* FetchTexel* filled in by 					 * savageDDInitTextureFuncs */};static struct gl_texture_format _savage_texformat_a1118888 = {    MESA_FORMAT_ARGB8888,		/* MesaFormat */    GL_RGBA,				/* BaseFormat */    GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */    8,					/* RedBits */    8,					/* GreenBits */    8,					/* BlueBits */    8,					/* AlphaBits */    0,					/* LuminanceBits */    0,					/* IntensityBits */    0,					/* IndexBits */    0,					/* DepthBits */    0,					/* StencilBits */    4,					/* TexelBytes */    _savage_texstore_a1118888,		/* StoreTexImageFunc */    NULL, NULL, NULL, NULL, NULL, NULL  /* FetchTexel* filled in by 					 * savageDDInitTextureFuncs */};static GLboolean_savage_texstore_a1114444(TEXSTORE_PARAMS){    const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,                                                 baseInternalFormat,                                                 baseInternalFormat,                                                 srcWidth, srcHeight, srcDepth,                                                 srcFormat, srcType, srcAddr,                                                 srcPacking);    const GLchan *src = tempImage;    GLint img, row, col;    ASSERT(dstFormat == &_savage_texformat_a1114444);    ASSERT(baseInternalFormat == GL_ALPHA);    if (!tempImage)	return GL_FALSE;    _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);    for (img = 0; img < srcDepth; img++) {        GLubyte *dstRow = (GLubyte *) dstAddr           + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes           + dstYoffset * dstRowStride           + dstXoffset * dstFormat->TexelBytes;	for (row = 0; row < srcHeight; row++) {            GLushort *dstUI = (GLushort *) dstRow;	    for (col = 0; col < srcWidth; col++) {		dstUI[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[0]),					      255, 255, 255 );		src += 1;            }            dstRow += dstRowStride;	}    }    _mesa_free((void *) tempImage);    return GL_TRUE;}static GLboolean_savage_texstore_a1118888(TEXSTORE_PARAMS){    const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,                                                 baseInternalFormat,                                                 baseInternalFormat,                                                 srcWidth, srcHeight, srcDepth,                                                 srcFormat, srcType, srcAddr,                                                 srcPacking);    const GLchan *src = tempImage;    GLint img, row, col;    ASSERT(dstFormat == &_savage_texformat_a1118888);    ASSERT(baseInternalFormat == GL_ALPHA);    if (!tempImage)	return GL_FALSE;    _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);    for (img = 0; img < srcDepth; img++) {        GLubyte *dstRow = (GLubyte *) dstAddr           + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes           + dstYoffset * dstRowStride           + dstXoffset * dstFormat->TexelBytes;	for (row = 0; row < srcHeight; row++) {            GLuint *dstUI = (GLuint *) dstRow;	    for (col = 0; col < srcWidth; col++) {		dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[0]),					      255, 255, 255 );		src += 1;            }            dstRow += dstRowStride;	}    }    _mesa_free((void *) tempImage);    return GL_TRUE;}/* Called by the _mesa_store_teximage[123]d() functions. */static const struct gl_texture_format *savageChooseTextureFormat( GLcontext *ctx, GLint internalFormat,			   GLenum format, GLenum type ){   savageContextPtr imesa = SAVAGE_CONTEXT(ctx);   const GLboolean do32bpt =       ( imesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 );   const GLboolean force16bpt =       ( imesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 );   const GLboolean isSavage4 = (imesa->savageScreen->chipset >= S3_SAVAGE4);   (void) format;   switch ( internalFormat ) {   case 4:   case GL_RGBA:   case GL_COMPRESSED_RGBA:      switch ( type ) {      case GL_UNSIGNED_INT_10_10_10_2:      case GL_UNSIGNED_INT_2_10_10_10_REV:	 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555;      case GL_UNSIGNED_SHORT_4_4_4_4:      case GL_UNSIGNED_SHORT_4_4_4_4_REV:	 return &_mesa_texformat_argb4444;      case GL_UNSIGNED_SHORT_5_5_5_1:      case GL_UNSIGNED_SHORT_1_5_5_5_REV:	 return &_mesa_texformat_argb1555;      default:         return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;      }   case 3:   case GL_RGB:   case GL_COMPRESSED_RGB:      switch ( type ) {      case GL_UNSIGNED_SHORT_4_4_4_4:      case GL_UNSIGNED_SHORT_4_4_4_4_REV:	 return &_mesa_texformat_argb4444;      case GL_UNSIGNED_SHORT_5_5_5_1:      case GL_UNSIGNED_SHORT_1_5_5_5_REV:	 return &_mesa_texformat_argb1555;      case GL_UNSIGNED_SHORT_5_6_5:      case GL_UNSIGNED_SHORT_5_6_5_REV:	 return &_mesa_texformat_rgb565;      default:         return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;      }   case GL_RGBA8:   case GL_RGBA12:   case GL_RGBA16:      return !force16bpt ?	  &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;   case GL_RGB10_A2:      return !force16bpt ?	  &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555;   case GL_RGBA4:   case GL_RGBA2:      return &_mesa_texformat_argb4444;   case GL_RGB5_A1:      return &_mesa_texformat_argb1555;   case GL_RGB8:   case GL_RGB10:   case GL_RGB12:   case GL_RGB16:      return !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;   case GL_RGB5:   case GL_RGB4:   case GL_R3_G3_B2:      return &_mesa_texformat_rgb565;   case GL_ALPHA:   case GL_COMPRESSED_ALPHA:      return isSavage4 ? &_mesa_texformat_a8 : (	 do32bpt ? &_savage_texformat_a1118888 : &_savage_texformat_a1114444);   case GL_ALPHA4:      return isSavage4 ? &_mesa_texformat_a8 : &_savage_texformat_a1114444;   case GL_ALPHA8:   case GL_ALPHA12:   case GL_ALPHA16:      return isSavage4 ? &_mesa_texformat_a8 : (	 !force16bpt ? &_savage_texformat_a1118888 : &_savage_texformat_a1114444);   case 1:   case GL_LUMINANCE:   case GL_COMPRESSED_LUMINANCE:      /* no alpha, but use argb1555 in 16bit case to get pure grey values */      return isSavage4 ? &_mesa_texformat_l8 : (	 do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555);   case GL_LUMINANCE4:      return isSavage4 ? &_mesa_texformat_l8 : &_mesa_texformat_argb1555;   case GL_LUMINANCE8:   case GL_LUMINANCE12:   case GL_LUMINANCE16:      return isSavage4 ? &_mesa_texformat_l8 : (	 !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555);   case 2:   case GL_LUMINANCE_ALPHA:   case GL_COMPRESSED_LUMINANCE_ALPHA:      /* Savage4 has a al44 texture format. But it's not supported by Mesa. */      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;   case GL_LUMINANCE4_ALPHA4:   case GL_LUMINANCE6_ALPHA2:      return &_mesa_texformat_argb4444;   case GL_LUMINANCE8_ALPHA8:   case GL_LUMINANCE12_ALPHA4:   case GL_LUMINANCE12_ALPHA12:   case GL_LUMINANCE16_ALPHA16:      return !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;#if 0   /* TFT_I8 produces garbage on ProSavageDDR and subsequent texture    * disable keeps rendering garbage. Disabled for now. */   case GL_INTENSITY:   case GL_COMPRESSED_INTENSITY:      return isSavage4 ? &_mesa_texformat_i8 : (	 do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);   case GL_INTENSITY4:      return isSavage4 ? &_mesa_texformat_i8 : &_mesa_texformat_argb4444;   case GL_INTENSITY8:   case GL_INTENSITY12:   case GL_INTENSITY16:      return isSavage4 ? &_mesa_texformat_i8 : (	 !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);#else   case GL_INTENSITY:   case GL_COMPRESSED_INTENSITY:      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;   case GL_INTENSITY4:      return &_mesa_texformat_argb4444;   case GL_INTENSITY8:   case GL_INTENSITY12:   case GL_INTENSITY16:      return !force16bpt ? &_mesa_texformat_argb8888 :	  &_mesa_texformat_argb4444;#endif   case GL_RGB_S3TC:   case GL_RGB4_S3TC:   case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:      return &_mesa_texformat_rgb_dxt1;   case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:      return &_mesa_texformat_rgba_dxt1;   case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:      return &_mesa_texformat_rgba_dxt3;   case GL_RGBA_S3TC:   case GL_RGBA4_S3TC:      if (!isSavage4)	 /* Not the best choice but Savage3D/MX/IX don't support DXT3 or DXT5. */	 return &_mesa_texformat_rgba_dxt1;      /* fall through */   case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:      return &_mesa_texformat_rgba_dxt5;/*   case GL_COLOR_INDEX:   case GL_COLOR_INDEX1_EXT:   case GL_COLOR_INDEX2_EXT:   case GL_COLOR_INDEX4_EXT:   case GL_COLOR_INDEX8_EXT:   case GL_COLOR_INDEX12_EXT:   case GL_COLOR_INDEX16_EXT:      return &_mesa_texformat_ci8;*/   default:      _mesa_problem(ctx, "unexpected texture format in %s", __FUNCTION__);      return NULL;   }}static void savageSetTexImages( savageContextPtr imesa,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -