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 * SPDX-License-Identifier: SGI-B-2.0
6 */
7
8 #include "glxclient.h"
9 #include "indirect.h"
10 #include "indirect_vertex_array.h"
11
12 #if !defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)
13
14 /*****************************************************************************/
15
16 /**
17 * \name Vertex array pointer bridge functions
18 *
19 * When EXT_vertex_array was moved into the core GL spec, the \c count
20 * parameter was lost. This libGL really only wants to implement the GL 1.1
21 * version, but we need to support applications that were written to the old
22 * interface. These bridge functions are part of the glue that makes this
23 * happen.
24 */
25 /*@{*/
26 void
__indirect_glColorPointerEXT(GLint size,GLenum type,GLsizei stride,GLsizei count,const GLvoid * pointer)27 __indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride,
28 GLsizei count, const GLvoid * pointer)
29 {
30 (void) count;
31 __indirect_glColorPointer(size, type, stride, pointer);
32 }
33
34 void
__indirect_glEdgeFlagPointerEXT(GLsizei stride,GLsizei count,const GLboolean * pointer)35 __indirect_glEdgeFlagPointerEXT(GLsizei stride,
36 GLsizei count, const GLboolean * pointer)
37 {
38 (void) count;
39 __indirect_glEdgeFlagPointer(stride, pointer);
40 }
41
42 void
__indirect_glIndexPointerEXT(GLenum type,GLsizei stride,GLsizei count,const GLvoid * pointer)43 __indirect_glIndexPointerEXT(GLenum type, GLsizei stride,
44 GLsizei count, const GLvoid * pointer)
45 {
46 (void) count;
47 __indirect_glIndexPointer(type, stride, pointer);
48 }
49
50 void
__indirect_glNormalPointerEXT(GLenum type,GLsizei stride,GLsizei count,const GLvoid * pointer)51 __indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
52 const GLvoid * pointer)
53 {
54 (void) count;
55 __indirect_glNormalPointer(type, stride, pointer);
56 }
57
58 void
__indirect_glTexCoordPointerEXT(GLint size,GLenum type,GLsizei stride,GLsizei count,const GLvoid * pointer)59 __indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
60 GLsizei count, const GLvoid * pointer)
61 {
62 (void) count;
63 __indirect_glTexCoordPointer(size, type, stride, pointer);
64 }
65
66 void
__indirect_glVertexPointerEXT(GLint size,GLenum type,GLsizei stride,GLsizei count,const GLvoid * pointer)67 __indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride,
68 GLsizei count, const GLvoid * pointer)
69 {
70 (void) count;
71 __indirect_glVertexPointer(size, type, stride, pointer);
72 }
73
74 /*@}*/
75
76 /*****************************************************************************/
77
78 void
__indirect_glInterleavedArrays(GLenum format,GLsizei stride,const GLvoid * pointer)79 __indirect_glInterleavedArrays(GLenum format, GLsizei stride,
80 const GLvoid * pointer)
81 {
82 struct glx_context *gc = __glXGetCurrentContext();
83 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
84
85 #define NONE {0, 0, 0}
86 #define F(x) {GL_FLOAT, x, x * sizeof(GLfloat)}
87 #define UB4 {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)}
88
89 /* Each row in this array describes the elements of a particular
90 * interleaved array mode. Each column describes, in the order in which
91 * they appear in the interleaved arrays, one of the four possible types
92 * of vertex data that can appear in an interleaved array.
93 */
94 struct
95 {
96 /**
97 * The enum describing the GL type, as would be passed to the
98 * appropriate gl*Pointer function.
99 */
100 GLushort type;
101
102 /**
103 * Number of elements in the subarray, as would be passed (as the
104 * \c size parameter) to the appropriate gl*Pointer function.
105 */
106 GLubyte count;
107
108 /**
109 * True size of a single element in the subarray, as would be passed
110 * (as the \c stride parameter) to the appropriate gl*Pointer
111 * function.
112 */
113 GLubyte size;
114 }
115 static const modes[14][4] = {
116 /* texture color normal vertex */
117 {NONE, NONE, NONE, F(2)}, /* GL_V2F */
118 {NONE, NONE, NONE, F(3)}, /* GL_V3F */
119 {NONE, UB4, NONE, F(2)}, /* GL_C4UB_V2F */
120 {NONE, UB4, NONE, F(3)}, /* GL_C4UB_V3F */
121 {NONE, F(3), NONE, F(3)}, /* GL_C3F_V3F */
122 {NONE, NONE, F(3), F(3)}, /* GL_N3F_V3F */
123 {NONE, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */
124 {F(2), NONE, NONE, F(3)}, /* GL_T2F_V3F */
125 {F(4), NONE, NONE, F(4)}, /* GL_T4F_V4F */
126 {F(2), UB4, NONE, F(3)}, /* GL_T2F_C4UB_V3F */
127 {F(2), F(3), NONE, F(3)}, /* GL_T2F_C3F_V3F */
128 {F(2), NONE, F(3), F(3)}, /* GL_T2F_N3F_V3F */
129 {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */
130 {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */
131 };
132 #undef NONE
133 #undef F
134 #undef UB4
135
136 GLint trueStride, size;
137 int offsets[4];
138 unsigned i;
139 const int idx = format - GL_V2F;
140
141
142 /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D]. Since idx
143 * is just the format biased by -GL_V2F, all valid idx values are on the
144 * range [0, 0x0D].
145 */
146 if ((idx < 0) || (idx > 0x0D)) {
147 __glXSetError(gc, GL_INVALID_ENUM);
148 return;
149 }
150
151 if (stride < 0) {
152 __glXSetError(gc, GL_INVALID_VALUE);
153 return;
154 }
155
156
157 /* If the 'count' for a subarray is non-zero, then the offset of its
158 * first element is at the currently accumulated 'size'.
159 */
160 size = 0;
161 for (i = 0; i < 4; i++) {
162 offsets[i] = (modes[idx][i].count != 0) ? size : -1;
163 size += modes[idx][i].size;
164 }
165
166 trueStride = (stride == 0) ? size : stride;
167
168 __glXArrayDisableAll(state);
169
170 if (offsets[0] >= 0) {
171 __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
172 __indirect_glTexCoordPointer(modes[idx][0].count, GL_FLOAT,
173 trueStride, (const char *) pointer);
174 }
175 if (offsets[1] >= 0) {
176 __indirect_glEnableClientState(GL_COLOR_ARRAY);
177 __indirect_glColorPointer(modes[idx][1].count, modes[idx][1].type,
178 trueStride,
179 (const char *) pointer + offsets[1]);
180 }
181 if (offsets[2] >= 0) {
182 __indirect_glEnableClientState(GL_NORMAL_ARRAY);
183 __indirect_glNormalPointer(GL_FLOAT, trueStride,
184 (const char *) pointer + offsets[2]);
185 }
186 __indirect_glEnableClientState(GL_VERTEX_ARRAY);
187 __indirect_glVertexPointer(modes[idx][3].count, GL_FLOAT,
188 trueStride,
189 (const char *) pointer + offsets[3]);
190 }
191
192 #endif
193