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_state.h"
30 #include "i915_screen.h"
31 #include "i915_surface.h"
32 #include "i915_batch.h"
33 #include "i915_resource.h"
35 #include "draw/draw_context.h"
36 #include "pipe/p_defines.h"
37 #include "util/u_inlines.h"
38 #include "util/u_memory.h"
39 #include "pipe/p_screen.h"
42 DEBUG_GET_ONCE_BOOL_OPTION(i915_no_vbuf
, "I915_NO_VBUF", FALSE
);
51 i915_draw_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
)
53 struct i915_context
*i915
= i915_context(pipe
);
54 struct draw_context
*draw
= i915
->draw
;
55 void *mapped_indices
= NULL
;
60 * Ack vs contants here, helps ipers a lot.
62 cbuf_dirty
= i915
->dirty
& I915_NEW_VS_CONSTANTS
;
63 i915
->dirty
&= ~I915_NEW_VS_CONSTANTS
;
66 i915_update_derived(i915
);
69 * Map index buffer, if present
71 if (info
->indexed
&& i915
->index_buffer
.buffer
)
72 mapped_indices
= i915_buffer(i915
->index_buffer
.buffer
)->data
;
73 draw_set_mapped_index_buffer(draw
, mapped_indices
);
76 draw_set_mapped_constant_buffer(draw
, PIPE_SHADER_VERTEX
, 0,
77 i915_buffer(i915
->constants
[PIPE_SHADER_VERTEX
])->data
,
78 (i915
->current
.num_user_constants
[PIPE_SHADER_VERTEX
] *
85 draw_vbo(i915
->draw
, info
);
88 draw_set_mapped_index_buffer(draw
, NULL
);
93 * Generic context functions
97 static void i915_destroy(struct pipe_context
*pipe
)
99 struct i915_context
*i915
= i915_context(pipe
);
102 draw_destroy(i915
->draw
);
105 i915
->iws
->batchbuffer_destroy(i915
->batch
);
107 /* unbind framebuffer */
108 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
109 pipe_surface_reference(&i915
->framebuffer
.cbufs
[i
], NULL
);
111 pipe_surface_reference(&i915
->framebuffer
.zsbuf
, NULL
);
113 /* unbind constant buffers */
114 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
115 pipe_resource_reference(&i915
->constants
[i
], NULL
);
121 struct pipe_context
*
122 i915_create_context(struct pipe_screen
*screen
, void *priv
)
124 struct i915_context
*i915
;
126 i915
= CALLOC_STRUCT(i915_context
);
130 i915
->iws
= i915_screen(screen
)->iws
;
131 i915
->base
.winsys
= NULL
;
132 i915
->base
.screen
= screen
;
133 i915
->base
.priv
= priv
;
135 i915
->base
.destroy
= i915_destroy
;
137 i915
->base
.clear
= i915_clear
;
139 i915
->base
.draw_vbo
= i915_draw_vbo
;
141 /* init this before draw */
142 util_slab_create(&i915
->transfer_pool
, sizeof(struct pipe_transfer
),
143 16, UTIL_SLAB_SINGLETHREADED
);
146 * Create drawing context and plug our rendering stage into it.
148 i915
->draw
= draw_create(&i915
->base
);
150 if (!debug_get_option_i915_no_vbuf()) {
151 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_resource_functions(i915
);
161 draw_install_aaline_stage(i915
->draw
, &i915
->base
);
162 draw_install_aapoint_stage(i915
->draw
, &i915
->base
);
165 i915
->hardware_dirty
= ~0;
167 /* Batch stream debugging is a bit hacked up at the moment:
169 i915
->batch
= i915
->iws
->batchbuffer_create(i915
->iws
);