f1a93d6e434841e6e585c5f45de97cf9059a122f
1 /**************************************************************************
3 * Copyright 2005 VMware, Inc.
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 VMWARE 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 **************************************************************************/
29 #include "main/context.h"
30 #include "main/glheader.h"
31 #include "main/enums.h"
32 #include "main/imports.h"
33 #include "main/mtypes.h"
34 #include "main/dispatch.h"
35 #include "glapi/glapi.h"
37 #include "vbo_private.h"
40 typedef void (*attr_func
)(struct gl_context
*ctx
, GLint index
, const GLfloat
*);
43 /* This file makes heavy use of the aliasing of NV vertex attributes
44 * with the legacy attributes, and also with ARB and Material
45 * attributes as currently implemented.
48 VertexAttrib1fvNV(struct gl_context
*ctx
, GLint index
, const GLfloat
*v
)
50 CALL_VertexAttrib1fvNV(ctx
->Exec
, (index
, v
));
55 VertexAttrib2fvNV(struct gl_context
*ctx
, GLint index
, const GLfloat
*v
)
57 CALL_VertexAttrib2fvNV(ctx
->Exec
, (index
, v
));
62 VertexAttrib3fvNV(struct gl_context
*ctx
, GLint index
, const GLfloat
*v
)
64 CALL_VertexAttrib3fvNV(ctx
->Exec
, (index
, v
));
69 VertexAttrib4fvNV(struct gl_context
*ctx
, GLint index
, const GLfloat
*v
)
71 CALL_VertexAttrib4fvNV(ctx
->Exec
, (index
, v
));
75 static attr_func vert_attrfunc
[4] = {
83 struct loopback_attr
{
84 enum vbo_attrib index
;
91 * Don't emit ends and begins on wrapped primitives. Don't replay
92 * wrapped vertices. If we get here, it's probably because the
93 * precalculated wrapping is wrong.
96 loopback_prim(struct gl_context
*ctx
,
97 const GLubyte
*buffer
,
98 const struct _mesa_prim
*prim
,
101 const struct loopback_attr
*la
, GLuint nr
)
103 GLuint start
= prim
->start
;
104 const GLuint end
= start
+ prim
->count
;
108 printf("loopback prim %s(%s,%s) verts %d..%d vsize %d\n",
109 _mesa_lookup_prim_by_nr(prim
->mode
),
110 prim
->begin
? "begin" : "..",
111 prim
->end
? "end" : "..",
116 CALL_Begin(GET_DISPATCH(), (prim
->mode
));
122 data
= buffer
+ start
* stride
;
124 for (GLuint j
= start
; j
< end
; j
++) {
125 for (GLuint k
= 0; k
< nr
; k
++)
126 la
[k
].func(ctx
, la
[k
].index
, (const GLfloat
*)(data
+ la
[k
].offset
));
132 CALL_End(GET_DISPATCH(), ());
138 * Primitives generated by DrawArrays/DrawElements/Rectf may be
139 * caught here. If there is no primitive in progress, execute them
140 * normally, otherwise need to track and discard the generated
144 loopback_weak_prim(struct gl_context
*ctx
,
145 const struct _mesa_prim
*prim
)
147 /* Use the prim_weak flag to ensure that if this primitive
148 * wraps, we don't mistake future vertex_lists for part of the
149 * surrounding primitive.
151 * While this flag is set, we are simply disposing of data
152 * generated by an operation now known to be a noop.
155 ctx
->Driver
.CurrentExecPrimitive
|= VBO_SAVE_PRIM_WEAK
;
157 ctx
->Driver
.CurrentExecPrimitive
&= ~VBO_SAVE_PRIM_WEAK
;
162 append_attr(GLuint
*nr
, struct loopback_attr la
[], int i
, int shift
,
163 const struct gl_vertex_array_object
*vao
)
165 la
[*nr
].index
= shift
+ i
;
166 la
[*nr
].offset
= vao
->VertexAttrib
[i
].RelativeOffset
;
167 la
[*nr
].func
= vert_attrfunc
[vao
->VertexAttrib
[i
].Size
- 1];
173 _vbo_loopback_vertex_list(struct gl_context
*ctx
,
174 const struct vbo_save_vertex_list
* node
)
176 struct loopback_attr la
[VBO_ATTRIB_MAX
];
179 /* All Legacy, NV, ARB and Material attributes are routed through
180 * the NV attributes entrypoints:
182 const struct gl_vertex_array_object
*vao
= node
->VAO
[VP_MODE_FF
];
183 GLbitfield mask
= vao
->_Enabled
& VERT_BIT_MAT_ALL
;
185 const int i
= u_bit_scan(&mask
);
186 append_attr(&nr
, la
, i
, VBO_MATERIAL_SHIFT
, vao
);
189 vao
= node
->VAO
[VP_MODE_SHADER
];
190 mask
= vao
->_Enabled
& ~(VERT_BIT_POS
| VERT_BIT_GENERIC0
);
192 const int i
= u_bit_scan(&mask
);
193 append_attr(&nr
, la
, i
, 0, vao
);
196 /* The last in the list should be the vertex provoking attribute */
197 if (vao
->_Enabled
& VERT_BIT_GENERIC0
) {
198 append_attr(&nr
, la
, VERT_ATTRIB_GENERIC0
, 0, vao
);
199 } else if (vao
->_Enabled
& VERT_BIT_POS
) {
200 append_attr(&nr
, la
, VERT_ATTRIB_POS
, 0, vao
);
203 const GLuint wrap_count
= node
->wrap_count
;
204 const GLuint stride
= _vbo_save_get_stride(node
);
205 const GLubyte
*buffer
= NULL
;
207 /* Compute the minimal offset into the vertex buffer object */
209 for (GLuint i
= 0; i
< nr
; ++i
)
210 offset
= MIN2(offset
, la
[i
].offset
);
211 for (GLuint i
= 0; i
< nr
; ++i
)
212 la
[i
].offset
-= offset
;
214 /* Get the mapped base pointer, assert sufficient mapping */
215 struct gl_buffer_object
*bufferobj
= vao
->BufferBinding
[0].BufferObj
;
216 assert(bufferobj
&& bufferobj
->Mappings
[MAP_INTERNAL
].Pointer
);
217 buffer
= bufferobj
->Mappings
[MAP_INTERNAL
].Pointer
;
218 assert(bufferobj
->Mappings
[MAP_INTERNAL
].Offset
219 <= vao
->BufferBinding
[0].Offset
+ offset
220 + stride
*(_vbo_save_get_min_index(node
) + wrap_count
));
221 buffer
+= vao
->BufferBinding
[0].Offset
+ offset
222 - bufferobj
->Mappings
[MAP_INTERNAL
].Offset
;
223 assert(stride
*(_vbo_save_get_vertex_count(node
) - wrap_count
)
224 <= bufferobj
->Mappings
[MAP_INTERNAL
].Length
);
227 /* Replay the primitives */
228 const struct _mesa_prim
*prims
= node
->prims
;
229 const GLuint prim_count
= node
->prim_count
;
230 for (GLuint i
= 0; i
< prim_count
; i
++) {
231 if ((prims
[i
].mode
& VBO_SAVE_PRIM_WEAK
) && _mesa_inside_begin_end(ctx
)) {
232 loopback_weak_prim(ctx
, &prims
[i
]);
234 loopback_prim(ctx
, buffer
, &prims
[i
], wrap_count
, stride
, la
, nr
);