st_cb_texture.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

GLboolean st_finalize_texture (GLcontext *ctx, struct pipe_context *pipe, struct gl_texture_object *tObj, GLboolean *needFlush)
 Called during state validation.
struct gl_texture_object * st_get_default_texture (struct st_context *st)
 Returns pointer to a default/dummy texture.
void st_init_texture_functions (struct dd_function_table *functions)


Function Documentation

GLboolean st_finalize_texture ( GLcontext *  ctx,
struct pipe_context pipe,
struct gl_texture_object *  tObj,
GLboolean *  needFlush 
)

Called during state validation.

When this function is finished, the texture object should be ready for rendering.

Returns:
GL_TRUE for success, GL_FALSE for failure (out of mem)

Definition at line 1364 of file st_cb_texture.c.

References assert, st_texture_image::base, st_texture_object::base, pipe_texture::block, calculate_first_last_level(), pipe_texture::compressed, compressed_num_bytes(), copy_image_data_to_texture(), pipe_texture::depth, pipe_texture::format, gl_target_to_pipe(), pipe_format_block::height, pipe_texture::height, pipe_texture::last_level, st_texture_object::lastLevel, st_texture_image::level, pf_is_depth_stencil(), pipe_texture_reference(), pipe_texture_release(), PIPE_TEXTURE_USAGE_DEPTH_STENCIL, PIPE_TEXTURE_USAGE_RENDER_TARGET, PIPE_TEXTURE_USAGE_SAMPLER, st_texture_object::pt, st_texture_image::pt, pipe_format_block::size, st_mesa_format_to_pipe_format(), ST_NEW_FRAMEBUFFER, st_texture_create(), st_texture_image(), st_texture_object(), pipe_texture::target, pipe_format_block::width, and pipe_texture::width.

01368 {
01369    struct st_texture_object *stObj = st_texture_object(tObj);
01370    const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
01371    int comp_byte = 0;
01372    int cpp;
01373    GLuint face;
01374    struct st_texture_image *firstImage;
01375 
01376    *needFlush = GL_FALSE;
01377 
01378    /* We know/require this is true by now: 
01379     */
01380    assert(stObj->base._Complete);
01381 
01382    /* What levels must the texture include at a minimum?
01383     */
01384    calculate_first_last_level(stObj);
01385    firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
01386 
01387    /* If both firstImage and stObj point to a texture which can contain
01388     * all active images, favour firstImage.  Note that because of the
01389     * completeness requirement, we know that the image dimensions
01390     * will match.
01391     */
01392    if (firstImage->pt &&
01393        firstImage->pt != stObj->pt &&
01394        firstImage->pt->last_level >= stObj->lastLevel) {
01395 
01396       pipe_texture_reference(&stObj->pt, firstImage->pt);
01397    }
01398 
01399    /* FIXME: determine format block instead of cpp */
01400    if (firstImage->base.IsCompressed) {
01401       comp_byte = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat);
01402       cpp = comp_byte;
01403    }
01404    else {
01405       cpp = firstImage->base.TexFormat->TexelBytes;
01406    }
01407 
01408    /* If we already have a gallium texture, check that it matches the texture
01409     * object's format, target, size, num_levels, etc.
01410     */
01411    if (stObj->pt) {
01412       const enum pipe_format fmt =
01413          st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat);
01414       if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
01415           stObj->pt->format != fmt ||
01416           stObj->pt->last_level < stObj->lastLevel ||
01417           stObj->pt->width[0] != firstImage->base.Width2 ||
01418           stObj->pt->height[0] != firstImage->base.Height2 ||
01419           stObj->pt->depth[0] != firstImage->base.Depth2 ||
01420           stObj->pt->block.size != cpp ||
01421           stObj->pt->block.width != 1 ||
01422           stObj->pt->block.height != 1 ||
01423           stObj->pt->compressed != firstImage->base.IsCompressed) {
01424          pipe_texture_release(&stObj->pt);
01425          ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
01426       }
01427    }
01428 
01429    /* May need to create a new gallium texture:
01430     */
01431    if (!stObj->pt) {
01432       const enum pipe_format fmt =
01433          st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat);
01434       stObj->pt = st_texture_create(ctx->st,
01435                                     gl_target_to_pipe(stObj->base.Target),
01436                                     fmt,
01437                                     stObj->lastLevel,
01438                                     firstImage->base.Width2,
01439                                     firstImage->base.Height2,
01440                                     firstImage->base.Depth2,
01441                                     comp_byte,
01442                                     ( (pf_is_depth_stencil(fmt) ?
01443                                       PIPE_TEXTURE_USAGE_DEPTH_STENCIL :
01444                                       PIPE_TEXTURE_USAGE_RENDER_TARGET) |
01445                                       PIPE_TEXTURE_USAGE_SAMPLER ));
01446 
01447       if (!stObj->pt) {
01448          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
01449          return GL_FALSE;
01450       }
01451    }
01452 
01453    /* Pull in any images not in the object's texture:
01454     */
01455    for (face = 0; face < nr_faces; face++) {
01456       GLuint level;
01457       for (level = 0; level <= stObj->lastLevel; level++) {
01458          struct st_texture_image *stImage =
01459             st_texture_image(stObj->base.Image[face][stObj->base.BaseLevel + level]);
01460 
01461          /* Need to import images in main memory or held in other textures.
01462           */
01463          if (stImage && stObj->pt != stImage->pt) {
01464             copy_image_data_to_texture(ctx->st, stObj, level, stImage);
01465             *needFlush = GL_TRUE;
01466          }
01467       }
01468    }
01469 
01470    return GL_TRUE;
01471 }

