Silence minor compiler warnings (-Wextra).
[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 "indirect_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_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
48 GLint order, const GLdouble *pnts)
49 {
50 __GLX_DECLARE_VARIABLES();
51 GLint k;
52
53 __GLX_LOAD_VARIABLES();
54 k = __glMap1d_size(target);
55 if (k == 0) {
56 __glXSetError(gc, GL_INVALID_ENUM);
57 return;
58 } else if (stride < k || order <= 0) {
59 __glXSetError(gc, GL_INVALID_VALUE);
60 return;
61 }
62 compsize = k * order * __GLX_SIZE_FLOAT64;
63 cmdlen = 28+compsize;
64 if (!gc->currentDpy) return;
65
66 if (cmdlen <= gc->maxSmallRenderCommandSize) {
67 /* Use GLXRender protocol to send small command */
68 __GLX_BEGIN_VARIABLE(X_GLrop_Map1d,cmdlen);
69 __GLX_PUT_DOUBLE(4,u1);
70 __GLX_PUT_DOUBLE(12,u2);
71 __GLX_PUT_LONG(20,target);
72 __GLX_PUT_LONG(24,order);
73 /*
74 ** NOTE: the doubles that follow are not aligned because of 3
75 ** longs preceeding
76 */
77 __glFillMap1d(k, order, stride, pnts, (pc+28));
78 __GLX_END(cmdlen);
79 } else {
80 /* Use GLXRenderLarge protocol to send command */
81 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d,cmdlen+4);
82 __GLX_PUT_DOUBLE(8,u1);
83 __GLX_PUT_DOUBLE(16,u2);
84 __GLX_PUT_LONG(24,target);
85 __GLX_PUT_LONG(28,order);
86
87 /*
88 ** NOTE: the doubles that follow are not aligned because of 3
89 ** longs preceeding
90 */
91 if (stride != k) {
92 GLubyte *buf;
93
94 buf = (GLubyte *) Xmalloc(compsize);
95 if (!buf) {
96 __glXSetError(gc, GL_OUT_OF_MEMORY);
97 return;
98 }
99 __glFillMap1d(k, order, stride, pnts, buf);
100 __glXSendLargeCommand(gc, pc, 32, buf, compsize);
101 Xfree((char*) buf);
102 } else {
103 /* Data is already packed. Just send it out */
104 __glXSendLargeCommand(gc, pc, 32, pnts, compsize);
105 }
106 }
107 }
108
109 void __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
110 GLint order, const GLfloat *pnts)
111 {
112 __GLX_DECLARE_VARIABLES();
113 GLint k;
114
115 __GLX_LOAD_VARIABLES();
116 k = __glMap1f_size(target);
117 if (k == 0) {
118 __glXSetError(gc, GL_INVALID_ENUM);
119 return;
120 } else if (stride < k || order <= 0) {
121 __glXSetError(gc, GL_INVALID_VALUE);
122 return;
123 }
124 compsize = k * order * __GLX_SIZE_FLOAT32;
125 cmdlen = 20+compsize;
126 if (!gc->currentDpy) return;
127
128 /*
129 ** The order that arguments are packed is different from the order
130 ** for glMap1d.
131 */
132 if (cmdlen <= gc->maxSmallRenderCommandSize) {
133 /* Use GLXRender protocol to send small command */
134 __GLX_BEGIN_VARIABLE(X_GLrop_Map1f,cmdlen);
135 __GLX_PUT_LONG(4,target);
136 __GLX_PUT_FLOAT(8,u1);
137 __GLX_PUT_FLOAT(12,u2);
138 __GLX_PUT_LONG(16,order);
139 __glFillMap1f(k, order, stride, pnts, (GLubyte*) (pc+20));
140 __GLX_END(cmdlen);
141 } else {
142 /* Use GLXRenderLarge protocol to send command */
143 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f,cmdlen+4);
144 __GLX_PUT_LONG(8,target);
145 __GLX_PUT_FLOAT(12,u1);
146 __GLX_PUT_FLOAT(16,u2);
147 __GLX_PUT_LONG(20,order);
148
149 if (stride != k) {
150 GLubyte *buf;
151
152 buf = (GLubyte *) Xmalloc(compsize);
153 if (!buf) {
154 __glXSetError(gc, GL_OUT_OF_MEMORY);
155 return;
156 }
157 __glFillMap1f(k, order, stride, pnts, buf);
158 __glXSendLargeCommand(gc, pc, 24, buf, compsize);
159 Xfree((char*) buf);
160 } else {
161 /* Data is already packed. Just send it out */
162 __glXSendLargeCommand(gc, pc, 24, pnts, compsize);
163 }
164 }
165 }
166
167 void __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, GLint uord,
168 GLdouble v1, GLdouble v2, GLint vstr, GLint vord,
169 const GLdouble *pnts)
170 {
171 __GLX_DECLARE_VARIABLES();
172 GLint k;
173
174 __GLX_LOAD_VARIABLES();
175 k = __glMap2d_size(target);
176 if (k == 0) {
177 __glXSetError(gc, GL_INVALID_ENUM);
178 return;
179 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
180 __glXSetError(gc, GL_INVALID_VALUE);
181 return;
182 }
183 compsize = k * uord * vord * __GLX_SIZE_FLOAT64;
184 cmdlen = 48+compsize;
185 if (!gc->currentDpy) return;
186
187 if (cmdlen <= gc->maxSmallRenderCommandSize) {
188 /* Use GLXRender protocol to send small command */
189 __GLX_BEGIN_VARIABLE(X_GLrop_Map2d,cmdlen);
190 __GLX_PUT_DOUBLE(4,u1);
191 __GLX_PUT_DOUBLE(12,u2);
192 __GLX_PUT_DOUBLE(20,v1);
193 __GLX_PUT_DOUBLE(28,v2);
194 __GLX_PUT_LONG(36,target);
195 __GLX_PUT_LONG(40,uord);
196 __GLX_PUT_LONG(44,vord);
197 /*
198 ** Pack into a u-major ordering.
199 ** NOTE: the doubles that follow are not aligned because of 5
200 ** longs preceeding
201 */
202 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble*) (pc+48));
203 __GLX_END(cmdlen);
204 } else {
205 /* Use GLXRenderLarge protocol to send command */
206 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d,cmdlen+4);
207 __GLX_PUT_DOUBLE(8,u1);
208 __GLX_PUT_DOUBLE(16,u2);
209 __GLX_PUT_DOUBLE(24,v1);
210 __GLX_PUT_DOUBLE(32,v2);
211 __GLX_PUT_LONG(40,target);
212 __GLX_PUT_LONG(44,uord);
213 __GLX_PUT_LONG(48,vord);
214
215 /*
216 ** NOTE: the doubles that follow are not aligned because of 5
217 ** longs preceeding
218 */
219 if ((vstr != k) || (ustr != k*vord)) {
220 GLdouble *buf;
221
222 buf = (GLdouble *) Xmalloc(compsize);
223 if (!buf) {
224 __glXSetError(gc, GL_OUT_OF_MEMORY);
225 return;
226 }
227 /*
228 ** Pack into a u-major ordering.
229 */
230 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf);
231 __glXSendLargeCommand(gc, pc, 52, buf, compsize);
232 Xfree((char*) buf);
233 } else {
234 /* Data is already packed. Just send it out */
235 __glXSendLargeCommand(gc, pc, 52, pnts, compsize);
236 }
237 }
238 }
239
240 void __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, GLint uord,
241 GLfloat v1, GLfloat v2, GLint vstr, GLint vord,
242 const GLfloat *pnts)
243 {
244 __GLX_DECLARE_VARIABLES();
245 GLint k;
246
247 __GLX_LOAD_VARIABLES();
248 k = __glMap2f_size(target);
249 if (k == 0) {
250 __glXSetError(gc, GL_INVALID_ENUM);
251 return;
252 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
253 __glXSetError(gc, GL_INVALID_VALUE);
254 return;
255 }
256 compsize = k * uord * vord * __GLX_SIZE_FLOAT32;
257 cmdlen = 32+compsize;
258 if (!gc->currentDpy) return;
259
260 /*
261 ** The order that arguments are packed is different from the order
262 ** for glMap2d.
263 */
264 if (cmdlen <= gc->maxSmallRenderCommandSize) {
265 /* Use GLXRender protocol to send small command */
266 __GLX_BEGIN_VARIABLE(X_GLrop_Map2f,cmdlen);
267 __GLX_PUT_LONG(4,target);
268 __GLX_PUT_FLOAT(8,u1);
269 __GLX_PUT_FLOAT(12,u2);
270 __GLX_PUT_LONG(16,uord);
271 __GLX_PUT_FLOAT(20,v1);
272 __GLX_PUT_FLOAT(24,v2);
273 __GLX_PUT_LONG(28,vord);
274 /*
275 ** Pack into a u-major ordering.
276 */
277 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat*) (pc+32));
278 __GLX_END(cmdlen);
279 } else {
280 /* Use GLXRenderLarge protocol to send command */
281 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f,cmdlen+4);
282 __GLX_PUT_LONG(8,target);
283 __GLX_PUT_FLOAT(12,u1);
284 __GLX_PUT_FLOAT(16,u2);
285 __GLX_PUT_LONG(20,uord);
286 __GLX_PUT_FLOAT(24,v1);
287 __GLX_PUT_FLOAT(28,v2);
288 __GLX_PUT_LONG(32,vord);
289
290 if ((vstr != k) || (ustr != k*vord)) {
291 GLfloat *buf;
292
293 buf = (GLfloat *) Xmalloc(compsize);
294 if (!buf) {
295 __glXSetError(gc, GL_OUT_OF_MEMORY);
296 return;
297 }
298 /*
299 ** Pack into a u-major ordering.
300 */
301 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf);
302 __glXSendLargeCommand(gc, pc, 36, buf, compsize);
303 Xfree((char*) buf);
304 } else {
305 /* Data is already packed. Just send it out */
306 __glXSendLargeCommand(gc, pc, 36, pnts, compsize);
307 }
308 }
309 }
310
311 void __indirect_glEnable(GLenum cap)
312 {
313 __GLX_DECLARE_VARIABLES();
314
315 __GLX_LOAD_VARIABLES();
316 if (!gc->currentDpy) return;
317
318 switch(cap) {
319 case GL_COLOR_ARRAY:
320 case GL_EDGE_FLAG_ARRAY:
321 case GL_INDEX_ARRAY:
322 case GL_NORMAL_ARRAY:
323 case GL_TEXTURE_COORD_ARRAY:
324 case GL_VERTEX_ARRAY:
325 case GL_SECONDARY_COLOR_ARRAY:
326 case GL_FOG_COORD_ARRAY:
327 __indirect_glEnableClientState(cap);
328 return;
329 default:
330 break;
331 }
332
333 __GLX_BEGIN(X_GLrop_Enable,8);
334 __GLX_PUT_LONG(4,cap);
335 __GLX_END(8);
336 }
337
338 void __indirect_glDisable(GLenum cap)
339 {
340 __GLX_DECLARE_VARIABLES();
341
342 __GLX_LOAD_VARIABLES();
343 if (!gc->currentDpy) return;
344
345 switch(cap) {
346 case GL_COLOR_ARRAY:
347 case GL_EDGE_FLAG_ARRAY:
348 case GL_INDEX_ARRAY:
349 case GL_NORMAL_ARRAY:
350 case GL_TEXTURE_COORD_ARRAY:
351 case GL_VERTEX_ARRAY:
352 case GL_SECONDARY_COLOR_ARRAY:
353 case GL_FOG_COORD_ARRAY:
354 __indirect_glDisableClientState(cap);
355 return;
356 default:
357 break;
358 }
359
360 __GLX_BEGIN(X_GLrop_Disable,8);
361 __GLX_PUT_LONG(4,cap);
362 __GLX_END(8);
363 }