From f7e1dfeaefda8865252513bc4d880ea8640efe4d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 17 Feb 2001 00:15:39 +0000 Subject: [PATCH] Work in glGetTexImage() to return GL_COLOR_INDEX images. Prototype code for GL_SGIX_depth_texture / more flexible teximage code. --- src/mesa/main/extensions.c | 8 +- src/mesa/main/mtypes.h | 4 +- src/mesa/main/teximage.c | 184 +++++++++++++++++++++++++++++++++---- src/mesa/main/texstate.c | 13 ++- src/mesa/main/texstore.c | 131 +++++++++++++++++++++++--- 5 files changed, 302 insertions(+), 38 deletions(-) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 5715bff75a5..7c6dc8b72a9 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -1,10 +1,10 @@ -/* $Id: extensions.c,v 1.45 2001/01/24 04:56:20 brianp Exp $ */ +/* $Id: extensions.c,v 1.46 2001/02/17 00:15:39 brianp Exp $ */ /* * Mesa 3-D graphics library * Version: 3.5 * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -84,7 +84,7 @@ static struct { { ON, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) }, { ON, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) }, { ON, "GL_EXT_texture3D", F(EXT_texture3D) }, - { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) }, + { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc)}, { ON, "GL_EXT_texture_env_add", F(EXT_texture_env_add) }, { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) }, { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) }, @@ -103,6 +103,7 @@ static struct { { ON, "GL_SGI_color_table", F(SGI_color_table) }, { ON, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) }, { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) }, + { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) }, { ON, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) }, { OFF, "GL_3DFX_texture_compression_FXT1", F(_3DFX_texture_compression_FXT1) } }; @@ -124,6 +125,7 @@ _mesa_enable_sw_extensions(GLcontext *ctx) gl_extensions_enable(ctx, "GL_HP_occlusion_test"); gl_extensions_enable(ctx, "GL_NV_blend_square"); gl_extensions_enable(ctx, "GL_MESA_sprite_point"); + gl_extensions_enable(ctx, "GL_SGIX_depth_texture"); } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 2e0c1d149da..59cd836c8ac 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,4 +1,4 @@ -/* $Id: mtypes.h,v 1.18 2001/02/06 21:42:48 brianp Exp $ */ +/* $Id: mtypes.h,v 1.19 2001/02/17 00:15:39 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -788,6 +788,7 @@ struct gl_texture_image { GLubyte IntensityBits; /* color resolution. */ GLubyte LuminanceBits; GLubyte IndexBits; + GLubyte DepthBits; GLuint Border; /* 0 or 1 */ GLuint Width; /* = 2^WidthLog2 + 2*Border */ GLuint Height; /* = 2^HeightLog2 + 2*Border */ @@ -1221,6 +1222,7 @@ struct gl_extensions { GLboolean SGI_color_table; GLboolean SGIS_pixel_texture; GLboolean SGIS_texture_edge_clamp; + GLboolean SGIX_depth_texture; GLboolean SGIX_pixel_texture; GLboolean _3DFX_texture_compression_FXT1; }; diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 22973c35f80..fe5fb449810 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1,4 +1,4 @@ -/* $Id: teximage.c,v 1.75 2001/02/07 18:59:45 brianp Exp $ */ +/* $Id: teximage.c,v 1.76 2001/02/17 00:15:39 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -210,12 +210,94 @@ _mesa_base_tex_format( GLcontext *ctx, GLint format ) case GL_COLOR_INDEX12_EXT: case GL_COLOR_INDEX16_EXT: return GL_COLOR_INDEX; + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16_SGIX: + case GL_DEPTH_COMPONENT24_SGIX: + case GL_DEPTH_COMPONENT32_SGIX: + if (ctx->Extensions.SGIX_depth_texture) + return GL_DEPTH_COMPONENT; + else + return -1; default: return -1; /* error */ } } +/* + * Test if the given image format is a color/rgba format. That is, + * not color index, depth, stencil, etc. + */ +static GLboolean +is_color_format(GLenum format) +{ + switch (format) { + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + case 3: + case GL_RGB: + case GL_R3_G3_B2: + case GL_RGB4: + case GL_RGB5: + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + case 4: + case GL_RGBA: + case GL_RGBA2: + case GL_RGBA4: + case GL_RGB5_A1: + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +static GLboolean +is_index_format(GLenum format) +{ + switch (format) { + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return GL_TRUE; + default: + return GL_FALSE; + } +} + /* * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE @@ -476,6 +558,7 @@ clear_teximage_fields(struct gl_texture_image *img) { ASSERT(img); img->Format = 0; + img->Type = 0; img->IntFormat = 0; img->RedBits = 0; img->GreenBits = 0; @@ -1028,11 +1111,22 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format, return; } - if (_mesa_components_in_format(format) <= 0) { + if (_mesa_components_in_format(format) <= 0 || + format == GL_STENCIL_INDEX) { gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); return; } + if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); + } + + if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) { + gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); + } + + /* XXX what if format/type doesn't match texture format/type? */ + if (!pixels) return; @@ -1057,7 +1151,8 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); - if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { + if (is_color_format(format) && + ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { /* convert texture image to GL_RGBA, GL_FLOAT */ GLint width = texImage->Width; GLint height = texImage->Height; @@ -1132,7 +1227,7 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format, FREE(convImage); } else { - /* no convolution */ + /* no convolution, or non-rgba image */ GLint width = texImage->Width; GLint height = texImage->Height; GLint depth = texImage->Depth; @@ -1141,10 +1236,41 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format, for (row = 0; row < height; row++) { /* compute destination address in client memory */ GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, - width, height, format, type, img, row, 0); + width, height, format, type, + img, row, 0); assert(dest); - { + if (format == GL_COLOR_INDEX) { + GLuint indexRow[MAX_WIDTH]; + GLint col; + for (col = 0; col < width; col++) { + GLchan rgba[1]; + /* XXX this won't really work yet */ + /*need (*texImage->FetchRawTexel)() */ + (*texImage->FetchTexel)(ctx, texObj, texImage, + col, row, img, rgba); + indexRow[col] = rgba[0]; + } + _mesa_pack_index_span(ctx, width, type, dest, + indexRow, &ctx->Pack, + ctx->_ImageTransferState); + } + else if (format == GL_DEPTH_COMPONENT) { + /* XXX finish this */ + GLfloat depthRow[MAX_WIDTH]; + GLint col; + for (col = 0; col < width; col++) { + GLchan rgba[1]; + /* XXX this won't really work yet */ + /*need (*texImage->FetchRawTexel)() */ + (*texImage->FetchTexel)(ctx, texObj, texImage, + col, row, img, rgba); + depthRow[col] = (GLfloat) rgba[0]; + } + _mesa_pack_depth_span(ctx, width, dest, type, + depthRow, &ctx->Pack); + } + else { /* general case: convert row to RGBA format */ GLchan rgba[MAX_WIDTH][4]; GLint col; @@ -1152,7 +1278,6 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format, (*texImage->FetchTexel)(ctx, texObj, texImage, col, row, img, rgba[col]); } - _mesa_pack_rgba_span( ctx, width, (const GLchan (*)[4])rgba, format, type, dest, &ctx->Pack, ctx->_ImageTransferState ); @@ -1176,7 +1301,9 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); - _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + if (is_color_format(internalFormat)) { + _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + } if (target == GL_TEXTURE_1D) { struct gl_texture_unit *texUnit; @@ -1231,7 +1358,8 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, /* one of these has to be non-zero! */ ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || - texImage->LuminanceBits || texImage->IntensityBits); + texImage->LuminanceBits || texImage->IntensityBits || + texImage->DepthBits); ASSERT(texImage->FetchTexel); /* state update */ @@ -1279,7 +1407,10 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); - _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); + if (is_color_format(internalFormat)) { + _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, + &postConvHeight); + } if (target == GL_TEXTURE_2D || (ctx->Extensions.ARB_texture_cube_map && @@ -1339,7 +1470,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, /* one of these has to be non-zero! */ ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || - texImage->LuminanceBits || texImage->IntensityBits); + texImage->LuminanceBits || texImage->IntensityBits || + texImage->DepthBits); ASSERT(texImage->FetchTexel); /* state update */ @@ -1443,7 +1575,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, /* one of these has to be non-zero! */ ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || - texImage->LuminanceBits || texImage->IntensityBits); + texImage->LuminanceBits || texImage->IntensityBits || + texImage->DepthBits); ASSERT(texImage->FetchTexel); /* state update */ @@ -1504,7 +1637,10 @@ _mesa_TexSubImage1D( GLenum target, GLint level, struct gl_texture_object *texObj; struct gl_texture_image *texImage; - _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + /* XXX should test internal format */ + if (is_color_format(format)) { + _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + } if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, postConvWidth, 1, 1, format, type)) { @@ -1542,7 +1678,11 @@ _mesa_TexSubImage2D( GLenum target, GLint level, struct gl_texture_object *texObj; struct gl_texture_image *texImage; - _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); + /* XXX should test internal format */ + if (is_color_format(format)) { + _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, + &postConvHeight); + } if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, postConvWidth, postConvHeight, 1, format, type)) { @@ -1663,7 +1803,9 @@ _mesa_CopyTexImage1D( GLenum target, GLint level, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); - _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + if (is_color_format(internalFormat)) { + _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); + } if (copytexture_error_check(ctx, 1, target, level, internalFormat, postConvWidth, 1, border)) @@ -1706,7 +1848,10 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); - _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); + if (is_color_format(internalFormat)) { + _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, + &postConvHeight); + } if (copytexture_error_check(ctx, 2, target, level, internalFormat, postConvWidth, postConvHeight, border)) @@ -1748,6 +1893,7 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); + /* XXX should test internal format */ _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); if (copytexsubimage_error_check(ctx, 1, target, level, @@ -1798,7 +1944,8 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); - _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); + /* XXX should test internal format */ + _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, postConvWidth, postConvHeight)) @@ -1848,7 +1995,8 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level, if (ctx->NewState & _NEW_PIXEL) gl_update_state(ctx); - _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); + /* XXX should test internal format */ + _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, postConvWidth, postConvHeight)) diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 33b7da06041..ecfd5c59b31 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -1,10 +1,10 @@ -/* $Id: texstate.c,v 1.30 2001/02/06 21:42:48 brianp Exp $ */ +/* $Id: texstate.c,v 1.31 2001/02/17 00:15:39 brianp Exp $ */ /* * Mesa 3-D graphics library * Version: 3.5 * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -921,6 +921,15 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level, case GL_TEXTURE_INDEX_SIZE_EXT: *params = img->IndexBits; return; + case GL_DEPTH_BITS: + /* XXX this isn't in the GL_SGIX_depth_texture spec + * but seems appropriate. + */ + if (ctx->Extensions.SGIX_depth_texture) + *params = img->DepthBits; + else + gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)"); + return; /* GL_ARB_texture_compression */ case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB: diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 9b38d7e813d..224f79dd783 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1,4 +1,4 @@ -/* $Id: texstore.c,v 1.4 2001/02/07 19:02:23 brianp Exp $ */ +/* $Id: texstore.c,v 1.5 2001/02/17 00:15:39 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -150,6 +150,13 @@ fetch_1d_texel(GLcontext *ctx, rgba[BCOMP] = texel[2]; rgba[ACOMP] = texel[3]; return; + case GL_DEPTH_COMPONENT: + { + const GLfloat *data = (const GLfloat *) img->Data; + GLfloat *texel = (GLfloat *) rgba; + *texel = data[i]; + return; + } default: gl_problem(NULL, "Bad format in fetch_1d_texel"); return; @@ -210,6 +217,13 @@ fetch_2d_texel(GLcontext *ctx, rgba[BCOMP] = texel[2]; rgba[ACOMP] = texel[3]; return; + case GL_DEPTH_COMPONENT: + { + const GLfloat *data = (const GLfloat *) img->Data; + GLfloat *texel = (GLfloat *) rgba; + *texel = data[width * j + i]; + return; + } default: gl_problem(NULL, "Bad format in fetch_2d_texel"); } @@ -273,6 +287,13 @@ fetch_3d_texel(GLcontext *ctx, rgba[BCOMP] = texel[2]; rgba[ACOMP] = texel[3]; return; + case GL_DEPTH_COMPONENT: + { + const GLfloat *data = (const GLfloat *) img->Data; + GLfloat *texel = (GLfloat *) rgba; + *texel = data[rectarea * k + width * j + i]; + return; + } default: gl_problem(NULL, "Bad format in fetch_3d_texel"); } @@ -298,6 +319,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_LUMINANCE: texImage->RedBits = 0; @@ -307,6 +329,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 8 * sizeof(GLchan); texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_LUMINANCE_ALPHA: texImage->RedBits = 0; @@ -316,6 +339,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 8 * sizeof(GLchan); texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_INTENSITY: texImage->RedBits = 0; @@ -325,6 +349,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 8 * sizeof(GLchan); texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_RED: texImage->RedBits = 8 * sizeof(GLchan); @@ -334,6 +359,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_GREEN: texImage->RedBits = 0; @@ -343,6 +369,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_BLUE: texImage->RedBits = 0; @@ -352,6 +379,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_RGB: case GL_BGR: @@ -362,6 +390,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_RGBA: case GL_BGRA: @@ -373,6 +402,7 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 0; + texImage->DepthBits = 0; break; case GL_COLOR_INDEX: texImage->RedBits = 0; @@ -382,6 +412,17 @@ set_teximage_component_sizes( struct gl_texture_image *texImage ) texImage->IntensityBits = 0; texImage->LuminanceBits = 0; texImage->IndexBits = 8 * sizeof(GLchan); + texImage->DepthBits = 0; + break; + case GL_DEPTH_COMPONENT: + texImage->RedBits = 0; + texImage->GreenBits = 0; + texImage->BlueBits = 0; + texImage->AlphaBits = 0; + texImage->IntensityBits = 0; + texImage->LuminanceBits = 0; + texImage->IndexBits = 0; + texImage->DepthBits = 8 * sizeof(GLfloat); break; default: gl_problem(NULL, "unexpected format in set_teximage_component_sizes"); @@ -456,6 +497,11 @@ components_in_intformat( GLint format ) case GL_COLOR_INDEX12_EXT: case GL_COLOR_INDEX16_EXT: return 1; + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16_SGIX: + case GL_DEPTH_COMPONENT24_SGIX: + case GL_DEPTH_COMPONENT32_SGIX: + return 1; default: return -1; /* error */ } @@ -516,8 +562,7 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions, texComponents = components_in_intformat(texFormat); /* try common 2D texture cases first */ - if (!ctx->_ImageTransferState && dimensions == 2 - && srcType == CHAN_TYPE) { + if (!ctx->_ImageTransferState && dimensions == 2 && srcType == CHAN_TYPE) { if (srcFormat == texFormat) { /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA, @@ -593,6 +638,31 @@ _mesa_transfer_teximage(GLcontext *ctx, GLuint dimensions, dest += dstImageStride; } } + else if (texFormat == GL_DEPTH_COMPONENT) { + /* Depth texture (shadow maps) */ + const GLenum texType = GL_FLOAT; + GLint img, row; + GLfloat *dest = (GLfloat *) texAddr + dstZoffset * dstImageStride + + dstYoffset * dstRowStride + + dstXoffset * texComponents; + for (img = 0; img < srcDepth; img++) { + GLfloat *destRow = dest; + for (row = 0; row < srcHeight; row++) { + const GLvoid *src = _mesa_image_address(srcPacking, + srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); + (void) src; + (void) texType; + /* XXX destRow: GLfloat vs. GLdepth? */ + /* + _mesa_unpack_depth_span(ctx, srcWidth, texType, destRow, + srcType, src, srcPacking, + ctx->_ImageTransferState); + */ + destRow += dstRowStride; + } + dest += dstImageStride; + } + } else { /* regular, color texture */ if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) || @@ -713,6 +783,7 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLint components = components_in_intformat(internalFormat); + GLint compSize; GLint postConvWidth = width; if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { @@ -721,13 +792,19 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, /* setup the teximage struct's fields */ texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); - texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + if (format == GL_DEPTH_COMPONENT) { + texImage->Type = GL_FLOAT; /* XXX or GL_UNSIGNED_INT? */ + compSize = sizeof(GLfloat); + } + else { + texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + compSize = sizeof(CHAN_TYPE); + } texImage->FetchTexel = fetch_1d_texel; set_teximage_component_sizes(texImage); /* allocate memory */ - texImage->Data = (GLchan *) MALLOC(postConvWidth - * components * sizeof(GLchan)); + texImage->Data = (GLchan *) MALLOC(postConvWidth * components * compSize); if (!texImage->Data) return; /* out of memory */ @@ -757,6 +834,7 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLint components = components_in_intformat(internalFormat); + GLint compSize; GLint postConvWidth = width, postConvHeight = height; if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { @@ -766,13 +844,20 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, /* setup the teximage struct's fields */ texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); - texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + if (format == GL_DEPTH_COMPONENT) { + texImage->Type = GL_FLOAT; /* XXX or GL_UNSIGNED_INT? */ + compSize = sizeof(GLfloat); + } + else { + texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + compSize = sizeof(CHAN_TYPE); + } texImage->FetchTexel = fetch_2d_texel; set_teximage_component_sizes(texImage); /* allocate memory */ texImage->Data = (GLchan *) MALLOC(postConvWidth * postConvHeight - * components * sizeof(GLchan)); + * components * compSize); if (!texImage->Data) return; /* out of memory */ @@ -803,16 +888,24 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLint components = components_in_intformat(internalFormat); + GLint compSize; /* setup the teximage struct's fields */ texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); - texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + if (format == GL_DEPTH_COMPONENT) { + texImage->Type = GL_FLOAT; /* XXX or GL_UNSIGNED_INT? */ + compSize = sizeof(GLfloat); + } + else { + texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + compSize = sizeof(CHAN_TYPE); + } texImage->FetchTexel = fetch_3d_texel; set_teximage_component_sizes(texImage); /* allocate memory */ texImage->Data = (GLchan *) MALLOC(width * height * depth - * components * sizeof(GLchan)); + * components * compSize); if (!texImage->Data) return; /* out of memory */ @@ -861,10 +954,11 @@ _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLint components = components_in_intformat(texImage->IntFormat); + const GLint compSize = _mesa_sizeof_type(texImage->Type); _mesa_transfer_teximage(ctx, 2, texImage->Format, texImage->Data, width, height, 1, /* src size */ xoffset, yoffset, 0, /* dest offsets */ - texImage->Width * components * sizeof(GLchan), + texImage->Width * components * compSize, 0, /* dstImageStride */ format, type, pixels, packing); } @@ -883,12 +977,13 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLint components = components_in_intformat(texImage->IntFormat); + const GLint compSize = _mesa_sizeof_type(texImage->Type); _mesa_transfer_teximage(ctx, 3, texImage->Format, texImage->Data, width, height, depth, /* src size */ xoffset, yoffset, xoffset, /* dest offsets */ - texImage->Width * components * sizeof(GLchan), + texImage->Width * components * compSize, texImage->Width * texImage->Height * components - * sizeof(GLchan), + * compSize, format, type, pixels, packing); } @@ -963,6 +1058,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_unit *texUnit; struct gl_texture_object *texObj; struct gl_texture_image *texImage; + GLint compSize; (void) format; (void) type; @@ -978,7 +1074,14 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, */ /* setup the teximage struct's fields */ texImage->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); - texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + if (format == GL_DEPTH_COMPONENT) { + texImage->Type = GL_FLOAT; /* XXX or GL_UNSIGNED_INT? */ + compSize = sizeof(GLfloat); + } + else { + texImage->Type = CHAN_TYPE; /* usually GL_UNSIGNED_BYTE */ + compSize = sizeof(CHAN_TYPE); + } set_teximage_component_sizes(texImage); return GL_TRUE; -- 2.30.2