1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
34 #include "pipe/p_defines.h"
35 #include "pipe/p_context.h"
36 #include "util/u_prim.h"
38 #include "lp_context.h"
41 #include "draw/draw_context.h"
46 * Draw vertex arrays, with optional indexing, optional instancing.
47 * All the other drawing functions are implemented in terms of this function.
48 * Basically, map the vertex buffers (and drawing surfaces), then hand off
49 * the drawing to the 'draw' module.
52 llvmpipe_draw_range_elements_instanced(struct pipe_context
*pipe
,
53 struct pipe_resource
*indexBuffer
,
61 unsigned startInstance
,
62 unsigned instanceCount
)
64 struct llvmpipe_context
*lp
= llvmpipe_context(pipe
);
65 struct draw_context
*draw
= lp
->draw
;
69 llvmpipe_update_derived( lp
);
74 for (i
= 0; i
< lp
->num_vertex_buffers
; i
++) {
75 void *buf
= llvmpipe_resource_data(lp
->vertex_buffer
[i
].buffer
);
76 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
79 /* Map index buffer, if present */
81 void *mapped_indexes
= llvmpipe_resource_data(indexBuffer
);
82 draw_set_mapped_element_buffer_range(draw
,
90 /* no index/element buffer */
91 draw_set_mapped_element_buffer_range(draw
, 0, 0, start
,
92 start
+ count
- 1, NULL
);
94 llvmpipe_prepare_vertex_sampling(lp
,
95 lp
->num_vertex_sampler_views
,
96 lp
->vertex_sampler_views
);
99 draw_arrays_instanced(draw
, mode
, start
, count
,
100 startInstance
, instanceCount
);
103 * unmap vertex/index buffers
105 for (i
= 0; i
< lp
->num_vertex_buffers
; i
++) {
106 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
109 draw_set_mapped_element_buffer(draw
, 0, 0, NULL
);
111 llvmpipe_cleanup_vertex_sampling(lp
);
114 * TODO: Flush only when a user vertex/index buffer is present
115 * (or even better, modify draw module to do this
116 * internally when this condition is seen?)
123 llvmpipe_draw_arrays_instanced(struct pipe_context
*pipe
,
127 unsigned startInstance
,
128 unsigned instanceCount
)
130 llvmpipe_draw_range_elements_instanced(pipe
,
131 NULL
, /* no indexBuffer */
132 0, 0, /* indexSize, indexBias */
133 0, ~0, /* minIndex, maxIndex */
143 llvmpipe_draw_elements_instanced(struct pipe_context
*pipe
,
144 struct pipe_resource
*indexBuffer
,
150 unsigned startInstance
,
151 unsigned instanceCount
)
153 llvmpipe_draw_range_elements_instanced(pipe
,
155 indexSize
, indexBias
,
156 0, ~0, /* minIndex, maxIndex */
166 llvmpipe_draw_elements(struct pipe_context
*pipe
,
167 struct pipe_resource
*indexBuffer
,
174 llvmpipe_draw_range_elements_instanced(pipe
,
176 indexSize
, indexBias
,
177 0, 0xffffffff, /* min, maxIndex */
179 0, /* startInstance */
180 1); /* instanceCount */
185 llvmpipe_draw_range_elements(struct pipe_context
*pipe
,
186 struct pipe_resource
*indexBuffer
,
195 llvmpipe_draw_range_elements_instanced(pipe
,
197 indexSize
, indexBias
,
198 min_index
, max_index
,
200 0, /* startInstance */
201 1); /* instanceCount */
206 llvmpipe_draw_arrays(struct pipe_context
*pipe
,
211 llvmpipe_draw_range_elements_instanced(pipe
,
212 NULL
, /* indexBuffer */
215 0, ~0, /* min, maxIndex */
217 0, /* startInstance */
218 1); /* instanceCount */
223 llvmpipe_init_draw_funcs(struct llvmpipe_context
*llvmpipe
)
225 llvmpipe
->pipe
.draw_arrays
= llvmpipe_draw_arrays
;
226 llvmpipe
->pipe
.draw_elements
= llvmpipe_draw_elements
;
227 llvmpipe
->pipe
.draw_range_elements
= llvmpipe_draw_range_elements
;
228 llvmpipe
->pipe
.draw_arrays_instanced
= llvmpipe_draw_arrays_instanced
;
229 llvmpipe
->pipe
.draw_elements_instanced
= llvmpipe_draw_elements_instanced
;