st_atom_texture.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Keith Whitwell <keith@tungstengraphics.com>
00031   *   Brian Paul
00032   */
00033  
00034 
00035 #include "st_context.h"
00036 #include "st_atom.h"
00037 #include "st_texture.h"
00038 #include "st_cb_texture.h"
00039 #include "pipe/p_context.h"
00040 #include "pipe/p_inlines.h"
00041 #include "cso_cache/cso_context.h"
00042 
00043 
00044 static void 
00045 update_textures(struct st_context *st)
00046 {
00047    struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
00048    GLuint su;
00049 
00050    st->state.num_textures = 0;
00051 
00052    /*printf("%s samplers used = 0x%x\n", __FUNCTION__, fprog->Base.SamplersUsed);*/
00053 
00054    for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) {
00055       struct pipe_texture *pt = NULL;
00056 
00057       if (fprog->Base.SamplersUsed & (1 << su)) {
00058          const GLuint texUnit = fprog->Base.SamplerUnits[su];
00059          struct gl_texture_object *texObj
00060             = st->ctx->Texture.Unit[texUnit]._Current;
00061          struct st_texture_object *stObj;
00062          GLboolean flush, retval;
00063 
00064          if (!texObj) {
00065             texObj = st_get_default_texture(st);
00066          }
00067          stObj = st_texture_object(texObj);
00068 
00069          retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
00070          if (!retval) {
00071             /* out of mem */
00072             continue;
00073          }
00074 
00075          st->state.num_textures = su + 1;
00076 
00077          pt = st_get_stobj_texture(stObj);
00078       }
00079 
00080       /*
00081       if (pt) {
00082          printf("%s su=%u non-null\n", __FUNCTION__, su);
00083       }
00084       else {
00085          printf("%s su=%u null\n", __FUNCTION__, su);
00086       }
00087       */
00088 
00089       pipe_texture_reference(&st->state.sampler_texture[su], pt);
00090    }
00091 
00092    cso_set_sampler_textures(st->cso_context,
00093                             st->state.num_textures,
00094                             st->state.sampler_texture);
00095 }
00096 
00097 
00098 const struct st_tracked_state st_update_texture = {
00099    "st_update_texture",                                 /* name */
00100    {                                                    /* dirty */
00101       _NEW_TEXTURE,                                     /* mesa */
00102       ST_NEW_FRAGMENT_PROGRAM,                          /* st */
00103    },
00104    update_textures                                      /* update */
00105 };
00106 
00107 
00108 
00109 
00110 static void 
00111 finalize_textures(struct st_context *st)
00112 {
00113    struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current;
00114    const GLboolean prev_missing_textures = st->missing_textures;
00115    GLuint su;
00116 
00117    st->missing_textures = GL_FALSE;
00118 
00119    for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) {
00120       if (fprog->Base.SamplersUsed & (1 << su)) {
00121          const GLuint texUnit = fprog->Base.SamplerUnits[su];
00122          struct gl_texture_object *texObj
00123             = st->ctx->Texture.Unit[texUnit]._Current;
00124          struct st_texture_object *stObj = st_texture_object(texObj);
00125 
00126          if (texObj) {
00127             GLboolean flush, retval;
00128 
00129             retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush);
00130             if (!retval) {
00131                /* out of mem */
00132                st->missing_textures = GL_TRUE;
00133                continue;
00134             }
00135 
00136             stObj->teximage_realloc = TRUE;
00137          }
00138       }
00139    }
00140 
00141    if (prev_missing_textures != st->missing_textures)
00142       st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM;
00143 }
00144 
00145 
00146 
00147 const struct st_tracked_state st_finalize_textures = {
00148    "st_finalize_textures",              /* name */
00149    {                                    /* dirty */
00150       _NEW_TEXTURE,                     /* mesa */
00151       0,                                /* st */
00152    },
00153    finalize_textures                    /* update */
00154 };

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