From: Brian Paul Date: Mon, 16 Sep 2002 17:57:14 +0000 (+0000) Subject: fixed _mesa_generate_mipmaps() target problem X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d5bbbd41c431ad93c0867d5b0b234426d8570499;p=mesa.git fixed _mesa_generate_mipmaps() target problem --- diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 674de7af52c..d8ea2ee3539 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1,4 +1,4 @@ -/* $Id: texstore.c,v 1.38 2002/06/29 19:48:16 brianp Exp $ */ +/* $Id: texstore.c,v 1.39 2002/09/16 17:57:14 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -666,7 +666,7 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, + _mesa_generate_mipmap(ctx, target, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } @@ -739,7 +739,7 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, + _mesa_generate_mipmap(ctx, target, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } @@ -805,7 +805,7 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, + _mesa_generate_mipmap(ctx, target, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } @@ -837,7 +837,8 @@ _mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], + _mesa_generate_mipmap(ctx, target, + &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } } @@ -866,7 +867,8 @@ _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], + _mesa_generate_mipmap(ctx, target, + &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } } @@ -895,7 +897,8 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level, format, type, pixels, packing); /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], + _mesa_generate_mipmap(ctx, target, + &ctx->Texture.Unit[ctx->Texture.CurrentUnit], texObj); } } @@ -1603,22 +1606,10 @@ make_3d_mipmap(const struct gl_texture_format *format, GLint border, * Stop at texObj's MaxLevel or when we get to the 1x1 texture. */ void -_mesa_generate_mipmap(GLcontext *ctx, +_mesa_generate_mipmap(GLcontext *ctx, GLenum target, const struct gl_texture_unit *texUnit, struct gl_texture_object *texObj) { - const GLenum targets1D[] = { GL_TEXTURE_1D, 0 }; - const GLenum targets2D[] = { GL_TEXTURE_2D, 0 }; - const GLenum targets3D[] = { GL_TEXTURE_3D, 0 }; - const GLenum targetsCube[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, - GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, - GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, - GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, - 0 }; - const GLenum targetsRect[] = { GL_TEXTURE_RECTANGLE_NV, 0 }; - const GLenum *targets; GLint level; GLint maxLevels = 0; @@ -1627,23 +1618,18 @@ _mesa_generate_mipmap(GLcontext *ctx, switch (texObj->Target) { case GL_TEXTURE_1D: - targets = targets1D; maxLevels = ctx->Const.MaxTextureLevels; break; case GL_TEXTURE_2D: - targets = targets2D; maxLevels = ctx->Const.MaxTextureLevels; break; case GL_TEXTURE_3D: - targets = targets3D; maxLevels = ctx->Const.Max3DTextureLevels; break; case GL_TEXTURE_CUBE_MAP_ARB: - targets = targetsCube; maxLevels = ctx->Const.MaxCubeTextureLevels; break; case GL_TEXTURE_RECTANGLE_NV: - targets = targetsRect; maxLevels = 1; break; default: @@ -1697,70 +1683,73 @@ _mesa_generate_mipmap(GLcontext *ctx, return; } - /* Need this loop just because of cubemaps */ - for (t = 0; targets[t]; t++) { - ASSERT(t < 6); - - dstImage = _mesa_select_tex_image(ctx, texUnit, targets[t], level+1); + /* get dest gl_texture_image */ + dstImage = _mesa_select_tex_image(ctx, texUnit, target, level+1); + if (!dstImage) { + dstImage = _mesa_alloc_texture_image(); if (!dstImage) { - dstImage = _mesa_alloc_texture_image(); - if (!dstImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); - return; - } - _mesa_set_tex_image(texObj, targets[t], level + 1, dstImage); - } - - /* Free old image data */ - if (dstImage->Data) - MESA_PBUFFER_FREE(dstImage->Data); - - /* initialize new image */ - _mesa_init_teximage_fields(ctx, t, dstImage, dstWidth, dstHeight, - dstDepth, border, srcImage->Format); - dstImage->DriverData = NULL; - dstImage->TexFormat = srcImage->TexFormat; - dstImage->FetchTexel = srcImage->FetchTexel; - ASSERT(dstImage->TexFormat); - ASSERT(dstImage->FetchTexel); - - ASSERT(dstWidth * dstHeight * dstDepth * bytesPerTexel > 0); - - /* alloc new image buffer */ - dstImage->Data = MESA_PBUFFER_ALLOC(dstWidth * dstHeight * dstDepth - * bytesPerTexel); - if (!dstImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); return; } + _mesa_set_tex_image(texObj, target, level + 1, dstImage); + } - /* - * We use simple 2x2 averaging to compute the next mipmap level. - */ - switch (texObj->Target) { - case GL_TEXTURE_1D: - make_1d_mipmap(srcImage->TexFormat, border, - srcWidth, (const GLubyte *) srcImage->Data, - dstWidth, (GLubyte *) dstImage->Data); - break; - case GL_TEXTURE_2D: - case GL_TEXTURE_CUBE_MAP_ARB: - make_2d_mipmap(srcImage->TexFormat, border, - srcWidth, srcHeight, (const GLubyte *) srcImage->Data, - dstWidth, dstHeight, (GLubyte *) dstImage->Data); - break; - case GL_TEXTURE_3D: - make_3d_mipmap(srcImage->TexFormat, border, - srcWidth, srcHeight, srcDepth, (const GLubyte *) srcImage->Data, - dstWidth, dstHeight, dstDepth, (GLubyte *) dstImage->Data); - break; - case GL_TEXTURE_RECTANGLE_NV: - /* no mipmaps, do nothing */ - break; - default: - _mesa_problem(ctx, "bad dimensions in _mesa_generate_mipmaps"); - return; - } - } /* loop over tex image targets */ - } /* loop over tex levels */ + /* Free old image data */ + if (dstImage->Data) + MESA_PBUFFER_FREE(dstImage->Data); + + /* initialize new image */ + _mesa_init_teximage_fields(ctx, t, dstImage, dstWidth, dstHeight, + dstDepth, border, srcImage->Format); + dstImage->DriverData = NULL; + dstImage->TexFormat = srcImage->TexFormat; + dstImage->FetchTexel = srcImage->FetchTexel; + ASSERT(dstImage->TexFormat); + ASSERT(dstImage->FetchTexel); + + ASSERT(dstWidth * dstHeight * dstDepth * bytesPerTexel > 0); + + /* alloc new image buffer */ + dstImage->Data = MESA_PBUFFER_ALLOC(dstWidth * dstHeight * dstDepth + * bytesPerTexel); + if (!dstImage->Data) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); + return; + } + + /* + * We use simple 2x2 averaging to compute the next mipmap level. + */ + switch (target) { + case GL_TEXTURE_1D: + make_1d_mipmap(srcImage->TexFormat, border, + srcWidth, (const GLubyte *) srcImage->Data, + dstWidth, (GLubyte *) dstImage->Data); + break; + case GL_TEXTURE_2D: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: + make_2d_mipmap(srcImage->TexFormat, border, + srcWidth, srcHeight, (const GLubyte *) srcImage->Data, + dstWidth, dstHeight, (GLubyte *) dstImage->Data); + break; + case GL_TEXTURE_3D: + make_3d_mipmap(srcImage->TexFormat, border, + srcWidth, srcHeight, srcDepth, + (const GLubyte *) srcImage->Data, + dstWidth, dstHeight, dstDepth, + (GLubyte *) dstImage->Data); + break; + case GL_TEXTURE_RECTANGLE_NV: + /* no mipmaps, do nothing */ + break; + default: + _mesa_problem(ctx, "bad dimensions in _mesa_generate_mipmaps"); + return; + } + } /* loop over mipmap levels */ } diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h index bde79090185..6b1b09a1d90 100644 --- a/src/mesa/main/texstore.h +++ b/src/mesa/main/texstore.h @@ -1,10 +1,10 @@ -/* $Id: texstore.h,v 1.9 2001/06/15 14:18:46 brianp Exp $ */ +/* $Id: texstore.h,v 1.10 2002/09/16 17:57:14 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 4.1 * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2002 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"), @@ -149,7 +149,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level, extern void -_mesa_generate_mipmap(GLcontext *ctx, +_mesa_generate_mipmap(GLcontext *ctx, GLenum target, const struct gl_texture_unit *texUnit, struct gl_texture_object *texObj); diff --git a/src/mesa/swrast/s_texstore.c b/src/mesa/swrast/s_texstore.c index 88fe786ef8c..2ed4c6c9540 100644 --- a/src/mesa/swrast/s_texstore.c +++ b/src/mesa/swrast/s_texstore.c @@ -1,10 +1,10 @@ -/* $Id: s_texstore.c,v 1.6 2002/07/09 01:22:52 brianp Exp $ */ +/* $Id: s_texstore.c,v 1.7 2002/09/16 17:57:14 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 4.1 * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2002 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"), @@ -192,7 +192,7 @@ _swrast_copy_teximage1d( GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, texUnit, texObj); + _mesa_generate_mipmap(ctx, target, texUnit, texObj); } } @@ -251,7 +251,7 @@ _swrast_copy_teximage2d( GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, texUnit, texObj); + _mesa_generate_mipmap(ctx, target, texUnit, texObj); } } @@ -323,7 +323,7 @@ _swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, texUnit, texObj); + _mesa_generate_mipmap(ctx, target, texUnit, texObj); } } @@ -399,7 +399,7 @@ _swrast_copy_texsubimage2d( GLcontext *ctx, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, texUnit, texObj); + _mesa_generate_mipmap(ctx, target, texUnit, texObj); } } @@ -474,6 +474,6 @@ _swrast_copy_texsubimage3d( GLcontext *ctx, /* GL_SGIS_generate_mipmap */ if (level == texObj->BaseLevel && texObj->GenerateMipmap) { - _mesa_generate_mipmap(ctx, texUnit, texObj); + _mesa_generate_mipmap(ctx, target, texUnit, texObj); } }