2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "vbo_context.h"
37 static void vbo_exec_debug_verts( struct vbo_exec_context
*exec
)
39 GLuint count
= exec
->vtx
.vert_count
;
42 _mesa_printf("%s: %u vertices %d primitives, %d vertsize\n",
46 exec
->vtx
.vertex_size
);
48 for (i
= 0 ; i
< exec
->vtx
.prim_count
; i
++) {
49 struct _mesa_prim
*prim
= &exec
->vtx
.prim
[i
];
50 _mesa_printf(" prim %d: %s%s %d..%d %s %s\n",
52 _mesa_lookup_enum_by_nr(prim
->mode
),
53 prim
->weak
? " (weak)" : "",
55 prim
->start
+ prim
->count
,
56 prim
->begin
? "BEGIN" : "(wrap)",
57 prim
->end
? "END" : "(wrap)");
63 * NOTE: Need to have calculated primitives by this point -- do it on the fly.
64 * NOTE: Old 'parity' issue is gone.
66 static GLuint
vbo_copy_vertices( struct vbo_exec_context
*exec
)
68 GLuint nr
= exec
->vtx
.prim
[exec
->vtx
.prim_count
-1].count
;
70 GLuint sz
= exec
->vtx
.vertex_size
;
71 GLfloat
*dst
= exec
->vtx
.copied
.buffer
;
72 GLfloat
*src
= ((GLfloat
*)exec
->vtx
.buffer_map
+
73 exec
->vtx
.prim
[exec
->vtx
.prim_count
-1].start
*
74 exec
->vtx
.vertex_size
);
77 switch( exec
->ctx
->Driver
.CurrentExecPrimitive
)
83 for (i
= 0 ; i
< ovf
; i
++)
84 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
* sizeof(GLfloat
) );
88 for (i
= 0 ; i
< ovf
; i
++)
89 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
* sizeof(GLfloat
) );
93 for (i
= 0 ; i
< ovf
; i
++)
94 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
* sizeof(GLfloat
) );
100 _mesa_memcpy( dst
, src
+(nr
-1)*sz
, sz
* sizeof(GLfloat
) );
104 case GL_TRIANGLE_FAN
:
109 _mesa_memcpy( dst
, src
+0, sz
* sizeof(GLfloat
) );
112 _mesa_memcpy( dst
, src
+0, sz
* sizeof(GLfloat
) );
113 _mesa_memcpy( dst
+sz
, src
+(nr
-1)*sz
, sz
* sizeof(GLfloat
) );
116 case GL_TRIANGLE_STRIP
:
117 /* no parity issue, but need to make sure the tri is not drawn twice */
119 exec
->vtx
.prim
[exec
->vtx
.prim_count
-1].count
--;
124 case 0: ovf
= 0; break;
125 case 1: ovf
= 1; break;
126 default: ovf
= 2 + (nr
&1); break;
128 for (i
= 0 ; i
< ovf
; i
++)
129 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
* sizeof(GLfloat
) );
141 /* TODO: populate these as the vertex is defined:
143 static void vbo_exec_bind_arrays( GLcontext
*ctx
)
145 struct vbo_context
*vbo
= vbo_context(ctx
);
146 struct vbo_exec_context
*exec
= &vbo
->exec
;
147 struct gl_client_array
*arrays
= exec
->vtx
.arrays
;
148 GLuint count
= exec
->vtx
.vert_count
;
149 GLubyte
*data
= exec
->vtx
.buffer_map
;
153 /* Install the default (ie Current) attributes first, then overlay
156 switch (get_program_mode(exec
->ctx
)) {
158 memcpy(arrays
, vbo
->legacy_currval
, 16 * sizeof(arrays
[0]));
159 memcpy(arrays
+ 16, vbo
->mat_currval
, MAT_ATTRIB_MAX
* sizeof(arrays
[0]));
160 map
= vbo
->map_vp_none
;
164 /* The aliasing of attributes for NV vertex programs has already
165 * occurred. NV vertex programs cannot access material values,
166 * nor attributes greater than VERT_ATTRIB_TEX7.
168 memcpy(arrays
, vbo
->legacy_currval
, 16 * sizeof(arrays
[0]));
169 memcpy(arrays
+ 16, vbo
->generic_currval
, 16 * sizeof(arrays
[0]));
170 map
= vbo
->map_vp_arb
;
174 /* Make all active attributes (including edgeflag) available as
177 for (attr
= 0; attr
< VERT_ATTRIB_MAX
; attr
++) {
178 GLuint src
= map
[attr
];
180 if (exec
->vtx
.attrsz
[src
]) {
181 arrays
[attr
].Ptr
= (void *)data
;
182 arrays
[attr
].Size
= exec
->vtx
.attrsz
[src
];
183 arrays
[attr
].StrideB
= exec
->vtx
.vertex_size
* sizeof(GLfloat
);
184 arrays
[attr
].Stride
= exec
->vtx
.vertex_size
* sizeof(GLfloat
);
185 arrays
[attr
].Type
= GL_FLOAT
;
186 arrays
[attr
].Enabled
= 1;
187 arrays
[attr
].BufferObj
= exec
->vtx
.bufferobj
; /* NullBufferObj */
188 arrays
[attr
]._MaxElement
= count
; /* ??? */
190 data
+= exec
->vtx
.attrsz
[attr
] * sizeof(GLfloat
);
197 * Execute the buffer and save copied verts.
199 void vbo_exec_vtx_flush( struct vbo_exec_context
*exec
)
202 vbo_exec_debug_verts( exec
);
205 if (exec
->vtx
.prim_count
&&
206 exec
->vtx
.vert_count
) {
208 exec
->vtx
.copied
.nr
= vbo_copy_vertices( exec
);
210 if (exec
->vtx
.copied
.nr
!= exec
->vtx
.vert_count
) {
211 GLcontext
*ctx
= exec
->ctx
;
213 vbo_exec_bind_arrays( ctx
);
215 vbo_context(ctx
)->draw_prims( ctx
,
218 exec
->vtx
.prim_count
,
221 exec
->vtx
.vert_count
- 1);
225 exec
->vtx
.prim_count
= 0;
226 exec
->vtx
.vert_count
= 0;
227 exec
->vtx
.vbptr
= (GLfloat
*)exec
->vtx
.buffer_map
;