i915_context.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2003 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 "i915_context.h"
00029 #include "i915_winsys.h"
00030 #include "i915_state.h"
00031 #include "i915_batch.h"
00032 #include "i915_texture.h"
00033 #include "i915_reg.h"
00034 
00035 #include "draw/draw_context.h"
00036 #include "pipe/p_defines.h"
00037 #include "pipe/p_winsys.h"
00038 #include "pipe/p_inlines.h"
00039 #include "util/u_memory.h"
00040 #include "pipe/p_screen.h"
00041 
00042 
00043 static void i915_destroy( struct pipe_context *pipe )
00044 {
00045    struct i915_context *i915 = i915_context( pipe );
00046 
00047    draw_destroy( i915->draw );
00048    
00049    if(i915->winsys->destroy)
00050       i915->winsys->destroy(i915->winsys);
00051 
00052    FREE( i915 );
00053 }
00054 
00055 
00056 static boolean
00057 i915_draw_range_elements(struct pipe_context *pipe,
00058                              struct pipe_buffer *indexBuffer,
00059                              unsigned indexSize,
00060                              unsigned min_index,
00061                              unsigned max_index,
00062                              unsigned prim, unsigned start, unsigned count)
00063 {
00064    struct i915_context *i915 = i915_context( pipe );
00065    struct draw_context *draw = i915->draw;
00066    unsigned i;
00067 
00068    if (i915->dirty)
00069       i915_update_derived( i915 );
00070 
00071    /*
00072     * Map vertex buffers
00073     */
00074    for (i = 0; i < i915->num_vertex_buffers; i++) {
00075       void *buf
00076          = pipe_buffer_map(pipe->screen,
00077                                     i915->vertex_buffer[i].buffer,
00078                                     PIPE_BUFFER_USAGE_CPU_READ);
00079       draw_set_mapped_vertex_buffer(draw, i, buf);
00080    }
00081    /* Map index buffer, if present */
00082    if (indexBuffer) {
00083       void *mapped_indexes
00084          = pipe_buffer_map(pipe->screen, indexBuffer,
00085                                     PIPE_BUFFER_USAGE_CPU_READ);
00086       draw_set_mapped_element_buffer_range(draw, indexSize,
00087                                            min_index,
00088                                            max_index,
00089                                            mapped_indexes);
00090    }
00091    else {
00092       /* no index/element buffer */
00093       draw_set_mapped_element_buffer(draw, 0, NULL);
00094    }
00095 
00096 
00097    draw_set_mapped_constant_buffer(draw,
00098                                    i915->current.constants[PIPE_SHADER_VERTEX],
00099                                    ( i915->current.num_user_constants[PIPE_SHADER_VERTEX] * 
00100                                      4 * sizeof(float) ));
00101 
00102    /* draw! */
00103    draw_arrays(i915->draw, prim, start, count);
00104 
00105    /*
00106     * unmap vertex/index buffers
00107     */
00108    for (i = 0; i < i915->num_vertex_buffers; i++) {
00109       pipe_buffer_unmap(pipe->screen, i915->vertex_buffer[i].buffer);
00110       draw_set_mapped_vertex_buffer(draw, i, NULL);
00111    }
00112    if (indexBuffer) {
00113       pipe_buffer_unmap(pipe->screen, indexBuffer);
00114       draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
00115    }
00116 
00117    return TRUE;
00118 }
00119 
00120 static boolean
00121 i915_draw_elements( struct pipe_context *pipe,
00122                     struct pipe_buffer *indexBuffer,
00123                     unsigned indexSize,
00124                     unsigned prim, unsigned start, unsigned count)
00125 {
00126    return i915_draw_range_elements( pipe, indexBuffer,
00127                                         indexSize,
00128                                         0, 0xffffffff,
00129                                         prim, start, count );
00130 }
00131 
00132 static boolean i915_draw_arrays( struct pipe_context *pipe,
00133                                  unsigned prim, unsigned start, unsigned count)
00134 {
00135    return i915_draw_elements(pipe, NULL, 0, prim, start, count);
00136 }
00137 
00138 
00139 
00140 struct pipe_context *i915_create_context( struct pipe_screen *screen,
00141                                           struct pipe_winsys *pipe_winsys,
00142                                           struct i915_winsys *i915_winsys )
00143 {
00144    struct i915_context *i915;
00145 
00146    i915 = CALLOC_STRUCT(i915_context);
00147    if (i915 == NULL)
00148       return NULL;
00149 
00150    i915->winsys = i915_winsys;
00151    i915->pipe.winsys = pipe_winsys;
00152    i915->pipe.screen = screen;
00153 
00154    i915->pipe.destroy = i915_destroy;
00155 
00156    i915->pipe.clear = i915_clear;
00157 
00158 
00159    i915->pipe.draw_arrays = i915_draw_arrays;
00160    i915->pipe.draw_elements = i915_draw_elements;
00161    i915->pipe.draw_range_elements = i915_draw_range_elements;
00162 
00163    /*
00164     * Create drawing context and plug our rendering stage into it.
00165     */
00166    i915->draw = draw_create();
00167    assert(i915->draw);
00168    if (!debug_get_bool_option("I915_NO_VBUF", FALSE)) {
00169       draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915));
00170    }
00171    else {
00172       draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915));
00173    }
00174 
00175    i915_init_surface_functions(i915);
00176    i915_init_state_functions(i915);
00177    i915_init_flush_functions(i915);
00178    i915_init_texture_functions(i915);
00179 
00180    draw_install_aaline_stage(i915->draw, &i915->pipe);
00181    draw_install_aapoint_stage(i915->draw, &i915->pipe);
00182 
00183    i915->dirty = ~0;
00184    i915->hardware_dirty = ~0;
00185 
00186    /* Batch stream debugging is a bit hacked up at the moment:
00187     */
00188    i915->batch = i915_winsys->batch_get(i915_winsys);
00189    i915->batch->winsys = i915_winsys;
00190 
00191    return &i915->pipe;
00192 }
00193 

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