gallium: add face, dirtyLevels params to pipe->texture_update()
[mesa.git] / src / gallium / drivers / i915simple / i915_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "i915_context.h"
29 #include "i915_winsys.h"
30 #include "i915_state.h"
31 #include "i915_batch.h"
32 #include "i915_texture.h"
33 #include "i915_reg.h"
34
35 #include "draw/draw_context.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_winsys.h"
38 #include "pipe/p_util.h"
39 #include "pipe/p_screen.h"
40
41
42 static void i915_destroy( struct pipe_context *pipe )
43 {
44 struct i915_context *i915 = i915_context( pipe );
45
46 draw_destroy( i915->draw );
47
48 FREE( i915 );
49 }
50
51
52 static boolean
53 i915_draw_elements( struct pipe_context *pipe,
54 struct pipe_buffer *indexBuffer,
55 unsigned indexSize,
56 unsigned prim, unsigned start, unsigned count)
57 {
58 struct i915_context *i915 = i915_context( pipe );
59 struct draw_context *draw = i915->draw;
60 unsigned i;
61
62 if (i915->dirty)
63 i915_update_derived( i915 );
64
65 /*
66 * Map vertex buffers
67 */
68 for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
69 if (i915->vertex_buffer[i].buffer) {
70 void *buf
71 = pipe->winsys->buffer_map(pipe->winsys,
72 i915->vertex_buffer[i].buffer,
73 PIPE_BUFFER_USAGE_CPU_READ);
74 draw_set_mapped_vertex_buffer(draw, i, buf);
75 }
76 }
77 /* Map index buffer, if present */
78 if (indexBuffer) {
79 void *mapped_indexes
80 = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
81 PIPE_BUFFER_USAGE_CPU_READ);
82 draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
83 }
84 else {
85 /* no index/element buffer */
86 draw_set_mapped_element_buffer(draw, 0, NULL);
87 }
88
89
90 draw_set_mapped_constant_buffer(draw,
91 i915->current.constants[PIPE_SHADER_VERTEX]);
92
93 /* draw! */
94 draw_arrays(i915->draw, prim, start, count);
95
96 /*
97 * unmap vertex/index buffers
98 */
99 for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
100 if (i915->vertex_buffer[i].buffer) {
101 pipe->winsys->buffer_unmap(pipe->winsys, i915->vertex_buffer[i].buffer);
102 draw_set_mapped_vertex_buffer(draw, i, NULL);
103 }
104 }
105 if (indexBuffer) {
106 pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
107 draw_set_mapped_element_buffer(draw, 0, NULL);
108 }
109
110 return TRUE;
111 }
112
113
114 static boolean i915_draw_arrays( struct pipe_context *pipe,
115 unsigned prim, unsigned start, unsigned count)
116 {
117 return i915_draw_elements(pipe, NULL, 0, prim, start, count);
118 }
119
120
121
122 struct pipe_context *i915_create_context( struct pipe_screen *screen,
123 struct pipe_winsys *pipe_winsys,
124 struct i915_winsys *i915_winsys )
125 {
126 struct i915_context *i915;
127
128 i915 = CALLOC_STRUCT(i915_context);
129 if (i915 == NULL)
130 return NULL;
131
132 i915->winsys = i915_winsys;
133 i915->pipe.winsys = pipe_winsys;
134 i915->pipe.screen = screen;
135
136 i915->pipe.destroy = i915_destroy;
137
138 i915->pipe.clear = i915_clear;
139
140
141 i915->pipe.draw_arrays = i915_draw_arrays;
142 i915->pipe.draw_elements = i915_draw_elements;
143
144 /*
145 * Create drawing context and plug our rendering stage into it.
146 */
147 i915->draw = draw_create();
148 assert(i915->draw);
149 if (GETENV("I915_VBUF")) {
150 draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915));
151 }
152 else {
153 draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915));
154 }
155
156 i915_init_surface_functions(i915);
157 i915_init_state_functions(i915);
158 i915_init_flush_functions(i915);
159 i915_init_texture_functions(i915);
160
161 draw_install_aaline_stage(i915->draw, &i915->pipe);
162 draw_install_aapoint_stage(i915->draw, &i915->pipe);
163
164 i915->dirty = ~0;
165 i915->hardware_dirty = ~0;
166
167 /* Batch stream debugging is a bit hacked up at the moment:
168 */
169 i915->batch_start = NULL;
170
171 return &i915->pipe;
172 }
173