i915: Add missing include.
[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_inlines.h"
39 #include "util/u_memory.h"
40 #include "pipe/p_screen.h"
41
42
43 static void i915_destroy( struct pipe_context *pipe )
44 {
45 struct i915_context *i915 = i915_context( pipe );
46
47 draw_destroy( i915->draw );
48
49 if(i915->winsys->destroy)
50 i915->winsys->destroy(i915->winsys);
51
52 FREE( i915 );
53 }
54
55
56 static boolean
57 i915_draw_range_elements(struct pipe_context *pipe,
58 struct pipe_buffer *indexBuffer,
59 unsigned indexSize,
60 unsigned min_index,
61 unsigned max_index,
62 unsigned prim, unsigned start, unsigned count)
63 {
64 struct i915_context *i915 = i915_context( pipe );
65 struct draw_context *draw = i915->draw;
66 unsigned i;
67
68 if (i915->dirty)
69 i915_update_derived( i915 );
70
71 /*
72 * Map vertex buffers
73 */
74 for (i = 0; i < i915->num_vertex_buffers; i++) {
75 void *buf
76 = pipe_buffer_map(pipe->screen,
77 i915->vertex_buffer[i].buffer,
78 PIPE_BUFFER_USAGE_CPU_READ);
79 draw_set_mapped_vertex_buffer(draw, i, buf);
80 }
81 /* Map index buffer, if present */
82 if (indexBuffer) {
83 void *mapped_indexes
84 = pipe_buffer_map(pipe->screen, indexBuffer,
85 PIPE_BUFFER_USAGE_CPU_READ);
86 draw_set_mapped_element_buffer_range(draw, indexSize,
87 min_index,
88 max_index,
89 mapped_indexes);
90 }
91 else {
92 /* no index/element buffer */
93 draw_set_mapped_element_buffer(draw, 0, NULL);
94 }
95
96
97 draw_set_mapped_constant_buffer(draw,
98 i915->current.constants[PIPE_SHADER_VERTEX],
99 ( i915->current.num_user_constants[PIPE_SHADER_VERTEX] *
100 4 * sizeof(float) ));
101
102 /* draw! */
103 draw_arrays(i915->draw, prim, start, count);
104
105 /*
106 * unmap vertex/index buffers
107 */
108 for (i = 0; i < i915->num_vertex_buffers; i++) {
109 pipe_buffer_unmap(pipe->screen, i915->vertex_buffer[i].buffer);
110 draw_set_mapped_vertex_buffer(draw, i, NULL);
111 }
112 if (indexBuffer) {
113 pipe_buffer_unmap(pipe->screen, indexBuffer);
114 draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
115 }
116
117 return TRUE;
118 }
119
120 static boolean
121 i915_draw_elements( struct pipe_context *pipe,
122 struct pipe_buffer *indexBuffer,
123 unsigned indexSize,
124 unsigned prim, unsigned start, unsigned count)
125 {
126 return i915_draw_range_elements( pipe, indexBuffer,
127 indexSize,
128 0, 0xffffffff,
129 prim, start, count );
130 }
131
132 static boolean i915_draw_arrays( struct pipe_context *pipe,
133 unsigned prim, unsigned start, unsigned count)
134 {
135 return i915_draw_elements(pipe, NULL, 0, prim, start, count);
136 }
137
138
139
140 struct pipe_context *i915_create_context( struct pipe_screen *screen,
141 struct pipe_winsys *pipe_winsys,
142 struct i915_winsys *i915_winsys )
143 {
144 struct i915_context *i915;
145
146 i915 = CALLOC_STRUCT(i915_context);
147 if (i915 == NULL)
148 return NULL;
149
150 i915->winsys = i915_winsys;
151 i915->pipe.winsys = pipe_winsys;
152 i915->pipe.screen = screen;
153
154 i915->pipe.destroy = i915_destroy;
155
156 i915->pipe.clear = i915_clear;
157
158
159 i915->pipe.draw_arrays = i915_draw_arrays;
160 i915->pipe.draw_elements = i915_draw_elements;
161 i915->pipe.draw_range_elements = i915_draw_range_elements;
162
163 /*
164 * Create drawing context and plug our rendering stage into it.
165 */
166 i915->draw = draw_create();
167 assert(i915->draw);
168 if (!debug_get_bool_option("I915_NO_VBUF", FALSE)) {
169 draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915));
170 }
171 else {
172 draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915));
173 }
174
175 i915_init_surface_functions(i915);
176 i915_init_state_functions(i915);
177 i915_init_flush_functions(i915);
178 i915_init_texture_functions(i915);
179
180 draw_install_aaline_stage(i915->draw, &i915->pipe);
181 draw_install_aapoint_stage(i915->draw, &i915->pipe);
182
183 i915->dirty = ~0;
184 i915->hardware_dirty = ~0;
185
186 /* Batch stream debugging is a bit hacked up at the moment:
187 */
188 i915->batch = i915_winsys->batch_get(i915_winsys);
189 i915->batch->winsys = i915_winsys;
190
191 return &i915->pipe;
192 }
193