initial commit
[profile/ivi/xorg-x11-server.git] / glx / render2.c
1 /*
2  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice including the dates of first publication and
13  * either this permission notice or a reference to
14  * http://oss.sgi.com/projects/FreeB/
15  * shall be included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Except as contained in this notice, the name of Silicon Graphics, Inc.
26  * shall not be used in advertising or otherwise to promote the sale, use or
27  * other dealings in this Software without prior written authorization from
28  * Silicon Graphics, Inc.
29  */
30
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
33 #endif
34
35 #include <glxserver.h>
36 #include "unpack.h"
37 #include "indirect_size.h"
38 #include "indirect_dispatch.h"
39 #include "glapitable.h"
40 #include "glapi.h"
41 #include "glthread.h"
42 #include "dispatch.h"
43
44
45 void __glXDisp_Map1f(GLbyte *pc)
46 {
47     GLint order, k;
48     GLfloat u1, u2, *points;
49     GLenum target;
50
51     target = *(GLenum *)(pc + 0);
52     order = *(GLint *)(pc + 12);
53     u1 = *(GLfloat *)(pc + 4);
54     u2 = *(GLfloat *)(pc + 8);
55     points = (GLfloat *)(pc + 16);
56     k = __glMap1f_size(target);
57
58     CALL_Map1f( GET_DISPATCH(), (target, u1, u2, k, order, points) );
59 }
60
61 void __glXDisp_Map2f(GLbyte *pc)
62 {
63     GLint uorder, vorder, ustride, vstride, k;
64     GLfloat u1, u2, v1, v2, *points;
65     GLenum target;
66
67     target = *(GLenum *)(pc + 0);
68     uorder = *(GLint *)(pc + 12);
69     vorder = *(GLint *)(pc + 24);
70     u1 = *(GLfloat *)(pc + 4);
71     u2 = *(GLfloat *)(pc + 8);
72     v1 = *(GLfloat *)(pc + 16);
73     v2 = *(GLfloat *)(pc + 20);
74     points = (GLfloat *)(pc + 28);
75
76     k = __glMap2f_size(target);
77     ustride = vorder * k;
78     vstride = k;
79
80    CALL_Map2f( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
81 }
82
83 void __glXDisp_Map1d(GLbyte *pc)
84 {
85     GLint order, k;
86 #ifdef __GLX_ALIGN64
87     GLint compsize;
88 #endif
89     GLenum target;
90     GLdouble u1, u2, *points;
91
92     target = *(GLenum*) (pc + 16);
93     order = *(GLint*) (pc + 20);
94     k = __glMap1d_size(target);
95
96 #ifdef __GLX_ALIGN64
97     if (order < 0 || k < 0) {
98         compsize = 0;
99     } else {
100         compsize = order * k;
101     }
102 #endif
103
104     __GLX_GET_DOUBLE(u1,pc);
105     __GLX_GET_DOUBLE(u2,pc+8);
106     pc += 24;
107
108 #ifdef __GLX_ALIGN64
109     if (((unsigned long)pc) & 7) {
110         /*
111         ** Copy the doubles up 4 bytes, trashing the command but aligning
112         ** the data in the process
113         */
114         __GLX_MEM_COPY(pc-4, pc, compsize*8);
115         points = (GLdouble*) (pc - 4);
116     } else {
117         points = (GLdouble*) pc;
118     }
119 #else
120     points = (GLdouble*) pc;
121 #endif
122     CALL_Map1d( GET_DISPATCH(), (target, u1, u2, k, order, points) );
123 }
124
125 void __glXDisp_Map2d(GLbyte *pc)
126 {
127     GLdouble u1, u2, v1, v2, *points;
128     GLint uorder, vorder, ustride, vstride, k;
129 #ifdef __GLX_ALIGN64
130     GLint compsize;
131 #endif
132     GLenum target;
133
134     target = *(GLenum *)(pc + 32);
135     uorder = *(GLint *)(pc + 36);
136     vorder = *(GLint *)(pc + 40);
137     k = __glMap2d_size(target);
138
139 #ifdef __GLX_ALIGN64
140     if (vorder < 0 || uorder < 0 || k < 0) {
141         compsize = 0;
142     } else {
143         compsize = uorder * vorder * k;
144     }
145 #endif
146
147     __GLX_GET_DOUBLE(u1,pc);
148     __GLX_GET_DOUBLE(u2,pc+8);
149     __GLX_GET_DOUBLE(v1,pc+16);
150     __GLX_GET_DOUBLE(v2,pc+24);
151     pc += 44;
152
153     ustride = vorder * k;
154     vstride = k;
155
156 #ifdef __GLX_ALIGN64
157     if (((unsigned long)pc) & 7) {
158         /*
159         ** Copy the doubles up 4 bytes, trashing the command but aligning
160         ** the data in the process
161         */
162         __GLX_MEM_COPY(pc-4, pc, compsize*8);
163         points = (GLdouble*) (pc - 4);
164     } else {
165         points = (GLdouble*) pc;
166     }
167 #else
168     points = (GLdouble*) pc;
169 #endif
170     CALL_Map2d( GET_DISPATCH(), (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points) );
171 }
172
173 void __glXDisp_DrawArrays(GLbyte *pc)
174 {
175     __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc;
176     __GLXdispatchDrawArraysComponentHeader *compHeader;
177     GLint numVertexes = hdr->numVertexes;
178     GLint numComponents = hdr->numComponents;
179     GLenum primType = hdr->primType;
180     GLint stride = 0;
181     int i;
182
183     pc += sizeof(__GLXdispatchDrawArraysHeader);
184     compHeader = (__GLXdispatchDrawArraysComponentHeader *)pc;
185
186     /* compute stride (same for all component arrays) */
187     for (i = 0; i < numComponents; i++) {
188         GLenum datatype = compHeader[i].datatype;
189         GLint numVals = compHeader[i].numVals;
190
191         stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
192     }
193
194     pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
195
196     /* set up component arrays */
197     for (i = 0; i < numComponents; i++) {
198         GLenum datatype = compHeader[i].datatype;
199         GLint numVals = compHeader[i].numVals;
200         GLenum component = compHeader[i].component;
201
202         switch (component) {
203           case GL_VERTEX_ARRAY:
204             CALL_EnableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
205             CALL_VertexPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
206             break;
207           case GL_NORMAL_ARRAY:
208             CALL_EnableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
209             CALL_NormalPointer( GET_DISPATCH(), (datatype, stride, pc) );
210             break;
211           case GL_COLOR_ARRAY:
212             CALL_EnableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
213             CALL_ColorPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
214             break;
215           case GL_INDEX_ARRAY:
216             CALL_EnableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
217             CALL_IndexPointer( GET_DISPATCH(), (datatype, stride, pc) );
218             break;
219           case GL_TEXTURE_COORD_ARRAY:
220             CALL_EnableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
221             CALL_TexCoordPointer( GET_DISPATCH(), (numVals, datatype, stride, pc) );
222             break;
223           case GL_EDGE_FLAG_ARRAY:
224             CALL_EnableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
225             CALL_EdgeFlagPointer( GET_DISPATCH(), (stride, (const GLboolean *)pc) );
226             break;
227           case GL_SECONDARY_COLOR_ARRAY:
228             CALL_EnableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
229             CALL_SecondaryColorPointerEXT( GET_DISPATCH(), (numVals, datatype, stride, pc) );
230             break;
231           case GL_FOG_COORD_ARRAY:
232             CALL_EnableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
233             CALL_FogCoordPointerEXT( GET_DISPATCH(), (datatype, stride, pc) );
234             break;
235           default:
236             break;
237         }
238
239         pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
240     }
241
242     CALL_DrawArrays( GET_DISPATCH(), (primType, 0, numVertexes) );
243
244     /* turn off anything we might have turned on */
245     CALL_DisableClientState( GET_DISPATCH(), (GL_VERTEX_ARRAY) );
246     CALL_DisableClientState( GET_DISPATCH(), (GL_NORMAL_ARRAY) );
247     CALL_DisableClientState( GET_DISPATCH(), (GL_COLOR_ARRAY) );
248     CALL_DisableClientState( GET_DISPATCH(), (GL_INDEX_ARRAY) );
249     CALL_DisableClientState( GET_DISPATCH(), (GL_TEXTURE_COORD_ARRAY) );
250     CALL_DisableClientState( GET_DISPATCH(), (GL_EDGE_FLAG_ARRAY) );
251     CALL_DisableClientState( GET_DISPATCH(), (GL_SECONDARY_COLOR_ARRAY) );
252     CALL_DisableClientState( GET_DISPATCH(), (GL_FOG_COORD_ARRAY) );
253 }