Merge branch 'nouveau-import'
[mesa.git] / src / glx / x11 / vertarr.c
1 /* $XFree86: xc/lib/GL/glx/vertarr.c,v 1.4 2001/03/25 05:32:00 tsi Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 #include "glxclient.h"
38 #include "indirect.h"
39 #include "indirect_vertex_array.h"
40
41
42 /*****************************************************************************/
43
44 /**
45 * \name Vertex array pointer bridge functions
46 *
47 * When EXT_vertex_array was moved into the core GL spec, the \c count
48 * parameter was lost. This libGL really only wants to implement the GL 1.1
49 * version, but we need to support applications that were written to the old
50 * interface. These bridge functions are part of the glue that makes this
51 * happen.
52 */
53 /*@{*/
54 void __indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride,
55 GLsizei count, const GLvoid * pointer )
56 {
57 (void) count; __indirect_glColorPointer( size, type, stride, pointer );
58 }
59
60 void __indirect_glEdgeFlagPointerEXT(GLsizei stride,
61 GLsizei count, const GLboolean * pointer )
62 {
63 (void) count; __indirect_glEdgeFlagPointer( stride, pointer );
64 }
65
66 void __indirect_glIndexPointerEXT(GLenum type, GLsizei stride,
67 GLsizei count, const GLvoid * pointer )
68 {
69 (void) count; __indirect_glIndexPointer( type, stride, pointer );
70 }
71
72 void __indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
73 const GLvoid * pointer )
74 {
75 (void) count; __indirect_glNormalPointer( type, stride, pointer );
76 }
77
78 void __indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
79 GLsizei count, const GLvoid * pointer )
80 {
81 (void) count; __indirect_glTexCoordPointer( size, type, stride, pointer );
82 }
83
84 void __indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride,
85 GLsizei count, const GLvoid * pointer )
86 {
87 (void) count; __indirect_glVertexPointer( size, type, stride, pointer );
88 }
89 /*@}*/
90
91 /*****************************************************************************/
92
93 void __indirect_glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
94 {
95 __GLXcontext *gc = __glXGetCurrentContext();
96 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
97
98 #define NONE {0, 0, 0}
99 #define F(x) {GL_FLOAT, x, x * sizeof(GLfloat)}
100 #define UB4 {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)}
101
102 /* Each row in this array describes the elements of a particular
103 * interleaved array mode. Each column describes, in the order in which
104 * they appear in the interleaved arrays, one of the four possible types
105 * of vertex data that can appear in an interleaved array.
106 */
107 struct {
108 /**
109 * The enum describing the GL type, as would be passed to the
110 * appropriate gl*Pointer function.
111 */
112 GLushort type;
113
114 /**
115 * Number of elements in the subarray, as would be passed (as the
116 * \c size parameter) to the appropriate gl*Pointer function.
117 */
118 GLubyte count;
119
120 /**
121 * True size of a single element in the subarray, as would be passed
122 * (as the \c stride parameter) to the appropriate gl*Pointer
123 * function.
124 */
125 GLubyte size;
126 }
127 static const modes[14][4] = {
128 /* texture color normal vertex */
129 {NONE, NONE, NONE, F(2)}, /* GL_V2F */
130 {NONE, NONE, NONE, F(3)}, /* GL_V3F */
131 {NONE, UB4, NONE, F(2)}, /* GL_C4UB_V2F */
132 {NONE, UB4, NONE, F(3)}, /* GL_C4UB_V3F */
133 {NONE, F(3), NONE, F(3)}, /* GL_C3F_V3F */
134 {NONE, NONE, F(3), F(3)}, /* GL_N3F_V3F */
135 {NONE, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */
136 {F(2), NONE, NONE, F(3)}, /* GL_T2F_V3F */
137 {F(4), NONE, NONE, F(4)}, /* GL_T4F_V4F */
138 {F(2), UB4, NONE, F(3)}, /* GL_T2F_C4UB_V3F */
139 {F(2), F(3), NONE, F(3)}, /* GL_T2F_C3F_V3F */
140 {F(2), NONE, F(3), F(3)}, /* GL_T2F_N3F_V3F */
141 {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */
142 {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */
143 };
144 #undef NONE
145 #undef F
146 #undef UB4
147
148 GLint trueStride, size;
149 int offsets[4];
150 unsigned i;
151 const int idx = format - GL_V2F;
152
153
154 /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D]. Since idx
155 * is just the format biased by -GL_V2F, all valid idx values are on the
156 * range [0, 0x0D].
157 */
158 if ( (idx < 0) || (idx > 0x0D) ) {
159 __glXSetError(gc, GL_INVALID_ENUM);
160 return;
161 }
162
163 if ( stride < 0 ) {
164 __glXSetError(gc, GL_INVALID_VALUE);
165 return;
166 }
167
168
169 /* If the 'count' for a subarray is non-zero, then the offset of its
170 * first element is at the currently accumulated 'size'.
171 */
172 size = 0;
173 for ( i = 0 ; i < 4 ; i++ ) {
174 offsets[i] = (modes[idx][i].count != 0) ? size : -1;
175 size += modes[idx][i].size;
176 }
177
178 trueStride = (stride == 0) ? size : stride;
179
180 __glXArrayDisableAll( state );
181
182 if ( offsets[0] >= 0 ) {
183 __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
184 __indirect_glTexCoordPointer( modes[idx][0].count, GL_FLOAT,
185 trueStride,
186 (const char *) pointer );
187 }
188 if ( offsets[1] >= 0 ) {
189 __indirect_glEnableClientState(GL_COLOR_ARRAY);
190 __indirect_glColorPointer( modes[idx][1].count, modes[idx][1].type,
191 trueStride,
192 (const char *) pointer + offsets[1] );
193 }
194 if ( offsets[2] >= 0 ) {
195 __indirect_glEnableClientState(GL_NORMAL_ARRAY);
196 __indirect_glNormalPointer( GL_FLOAT, trueStride,
197 (const char *)pointer + offsets[2] );
198 }
199 __indirect_glEnableClientState(GL_VERTEX_ARRAY);
200 __indirect_glVertexPointer( modes[idx][3].count, GL_FLOAT,
201 trueStride,
202 (const char *)pointer + offsets[3] );
203 }