1 /* $XFree86: xc/lib/GL/glx/render2.c,v 1.6 2004/01/31 09:29:33 alanh Exp $ */
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:
11 ** http://oss.sgi.com/projects/FreeB
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.
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.
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.
37 #include "packrender.h"
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.
46 void glCallLists(GLsizei n
, GLenum type
, const GLvoid
*lists
)
48 __GLX_DECLARE_VARIABLES();
49 __GLX_LOAD_VARIABLES();
51 compsize
= __glCallLists_size(n
,type
);
52 cmdlen
= __GLX_PAD(12 + compsize
);
53 if (!gc
->currentDpy
) return;
55 if (cmdlen
<= gc
->maxSmallRenderCommandSize
) {
56 /* Use GLXRender protocol to send small command */
57 __GLX_BEGIN_VARIABLE(X_GLrop_CallLists
,cmdlen
);
59 __GLX_PUT_LONG(8,type
);
60 __GLX_PUT_CHAR_ARRAY(12,lists
,compsize
);
63 /* Use GLXRenderLarge protocol to send command */
64 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CallLists
,cmdlen
+4);
66 __GLX_PUT_LONG(12,type
);
67 __glXSendLargeCommand(gc
, pc
, 16, lists
, compsize
);
71 void glMap1d(GLenum target
, GLdouble u1
, GLdouble u2
, GLint stride
,
72 GLint order
, const GLdouble
*pnts
)
74 __GLX_DECLARE_VARIABLES();
77 __GLX_LOAD_VARIABLES();
78 k
= __glEvalComputeK(target
);
80 __glXSetError(gc
, GL_INVALID_ENUM
);
82 } else if (stride
< k
|| order
<= 0) {
83 __glXSetError(gc
, GL_INVALID_VALUE
);
86 compsize
= k
* order
* __GLX_SIZE_FLOAT64
;
88 if (!gc
->currentDpy
) return;
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
);
98 ** NOTE: the doubles that follow are not aligned because of 3
101 __glFillMap1d(k
, order
, stride
, pnts
, (pc
+28));
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
);
112 ** NOTE: the doubles that follow are not aligned because of 3
118 buf
= (GLubyte
*) Xmalloc(compsize
);
120 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
123 __glFillMap1d(k
, order
, stride
, pnts
, buf
);
124 __glXSendLargeCommand(gc
, pc
, 32, buf
, compsize
);
127 /* Data is already packed. Just send it out */
128 __glXSendLargeCommand(gc
, pc
, 32, pnts
, compsize
);
133 void glMap1f(GLenum target
, GLfloat u1
, GLfloat u2
, GLint stride
,
134 GLint order
, const GLfloat
*pnts
)
136 __GLX_DECLARE_VARIABLES();
139 __GLX_LOAD_VARIABLES();
140 k
= __glEvalComputeK(target
);
142 __glXSetError(gc
, GL_INVALID_ENUM
);
144 } else if (stride
< k
|| order
<= 0) {
145 __glXSetError(gc
, GL_INVALID_VALUE
);
148 compsize
= k
* order
* __GLX_SIZE_FLOAT32
;
149 cmdlen
= 20+compsize
;
150 if (!gc
->currentDpy
) return;
153 ** The order that arguments are packed is different from the order
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));
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
);
176 buf
= (GLubyte
*) Xmalloc(compsize
);
178 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
181 __glFillMap1f(k
, order
, stride
, pnts
, buf
);
182 __glXSendLargeCommand(gc
, pc
, 24, buf
, compsize
);
185 /* Data is already packed. Just send it out */
186 __glXSendLargeCommand(gc
, pc
, 24, pnts
, compsize
);
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
)
195 __GLX_DECLARE_VARIABLES();
198 __GLX_LOAD_VARIABLES();
199 k
= __glEvalComputeK(target
);
201 __glXSetError(gc
, GL_INVALID_ENUM
);
203 } else if (vstr
< k
|| ustr
< k
|| vord
<= 0 || uord
<= 0) {
204 __glXSetError(gc
, GL_INVALID_VALUE
);
207 compsize
= k
* uord
* vord
* __GLX_SIZE_FLOAT64
;
208 cmdlen
= 48+compsize
;
209 if (!gc
->currentDpy
) return;
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
);
222 ** Pack into a u-major ordering.
223 ** NOTE: the doubles that follow are not aligned because of 5
226 __glFillMap2d(k
, uord
, vord
, ustr
, vstr
, pnts
, (GLdouble
*) (pc
+48));
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
);
240 ** NOTE: the doubles that follow are not aligned because of 5
243 if ((vstr
!= k
) || (ustr
!= k
*vord
)) {
246 buf
= (GLdouble
*) Xmalloc(compsize
);
248 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
252 ** Pack into a u-major ordering.
254 __glFillMap2d(k
, uord
, vord
, ustr
, vstr
, pnts
, buf
);
255 __glXSendLargeCommand(gc
, pc
, 52, buf
, compsize
);
258 /* Data is already packed. Just send it out */
259 __glXSendLargeCommand(gc
, pc
, 52, pnts
, compsize
);
264 void glMap2f(GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustr
, GLint uord
,
265 GLfloat v1
, GLfloat v2
, GLint vstr
, GLint vord
,
268 __GLX_DECLARE_VARIABLES();
271 __GLX_LOAD_VARIABLES();
272 k
= __glEvalComputeK(target
);
274 __glXSetError(gc
, GL_INVALID_ENUM
);
276 } else if (vstr
< k
|| ustr
< k
|| vord
<= 0 || uord
<= 0) {
277 __glXSetError(gc
, GL_INVALID_VALUE
);
280 compsize
= k
* uord
* vord
* __GLX_SIZE_FLOAT32
;
281 cmdlen
= 32+compsize
;
282 if (!gc
->currentDpy
) return;
285 ** The order that arguments are packed is different from the order
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
);
299 ** Pack into a u-major ordering.
301 __glFillMap2f(k
, uord
, vord
, ustr
, vstr
, pnts
, (GLfloat
*) (pc
+32));
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
);
314 if ((vstr
!= k
) || (ustr
!= k
*vord
)) {
317 buf
= (GLfloat
*) Xmalloc(compsize
);
319 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
323 ** Pack into a u-major ordering.
325 __glFillMap2f(k
, uord
, vord
, ustr
, vstr
, pnts
, buf
);
326 __glXSendLargeCommand(gc
, pc
, 36, buf
, compsize
);
329 /* Data is already packed. Just send it out */
330 __glXSendLargeCommand(gc
, pc
, 36, pnts
, compsize
);
335 void glPixelMapfv(GLenum map
, GLint mapsize
, const GLfloat
*values
)
337 __GLX_DECLARE_VARIABLES();
339 __GLX_LOAD_VARIABLES();
341 __glXSetError(gc
, GL_INVALID_VALUE
);
344 compsize
= mapsize
* __GLX_SIZE_FLOAT32
;
345 cmdlen
= 12+compsize
;
346 if (!gc
->currentDpy
) return;
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
);
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
);
364 void glPixelMapuiv(GLenum map
, GLint mapsize
, const GLuint
*values
)
366 __GLX_DECLARE_VARIABLES();
368 __GLX_LOAD_VARIABLES();
370 __glXSetError(gc
, GL_INVALID_VALUE
);
373 compsize
= mapsize
* __GLX_SIZE_CARD32
;
374 cmdlen
= 12+compsize
;
375 if (!gc
->currentDpy
) return;
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
);
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
);
393 void glPixelMapusv(GLenum map
, GLint mapsize
, const GLushort
*values
)
395 __GLX_DECLARE_VARIABLES();
397 __GLX_LOAD_VARIABLES();
399 __glXSetError(gc
, GL_INVALID_VALUE
);
402 compsize
= mapsize
* __GLX_SIZE_CARD16
;
403 cmdlen
= __GLX_PAD(12 + compsize
);
404 if (!gc
->currentDpy
) return;
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
);
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
);
422 void glEnable(GLenum cap
)
424 __GLX_DECLARE_VARIABLES();
426 __GLX_LOAD_VARIABLES();
427 if (!gc
->currentDpy
) return;
431 case GL_EDGE_FLAG_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
);
444 __GLX_BEGIN(X_GLrop_Enable
,8);
445 __GLX_PUT_LONG(4,cap
);
449 void glDisable(GLenum cap
)
451 __GLX_DECLARE_VARIABLES();
453 __GLX_LOAD_VARIABLES();
454 if (!gc
->currentDpy
) return;
458 case GL_EDGE_FLAG_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
);
471 __GLX_BEGIN(X_GLrop_Disable
,8);
472 __GLX_PUT_LONG(4,cap
);
476 void glSampleCoverageARB( GLfloat value
, GLboolean invert
)
478 __GLX_DECLARE_VARIABLES();
480 __GLX_LOAD_VARIABLES();
481 if (!gc
->currentDpy
) return;
483 __GLX_BEGIN(X_GLrop_SampleCoverageARB
,12);
484 __GLX_PUT_FLOAT(4,value
);
485 __GLX_PUT_CHAR(8,invert
);
489 void glSampleMaskSGIS( GLfloat value
, GLboolean invert
)
491 __GLX_DECLARE_VARIABLES();
493 __GLX_LOAD_VARIABLES();
494 if (!gc
->currentDpy
) return;
496 __GLX_BEGIN(X_GLvop_SampleMaskSGIS
,12);
497 __GLX_PUT_FLOAT(4,value
);
498 __GLX_PUT_CHAR(8,invert
);
502 void glSamplePatternSGIS( GLenum pass
)
504 __GLX_DECLARE_VARIABLES();
506 __GLX_LOAD_VARIABLES();
507 if (!gc
->currentDpy
) return;
509 __GLX_BEGIN(X_GLvop_SamplePatternSGIS
,8);
510 __GLX_PUT_LONG(4,pass
);