struct gl_texture_object* st_get_default_texture ( struct st_context st  )  [read]

Returns pointer to a default/dummy texture.

This is typically used when the current shader has tex/sample instructions but the user has not provided a (any) texture(s).

Definition at line 1480 of file st_cb_texture.c.

References st_context::ctx, st_context::default_texture, and st_TexImage().

01481 {
01482    if (!st->default_texture) {
01483       static const GLenum target = GL_TEXTURE_2D;
01484       GLubyte pixels[16][16][4];
01485       struct gl_texture_object *texObj;
01486       struct gl_texture_image *texImg;
01487 
01488       /* init image to gray */
01489       memset(pixels, 127, sizeof(pixels));
01490 
01491       texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
01492 
01493       texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
01494 
01495       _mesa_init_teximage_fields(st->ctx, target, texImg,
01496                                  16, 16, 1, 0,  /* w, h, d, border */
01497                                  GL_RGBA);
01498 
01499       st_TexImage(st->ctx, 2, target,
01500                   0, GL_RGBA,    /* level, intformat */
01501                   16, 16, 1, 0,  /* w, h, d, border */
01502                   GL_RGBA, GL_UNSIGNED_BYTE, pixels,
01503                   &st->ctx->DefaultPacking,
01504                   texObj, texImg,
01505                   0, 0);
01506 
01507       texObj->MinFilter = GL_NEAREST;
01508       texObj->MagFilter = GL_NEAREST;
01509       texObj->_Complete = GL_TRUE;
01510 
01511       st->default_texture = texObj;
01512    }
01513    return st->default_texture;
01514 }

void st_init_texture_functions ( struct dd_function_table *  functions  ) 

Definition at line 1518 of file st_cb_texture.c.

References do_memcpy(), st_ChooseTextureFormat(), st_CompressedTexImage2D(), st_CopyTexImage1D(), st_CopyTexImage2D(), st_CopyTexSubImage1D(), st_CopyTexSubImage2D(), st_CopyTexSubImage3D(), st_DeleteTextureObject(), st_FreeTextureImageData(), st_generate_mipmap(), st_GetCompressedTexImage(), st_GetTexImage(), st_NewTextureImage(), st_NewTextureObject(), st_TexImage1D(), st_TexImage2D(), st_TexImage3D(), st_TexSubImage1D(), st_TexSubImage2D(), and st_TexSubImage3D().

01519 {
01520    functions->ChooseTextureFormat = st_ChooseTextureFormat;
01521    functions->TexImage1D = st_TexImage1D;
01522    functions->TexImage2D = st_TexImage2D;
01523    functions->TexImage3D = st_TexImage3D;
01524    functions->TexSubImage1D = st_TexSubImage1D;
01525    functions->TexSubImage2D = st_TexSubImage2D;
01526    functions->TexSubImage3D = st_TexSubImage3D;
01527    functions->CopyTexImage1D = st_CopyTexImage1D;
01528    functions->CopyTexImage2D = st_CopyTexImage2D;
01529    functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
01530    functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
01531    functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
01532    functions->GenerateMipmap = st_generate_mipmap;
01533 
01534    functions->GetTexImage = st_GetTexImage;
01535 
01536    /* compressed texture functions */
01537    functions->CompressedTexImage2D = st_CompressedTexImage2D;
01538    functions->GetCompressedTexImage = st_GetCompressedTexImage;
01539    functions->CompressedTextureSize = _mesa_compressed_texture_size;
01540 
01541    functions->NewTextureObject = st_NewTextureObject;
01542    functions->NewTextureImage = st_NewTextureImage;
01543    functions->DeleteTexture = st_DeleteTextureObject;
01544    functions->FreeTexImageData = st_FreeTextureImageData;
01545    functions->UpdateTexturePalette = 0;
01546 
01547    functions->TextureMemCpy = do_memcpy;
01548 
01549    /* XXX Temporary until we can query pipe's texture sizes */
01550    functions->TestProxyTexImage = _mesa_test_proxy_teximage;
01551 }


Generated on Tue Sep 29 06:25:54 2009 for Gallium3D by  doxygen 1.5.4