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_elements( struct pipe_context
*pipe
,
54 struct pipe_buffer
*indexBuffer
,
56 unsigned prim
, unsigned start
, unsigned count
)
58 struct i915_context
*i915
= i915_context( pipe
);
59 struct draw_context
*draw
= i915
->draw
;
63 i915_update_derived( i915
);
68 for (i
= 0; i
< PIPE_ATTRIB_MAX
; i
++) {
69 if (i915
->vertex_buffer
[i
].buffer
) {
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
);
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(draw
, indexSize
, mapped_indexes
);
85 /* no index/element buffer */
86 draw_set_mapped_element_buffer(draw
, 0, NULL
);
90 draw_set_mapped_constant_buffer(draw
,
91 i915
->current
.constants
[PIPE_SHADER_VERTEX
]);
94 draw_arrays(i915
->draw
, prim
, start
, count
);
97 * unmap vertex/index buffers
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
);
106 pipe
->winsys
->buffer_unmap(pipe
->winsys
, indexBuffer
);
107 draw_set_mapped_element_buffer(draw
, 0, NULL
);
114 static boolean
i915_draw_arrays( struct pipe_context
*pipe
,
115 unsigned prim
, unsigned start
, unsigned count
)
117 return i915_draw_elements(pipe
, NULL
, 0, prim
, start
, count
);
122 struct pipe_context
*i915_create_context( struct pipe_screen
*screen
,
123 struct pipe_winsys
*pipe_winsys
,
124 struct i915_winsys
*i915_winsys
)
126 struct i915_context
*i915
;
128 i915
= CALLOC_STRUCT(i915_context
);
132 i915
->winsys
= i915_winsys
;
133 i915
->pipe
.winsys
= pipe_winsys
;
134 i915
->pipe
.screen
= screen
;
136 i915
->pipe
.destroy
= i915_destroy
;
138 i915
->pipe
.clear
= i915_clear
;
141 i915
->pipe
.draw_arrays
= i915_draw_arrays
;
142 i915
->pipe
.draw_elements
= i915_draw_elements
;
145 * Create drawing context and plug our rendering stage into it.
147 i915
->draw
= draw_create();
149 if (GETENV("I915_VBUF")) {
150 draw_set_rasterize_stage(i915
->draw
, i915_draw_vbuf_stage(i915
));
153 draw_set_rasterize_stage(i915
->draw
, i915_draw_render_stage(i915
));
156 i915_init_surface_functions(i915
);
157 i915_init_state_functions(i915
);
158 i915_init_flush_functions(i915
);
159 i915_init_texture_functions(i915
);
161 draw_install_aaline_stage(i915
->draw
, &i915
->pipe
);
162 draw_install_aapoint_stage(i915
->draw
, &i915
->pipe
);
165 i915
->hardware_dirty
= ~0;
167 /* Batch stream debugging is a bit hacked up at the moment:
169 i915
->batch_start
= NULL
;