1848b8605Smrg/*
2848b8605Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3848b8605Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
10848b8605Smrg * Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice including the dates of first publication and
13848b8605Smrg * either this permission notice or a reference to
14848b8605Smrg * http://oss.sgi.com/projects/FreeB/
15848b8605Smrg * shall be included in all copies or substantial portions of the Software.
16848b8605Smrg *
17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20848b8605Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23848b8605Smrg * SOFTWARE.
24848b8605Smrg *
25848b8605Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
26848b8605Smrg * shall not be used in advertising or otherwise to promote the sale, use or
27848b8605Smrg * other dealings in this Software without prior written authorization from
28848b8605Smrg * Silicon Graphics, Inc.
29848b8605Smrg */
30848b8605Smrg
31848b8605Smrg#include "glxclient.h"
32848b8605Smrg#include "indirect.h"
33848b8605Smrg#include "indirect_vertex_array.h"
34848b8605Smrg
35848b8605Smrg#ifndef GLX_USE_APPLEGL
36848b8605Smrg
37848b8605Smrg/*****************************************************************************/
38848b8605Smrg
39848b8605Smrg/**
40848b8605Smrg * \name Vertex array pointer bridge functions
41848b8605Smrg *
42848b8605Smrg * When EXT_vertex_array was moved into the core GL spec, the \c count
43848b8605Smrg * parameter was lost.  This libGL really only wants to implement the GL 1.1
44848b8605Smrg * version, but we need to support applications that were written to the old
45848b8605Smrg * interface.  These bridge functions are part of the glue that makes this
46848b8605Smrg * happen.
47848b8605Smrg */
48848b8605Smrg/*@{*/
49848b8605Smrgvoid
50848b8605Smrg__indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride,
51848b8605Smrg                             GLsizei count, const GLvoid * pointer)
52848b8605Smrg{
53848b8605Smrg   (void) count;
54848b8605Smrg   __indirect_glColorPointer(size, type, stride, pointer);
55848b8605Smrg}
56848b8605Smrg
57848b8605Smrgvoid
58848b8605Smrg__indirect_glEdgeFlagPointerEXT(GLsizei stride,
59848b8605Smrg                                GLsizei count, const GLboolean * pointer)
60848b8605Smrg{
61848b8605Smrg   (void) count;
62848b8605Smrg   __indirect_glEdgeFlagPointer(stride, pointer);
63848b8605Smrg}
64848b8605Smrg
65848b8605Smrgvoid
66848b8605Smrg__indirect_glIndexPointerEXT(GLenum type, GLsizei stride,
67848b8605Smrg                             GLsizei count, const GLvoid * pointer)
68848b8605Smrg{
69848b8605Smrg   (void) count;
70848b8605Smrg   __indirect_glIndexPointer(type, stride, pointer);
71848b8605Smrg}
72848b8605Smrg
73848b8605Smrgvoid
74848b8605Smrg__indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
75848b8605Smrg                              const GLvoid * pointer)
76848b8605Smrg{
77848b8605Smrg   (void) count;
78848b8605Smrg   __indirect_glNormalPointer(type, stride, pointer);
79848b8605Smrg}
80848b8605Smrg
81848b8605Smrgvoid
82848b8605Smrg__indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
83848b8605Smrg                                GLsizei count, const GLvoid * pointer)
84848b8605Smrg{
85848b8605Smrg   (void) count;
86848b8605Smrg   __indirect_glTexCoordPointer(size, type, stride, pointer);
87848b8605Smrg}
88848b8605Smrg
89848b8605Smrgvoid
90848b8605Smrg__indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride,
91848b8605Smrg                              GLsizei count, const GLvoid * pointer)
92848b8605Smrg{
93848b8605Smrg   (void) count;
94848b8605Smrg   __indirect_glVertexPointer(size, type, stride, pointer);
95848b8605Smrg}
96848b8605Smrg
97848b8605Smrg/*@}*/
98848b8605Smrg
99848b8605Smrg/*****************************************************************************/
100848b8605Smrg
101848b8605Smrgvoid
102848b8605Smrg__indirect_glInterleavedArrays(GLenum format, GLsizei stride,
103848b8605Smrg                               const GLvoid * pointer)
104848b8605Smrg{
105848b8605Smrg   struct glx_context *gc = __glXGetCurrentContext();
106848b8605Smrg   __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
107848b8605Smrg
108848b8605Smrg#define NONE  {0, 0, 0}
109848b8605Smrg#define F(x)  {GL_FLOAT, x, x * sizeof(GLfloat)}
110848b8605Smrg#define UB4   {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)}
111848b8605Smrg
112848b8605Smrg   /* Each row in this array describes the elements of a particular
113848b8605Smrg    * interleaved array mode.  Each column describes, in the order in which
114848b8605Smrg    * they appear in the interleaved arrays, one of the four possible types
115848b8605Smrg    * of vertex data that can appear in an interleaved array.
116848b8605Smrg    */
117848b8605Smrg   struct
118848b8605Smrg   {
119848b8605Smrg        /**
120848b8605Smrg	 * The enum describing the GL type, as would be passed to the
121848b8605Smrg	 * appropriate gl*Pointer function.
122848b8605Smrg	 */
123848b8605Smrg      GLushort type;
124848b8605Smrg
125848b8605Smrg        /**
126848b8605Smrg	 * Number of elements in the subarray, as would be passed (as the
127848b8605Smrg	 * \c size parameter) to the appropriate gl*Pointer function.
128848b8605Smrg	 */
129848b8605Smrg      GLubyte count;
130848b8605Smrg
131848b8605Smrg        /**
132848b8605Smrg	 * True size of a single element in the subarray, as would be passed
133848b8605Smrg	 * (as the \c stride parameter) to the appropriate gl*Pointer
134848b8605Smrg	 * function.
135848b8605Smrg	 */
136848b8605Smrg      GLubyte size;
137848b8605Smrg   }
138848b8605Smrg   static const modes[14][4] = {
139848b8605Smrg      /* texture color normal vertex */
140848b8605Smrg      {NONE, NONE, NONE, F(2)}, /* GL_V2F */
141848b8605Smrg      {NONE, NONE, NONE, F(3)}, /* GL_V3F */
142848b8605Smrg      {NONE, UB4, NONE, F(2)},  /* GL_C4UB_V2F */
143848b8605Smrg      {NONE, UB4, NONE, F(3)},  /* GL_C4UB_V3F */
144848b8605Smrg      {NONE, F(3), NONE, F(3)}, /* GL_C3F_V3F */
145848b8605Smrg      {NONE, NONE, F(3), F(3)}, /* GL_N3F_V3F */
146848b8605Smrg      {NONE, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */
147848b8605Smrg      {F(2), NONE, NONE, F(3)}, /* GL_T2F_V3F */
148848b8605Smrg      {F(4), NONE, NONE, F(4)}, /* GL_T4F_V4F */
149848b8605Smrg      {F(2), UB4, NONE, F(3)},  /* GL_T2F_C4UB_V3F */
150848b8605Smrg      {F(2), F(3), NONE, F(3)}, /* GL_T2F_C3F_V3F */
151848b8605Smrg      {F(2), NONE, F(3), F(3)}, /* GL_T2F_N3F_V3F */
152848b8605Smrg      {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */
153848b8605Smrg      {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */
154848b8605Smrg   };
155848b8605Smrg#undef NONE
156848b8605Smrg#undef F
157848b8605Smrg#undef UB4
158848b8605Smrg
159848b8605Smrg   GLint trueStride, size;
160848b8605Smrg   int offsets[4];
161848b8605Smrg   unsigned i;
162848b8605Smrg   const int idx = format - GL_V2F;
163848b8605Smrg
164848b8605Smrg
165848b8605Smrg   /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D].  Since idx
166848b8605Smrg    * is just the format biased by -GL_V2F, all valid idx values are on the
167848b8605Smrg    * range [0, 0x0D].
168848b8605Smrg    */
169848b8605Smrg   if ((idx < 0) || (idx > 0x0D)) {
170848b8605Smrg      __glXSetError(gc, GL_INVALID_ENUM);
171848b8605Smrg      return;
172848b8605Smrg   }
173848b8605Smrg
174848b8605Smrg   if (stride < 0) {
175848b8605Smrg      __glXSetError(gc, GL_INVALID_VALUE);
176848b8605Smrg      return;
177848b8605Smrg   }
178848b8605Smrg
179848b8605Smrg
180848b8605Smrg   /* If the 'count' for a subarray is non-zero, then the offset of its
181848b8605Smrg    * first element is at the currently accumulated 'size'.
182848b8605Smrg    */
183848b8605Smrg   size = 0;
184848b8605Smrg   for (i = 0; i < 4; i++) {
185848b8605Smrg      offsets[i] = (modes[idx][i].count != 0) ? size : -1;
186848b8605Smrg      size += modes[idx][i].size;
187848b8605Smrg   }
188848b8605Smrg
189848b8605Smrg   trueStride = (stride == 0) ? size : stride;
190848b8605Smrg
191848b8605Smrg   __glXArrayDisableAll(state);
192848b8605Smrg
193848b8605Smrg   if (offsets[0] >= 0) {
194848b8605Smrg      __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
195848b8605Smrg      __indirect_glTexCoordPointer(modes[idx][0].count, GL_FLOAT,
196848b8605Smrg                                   trueStride, (const char *) pointer);
197848b8605Smrg   }
198848b8605Smrg   if (offsets[1] >= 0) {
199848b8605Smrg      __indirect_glEnableClientState(GL_COLOR_ARRAY);
200848b8605Smrg      __indirect_glColorPointer(modes[idx][1].count, modes[idx][1].type,
201848b8605Smrg                                trueStride,
202848b8605Smrg                                (const char *) pointer + offsets[1]);
203848b8605Smrg   }
204848b8605Smrg   if (offsets[2] >= 0) {
205848b8605Smrg      __indirect_glEnableClientState(GL_NORMAL_ARRAY);
206848b8605Smrg      __indirect_glNormalPointer(GL_FLOAT, trueStride,
207848b8605Smrg                                 (const char *) pointer + offsets[2]);
208848b8605Smrg   }
209848b8605Smrg   __indirect_glEnableClientState(GL_VERTEX_ARRAY);
210848b8605Smrg   __indirect_glVertexPointer(modes[idx][3].count, GL_FLOAT,
211848b8605Smrg                              trueStride,
212848b8605Smrg                              (const char *) pointer + offsets[3]);
213848b8605Smrg}
214848b8605Smrg
215848b8605Smrg#endif
216