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/internal/p_winsys_screen.h"
38 #include "pipe/p_inlines.h"
39 #include "util/u_memory.h"
40 #include "pipe/p_screen.h"
43 static void i915_destroy( struct pipe_context
*pipe
)
45 struct i915_context
*i915
= i915_context( pipe
);
47 draw_destroy( i915
->draw
);
49 if(i915
->winsys
->destroy
)
50 i915
->winsys
->destroy(i915
->winsys
);
57 i915_draw_range_elements(struct pipe_context
*pipe
,
58 struct pipe_buffer
*indexBuffer
,
62 unsigned prim
, unsigned start
, unsigned count
)
64 struct i915_context
*i915
= i915_context( pipe
);
65 struct draw_context
*draw
= i915
->draw
;
69 i915_update_derived( i915
);
74 for (i
= 0; i
< i915
->num_vertex_buffers
; i
++) {
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
);
81 /* Map index buffer, if present */
84 = pipe_buffer_map(pipe
->screen
, indexBuffer
,
85 PIPE_BUFFER_USAGE_CPU_READ
);
86 draw_set_mapped_element_buffer_range(draw
, indexSize
,
92 /* no index/element buffer */
93 draw_set_mapped_element_buffer(draw
, 0, NULL
);
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) ));
103 draw_arrays(i915
->draw
, prim
, start
, count
);
106 * unmap vertex/index buffers
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
);
113 pipe_buffer_unmap(pipe
->screen
, indexBuffer
);
114 draw_set_mapped_element_buffer_range(draw
, 0, start
, start
+ count
- 1, NULL
);
121 i915_draw_elements( struct pipe_context
*pipe
,
122 struct pipe_buffer
*indexBuffer
,
124 unsigned prim
, unsigned start
, unsigned count
)
126 return i915_draw_range_elements( pipe
, indexBuffer
,
129 prim
, start
, count
);
132 static boolean
i915_draw_arrays( struct pipe_context
*pipe
,
133 unsigned prim
, unsigned start
, unsigned count
)
135 return i915_draw_elements(pipe
, NULL
, 0, prim
, start
, count
);
140 i915_is_texture_referenced( struct pipe_context
*pipe
,
141 struct pipe_texture
*texture
,
142 unsigned face
, unsigned level
)
148 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
152 i915_is_buffer_referenced( struct pipe_context
*pipe
,
153 struct pipe_buffer
*buf
)
159 return PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
;
163 struct pipe_context
*i915_create_context( struct pipe_screen
*screen
,
164 struct pipe_winsys
*pipe_winsys
,
165 struct i915_winsys
*i915_winsys
)
167 struct i915_context
*i915
;
169 i915
= CALLOC_STRUCT(i915_context
);
173 i915
->winsys
= i915_winsys
;
174 i915
->pipe
.winsys
= pipe_winsys
;
175 i915
->pipe
.screen
= screen
;
177 i915
->pipe
.destroy
= i915_destroy
;
179 i915
->pipe
.clear
= i915_clear
;
182 i915
->pipe
.draw_arrays
= i915_draw_arrays
;
183 i915
->pipe
.draw_elements
= i915_draw_elements
;
184 i915
->pipe
.draw_range_elements
= i915_draw_range_elements
;
186 i915
->pipe
.is_texture_referenced
= i915_is_texture_referenced
;
187 i915
->pipe
.is_buffer_referenced
= i915_is_buffer_referenced
;
190 * Create drawing context and plug our rendering stage into it.
192 i915
->draw
= draw_create();
194 if (!debug_get_bool_option("I915_NO_VBUF", FALSE
)) {
195 draw_set_rasterize_stage(i915
->draw
, i915_draw_vbuf_stage(i915
));
198 draw_set_rasterize_stage(i915
->draw
, i915_draw_render_stage(i915
));
201 i915_init_surface_functions(i915
);
202 i915_init_state_functions(i915
);
203 i915_init_flush_functions(i915
);
204 i915_init_texture_functions(i915
);
206 draw_install_aaline_stage(i915
->draw
, &i915
->pipe
);
207 draw_install_aapoint_stage(i915
->draw
, &i915
->pipe
);
210 i915
->hardware_dirty
= ~0;
212 /* Batch stream debugging is a bit hacked up at the moment:
214 i915
->batch
= i915_winsys
->batch_get(i915_winsys
);
215 i915
->batch
->winsys
= i915_winsys
;