14642e01fSmrg/*
24642e01fSmrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
34642e01fSmrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
44642e01fSmrg *
54642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
64642e01fSmrg * copy of this software and associated documentation files (the "Software"),
74642e01fSmrg * to deal in the Software without restriction, including without limitation
84642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
94642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the
104642e01fSmrg * Software is furnished to do so, subject to the following conditions:
114642e01fSmrg *
124642e01fSmrg * The above copyright notice including the dates of first publication and
134642e01fSmrg * either this permission notice or a reference to
144642e01fSmrg * http://oss.sgi.com/projects/FreeB/
154642e01fSmrg * shall be included in all copies or substantial portions of the Software.
164642e01fSmrg *
174642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
184642e01fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
204642e01fSmrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
214642e01fSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
224642e01fSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
234642e01fSmrg * SOFTWARE.
244642e01fSmrg *
254642e01fSmrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
264642e01fSmrg * shall not be used in advertising or otherwise to promote the sale, use or
274642e01fSmrg * other dealings in this Software without prior written authorization from
284642e01fSmrg * Silicon Graphics, Inc.
294642e01fSmrg */
304642e01fSmrg
314642e01fSmrg#ifdef HAVE_DIX_CONFIG_H
324642e01fSmrg#include <dix-config.h>
334642e01fSmrg#endif
344642e01fSmrg
354642e01fSmrg#include "glxserver.h"
364642e01fSmrg#include "unpack.h"
374642e01fSmrg#include "indirect_size.h"
384642e01fSmrg#include "indirect_dispatch.h"
394642e01fSmrg
4035c4bbdfSmrgvoid
4135c4bbdfSmrg__glXDispSwap_Map1f(GLbyte * pc)
424642e01fSmrg{
434642e01fSmrg    GLint order, k;
444642e01fSmrg    GLfloat u1, u2, *points;
454642e01fSmrg    GLenum target;
464642e01fSmrg    GLint compsize;
4735c4bbdfSmrg
484642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
494642e01fSmrg    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
504642e01fSmrg
514642e01fSmrg    __GLX_SWAP_INT(pc + 0);
524642e01fSmrg    __GLX_SWAP_INT(pc + 12);
534642e01fSmrg    __GLX_SWAP_FLOAT(pc + 4);
544642e01fSmrg    __GLX_SWAP_FLOAT(pc + 8);
5535c4bbdfSmrg
5635c4bbdfSmrg    target = *(GLenum *) (pc + 0);
5735c4bbdfSmrg    order = *(GLint *) (pc + 12);
5835c4bbdfSmrg    u1 = *(GLfloat *) (pc + 4);
5935c4bbdfSmrg    u2 = *(GLfloat *) (pc + 8);
6035c4bbdfSmrg    points = (GLfloat *) (pc + 16);
614642e01fSmrg    k = __glMap1f_size(target);
624642e01fSmrg
634642e01fSmrg    if (order <= 0 || k < 0) {
6435c4bbdfSmrg        /* Erroneous command. */
6535c4bbdfSmrg        compsize = 0;
6635c4bbdfSmrg    }
6735c4bbdfSmrg    else {
6835c4bbdfSmrg        compsize = order * k;
694642e01fSmrg    }
704642e01fSmrg    __GLX_SWAP_FLOAT_ARRAY(points, compsize);
714642e01fSmrg
7235c4bbdfSmrg    glMap1f(target, u1, u2, k, order, points);
734642e01fSmrg}
744642e01fSmrg
7535c4bbdfSmrgvoid
7635c4bbdfSmrg__glXDispSwap_Map2f(GLbyte * pc)
774642e01fSmrg{
784642e01fSmrg    GLint uorder, vorder, ustride, vstride, k;
794642e01fSmrg    GLfloat u1, u2, v1, v2, *points;
804642e01fSmrg    GLenum target;
814642e01fSmrg    GLint compsize;
8235c4bbdfSmrg
834642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
844642e01fSmrg    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
854642e01fSmrg
864642e01fSmrg    __GLX_SWAP_INT(pc + 0);
874642e01fSmrg    __GLX_SWAP_INT(pc + 12);
884642e01fSmrg    __GLX_SWAP_INT(pc + 24);
894642e01fSmrg    __GLX_SWAP_FLOAT(pc + 4);
904642e01fSmrg    __GLX_SWAP_FLOAT(pc + 8);
914642e01fSmrg    __GLX_SWAP_FLOAT(pc + 16);
924642e01fSmrg    __GLX_SWAP_FLOAT(pc + 20);
9335c4bbdfSmrg
9435c4bbdfSmrg    target = *(GLenum *) (pc + 0);
9535c4bbdfSmrg    uorder = *(GLint *) (pc + 12);
9635c4bbdfSmrg    vorder = *(GLint *) (pc + 24);
9735c4bbdfSmrg    u1 = *(GLfloat *) (pc + 4);
9835c4bbdfSmrg    u2 = *(GLfloat *) (pc + 8);
9935c4bbdfSmrg    v1 = *(GLfloat *) (pc + 16);
10035c4bbdfSmrg    v2 = *(GLfloat *) (pc + 20);
10135c4bbdfSmrg    points = (GLfloat *) (pc + 28);
1024642e01fSmrg
1034642e01fSmrg    k = __glMap2f_size(target);
1044642e01fSmrg    ustride = vorder * k;
1054642e01fSmrg    vstride = k;
1064642e01fSmrg
1074642e01fSmrg    if (vorder <= 0 || uorder <= 0 || k < 0) {
10835c4bbdfSmrg        /* Erroneous command. */
10935c4bbdfSmrg        compsize = 0;
11035c4bbdfSmrg    }
11135c4bbdfSmrg    else {
11235c4bbdfSmrg        compsize = uorder * vorder * k;
1134642e01fSmrg    }
1144642e01fSmrg    __GLX_SWAP_FLOAT_ARRAY(points, compsize);
1154642e01fSmrg
11635c4bbdfSmrg    glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
1174642e01fSmrg}
1184642e01fSmrg
11935c4bbdfSmrgvoid
12035c4bbdfSmrg__glXDispSwap_Map1d(GLbyte * pc)
1214642e01fSmrg{
1224642e01fSmrg    GLint order, k, compsize;
1234642e01fSmrg    GLenum target;
1244642e01fSmrg    GLdouble u1, u2, *points;
12535c4bbdfSmrg
1264642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
1274642e01fSmrg    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
1284642e01fSmrg
1294642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 0);
1304642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 8);
1314642e01fSmrg    __GLX_SWAP_INT(pc + 16);
1324642e01fSmrg    __GLX_SWAP_INT(pc + 20);
1334642e01fSmrg
13435c4bbdfSmrg    target = *(GLenum *) (pc + 16);
13535c4bbdfSmrg    order = *(GLint *) (pc + 20);
1364642e01fSmrg    k = __glMap1d_size(target);
1374642e01fSmrg    if (order <= 0 || k < 0) {
13835c4bbdfSmrg        /* Erroneous command. */
13935c4bbdfSmrg        compsize = 0;
1404642e01fSmrg    }
14135c4bbdfSmrg    else {
14235c4bbdfSmrg        compsize = order * k;
14335c4bbdfSmrg    }
14435c4bbdfSmrg    __GLX_GET_DOUBLE(u1, pc);
14535c4bbdfSmrg    __GLX_GET_DOUBLE(u2, pc + 8);
14635c4bbdfSmrg    __GLX_SWAP_DOUBLE_ARRAY(pc + 24, compsize);
1474642e01fSmrg    pc += 24;
1484642e01fSmrg
1494642e01fSmrg#ifdef __GLX_ALIGN64
15035c4bbdfSmrg    if (((unsigned long) pc) & 7) {
15135c4bbdfSmrg        /*
15235c4bbdfSmrg         ** Copy the doubles up 4 bytes, trashing the command but aligning
15335c4bbdfSmrg         ** the data in the process
15435c4bbdfSmrg         */
15535c4bbdfSmrg        __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
15635c4bbdfSmrg        points = (GLdouble *) (pc - 4);
15735c4bbdfSmrg    }
15835c4bbdfSmrg    else {
15935c4bbdfSmrg        points = (GLdouble *) pc;
1604642e01fSmrg    }
1614642e01fSmrg#else
16235c4bbdfSmrg    points = (GLdouble *) pc;
1634642e01fSmrg#endif
16435c4bbdfSmrg    glMap1d(target, u1, u2, k, order, points);
1654642e01fSmrg}
1664642e01fSmrg
16735c4bbdfSmrgvoid
16835c4bbdfSmrg__glXDispSwap_Map2d(GLbyte * pc)
1694642e01fSmrg{
1704642e01fSmrg    GLdouble u1, u2, v1, v2, *points;
1714642e01fSmrg    GLint uorder, vorder, ustride, vstride, k, compsize;
1724642e01fSmrg    GLenum target;
17335c4bbdfSmrg
1744642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
1754642e01fSmrg    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
1764642e01fSmrg
1774642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 0);
1784642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 8);
1794642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 16);
1804642e01fSmrg    __GLX_SWAP_DOUBLE(pc + 24);
1814642e01fSmrg    __GLX_SWAP_INT(pc + 32);
1824642e01fSmrg    __GLX_SWAP_INT(pc + 36);
1834642e01fSmrg    __GLX_SWAP_INT(pc + 40);
1844642e01fSmrg
18535c4bbdfSmrg    target = *(GLenum *) (pc + 32);
18635c4bbdfSmrg    uorder = *(GLint *) (pc + 36);
18735c4bbdfSmrg    vorder = *(GLint *) (pc + 40);
1884642e01fSmrg    k = __glMap2d_size(target);
1894642e01fSmrg    if (vorder <= 0 || uorder <= 0 || k < 0) {
19035c4bbdfSmrg        /* Erroneous command. */
19135c4bbdfSmrg        compsize = 0;
19235c4bbdfSmrg    }
19335c4bbdfSmrg    else {
19435c4bbdfSmrg        compsize = uorder * vorder * k;
1954642e01fSmrg    }
19635c4bbdfSmrg    __GLX_GET_DOUBLE(u1, pc);
19735c4bbdfSmrg    __GLX_GET_DOUBLE(u2, pc + 8);
19835c4bbdfSmrg    __GLX_GET_DOUBLE(v1, pc + 16);
19935c4bbdfSmrg    __GLX_GET_DOUBLE(v2, pc + 24);
20035c4bbdfSmrg    __GLX_SWAP_DOUBLE_ARRAY(pc + 44, compsize);
2014642e01fSmrg    pc += 44;
2024642e01fSmrg    ustride = vorder * k;
2034642e01fSmrg    vstride = k;
2044642e01fSmrg
2054642e01fSmrg#ifdef __GLX_ALIGN64
20635c4bbdfSmrg    if (((unsigned long) pc) & 7) {
20735c4bbdfSmrg        /*
20835c4bbdfSmrg         ** Copy the doubles up 4 bytes, trashing the command but aligning
20935c4bbdfSmrg         ** the data in the process
21035c4bbdfSmrg         */
21135c4bbdfSmrg        __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
21235c4bbdfSmrg        points = (GLdouble *) (pc - 4);
21335c4bbdfSmrg    }
21435c4bbdfSmrg    else {
21535c4bbdfSmrg        points = (GLdouble *) pc;
2164642e01fSmrg    }
2174642e01fSmrg#else
21835c4bbdfSmrg    points = (GLdouble *) pc;
2194642e01fSmrg#endif
22035c4bbdfSmrg    glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
2214642e01fSmrg}
2224642e01fSmrg
22335c4bbdfSmrgstatic void
22435c4bbdfSmrgswapArray(GLint numVals, GLenum datatype,
22535c4bbdfSmrg          GLint stride, GLint numVertexes, GLbyte * pc)
2264642e01fSmrg{
22735c4bbdfSmrg    int i, j;
22835c4bbdfSmrg
2294642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
2304642e01fSmrg
2314642e01fSmrg    switch (datatype) {
23235c4bbdfSmrg    case GL_BYTE:
23335c4bbdfSmrg    case GL_UNSIGNED_BYTE:
23435c4bbdfSmrg        /* don't need to swap */
23535c4bbdfSmrg        return;
23635c4bbdfSmrg    case GL_SHORT:
23735c4bbdfSmrg    case GL_UNSIGNED_SHORT:
23835c4bbdfSmrg        for (i = 0; i < numVertexes; i++) {
23935c4bbdfSmrg            GLshort *pVal = (GLshort *) pc;
24035c4bbdfSmrg
24135c4bbdfSmrg            for (j = 0; j < numVals; j++) {
24235c4bbdfSmrg                __GLX_SWAP_SHORT(&pVal[j]);
24335c4bbdfSmrg            }
24435c4bbdfSmrg            pc += stride;
24535c4bbdfSmrg        }
24635c4bbdfSmrg        break;
24735c4bbdfSmrg    case GL_INT:
24835c4bbdfSmrg    case GL_UNSIGNED_INT:
24935c4bbdfSmrg        for (i = 0; i < numVertexes; i++) {
25035c4bbdfSmrg            GLint *pVal = (GLint *) pc;
25135c4bbdfSmrg
25235c4bbdfSmrg            for (j = 0; j < numVals; j++) {
25335c4bbdfSmrg                __GLX_SWAP_INT(&pVal[j]);
25435c4bbdfSmrg            }
25535c4bbdfSmrg            pc += stride;
25635c4bbdfSmrg        }
25735c4bbdfSmrg        break;
25835c4bbdfSmrg    case GL_FLOAT:
25935c4bbdfSmrg        for (i = 0; i < numVertexes; i++) {
26035c4bbdfSmrg            GLfloat *pVal = (GLfloat *) pc;
26135c4bbdfSmrg
26235c4bbdfSmrg            for (j = 0; j < numVals; j++) {
26335c4bbdfSmrg                __GLX_SWAP_FLOAT(&pVal[j]);
26435c4bbdfSmrg            }
26535c4bbdfSmrg            pc += stride;
26635c4bbdfSmrg        }
26735c4bbdfSmrg        break;
26835c4bbdfSmrg    case GL_DOUBLE:
26935c4bbdfSmrg        for (i = 0; i < numVertexes; i++) {
27035c4bbdfSmrg            GLdouble *pVal = (GLdouble *) pc;
27135c4bbdfSmrg
27235c4bbdfSmrg            for (j = 0; j < numVals; j++) {
27335c4bbdfSmrg                __GLX_SWAP_DOUBLE(&pVal[j]);
27435c4bbdfSmrg            }
27535c4bbdfSmrg            pc += stride;
27635c4bbdfSmrg        }
27735c4bbdfSmrg        break;
27835c4bbdfSmrg    default:
27935c4bbdfSmrg        return;
2804642e01fSmrg    }
2814642e01fSmrg}
2824642e01fSmrg
28335c4bbdfSmrgvoid
28435c4bbdfSmrg__glXDispSwap_DrawArrays(GLbyte * pc)
2854642e01fSmrg{
28635c4bbdfSmrg    __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *) pc;
2874642e01fSmrg    __GLXdispatchDrawArraysComponentHeader *compHeader;
2884642e01fSmrg    GLint numVertexes = hdr->numVertexes;
2894642e01fSmrg    GLint numComponents = hdr->numComponents;
2904642e01fSmrg    GLenum primType = hdr->primType;
2914642e01fSmrg    GLint stride = 0;
2924642e01fSmrg    int i;
29335c4bbdfSmrg
2944642e01fSmrg    __GLX_DECLARE_SWAP_VARIABLES;
2954642e01fSmrg
2964642e01fSmrg    __GLX_SWAP_INT(&numVertexes);
2974642e01fSmrg    __GLX_SWAP_INT(&numComponents);
2984642e01fSmrg    __GLX_SWAP_INT(&primType);
2994642e01fSmrg
3004642e01fSmrg    pc += sizeof(__GLXdispatchDrawArraysHeader);
3014642e01fSmrg    compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
3024642e01fSmrg
3034642e01fSmrg    /* compute stride (same for all component arrays) */
30435c4bbdfSmrg    for (i = 0; i < numComponents; i++) {
30535c4bbdfSmrg        GLenum datatype = compHeader[i].datatype;
30635c4bbdfSmrg        GLint numVals = compHeader[i].numVals;
30735c4bbdfSmrg        GLenum component = compHeader[i].component;
3084642e01fSmrg
30935c4bbdfSmrg        __GLX_SWAP_INT(&datatype);
31035c4bbdfSmrg        __GLX_SWAP_INT(&numVals);
31135c4bbdfSmrg        __GLX_SWAP_INT(&component);
3124642e01fSmrg
3134642e01fSmrg        stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
3144642e01fSmrg    }
3154642e01fSmrg
3164642e01fSmrg    pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
3174642e01fSmrg
3184642e01fSmrg    /* set up component arrays */
31935c4bbdfSmrg    for (i = 0; i < numComponents; i++) {
32035c4bbdfSmrg        GLenum datatype = compHeader[i].datatype;
32135c4bbdfSmrg        GLint numVals = compHeader[i].numVals;
32235c4bbdfSmrg        GLenum component = compHeader[i].component;
3234642e01fSmrg
32435c4bbdfSmrg        __GLX_SWAP_INT(&datatype);
32535c4bbdfSmrg        __GLX_SWAP_INT(&numVals);
32635c4bbdfSmrg        __GLX_SWAP_INT(&component);
3274642e01fSmrg
32835c4bbdfSmrg        swapArray(numVals, datatype, stride, numVertexes, pc);
3294642e01fSmrg
3304642e01fSmrg        switch (component) {
33135c4bbdfSmrg        case GL_VERTEX_ARRAY:
33235c4bbdfSmrg            glEnableClientState(GL_VERTEX_ARRAY);
33335c4bbdfSmrg            glVertexPointer(numVals, datatype, stride, pc);
3344642e01fSmrg            break;
33535c4bbdfSmrg        case GL_NORMAL_ARRAY:
33635c4bbdfSmrg            glEnableClientState(GL_NORMAL_ARRAY);
33735c4bbdfSmrg            glNormalPointer(datatype, stride, pc);
3384642e01fSmrg            break;
33935c4bbdfSmrg        case GL_COLOR_ARRAY:
34035c4bbdfSmrg            glEnableClientState(GL_COLOR_ARRAY);
34135c4bbdfSmrg            glColorPointer(numVals, datatype, stride, pc);
3424642e01fSmrg            break;
34335c4bbdfSmrg        case GL_INDEX_ARRAY:
34435c4bbdfSmrg            glEnableClientState(GL_INDEX_ARRAY);
34535c4bbdfSmrg            glIndexPointer(datatype, stride, pc);
3464642e01fSmrg            break;
34735c4bbdfSmrg        case GL_TEXTURE_COORD_ARRAY:
34835c4bbdfSmrg            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
34935c4bbdfSmrg            glTexCoordPointer(numVals, datatype, stride, pc);
3504642e01fSmrg            break;
35135c4bbdfSmrg        case GL_EDGE_FLAG_ARRAY:
35235c4bbdfSmrg            glEnableClientState(GL_EDGE_FLAG_ARRAY);
35335c4bbdfSmrg            glEdgeFlagPointer(stride, (const GLboolean *) pc);
3544642e01fSmrg            break;
35535c4bbdfSmrg        case GL_SECONDARY_COLOR_ARRAY:
35635c4bbdfSmrg        {
35735c4bbdfSmrg            PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointerEXT =
35835c4bbdfSmrg                __glGetProcAddress("glSecondaryColorPointerEXT");
35935c4bbdfSmrg            glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
36035c4bbdfSmrg            SecondaryColorPointerEXT(numVals, datatype, stride, pc);
3614642e01fSmrg            break;
36235c4bbdfSmrg        }
36335c4bbdfSmrg        case GL_FOG_COORD_ARRAY:
36435c4bbdfSmrg        {
36535c4bbdfSmrg            PFNGLFOGCOORDPOINTERPROC FogCoordPointerEXT =
36635c4bbdfSmrg                __glGetProcAddress("glFogCoordPointerEXT");
36735c4bbdfSmrg            glEnableClientState(GL_FOG_COORD_ARRAY);
36835c4bbdfSmrg            FogCoordPointerEXT(datatype, stride, pc);
3694642e01fSmrg            break;
37035c4bbdfSmrg        }
37135c4bbdfSmrg        default:
3724642e01fSmrg            break;
37335c4bbdfSmrg        }
3744642e01fSmrg
3754642e01fSmrg        pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
3764642e01fSmrg    }
3774642e01fSmrg
37835c4bbdfSmrg    glDrawArrays(primType, 0, numVertexes);
3794642e01fSmrg
3804642e01fSmrg    /* turn off anything we might have turned on */
38135c4bbdfSmrg    glDisableClientState(GL_VERTEX_ARRAY);
38235c4bbdfSmrg    glDisableClientState(GL_NORMAL_ARRAY);
38335c4bbdfSmrg    glDisableClientState(GL_COLOR_ARRAY);
38435c4bbdfSmrg    glDisableClientState(GL_INDEX_ARRAY);
38535c4bbdfSmrg    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
38635c4bbdfSmrg    glDisableClientState(GL_EDGE_FLAG_ARRAY);
38735c4bbdfSmrg    glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
38835c4bbdfSmrg    glDisableClientState(GL_FOG_COORD_ARRAY);
3894642e01fSmrg}
390