Merge branch 'gallium-0.1' into gallium-0.2
[mesa.git] / src / glx / x11 / render2.c
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 **
34 */
35
36 #include "packrender.h"
37 #include "indirect.h"
38 #include "indirect_size.h"
39
40 /*
41 ** This file contains routines that might need to be transported as
42 ** GLXRender or GLXRenderLarge commands, and these commands don't
43 ** use the pixel header. See renderpix.c for those routines.
44 */
45
46 void __indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
47 GLint order, const GLdouble *pnts)
48 {
49 __GLX_DECLARE_VARIABLES();
50 GLint k;
51
52 __GLX_LOAD_VARIABLES();
53 k = __glMap1d_size(target);
54 if (k == 0) {
55 __glXSetError(gc, GL_INVALID_ENUM);
56 return;
57 } else if (stride < k || order <= 0) {
58 __glXSetError(gc, GL_INVALID_VALUE);
59 return;
60 }
61 compsize = k * order * __GLX_SIZE_FLOAT64;
62 cmdlen = 28+compsize;
63 if (!gc->currentDpy) return;
64
65 if (cmdlen <= gc->maxSmallRenderCommandSize) {
66 /* Use GLXRender protocol to send small command */
67 __GLX_BEGIN_VARIABLE(X_GLrop_Map1d,cmdlen);
68 __GLX_PUT_DOUBLE(4,u1);
69 __GLX_PUT_DOUBLE(12,u2);
70 __GLX_PUT_LONG(20,target);
71 __GLX_PUT_LONG(24,order);
72 /*
73 ** NOTE: the doubles that follow are not aligned because of 3
74 ** longs preceeding
75 */
76 __glFillMap1d(k, order, stride, pnts, (pc+28));
77 __GLX_END(cmdlen);
78 } else {
79 /* Use GLXRenderLarge protocol to send command */
80 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d,cmdlen+4);
81 __GLX_PUT_DOUBLE(8,u1);
82 __GLX_PUT_DOUBLE(16,u2);
83 __GLX_PUT_LONG(24,target);
84 __GLX_PUT_LONG(28,order);
85
86 /*
87 ** NOTE: the doubles that follow are not aligned because of 3
88 ** longs preceeding
89 */
90 if (stride != k) {
91 GLubyte *buf;
92
93 buf = (GLubyte *) Xmalloc(compsize);
94 if (!buf) {
95 __glXSetError(gc, GL_OUT_OF_MEMORY);
96 return;
97 }
98 __glFillMap1d(k, order, stride, pnts, buf);
99 __glXSendLargeCommand(gc, pc, 32, buf, compsize);
100 Xfree((char*) buf);
101 } else {
102 /* Data is already packed. Just send it out */
103 __glXSendLargeCommand(gc, pc, 32, pnts, compsize);
104 }
105 }
106 }
107
108 void __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
109 GLint order, const GLfloat *pnts)
110 {
111 __GLX_DECLARE_VARIABLES();
112 GLint k;
113
114 __GLX_LOAD_VARIABLES();
115 k = __glMap1f_size(target);
116 if (k == 0) {
117 __glXSetError(gc, GL_INVALID_ENUM);
118 return;
119 } else if (stride < k || order <= 0) {
120 __glXSetError(gc, GL_INVALID_VALUE);
121 return;
122 }
123 compsize = k * order * __GLX_SIZE_FLOAT32;
124 cmdlen = 20+compsize;
125 if (!gc->currentDpy) return;
126
127 /*
128 ** The order that arguments are packed is different from the order
129 ** for glMap1d.
130 */
131 if (cmdlen <= gc->maxSmallRenderCommandSize) {
132 /* Use GLXRender protocol to send small command */
133 __GLX_BEGIN_VARIABLE(X_GLrop_Map1f,cmdlen);
134 __GLX_PUT_LONG(4,target);
135 __GLX_PUT_FLOAT(8,u1);
136 __GLX_PUT_FLOAT(12,u2);
137 __GLX_PUT_LONG(16,order);
138 __glFillMap1f(k, order, stride, pnts, (GLubyte*) (pc+20));
139 __GLX_END(cmdlen);
140 } else {
141 /* Use GLXRenderLarge protocol to send command */
142 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f,cmdlen+4);
143 __GLX_PUT_LONG(8,target);
144 __GLX_PUT_FLOAT(12,u1);
145 __GLX_PUT_FLOAT(16,u2);
146 __GLX_PUT_LONG(20,order);
147
148 if (stride != k) {
149 GLubyte *buf;
150
151 buf = (GLubyte *) Xmalloc(compsize);
152 if (!buf) {
153 __glXSetError(gc, GL_OUT_OF_MEMORY);
154 return;
155 }
156 __glFillMap1f(k, order, stride, pnts, buf);
157 __glXSendLargeCommand(gc, pc, 24, buf, compsize);
158 Xfree((char*) buf);
159 } else {
160 /* Data is already packed. Just send it out */
161 __glXSendLargeCommand(gc, pc, 24, pnts, compsize);
162 }
163 }
164 }
165
166 void __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, GLint uord,
167 GLdouble v1, GLdouble v2, GLint vstr, GLint vord,
168 const GLdouble *pnts)
169 {
170 __GLX_DECLARE_VARIABLES();
171 GLint k;
172
173 __GLX_LOAD_VARIABLES();
174 k = __glMap2d_size(target);
175 if (k == 0) {
176 __glXSetError(gc, GL_INVALID_ENUM);
177 return;
178 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
179 __glXSetError(gc, GL_INVALID_VALUE);
180 return;
181 }
182 compsize = k * uord * vord * __GLX_SIZE_FLOAT64;
183 cmdlen = 48+compsize;
184 if (!gc->currentDpy) return;
185
186 if (cmdlen <= gc->maxSmallRenderCommandSize) {
187 /* Use GLXRender protocol to send small command */
188 __GLX_BEGIN_VARIABLE(X_GLrop_Map2d,cmdlen);
189 __GLX_PUT_DOUBLE(4,u1);
190 __GLX_PUT_DOUBLE(12,u2);
191 __GLX_PUT_DOUBLE(20,v1);
192 __GLX_PUT_DOUBLE(28,v2);
193 __GLX_PUT_LONG(36,target);
194 __GLX_PUT_LONG(40,uord);
195 __GLX_PUT_LONG(44,vord);
196 /*
197 ** Pack into a u-major ordering.
198 ** NOTE: the doubles that follow are not aligned because of 5
199 ** longs preceeding
200 */
201 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble*) (pc+48));
202 __GLX_END(cmdlen);
203 } else {
204 /* Use GLXRenderLarge protocol to send command */
205 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d,cmdlen+4);
206 __GLX_PUT_DOUBLE(8,u1);
207 __GLX_PUT_DOUBLE(16,u2);
208 __GLX_PUT_DOUBLE(24,v1);
209 __GLX_PUT_DOUBLE(32,v2);
210 __GLX_PUT_LONG(40,target);
211 __GLX_PUT_LONG(44,uord);
212 __GLX_PUT_LONG(48,vord);
213
214 /*
215 ** NOTE: the doubles that follow are not aligned because of 5
216 ** longs preceeding
217 */
218 if ((vstr != k) || (ustr != k*vord)) {
219 GLdouble *buf;
220
221 buf = (GLdouble *) Xmalloc(compsize);
222 if (!buf) {
223 __glXSetError(gc, GL_OUT_OF_MEMORY);
224 return;
225 }
226 /*
227 ** Pack into a u-major ordering.
228 */
229 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf);
230 __glXSendLargeCommand(gc, pc, 52, buf, compsize);
231 Xfree((char*) buf);
232 } else {
233 /* Data is already packed. Just send it out */
234 __glXSendLargeCommand(gc, pc, 52, pnts, compsize);
235 }
236 }
237 }
238
239 void __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, GLint uord,
240 GLfloat v1, GLfloat v2, GLint vstr, GLint vord,
241 const GLfloat *pnts)
242 {
243 __GLX_DECLARE_VARIABLES();
244 GLint k;
245
246 __GLX_LOAD_VARIABLES();
247 k = __glMap2f_size(target);
248 if (k == 0) {
249 __glXSetError(gc, GL_INVALID_ENUM);
250 return;
251 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
252 __glXSetError(gc, GL_INVALID_VALUE);
253 return;
254 }
255 compsize = k * uord * vord * __GLX_SIZE_FLOAT32;
256 cmdlen = 32+compsize;
257 if (!gc->currentDpy) return;
258
259 /*
260 ** The order that arguments are packed is different from the order
261 ** for glMap2d.
262 */
263 if (cmdlen <= gc->maxSmallRenderCommandSize) {
264 /* Use GLXRender protocol to send small command */
265 __GLX_BEGIN_VARIABLE(X_GLrop_Map2f,cmdlen);
266 __GLX_PUT_LONG(4,target);
267 __GLX_PUT_FLOAT(8,u1);
268 __GLX_PUT_FLOAT(12,u2);
269 __GLX_PUT_LONG(16,uord);
270 __GLX_PUT_FLOAT(20,v1);
271 __GLX_PUT_FLOAT(24,v2);
272 __GLX_PUT_LONG(28,vord);
273 /*
274 ** Pack into a u-major ordering.
275 */
276 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat*) (pc+32));
277 __GLX_END(cmdlen);
278 } else {
279 /* Use GLXRenderLarge protocol to send command */
280 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f,cmdlen+4);
281 __GLX_PUT_LONG(8,target);
282 __GLX_PUT_FLOAT(12,u1);
283 __GLX_PUT_FLOAT(16,u2);
284 __GLX_PUT_LONG(20,uord);
285 __GLX_PUT_FLOAT(24,v1);
286 __GLX_PUT_FLOAT(28,v2);
287 __GLX_PUT_LONG(32,vord);
288
289 if ((vstr != k) || (ustr != k*vord)) {
290 GLfloat *buf;
291
292 buf = (GLfloat *) Xmalloc(compsize);
293 if (!buf) {
294 __glXSetError(gc, GL_OUT_OF_MEMORY);
295 return;
296 }
297 /*
298 ** Pack into a u-major ordering.
299 */
300 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf);
301 __glXSendLargeCommand(gc, pc, 36, buf, compsize);
302 Xfree((char*) buf);
303 } else {
304 /* Data is already packed. Just send it out */
305 __glXSendLargeCommand(gc, pc, 36, pnts, compsize);
306 }
307 }
308 }
309
310 void __indirect_glEnable(GLenum cap)
311 {
312 __GLX_DECLARE_VARIABLES();
313
314 __GLX_LOAD_VARIABLES();
315 if (!gc->currentDpy) return;
316
317 switch(cap) {
318 case GL_COLOR_ARRAY:
319 case GL_EDGE_FLAG_ARRAY:
320 case GL_INDEX_ARRAY:
321 case GL_NORMAL_ARRAY:
322 case GL_TEXTURE_COORD_ARRAY:
323 case GL_VERTEX_ARRAY:
324 case GL_SECONDARY_COLOR_ARRAY:
325 case GL_FOG_COORD_ARRAY:
326 __indirect_glEnableClientState(cap);
327 return;
328 default:
329 break;
330 }
331
332 __GLX_BEGIN(X_GLrop_Enable,8);
333 __GLX_PUT_LONG(4,cap);
334 __GLX_END(8);
335 }
336
337 void __indirect_glDisable(GLenum cap)
338 {
339 __GLX_DECLARE_VARIABLES();
340
341 __GLX_LOAD_VARIABLES();
342 if (!gc->currentDpy) return;
343
344 switch(cap) {
345 case GL_COLOR_ARRAY:
346 case GL_EDGE_FLAG_ARRAY:
347 case GL_INDEX_ARRAY:
348 case GL_NORMAL_ARRAY:
349 case GL_TEXTURE_COORD_ARRAY:
350 case GL_VERTEX_ARRAY:
351 case GL_SECONDARY_COLOR_ARRAY:
352 case GL_FOG_COORD_ARRAY:
353 __indirect_glDisableClientState(cap);
354 return;
355 default:
356 break;
357 }
358
359 __GLX_BEGIN(X_GLrop_Disable,8);
360 __GLX_PUT_LONG(4,cap);
361 __GLX_END(8);
362 }