[Mesa-dev] [PATCH 03/17] swrast: Factor out texture slice counting.
Brian Paul
brianp at vmware.com
Tue Apr 30 07:07:14 PDT 2013
On 04/22/2013 10:14 AM, Eric Anholt wrote:
> This function going to get used a lot more in upcoming patches.
> ---
> src/mesa/swrast/s_texture.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
> index 51048be..36a90dd 100644
> --- a/src/mesa/swrast/s_texture.c
> +++ b/src/mesa/swrast/s_texture.c
> @@ -58,6 +58,14 @@ _swrast_delete_texture_image(struct gl_context *ctx,
> _mesa_delete_texture_image(ctx, texImage);
> }
>
> +static unsigned int
> +texture_slices(struct gl_texture_image *texImage)
> +{
> + if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY)
> + return texImage->Height;
> + else
> + return texImage->Depth;
> +}
>
> /**
> * Called via ctx->Driver.AllocTextureImageBuffer()
> @@ -83,11 +91,11 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
> * We allocate the array for 1D/2D textures too in order to avoid special-
> * case code in the texstore routines.
> */
> - swImg->ImageOffsets = malloc(texImage->Depth * sizeof(GLuint));
> + swImg->ImageOffsets = malloc(texture_slices(texImage) * sizeof(GLuint));
> if (!swImg->ImageOffsets)
> return GL_FALSE;
>
> - for (i = 0; i< texImage->Depth; i++) {
> + for (i = 0; i< texture_slices(texImage); i++) {
> swImg->ImageOffsets[i] = i * texImage->Width * texImage->Height;
> }
>
Maybe save the result of texture_slices(texImage) in a local var so it
doesn't get called for each loop iteration. Not a big deal though.
> @@ -209,20 +217,20 @@ _swrast_map_teximage(struct gl_context *ctx,
>
> map = swImage->Buffer;
>
> + assert(slice< texture_slices(texImage));
> +
> if (texImage->TexObject->Target == GL_TEXTURE_3D ||
> texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {
> GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,
> texImage->Width,
> texImage->Height,
> 1);
> - assert(slice< texImage->Depth);
> map += slice * sliceSize;
> } else if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
> GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,
> texImage->Width,
> 1,
> 1);
> - assert(slice< texImage->Height);
> map += slice * sliceSize;
> }
>
More information about the mesa-dev
mailing list