1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
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"
42 static void i915_destroy( struct pipe_context
*pipe
)
44 struct i915_context
*i915
= i915_context( pipe
);
46 draw_destroy( i915
->draw
);
53 i915_draw_range_elements(struct pipe_context
*pipe
,
54 struct pipe_buffer
*indexBuffer
,
58 unsigned prim
, unsigned start
, unsigned count
)
60 struct i915_context
*i915
= i915_context( pipe
);
61 struct draw_context
*draw
= i915
->draw
;
65 i915_update_derived( i915
);
70 for (i
= 0; i
< i915
->num_vertex_buffers
; i
++) {
72 = pipe
->winsys
->buffer_map(pipe
->winsys
,
73 i915
->vertex_buffer
[i
].buffer
,
74 PIPE_BUFFER_USAGE_CPU_READ
);
75 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
77 /* Map index buffer, if present */
80 = pipe
->winsys
->buffer_map(pipe
->winsys
, indexBuffer
,
81 PIPE_BUFFER_USAGE_CPU_READ
);
82 draw_set_mapped_element_buffer_range(draw
, indexSize
,
88 /* no index/element buffer */
89 draw_set_mapped_element_buffer(draw
, 0, NULL
);
93 draw_set_mapped_constant_buffer(draw
,
94 i915
->current
.constants
[PIPE_SHADER_VERTEX
],
95 ( i915
->current
.num_user_constants
[PIPE_SHADER_VERTEX
] *
99 draw_arrays(i915
->draw
, prim
, start
, count
);
102 * unmap vertex/index buffers
104 for (i
= 0; i
< i915
->num_vertex_buffers
; i
++) {
105 pipe
->winsys
->buffer_unmap(pipe
->winsys
, i915
->vertex_buffer
[i
].buffer
);
106 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
109 pipe
->winsys
->buffer_unmap(pipe
->winsys
, indexBuffer
);
110 draw_set_mapped_element_buffer_range(draw
, 0, start
, start
+ count
- 1, NULL
);
117 i915_draw_elements( struct pipe_context
*pipe
,
118 struct pipe_buffer
*indexBuffer
,
120 unsigned prim
, unsigned start
, unsigned count
)
122 return i915_draw_range_elements( pipe
, indexBuffer
,
125 prim
, start
, count
);
128 static boolean
i915_draw_arrays( struct pipe_context
*pipe
,
129 unsigned prim
, unsigned start
, unsigned count
)
131 return i915_draw_elements(pipe
, NULL
, 0, prim
, start
, count
);
136 struct pipe_context
*i915_create_context( struct pipe_screen
*screen
,
137 struct pipe_winsys
*pipe_winsys
,
138 struct i915_winsys
*i915_winsys
)
140 struct i915_context
*i915
;
142 i915
= CALLOC_STRUCT(i915_context
);
146 i915
->winsys
= i915_winsys
;
147 i915
->pipe
.winsys
= pipe_winsys
;
148 i915
->pipe
.screen
= screen
;
150 i915
->pipe
.destroy
= i915_destroy
;
152 i915
->pipe
.clear
= i915_clear
;
155 i915
->pipe
.draw_arrays
= i915_draw_arrays
;
156 i915
->pipe
.draw_elements
= i915_draw_elements
;
157 i915
->pipe
.draw_range_elements
= i915_draw_range_elements
;
160 * Create drawing context and plug our rendering stage into it.
162 i915
->draw
= draw_create();
164 if (!debug_get_bool_option("I915_NO_VBUF", FALSE
)) {
165 draw_set_rasterize_stage(i915
->draw
, i915_draw_vbuf_stage(i915
));
168 draw_set_rasterize_stage(i915
->draw
, i915_draw_render_stage(i915
));
171 i915_init_surface_functions(i915
);
172 i915_init_state_functions(i915
);
173 i915_init_flush_functions(i915
);
174 i915_init_texture_functions(i915
);
176 draw_install_aaline_stage(i915
->draw
, &i915
->pipe
);
177 draw_install_aapoint_stage(i915
->draw
, &i915
->pipe
);
180 i915
->hardware_dirty
= ~0;
182 /* Batch stream debugging is a bit hacked up at the moment:
184 i915
->batch
= i915_winsys
->batch_get(i915_winsys
);
185 i915
->batch
->winsys
= i915_winsys
;