1706f2543Smrg/*
2706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4706f2543Smrg *
5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6706f2543Smrg * copy of this software and associated documentation files (the "Software"),
7706f2543Smrg * to deal in the Software without restriction, including without limitation
8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
10706f2543Smrg * Software is furnished to do so, subject to the following conditions:
11706f2543Smrg *
12706f2543Smrg * The above copyright notice including the dates of first publication and
13706f2543Smrg * either this permission notice or a reference to
14706f2543Smrg * http://oss.sgi.com/projects/FreeB/
15706f2543Smrg * shall be included in all copies or substantial portions of the Software.
16706f2543Smrg *
17706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23706f2543Smrg * SOFTWARE.
24706f2543Smrg *
25706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
26706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or
27706f2543Smrg * other dealings in this Software without prior written authorization from
28706f2543Smrg * Silicon Graphics, Inc.
29706f2543Smrg */
30706f2543Smrg
31706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
32706f2543Smrg#include <dix-config.h>
33706f2543Smrg#endif
34706f2543Smrg
35706f2543Smrg#include <glxserver.h>
36706f2543Smrg#include "unpack.h"
37706f2543Smrg#include "indirect_size.h"
38706f2543Smrg#include "indirect_dispatch.h"
39706f2543Smrg#include "glapitable.h"
40706f2543Smrg#include "glapi.h"
41706f2543Smrg#include "glthread.h"
42706f2543Smrg#include "dispatch.h"
43706f2543Smrg
44706f2543Smrg
45706f2543Smrgvoid __glXDisp_Map1f(GLbyte *pc)
46706f2543Smrg{
47706f2543Smrg    GLint order, k;
48706f2543Smrg    GLfloat u1, u2, *points;
49706f2543Smrg    GLenum target;
50706f2543Smrg
51706f2543Smrg    target = *(GLenum *)(pc + 0);
52706f2543Smrg    order = *(GLint *)(pc + 12);
53706f2543Smrg    u1 = *(GLfloat *)(pc + 4);
54706f2543Smrg    u2 = *(GLfloat *)(pc + 8);
55706f2543Smrg    points = (GLfloat *)(pc + 16);
56706f2543Smrg    k = __glMap1f_size(target);
57706f2543Smrg
58706f2543Smrg    CALL_Map1f( GET_DISPATCH(), (target, u1, u2, k, order, points) );
59706f2543Smrg}
60706f2543Smrg
61706f2543Smrgvoid __glXDisp_Map2f(GLbyte *pc)
62706f2543Smrg{
63706f2543Smrg    GLint uorder, vorder, ustride, vstride, k;
64706f2543Smrg    GLfloat u1, u2, v1, v2, *points;
65706f2543Smrg    GLenum target;
66706f2543Smrg
67706f2543Smrg    target = *(GLenum *)(pc + 0);
68706f2543Smrg    uorder = *(GLint *)(pc + 12);
69706f2543Smrg    vorder = *(GLint *)(pc + 24);
70706f2543Smrg    u1 = *(GLfloat *)(pc + 4);
71706f2543Smrg    u2 = *(GLfloat *)(pc + 8);
72706f2543Smrg    v1 = *(GLfloat *)(pc + 16);
73706f2543Smrg    v2 = *(GLfloat *)(pc + 20);
74706f2543Smrg    points = (GLfloat *)(pc + 28);
75706f2543Smrg
76706f2543Smrg    k = __glMap2f_size(target);
77706f2543Smrg    ustride = vorder * k;
78706f2543Smrg    vstride = k;
79706f2543Smrg
80706f2543Smrg   CALL_Map2f( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
81706f2543Smrg}
82706f2543Smrg
83706f2543Smrgvoid __glXDisp_Map1d(GLbyte *pc)
84706f2543Smrg{
85706f2543Smrg    GLint order, k;
86706f2543Smrg#ifdef __GLX_ALIGN64
87706f2543Smrg    GLint compsize;
88706f2543Smrg#endif
89706f2543Smrg    GLenum target;
90706f2543Smrg    GLdouble u1, u2, *points;
91706f2543Smrg
92706f2543Smrg    target = *(GLenum*) (pc + 16);
93706f2543Smrg    order = *(GLint*) (pc + 20);
94706f2543Smrg    k = __glMap1d_size(target);
95706f2543Smrg
96706f2543Smrg#ifdef __GLX_ALIGN64
97706f2543Smrg    if (order < 0 || k < 0) {
98706f2543Smrg	compsize = 0;
99706f2543Smrg    } else {
100706f2543Smrg	compsize = order * k;
101706f2543Smrg    }
102706f2543Smrg#endif
103706f2543Smrg
104706f2543Smrg    __GLX_GET_DOUBLE(u1,pc);
105706f2543Smrg    __GLX_GET_DOUBLE(u2,pc+8);
106706f2543Smrg    pc += 24;
107706f2543Smrg
108706f2543Smrg#ifdef __GLX_ALIGN64
109706f2543Smrg    if (((unsigned long)pc) & 7) {
110706f2543Smrg	/*
111706f2543Smrg	** Copy the doubles up 4 bytes, trashing the command but aligning
112706f2543Smrg	** the data in the process
113706f2543Smrg	*/
114706f2543Smrg	__GLX_MEM_COPY(pc-4, pc, compsize*8);
115706f2543Smrg	points = (GLdouble*) (pc - 4);
116706f2543Smrg    } else {
117706f2543Smrg	points = (GLdouble*) pc;
118706f2543Smrg    }
119706f2543Smrg#else
120706f2543Smrg    points = (GLdouble*) pc;
121706f2543Smrg#endif
122706f2543Smrg    CALL_Map1d( GET_DISPATCH(), (target, u1, u2, k, order, points) );
123706f2543Smrg}
124706f2543Smrg
125706f2543Smrgvoid __glXDisp_Map2d(GLbyte *pc)
126706f2543Smrg{
127706f2543Smrg    GLdouble u1, u2, v1, v2, *points;
128706f2543Smrg    GLint uorder, vorder, ustride, vstride, k;
129706f2543Smrg#ifdef __GLX_ALIGN64
130706f2543Smrg    GLint compsize;
131706f2543Smrg#endif
132706f2543Smrg    GLenum target;
133706f2543Smrg
134706f2543Smrg    target = *(GLenum *)(pc + 32);
135706f2543Smrg    uorder = *(GLint *)(pc + 36);
136706f2543Smrg    vorder = *(GLint *)(pc + 40);
137706f2543Smrg    k = __glMap2d_size(target);
138706f2543Smrg
139706f2543Smrg#ifdef __GLX_ALIGN64
140706f2543Smrg    if (vorder < 0 || uorder < 0 || k < 0) {
141706f2543Smrg	compsize = 0;
142706f2543Smrg    } else {
143706f2543Smrg	compsize = uorder * vorder * k;
144706f2543Smrg    }
145706f2543Smrg#endif
146706f2543Smrg
147706f2543Smrg    __GLX_GET_DOUBLE(u1,pc);
148706f2543Smrg    __GLX_GET_DOUBLE(u2,pc+8);
149706f2543Smrg    __GLX_GET_DOUBLE(v1,pc+16);
150706f2543Smrg    __GLX_GET_DOUBLE(v2,pc+24);
151706f2543Smrg    pc += 44;
152706f2543Smrg
153706f2543Smrg    ustride = vorder * k;
154706f2543Smrg    vstride = k;
155706f2543Smrg
156706f2543Smrg#ifdef __GLX_ALIGN64
157706f2543Smrg    if (((unsigned long)pc) & 7) {
158706f2543Smrg	/*
159706f2543Smrg	** Copy the doubles up 4 bytes, trashing the command but aligning
160706f2543Smrg	** the data in the process
161706f2543Smrg	*/
162706f2543Smrg	__GLX_MEM_COPY(pc-4, pc, compsize*8);
163706f2543Smrg	points = (GLdouble*) (pc - 4);
164706f2543Smrg    } else {
165706f2543Smrg	points = (GLdouble*) pc;
166706f2543Smrg    }
167706f2543Smrg#else
168706f2543Smrg    points = (GLdouble*) pc;
169706f2543Smrg#endif
170706f2543Smrg    CALL_Map2d( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
171706f2543Smrg}
172706f2543Smrg
173706f2543Smrgvoid __glXDisp_DrawArrays(GLbyte *pc)
174706f2543Smrg{
175706f2543Smrg    __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc;
176706f2543Smrg    __GLXdispatchDrawArraysComponentHeader *compHeader;
177706f2543Smrg    GLint numVertexes = hdr->numVertexes;
178706f2543Smrg    GLint numComponents = hdr->numComponents;
179706f2543Smrg    GLenum primType = hdr->primType;
180706f2543Smrg    GLint stride = 0;
181706f2543Smrg    int i;
182706f2543Smrg
183706f2543Smrg    pc += sizeof(__GLXdispatchDrawArraysHeader);
184706f2543Smrg    compHeader = (__GLXdispatchDrawArraysComponentHeader *)pc;
185706f2543Smrg
186706f2543Smrg    /* compute stride (same for all component arrays) */
187706f2543Smrg    for (i = 0; i < numComponents; i++) {
188706f2543Smrg	GLenum datatype = compHeader[i].datatype;
189706f2543Smrg	GLint numVals = compHeader[i].numVals;
190706f2543Smrg
191706f2543Smrg	stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
192706f2543Smrg    }
193706f2543Smrg
194706f2543Smrg    pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
195706f2543Smrg
196706f2543Smrg    /* set up component arrays */
197706f2543Smrg    for (i = 0; i < numComponents; i++) {
198706f2543Smrg	GLenum datatype = compHeader[i].datatype;
199706f2543Smrg	GLint numVals = compHeader[i].numVals;
200706f2543Smrg	GLenum component = compHeader[i].component;
201706f2543Smrg
202706f2543Smrg	switch (component) {
203706f2543Smrg	  case GL_VERTEX_ARRAY:
204706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
205706f2543Smrg	    CALL_VertexPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
206706f2543Smrg	    break;
207706f2543Smrg	  case GL_NORMAL_ARRAY:
208706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
209706f2543Smrg	    CALL_NormalPointer( GET_DISPATCH(), (datatype, stride, pc) );
210706f2543Smrg	    break;
211706f2543Smrg	  case GL_COLOR_ARRAY:
212706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
213706f2543Smrg	    CALL_ColorPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
214706f2543Smrg	    break;
215706f2543Smrg	  case GL_INDEX_ARRAY:
216706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
217706f2543Smrg	    CALL_IndexPointer( GET_DISPATCH(), (datatype, stride, pc) );
218706f2543Smrg	    break;
219706f2543Smrg	  case GL_TEXTURE_COORD_ARRAY:
220706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
221706f2543Smrg	    CALL_TexCoordPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
222706f2543Smrg	    break;
223706f2543Smrg	  case GL_EDGE_FLAG_ARRAY:
224706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
225706f2543Smrg	    CALL_EdgeFlagPointer( GET_DISPATCH(), (stride, (const GLboolean *)pc) );
226706f2543Smrg	    break;
227706f2543Smrg	  case GL_SECONDARY_COLOR_ARRAY:
228706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
229706f2543Smrg	    CALL_SecondaryColorPointerEXT( GET_DISPATCH(), (numVals, datatype, stride, pc) );
230706f2543Smrg	    break;
231706f2543Smrg	  case GL_FOG_COORD_ARRAY:
232706f2543Smrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
233706f2543Smrg	    CALL_FogCoordPointerEXT( GET_DISPATCH(), (datatype, stride, pc) );
234706f2543Smrg	    break;
235706f2543Smrg	  default:
236706f2543Smrg	    break;
237706f2543Smrg	}
238706f2543Smrg
239706f2543Smrg	pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
240706f2543Smrg    }
241706f2543Smrg
242706f2543Smrg    CALL_DrawArrays( GET_DISPATCH(), (primType, 0, numVertexes) );
243706f2543Smrg
244706f2543Smrg    /* turn off anything we might have turned on */
245706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
246706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
247706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
248706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
249706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
250706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
251706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
252706f2543Smrg    CALL_DisableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
253706f2543Smrg}
254