cell_state_derived.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 #include "util/u_memory.h"
00029 #include "pipe/p_shader_tokens.h"
00030 #include "draw/draw_context.h"
00031 #include "draw/draw_vertex.h"
00032 #include "cell_context.h"
00033 #include "cell_batch.h"
00034 #include "cell_state.h"
00035 #include "cell_state_emit.h"
00036 
00037 
00043 static void
00044 calculate_vertex_layout( struct cell_context *cell )
00045 {
00046    const struct cell_fragment_shader_state *fs = cell->fs;
00047    const enum interp_mode colorInterp
00048       = cell->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
00049    struct vertex_info *vinfo = &cell->vertex_info;
00050    uint i;
00051    int src;
00052 
00053 #if 0
00054    if (cell->vbuf) {
00055       /* if using the post-transform vertex buffer, tell draw_vbuf to
00056        * simply emit the whole post-xform vertex as-is:
00057        */
00058       struct vertex_info *vinfo_vbuf = &cell->vertex_info_vbuf;
00059       vinfo_vbuf->num_attribs = 0;
00060       draw_emit_vertex_attr(vinfo_vbuf, EMIT_ALL, INTERP_NONE, 0);
00061       vinfo_vbuf->size = 4 * vs->num_outputs + sizeof(struct vertex_header)/4;
00062    }
00063 #endif
00064 
00065    /* reset vinfo */
00066    vinfo->num_attribs = 0;
00067 
00068    /* we always want to emit vertex pos */
00069    src = draw_find_vs_output(cell->draw, TGSI_SEMANTIC_POSITION, 0);
00070    assert(src >= 0);
00071    draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, src);
00072 
00073 
00074    /*
00075     * Loop over fragment shader inputs, searching for the matching output
00076     * from the vertex shader.
00077     */
00078    for (i = 0; i < fs->info.num_inputs; i++) {
00079       switch (fs->info.input_semantic_name[i]) {
00080       case TGSI_SEMANTIC_POSITION:
00081          /* already done above */
00082          break;
00083 
00084       case TGSI_SEMANTIC_COLOR:
00085          src = draw_find_vs_output(cell->draw, TGSI_SEMANTIC_COLOR, 
00086                                    fs->info.input_semantic_index[i]);
00087          assert(src >= 0);
00088          draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
00089          break;
00090 
00091       case TGSI_SEMANTIC_FOG:
00092          src = draw_find_vs_output(cell->draw, TGSI_SEMANTIC_FOG, 0);
00093 #if 1
00094          if (src < 0) /* XXX temp hack, try demos/fogcoord.c with this */
00095             src = 0;
00096 #endif
00097          assert(src >= 0);
00098          draw_emit_vertex_attr(vinfo, EMIT_1F, INTERP_PERSPECTIVE, src);
00099          break;
00100 
00101       case TGSI_SEMANTIC_GENERIC:
00102          /* this includes texcoords and varying vars */
00103          src = draw_find_vs_output(cell->draw, TGSI_SEMANTIC_GENERIC,
00104                               fs->info.input_semantic_index[i]);
00105          assert(src >= 0);
00106          draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00107          break;
00108 
00109       default:
00110          assert(0);
00111       }
00112    }
00113 
00114    draw_compute_vertex_size(vinfo);
00115 
00116    /* XXX only signal this if format really changes */
00117    cell->dirty |= CELL_NEW_VERTEX_INFO;
00118 }
00119 
00120 
00121 #if 0
00122 
00125 static void
00126 compute_cliprect(struct cell_context *sp)
00127 {
00128    uint surfWidth = sp->framebuffer.width;
00129    uint surfHeight = sp->framebuffer.height;
00130 
00131    if (sp->rasterizer->scissor) {
00132       /* clip to scissor rect */
00133       sp->cliprect.minx = MAX2(sp->scissor.minx, 0);
00134       sp->cliprect.miny = MAX2(sp->scissor.miny, 0);
00135       sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth);
00136       sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight);
00137    }
00138    else {
00139       /* clip to surface bounds */
00140       sp->cliprect.minx = 0;
00141       sp->cliprect.miny = 0;
00142       sp->cliprect.maxx = surfWidth;
00143       sp->cliprect.maxy = surfHeight;
00144    }
00145 }
00146 #endif
00147 
00148 
00149 
00153 void cell_update_derived( struct cell_context *cell )
00154 {
00155    if (cell->dirty & (CELL_NEW_RASTERIZER |
00156                       CELL_NEW_FS |
00157                       CELL_NEW_VS))
00158       calculate_vertex_layout( cell );
00159 
00160 #if 0
00161    if (cell->dirty & (CELL_NEW_SCISSOR |
00162                       CELL_NEW_DEPTH_STENCIL_ALPHA |
00163                       CELL_NEW_FRAMEBUFFER))
00164       compute_cliprect(cell);
00165 #endif
00166 
00167    cell_emit_state(cell);
00168 
00169    cell->dirty = 0;
00170 }

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