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

📄 fxddtex.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
   fxTMFreeTexture(fxMesa, tObj);   FREE(ti);   tObj->DriverData = NULL;   /* Free mipmap images and the texture object itself */   _mesa_delete_texture_object(ctx, tObj);}/** * Allocate a new texture object. * Called via ctx->Driver.NewTextureObject. * Note: this function will be called during context creation to * allocate the default texture objects. */struct gl_texture_object *fxDDNewTextureObject( GLcontext *ctx, GLuint name, GLenum target ){   struct gl_texture_object *obj;   obj = _mesa_new_texture_object(ctx, name, target);   return obj;}/* * Return true if texture is resident, false otherwise. */GLbooleanfxDDIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj){   tfxTexInfo *ti = fxTMGetTexInfo(tObj);   return (ti && ti->isInTM);}/* * Convert a gl_color_table texture palette to Glide's format. */static GrTexTable_tconvertPalette(const fxMesaContext fxMesa, FxU32 data[256], const struct gl_color_table *table){   const GLubyte *tableUB = (const GLubyte *) table->Table;   GLint width = table->Size;   FxU32 r, g, b, a;   GLint i;   ASSERT(table->Type == GL_UNSIGNED_BYTE);   switch (table->_BaseFormat) {   case GL_INTENSITY:      for (i = 0; i < width; i++) {	 r = tableUB[i];	 g = tableUB[i];	 b = tableUB[i];	 a = tableUB[i];	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return fxMesa->HavePalExt ? GR_TEXTABLE_PALETTE_6666_EXT : GR_TEXTABLE_PALETTE;   case GL_LUMINANCE:      for (i = 0; i < width; i++) {	 r = tableUB[i];	 g = tableUB[i];	 b = tableUB[i];	 a = 255;	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return GR_TEXTABLE_PALETTE;   case GL_ALPHA:      for (i = 0; i < width; i++) {	 r = g = b = 255;	 a = tableUB[i];	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return fxMesa->HavePalExt ? GR_TEXTABLE_PALETTE_6666_EXT : GR_TEXTABLE_PALETTE;   case GL_LUMINANCE_ALPHA:      for (i = 0; i < width; i++) {	 r = g = b = tableUB[i * 2 + 0];	 a = tableUB[i * 2 + 1];	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return fxMesa->HavePalExt ? GR_TEXTABLE_PALETTE_6666_EXT : GR_TEXTABLE_PALETTE;   default:   case GL_RGB:      for (i = 0; i < width; i++) {	 r = tableUB[i * 3 + 0];	 g = tableUB[i * 3 + 1];	 b = tableUB[i * 3 + 2];	 a = 255;	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return GR_TEXTABLE_PALETTE;   case GL_RGBA:      for (i = 0; i < width; i++) {	 r = tableUB[i * 4 + 0];	 g = tableUB[i * 4 + 1];	 b = tableUB[i * 4 + 2];	 a = tableUB[i * 4 + 3];	 data[i] = (a << 24) | (r << 16) | (g << 8) | b;      }      return fxMesa->HavePalExt ? GR_TEXTABLE_PALETTE_6666_EXT : GR_TEXTABLE_PALETTE;   }}voidfxDDTexPalette(GLcontext * ctx, struct gl_texture_object *tObj){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   if (tObj) {      /* per-texture palette */      tfxTexInfo *ti;      if (TDFX_DEBUG & VERBOSE_DRIVER) {	 fprintf(stderr, "fxDDTexPalette(%d, %x)\n",		 tObj->Name, (GLuint) tObj->DriverData);      }      /* This might be a proxy texture. */      if (!tObj->Palette.Table)         return;      if (!tObj->DriverData)         tObj->DriverData = fxAllocTexObjData(fxMesa);      ti = fxTMGetTexInfo(tObj);      ti->paltype = convertPalette(fxMesa, ti->palette.data, &tObj->Palette);      fxTexInvalidate(ctx, tObj);   }   else {      /* global texture palette */      if (TDFX_DEBUG & VERBOSE_DRIVER) {	 fprintf(stderr, "fxDDTexPalette(global)\n");      }      fxMesa->glbPalType = convertPalette(fxMesa, fxMesa->glbPalette.data, &ctx->Texture.Palette);      fxMesa->new_state |= FX_NEW_TEXTURING;      grTexDownloadTable(fxMesa->glbPalType, &(fxMesa->glbPalette));   }}voidfxDDTexUseGlbPalette(GLcontext * ctx, GLboolean state){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   if (TDFX_DEBUG & VERBOSE_DRIVER) {      fprintf(stderr, "fxDDTexUseGlbPalette(%d)\n", state);   }   fxMesa->haveGlobalPaletteTexture = state;   fxMesa->new_state |= FX_NEW_TEXTURING;}static intlogbase2(int n){   GLint i = 1;   GLint log2 = 0;   if (n < 0) {      return -1;   }   while (n > i) {      i *= 2;      log2++;   }   if (i != n) {      return -1;   }   else {      return log2;   }}/* fxTexGetInfo * w, h     - source texture width and height * lodlevel - Glide lod level token for the larger texture dimension * ar       - Glide aspect ratio token * sscale   - S scale factor used during triangle setup * tscale   - T scale factor used during triangle setup * wscale   - OpenGL -> Glide image width scale factor * hscale   - OpenGL -> Glide image height scale factor */intfxTexGetInfo(int w, int h, GrLOD_t * lodlevel, GrAspectRatio_t * ar,	     float *sscale, float *tscale,	     int *wscale, int *hscale){   int logw, logh, ws, hs;   GrLOD_t l;   GrAspectRatio_t aspectratio;   float s, t;   logw = logbase2(w);   logh = logbase2(h);   l = MAX2(logw, logh);   aspectratio = logw - logh;   ws = hs = 1;   s = t = 256.0f;   /* hardware only allows a maximum aspect ratio of 8x1, so handle    * |aspectratio| > 3 by scaling the image and using an 8x1 aspect    * ratio    */   switch (aspectratio) {   case 0:      break;   case 1:      t = 128.0f;      break;   case 2:      t = 64.0f;      break;   case 3:      t = 32.0f;      break;   case -1:      s = 128.0f;      break;   case -2:      s = 64.0f;      break;   case -3:      s = 32.0f;      break;   default:      if (aspectratio > 3) {         t = 32.0f;         hs = 1 << (aspectratio - 3);         aspectratio = GR_ASPECT_LOG2_8x1;      } else /*if (aspectratio < -3)*/ {         s = 32.0f;         ws = 1 << (-aspectratio - 3);         aspectratio = GR_ASPECT_LOG2_1x8;      }   }   if (lodlevel)      (*lodlevel) = l;   if (ar)      (*ar) = aspectratio;   if (sscale)      (*sscale) = s;   if (tscale)      (*tscale) = t;   if (wscale)      (*wscale) = ws;   if (hscale)      (*hscale) = hs;   return 1;}static GLbooleanfxIsTexSupported(GLenum target, GLint internalFormat,		 const struct gl_texture_image *image){   if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))      return GL_FALSE;#if 0   if (!fxTexGetInfo(image->Width, image->Height, NULL, NULL, NULL, NULL, NULL, NULL))       return GL_FALSE;#endif   if (image->Border > 0)      return GL_FALSE;   return GL_TRUE;}/**********************************************************************//**** NEW TEXTURE IMAGE FUNCTIONS                                  ****//**********************************************************************/extern voidfxt1_decode_1 (const void *texture, int width,               int i, int j, unsigned char *rgba);/* Texel-fetch functions for software texturing and glGetTexImage(). * We should have been able to use some "standard" fetch functions (which * may get defined in texutil.c) but we have to account for scaled texture * images on tdfx hardware (the 8:1 aspect ratio limit). * Hence, we need special functions here. */static voidfetch_intensity8(const struct gl_texture_image *texImage,		 GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLubyte *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLubyte *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = *texel;   rgba[GCOMP] = *texel;   rgba[BCOMP] = *texel;   rgba[ACOMP] = *texel;}static voidfetch_luminance8(const struct gl_texture_image *texImage,		 GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLubyte *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLubyte *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = *texel;   rgba[GCOMP] = *texel;   rgba[BCOMP] = *texel;   rgba[ACOMP] = 255;}static voidfetch_alpha8(const struct gl_texture_image *texImage,	     GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLubyte *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLubyte *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = 255;   rgba[GCOMP] = 255;   rgba[BCOMP] = 255;   rgba[ACOMP] = *texel;}static voidfetch_index8(const struct gl_texture_image *texImage,	     GLint i, GLint j, GLint k, GLchan *indexOut){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLubyte *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLubyte *) texImage->Data) + j * mml->width + i;   *indexOut = *texel;}static voidfetch_luminance8_alpha8(const struct gl_texture_image *texImage,			GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLubyte *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLubyte *) texImage->Data) + (j * mml->width + i) * 2;   rgba[RCOMP] = texel[0];   rgba[GCOMP] = texel[0];   rgba[BCOMP] = texel[0];   rgba[ACOMP] = texel[1];}static voidfetch_r5g6b5(const struct gl_texture_image *texImage,	     GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLushort *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLushort *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = FX_rgb_scale_5[(*texel >> 11) & 0x1F];   rgba[GCOMP] = FX_rgb_scale_6[(*texel >>  5) & 0x3F];   rgba[BCOMP] = FX_rgb_scale_5[ *texel        & 0x1F];   rgba[ACOMP] = 255;}static voidfetch_r4g4b4a4(const struct gl_texture_image *texImage,	       GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLushort *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLushort *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = FX_rgb_scale_4[(*texel >>  8) & 0xF];   rgba[GCOMP] = FX_rgb_scale_4[(*texel >>  4) & 0xF];   rgba[BCOMP] = FX_rgb_scale_4[ *texel        & 0xF];   rgba[ACOMP] = FX_rgb_scale_4[(*texel >> 12) & 0xF];}static voidfetch_r5g5b5a1(const struct gl_texture_image *texImage,	       GLint i, GLint j, GLint k, GLchan *rgba){   const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);   const GLushort *texel;   i = i * mml->wScale;   j = j * mml->hScale;   texel = ((GLushort *) texImage->Data) + j * mml->width + i;   rgba[RCOMP] = FX_rgb_scale_5[(*texel >> 10) & 0x1F];   rgba[GCOMP] = FX_rgb_scale_5[(*texel >>  5) & 0x1F];   rgba[BCOMP] = FX_rgb_scale_5[ *texel        & 0x1F];   rgba[ACOMP] = (*texel >> 15) * 255;}static voidfetch_a8r8g8b8(const struct gl_texture_image *texImage,	       GLint i, GLint j, GLint k, GLchan *rgba){    const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);    const GLuint *texel;    i = i * mml->wScale;    j = j * mml->hScale;    texel = ((GLuint *) texImage->Data) + j * mml->width + i;    rgba[RCOMP] = (((*texel) >> 16) & 0xff);    rgba[GCOMP] = (((*texel) >>  8) & 0xff);    rgba[BCOMP] = (((*texel)      ) & 0xff);    rgba[ACOMP] = (((*texel) >> 24) & 0xff);}static voidfetch_rgb_fxt1(const struct gl_texture_image *texImage,	       GLint i, GLint j, GLint k, GLchan *rgba){    const tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);    i = i * mml->wScale;    j = j * mml->hScale;

⌨️ 快捷键说明

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