diff options
author | Brian Paul <[email protected]> | 2002-03-19 16:47:04 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2002-03-19 16:47:04 +0000 |
commit | aeb4434563c4014a662ea334878b60d3031bb3c1 (patch) | |
tree | c46189840da3ba9ba94cfcc5a99f4a6deccc582f /src/mesa/main | |
parent | d0570646bd67eae8152b63ccaf5c73970b1f56ea (diff) |
Use MESA_PBUFFER_ALLOC/FREE macros to allocate all framebuffer and texture
memory. These can be overridden by applications which need to manage this
memory specially. Contributed by Gerk Huisma.
Also, new code for 8-bit -> 16-bit/channel texture image storage which
fills in the least-significant bits properly.
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/context.c | 16 | ||||
-rw-r--r-- | src/mesa/main/image.c | 154 | ||||
-rw-r--r-- | src/mesa/main/teximage.c | 24 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 16 |
4 files changed, 144 insertions, 66 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 5ed31a18bc0..8d0c52a0c34 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,4 +1,4 @@ -/* $Id: context.c,v 1.156 2002/03/16 00:53:15 brianp Exp $ */ +/* $Id: context.c,v 1.157 2002/03/19 16:47:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -398,31 +398,31 @@ _mesa_free_framebuffer_data( GLframebuffer *buffer ) return; if (buffer->DepthBuffer) { - FREE( buffer->DepthBuffer ); + MESA_PBUFFER_FREE( buffer->DepthBuffer ); buffer->DepthBuffer = NULL; } if (buffer->Accum) { - FREE( buffer->Accum ); + MESA_PBUFFER_FREE( buffer->Accum ); buffer->Accum = NULL; } if (buffer->Stencil) { - FREE( buffer->Stencil ); + MESA_PBUFFER_FREE( buffer->Stencil ); buffer->Stencil = NULL; } if (buffer->FrontLeftAlpha) { - FREE( buffer->FrontLeftAlpha ); + MESA_PBUFFER_FREE( buffer->FrontLeftAlpha ); buffer->FrontLeftAlpha = NULL; } if (buffer->BackLeftAlpha) { - FREE( buffer->BackLeftAlpha ); + MESA_PBUFFER_FREE( buffer->BackLeftAlpha ); buffer->BackLeftAlpha = NULL; } if (buffer->FrontRightAlpha) { - FREE( buffer->FrontRightAlpha ); + MESA_PBUFFER_FREE( buffer->FrontRightAlpha ); buffer->FrontRightAlpha = NULL; } if (buffer->BackRightAlpha) { - FREE( buffer->BackRightAlpha ); + MESA_PBUFFER_FREE( buffer->BackRightAlpha ); buffer->BackRightAlpha = NULL; } } diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 1d779ea82bd..fc77bf88186 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -1,4 +1,4 @@ -/* $Id: image.c,v 1.64 2002/03/13 04:34:32 brianp Exp $ */ +/* $Id: image.c,v 1.65 2002/03/19 16:47:04 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1787,6 +1787,18 @@ _mesa_pack_rgba_span( GLcontext *ctx, dest += 3; } } + else if (transferOps == 0 && dstFormat == GL_RGBA && dstType == GL_UNSIGNED_BYTE) { + /* common simple case */ + GLuint i; + GLubyte *dest = (GLubyte *) dstAddr; + for (i = 0; i < n; i++) { + dest[0] = CHAN_TO_UBYTE(srcRgba[i][RCOMP]); + dest[1] = CHAN_TO_UBYTE(srcRgba[i][GCOMP]); + dest[2] = CHAN_TO_UBYTE(srcRgba[i][BCOMP]); + dest[3] = CHAN_TO_UBYTE(srcRgba[i][ACOMP]); + dest += 4; + } + } else { /* general solution */ GLuint i; @@ -2561,52 +2573,118 @@ _mesa_unpack_chan_color_span( GLcontext *ctx, srcType == GL_UNSIGNED_INT_2_10_10_10_REV); /* Try simple cases first */ - if (transferOps == 0 && srcType == CHAN_TYPE) { - if (dstFormat == GL_RGBA) { - if (srcFormat == GL_RGBA) { - MEMCPY( dest, source, n * 4 * sizeof(GLchan) ); - return; + if (transferOps == 0 ){ + if (srcType == CHAN_TYPE) { + if (dstFormat == GL_RGBA) { + if (srcFormat == GL_RGBA) { + MEMCPY( dest, source, n * 4 * sizeof(GLchan) ); + return; + } + else if (srcFormat == GL_RGB) { + GLuint i; + const GLchan *src = (const GLchan *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst[3] = CHAN_MAX; + src += 3; + dst += 4; + } + return; + } } - else if (srcFormat == GL_RGB) { - GLuint i; - const GLchan *src = (const GLchan *) source; - GLchan *dst = dest; - for (i = 0; i < n; i++) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = CHAN_MAX; - src += 3; - dst += 4; + else if (dstFormat == GL_RGB) { + if (srcFormat == GL_RGB) { + MEMCPY( dest, source, n * 3 * sizeof(GLchan) ); + return; + } + else if (srcFormat == GL_RGBA) { + GLuint i; + const GLchan *src = (const GLchan *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + src += 4; + dst += 3; + } + return; } + } + else if (dstFormat == srcFormat) { + GLint comps = _mesa_components_in_format(srcFormat); + assert(comps > 0); + MEMCPY( dest, source, n * comps * sizeof(GLchan) ); return; } } - else if (dstFormat == GL_RGB) { - if (srcFormat == GL_RGB) { - MEMCPY( dest, source, n * 3 * sizeof(GLchan) ); - return; + /* + * Common situation, loading 8bit RGBA/RGB source images + * into 16/32 bit destination. (OSMesa16/32) + */ + else if (srcType == GL_UNSIGNED_BYTE) { + if (dstFormat == GL_RGBA) { + if (srcFormat == GL_RGB) { + GLuint i; + const GLubyte *src = (const GLubyte *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = UBYTE_TO_CHAN(src[0]); + dst[1] = UBYTE_TO_CHAN(src[1]); + dst[2] = UBYTE_TO_CHAN(src[2]); + dst[3] = CHAN_MAX; + src += 3; + dst += 4; + } + return; + } + else if (srcFormat == GL_RGBA) { + GLuint i; + const GLubyte *src = (const GLubyte *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = UBYTE_TO_CHAN(src[0]); + dst[1] = UBYTE_TO_CHAN(src[1]); + dst[2] = UBYTE_TO_CHAN(src[2]); + dst[3] = UBYTE_TO_CHAN(src[3]); + src += 4; + dst += 4; + } + return; + } } - else if (srcFormat == GL_RGBA) { - GLuint i; - const GLchan *src = (const GLchan *) source; - GLchan *dst = dest; - for (i = 0; i < n; i++) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - src += 4; - dst += 3; + else if (dstFormat == GL_RGB) { + if (srcFormat == GL_RGB) { + GLuint i; + const GLubyte *src = (const GLubyte *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = UBYTE_TO_CHAN(src[0]); + dst[1] = UBYTE_TO_CHAN(src[1]); + dst[2] = UBYTE_TO_CHAN(src[2]); + src += 3; + dst += 3; + } + return; + } + else if (srcFormat == GL_RGBA) { + GLuint i; + const GLubyte *src = (const GLubyte *) source; + GLchan *dst = dest; + for (i = 0; i < n; i++) { + dst[0] = UBYTE_TO_CHAN(src[0]); + dst[1] = UBYTE_TO_CHAN(src[1]); + dst[2] = UBYTE_TO_CHAN(src[2]); + src += 4; + dst += 3; + } + return; } - return; } } - else if (dstFormat == srcFormat) { - GLint comps = _mesa_components_in_format(srcFormat); - assert(comps > 0); - MEMCPY( dest, source, n * comps * sizeof(GLchan) ); - return; - } } diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 89cf12c8d08..e383cbdfc96 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1,10 +1,10 @@ -/* $Id: teximage.c,v 1.106 2001/11/18 22:48:13 brianp Exp $ */ +/* $Id: teximage.c,v 1.107 2002/03/19 16:47:05 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 4.0.2 * - * 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"), @@ -382,7 +382,7 @@ void _mesa_free_texture_image( struct gl_texture_image *teximage ) { if (teximage->Data) { - FREE( teximage->Data ); + MESA_PBUFFER_FREE( teximage->Data ); teximage->Data = NULL; } FREE( teximage ); @@ -1350,7 +1350,7 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, } else if (texImage->Data) { /* free the old texture data */ - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } clear_teximage_fields(texImage); /* not really needed, but helpful */ @@ -1475,7 +1475,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, } else if (texImage->Data) { /* free the old texture data */ - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } clear_teximage_fields(texImage); /* not really needed, but helpful */ @@ -1596,7 +1596,7 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, } } else if (texImage->Data) { - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } clear_teximage_fields(texImage); /* not really needed, but helpful */ @@ -1866,7 +1866,7 @@ _mesa_CopyTexImage1D( GLenum target, GLint level, } else if (texImage->Data) { /* free the old texture data */ - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } @@ -1930,7 +1930,7 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, } else if (texImage->Data) { /* free the old texture data */ - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } @@ -2115,7 +2115,7 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level, } } else if (texImage->Data) { - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } @@ -2214,7 +2214,7 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level, } } else if (texImage->Data) { - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } @@ -2312,7 +2312,7 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level, } } else if (texImage->Data) { - FREE(texImage->Data); + MESA_PBUFFER_FREE(texImage->Data); texImage->Data = NULL; } diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 9798e32390f..317e2114f3d 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1,10 +1,10 @@ -/* $Id: texstore.c,v 1.34 2001/09/19 20:30:44 kschultz Exp $ */ +/* $Id: texstore.c,v 1.35 2002/03/19 16:47:05 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 4.0.2 * - * 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"), @@ -645,7 +645,7 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level, } /* allocate memory */ - texImage->Data = MALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); return; @@ -718,7 +718,7 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level, } /* allocate memory */ - texImage->Data = MALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); return; @@ -784,7 +784,7 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level, } /* allocate memory */ - texImage->Data = MALLOC(sizeInBytes); + texImage->Data = MESA_PBUFFER_ALLOC(sizeInBytes); if (!texImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); return; @@ -1705,7 +1705,7 @@ _mesa_generate_mipmap(GLcontext *ctx, /* Free old image data */ if (dstImage->Data) - FREE(dstImage->Data); + MESA_PBUFFER_FREE(dstImage->Data); /* initialize new image */ _mesa_init_teximage_fields(ctx, dstImage, dstWidth, dstHeight, @@ -1719,7 +1719,7 @@ _mesa_generate_mipmap(GLcontext *ctx, ASSERT(dstWidth * dstHeight * dstDepth * bytesPerTexel > 0); /* alloc new image buffer */ - dstImage->Data = MALLOC(dstWidth * dstHeight * dstDepth + dstImage->Data = MESA_PBUFFER_ALLOC(dstWidth * dstHeight * dstDepth * bytesPerTexel); if (!dstImage->Data) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps"); |