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