Use indirect_size.c and indirect_size.h generated by using
[mesa.git] / src / glx / x11 / render2.c
1 /* $XFree86: xc/lib/GL/glx/render2.c,v 1.6 2004/01/31 09:29:33 alanh Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 #include "packrender.h"
38 #include "indirect.h"
39 #include "size.h"
40
41 /*
42 ** This file contains routines that might need to be transported as
43 ** GLXRender or GLXRenderLarge commands, and these commands don't
44 ** use the pixel header. See renderpix.c for those routines.
45 */
46
47 void __indirect_glCallLists(GLsizei n, GLenum type, const GLvoid *lists)
48 {
49 __GLX_DECLARE_VARIABLES();
50 __GLX_LOAD_VARIABLES();
51
52 compsize = (n <= 0) ? 0 : __glCallLists_size(type) * n;
53 cmdlen = __GLX_PAD(12 + compsize);
54 if (!gc->currentDpy) return;
55
56 if (cmdlen <= gc->maxSmallRenderCommandSize) {
57 /* Use GLXRender protocol to send small command */
58 __GLX_BEGIN_VARIABLE(X_GLrop_CallLists,cmdlen);
59 __GLX_PUT_LONG(4,n);
60 __GLX_PUT_LONG(8,type);
61 __GLX_PUT_CHAR_ARRAY(12,lists,compsize);
62 __GLX_END(cmdlen);
63 } else {
64 /* Use GLXRenderLarge protocol to send command */
65 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CallLists,cmdlen+4);
66 __GLX_PUT_LONG(8,n);
67 __GLX_PUT_LONG(12,type);
68 __glXSendLargeCommand(gc, pc, 16, lists, compsize);
69 }
70 }
71
72 void __indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
73 GLint order, const GLdouble *pnts)
74 {
75 __GLX_DECLARE_VARIABLES();
76 GLint k;
77
78 __GLX_LOAD_VARIABLES();
79 k = __glMap1d_size(target);
80 if (k == 0) {
81 __glXSetError(gc, GL_INVALID_ENUM);
82 return;
83 } else if (stride < k || order <= 0) {
84 __glXSetError(gc, GL_INVALID_VALUE);
85 return;
86 }
87 compsize = k * order * __GLX_SIZE_FLOAT64;
88 cmdlen = 28+compsize;
89 if (!gc->currentDpy) return;
90
91 if (cmdlen <= gc->maxSmallRenderCommandSize) {
92 /* Use GLXRender protocol to send small command */
93 __GLX_BEGIN_VARIABLE(X_GLrop_Map1d,cmdlen);
94 __GLX_PUT_DOUBLE(4,u1);
95 __GLX_PUT_DOUBLE(12,u2);
96 __GLX_PUT_LONG(20,target);
97 __GLX_PUT_LONG(24,order);
98 /*
99 ** NOTE: the doubles that follow are not aligned because of 3
100 ** longs preceeding
101 */
102 __glFillMap1d(k, order, stride, pnts, (pc+28));
103 __GLX_END(cmdlen);
104 } else {
105 /* Use GLXRenderLarge protocol to send command */
106 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d,cmdlen+4);
107 __GLX_PUT_DOUBLE(8,u1);
108 __GLX_PUT_DOUBLE(16,u2);
109 __GLX_PUT_LONG(24,target);
110 __GLX_PUT_LONG(28,order);
111
112 /*
113 ** NOTE: the doubles that follow are not aligned because of 3
114 ** longs preceeding
115 */
116 if (stride != k) {
117 GLubyte *buf;
118
119 buf = (GLubyte *) Xmalloc(compsize);
120 if (!buf) {
121 __glXSetError(gc, GL_OUT_OF_MEMORY);
122 return;
123 }
124 __glFillMap1d(k, order, stride, pnts, buf);
125 __glXSendLargeCommand(gc, pc, 32, buf, compsize);
126 Xfree((char*) buf);
127 } else {
128 /* Data is already packed. Just send it out */
129 __glXSendLargeCommand(gc, pc, 32, pnts, compsize);
130 }
131 }
132 }
133
134 void __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
135 GLint order, const GLfloat *pnts)
136 {
137 __GLX_DECLARE_VARIABLES();
138 GLint k;
139
140 __GLX_LOAD_VARIABLES();
141 k = __glMap1f_size(target);
142 if (k == 0) {
143 __glXSetError(gc, GL_INVALID_ENUM);
144 return;
145 } else if (stride < k || order <= 0) {
146 __glXSetError(gc, GL_INVALID_VALUE);
147 return;
148 }
149 compsize = k * order * __GLX_SIZE_FLOAT32;
150 cmdlen = 20+compsize;
151 if (!gc->currentDpy) return;
152
153 /*
154 ** The order that arguments are packed is different from the order
155 ** for glMap1d.
156 */
157 if (cmdlen <= gc->maxSmallRenderCommandSize) {
158 /* Use GLXRender protocol to send small command */
159 __GLX_BEGIN_VARIABLE(X_GLrop_Map1f,cmdlen);
160 __GLX_PUT_LONG(4,target);
161 __GLX_PUT_FLOAT(8,u1);
162 __GLX_PUT_FLOAT(12,u2);
163 __GLX_PUT_LONG(16,order);
164 __glFillMap1f(k, order, stride, pnts, (GLubyte*) (pc+20));
165 __GLX_END(cmdlen);
166 } else {
167 /* Use GLXRenderLarge protocol to send command */
168 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f,cmdlen+4);
169 __GLX_PUT_LONG(8,target);
170 __GLX_PUT_FLOAT(12,u1);
171 __GLX_PUT_FLOAT(16,u2);
172 __GLX_PUT_LONG(20,order);
173
174 if (stride != k) {
175 GLubyte *buf;
176
177 buf = (GLubyte *) Xmalloc(compsize);
178 if (!buf) {
179 __glXSetError(gc, GL_OUT_OF_MEMORY);
180 return;
181 }
182 __glFillMap1f(k, order, stride, pnts, buf);
183 __glXSendLargeCommand(gc, pc, 24, buf, compsize);
184 Xfree((char*) buf);
185 } else {
186 /* Data is already packed. Just send it out */
187 __glXSendLargeCommand(gc, pc, 24, pnts, compsize);
188 }
189 }
190 }
191
192 void __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, GLint uord,
193 GLdouble v1, GLdouble v2, GLint vstr, GLint vord,
194 const GLdouble *pnts)
195 {
196 __GLX_DECLARE_VARIABLES();
197 GLint k;
198
199 __GLX_LOAD_VARIABLES();
200 k = __glMap2d_size(target);
201 if (k == 0) {
202 __glXSetError(gc, GL_INVALID_ENUM);
203 return;
204 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
205 __glXSetError(gc, GL_INVALID_VALUE);
206 return;
207 }
208 compsize = k * uord * vord * __GLX_SIZE_FLOAT64;
209 cmdlen = 48+compsize;
210 if (!gc->currentDpy) return;
211
212 if (cmdlen <= gc->maxSmallRenderCommandSize) {
213 /* Use GLXRender protocol to send small command */
214 __GLX_BEGIN_VARIABLE(X_GLrop_Map2d,cmdlen);
215 __GLX_PUT_DOUBLE(4,u1);
216 __GLX_PUT_DOUBLE(12,u2);
217 __GLX_PUT_DOUBLE(20,v1);
218 __GLX_PUT_DOUBLE(28,v2);
219 __GLX_PUT_LONG(36,target);
220 __GLX_PUT_LONG(40,uord);
221 __GLX_PUT_LONG(44,vord);
222 /*
223 ** Pack into a u-major ordering.
224 ** NOTE: the doubles that follow are not aligned because of 5
225 ** longs preceeding
226 */
227 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble*) (pc+48));
228 __GLX_END(cmdlen);
229 } else {
230 /* Use GLXRenderLarge protocol to send command */
231 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d,cmdlen+4);
232 __GLX_PUT_DOUBLE(8,u1);
233 __GLX_PUT_DOUBLE(16,u2);
234 __GLX_PUT_DOUBLE(24,v1);
235 __GLX_PUT_DOUBLE(32,v2);
236 __GLX_PUT_LONG(40,target);
237 __GLX_PUT_LONG(44,uord);
238 __GLX_PUT_LONG(48,vord);
239
240 /*
241 ** NOTE: the doubles that follow are not aligned because of 5
242 ** longs preceeding
243 */
244 if ((vstr != k) || (ustr != k*vord)) {
245 GLdouble *buf;
246
247 buf = (GLdouble *) Xmalloc(compsize);
248 if (!buf) {
249 __glXSetError(gc, GL_OUT_OF_MEMORY);
250 return;
251 }
252 /*
253 ** Pack into a u-major ordering.
254 */
255 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf);
256 __glXSendLargeCommand(gc, pc, 52, buf, compsize);
257 Xfree((char*) buf);
258 } else {
259 /* Data is already packed. Just send it out */
260 __glXSendLargeCommand(gc, pc, 52, pnts, compsize);
261 }
262 }
263 }
264
265 void __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, GLint uord,
266 GLfloat v1, GLfloat v2, GLint vstr, GLint vord,
267 const GLfloat *pnts)
268 {
269 __GLX_DECLARE_VARIABLES();
270 GLint k;
271
272 __GLX_LOAD_VARIABLES();
273 k = __glMap2f_size(target);
274 if (k == 0) {
275 __glXSetError(gc, GL_INVALID_ENUM);
276 return;
277 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
278 __glXSetError(gc, GL_INVALID_VALUE);
279 return;
280 }
281 compsize = k * uord * vord * __GLX_SIZE_FLOAT32;
282 cmdlen = 32+compsize;
283 if (!gc->currentDpy) return;
284
285 /*
286 ** The order that arguments are packed is different from the order
287 ** for glMap2d.
288 */
289 if (cmdlen <= gc->maxSmallRenderCommandSize) {
290 /* Use GLXRender protocol to send small command */
291 __GLX_BEGIN_VARIABLE(X_GLrop_Map2f,cmdlen);
292 __GLX_PUT_LONG(4,target);
293 __GLX_PUT_FLOAT(8,u1);
294 __GLX_PUT_FLOAT(12,u2);
295 __GLX_PUT_LONG(16,uord);
296 __GLX_PUT_FLOAT(20,v1);
297 __GLX_PUT_FLOAT(24,v2);
298 __GLX_PUT_LONG(28,vord);
299 /*
300 ** Pack into a u-major ordering.
301 */
302 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat*) (pc+32));
303 __GLX_END(cmdlen);
304 } else {
305 /* Use GLXRenderLarge protocol to send command */
306 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f,cmdlen+4);
307 __GLX_PUT_LONG(8,target);
308 __GLX_PUT_FLOAT(12,u1);
309 __GLX_PUT_FLOAT(16,u2);
310 __GLX_PUT_LONG(20,uord);
311 __GLX_PUT_FLOAT(24,v1);
312 __GLX_PUT_FLOAT(28,v2);
313 __GLX_PUT_LONG(32,vord);
314
315 if ((vstr != k) || (ustr != k*vord)) {
316 GLfloat *buf;
317
318 buf = (GLfloat *) Xmalloc(compsize);
319 if (!buf) {
320 __glXSetError(gc, GL_OUT_OF_MEMORY);
321 return;
322 }
323 /*
324 ** Pack into a u-major ordering.
325 */
326 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf);
327 __glXSendLargeCommand(gc, pc, 36, buf, compsize);
328 Xfree((char*) buf);
329 } else {
330 /* Data is already packed. Just send it out */
331 __glXSendLargeCommand(gc, pc, 36, pnts, compsize);
332 }
333 }
334 }
335
336 void __indirect_glPixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
337 {
338 __GLX_DECLARE_VARIABLES();
339
340 __GLX_LOAD_VARIABLES();
341 if (mapsize < 0) {
342 __glXSetError(gc, GL_INVALID_VALUE);
343 return;
344 }
345 compsize = mapsize * __GLX_SIZE_FLOAT32;
346 cmdlen = 12+compsize;
347 if (!gc->currentDpy) return;
348
349 if (cmdlen <= gc->maxSmallRenderCommandSize) {
350 /* Use GLXRender protocol to send small command */
351 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapfv,cmdlen);
352 __GLX_PUT_LONG(4,map);
353 __GLX_PUT_LONG(8,mapsize);
354 __GLX_PUT_FLOAT_ARRAY(12,values,mapsize);
355 __GLX_END(cmdlen);
356 } else {
357 /* Use GLXRenderLarge protocol to send command */
358 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapfv,cmdlen+4);
359 __GLX_PUT_LONG(8,map);
360 __GLX_PUT_LONG(12,mapsize);
361 __glXSendLargeCommand(gc, pc, 16, values, compsize);
362 }
363 }
364
365 void __indirect_glPixelMapuiv(GLenum map, GLint mapsize, const GLuint *values)
366 {
367 __GLX_DECLARE_VARIABLES();
368
369 __GLX_LOAD_VARIABLES();
370 if (mapsize < 0) {
371 __glXSetError(gc, GL_INVALID_VALUE);
372 return;
373 }
374 compsize = mapsize * __GLX_SIZE_CARD32;
375 cmdlen = 12+compsize;
376 if (!gc->currentDpy) return;
377
378 if (cmdlen <= gc->maxSmallRenderCommandSize) {
379 /* Use GLXRender protocol to send small command */
380 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapuiv,cmdlen);
381 __GLX_PUT_LONG(4,map);
382 __GLX_PUT_LONG(8,mapsize);
383 __GLX_PUT_LONG_ARRAY(12,values,mapsize);
384 __GLX_END(cmdlen);
385 } else {
386 /* Use GLXRenderLarge protocol to send command */
387 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapuiv,cmdlen+4);
388 __GLX_PUT_LONG(8,map);
389 __GLX_PUT_LONG(12,mapsize);
390 __glXSendLargeCommand(gc, pc, 16, values, compsize);
391 }
392 }
393
394 void __indirect_glPixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
395 {
396 __GLX_DECLARE_VARIABLES();
397
398 __GLX_LOAD_VARIABLES();
399 if (mapsize < 0) {
400 __glXSetError(gc, GL_INVALID_VALUE);
401 return;
402 }
403 compsize = mapsize * __GLX_SIZE_CARD16;
404 cmdlen = __GLX_PAD(12 + compsize);
405 if (!gc->currentDpy) return;
406
407 if (cmdlen <= gc->maxSmallRenderCommandSize) {
408 /* Use GLXRender protocol to send small command */
409 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapusv,cmdlen);
410 __GLX_PUT_LONG(4,map);
411 __GLX_PUT_LONG(8,mapsize);
412 __GLX_PUT_SHORT_ARRAY(12,values,mapsize);
413 __GLX_END(cmdlen);
414 } else {
415 /* Use GLXRenderLarge protocol to send command */
416 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapusv,cmdlen+4);
417 __GLX_PUT_LONG(8,map);
418 __GLX_PUT_LONG(12,mapsize);
419 __glXSendLargeCommand(gc, pc, 16, values, compsize);
420 }
421 }
422
423 void __indirect_glEnable(GLenum cap)
424 {
425 __GLX_DECLARE_VARIABLES();
426
427 __GLX_LOAD_VARIABLES();
428 if (!gc->currentDpy) return;
429
430 switch(cap) {
431 case GL_COLOR_ARRAY:
432 case GL_EDGE_FLAG_ARRAY:
433 case GL_INDEX_ARRAY:
434 case GL_NORMAL_ARRAY:
435 case GL_TEXTURE_COORD_ARRAY:
436 case GL_VERTEX_ARRAY:
437 case GL_SECONDARY_COLOR_ARRAY:
438 case GL_FOG_COORD_ARRAY:
439 __indirect_glEnableClientState(cap);
440 return;
441 default:
442 break;
443 }
444
445 __GLX_BEGIN(X_GLrop_Enable,8);
446 __GLX_PUT_LONG(4,cap);
447 __GLX_END(8);
448 }
449
450 void __indirect_glDisable(GLenum cap)
451 {
452 __GLX_DECLARE_VARIABLES();
453
454 __GLX_LOAD_VARIABLES();
455 if (!gc->currentDpy) return;
456
457 switch(cap) {
458 case GL_COLOR_ARRAY:
459 case GL_EDGE_FLAG_ARRAY:
460 case GL_INDEX_ARRAY:
461 case GL_NORMAL_ARRAY:
462 case GL_TEXTURE_COORD_ARRAY:
463 case GL_VERTEX_ARRAY:
464 case GL_SECONDARY_COLOR_ARRAY:
465 case GL_FOG_COORD_ARRAY:
466 __indirect_glDisableClientState(cap);
467 return;
468 default:
469 break;
470 }
471
472 __GLX_BEGIN(X_GLrop_Disable,8);
473 __GLX_PUT_LONG(4,cap);
474 __GLX_END(8);
475 }
476
477 void __indirect_glSampleCoverageARB( GLfloat value, GLboolean invert )
478 {
479 __GLX_DECLARE_VARIABLES();
480
481 __GLX_LOAD_VARIABLES();
482 if (!gc->currentDpy) return;
483
484 __GLX_BEGIN(X_GLrop_SampleCoverageARB,12);
485 __GLX_PUT_FLOAT(4,value);
486 __GLX_PUT_CHAR(8,invert);
487 __GLX_END(12);
488 }
489
490 void __indirect_glSampleMaskSGIS( GLfloat value, GLboolean invert )
491 {
492 __GLX_DECLARE_VARIABLES();
493
494 __GLX_LOAD_VARIABLES();
495 if (!gc->currentDpy) return;
496
497 __GLX_BEGIN(X_GLvop_SampleMaskSGIS,12);
498 __GLX_PUT_FLOAT(4,value);
499 __GLX_PUT_CHAR(8,invert);
500 __GLX_END(12);
501 }
502
503 void __indirect_glSamplePatternSGIS( GLenum pass )
504 {
505 __GLX_DECLARE_VARIABLES();
506
507 __GLX_LOAD_VARIABLES();
508 if (!gc->currentDpy) return;
509
510 __GLX_BEGIN(X_GLvop_SamplePatternSGIS,8);
511 __GLX_PUT_LONG(4,pass);
512 __GLX_END(8);
513 }