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

📄 texformat_tmp.h

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 H
📖 第 1 页 / 共 4 页
字号:
/* MESA_FORMAT_CI8 ***********************************************************//* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a * color table, and return 4 GLchans. */static void FETCH(ci8)( const struct gl_texture_image *texImage,			GLint i, GLint j, GLint k, GLchan *texel ){   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);   const struct gl_color_table *palette;   GLubyte texelUB[4];   GLuint index;   GET_CURRENT_CONTEXT(ctx);   if (ctx->Texture.SharedPalette) {      palette = &ctx->Texture.Palette;   }   else {      palette = &texImage->TexObject->Palette;   }   if (palette->Size == 0)      return; /* undefined results */   /* Mask the index against size of palette to avoid going out of bounds */   index = (*src) & (palette->Size - 1);   {      const GLubyte *table = palette->TableUB;      switch (palette->_BaseFormat) {      case GL_ALPHA:         texelUB[RCOMP] =         texelUB[GCOMP] =         texelUB[BCOMP] = 0;         texelUB[ACOMP] = table[index];         break;;      case GL_LUMINANCE:         texelUB[RCOMP] =         texelUB[GCOMP] =         texelUB[BCOMP] = table[index];         texelUB[ACOMP] = 255;         break;      case GL_INTENSITY:         texelUB[RCOMP] =         texelUB[GCOMP] =         texelUB[BCOMP] =         texelUB[ACOMP] = table[index];         break;;      case GL_LUMINANCE_ALPHA:         texelUB[RCOMP] =         texelUB[GCOMP] =         texelUB[BCOMP] = table[index * 2 + 0];         texelUB[ACOMP] = table[index * 2 + 1];         break;;      case GL_RGB:         texelUB[RCOMP] = table[index * 3 + 0];         texelUB[GCOMP] = table[index * 3 + 1];         texelUB[BCOMP] = table[index * 3 + 2];         texelUB[ACOMP] = 255;         break;;      case GL_RGBA:         texelUB[RCOMP] = table[index * 4 + 0];         texelUB[GCOMP] = table[index * 4 + 1];         texelUB[BCOMP] = table[index * 4 + 2];         texelUB[ACOMP] = table[index * 4 + 3];         break;;      default:         _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");         return;      }#if CHAN_TYPE == GL_UNSIGNED_BYTE      COPY_4UBV(texel, texelUB);#elif CHAN_TYPE == GL_UNSIGNED_SHORT      texel[0] = UBYTE_TO_USHORT(texelUB[0]);      texel[1] = UBYTE_TO_USHORT(texelUB[1]);      texel[2] = UBYTE_TO_USHORT(texelUB[2]);      texel[3] = UBYTE_TO_USHORT(texelUB[3]);#else      texel[0] = UBYTE_TO_FLOAT(texelUB[0]);      texel[1] = UBYTE_TO_FLOAT(texelUB[1]);      texel[2] = UBYTE_TO_FLOAT(texelUB[2]);      texel[3] = UBYTE_TO_FLOAT(texelUB[3]);#endif   }}#if DIM == 3static void store_texel_ci8(struct gl_texture_image *texImage,                            GLint i, GLint j, GLint k, const void *texel){   const GLubyte *index = (const GLubyte *) texel;   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);   *dst = *index;}#endif#if FEATURE_EXT_texture_sRGB/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */static void FETCH(srgb8)(const struct gl_texture_image *texImage,                         GLint i, GLint j, GLint k, GLfloat *texel ){   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);   texel[RCOMP] = nonlinear_to_linear(src[0]);   texel[GCOMP] = nonlinear_to_linear(src[1]);   texel[BCOMP] = nonlinear_to_linear(src[2]);   texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_srgb8(struct gl_texture_image *texImage,                              GLint i, GLint j, GLint k, const void *texel){   const GLubyte *rgba = (const GLubyte *) texel;   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);   dst[0] = rgba[RCOMP]; /* no conversion */   dst[1] = rgba[GCOMP];   dst[2] = rgba[BCOMP];}#endif/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */static void FETCH(srgba8)(const struct gl_texture_image *texImage,                          GLint i, GLint j, GLint k, GLfloat *texel ){   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);   texel[RCOMP] = nonlinear_to_linear(src[0]);   texel[GCOMP] = nonlinear_to_linear(src[1]);   texel[BCOMP] = nonlinear_to_linear(src[2]);   texel[ACOMP] = UBYTE_TO_FLOAT(src[3]); /* linear! */}#if DIM == 3static void store_texel_srgba8(struct gl_texture_image *texImage,                               GLint i, GLint j, GLint k, const void *texel){   const GLubyte *rgba = (const GLubyte *) texel;   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);   dst[0] = rgba[RCOMP];   dst[1] = rgba[GCOMP];   dst[2] = rgba[BCOMP];}#endif/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */static void FETCH(sl8)(const struct gl_texture_image *texImage,                       GLint i, GLint j, GLint k, GLfloat *texel ){   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);   texel[RCOMP] =    texel[GCOMP] =    texel[BCOMP] = nonlinear_to_linear(src[0]);   texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_sl8(struct gl_texture_image *texImage,                            GLint i, GLint j, GLint k, const void *texel){   const GLubyte *rgba = (const GLubyte *) texel;   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);   dst[0] = rgba[RCOMP];}#endif/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */static void FETCH(sla8)(const struct gl_texture_image *texImage,                       GLint i, GLint j, GLint k, GLfloat *texel ){   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);   texel[RCOMP] =   texel[GCOMP] =   texel[BCOMP] = nonlinear_to_linear(src[0]);   texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */}#if DIM == 3static void store_texel_sla8(struct gl_texture_image *texImage,                            GLint i, GLint j, GLint k, const void *texel){   const GLubyte *rgba = (const GLubyte *) texel;   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);   dst[0] = rgba[RCOMP];   dst[1] = rgba[ACOMP];}#endif#endif /* FEATURE_EXT_texture_sRGB *//* MESA_FORMAT_YCBCR *********************************************************//* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans *//* We convert YCbCr to RGB here *//* XXX this may break if GLchan != GLubyte */static void FETCH(ycbcr)( const struct gl_texture_image *texImage,                          GLint i, GLint j, GLint k, GLchan *texel ){   const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */   const GLushort *src1 = src0 + 1;                               /* odd */   const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */   const GLubyte cb = *src0 & 0xff;         /* chroma U */   const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */   const GLubyte cr = *src1 & 0xff;         /* chroma V */   GLint r, g, b;   if (i & 1) {      /* odd pixel: use y1,cr,cb */      r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));      g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));      b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));   }   else {      /* even pixel: use y0,cr,cb */      r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));      g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));      b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));   }   texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);   texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);   texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);   texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_ycbcr(struct gl_texture_image *texImage,                              GLint i, GLint j, GLint k, const void *texel){   (void) texImage;   (void) i;   (void) j;   (void) k;   (void) texel;   /* XXX to do */}#endif/* MESA_FORMAT_YCBCR_REV *****************************************************//* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans *//* We convert YCbCr to RGB here *//* XXX this may break if GLchan != GLubyte */static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,                              GLint i, GLint j, GLint k, GLchan *texel ){   const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */   const GLushort *src1 = src0 + 1;                               /* odd */   const GLubyte y0 = *src0 & 0xff;         /* luminance */   const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */   const GLubyte y1 = *src1 & 0xff;         /* luminance */   const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */   GLint r, g, b;   if (i & 1) {      /* odd pixel: use y1,cr,cb */      r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));      g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));      b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));   }   else {      /* even pixel: use y0,cr,cb */      r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));      g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));      b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));   }   texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);   texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);   texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);   texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,                                  GLint i, GLint j, GLint k, const void *texel){   (void) texImage;   (void) i;   (void) j;   (void) k;   (void) texel;   /* XXX to do */}#endif/* MESA_TEXFORMAT_Z24_S8 ***************************************************/static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,                             GLint i, GLint j, GLint k, GLfloat *texel ){   /* only return Z, not stencil data */   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;   texel[0] = ((*src) >> 8) * scale;   ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8);   ASSERT(texel[0] >= 0.0F);   ASSERT(texel[0] <= 1.0F);}#if DIM == 3static void store_texel_z24_s8(struct gl_texture_image *texImage,                               GLint i, GLint j, GLint k, const void *texel){   /* only store Z, not stencil */   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);   GLfloat depth = *((GLfloat *) texel);   GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;   *dst = zi | (*dst & 0xff);}#endif/* MESA_TEXFORMAT_S8_Z24 ***************************************************/static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,                             GLint i, GLint j, GLint k, GLfloat *texel ){   /* only return Z, not stencil data */   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;   texel[0] = ((*src) & 0x00ffffff) * scale;   ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_S8_Z24);   ASSERT(texel[0] >= 0.0F);   ASSERT(texel[0] <= 1.0F);}#if DIM == 3static void store_texel_s8_z24(struct gl_texture_image *texImage,                               GLint i, GLint j, GLint k, const void *texel){   /* only store Z, not stencil */   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);   GLfloat depth = *((GLfloat *) texel);   GLuint zi = (GLuint) (depth * 0xffffff);   *dst = zi | (*dst & 0xff000000);}#endif#undef TEXEL_ADDR#undef DIM#undef FETCH

⌨️ 快捷键说明

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