mesa: Support for MESA_FORMAT_S8_Z24 texture

cherry-picked from gallium-0.1
This commit is contained in:
Jakob Bornecrantz 2008-09-04 10:35:01 +08:00 committed by Xiang, Haihao
parent a04aeea5c0
commit dc44bb8e92
5 changed files with 134 additions and 0 deletions

View file

@ -1207,6 +1207,30 @@ const struct gl_texture_format _mesa_texformat_z24_s8 = {
store_texel_z24_s8 /* StoreTexel */
};
const struct gl_texture_format _mesa_texformat_s8_z24 = {
MESA_FORMAT_S8_Z24, /* MesaFormat */
GL_DEPTH_STENCIL_EXT, /* BaseFormat */
GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
0, /* RedBits */
0, /* GreenBits */
0, /* BlueBits */
0, /* AlphaBits */
0, /* LuminanceBits */
0, /* IntensityBits */
0, /* IndexBits */
24, /* DepthBits */
8, /* StencilBits */
4, /* TexelBytes */
_mesa_texstore_s8_z24, /* StoreTexImageFunc */
NULL, /* FetchTexel1D */
NULL, /* FetchTexel2D */
NULL, /* FetchTexel3D */
fetch_texel_1d_f_s8_z24, /* FetchTexel1Df */
fetch_texel_2d_f_s8_z24, /* FetchTexel2Df */
fetch_texel_3d_f_s8_z24, /* FetchTexel3Df */
store_texel_s8_z24 /* StoreTexel */
};
const struct gl_texture_format _mesa_texformat_z16 = {
MESA_FORMAT_Z16, /* MesaFormat */
GL_DEPTH_COMPONENT, /* BaseFormat */

View file

@ -84,6 +84,7 @@ enum _format {
MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */
MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
MESA_FORMAT_Z24_S8, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
MESA_FORMAT_S8_Z24, /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
MESA_FORMAT_Z16, /* ZZZZ ZZZZ ZZZZ ZZZZ */
MESA_FORMAT_Z32, /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
/*@}*/
@ -211,6 +212,7 @@ extern const struct gl_texture_format _mesa_texformat_l8;
extern const struct gl_texture_format _mesa_texformat_i8;
extern const struct gl_texture_format _mesa_texformat_ci8;
extern const struct gl_texture_format _mesa_texformat_z24_s8;
extern const struct gl_texture_format _mesa_texformat_s8_z24;
extern const struct gl_texture_format _mesa_texformat_z16;
extern const struct gl_texture_format _mesa_texformat_z32;
/*@}*/

View file

@ -1363,6 +1363,32 @@ static void store_texel_z24_s8(struct gl_texture_image *texImage,
#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 == 3
static 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

View file

@ -2445,6 +2445,87 @@ _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
}
/**
* Store a combined depth/stencil texture image.
*/
GLboolean
_mesa_texstore_s8_z24(TEXSTORE_PARAMS)
{
const GLuint depthScale = 0xffffff;
const GLint srcRowStride
= _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
/ sizeof(GLuint);
GLint img, row;
ASSERT(dstFormat == &_mesa_texformat_s8_z24);
ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
/* Incase we only upload depth we need to preserve the stencil */
if (srcFormat == GL_DEPTH_COMPONENT) {
for (img = 0; img < srcDepth; img++) {
GLuint *dstRow = (GLuint *) dstAddr
+ dstImageOffsets[dstZoffset + img]
+ dstYoffset * dstRowStride / sizeof(GLuint)
+ dstXoffset;
const GLuint *src
= (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
srcWidth, srcHeight,
srcFormat, srcType,
img, 0, 0);
for (row = 0; row < srcHeight; row++) {
GLuint depth[MAX_WIDTH];
GLint i;
_mesa_unpack_depth_span(ctx, srcWidth,
GL_UNSIGNED_INT, /* dst type */
depth, /* dst addr */
depthScale,
srcType, src, srcPacking);
for (i = 0; i < srcWidth; i++)
dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
src += srcRowStride;
dstRow += dstRowStride / sizeof(GLuint);
}
}
} else {
for (img = 0; img < srcDepth; img++) {
GLuint *dstRow = (GLuint *) dstAddr
+ dstImageOffsets[dstZoffset + img]
+ dstYoffset * dstRowStride / sizeof(GLuint)
+ dstXoffset;
const GLuint *src
= (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
srcWidth, srcHeight,
srcFormat, srcType,
img, 0, 0);
for (row = 0; row < srcHeight; row++) {
GLubyte stencil[MAX_WIDTH];
GLint i;
/* the 24 depth bits will be in the high position: */
_mesa_unpack_depth_span(ctx, srcWidth,
GL_UNSIGNED_INT, /* dst type */
dstRow, /* dst addr */
depthScale,
srcType, src, srcPacking);
/* get the 8-bit stencil values */
_mesa_unpack_stencil_span(ctx, srcWidth,
GL_UNSIGNED_BYTE, /* dst type */
stencil, /* dst addr */
srcType, src, srcPacking,
ctx->_ImageTransferState);
/* merge stencil values into depth values */
for (i = 0; i < srcWidth; i++)
dstRow[i] = stencil[i] << 24;
src += srcRowStride;
dstRow += dstRowStride / sizeof(GLuint);
}
}
}
return GL_TRUE;
}
/**
* Store an image in any of the formats:

View file

@ -57,6 +57,7 @@ extern GLboolean _mesa_texstore_a8(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_ci8(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_ycbcr(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_z24_s8(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_s8_z24(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_z16(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_z32(TEXSTORE_PARAMS);
extern GLboolean _mesa_texstore_rgba_float32(TEXSTORE_PARAMS);