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

📄 s_texfilter.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 5 页
字号:
   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];   (void) lambda;   for (i=0;i<n;i++) {      sample_3d_nearest(ctx, tObj, image, texcoords[i], rgba[i]);   }}static voidsample_linear_3d( GLcontext *ctx,                  const struct gl_texture_object *tObj, GLuint n,                  const GLfloat texcoords[][4],		  const GLfloat lambda[], GLchan rgba[][4] ){   GLuint i;   struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];   (void) lambda;   for (i=0;i<n;i++) {      sample_3d_linear(ctx, tObj, image, texcoords[i], rgba[i]);   }}/* * Given an (s,t,r) texture coordinate and lambda (level of detail) value, * return a texture sample. */static voidsample_lambda_3d( GLcontext *ctx,                  const struct gl_texture_object *tObj, GLuint n,                  const GLfloat texcoords[][4], const GLfloat lambda[],                  GLchan rgba[][4] ){   GLuint minStart, minEnd;  /* texels with minification */   GLuint magStart, magEnd;  /* texels with magnification */   GLuint i;   ASSERT(lambda != NULL);   compute_min_mag_ranges(tObj, n, lambda,                          &minStart, &minEnd, &magStart, &magEnd);   if (minStart < minEnd) {      /* do the minified texels */      GLuint m = minEnd - minStart;      switch (tObj->MinFilter) {      case GL_NEAREST:         for (i = minStart; i < minEnd; i++)            sample_3d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                              texcoords[i], rgba[i]);         break;      case GL_LINEAR:         for (i = minStart; i < minEnd; i++)            sample_3d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                             texcoords[i], rgba[i]);         break;      case GL_NEAREST_MIPMAP_NEAREST:         sample_3d_nearest_mipmap_nearest(ctx, tObj, m, texcoords + minStart,                                          lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_NEAREST:         sample_3d_linear_mipmap_nearest(ctx, tObj, m, texcoords + minStart,                                         lambda + minStart, rgba + minStart);         break;      case GL_NEAREST_MIPMAP_LINEAR:         sample_3d_nearest_mipmap_linear(ctx, tObj, m, texcoords + minStart,                                         lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_LINEAR:         sample_3d_linear_mipmap_linear(ctx, tObj, m, texcoords + minStart,                                        lambda + minStart, rgba + minStart);         break;      default:         _mesa_problem(ctx, "Bad min filter in sample_3d_texture");         return;      }   }   if (magStart < magEnd) {      /* do the magnified texels */      switch (tObj->MagFilter) {      case GL_NEAREST:         for (i = magStart; i < magEnd; i++)            sample_3d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                              texcoords[i], rgba[i]);         break;      case GL_LINEAR:         for (i = magStart; i < magEnd; i++)            sample_3d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                             texcoords[i], rgba[i]);         break;      default:         _mesa_problem(ctx, "Bad mag filter in sample_3d_texture");         return;      }   }}/**********************************************************************//*                Texture Cube Map Sampling Functions                 *//**********************************************************************//** * Choose one of six sides of a texture cube map given the texture * coord (rx,ry,rz).  Return pointer to corresponding array of texture * images. */static const struct gl_texture_image **choose_cube_face(const struct gl_texture_object *texObj,                 const GLfloat texcoord[4], GLfloat newCoord[4]){   /*      major axis      direction     target                             sc     tc    ma      ----------    -------------------------------    ---    ---   ---       +rx          TEXTURE_CUBE_MAP_POSITIVE_X_EXT    -rz    -ry   rx       -rx          TEXTURE_CUBE_MAP_NEGATIVE_X_EXT    +rz    -ry   rx       +ry          TEXTURE_CUBE_MAP_POSITIVE_Y_EXT    +rx    +rz   ry       -ry          TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT    +rx    -rz   ry       +rz          TEXTURE_CUBE_MAP_POSITIVE_Z_EXT    +rx    -ry   rz       -rz          TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT    -rx    -ry   rz   */   const GLfloat rx = texcoord[0];   const GLfloat ry = texcoord[1];   const GLfloat rz = texcoord[2];   const GLfloat arx = FABSF(rx), ary = FABSF(ry), arz = FABSF(rz);   GLuint face;   GLfloat sc, tc, ma;   if (arx > ary && arx > arz) {      if (rx >= 0.0F) {         face = FACE_POS_X;         sc = -rz;         tc = -ry;         ma = arx;      }      else {         face = FACE_NEG_X;         sc = rz;         tc = -ry;         ma = arx;      }   }   else if (ary > arx && ary > arz) {      if (ry >= 0.0F) {         face = FACE_POS_Y;         sc = rx;         tc = rz;         ma = ary;      }      else {         face = FACE_NEG_Y;         sc = rx;         tc = -rz;         ma = ary;      }   }   else {      if (rz > 0.0F) {         face = FACE_POS_Z;         sc = rx;         tc = -ry;         ma = arz;      }      else {         face = FACE_NEG_Z;         sc = -rx;         tc = -ry;         ma = arz;      }   }   newCoord[0] = ( sc / ma + 1.0F ) * 0.5F;   newCoord[1] = ( tc / ma + 1.0F ) * 0.5F;   return (const struct gl_texture_image **) texObj->Image[face];}static voidsample_nearest_cube(GLcontext *ctx,		    const struct gl_texture_object *tObj, GLuint n,                    const GLfloat texcoords[][4], const GLfloat lambda[],                    GLchan rgba[][4]){   GLuint i;   (void) lambda;   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      images = choose_cube_face(tObj, texcoords[i], newCoord);      sample_2d_nearest(ctx, tObj, images[tObj->BaseLevel],                        newCoord, rgba[i]);   }}static voidsample_linear_cube(GLcontext *ctx,		   const struct gl_texture_object *tObj, GLuint n,                   const GLfloat texcoords[][4],		   const GLfloat lambda[], GLchan rgba[][4]){   GLuint i;   (void) lambda;   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      images = choose_cube_face(tObj, texcoords[i], newCoord);      sample_2d_linear(ctx, tObj, images[tObj->BaseLevel],                       newCoord, rgba[i]);   }}static voidsample_cube_nearest_mipmap_nearest(GLcontext *ctx,                                   const struct gl_texture_object *tObj,                                   GLuint n, const GLfloat texcoord[][4],                                   const GLfloat lambda[], GLchan rgba[][4]){   GLuint i;   ASSERT(lambda != NULL);   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      GLint level = nearest_mipmap_level(tObj, lambda[i]);      images = choose_cube_face(tObj, texcoord[i], newCoord);      sample_2d_nearest(ctx, tObj, images[level], newCoord, rgba[i]);   }}static voidsample_cube_linear_mipmap_nearest(GLcontext *ctx,                                  const struct gl_texture_object *tObj,                                  GLuint n, const GLfloat texcoord[][4],                                  const GLfloat lambda[], GLchan rgba[][4]){   GLuint i;   ASSERT(lambda != NULL);   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      GLint level = nearest_mipmap_level(tObj, lambda[i]);      images = choose_cube_face(tObj, texcoord[i], newCoord);      sample_2d_linear(ctx, tObj, images[level], newCoord, rgba[i]);   }}static voidsample_cube_nearest_mipmap_linear(GLcontext *ctx,                                  const struct gl_texture_object *tObj,                                  GLuint n, const GLfloat texcoord[][4],                                  const GLfloat lambda[], GLchan rgba[][4]){   GLuint i;   ASSERT(lambda != NULL);   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      GLint level = linear_mipmap_level(tObj, lambda[i]);      images = choose_cube_face(tObj, texcoord[i], newCoord);      if (level >= tObj->_MaxLevel) {         sample_2d_nearest(ctx, tObj, images[tObj->_MaxLevel],                           newCoord, rgba[i]);      }      else {         GLchan t0[4], t1[4];  /* texels */         const GLfloat f = FRAC(lambda[i]);         sample_2d_nearest(ctx, tObj, images[level  ], newCoord, t0);         sample_2d_nearest(ctx, tObj, images[level+1], newCoord, t1);         lerp_rgba(rgba[i], f, t0, t1);      }   }}static voidsample_cube_linear_mipmap_linear(GLcontext *ctx,                                 const struct gl_texture_object *tObj,                                 GLuint n, const GLfloat texcoord[][4],                                 const GLfloat lambda[], GLchan rgba[][4]){   GLuint i;   ASSERT(lambda != NULL);   for (i = 0; i < n; i++) {      const struct gl_texture_image **images;      GLfloat newCoord[4];      GLint level = linear_mipmap_level(tObj, lambda[i]);      images = choose_cube_face(tObj, texcoord[i], newCoord);      if (level >= tObj->_MaxLevel) {         sample_2d_linear(ctx, tObj, images[tObj->_MaxLevel],                          newCoord, rgba[i]);      }      else {         GLchan t0[4], t1[4];         const GLfloat f = FRAC(lambda[i]);         sample_2d_linear(ctx, tObj, images[level  ], newCoord, t0);         sample_2d_linear(ctx, tObj, images[level+1], newCoord, t1);         lerp_rgba(rgba[i], f, t0, t1);      }   }}static voidsample_lambda_cube( GLcontext *ctx,		    const struct gl_texture_object *tObj, GLuint n,		    const GLfloat texcoords[][4], const GLfloat lambda[],		    GLchan rgba[][4]){   GLuint minStart, minEnd;  /* texels with minification */   GLuint magStart, magEnd;  /* texels with magnification */   ASSERT(lambda != NULL);   compute_min_mag_ranges(tObj, n, lambda,                          &minStart, &minEnd, &magStart, &magEnd);   if (minStart < minEnd) {      /* do the minified texels */      const GLuint m = minEnd - minStart;      switch (tObj->MinFilter) {      case GL_NEAREST:         sample_nearest_cube(ctx, tObj, m, texcoords + minStart,                             lambda + minStart, rgba + minStart);         break;      case GL_LINEAR:         sample_linear_cube(ctx, tObj, m, texcoords + minStart,                            lambda + minStart, rgba + minStart);         break;      case GL_NEAREST_MIPMAP_NEAREST:         sample_cube_nearest_mipmap_nearest(ctx, tObj, m,                                            texcoords + minStart,                                           lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_NEAREST:         sample_cube_linear_mipmap_nearest(ctx, tObj, m,                                           texcoords + minStart,                                           lambda + minStart, rgba + minStart);         break;      case GL_NEAREST_MIPMAP_LINEAR:         sample_cube_nearest_mipmap_linear(ctx, tObj, m,                                           texcoords + minStart,                                           lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_LINEAR:         sample_cube_linear_mipmap_linear(ctx, tObj, m,                                          texcoords + minStart,                                          lambda + minStart, rgba + minStart);         break;      default:         _mesa_problem(ctx, "Bad min filter in sample_lambda_cube");      }   }   if (magStart < magEnd) {      /* do the magnified texels */      const GLuint m = magEnd - magStart;      switch (tObj->MagFilter) {      case GL_NEAREST:         sample_nearest_cube(ctx, tObj, m, texcoords + magStart,                             lambda + magStart, rgba + magStart);         break;      case GL_LINEAR:         sample_linear_cube(ctx, tObj, m, texcoords + magStart,                            lambda + magStart, rgba + magStart);         break;      default:         _mesa_problem(ctx, "Bad mag filter in sample_lambda_cube");      }   }}/**********************************************************************//*               Texture Rectangle Sampling Functions                 *//**********************************************************************/static voidsample_nearest_rect(GLcontext *ctx,		    const struct gl_texture_object *tObj, GLuint n,                    const GLfloat texcoords[][4], const GLfloat lambda[],                    GLchan rgba[][4]){   const struct gl_texture_image *img = tObj->Image[0][0];   const GLfloat width = (GLfloat) img->Width;   const GLfloat height = (GLfloat) img->Height;   const GLint width_minus_1 = img->Width - 1;   const GLint height_minus_1 = img->Height - 1;   GLuint i;   (void) ctx;   (void) lambda;   ASSERT(tObj->WrapS == GL_CLAMP ||          tObj->WrapS == GL_CLAMP_TO_EDGE ||          tObj->WrapS == GL_CLAMP_TO_BORDER);   ASSERT(tObj->WrapT == GL_CLAMP ||          tObj->WrapT == GL_CLAMP_TO_EDGE ||          tObj->WrapT == GL_CLAMP_TO_BORDER);   ASSERT(img->_BaseFormat != GL_COLOR_INDEX);   /* XXX move Wrap mode tests outside of loops for common cases */   for (i = 0; i < n; i++) {      GLint row, col;      /* NOTE: we DO NOT use [0, 1

⌨️ 快捷键说明

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