the file was empty!
[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 "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 glCallLists(GLsizei n, GLenum type, const GLvoid *lists)
47 {
48 __GLX_DECLARE_VARIABLES();
49 __GLX_LOAD_VARIABLES();
50
51 compsize = __glCallLists_size(n,type);
52 cmdlen = __GLX_PAD(12 + compsize);
53 if (!gc->currentDpy) return;
54
55 if (cmdlen <= gc->maxSmallRenderCommandSize) {
56 /* Use GLXRender protocol to send small command */
57 __GLX_BEGIN_VARIABLE(X_GLrop_CallLists,cmdlen);
58 __GLX_PUT_LONG(4,n);
59 __GLX_PUT_LONG(8,type);
60 __GLX_PUT_CHAR_ARRAY(12,lists,compsize);
61 __GLX_END(cmdlen);
62 } else {
63 /* Use GLXRenderLarge protocol to send command */
64 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CallLists,cmdlen+4);
65 __GLX_PUT_LONG(8,n);
66 __GLX_PUT_LONG(12,type);
67 __glXSendLargeCommand(gc, pc, 16, lists, compsize);
68 }
69 }
70
71 void glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
72 GLint order, const GLdouble *pnts)
73 {
74 __GLX_DECLARE_VARIABLES();
75 GLint k;
76
77 __GLX_LOAD_VARIABLES();
78 k = __glEvalComputeK(target);
79 if (k == 0) {
80 __glXSetError(gc, GL_INVALID_ENUM);
81 return;
82 } else if (stride < k || order <= 0) {
83 __glXSetError(gc, GL_INVALID_VALUE);
84 return;
85 }
86 compsize = k * order * __GLX_SIZE_FLOAT64;
87 cmdlen = 28+compsize;
88 if (!gc->currentDpy) return;
89
90 if (cmdlen <= gc->maxSmallRenderCommandSize) {
91 /* Use GLXRender protocol to send small command */
92 __GLX_BEGIN_VARIABLE(X_GLrop_Map1d,cmdlen);
93 __GLX_PUT_DOUBLE(4,u1);
94 __GLX_PUT_DOUBLE(12,u2);
95 __GLX_PUT_LONG(20,target);
96 __GLX_PUT_LONG(24,order);
97 /*
98 ** NOTE: the doubles that follow are not aligned because of 3
99 ** longs preceeding
100 */
101 __glFillMap1d(k, order, stride, pnts, (pc+28));
102 __GLX_END(cmdlen);
103 } else {
104 /* Use GLXRenderLarge protocol to send command */
105 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d,cmdlen+4);
106 __GLX_PUT_DOUBLE(8,u1);
107 __GLX_PUT_DOUBLE(16,u2);
108 __GLX_PUT_LONG(24,target);
109 __GLX_PUT_LONG(28,order);
110
111 /*
112 ** NOTE: the doubles that follow are not aligned because of 3
113 ** longs preceeding
114 */
115 if (stride != k) {
116 GLubyte *buf;
117
118 buf = (GLubyte *) Xmalloc(compsize);
119 if (!buf) {
120 __glXSetError(gc, GL_OUT_OF_MEMORY);
121 return;
122 }
123 __glFillMap1d(k, order, stride, pnts, buf);
124 __glXSendLargeCommand(gc, pc, 32, buf, compsize);
125 Xfree((char*) buf);
126 } else {
127 /* Data is already packed. Just send it out */
128 __glXSendLargeCommand(gc, pc, 32, pnts, compsize);
129 }
130 }
131 }
132
133 void glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
134 GLint order, const GLfloat *pnts)
135 {
136 __GLX_DECLARE_VARIABLES();
137 GLint k;
138
139 __GLX_LOAD_VARIABLES();
140 k = __glEvalComputeK(target);
141 if (k == 0) {
142 __glXSetError(gc, GL_INVALID_ENUM);
143 return;
144 } else if (stride < k || order <= 0) {
145 __glXSetError(gc, GL_INVALID_VALUE);
146 return;
147 }
148 compsize = k * order * __GLX_SIZE_FLOAT32;
149 cmdlen = 20+compsize;
150 if (!gc->currentDpy) return;
151
152 /*
153 ** The order that arguments are packed is different from the order
154 ** for glMap1d.
155 */
156 if (cmdlen <= gc->maxSmallRenderCommandSize) {
157 /* Use GLXRender protocol to send small command */
158 __GLX_BEGIN_VARIABLE(X_GLrop_Map1f,cmdlen);
159 __GLX_PUT_LONG(4,target);
160 __GLX_PUT_FLOAT(8,u1);
161 __GLX_PUT_FLOAT(12,u2);
162 __GLX_PUT_LONG(16,order);
163 __glFillMap1f(k, order, stride, pnts, (GLubyte*) (pc+20));
164 __GLX_END(cmdlen);
165 } else {
166 /* Use GLXRenderLarge protocol to send command */
167 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f,cmdlen+4);
168 __GLX_PUT_LONG(8,target);
169 __GLX_PUT_FLOAT(12,u1);
170 __GLX_PUT_FLOAT(16,u2);
171 __GLX_PUT_LONG(20,order);
172
173 if (stride != k) {
174 GLubyte *buf;
175
176 buf = (GLubyte *) Xmalloc(compsize);
177 if (!buf) {
178 __glXSetError(gc, GL_OUT_OF_MEMORY);
179 return;
180 }
181 __glFillMap1f(k, order, stride, pnts, buf);
182 __glXSendLargeCommand(gc, pc, 24, buf, compsize);
183 Xfree((char*) buf);
184 } else {
185 /* Data is already packed. Just send it out */
186 __glXSendLargeCommand(gc, pc, 24, pnts, compsize);
187 }
188 }
189 }
190
191 void glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, GLint uord,
192 GLdouble v1, GLdouble v2, GLint vstr, GLint vord,
193 const GLdouble *pnts)
194 {
195 __GLX_DECLARE_VARIABLES();
196 GLint k;
197
198 __GLX_LOAD_VARIABLES();
199 k = __glEvalComputeK(target);
200 if (k == 0) {
201 __glXSetError(gc, GL_INVALID_ENUM);
202 return;
203 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
204 __glXSetError(gc, GL_INVALID_VALUE);
205 return;
206 }
207 compsize = k * uord * vord * __GLX_SIZE_FLOAT64;
208 cmdlen = 48+compsize;
209 if (!gc->currentDpy) return;
210
211 if (cmdlen <= gc->maxSmallRenderCommandSize) {
212 /* Use GLXRender protocol to send small command */
213 __GLX_BEGIN_VARIABLE(X_GLrop_Map2d,cmdlen);
214 __GLX_PUT_DOUBLE(4,u1);
215 __GLX_PUT_DOUBLE(12,u2);
216 __GLX_PUT_DOUBLE(20,v1);
217 __GLX_PUT_DOUBLE(28,v2);
218 __GLX_PUT_LONG(36,target);
219 __GLX_PUT_LONG(40,uord);
220 __GLX_PUT_LONG(44,vord);
221 /*
222 ** Pack into a u-major ordering.
223 ** NOTE: the doubles that follow are not aligned because of 5
224 ** longs preceeding
225 */
226 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble*) (pc+48));
227 __GLX_END(cmdlen);
228 } else {
229 /* Use GLXRenderLarge protocol to send command */
230 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d,cmdlen+4);
231 __GLX_PUT_DOUBLE(8,u1);
232 __GLX_PUT_DOUBLE(16,u2);
233 __GLX_PUT_DOUBLE(24,v1);
234 __GLX_PUT_DOUBLE(32,v2);
235 __GLX_PUT_LONG(40,target);
236 __GLX_PUT_LONG(44,uord);
237 __GLX_PUT_LONG(48,vord);
238
239 /*
240 ** NOTE: the doubles that follow are not aligned because of 5
241 ** longs preceeding
242 */
243 if ((vstr != k) || (ustr != k*vord)) {
244 GLdouble *buf;
245
246 buf = (GLdouble *) Xmalloc(compsize);
247 if (!buf) {
248 __glXSetError(gc, GL_OUT_OF_MEMORY);
249 return;
250 }
251 /*
252 ** Pack into a u-major ordering.
253 */
254 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf);
255 __glXSendLargeCommand(gc, pc, 52, buf, compsize);
256 Xfree((char*) buf);
257 } else {
258 /* Data is already packed. Just send it out */
259 __glXSendLargeCommand(gc, pc, 52, pnts, compsize);
260 }
261 }
262 }
263
264 void glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, GLint uord,
265 GLfloat v1, GLfloat v2, GLint vstr, GLint vord,
266 const GLfloat *pnts)
267 {
268 __GLX_DECLARE_VARIABLES();
269 GLint k;
270
271 __GLX_LOAD_VARIABLES();
272 k = __glEvalComputeK(target);
273 if (k == 0) {
274 __glXSetError(gc, GL_INVALID_ENUM);
275 return;
276 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
277 __glXSetError(gc, GL_INVALID_VALUE);
278 return;
279 }
280 compsize = k * uord * vord * __GLX_SIZE_FLOAT32;
281 cmdlen = 32+compsize;
282 if (!gc->currentDpy) return;
283
284 /*
285 ** The order that arguments are packed is different from the order
286 ** for glMap2d.
287 */
288 if (cmdlen <= gc->maxSmallRenderCommandSize) {
289 /* Use GLXRender protocol to send small command */
290 __GLX_BEGIN_VARIABLE(X_GLrop_Map2f,cmdlen);
291 __GLX_PUT_LONG(4,target);
292 __GLX_PUT_FLOAT(8,u1);
293 __GLX_PUT_FLOAT(12,u2);
294 __GLX_PUT_LONG(16,uord);
295 __GLX_PUT_FLOAT(20,v1);
296 __GLX_PUT_FLOAT(24,v2);
297 __GLX_PUT_LONG(28,vord);
298 /*
299 ** Pack into a u-major ordering.
300 */
301 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat*) (pc+32));
302 __GLX_END(cmdlen);
303 } else {
304 /* Use GLXRenderLarge protocol to send command */
305 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f,cmdlen+4);
306 __GLX_PUT_LONG(8,target);
307 __GLX_PUT_FLOAT(12,u1);
308 __GLX_PUT_FLOAT(16,u2);
309 __GLX_PUT_LONG(20,uord);
310 __GLX_PUT_FLOAT(24,v1);
311 __GLX_PUT_FLOAT(28,v2);
312 __GLX_PUT_LONG(32,vord);
313
314 if ((vstr != k) || (ustr != k*vord)) {
315 GLfloat *buf;
316
317 buf = (GLfloat *) Xmalloc(compsize);
318 if (!buf) {
319 __glXSetError(gc, GL_OUT_OF_MEMORY);
320 return;
321 }
322 /*
323 ** Pack into a u-major ordering.
324 */
325 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf);
326 __glXSendLargeCommand(gc, pc, 36, buf, compsize);
327 Xfree((char*) buf);
328 } else {
329 /* Data is already packed. Just send it out */
330 __glXSendLargeCommand(gc, pc, 36, pnts, compsize);
331 }
332 }
333 }
334
335 void glPixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
336 {
337 __GLX_DECLARE_VARIABLES();
338
339 __GLX_LOAD_VARIABLES();
340 if (mapsize < 0) {
341 __glXSetError(gc, GL_INVALID_VALUE);
342 return;
343 }
344 compsize = mapsize * __GLX_SIZE_FLOAT32;
345 cmdlen = 12+compsize;
346 if (!gc->currentDpy) return;
347
348 if (cmdlen <= gc->maxSmallRenderCommandSize) {
349 /* Use GLXRender protocol to send small command */
350 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapfv,cmdlen);
351 __GLX_PUT_LONG(4,map);
352 __GLX_PUT_LONG(8,mapsize);
353 __GLX_PUT_FLOAT_ARRAY(12,values,mapsize);
354 __GLX_END(cmdlen);
355 } else {
356 /* Use GLXRenderLarge protocol to send command */
357 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapfv,cmdlen+4);
358 __GLX_PUT_LONG(8,map);
359 __GLX_PUT_LONG(12,mapsize);
360 __glXSendLargeCommand(gc, pc, 16, values, compsize);
361 }
362 }
363
364 void glPixelMapuiv(GLenum map, GLint mapsize, const GLuint *values)
365 {
366 __GLX_DECLARE_VARIABLES();
367
368 __GLX_LOAD_VARIABLES();
369 if (mapsize < 0) {
370 __glXSetError(gc, GL_INVALID_VALUE);
371 return;
372 }
373 compsize = mapsize * __GLX_SIZE_CARD32;
374 cmdlen = 12+compsize;
375 if (!gc->currentDpy) return;
376
377 if (cmdlen <= gc->maxSmallRenderCommandSize) {
378 /* Use GLXRender protocol to send small command */
379 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapuiv,cmdlen);
380 __GLX_PUT_LONG(4,map);
381 __GLX_PUT_LONG(8,mapsize);
382 __GLX_PUT_LONG_ARRAY(12,values,mapsize);
383 __GLX_END(cmdlen);
384 } else {
385 /* Use GLXRenderLarge protocol to send command */
386 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapuiv,cmdlen+4);
387 __GLX_PUT_LONG(8,map);
388 __GLX_PUT_LONG(12,mapsize);
389 __glXSendLargeCommand(gc, pc, 16, values, compsize);
390 }
391 }
392
393 void glPixelMapusv(GLenum map, GLint mapsize, const GLushort *values)
394 {
395 __GLX_DECLARE_VARIABLES();
396
397 __GLX_LOAD_VARIABLES();
398 if (mapsize < 0) {
399 __glXSetError(gc, GL_INVALID_VALUE);
400 return;
401 }
402 compsize = mapsize * __GLX_SIZE_CARD16;
403 cmdlen = __GLX_PAD(12 + compsize);
404 if (!gc->currentDpy) return;
405
406 if (cmdlen <= gc->maxSmallRenderCommandSize) {
407 /* Use GLXRender protocol to send small command */
408 __GLX_BEGIN_VARIABLE(X_GLrop_PixelMapusv,cmdlen);
409 __GLX_PUT_LONG(4,map);
410 __GLX_PUT_LONG(8,mapsize);
411 __GLX_PUT_SHORT_ARRAY(12,values,mapsize);
412 __GLX_END(cmdlen);
413 } else {
414 /* Use GLXRenderLarge protocol to send command */
415 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_PixelMapusv,cmdlen+4);
416 __GLX_PUT_LONG(8,map);
417 __GLX_PUT_LONG(12,mapsize);
418 __glXSendLargeCommand(gc, pc, 16, values, compsize);
419 }
420 }
421
422 void glEnable(GLenum cap)
423 {
424 __GLX_DECLARE_VARIABLES();
425
426 __GLX_LOAD_VARIABLES();
427 if (!gc->currentDpy) return;
428
429 switch(cap) {
430 case GL_COLOR_ARRAY:
431 case GL_EDGE_FLAG_ARRAY:
432 case GL_INDEX_ARRAY:
433 case GL_NORMAL_ARRAY:
434 case GL_TEXTURE_COORD_ARRAY:
435 case GL_VERTEX_ARRAY:
436 case GL_SECONDARY_COLOR_ARRAY:
437 case GL_FOG_COORD_ARRAY:
438 glEnableClientState(cap);
439 return;
440 default:
441 break;
442 }
443
444 __GLX_BEGIN(X_GLrop_Enable,8);
445 __GLX_PUT_LONG(4,cap);
446 __GLX_END(8);
447 }
448
449 void glDisable(GLenum cap)
450 {
451 __GLX_DECLARE_VARIABLES();
452
453 __GLX_LOAD_VARIABLES();
454 if (!gc->currentDpy) return;
455
456 switch(cap) {
457 case GL_COLOR_ARRAY:
458 case GL_EDGE_FLAG_ARRAY:
459 case GL_INDEX_ARRAY:
460 case GL_NORMAL_ARRAY:
461 case GL_TEXTURE_COORD_ARRAY:
462 case GL_VERTEX_ARRAY:
463 case GL_SECONDARY_COLOR_ARRAY:
464 case GL_FOG_COORD_ARRAY:
465 glDisableClientState(cap);
466 return;
467 default:
468 break;
469 }
470
471 __GLX_BEGIN(X_GLrop_Disable,8);
472 __GLX_PUT_LONG(4,cap);
473 __GLX_END(8);
474 }
475
476 void glSampleCoverageARB( GLfloat value, GLboolean invert )
477 {
478 __GLX_DECLARE_VARIABLES();
479
480 __GLX_LOAD_VARIABLES();
481 if (!gc->currentDpy) return;
482
483 __GLX_BEGIN(X_GLrop_SampleCoverageARB,12);
484 __GLX_PUT_FLOAT(4,value);
485 __GLX_PUT_CHAR(8,invert);
486 __GLX_END(12);
487 }
488
489 void glSampleMaskSGIS( GLfloat value, GLboolean invert )
490 {
491 __GLX_DECLARE_VARIABLES();
492
493 __GLX_LOAD_VARIABLES();
494 if (!gc->currentDpy) return;
495
496 __GLX_BEGIN(X_GLvop_SampleMaskSGIS,12);
497 __GLX_PUT_FLOAT(4,value);
498 __GLX_PUT_CHAR(8,invert);
499 __GLX_END(12);
500 }
501
502 void glSamplePatternSGIS( GLenum pass )
503 {
504 __GLX_DECLARE_VARIABLES();
505
506 __GLX_LOAD_VARIABLES();
507 if (!gc->currentDpy) return;
508
509 __GLX_BEGIN(X_GLvop_SamplePatternSGIS,8);
510 __GLX_PUT_LONG(4,pass);
511 __GLX_END(8);
512 }