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"
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.
47 void __indirect_glCallLists(GLsizei n
, GLenum type
, const GLvoid
*lists
)
49 __GLX_DECLARE_VARIABLES();
50 __GLX_LOAD_VARIABLES();
52 compsize
= __glCallLists_size(n
,type
);
53 cmdlen
= __GLX_PAD(12 + compsize
);
54 if (!gc
->currentDpy
) return;
56 if (cmdlen
<= gc
->maxSmallRenderCommandSize
) {
57 /* Use GLXRender protocol to send small command */
58 __GLX_BEGIN_VARIABLE(X_GLrop_CallLists
,cmdlen
);
60 __GLX_PUT_LONG(8,type
);
61 __GLX_PUT_CHAR_ARRAY(12,lists
,compsize
);
64 /* Use GLXRenderLarge protocol to send command */
65 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CallLists
,cmdlen
+4);
67 __GLX_PUT_LONG(12,type
);
68 __glXSendLargeCommand(gc
, pc
, 16, lists
, compsize
);
72 void __indirect_glMap1d(GLenum target
, GLdouble u1
, GLdouble u2
, GLint stride
,
73 GLint order
, const GLdouble
*pnts
)
75 __GLX_DECLARE_VARIABLES();
78 __GLX_LOAD_VARIABLES();
79 k
= __glEvalComputeK(target
);
81 __glXSetError(gc
, GL_INVALID_ENUM
);
83 } else if (stride
< k
|| order
<= 0) {
84 __glXSetError(gc
, GL_INVALID_VALUE
);
87 compsize
= k
* order
* __GLX_SIZE_FLOAT64
;
89 if (!gc
->currentDpy
) return;
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
);
99 ** NOTE: the doubles that follow are not aligned because of 3
102 __glFillMap1d(k
, order
, stride
, pnts
, (pc
+28));
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
);
113 ** NOTE: the doubles that follow are not aligned because of 3
119 buf
= (GLubyte
*) Xmalloc(compsize
);
121 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
124 __glFillMap1d(k
, order
, stride
, pnts
, buf
);
125 __glXSendLargeCommand(gc
, pc
, 32, buf
, compsize
);
128 /* Data is already packed. Just send it out */
129 __glXSendLargeCommand(gc
, pc
, 32, pnts
, compsize
);
134 void __indirect_glMap1f(GLenum target
, GLfloat u1
, GLfloat u2
, GLint stride
,
135 GLint order
, const GLfloat
*pnts
)
137 __GLX_DECLARE_VARIABLES();
140 __GLX_LOAD_VARIABLES();
141 k
= __glEvalComputeK(target
);
143 __glXSetError(gc
, GL_INVALID_ENUM
);
145 } else if (stride
< k
|| order
<= 0) {
146 __glXSetError(gc
, GL_INVALID_VALUE
);
149 compsize
= k
* order
* __GLX_SIZE_FLOAT32
;
150 cmdlen
= 20+compsize
;
151 if (!gc
->currentDpy
) return;
154 ** The order that arguments are packed is different from the order
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));
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
);
177 buf
= (GLubyte
*) Xmalloc(compsize
);
179 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
182 __glFillMap1f(k
, order
, stride
, pnts
, buf
);
183 __glXSendLargeCommand(gc
, pc
, 24, buf
, compsize
);
186 /* Data is already packed. Just send it out */
187 __glXSendLargeCommand(gc
, pc
, 24, pnts
, compsize
);
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
)
196 __GLX_DECLARE_VARIABLES();
199 __GLX_LOAD_VARIABLES();
200 k
= __glEvalComputeK(target
);
202 __glXSetError(gc
, GL_INVALID_ENUM
);
204 } else if (vstr
< k
|| ustr
< k
|| vord
<= 0 || uord
<= 0) {
205 __glXSetError(gc
, GL_INVALID_VALUE
);
208 compsize
= k
* uord
* vord
* __GLX_SIZE_FLOAT64
;
209 cmdlen
= 48+compsize
;
210 if (!gc
->currentDpy
) return;
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
);
223 ** Pack into a u-major ordering.
224 ** NOTE: the doubles that follow are not aligned because of 5
227 __glFillMap2d(k
, uord
, vord
, ustr
, vstr
, pnts
, (GLdouble
*) (pc
+48));
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
);
241 ** NOTE: the doubles that follow are not aligned because of 5
244 if ((vstr
!= k
) || (ustr
!= k
*vord
)) {
247 buf
= (GLdouble
*) Xmalloc(compsize
);
249 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
253 ** Pack into a u-major ordering.
255 __glFillMap2d(k
, uord
, vord
, ustr
, vstr
, pnts
, buf
);
256 __glXSendLargeCommand(gc
, pc
, 52, buf
, compsize
);
259 /* Data is already packed. Just send it out */
260 __glXSendLargeCommand(gc
, pc
, 52, pnts
, compsize
);
265 void __indirect_glMap2f(GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustr
, GLint uord
,
266 GLfloat v1
, GLfloat v2
, GLint vstr
, GLint vord
,
269 __GLX_DECLARE_VARIABLES();
272 __GLX_LOAD_VARIABLES();
273 k
= __glEvalComputeK(target
);
275 __glXSetError(gc
, GL_INVALID_ENUM
);
277 } else if (vstr
< k
|| ustr
< k
|| vord
<= 0 || uord
<= 0) {
278 __glXSetError(gc
, GL_INVALID_VALUE
);
281 compsize
= k
* uord
* vord
* __GLX_SIZE_FLOAT32
;
282 cmdlen
= 32+compsize
;
283 if (!gc
->currentDpy
) return;
286 ** The order that arguments are packed is different from the order
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
);
300 ** Pack into a u-major ordering.
302 __glFillMap2f(k
, uord
, vord
, ustr
, vstr
, pnts
, (GLfloat
*) (pc
+32));
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
);
315 if ((vstr
!= k
) || (ustr
!= k
*vord
)) {
318 buf
= (GLfloat
*) Xmalloc(compsize
);
320 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
324 ** Pack into a u-major ordering.
326 __glFillMap2f(k
, uord
, vord
, ustr
, vstr
, pnts
, buf
);
327 __glXSendLargeCommand(gc
, pc
, 36, buf
, compsize
);
330 /* Data is already packed. Just send it out */
331 __glXSendLargeCommand(gc
, pc
, 36, pnts
, compsize
);
336 void __indirect_glPixelMapfv(GLenum map
, GLint mapsize
, const GLfloat
*values
)
338 __GLX_DECLARE_VARIABLES();
340 __GLX_LOAD_VARIABLES();
342 __glXSetError(gc
, GL_INVALID_VALUE
);
345 compsize
= mapsize
* __GLX_SIZE_FLOAT32
;
346 cmdlen
= 12+compsize
;
347 if (!gc
->currentDpy
) return;
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
);
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
);
365 void __indirect_glPixelMapuiv(GLenum map
, GLint mapsize
, const GLuint
*values
)
367 __GLX_DECLARE_VARIABLES();
369 __GLX_LOAD_VARIABLES();
371 __glXSetError(gc
, GL_INVALID_VALUE
);
374 compsize
= mapsize
* __GLX_SIZE_CARD32
;
375 cmdlen
= 12+compsize
;
376 if (!gc
->currentDpy
) return;
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
);
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
);
394 void __indirect_glPixelMapusv(GLenum map
, GLint mapsize
, const GLushort
*values
)
396 __GLX_DECLARE_VARIABLES();
398 __GLX_LOAD_VARIABLES();
400 __glXSetError(gc
, GL_INVALID_VALUE
);
403 compsize
= mapsize
* __GLX_SIZE_CARD16
;
404 cmdlen
= __GLX_PAD(12 + compsize
);
405 if (!gc
->currentDpy
) return;
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
);
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
);
423 void __indirect_glEnable(GLenum cap
)
425 __GLX_DECLARE_VARIABLES();
427 __GLX_LOAD_VARIABLES();
428 if (!gc
->currentDpy
) return;
432 case GL_EDGE_FLAG_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
);
445 __GLX_BEGIN(X_GLrop_Enable
,8);
446 __GLX_PUT_LONG(4,cap
);
450 void __indirect_glDisable(GLenum cap
)
452 __GLX_DECLARE_VARIABLES();
454 __GLX_LOAD_VARIABLES();
455 if (!gc
->currentDpy
) return;
459 case GL_EDGE_FLAG_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
);
472 __GLX_BEGIN(X_GLrop_Disable
,8);
473 __GLX_PUT_LONG(4,cap
);
477 void __indirect_glSampleCoverageARB( GLfloat value
, GLboolean invert
)
479 __GLX_DECLARE_VARIABLES();
481 __GLX_LOAD_VARIABLES();
482 if (!gc
->currentDpy
) return;
484 __GLX_BEGIN(X_GLrop_SampleCoverageARB
,12);
485 __GLX_PUT_FLOAT(4,value
);
486 __GLX_PUT_CHAR(8,invert
);
490 void __indirect_glSampleMaskSGIS( GLfloat value
, GLboolean invert
)
492 __GLX_DECLARE_VARIABLES();
494 __GLX_LOAD_VARIABLES();
495 if (!gc
->currentDpy
) return;
497 __GLX_BEGIN(X_GLvop_SampleMaskSGIS
,12);
498 __GLX_PUT_FLOAT(4,value
);
499 __GLX_PUT_CHAR(8,invert
);
503 void __indirect_glSamplePatternSGIS( GLenum pass
)
505 __GLX_DECLARE_VARIABLES();
507 __GLX_LOAD_VARIABLES();
508 if (!gc
->currentDpy
) return;
510 __GLX_BEGIN(X_GLvop_SamplePatternSGIS
,8);
511 __GLX_PUT_LONG(4,pass
);