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