render2.c revision 4642e01f
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/* #define NEED_REPLIES */
324642e01fSmrg#ifdef HAVE_DIX_CONFIG_H
334642e01fSmrg#include <dix-config.h>
344642e01fSmrg#endif
354642e01fSmrg
364642e01fSmrg#include <glxserver.h>
374642e01fSmrg#include "unpack.h"
384642e01fSmrg#include "indirect_size.h"
394642e01fSmrg#include "indirect_dispatch.h"
404642e01fSmrg#include "glapitable.h"
414642e01fSmrg#include "glapi.h"
424642e01fSmrg#include "glthread.h"
434642e01fSmrg#include "dispatch.h"
444642e01fSmrg
454642e01fSmrg
464642e01fSmrgvoid __glXDisp_Map1f(GLbyte *pc)
474642e01fSmrg{
484642e01fSmrg    GLint order, k;
494642e01fSmrg    GLfloat u1, u2, *points;
504642e01fSmrg    GLenum target;
514642e01fSmrg
524642e01fSmrg    target = *(GLenum *)(pc + 0);
534642e01fSmrg    order = *(GLint *)(pc + 12);
544642e01fSmrg    u1 = *(GLfloat *)(pc + 4);
554642e01fSmrg    u2 = *(GLfloat *)(pc + 8);
564642e01fSmrg    points = (GLfloat *)(pc + 16);
574642e01fSmrg    k = __glMap1f_size(target);
584642e01fSmrg
594642e01fSmrg    CALL_Map1f( GET_DISPATCH(), (target, u1, u2, k, order, points) );
604642e01fSmrg}
614642e01fSmrg
624642e01fSmrgvoid __glXDisp_Map2f(GLbyte *pc)
634642e01fSmrg{
644642e01fSmrg    GLint uorder, vorder, ustride, vstride, k;
654642e01fSmrg    GLfloat u1, u2, v1, v2, *points;
664642e01fSmrg    GLenum target;
674642e01fSmrg
684642e01fSmrg    target = *(GLenum *)(pc + 0);
694642e01fSmrg    uorder = *(GLint *)(pc + 12);
704642e01fSmrg    vorder = *(GLint *)(pc + 24);
714642e01fSmrg    u1 = *(GLfloat *)(pc + 4);
724642e01fSmrg    u2 = *(GLfloat *)(pc + 8);
734642e01fSmrg    v1 = *(GLfloat *)(pc + 16);
744642e01fSmrg    v2 = *(GLfloat *)(pc + 20);
754642e01fSmrg    points = (GLfloat *)(pc + 28);
764642e01fSmrg
774642e01fSmrg    k = __glMap2f_size(target);
784642e01fSmrg    ustride = vorder * k;
794642e01fSmrg    vstride = k;
804642e01fSmrg
814642e01fSmrg   CALL_Map2f( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
824642e01fSmrg}
834642e01fSmrg
844642e01fSmrgvoid __glXDisp_Map1d(GLbyte *pc)
854642e01fSmrg{
864642e01fSmrg    GLint order, k;
874642e01fSmrg#ifdef __GLX_ALIGN64
884642e01fSmrg    GLint compsize;
894642e01fSmrg#endif
904642e01fSmrg    GLenum target;
914642e01fSmrg    GLdouble u1, u2, *points;
924642e01fSmrg
934642e01fSmrg    target = *(GLenum*) (pc + 16);
944642e01fSmrg    order = *(GLint*) (pc + 20);
954642e01fSmrg    k = __glMap1d_size(target);
964642e01fSmrg
974642e01fSmrg#ifdef __GLX_ALIGN64
984642e01fSmrg    if (order < 0 || k < 0) {
994642e01fSmrg	compsize = 0;
1004642e01fSmrg    } else {
1014642e01fSmrg	compsize = order * k;
1024642e01fSmrg    }
1034642e01fSmrg#endif
1044642e01fSmrg
1054642e01fSmrg    __GLX_GET_DOUBLE(u1,pc);
1064642e01fSmrg    __GLX_GET_DOUBLE(u2,pc+8);
1074642e01fSmrg    pc += 24;
1084642e01fSmrg
1094642e01fSmrg#ifdef __GLX_ALIGN64
1104642e01fSmrg    if (((unsigned long)pc) & 7) {
1114642e01fSmrg	/*
1124642e01fSmrg	** Copy the doubles up 4 bytes, trashing the command but aligning
1134642e01fSmrg	** the data in the process
1144642e01fSmrg	*/
1154642e01fSmrg	__GLX_MEM_COPY(pc-4, pc, compsize*8);
1164642e01fSmrg	points = (GLdouble*) (pc - 4);
1174642e01fSmrg    } else {
1184642e01fSmrg	points = (GLdouble*) pc;
1194642e01fSmrg    }
1204642e01fSmrg#else
1214642e01fSmrg    points = (GLdouble*) pc;
1224642e01fSmrg#endif
1234642e01fSmrg    CALL_Map1d( GET_DISPATCH(), (target, u1, u2, k, order, points) );
1244642e01fSmrg}
1254642e01fSmrg
1264642e01fSmrgvoid __glXDisp_Map2d(GLbyte *pc)
1274642e01fSmrg{
1284642e01fSmrg    GLdouble u1, u2, v1, v2, *points;
1294642e01fSmrg    GLint uorder, vorder, ustride, vstride, k;
1304642e01fSmrg#ifdef __GLX_ALIGN64
1314642e01fSmrg    GLint compsize;
1324642e01fSmrg#endif
1334642e01fSmrg    GLenum target;
1344642e01fSmrg
1354642e01fSmrg    target = *(GLenum *)(pc + 32);
1364642e01fSmrg    uorder = *(GLint *)(pc + 36);
1374642e01fSmrg    vorder = *(GLint *)(pc + 40);
1384642e01fSmrg    k = __glMap2d_size(target);
1394642e01fSmrg
1404642e01fSmrg#ifdef __GLX_ALIGN64
1414642e01fSmrg    if (vorder < 0 || uorder < 0 || k < 0) {
1424642e01fSmrg	compsize = 0;
1434642e01fSmrg    } else {
1444642e01fSmrg	compsize = uorder * vorder * k;
1454642e01fSmrg    }
1464642e01fSmrg#endif
1474642e01fSmrg
1484642e01fSmrg    __GLX_GET_DOUBLE(u1,pc);
1494642e01fSmrg    __GLX_GET_DOUBLE(u2,pc+8);
1504642e01fSmrg    __GLX_GET_DOUBLE(v1,pc+16);
1514642e01fSmrg    __GLX_GET_DOUBLE(v2,pc+24);
1524642e01fSmrg    pc += 44;
1534642e01fSmrg
1544642e01fSmrg    ustride = vorder * k;
1554642e01fSmrg    vstride = k;
1564642e01fSmrg
1574642e01fSmrg#ifdef __GLX_ALIGN64
1584642e01fSmrg    if (((unsigned long)pc) & 7) {
1594642e01fSmrg	/*
1604642e01fSmrg	** Copy the doubles up 4 bytes, trashing the command but aligning
1614642e01fSmrg	** the data in the process
1624642e01fSmrg	*/
1634642e01fSmrg	__GLX_MEM_COPY(pc-4, pc, compsize*8);
1644642e01fSmrg	points = (GLdouble*) (pc - 4);
1654642e01fSmrg    } else {
1664642e01fSmrg	points = (GLdouble*) pc;
1674642e01fSmrg    }
1684642e01fSmrg#else
1694642e01fSmrg    points = (GLdouble*) pc;
1704642e01fSmrg#endif
1714642e01fSmrg    CALL_Map2d( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
1724642e01fSmrg}
1734642e01fSmrg
1744642e01fSmrgvoid __glXDisp_DrawArrays(GLbyte *pc)
1754642e01fSmrg{
1764642e01fSmrg    __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc;
1774642e01fSmrg    __GLXdispatchDrawArraysComponentHeader *compHeader;
1784642e01fSmrg    GLint numVertexes = hdr->numVertexes;
1794642e01fSmrg    GLint numComponents = hdr->numComponents;
1804642e01fSmrg    GLenum primType = hdr->primType;
1814642e01fSmrg    GLint stride = 0;
1824642e01fSmrg    int i;
1834642e01fSmrg
1844642e01fSmrg    pc += sizeof(__GLXdispatchDrawArraysHeader);
1854642e01fSmrg    compHeader = (__GLXdispatchDrawArraysComponentHeader *)pc;
1864642e01fSmrg
1874642e01fSmrg    /* compute stride (same for all component arrays) */
1884642e01fSmrg    for (i = 0; i < numComponents; i++) {
1894642e01fSmrg	GLenum datatype = compHeader[i].datatype;
1904642e01fSmrg	GLint numVals = compHeader[i].numVals;
1914642e01fSmrg
1924642e01fSmrg	stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
1934642e01fSmrg    }
1944642e01fSmrg
1954642e01fSmrg    pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
1964642e01fSmrg
1974642e01fSmrg    /* set up component arrays */
1984642e01fSmrg    for (i = 0; i < numComponents; i++) {
1994642e01fSmrg	GLenum datatype = compHeader[i].datatype;
2004642e01fSmrg	GLint numVals = compHeader[i].numVals;
2014642e01fSmrg	GLenum component = compHeader[i].component;
2024642e01fSmrg
2034642e01fSmrg	switch (component) {
2044642e01fSmrg	  case GL_VERTEX_ARRAY:
2054642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
2064642e01fSmrg	    CALL_VertexPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
2074642e01fSmrg	    break;
2084642e01fSmrg	  case GL_NORMAL_ARRAY:
2094642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
2104642e01fSmrg	    CALL_NormalPointer( GET_DISPATCH(), (datatype, stride, pc) );
2114642e01fSmrg	    break;
2124642e01fSmrg	  case GL_COLOR_ARRAY:
2134642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
2144642e01fSmrg	    CALL_ColorPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
2154642e01fSmrg	    break;
2164642e01fSmrg	  case GL_INDEX_ARRAY:
2174642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
2184642e01fSmrg	    CALL_IndexPointer( GET_DISPATCH(), (datatype, stride, pc) );
2194642e01fSmrg	    break;
2204642e01fSmrg	  case GL_TEXTURE_COORD_ARRAY:
2214642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
2224642e01fSmrg	    CALL_TexCoordPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
2234642e01fSmrg	    break;
2244642e01fSmrg	  case GL_EDGE_FLAG_ARRAY:
2254642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
2264642e01fSmrg	    CALL_EdgeFlagPointer( GET_DISPATCH(), (stride, (const GLboolean *)pc) );
2274642e01fSmrg	    break;
2284642e01fSmrg	  case GL_SECONDARY_COLOR_ARRAY:
2294642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
2304642e01fSmrg	    CALL_SecondaryColorPointerEXT( GET_DISPATCH(), (numVals, datatype, stride, pc) );
2314642e01fSmrg	    break;
2324642e01fSmrg	  case GL_FOG_COORD_ARRAY:
2334642e01fSmrg	    CALL_EnableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
2344642e01fSmrg	    CALL_FogCoordPointerEXT( GET_DISPATCH(), (datatype, stride, pc) );
2354642e01fSmrg	    break;
2364642e01fSmrg	  default:
2374642e01fSmrg	    break;
2384642e01fSmrg	}
2394642e01fSmrg
2404642e01fSmrg	pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
2414642e01fSmrg    }
2424642e01fSmrg
2434642e01fSmrg    CALL_DrawArrays( GET_DISPATCH(), (primType, 0, numVertexes) );
2444642e01fSmrg
2454642e01fSmrg    /* turn off anything we might have turned on */
2464642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
2474642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
2484642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
2494642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
2504642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
2514642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
2524642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
2534642e01fSmrg    CALL_DisableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
2544642e01fSmrg}
2554642e01fSmrg
2564642e01fSmrgvoid __glXDisp_DrawArraysEXT(GLbyte *pc)
2574642e01fSmrg{
2584642e01fSmrg   __glXDisp_DrawArrays(pc);
2594642e01fSmrg}
260