sp_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 "sp_context.h"
00040 #include "sp_state.h"
00041 
00042 #include "draw/draw_context.h"
00043 
00044 
00045 
00046 static void
00047 softpipe_map_constant_buffers(struct softpipe_context *sp)
00048 {
00049    struct pipe_winsys *ws = sp->pipe.winsys;
00050    uint i;
00051    for (i = 0; i < PIPE_SHADER_TYPES; i++) {
00052       if (sp->constants[i].size)
00053          sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
00054                                                   PIPE_BUFFER_USAGE_CPU_READ);
00055    }
00056 
00057    draw_set_mapped_constant_buffer(sp->draw,
00058                                    sp->mapped_constants[PIPE_SHADER_VERTEX],
00059                                    sp->constants[PIPE_SHADER_VERTEX].size);
00060 }
00061 
00062 static void
00063 softpipe_unmap_constant_buffers(struct softpipe_context *sp)
00064 {
00065    struct pipe_winsys *ws = sp->pipe.winsys;
00066    uint i;
00067 
00068    /* really need to flush all prims since the vert/frag shaders const buffers
00069     * are going away now.
00070     */
00071    draw_flush(sp->draw);
00072 
00073    draw_set_mapped_constant_buffer(sp->draw, NULL, 0);
00074 
00075    for (i = 0; i < 2; i++) {
00076       if (sp->constants[i].size)
00077          ws->buffer_unmap(ws, sp->constants[i].buffer);
00078       sp->mapped_constants[i] = NULL;
00079    }
00080 }
00081 
00082 
00083 static unsigned reduced_prim[PIPE_PRIM_POLYGON + 1] = {
00084    PIPE_PRIM_POINTS,
00085    PIPE_PRIM_LINES,
00086    PIPE_PRIM_LINES,
00087    PIPE_PRIM_LINES,
00088    PIPE_PRIM_TRIANGLES,
00089    PIPE_PRIM_TRIANGLES,
00090    PIPE_PRIM_TRIANGLES,
00091    PIPE_PRIM_TRIANGLES,
00092    PIPE_PRIM_TRIANGLES,
00093    PIPE_PRIM_TRIANGLES
00094 };
00095 
00096 
00097 boolean
00098 softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
00099                      unsigned start, unsigned count)
00100 {
00101    return softpipe_draw_elements(pipe, NULL, 0, mode, start, count);
00102 }
00103 
00104 
00105 
00114 boolean
00115 softpipe_draw_range_elements(struct pipe_context *pipe,
00116                              struct pipe_buffer *indexBuffer,
00117                              unsigned indexSize,
00118                              unsigned min_index,
00119                              unsigned max_index,
00120                              unsigned mode, unsigned start, unsigned count)
00121 {
00122    struct softpipe_context *sp = softpipe_context(pipe);
00123    struct draw_context *draw = sp->draw;
00124    unsigned i;
00125 
00126    sp->reduced_api_prim = reduced_prim[mode];
00127 
00128    if (sp->dirty)
00129       softpipe_update_derived( sp );
00130 
00131    softpipe_map_surfaces(sp);
00132    softpipe_map_constant_buffers(sp);
00133 
00134    /*
00135     * Map vertex buffers
00136     */
00137    for (i = 0; i < sp->num_vertex_buffers; i++) {
00138       void *buf
00139          = pipe_buffer_map(pipe->screen,
00140                                     sp->vertex_buffer[i].buffer,
00141                                     PIPE_BUFFER_USAGE_CPU_READ);
00142       draw_set_mapped_vertex_buffer(draw, i, buf);
00143    }
00144    /* Map index buffer, if present */
00145    if (indexBuffer) {
00146       void *mapped_indexes
00147          = pipe_buffer_map(pipe->screen, indexBuffer,
00148                                     PIPE_BUFFER_USAGE_CPU_READ);
00149       draw_set_mapped_element_buffer_range(draw, indexSize,
00150                                            min_index,
00151                                            max_index,
00152                                            mapped_indexes);
00153    }
00154    else {
00155       /* no index/element buffer */
00156       draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
00157    }
00158 
00159 
00160    /* draw! */
00161    draw_arrays(draw, mode, start, count);
00162 
00163    /*
00164     * unmap vertex/index buffers - will cause draw module to flush
00165     */
00166    for (i = 0; i < sp->num_vertex_buffers; i++) {
00167       draw_set_mapped_vertex_buffer(draw, i, NULL);
00168       pipe_buffer_unmap(pipe->screen, sp->vertex_buffer[i].buffer);
00169    }
00170    if (indexBuffer) {
00171       draw_set_mapped_element_buffer(draw, 0, NULL);
00172       pipe_buffer_unmap(pipe->screen, indexBuffer);
00173    }
00174 
00175 
00176    /* Note: leave drawing surfaces mapped */
00177    softpipe_unmap_constant_buffers(sp);
00178 
00179    return TRUE;
00180 }
00181 
00182 boolean
00183 softpipe_draw_elements(struct pipe_context *pipe,
00184                        struct pipe_buffer *indexBuffer,
00185                        unsigned indexSize,
00186                        unsigned mode, unsigned start, unsigned count)
00187 {
00188    return softpipe_draw_range_elements( pipe, indexBuffer,
00189                                         indexSize,
00190                                         0, 0xffffffff,
00191                                         mode, start, count );
00192 }
00193 
00194 
00195 
00196 void
00197 softpipe_set_edgeflags(struct pipe_context *pipe, const unsigned *edgeflags)
00198 {
00199    struct softpipe_context *sp = softpipe_context(pipe);
00200    draw_set_edgeflags(sp->draw, edgeflags);
00201 }
00202 

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