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

📄 s_texsample.h

📁 mesa-6.5-minigui源码
💻 H
📖 第 1 页 / 共 2 页
字号:
         rgba[GCOMP] = palette[index * 3 + 1];         rgba[BCOMP] = palette[index * 3 + 2];         return;      case GL_RGBA:         rgba[RCOMP] = palette[(index << 2) + 0];         rgba[GCOMP] = palette[(index << 2) + 1];         rgba[BCOMP] = palette[(index << 2) + 2];         rgba[ACOMP] = palette[(index << 2) + 3];         return;      default:         _mesa_problem(ctx, "Bad palette format in palette_sample");   }}#endif/**********************************************************************//*                    1-D Texture Sampling Functions                  *//**********************************************************************//* * Return the texture sample for coordinate (s) using GL_NEAREST filter. */static voidsample_1d_nearest(GLcontext *ctx,                  const struct gl_texture_object *tObj,                  const struct gl_texture_image *img,                  const GLfloat texcoord[4], TYPE rgba[4]){   const GLint width = img->Width2;  /* without border */   GLint i;   COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapS, texcoord[0], width, i);   /* skip over the border, if any */   i += img->Border;   if (i < 0 || i >= (GLint) img->Width) {      /* Need this test for GL_CLAMP_TO_BORDER mode */#if TYPE_ENUM == GL_FLOAT      COPY_4V(rgba, tObj->BorderColor);#else      COPY_CHAN4(rgba, tObj->_BorderChan);#endif         }   else {#if TYPE_ENUM == GL_FLOAT      img->FetchTexelf(img, i, 0, 0, rgba);#else      img->FetchTexelc(img, i, 0, 0, rgba);#endif      if (img->Format == GL_COLOR_INDEX) {         palette_sample(ctx, tObj, rgba[0], rgba);      }   }}/* * Return the texture sample for coordinate (s) using GL_LINEAR filter. */static voidsample_1d_linear(GLcontext *ctx,                 const struct gl_texture_object *tObj,                 const struct gl_texture_image *img,                 const GLfloat texcoord[4], GLchan rgba[4]){   const GLint width = img->Width2;   GLint i0, i1;   GLfloat u;   GLuint useBorderColor;   COMPUTE_LINEAR_TEXEL_LOCATIONS(tObj->WrapS, texcoord[0], u, width, i0, i1);   useBorderColor = 0;   if (img->Border) {      i0 += img->Border;      i1 += img->Border;   }   else {      if (i0 < 0 || i0 >= width)   useBorderColor |= I0BIT;      if (i1 < 0 || i1 >= width)   useBorderColor |= I1BIT;   }   {      const GLfloat a = FRAC(u);#if CHAN_TYPE == GL_FLOAT || CHAN_TYPE == GL_UNSIGNED_SHORT      const GLfloat w0 = (1.0F-a);      const GLfloat w1 =       a ;#else /* CHAN_BITS == 8 */      /* compute sample weights in fixed point in [0,WEIGHT_SCALE] */      const GLint w0 = IROUND_POS((1.0F - a) * WEIGHT_SCALE);      const GLint w1 = IROUND_POS(        a  * WEIGHT_SCALE);#endif      GLchan t0[4], t1[4];  /* texels */      if (useBorderColor & I0BIT) {         COPY_CHAN4(t0, tObj->_BorderChan);      }      else {         img->FetchTexelc(img, i0, 0, 0, t0);         if (img->Format == GL_COLOR_INDEX) {            palette_sample(ctx, tObj, t0[0], t0);         }      }      if (useBorderColor & I1BIT) {         COPY_CHAN4(t1, tObj->_BorderChan);      }      else {         img->FetchTexelc(img, i1, 0, 0, t1);         if (img->Format == GL_COLOR_INDEX) {            palette_sample(ctx, tObj, t1[0], t1);         }      }#if CHAN_TYPE == GL_FLOAT      rgba[0] = w0 * t0[0] + w1 * t1[0];      rgba[1] = w0 * t0[1] + w1 * t1[1];      rgba[2] = w0 * t0[2] + w1 * t1[2];      rgba[3] = w0 * t0[3] + w1 * t1[3];#elif CHAN_TYPE == GL_UNSIGNED_SHORT      rgba[0] = (GLchan) (w0 * t0[0] + w1 * t1[0] + 0.5);      rgba[1] = (GLchan) (w0 * t0[1] + w1 * t1[1] + 0.5);      rgba[2] = (GLchan) (w0 * t0[2] + w1 * t1[2] + 0.5);      rgba[3] = (GLchan) (w0 * t0[3] + w1 * t1[3] + 0.5);#else /* CHAN_BITS == 8 */      rgba[0] = (GLchan) ((w0 * t0[0] + w1 * t1[0]) >> WEIGHT_SHIFT);      rgba[1] = (GLchan) ((w0 * t0[1] + w1 * t1[1]) >> WEIGHT_SHIFT);      rgba[2] = (GLchan) ((w0 * t0[2] + w1 * t1[2]) >> WEIGHT_SHIFT);      rgba[3] = (GLchan) ((w0 * t0[3] + w1 * t1[3]) >> WEIGHT_SHIFT);#endif   }}static voidsample_1d_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++) {      GLint level;      COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda[i], level);      sample_1d_nearest(ctx, tObj, tObj->Image[0][level], texcoord[i], rgba[i]);   }}static voidsample_1d_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++) {      GLint level;      COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda[i], level);      sample_1d_linear(ctx, tObj, tObj->Image[0][level], texcoord[i], rgba[i]);   }}/* * This is really just needed in order to prevent warnings with some compilers. */#if CHAN_TYPE == GL_FLOAT#define CHAN_CAST#else#define CHAN_CAST (GLchan) (GLint)#endifstatic voidsample_1d_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++) {      GLint level;      COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda[i], level);      if (level >= tObj->_MaxLevel) {         sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->_MaxLevel],                           texcoord[i], rgba[i]);      }      else {         GLchan t0[4], t1[4];         const GLfloat f = FRAC(lambda[i]);         sample_1d_nearest(ctx, tObj, tObj->Image[0][level  ], texcoord[i], t0);         sample_1d_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1);         rgba[i][RCOMP] = CHAN_CAST ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);         rgba[i][GCOMP] = CHAN_CAST ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]);         rgba[i][BCOMP] = CHAN_CAST ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]);         rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]);      }   }}static voidsample_1d_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++) {      GLint level;      COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda[i], level);      if (level >= tObj->_MaxLevel) {         sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->_MaxLevel],                          texcoord[i], rgba[i]);      }      else {         GLchan t0[4], t1[4];         const GLfloat f = FRAC(lambda[i]);         sample_1d_linear(ctx, tObj, tObj->Image[0][level  ], texcoord[i], t0);         sample_1d_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1);         rgba[i][RCOMP] = CHAN_CAST ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);         rgba[i][GCOMP] = CHAN_CAST ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]);         rgba[i][BCOMP] = CHAN_CAST ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]);         rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]);      }   }}static voidsample_nearest_1d( GLcontext *ctx, GLuint texUnit,                   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_1d_nearest(ctx, tObj, image, texcoords[i], rgba[i]);   }}static voidsample_linear_1d( GLcontext *ctx, GLuint texUnit,                  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_1d_linear(ctx, tObj, image, texcoords[i], rgba[i]);   }}/* * Given an (s) texture coordinate and lambda (level of detail) value, * return a texture sample. * */static voidsample_lambda_1d( GLcontext *ctx, GLuint texUnit,                  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(SWRAST_CONTEXT(ctx)->_MinMagThresh[texUnit],                          n, lambda, &minStart, &minEnd, &magStart, &magEnd);   if (minStart < minEnd) {      /* do the minified texels */      const GLuint m = minEnd - minStart;      switch (tObj->MinFilter) {      case GL_NEAREST:         for (i = minStart; i < minEnd; i++)            sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                              texcoords[i], rgba[i]);         break;      case GL_LINEAR:         for (i = minStart; i < minEnd; i++)            sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                             texcoords[i], rgba[i]);         break;      case GL_NEAREST_MIPMAP_NEAREST:         sample_1d_nearest_mipmap_nearest(ctx, tObj, m, texcoords + minStart,                                          lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_NEAREST:         sample_1d_linear_mipmap_nearest(ctx, tObj, m, texcoords + minStart,                                         lambda + minStart, rgba + minStart);         break;      case GL_NEAREST_MIPMAP_LINEAR:         sample_1d_nearest_mipmap_linear(ctx, tObj, m, texcoords + minStart,                                         lambda + minStart, rgba + minStart);         break;      case GL_LINEAR_MIPMAP_LINEAR:         sample_1d_linear_mipmap_linear(ctx, tObj, m, texcoords + minStart,                                        lambda + minStart, rgba + minStart);         break;      default:         _mesa_problem(ctx, "Bad min filter in sample_1d_texture");         return;      }   }   if (magStart < magEnd) {      /* do the magnified texels */      switch (tObj->MagFilter) {      case GL_NEAREST:         for (i = magStart; i < magEnd; i++)            sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                              texcoords[i], rgba[i]);         break;      case GL_LINEAR:         for (i = magStart; i < magEnd; i++)            sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],                             texcoords[i], rgba[i]);         break;      default:         _mesa_problem(ctx, "Bad mag filter in sample_1d_texture");         return;      }   }}

⌨️ 快捷键说明

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