diff options
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r-- | src/mesa/swrast/s_context.h | 16 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfetch_tmp.h | 8 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfilter.c | 6 | ||||
-rw-r--r-- | src/mesa/swrast/s_texrender.c | 2 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.c | 40 | ||||
-rw-r--r-- | src/mesa/swrast/s_triangle.c | 18 |
6 files changed, 58 insertions, 32 deletions
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index ec8451eb8f0..55f7c31ce51 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -138,20 +138,14 @@ struct swrast_texture_image /** used for mipmap LOD computation */ GLfloat WidthScale, HeightScale, DepthScale; -#if 0 - GLubyte *Data; /**< The actual texture data in malloc'd memory */ - - GLint TexelSize; /**< bytes per texel block */ -#endif + /** These fields only valid when texture memory is mapped */ + GLint RowStride; /**< Padded width in units of texels */ + GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to + each 2D slice in 'Data', in texels */ + GLubyte *Data; /**< Image data, accessed via FetchTexel() */ FetchTexelFunc FetchTexel; StoreTexelFunc Store; - -#if 0 - /** These fields only valid when texture memory is mapped */ - GLubyte **SliceMaps; /**< points to OneMap or a malloc'd array */ - GLint RowStride; /**< bytes per row of blocks */ -#endif }; diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h index c63b2043c74..8b7e930f905 100644 --- a/src/mesa/swrast/s_texfetch_tmp.h +++ b/src/mesa/swrast/s_texfetch_tmp.h @@ -43,7 +43,7 @@ #if DIM == 1 #define TEXEL_ADDR( type, image, i, j, k, size ) \ - ((void) (j), (void) (k), ((type *)(image)->Base.Data + (i) * (size))) + ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size))) #define FETCH(x) fetch_texel_1d_##x @@ -51,15 +51,15 @@ #define TEXEL_ADDR( type, image, i, j, k, size ) \ ((void) (k), \ - ((type *)(image)->Base.Data + ((image)->Base.RowStride * (j) + (i)) * (size))) + ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size))) #define FETCH(x) fetch_texel_2d_##x #elif DIM == 3 #define TEXEL_ADDR( type, image, i, j, k, size ) \ - ((type *)(image)->Base.Data + ((image)->Base.ImageOffsets[k] \ - + (image)->Base.RowStride * (j) + (i)) * (size)) + ((type *)(image)->Data + ((image)->ImageOffsets[k] \ + + (image)->RowStride * (j) + (i)) * (size)) #define FETCH(x) fetch_texel_3d_##x diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index f8b0fa1aa73..9de5c0276e1 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -1375,7 +1375,7 @@ opt_sample_rgb_2d(struct gl_context *ctx, GLint i = IFLOOR(texcoords[k][0] * width) & colMask; GLint j = IFLOOR(texcoords[k][1] * height) & rowMask; GLint pos = (j << shift) | i; - GLubyte *texel = ((GLubyte *) img->Data) + 3*pos; + GLubyte *texel = swImg->Data + 3 * pos; rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]); rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]); rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]); @@ -1419,7 +1419,7 @@ opt_sample_rgba_2d(struct gl_context *ctx, const GLint col = IFLOOR(texcoords[i][0] * width) & colMask; const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask; const GLint pos = (row << shift) | col; - const GLuint texel = *((GLuint *) img->Data + pos); + const GLuint texel = *((GLuint *) swImg->Data + pos); rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24) ); rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff ); rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >> 8) & 0xff ); @@ -1442,7 +1442,7 @@ sample_lambda_2d(struct gl_context *ctx, const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT) && (tObj->Sampler.WrapT == GL_REPEAT) - && (tImg->Border == 0 && (tImg->Width == tImg->RowStride)) + && (tImg->Border == 0 && (tImg->Width == swImg->RowStride)) && swImg->_IsPowerOfTwo; ASSERT(lambda != NULL); diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c index 47e458e1c5c..caa17f983e3 100644 --- a/src/mesa/swrast/s_texrender.c +++ b/src/mesa/swrast/s_texrender.c @@ -610,7 +610,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att) trb->Base.DataType = CHAN_TYPE; trb->Base._BaseFormat = GL_RGBA; } - trb->Base.Data = trb->TexImage->Base.Data; + trb->Base.Data = trb->TexImage->Data; } diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index 36b429cfab9..df371c30e3c 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -69,14 +69,32 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx, { struct swrast_texture_image *swImg = swrast_texture_image(texImage); GLuint bytes = _mesa_format_image_size(format, width, height, depth); + GLuint i; /* This _should_ be true (revisit if these ever fail) */ assert(texImage->Width == width); assert(texImage->Height == height); assert(texImage->Depth == depth); - assert(!texImage->Data); - texImage->Data = _mesa_align_malloc(bytes, 512); + assert(!swImg->Data); + swImg->Data = _mesa_align_malloc(bytes, 512); + if (!swImg->Data) + return GL_FALSE; + + /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ + swImg->RowStride = width; + + /* Allocate the ImageOffsets array and initialize to typical values. + * We allocate the array for 1D/2D textures too in order to avoid special- + * case code in the texstore routines. + */ + swImg->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint)); + if (!swImg->ImageOffsets) + return GL_FALSE; + + for (i = 0; i < depth; i++) { + swImg->ImageOffsets[i] = i * width * height; + } if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) && (height == 1 || _mesa_is_pow_two(texImage->Height2)) && @@ -98,7 +116,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx, swImg->DepthScale = (GLfloat) texImage->Depth; } - return texImage->Data != NULL; + return GL_TRUE; } @@ -109,11 +127,16 @@ void _swrast_free_texture_image_buffer(struct gl_context *ctx, struct gl_texture_image *texImage) { - if (texImage->Data) { - _mesa_align_free(texImage->Data); + struct swrast_texture_image *swImage = swrast_texture_image(texImage); + if (swImage->Data) { + _mesa_align_free(swImage->Data); + swImage->Data = NULL; } - texImage->Data = NULL; + if (swImage->ImageOffsets) { + free(swImage->ImageOffsets); + swImage->ImageOffsets = NULL; + } } @@ -155,6 +178,7 @@ _swrast_map_teximage(struct gl_context *ctx, GLubyte **mapOut, GLint *rowStrideOut) { + struct swrast_texture_image *swImage = swrast_texture_image(texImage); GLubyte *map; GLint stride, texelSize; GLuint bw, bh; @@ -165,9 +189,9 @@ _swrast_map_teximage(struct gl_context *ctx, stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); - assert(texImage->Data); + assert(swImage->Data); - map = texImage->Data; + map = swImage->Data; if (texImage->TexObject->Target == GL_TEXTURE_3D || texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) { diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index 839c4fd0855..b4f8e747929 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -127,10 +127,12 @@ _swrast_culltriangle( struct gl_context *ctx, ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ const struct gl_texture_image *texImg = \ obj->Image[0][obj->BaseLevel]; \ + const struct swrast_texture_image *swImg = \ + swrast_texture_image_const(texImg); \ const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat theight = (GLfloat) texImg->Height; \ const GLint twidth_log2 = texImg->WidthLog2; \ - const GLubyte *texture = (const GLubyte *) texImg->Data; \ + const GLubyte *texture = (const GLubyte *) swImg->Data; \ const GLint smask = texImg->Width - 1; \ const GLint tmask = texImg->Height - 1; \ ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ @@ -181,10 +183,12 @@ _swrast_culltriangle( struct gl_context *ctx, ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ const struct gl_texture_image *texImg = \ obj->Image[0][obj->BaseLevel]; \ + const struct swrast_texture_image *swImg = \ + swrast_texture_image_const(texImg); \ const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat theight = (GLfloat) texImg->Height; \ const GLint twidth_log2 = texImg->WidthLog2; \ - const GLubyte *texture = (const GLubyte *) texImg->Data; \ + const GLubyte *texture = (const GLubyte *) swImg->Data; \ const GLint smask = texImg->Width - 1; \ const GLint tmask = texImg->Height - 1; \ ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ @@ -533,9 +537,11 @@ affine_span(struct gl_context *ctx, SWspan *span, ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ const struct gl_texture_image *texImg = \ obj->Image[0][obj->BaseLevel]; \ + const struct swrast_texture_image *swImg = \ + swrast_texture_image_const(texImg); \ const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat theight = (GLfloat) texImg->Height; \ - info.texture = (const GLchan *) texImg->Data; \ + info.texture = (const GLchan *) swImg->Data; \ info.twidth_log2 = texImg->WidthLog2; \ info.smask = texImg->Width - 1; \ info.tmask = texImg->Height - 1; \ @@ -800,7 +806,9 @@ fast_persp_span(struct gl_context *ctx, SWspan *span, ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ const struct gl_texture_image *texImg = \ obj->Image[0][obj->BaseLevel]; \ - info.texture = (const GLchan *) texImg->Data; \ + const struct swrast_texture_image *swImg = \ + swrast_texture_image_const(texImg); \ + info.texture = (const GLchan *) swImg->Data; \ info.twidth_log2 = texImg->WidthLog2; \ info.smask = texImg->Width - 1; \ info.tmask = texImg->Height - 1; \ @@ -1062,7 +1070,7 @@ _swrast_choose_triangle( struct gl_context *ctx ) && texObj2D->_Swizzle == SWIZZLE_NOOP && swImg->_IsPowerOfTwo && texImg->Border == 0 - && texImg->Width == texImg->RowStride + && texImg->Width == swImg->RowStride && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888) && minFilter == magFilter && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR |