[MESA]
[reactos.git] / reactos / dll / opengl / mesa / vbo / vbo_save_loopback.c
1 /**************************************************************************
2 *
3 * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <precomp.h>
29
30 #if FEATURE_dlist
31
32
33 typedef void (*attr_func)( struct gl_context *ctx, GLint target, const GLfloat * );
34
35
36 /* This file makes heavy use of the aliasing of NV vertex attributes
37 * with the legacy attributes, and also with ARB and Material
38 * attributes as currently implemented.
39 */
40 static void VertexAttrib1fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
41 {
42 CALL_VertexAttrib1fvNV(ctx->Exec, (target, v));
43 }
44
45 static void VertexAttrib2fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
46 {
47 CALL_VertexAttrib2fvNV(ctx->Exec, (target, v));
48 }
49
50 static void VertexAttrib3fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
51 {
52 CALL_VertexAttrib3fvNV(ctx->Exec, (target, v));
53 }
54
55 static void VertexAttrib4fvNV(struct gl_context *ctx, GLint target, const GLfloat *v)
56 {
57 CALL_VertexAttrib4fvNV(ctx->Exec, (target, v));
58 }
59
60 static attr_func vert_attrfunc[4] = {
61 VertexAttrib1fvNV,
62 VertexAttrib2fvNV,
63 VertexAttrib3fvNV,
64 VertexAttrib4fvNV
65 };
66
67 struct loopback_attr {
68 GLint target;
69 GLint sz;
70 attr_func func;
71 };
72
73 /* Don't emit ends and begins on wrapped primitives. Don't replay
74 * wrapped vertices. If we get here, it's probably because the
75 * precalculated wrapping is wrong.
76 */
77 static void loopback_prim( struct gl_context *ctx,
78 const GLfloat *buffer,
79 const struct _mesa_prim *prim,
80 GLuint wrap_count,
81 GLuint vertex_size,
82 const struct loopback_attr *la, GLuint nr )
83 {
84 GLint start = prim->start;
85 GLint end = start + prim->count;
86 const GLfloat *data;
87 GLint j;
88 GLuint k;
89
90 if (0)
91 printf("loopback prim %s(%s,%s) verts %d..%d\n",
92 _mesa_lookup_prim_by_nr(prim->mode),
93 prim->begin ? "begin" : "..",
94 prim->end ? "end" : "..",
95 start,
96 end);
97
98 if (prim->begin) {
99 CALL_Begin(GET_DISPATCH(), ( prim->mode ));
100 }
101 else {
102 assert(start == 0);
103 start += wrap_count;
104 }
105
106 data = buffer + start * vertex_size;
107
108 for (j = start ; j < end ; j++) {
109 const GLfloat *tmp = data + la[0].sz;
110
111 for (k = 1 ; k < nr ; k++) {
112 la[k].func( ctx, la[k].target, tmp );
113 tmp += la[k].sz;
114 }
115
116 /* Fire the vertex
117 */
118 la[0].func( ctx, VBO_ATTRIB_POS, data );
119 data = tmp;
120 }
121
122 if (prim->end) {
123 CALL_End(GET_DISPATCH(), ());
124 }
125 }
126
127 /* Primitives generated by DrawArrays/DrawElements/Rectf may be
128 * caught here. If there is no primitive in progress, execute them
129 * normally, otherwise need to track and discard the generated
130 * primitives.
131 */
132 static void loopback_weak_prim( struct gl_context *ctx,
133 const struct _mesa_prim *prim )
134 {
135 /* Use the prim_weak flag to ensure that if this primitive
136 * wraps, we don't mistake future vertex_lists for part of the
137 * surrounding primitive.
138 *
139 * While this flag is set, we are simply disposing of data
140 * generated by an operation now known to be a noop.
141 */
142 if (prim->begin)
143 ctx->Driver.CurrentExecPrimitive |= VBO_SAVE_PRIM_WEAK;
144 if (prim->end)
145 ctx->Driver.CurrentExecPrimitive &= ~VBO_SAVE_PRIM_WEAK;
146 }
147
148
149 void vbo_loopback_vertex_list( struct gl_context *ctx,
150 const GLfloat *buffer,
151 const GLubyte *attrsz,
152 const struct _mesa_prim *prim,
153 GLuint prim_count,
154 GLuint wrap_count,
155 GLuint vertex_size)
156 {
157 struct loopback_attr la[VBO_ATTRIB_MAX];
158 GLuint i, nr = 0;
159
160 /* All Legacy, NV, ARB and Material attributes are routed through
161 * the NV attributes entrypoints:
162 */
163 for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) {
164 if (attrsz[i]) {
165 la[nr].target = i;
166 la[nr].sz = attrsz[i];
167 la[nr].func = vert_attrfunc[attrsz[i]-1];
168 nr++;
169 }
170 }
171
172 for (i = 0 ; i < prim_count ; i++) {
173 if ((prim[i].mode & VBO_SAVE_PRIM_WEAK) &&
174 (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END))
175 {
176 loopback_weak_prim( ctx, &prim[i] );
177 }
178 else
179 {
180 loopback_prim( ctx, buffer, &prim[i], wrap_count, vertex_size, la, nr );
181 }
182 }
183 }
184
185
186 #endif /* FEATURE_dlist */