Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1901 | serge | 1 | |
2 | * Mesa 3-D graphics library |
||
3 | * Version: 6.5 |
||
4 | * |
||
5 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
||
6 | * |
||
7 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
8 | * copy of this software and associated documentation files (the "Software"), |
||
9 | * to deal in the Software without restriction, including without limitation |
||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
11 | * and/or sell copies of the Software, and to permit persons to whom the |
||
12 | * Software is furnished to do so, subject to the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice shall be included |
||
15 | * in all copies or substantial portions of the Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
23 | * |
||
24 | * Authors: |
||
25 | * Keith Whitwell |
||
26 | */ |
||
27 | |||
28 | |||
29 | * - maximum number of vertices in buffer |
||
30 | * - maximum number of elements (maybe zero) |
||
31 | * |
||
32 | * The maximums may vary with opengl state (eg if a larger hardware |
||
33 | * vertex is required in this state, the maximum number of vertices |
||
34 | * may be smaller than in another state). |
||
35 | * |
||
36 | * We want buffer splitting to be a convenience function for the code |
||
37 | * actually drawing the primitives rather than a system-wide maximum, |
||
38 | * otherwise it is hard to avoid pessimism. |
||
39 | * |
||
40 | * For instance, if a driver has no hardware limits on vertex buffer |
||
41 | * dimensions, it would not ordinarily want to split vbos. But if |
||
42 | * there is an unexpected fallback, eg memory manager fails to upload |
||
43 | * textures, it will want to pass the drawing commands onto swtnl, |
||
44 | * which does have limitations. A convenience function allows swtnl |
||
45 | * to split the drawing and vbos internally without imposing its |
||
46 | * limitations on drivers which want to use it as a fallback path. |
||
47 | */ |
||
48 | |||
49 | |||
50 | #include "main/imports.h" |
||
51 | #include "main/mtypes.h" |
||
52 | #include "main/macros.h" |
||
53 | |||
54 | |||
55 | #include "vbo.h" |
||
56 | |||
57 | |||
58 | * otherwise. |
||
59 | */ |
||
60 | GLboolean split_prim_inplace(GLenum mode, GLuint *first, GLuint *incr) |
||
61 | { |
||
62 | switch (mode) { |
||
63 | case GL_POINTS: |
||
64 | *first = 1; |
||
65 | *incr = 1; |
||
66 | return GL_TRUE; |
||
67 | case GL_LINES: |
||
68 | *first = 2; |
||
69 | *incr = 2; |
||
70 | return GL_TRUE; |
||
71 | case GL_LINE_STRIP: |
||
72 | *first = 2; |
||
73 | *incr = 1; |
||
74 | return GL_TRUE; |
||
75 | case GL_TRIANGLES: |
||
76 | *first = 3; |
||
77 | *incr = 3; |
||
78 | return GL_TRUE; |
||
79 | case GL_TRIANGLE_STRIP: |
||
80 | *first = 3; |
||
81 | *incr = 1; |
||
82 | return GL_TRUE; |
||
83 | case GL_QUADS: |
||
84 | *first = 4; |
||
85 | *incr = 4; |
||
86 | return GL_TRUE; |
||
87 | case GL_QUAD_STRIP: |
||
88 | *first = 4; |
||
89 | *incr = 2; |
||
90 | return GL_TRUE; |
||
91 | default: |
||
92 | *first = 0; |
||
93 | *incr = 1; /* so that count % incr works */ |
||
94 | return GL_FALSE; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | |||
99 | |||
100 | |||
101 | const struct gl_client_array *arrays[], |
||
102 | const struct _mesa_prim *prim, |
||
103 | GLuint nr_prims, |
||
104 | const struct _mesa_index_buffer *ib, |
||
105 | GLuint min_index, |
||
106 | GLuint max_index, |
||
107 | vbo_draw_func draw, |
||
108 | const struct split_limits *limits ) |
||
109 | { |
||
110 | GLint max_basevertex = prim->basevertex; |
||
111 | GLuint i; |
||
112 | |||
113 | |||
114 | max_basevertex = MAX2(max_basevertex, prim[i].basevertex); |
||
115 | |||
116 | |||
117 | |||
118 | |||
119 | if (limits->max_indices == 0) { |
||
120 | /* Could traverse the indices, re-emitting vertices in turn. |
||
121 | * But it's hard to see why this case would be needed - for |
||
122 | * software tnl, it is better to convert to non-indexed |
||
123 | * rendering after transformation is complete, as is done in |
||
124 | * the t_dd_rendertmp.h templates. Are there any devices |
||
125 | * with hardware tnl that cannot do indexed rendering? |
||
126 | * |
||
127 | * For now, this path is disabled. |
||
128 | */ |
||
129 | assert(0); |
||
130 | } |
||
131 | else if (max_index - min_index >= limits->max_verts) { |
||
132 | /* The vertex buffers are too large for hardware (or the |
||
133 | * swtnl module). Traverse the indices, re-emitting vertices |
||
134 | * in turn. Use a vertex cache to preserve some of the |
||
135 | * sharing from the original index list. |
||
136 | */ |
||
137 | vbo_split_copy(ctx, arrays, prim, nr_prims, ib, |
||
138 | draw, limits ); |
||
139 | } |
||
140 | else if (ib->count > limits->max_indices) { |
||
141 | /* The index buffer is too large for hardware. Try to split |
||
142 | * on whole-primitive boundaries, otherwise try to split the |
||
143 | * individual primitives. |
||
144 | */ |
||
145 | vbo_split_inplace(ctx, arrays, prim, nr_prims, ib, |
||
146 | min_index, max_index, draw, limits ); |
||
147 | } |
||
148 | else { |
||
149 | /* Why were we called? */ |
||
150 | assert(0); |
||
151 | } |
||
152 | } |
||
153 | else { |
||
154 | if (max_index - min_index >= limits->max_verts) { |
||
155 | /* The vertex buffer is too large for hardware (or the swtnl |
||
156 | * module). Try to split on whole-primitive boundaries, |
||
157 | * otherwise try to split the individual primitives. |
||
158 | */ |
||
159 | vbo_split_inplace(ctx, arrays, prim, nr_prims, ib, |
||
160 | min_index, max_index, draw, limits ); |
||
161 | } |
||
162 | else { |
||
163 | /* Why were we called? */ |
||
164 | assert(0); |
||
165 | } |
||
166 | } |
||
167 | }> |
||
168 |