3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
29 /* Deal with hardware and/or swtnl maximums:
30 * - maximum number of vertices in buffer
31 * - maximum number of elements (maybe zero)
33 * The maximums may vary with opengl state (eg if a larger hardware
34 * vertex is required in this state, the maximum number of vertices
35 * may be smaller than in another state).
37 * We want buffer splitting to be a convenience function for the code
38 * actually drawing the primitives rather than a system-wide maximum,
39 * otherwise it is hard to avoid pessimism.
41 * For instance, if a driver has no hardware limits on vertex buffer
42 * dimensions, it would not ordinarily want to split vbos. But if
43 * there is an unexpected fallback, eg memory manager fails to upload
44 * textures, it will want to pass the drawing commands onto swtnl,
45 * which does have limitations. A convenience function allows swtnl
46 * to split the drawing and vbos internally without imposing its
47 * limitations on drivers which want to use it as a fallback path.
54 #include "vbo_split.h"
57 /* True if a primitive can be split without copying of vertices, false
60 GLboolean
split_prim_inplace(GLenum mode
, GLuint
*first
, GLuint
*incr
)
79 case GL_TRIANGLE_STRIP
:
93 *incr
= 1; /* so that count % incr works */
100 void vbo_split_prims( GLcontext
*ctx
,
101 const struct gl_client_array
*arrays
[],
102 const struct _mesa_prim
*prim
,
104 const struct _mesa_index_buffer
*ib
,
108 const struct split_limits
*limits
)
112 if (limits
->max_indices
== 0) {
113 /* Could traverse the indices, re-emitting vertices in turn.
114 * But it's hard to see why this case would be needed - for
115 * software tnl, it is better to convert to non-indexed
116 * rendering after transformation is complete, as is done in
117 * the t_dd_rendertmp.h templates. Are there any devices
118 * with hardware tnl that cannot do indexed rendering?
120 * For now, this path is disabled.
124 else if (max_index
- min_index
>= limits
->max_verts
) {
125 /* The vertex buffers are too large for hardware (or the
126 * swtnl module). Traverse the indices, re-emitting vertices
127 * in turn. Use a vertex cache to preserve some of the
128 * sharing from the original index list.
130 vbo_split_copy(ctx
, arrays
, prim
, nr_prims
, ib
,
133 else if (ib
->count
> limits
->max_indices
) {
134 /* The index buffer is too large for hardware. Try to split
135 * on whole-primitive boundaries, otherwise try to split the
136 * individual primitives.
138 vbo_split_inplace(ctx
, arrays
, prim
, nr_prims
, ib
,
139 min_index
, max_index
, draw
, limits
);
142 /* Why were we called? */
147 if (max_index
- min_index
>= limits
->max_verts
) {
148 /* The vertex buffer is too large for hardware (or the swtnl
149 * module). Try to split on whole-primitive boundaries,
150 * otherwise try to split the individual primitives.
152 vbo_split_inplace(ctx
, arrays
, prim
, nr_prims
, ib
,
153 min_index
, max_index
, draw
, limits
);
156 /* Why were we called? */