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/mesa_private.h"
33
#include "main/dispatch.h"
34
#include "glapi/glapi.h"
36
#include "vbo_private.h"
39
typedef void (*attr_func)(struct gl_context *ctx, GLint index, const GLfloat *);
42
/* This file makes heavy use of the aliasing of NV vertex attributes
43
* with the legacy attributes, and also with ARB and Material
44
* attributes as currently implemented.
47
VertexAttrib1fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
49
CALL_VertexAttrib1fvNV(ctx->Exec, (index, v));
54
VertexAttrib2fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
56
CALL_VertexAttrib2fvNV(ctx->Exec, (index, v));
61
VertexAttrib3fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
63
CALL_VertexAttrib3fvNV(ctx->Exec, (index, v));
68
VertexAttrib4fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
70
CALL_VertexAttrib4fvNV(ctx->Exec, (index, v));
74
static attr_func vert_attrfunc[4] = {
82
struct loopback_attr {
83
enum vbo_attrib index;
90
* Don't emit ends and begins on wrapped primitives. Don't replay
91
* wrapped vertices. If we get here, it's probably because the
92
* precalculated wrapping is wrong.
95
loopback_prim(struct gl_context *ctx,
96
const GLubyte *buffer,
97
const struct _mesa_prim *prim,
100
const struct loopback_attr *la, GLuint nr)
102
GLuint start = prim->start;
103
const GLuint end = start + prim->count;
107
printf("loopback prim %s(%s,%s) verts %d..%d vsize %d\n",
108
_mesa_lookup_prim_by_nr(prim->mode),
109
prim->begin ? "begin" : "..",
110
prim->end ? "end" : "..",
115
CALL_Begin(ctx->Exec, (prim->mode));
121
data = buffer + start * stride;
123
for (GLuint j = start; j < end; j++) {
124
for (GLuint k = 0; k < nr; k++)
125
la[k].func(ctx, la[k].index, (const GLfloat *)(data + la[k].offset));
131
CALL_End(ctx->Exec, ());
137
append_attr(GLuint *nr, struct loopback_attr la[], int i, int shift,
138
const struct gl_vertex_array_object *vao)
140
la[*nr].index = shift + i;
141
la[*nr].offset = vao->VertexAttrib[i].RelativeOffset;
142
la[*nr].func = vert_attrfunc[vao->VertexAttrib[i].Format.Size - 1];
148
_vbo_loopback_vertex_list(struct gl_context *ctx,
149
const struct vbo_save_vertex_list* node,
152
struct loopback_attr la[VBO_ATTRIB_MAX];
155
/* All Legacy, NV, ARB and Material attributes are routed through
156
* the NV attributes entrypoints:
158
const struct gl_vertex_array_object *vao = node->cold->VAO[VP_MODE_FF];
159
GLbitfield mask = vao->Enabled & VERT_BIT_MAT_ALL;
161
const int i = u_bit_scan(&mask);
162
append_attr(&nr, la, i, VBO_MATERIAL_SHIFT, vao);
165
vao = node->cold->VAO[VP_MODE_SHADER];
166
mask = vao->Enabled & ~(VERT_BIT_POS | VERT_BIT_GENERIC0);
168
const int i = u_bit_scan(&mask);
169
append_attr(&nr, la, i, 0, vao);
172
/* The last in the list should be the vertex provoking attribute */
173
if (vao->Enabled & VERT_BIT_GENERIC0) {
174
append_attr(&nr, la, VERT_ATTRIB_GENERIC0, 0, vao);
175
} else if (vao->Enabled & VERT_BIT_POS) {
176
append_attr(&nr, la, VERT_ATTRIB_POS, 0, vao);
179
const GLuint wrap_count = node->cold->wrap_count;
180
const GLuint stride = _vbo_save_get_stride(node);
182
/* Replay the primitives */
183
const struct _mesa_prim *prims = node->cold->prims;
184
const GLuint prim_count = node->cold->prim_count;
186
for (GLuint i = 0; i < prim_count; i++) {
187
loopback_prim(ctx, (GLubyte*)buffer + vao->BufferBinding[0].Offset,
188
&prims[i], wrap_count, stride, la, nr);