📄 texformat_tmp.h
字号:
const GLushort s = *src; texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) ); texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) ); texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );}#if DIM == 3static void store_texel_argb1555(struct gl_texture_image *texImage, GLint i, GLint j, GLint k, const void *texel){ const GLubyte *rgba = (const GLubyte *) texel; GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1); *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);}#endif/* MESA_FORMAT_ARGB1555_REV **************************************************//* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLchan *texel ){ const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1); const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */ texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) ); texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) ); texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );}#if DIM == 3static void store_texel_argb1555_rev(struct gl_texture_image *texImage, GLint i, GLint j, GLint k, const void *texel){ const GLubyte *rgba = (const GLubyte *) texel; GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1); *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);}#endif/* MESA_FORMAT_AL88 **********************************************************//* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */static void FETCH(al88)( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLchan *texel ){ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1); texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff ); texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );}#if DIM == 3static void store_texel_al88(struct gl_texture_image *texImage, GLint i, GLint j, GLint k, const void *texel){ const GLubyte *rgba = (const GLubyte *) texel; GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1); *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);}#endif/* MESA_FORMAT_AL88_REV ******************************************************//* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */static void FETCH(al88_rev)( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLchan *texel ){ const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1); texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 ); texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );}#if DIM == 3static void store_texel_al88_rev(struct gl_texture_image *texImage, GLint i, GLint j, GLint k, const void *texel){ const GLubyte *rgba = (const GLubyte *) texel; GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1); *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);}#endif/* MESA_FORMAT_RGB332 ********************************************************//* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */static void FETCH(rgb332)( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLchan *texel ){ static const GLubyte lut2to8[4] = {0, 85, 170, 255}; static const GLubyte lut3to8[8] = {0, 36, 73, 109, 146, 182, 219, 255}; const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1); const GLubyte s = *src; texel[RCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 5) & 0x7] ); texel[GCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 2) & 0x7] ); texel[BCOMP] = UBYTE_TO_CHAN( lut2to8[(s ) & 0x3] ); texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_rgb332(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 = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);}#endif/* MESA_FORMAT_A8 ************************************************************//* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */static void FETCH(a8)( 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); texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = 0; texel[ACOMP] = UBYTE_TO_CHAN( src[0] );}#if DIM == 3static void store_texel_a8(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 = rgba[ACOMP];}#endif/* MESA_FORMAT_L8 ************************************************************//* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */static void FETCH(l8)( 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); texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = UBYTE_TO_CHAN( src[0] ); texel[ACOMP] = CHAN_MAX;}#if DIM == 3static void store_texel_l8(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 = rgba[RCOMP];}#endif/* MESA_FORMAT_I8 ************************************************************//* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */static void FETCH(i8)( 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); texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = texel[ACOMP] = UBYTE_TO_CHAN( src[0] );}#if DIM == 3static void store_texel_i8(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 = rgba[RCOMP];}#endif/* 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; 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); if (palette->Type == GL_FLOAT) { const GLfloat *ftable = (const GLfloat *) palette->Table; switch (palette->_BaseFormat) { case GL_ALPHA: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = 0; texel[ACOMP] = (GLchan) (ftable[index] * CHAN_MAX); return; case GL_LUMINANCE: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = (GLchan) (ftable[index] * CHAN_MAX); texel[ACOMP] = CHAN_MAX; break; case GL_INTENSITY: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = texel[ACOMP] = ftable[index] * CHAN_MAX; return; case GL_LUMINANCE_ALPHA: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = (GLchan) (ftable[index * 2 + 0] * CHAN_MAX); texel[ACOMP] = (GLchan) (ftable[index * 2 + 1] * CHAN_MAX); return; case GL_RGB: texel[RCOMP] = (GLchan) (ftable[index * 3 + 0] * CHAN_MAX); texel[GCOMP] = (GLchan) (ftable[index * 3 + 1] * CHAN_MAX); texel[BCOMP] = (GLchan) (ftable[index * 3 + 2] * CHAN_MAX); texel[ACOMP] = CHAN_MAX; return; case GL_RGBA: texel[RCOMP] = (GLchan) (ftable[index * 4 + 0] * CHAN_MAX); texel[GCOMP] = (GLchan) (ftable[index * 4 + 1] * CHAN_MAX); texel[BCOMP] = (GLchan) (ftable[index * 4 + 2] * CHAN_MAX); texel[ACOMP] = (GLchan) (ftable[index * 4 + 3] * CHAN_MAX); return; default: _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8"); } } else { const GLchan *table = (const GLchan *) palette->Table; switch (palette->_BaseFormat) { case GL_ALPHA: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = 0; texel[ACOMP] = table[index]; return; case GL_LUMINANCE: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = table[index]; texel[ACOMP] = CHAN_MAX; break; case GL_INTENSITY: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = texel[ACOMP] = table[index]; return; case GL_LUMINANCE_ALPHA: texel[RCOMP] = texel[GCOMP] = texel[BCOMP] = table[index * 2 + 0]; texel[ACOMP] = table[index * 2 + 1]; return; case GL_RGB: texel[RCOMP] = table[index * 3 + 0]; texel[GCOMP] = table[index * 3 + 1]; texel[BCOMP] = table[index * 3 + 2]; texel[ACOMP] = CHAN_MAX; return; case GL_RGBA: texel[RCOMP] = table[index * 4 + 0]; texel[GCOMP] = table[index * 4 + 1]; texel[BCOMP] = table[index * 4 + 2]; texel[ACOMP] = table[index * 4 + 3]; return; default: _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8"); } }}#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/* 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){ /* 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){ /* 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#undef TEXEL_ADDR#undef DIM#undef FETCH
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -