cell_draw_arrays.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 /* Author:
00029  *    Brian Paul
00030  *    Keith Whitwell
00031  */
00032 
00033 
00034 #include "pipe/p_defines.h"
00035 #include "pipe/p_context.h"
00036 #include "pipe/p_winsys.h"
00037 #include "pipe/p_inlines.h"
00038 
00039 #include "cell_context.h"
00040 #include "cell_draw_arrays.h"
00041 #include "cell_state.h"
00042 #include "cell_flush.h"
00043 
00044 #include "draw/draw_context.h"
00045 
00046 
00047 
00048 static void
00049 cell_map_constant_buffers(struct cell_context *sp)
00050 {
00051    struct pipe_winsys *ws = sp->pipe.winsys;
00052    uint i;
00053    for (i = 0; i < 2; i++) {
00054       if (sp->constants[i].size) {
00055          sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
00056                                                   PIPE_BUFFER_USAGE_CPU_READ);
00057          cell_flush_buffer_range(sp, sp->mapped_constants[i], 
00058                                  sp->constants[i].buffer->size);
00059       }
00060    }
00061 
00062    draw_set_mapped_constant_buffer(sp->draw,
00063                                    sp->mapped_constants[PIPE_SHADER_VERTEX],
00064                                    sp->constants[PIPE_SHADER_VERTEX].size);
00065 }
00066 
00067 static void
00068 cell_unmap_constant_buffers(struct cell_context *sp)
00069 {
00070    struct pipe_winsys *ws = sp->pipe.winsys;
00071    uint i;
00072    for (i = 0; i < 2; i++) {
00073       if (sp->constants[i].size)
00074          ws->buffer_unmap(ws, sp->constants[i].buffer);
00075       sp->mapped_constants[i] = NULL;
00076    }
00077 }
00078 
00079 
00080 
00088 static boolean
00089 cell_draw_range_elements(struct pipe_context *pipe,
00090                          struct pipe_buffer *indexBuffer,
00091                          unsigned indexSize,
00092                          unsigned min_index,
00093                          unsigned max_index,
00094                          unsigned mode, unsigned start, unsigned count)
00095 {
00096    struct cell_context *sp = cell_context(pipe);
00097    struct draw_context *draw = sp->draw;
00098    unsigned i;
00099 
00100    if (sp->dirty)
00101       cell_update_derived( sp );
00102 
00103 #if 0
00104    cell_map_surfaces(sp);
00105 #endif
00106    cell_map_constant_buffers(sp);
00107 
00108    /*
00109     * Map vertex buffers
00110     */
00111    for (i = 0; i < sp->num_vertex_buffers; i++) {
00112       void *buf = pipe_buffer_map(pipe->screen,
00113                                            sp->vertex_buffer[i].buffer,
00114                                            PIPE_BUFFER_USAGE_CPU_READ);
00115       cell_flush_buffer_range(sp, buf, sp->vertex_buffer[i].buffer->size);
00116       draw_set_mapped_vertex_buffer(draw, i, buf);
00117    }
00118    /* Map index buffer, if present */
00119    if (indexBuffer) {
00120       void *mapped_indexes = pipe_buffer_map(pipe->screen,
00121                                                       indexBuffer,
00122                                                       PIPE_BUFFER_USAGE_CPU_READ);
00123       draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
00124    }
00125    else {
00126       /* no index/element buffer */
00127       draw_set_mapped_element_buffer(draw, 0, NULL);
00128    }
00129 
00130 
00131    /* draw! */
00132    draw_arrays(draw, mode, start, count);
00133 
00134    /*
00135     * unmap vertex/index buffers - will cause draw module to flush
00136     */
00137    for (i = 0; i < sp->num_vertex_buffers; i++) {
00138       draw_set_mapped_vertex_buffer(draw, i, NULL);
00139       pipe_buffer_unmap(pipe->screen, sp->vertex_buffer[i].buffer);
00140    }
00141    if (indexBuffer) {
00142       draw_set_mapped_element_buffer(draw, 0, NULL);
00143       pipe_buffer_unmap(pipe->screen, indexBuffer);
00144    }
00145 
00146    /* Note: leave drawing surfaces mapped */
00147    cell_unmap_constant_buffers(sp);
00148 
00149    return TRUE;
00150 }
00151 
00152 
00153 static boolean
00154 cell_draw_elements(struct pipe_context *pipe,
00155                    struct pipe_buffer *indexBuffer,
00156                    unsigned indexSize,
00157                    unsigned mode, unsigned start, unsigned count)
00158 {
00159    return cell_draw_range_elements( pipe, indexBuffer,
00160                                     indexSize,
00161                                     0, 0xffffffff,
00162                                     mode, start, count );
00163 }
00164 
00165 
00166 static boolean
00167 cell_draw_arrays(struct pipe_context *pipe, unsigned mode,
00168                      unsigned start, unsigned count)
00169 {
00170    return cell_draw_elements(pipe, NULL, 0, mode, start, count);
00171 }
00172 
00173 
00174 static void
00175 cell_set_edgeflags(struct pipe_context *pipe, const unsigned *edgeflags)
00176 {
00177    struct cell_context *cell = cell_context(pipe);
00178    draw_set_edgeflags(cell->draw, edgeflags);
00179 }
00180 
00181 
00182 
00183 void
00184 cell_init_draw_functions(struct cell_context *cell)
00185 {
00186    cell->pipe.draw_arrays = cell_draw_arrays;
00187    cell->pipe.draw_elements = cell_draw_elements;
00188    cell->pipe.draw_range_elements = cell_draw_range_elements;
00189    cell->pipe.set_edgeflags = cell_set_edgeflags;
00190 }
00191 

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