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

📄 fxddtex.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * Mesa 3-D graphics library * Version:  4.0 * * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//* Authors: *    David Bucciarelli *    Brian Paul *    Daryll Strauss *    Keith Whitwell *    Daniel Borca *    Hiroshi Morii */#ifdef HAVE_CONFIG_H#include "conf.h"#endif#if defined(FX)#include "fxdrv.h"#include "enums.h"#include "image.h"#include "teximage.h"#include "texformat.h"#include "texcompress.h"#include "texobj.h"#include "texstore.h"/* no borders! can't halve 1x1! (stride > width * comp) not allowed */static void_mesa_halve2x2_teximage2d ( GLcontext *ctx,			    struct gl_texture_image *texImage,			    GLuint bytesPerPixel,			    GLint srcWidth, GLint srcHeight,			    const GLvoid *srcImage, GLvoid *dstImage ){   GLint i, j, k;   GLint dstWidth = srcWidth / 2;   GLint dstHeight = srcHeight / 2;   GLint srcRowStride = srcWidth * bytesPerPixel;   GLubyte *src = (GLubyte *)srcImage;   GLubyte *dst = dstImage;   GLuint bpt = 0;   GLubyte *_s = NULL;   GLubyte *_d = NULL;   GLenum _t = 0;   if (texImage->TexFormat->MesaFormat == MESA_FORMAT_RGB565) {      _t = GL_UNSIGNED_SHORT_5_6_5_REV;      bpt = bytesPerPixel;   } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB4444) {      _t = GL_UNSIGNED_SHORT_4_4_4_4_REV;      bpt = bytesPerPixel;   } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB1555) {      _t = GL_UNSIGNED_SHORT_1_5_5_5_REV;      bpt = bytesPerPixel;   }   if (bpt) {      bytesPerPixel = 4;      srcRowStride = srcWidth * bytesPerPixel;      if (dstWidth == 0) {         dstWidth = 1;      }      if (dstHeight == 0) {         dstHeight = 1;      }      _s = src = MALLOC(srcRowStride * srcHeight);      _d = dst = MALLOC(dstWidth * bytesPerPixel * dstHeight);      _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,                              &_mesa_texformat_rgba8888_rev, src,                              0, 0, 0, /* dstX/Y/Zoffset */                              srcRowStride, /* dstRowStride */                              0, /* dstImageStride */                              srcWidth, srcHeight, 1,                              texImage->_BaseFormat, _t,                              srcImage, &ctx->DefaultPacking);   }   if (srcHeight == 1) {      for (i = 0; i < dstWidth; i++) {         for (k = 0; k < bytesPerPixel; k++) {            dst[0] = (src[0] + src[bytesPerPixel] + 1) / 2;            src++;            dst++;         }         src += bytesPerPixel;      }   } else if (srcWidth == 1) {      for (j = 0; j < dstHeight; j++) {         for (k = 0; k < bytesPerPixel; k++) {            dst[0] = (src[0] + src[srcRowStride] + 1) / 2;            src++;            dst++;         }         src += srcRowStride;      }   } else {      for (j = 0; j < dstHeight; j++) {         for (i = 0; i < dstWidth; i++) {            for (k = 0; k < bytesPerPixel; k++) {               dst[0] = (src[0] +                         src[bytesPerPixel] +                         src[srcRowStride] +                         src[srcRowStride + bytesPerPixel] + 2) / 4;               src++;               dst++;            }            src += bytesPerPixel;         }         src += srcRowStride;      }   }   if (bpt) {      src = _s;      dst = _d;      texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,                                      texImage->TexFormat, dstImage,                                      0, 0, 0, /* dstX/Y/Zoffset */                                      dstWidth * bpt,                                      0, /* dstImageStride */                                      dstWidth, dstHeight, 1,                                      GL_BGRA, CHAN_TYPE, dst, &ctx->DefaultPacking);      FREE(dst);      FREE(src);   }}voidfxPrintTextureData(tfxTexInfo * ti){   fprintf(stderr, "Texture Data:\n");   if (ti->tObj) {      fprintf(stderr, "\tName: %d\n", ti->tObj->Name);      fprintf(stderr, "\tBaseLevel: %d\n", ti->tObj->BaseLevel);      fprintf(stderr, "\tSize: %d x %d\n",	      ti->tObj->Image[0][ti->tObj->BaseLevel]->Width,	      ti->tObj->Image[0][ti->tObj->BaseLevel]->Height);   }   else      fprintf(stderr, "\tName: UNNAMED\n");   fprintf(stderr, "\tLast used: %d\n", ti->lastTimeUsed);   fprintf(stderr, "\tTMU: %ld\n", ti->whichTMU);   fprintf(stderr, "\t%s\n", (ti->isInTM) ? "In TMU" : "Not in TMU");   if (ti->tm[0])      fprintf(stderr, "\tMem0: %x-%x\n", (unsigned) ti->tm[0]->startAddr,	      (unsigned) ti->tm[0]->endAddr);   if (ti->tm[1])      fprintf(stderr, "\tMem1: %x-%x\n", (unsigned) ti->tm[1]->startAddr,	      (unsigned) ti->tm[1]->endAddr);   fprintf(stderr, "\tMipmaps: %d-%d\n", ti->minLevel, ti->maxLevel);   fprintf(stderr, "\tFilters: min %d max %d\n",	   (int) ti->minFilt, (int) ti->maxFilt);   fprintf(stderr, "\tClamps: s %d t %d\n", (int) ti->sClamp,	   (int) ti->tClamp);   fprintf(stderr, "\tScales: s %f t %f\n", ti->sScale, ti->tScale);   fprintf(stderr, "\t%s\n",	   (ti->fixedPalette) ? "Fixed palette" : "Non fixed palette");   fprintf(stderr, "\t%s\n", (ti->validated) ? "Validated" : "Not validated");}/************************************************************************//*************************** Texture Mapping ****************************//************************************************************************/static voidfxTexInvalidate(GLcontext * ctx, struct gl_texture_object *tObj){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   tfxTexInfo *ti;   ti = fxTMGetTexInfo(tObj);   if (ti->isInTM)      fxTMMoveOutTM(fxMesa, tObj);	/* TO DO: SLOW but easy to write */   ti->validated = GL_FALSE;   fxMesa->new_state |= FX_NEW_TEXTURING;}static tfxTexInfo *fxAllocTexObjData(fxMesaContext fxMesa){   tfxTexInfo *ti;   if (!(ti = CALLOC(sizeof(tfxTexInfo)))) {      fprintf(stderr, "fxAllocTexObjData: ERROR: out of memory !\n");      fxCloseHardware();      exit(-1);   }   ti->validated = GL_FALSE;   ti->isInTM = GL_FALSE;   ti->whichTMU = FX_TMU_NONE;   ti->tm[FX_TMU0] = NULL;   ti->tm[FX_TMU1] = NULL;   ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;   ti->maxFilt = GR_TEXTUREFILTER_BILINEAR;   ti->sClamp = GR_TEXTURECLAMP_WRAP;   ti->tClamp = GR_TEXTURECLAMP_WRAP;   ti->mmMode = GR_MIPMAP_NEAREST;   ti->LODblend = FXFALSE;   return ti;}voidfxDDTexBind(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   tfxTexInfo *ti;   if (TDFX_DEBUG & VERBOSE_DRIVER) {      fprintf(stderr, "fxDDTexBind(%d, %x)\n", tObj->Name, (GLuint)tObj->DriverData);   }   if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))      return;   if (!tObj->DriverData) {      tObj->DriverData = fxAllocTexObjData(fxMesa);   }   ti = fxTMGetTexInfo(tObj);   fxMesa->texBindNumber++;   ti->lastTimeUsed = fxMesa->texBindNumber;   fxMesa->new_state |= FX_NEW_TEXTURING;}voidfxDDTexEnv(GLcontext * ctx, GLenum target, GLenum pname,	   const GLfloat * param){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   if (TDFX_DEBUG & VERBOSE_DRIVER) {      if (param)	 fprintf(stderr, "fxDDTexEnv(%x, %x)\n", pname, (GLint) (*param));      else	 fprintf(stderr, "fxDDTexEnv(%x)\n", pname);   }   /* apply any lod biasing right now */   if (pname == GL_TEXTURE_LOD_BIAS_EXT) {      GLfloat bias = *param;      CLAMP_SELF(bias, -ctx->Const.MaxTextureLodBias,                        ctx->Const.MaxTextureLodBias - 0.25);      grTexLodBiasValue(GR_TMU0, bias);      if (fxMesa->haveTwoTMUs) {	 grTexLodBiasValue(GR_TMU1, bias);      }   }   fxMesa->new_state |= FX_NEW_TEXTURING;}voidfxDDTexParam(GLcontext * ctx, GLenum target, struct gl_texture_object *tObj,	     GLenum pname, const GLfloat * params){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   GLenum param = (GLenum) (GLint) params[0];   tfxTexInfo *ti;   if (TDFX_DEBUG & VERBOSE_DRIVER) {      fprintf(stderr, "fxDDTexParam(%d, %x, %s, %s)\n",                      tObj->Name, (GLuint) tObj->DriverData,                      _mesa_lookup_enum_by_nr(pname),                      _mesa_lookup_enum_by_nr(param));   }   if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))      return;   if (!tObj->DriverData)      tObj->DriverData = fxAllocTexObjData(fxMesa);   ti = fxTMGetTexInfo(tObj);   switch (pname) {   case GL_TEXTURE_MIN_FILTER:      switch (param) {      case GL_NEAREST:	 ti->mmMode = GR_MIPMAP_DISABLE;	 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;	 ti->LODblend = FXFALSE;	 break;      case GL_LINEAR:	 ti->mmMode = GR_MIPMAP_DISABLE;	 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;	 ti->LODblend = FXFALSE;	 break;      case GL_NEAREST_MIPMAP_LINEAR:         /* [dBorca]          * currently Napalm can't do single-pass trilinear,          * because the way its combiners are set. So we fall back          * to GL_NEAREST_MIPMAP_NEAREST. We'll let true trilinear          * enabled for V2, V3.          */         if (!fxMesa->HaveCmbExt) {	    if (fxMesa->haveTwoTMUs) {	       ti->mmMode = GR_MIPMAP_NEAREST;	       ti->LODblend = FXTRUE;            } else {	       ti->mmMode = GR_MIPMAP_NEAREST_DITHER;	       ti->LODblend = FXFALSE;            }	    ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;	    break;         }      case GL_NEAREST_MIPMAP_NEAREST:	 ti->mmMode = GR_MIPMAP_NEAREST;	 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;	 ti->LODblend = FXFALSE;	 break;      case GL_LINEAR_MIPMAP_LINEAR:         /* [dBorca]          * currently Napalm can't do single-pass trilinear,          * because the way its combiners are set. So we fall back          * to GL_LINEAR_MIPMAP_NEAREST. We'll let true trilinear          * enabled for V2, V3.          */         if (!fxMesa->HaveCmbExt) {            if (fxMesa->haveTwoTMUs) {               ti->mmMode = GR_MIPMAP_NEAREST;               ti->LODblend = FXTRUE;            } else {               ti->mmMode = GR_MIPMAP_NEAREST_DITHER;               ti->LODblend = FXFALSE;            }            ti->minFilt = GR_TEXTUREFILTER_BILINEAR;            break;         }      case GL_LINEAR_MIPMAP_NEAREST:	 ti->mmMode = GR_MIPMAP_NEAREST;	 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;	 ti->LODblend = FXFALSE;	 break;      default:	 break;      }      fxTexInvalidate(ctx, tObj);      break;   case GL_TEXTURE_MAG_FILTER:      switch (param) {      case GL_NEAREST:	 ti->maxFilt = GR_TEXTUREFILTER_POINT_SAMPLED;	 break;      case GL_LINEAR:	 ti->maxFilt = GR_TEXTUREFILTER_BILINEAR;	 break;      default:	 break;      }      fxMesa->new_state |= FX_NEW_TEXTURING;      break;   case GL_TEXTURE_WRAP_S:      switch (param) {      case GL_MIRRORED_REPEAT:         ti->sClamp = GR_TEXTURECLAMP_MIRROR_EXT;         break;      case GL_CLAMP_TO_BORDER: /* no-no, but don't REPEAT, either */      case GL_CLAMP_TO_EDGE: /* CLAMP discarding border */      case GL_CLAMP:	 ti->sClamp = GR_TEXTURECLAMP_CLAMP;	 break;      case GL_REPEAT:	 ti->sClamp = GR_TEXTURECLAMP_WRAP;	 break;      default:	 break;      }      fxMesa->new_state |= FX_NEW_TEXTURING;      break;   case GL_TEXTURE_WRAP_T:      switch (param) {      case GL_MIRRORED_REPEAT:         ti->tClamp = GR_TEXTURECLAMP_MIRROR_EXT;         break;      case GL_CLAMP_TO_BORDER: /* no-no, but don't REPEAT, either */      case GL_CLAMP_TO_EDGE: /* CLAMP discarding border */      case GL_CLAMP:	 ti->tClamp = GR_TEXTURECLAMP_CLAMP;	 break;      case GL_REPEAT:	 ti->tClamp = GR_TEXTURECLAMP_WRAP;	 break;      default:	 break;      }      fxMesa->new_state |= FX_NEW_TEXTURING;      break;   case GL_TEXTURE_BORDER_COLOR:      /* TO DO */      break;   case GL_TEXTURE_MIN_LOD:      /* TO DO */      break;   case GL_TEXTURE_MAX_LOD:      /* TO DO */      break;   case GL_TEXTURE_BASE_LEVEL:      fxTexInvalidate(ctx, tObj);      break;   case GL_TEXTURE_MAX_LEVEL:      fxTexInvalidate(ctx, tObj);      break;   default:      break;   }}voidfxDDTexDel(GLcontext * ctx, struct gl_texture_object *tObj){   fxMesaContext fxMesa = FX_CONTEXT(ctx);   tfxTexInfo *ti = fxTMGetTexInfo(tObj);   if (TDFX_DEBUG & VERBOSE_DRIVER) {      fprintf(stderr, "fxDDTexDel(%d, %p)\n", tObj->Name, (void *) ti);   }   if (!ti)      return;

⌨️ 快捷键说明

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