glx: add a line of Emacs helping variables
[mesa.git] / src / glx / x11 / vertarr.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. 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 "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions 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 MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
30 */
31
32 #include "glxclient.h"
33 #include "indirect.h"
34 #include "indirect_vertex_array.h"
35
36
37 /*****************************************************************************/
38
39 /**
40 * \name Vertex array pointer bridge functions
41 *
42 * When EXT_vertex_array was moved into the core GL spec, the \c count
43 * parameter was lost. This libGL really only wants to implement the GL 1.1
44 * version, but we need to support applications that were written to the old
45 * interface. These bridge functions are part of the glue that makes this
46 * happen.
47 */
48 /*@{*/
49 void __indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride,
50 GLsizei count, const GLvoid * pointer )
51 {
52 (void) count; __indirect_glColorPointer( size, type, stride, pointer );
53 }
54
55 void __indirect_glEdgeFlagPointerEXT(GLsizei stride,
56 GLsizei count, const GLboolean * pointer )
57 {
58 (void) count; __indirect_glEdgeFlagPointer( stride, pointer );
59 }
60
61 void __indirect_glIndexPointerEXT(GLenum type, GLsizei stride,
62 GLsizei count, const GLvoid * pointer )
63 {
64 (void) count; __indirect_glIndexPointer( type, stride, pointer );
65 }
66
67 void __indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
68 const GLvoid * pointer )
69 {
70 (void) count; __indirect_glNormalPointer( type, stride, pointer );
71 }
72
73 void __indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
74 GLsizei count, const GLvoid * pointer )
75 {
76 (void) count; __indirect_glTexCoordPointer( size, type, stride, pointer );
77 }
78
79 void __indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride,
80 GLsizei count, const GLvoid * pointer )
81 {
82 (void) count; __indirect_glVertexPointer( size, type, stride, pointer );
83 }
84 /*@}*/
85
86 /*****************************************************************************/
87
88 void __indirect_glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
89 {
90 __GLXcontext *gc = __glXGetCurrentContext();
91 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
92
93 #define NONE {0, 0, 0}
94 #define F(x) {GL_FLOAT, x, x * sizeof(GLfloat)}
95 #define UB4 {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)}
96
97 /* Each row in this array describes the elements of a particular
98 * interleaved array mode. Each column describes, in the order in which
99 * they appear in the interleaved arrays, one of the four possible types
100 * of vertex data that can appear in an interleaved array.
101 */
102 struct {
103 /**
104 * The enum describing the GL type, as would be passed to the
105 * appropriate gl*Pointer function.
106 */
107 GLushort type;
108
109 /**
110 * Number of elements in the subarray, as would be passed (as the
111 * \c size parameter) to the appropriate gl*Pointer function.
112 */
113 GLubyte count;
114
115 /**
116 * True size of a single element in the subarray, as would be passed
117 * (as the \c stride parameter) to the appropriate gl*Pointer
118 * function.
119 */
120 GLubyte size;
121 }
122 static const modes[14][4] = {
123 /* texture color normal vertex */
124 {NONE, NONE, NONE, F(2)}, /* GL_V2F */
125 {NONE, NONE, NONE, F(3)}, /* GL_V3F */
126 {NONE, UB4, NONE, F(2)}, /* GL_C4UB_V2F */
127 {NONE, UB4, NONE, F(3)}, /* GL_C4UB_V3F */
128 {NONE, F(3), NONE, F(3)}, /* GL_C3F_V3F */
129 {NONE, NONE, F(3), F(3)}, /* GL_N3F_V3F */
130 {NONE, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */
131 {F(2), NONE, NONE, F(3)}, /* GL_T2F_V3F */
132 {F(4), NONE, NONE, F(4)}, /* GL_T4F_V4F */
133 {F(2), UB4, NONE, F(3)}, /* GL_T2F_C4UB_V3F */
134 {F(2), F(3), NONE, F(3)}, /* GL_T2F_C3F_V3F */
135 {F(2), NONE, F(3), F(3)}, /* GL_T2F_N3F_V3F */
136 {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */
137 {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */
138 };
139 #undef NONE
140 #undef F
141 #undef UB4
142
143 GLint trueStride, size;
144 int offsets[4];
145 unsigned i;
146 const int idx = format - GL_V2F;
147
148
149 /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D]. Since idx
150 * is just the format biased by -GL_V2F, all valid idx values are on the
151 * range [0, 0x0D].
152 */
153 if ( (idx < 0) || (idx > 0x0D) ) {
154 __glXSetError(gc, GL_INVALID_ENUM);
155 return;
156 }
157
158 if ( stride < 0 ) {
159 __glXSetError(gc, GL_INVALID_VALUE);
160 return;
161 }
162
163
164 /* If the 'count' for a subarray is non-zero, then the offset of its
165 * first element is at the currently accumulated 'size'.
166 */
167 size = 0;
168 for ( i = 0 ; i < 4 ; i++ ) {
169 offsets[i] = (modes[idx][i].count != 0) ? size : -1;
170 size += modes[idx][i].size;
171 }
172
173 trueStride = (stride == 0) ? size : stride;
174
175 __glXArrayDisableAll( state );
176
177 if ( offsets[0] >= 0 ) {
178 __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
179 __indirect_glTexCoordPointer( modes[idx][0].count, GL_FLOAT,
180 trueStride,
181 (const char *) pointer );
182 }
183 if ( offsets[1] >= 0 ) {
184 __indirect_glEnableClientState(GL_COLOR_ARRAY);
185 __indirect_glColorPointer( modes[idx][1].count, modes[idx][1].type,
186 trueStride,
187 (const char *) pointer + offsets[1] );
188 }
189 if ( offsets[2] >= 0 ) {
190 __indirect_glEnableClientState(GL_NORMAL_ARRAY);
191 __indirect_glNormalPointer( GL_FLOAT, trueStride,
192 (const char *)pointer + offsets[2] );
193 }
194 __indirect_glEnableClientState(GL_VERTEX_ARRAY);
195 __indirect_glVertexPointer( modes[idx][3].count, GL_FLOAT,
196 trueStride,
197 (const char *)pointer + offsets[3] );
198 }