• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2005 VMware, Inc.
4  * All Rights Reserved.
5  *
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:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
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.
25  *
26  **************************************************************************/
27 
28 #include <stdio.h>
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"
36 
37 #include "vbo_context.h"
38 
39 
40 typedef void (*attr_func)(struct gl_context *ctx, GLint index, const GLfloat *);
41 
42 
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.
46  */
47 static void
VertexAttrib1fvNV(struct gl_context * ctx,GLint index,const GLfloat * v)48 VertexAttrib1fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
49 {
50    CALL_VertexAttrib1fvNV(ctx->Exec, (index, v));
51 }
52 
53 
54 static void
VertexAttrib2fvNV(struct gl_context * ctx,GLint index,const GLfloat * v)55 VertexAttrib2fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
56 {
57    CALL_VertexAttrib2fvNV(ctx->Exec, (index, v));
58 }
59 
60 
61 static void
VertexAttrib3fvNV(struct gl_context * ctx,GLint index,const GLfloat * v)62 VertexAttrib3fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
63 {
64    CALL_VertexAttrib3fvNV(ctx->Exec, (index, v));
65 }
66 
67 
68 static void
VertexAttrib4fvNV(struct gl_context * ctx,GLint index,const GLfloat * v)69 VertexAttrib4fvNV(struct gl_context *ctx, GLint index, const GLfloat *v)
70 {
71    CALL_VertexAttrib4fvNV(ctx->Exec, (index, v));
72 }
73 
74 
75 static attr_func vert_attrfunc[4] = {
76    VertexAttrib1fvNV,
77    VertexAttrib2fvNV,
78    VertexAttrib3fvNV,
79    VertexAttrib4fvNV
80 };
81 
82 
83 struct loopback_attr {
84    GLint index;
85    GLint sz;
86    attr_func func;
87 };
88 
89 
90 /**
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.
94  */
95 static void
loopback_prim(struct gl_context * ctx,const GLfloat * buffer,const struct _mesa_prim * prim,GLuint wrap_count,GLuint vertex_size,const struct loopback_attr * la,GLuint nr)96 loopback_prim(struct gl_context *ctx,
97               const GLfloat *buffer,
98               const struct _mesa_prim *prim,
99               GLuint wrap_count,
100               GLuint vertex_size,
101               const struct loopback_attr *la, GLuint nr)
102 {
103    GLint start = prim->start;
104    GLint end = start + prim->count;
105    const GLfloat *data;
106    GLint j;
107    GLuint k;
108 
109    if (0)
110       printf("loopback prim %s(%s,%s) verts %d..%d  vsize %d\n",
111              _mesa_lookup_prim_by_nr(prim->mode),
112              prim->begin ? "begin" : "..",
113              prim->end ? "end" : "..",
114              start, end,
115              vertex_size);
116 
117    if (prim->begin) {
118       CALL_Begin(GET_DISPATCH(), (prim->mode));
119    }
120    else {
121       start += wrap_count;
122    }
123 
124    data = buffer + start * vertex_size;
125 
126    for (j = start; j < end; j++) {
127       const GLfloat *tmp = data + la[0].sz;
128 
129       for (k = 1; k < nr; k++) {
130          la[k].func(ctx, la[k].index, tmp);
131          tmp += la[k].sz;
132       }
133 
134       /* Fire the vertex
135        */
136       la[0].func(ctx, VBO_ATTRIB_POS, data);
137       data = tmp;
138    }
139 
140    if (prim->end) {
141       CALL_End(GET_DISPATCH(), ());
142    }
143 }
144 
145 
146 /**
147  * Primitives generated by DrawArrays/DrawElements/Rectf may be
148  * caught here.  If there is no primitive in progress, execute them
149  * normally, otherwise need to track and discard the generated
150  * primitives.
151  */
152 static void
loopback_weak_prim(struct gl_context * ctx,const struct _mesa_prim * prim)153 loopback_weak_prim(struct gl_context *ctx,
154                    const struct _mesa_prim *prim)
155 {
156    /* Use the prim_weak flag to ensure that if this primitive
157     * wraps, we don't mistake future vertex_lists for part of the
158     * surrounding primitive.
159     *
160     * While this flag is set, we are simply disposing of data
161     * generated by an operation now known to be a noop.
162     */
163    if (prim->begin)
164       ctx->Driver.CurrentExecPrimitive |= VBO_SAVE_PRIM_WEAK;
165    if (prim->end)
166       ctx->Driver.CurrentExecPrimitive &= ~VBO_SAVE_PRIM_WEAK;
167 }
168 
169 
170 void
vbo_loopback_vertex_list(struct gl_context * ctx,const GLfloat * buffer,const GLubyte * attrsz,const struct _mesa_prim * prim,GLuint prim_count,GLuint wrap_count,GLuint vertex_size)171 vbo_loopback_vertex_list(struct gl_context *ctx,
172                          const GLfloat *buffer,
173                          const GLubyte *attrsz,
174                          const struct _mesa_prim *prim,
175                          GLuint prim_count,
176                          GLuint wrap_count,
177                          GLuint vertex_size)
178 {
179    struct loopback_attr la[VBO_ATTRIB_MAX];
180    GLuint i, nr = 0;
181 
182    /* All Legacy, NV, ARB and Material attributes are routed through
183     * the NV attributes entrypoints:
184     */
185    for (i = 0; i < VBO_ATTRIB_MAX; i++) {
186       if (attrsz[i]) {
187          la[nr].index = i;
188          la[nr].sz = attrsz[i];
189          la[nr].func = vert_attrfunc[attrsz[i]-1];
190          nr++;
191       }
192    }
193 
194    for (i = 0; i < prim_count; i++) {
195       if ((prim[i].mode & VBO_SAVE_PRIM_WEAK) &&
196           _mesa_inside_begin_end(ctx)) {
197          loopback_weak_prim(ctx, &prim[i]);
198       } else {
199          loopback_prim(ctx, buffer, &prim[i], wrap_count, vertex_size, la, nr);
200       }
201    }
202 }
203