00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
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
00103 draw_arrays(i915->draw, prim, start, count);
00104
00105
00106
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
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
00187
00188 i915->batch = i915_winsys->batch_get(i915_winsys);
00189 i915->batch->winsys = i915_winsys;
00190
00191 return &i915->pipe;
00192 }
00193