2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
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:
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.
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
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.
31 #include "glxclient.h"
33 #include "indirect_vertex_array.h"
36 /*****************************************************************************/
39 * \name Vertex array pointer bridge functions
41 * When EXT_vertex_array was moved into the core GL spec, the \c count
42 * parameter was lost. This libGL really only wants to implement the GL 1.1
43 * version, but we need to support applications that were written to the old
44 * interface. These bridge functions are part of the glue that makes this
49 __indirect_glColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
50 GLsizei count
, const GLvoid
* pointer
)
53 __indirect_glColorPointer(size
, type
, stride
, pointer
);
57 __indirect_glEdgeFlagPointerEXT(GLsizei stride
,
58 GLsizei count
, const GLboolean
* pointer
)
61 __indirect_glEdgeFlagPointer(stride
, pointer
);
65 __indirect_glIndexPointerEXT(GLenum type
, GLsizei stride
,
66 GLsizei count
, const GLvoid
* pointer
)
69 __indirect_glIndexPointer(type
, stride
, pointer
);
73 __indirect_glNormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
74 const GLvoid
* pointer
)
77 __indirect_glNormalPointer(type
, stride
, pointer
);
81 __indirect_glTexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
82 GLsizei count
, const GLvoid
* pointer
)
85 __indirect_glTexCoordPointer(size
, type
, stride
, pointer
);
89 __indirect_glVertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
90 GLsizei count
, const GLvoid
* pointer
)
93 __indirect_glVertexPointer(size
, type
, stride
, pointer
);
98 /*****************************************************************************/
101 __indirect_glInterleavedArrays(GLenum format
, GLsizei stride
,
102 const GLvoid
* pointer
)
104 struct glx_context
*gc
= __glXGetCurrentContext();
105 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
107 #define NONE {0, 0, 0}
108 #define F(x) {GL_FLOAT, x, x * sizeof(GLfloat)}
109 #define UB4 {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)}
111 /* Each row in this array describes the elements of a particular
112 * interleaved array mode. Each column describes, in the order in which
113 * they appear in the interleaved arrays, one of the four possible types
114 * of vertex data that can appear in an interleaved array.
119 * The enum describing the GL type, as would be passed to the
120 * appropriate gl*Pointer function.
125 * Number of elements in the subarray, as would be passed (as the
126 * \c size parameter) to the appropriate gl*Pointer function.
131 * True size of a single element in the subarray, as would be passed
132 * (as the \c stride parameter) to the appropriate gl*Pointer
137 static const modes
[14][4] = {
138 /* texture color normal vertex */
139 {NONE
, NONE
, NONE
, F(2)}, /* GL_V2F */
140 {NONE
, NONE
, NONE
, F(3)}, /* GL_V3F */
141 {NONE
, UB4
, NONE
, F(2)}, /* GL_C4UB_V2F */
142 {NONE
, UB4
, NONE
, F(3)}, /* GL_C4UB_V3F */
143 {NONE
, F(3), NONE
, F(3)}, /* GL_C3F_V3F */
144 {NONE
, NONE
, F(3), F(3)}, /* GL_N3F_V3F */
145 {NONE
, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */
146 {F(2), NONE
, NONE
, F(3)}, /* GL_T2F_V3F */
147 {F(4), NONE
, NONE
, F(4)}, /* GL_T4F_V4F */
148 {F(2), UB4
, NONE
, F(3)}, /* GL_T2F_C4UB_V3F */
149 {F(2), F(3), NONE
, F(3)}, /* GL_T2F_C3F_V3F */
150 {F(2), NONE
, F(3), F(3)}, /* GL_T2F_N3F_V3F */
151 {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */
152 {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */
158 GLint trueStride
, size
;
161 const int idx
= format
- GL_V2F
;
164 /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D]. Since idx
165 * is just the format biased by -GL_V2F, all valid idx values are on the
168 if ((idx
< 0) || (idx
> 0x0D)) {
169 __glXSetError(gc
, GL_INVALID_ENUM
);
174 __glXSetError(gc
, GL_INVALID_VALUE
);
179 /* If the 'count' for a subarray is non-zero, then the offset of its
180 * first element is at the currently accumulated 'size'.
183 for (i
= 0; i
< 4; i
++) {
184 offsets
[i
] = (modes
[idx
][i
].count
!= 0) ? size
: -1;
185 size
+= modes
[idx
][i
].size
;
188 trueStride
= (stride
== 0) ? size
: stride
;
190 __glXArrayDisableAll(state
);
192 if (offsets
[0] >= 0) {
193 __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
194 __indirect_glTexCoordPointer(modes
[idx
][0].count
, GL_FLOAT
,
195 trueStride
, (const char *) pointer
);
197 if (offsets
[1] >= 0) {
198 __indirect_glEnableClientState(GL_COLOR_ARRAY
);
199 __indirect_glColorPointer(modes
[idx
][1].count
, modes
[idx
][1].type
,
201 (const char *) pointer
+ offsets
[1]);
203 if (offsets
[2] >= 0) {
204 __indirect_glEnableClientState(GL_NORMAL_ARRAY
);
205 __indirect_glNormalPointer(GL_FLOAT
, trueStride
,
206 (const char *) pointer
+ offsets
[2]);
208 __indirect_glEnableClientState(GL_VERTEX_ARRAY
);
209 __indirect_glVertexPointer(modes
[idx
][3].count
, GL_FLOAT
,
211 (const char *) pointer
+ offsets
[3]);