summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texstore.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2002-09-16 17:57:14 +0000
committerBrian Paul <[email protected]>2002-09-16 17:57:14 +0000
commitd5bbbd41c431ad93c0867d5b0b234426d8570499 (patch)
tree83b922e1d4b53fe2a07788bc5d97439bfb48e753 /src/mesa/main/texstore.c
parent8cd2d0e7828186f1ffffb775466b1dfd21eeef33 (diff)
fixed _mesa_generate_mipmaps() target problem
Diffstat (limited to 'src/mesa/main/texstore.c')
-rw-r--r--src/mesa/main/texstore.c161
1 files changed, 75 insertions, 86 deletions
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 */
}