c204d3ded4a4a57e78147bd8d4d48e15dcdfa391
[deb_xorg-server.git] / hw / dmx / glxProxy / compsize.c
1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31 #include <GL/gl.h>
32 #include "compsize.h"
33
34 GLint
35 __glFogiv_size(GLenum pname)
36 {
37 switch (pname) {
38 case GL_FOG_COLOR:
39 return 4;
40 case GL_FOG_DENSITY:
41 return 1;
42 case GL_FOG_END:
43 return 1;
44 case GL_FOG_MODE:
45 return 1;
46 case GL_FOG_INDEX:
47 return 1;
48 case GL_FOG_START:
49 return 1;
50 default:
51 return 0;
52 }
53 }
54
55 GLint
56 __glFogfv_size(GLenum pname)
57 {
58 return __glFogiv_size(pname);
59 }
60
61 GLint
62 __glCallLists_size(GLsizei n, GLenum type)
63 {
64 GLint size;
65
66 if (n < 0)
67 return 0;
68 switch (type) {
69 case GL_BYTE:
70 size = 1;
71 break;
72 case GL_UNSIGNED_BYTE:
73 size = 1;
74 break;
75 case GL_SHORT:
76 size = 2;
77 break;
78 case GL_UNSIGNED_SHORT:
79 size = 2;
80 break;
81 case GL_INT:
82 size = 4;
83 break;
84 case GL_UNSIGNED_INT:
85 size = 4;
86 break;
87 case GL_FLOAT:
88 size = 4;
89 break;
90 case GL_2_BYTES:
91 size = 2;
92 break;
93 case GL_3_BYTES:
94 size = 3;
95 break;
96 case GL_4_BYTES:
97 size = 4;
98 break;
99 default:
100 return 0;
101 }
102 return n * size;
103 }
104
105 GLint
106 __glDrawPixels_size(GLenum format, GLenum type, GLsizei w, GLsizei h)
107 {
108 GLint elements, esize;
109
110 switch (format) {
111 case GL_COLOR_INDEX:
112 case GL_STENCIL_INDEX:
113 case GL_DEPTH_COMPONENT:
114 elements = 1;
115 break;
116 case GL_RED:
117 case GL_GREEN:
118 case GL_BLUE:
119 case GL_ALPHA:
120 case GL_LUMINANCE:
121 elements = 1;
122 break;
123 case GL_LUMINANCE_ALPHA:
124 elements = 2;
125 break;
126 case GL_RGB:
127 elements = 3;
128 break;
129 case GL_RGBA:
130 case GL_ABGR_EXT:
131 elements = 4;
132 break;
133 default:
134 return 0;
135 }
136 switch (type) {
137 case GL_BITMAP:
138 if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) {
139 return (h * ((w + 7) / 8));
140 }
141 else {
142 return 0;
143 }
144 case GL_BYTE:
145 case GL_UNSIGNED_BYTE:
146 esize = 1;
147 break;
148 case GL_UNSIGNED_BYTE_3_3_2:
149 case GL_UNSIGNED_BYTE_2_3_3_REV:
150 esize = 1;
151 elements = 1;
152 break;
153 case GL_SHORT:
154 case GL_UNSIGNED_SHORT:
155 esize = 2;
156 break;
157 case GL_UNSIGNED_SHORT_5_6_5:
158 case GL_UNSIGNED_SHORT_5_6_5_REV:
159 case GL_UNSIGNED_SHORT_4_4_4_4:
160 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
161 case GL_UNSIGNED_SHORT_5_5_5_1:
162 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
163 esize = 2;
164 elements = 1;
165 break;
166 case GL_INT:
167 case GL_UNSIGNED_INT:
168 case GL_FLOAT:
169 esize = 4;
170 break;
171 case GL_UNSIGNED_INT_8_8_8_8:
172 case GL_UNSIGNED_INT_8_8_8_8_REV:
173 case GL_UNSIGNED_INT_10_10_10_2:
174 case GL_UNSIGNED_INT_2_10_10_10_REV:
175 esize = 4;
176 elements = 1;
177 break;
178 default:
179 return 0;
180 }
181 return elements * esize * w * h;
182 }
183
184 GLint
185 __glBitmap_size(GLsizei w, GLsizei h)
186 {
187 return __glDrawPixels_size(GL_COLOR_INDEX, GL_BITMAP, w, h);
188 }
189
190 GLint
191 __glTexGendv_size(GLenum e)
192 {
193 switch (e) {
194 case GL_TEXTURE_GEN_MODE:
195 return 1;
196 case GL_OBJECT_PLANE:
197 case GL_EYE_PLANE:
198 return 4;
199 default:
200 return 0;
201 }
202 }
203
204 GLint
205 __glTexGenfv_size(GLenum e)
206 {
207 return __glTexGendv_size(e);
208 }
209
210 GLint
211 __glTexGeniv_size(GLenum e)
212 {
213 return __glTexGendv_size(e);
214 }
215
216 GLint
217 __glTexParameterfv_size(GLenum e)
218 {
219 switch (e) {
220 case GL_TEXTURE_WRAP_S:
221 case GL_TEXTURE_WRAP_T:
222 case GL_TEXTURE_WRAP_R:
223 case GL_TEXTURE_MIN_FILTER:
224 case GL_TEXTURE_MAG_FILTER:
225 return 1;
226 case GL_TEXTURE_BORDER_COLOR:
227 return 4;
228 case GL_TEXTURE_PRIORITY:
229 return 1;
230 case GL_TEXTURE_MIN_LOD:
231 case GL_TEXTURE_MAX_LOD:
232 case GL_TEXTURE_BASE_LEVEL:
233 case GL_TEXTURE_MAX_LEVEL:
234 return 1;
235 default:
236 return 0;
237 }
238 }
239
240 GLint
241 __glTexParameteriv_size(GLenum e)
242 {
243 return __glTexParameterfv_size(e);
244 }
245
246 GLint
247 __glTexEnvfv_size(GLenum e)
248 {
249 switch (e) {
250 case GL_TEXTURE_ENV_MODE:
251 return 1;
252 case GL_TEXTURE_ENV_COLOR:
253 return 4;
254 default:
255 return 0;
256 }
257 }
258
259 GLint
260 __glTexEnviv_size(GLenum e)
261 {
262 return __glTexEnvfv_size(e);
263 }
264
265 GLint
266 __glTexImage1D_size(GLenum format, GLenum type, GLsizei w)
267 {
268 GLint elements, esize;
269
270 if (w < 0)
271 return 0;
272 switch (format) {
273 case GL_COLOR_INDEX:
274 elements = 1;
275 break;
276 case GL_RED:
277 case GL_GREEN:
278 case GL_BLUE:
279 case GL_ALPHA:
280 case GL_LUMINANCE:
281 elements = 1;
282 break;
283 case GL_LUMINANCE_ALPHA:
284 elements = 2;
285 break;
286 case GL_RGB:
287 elements = 3;
288 break;
289 case GL_RGBA:
290 case GL_ABGR_EXT:
291 elements = 4;
292 break;
293 default:
294 return 0;
295 }
296 switch (type) {
297 case GL_BITMAP:
298 if (format == GL_COLOR_INDEX) {
299 return (w + 7) / 8;
300 }
301 else {
302 return 0;
303 }
304 case GL_BYTE:
305 case GL_UNSIGNED_BYTE:
306 esize = 1;
307 break;
308 case GL_UNSIGNED_BYTE_3_3_2:
309 case GL_UNSIGNED_BYTE_2_3_3_REV:
310 esize = 1;
311 elements = 1;
312 break;
313 case GL_SHORT:
314 case GL_UNSIGNED_SHORT:
315 esize = 2;
316 break;
317 case GL_UNSIGNED_SHORT_5_6_5:
318 case GL_UNSIGNED_SHORT_5_6_5_REV:
319 case GL_UNSIGNED_SHORT_4_4_4_4:
320 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
321 case GL_UNSIGNED_SHORT_5_5_5_1:
322 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
323 esize = 2;
324 elements = 1;
325 break;
326 case GL_INT:
327 case GL_UNSIGNED_INT:
328 case GL_FLOAT:
329 esize = 4;
330 break;
331 case GL_UNSIGNED_INT_8_8_8_8:
332 case GL_UNSIGNED_INT_8_8_8_8_REV:
333 case GL_UNSIGNED_INT_10_10_10_2:
334 case GL_UNSIGNED_INT_2_10_10_10_REV:
335 esize = 4;
336 elements = 1;
337 break;
338 default:
339 return 0;
340 }
341 return elements * esize * w;
342 }
343
344 GLint
345 __glTexImage2D_size(GLenum format, GLenum type, GLsizei w, GLsizei h)
346 {
347 GLint elements, esize;
348
349 if (w < 0)
350 return 0;
351 if (h < 0)
352 return 0;
353 switch (format) {
354 case GL_COLOR_INDEX:
355 elements = 1;
356 break;
357 case GL_RED:
358 case GL_GREEN:
359 case GL_BLUE:
360 case GL_ALPHA:
361 case GL_LUMINANCE:
362 elements = 1;
363 break;
364 case GL_LUMINANCE_ALPHA:
365 elements = 2;
366 break;
367 case GL_RGB:
368 elements = 3;
369 break;
370 case GL_RGBA:
371 case GL_ABGR_EXT:
372 elements = 4;
373 break;
374 default:
375 return 0;
376 }
377 switch (type) {
378 case GL_BITMAP:
379 if (format == GL_COLOR_INDEX) {
380 return (h * ((w + 7) / 8));
381 }
382 else {
383 return 0;
384 }
385 case GL_BYTE:
386 case GL_UNSIGNED_BYTE:
387 esize = 1;
388 break;
389 case GL_UNSIGNED_BYTE_3_3_2:
390 case GL_UNSIGNED_BYTE_2_3_3_REV:
391 esize = 1;
392 elements = 1;
393 break;
394 case GL_SHORT:
395 case GL_UNSIGNED_SHORT:
396 esize = 2;
397 break;
398 case GL_UNSIGNED_SHORT_5_6_5:
399 case GL_UNSIGNED_SHORT_5_6_5_REV:
400 case GL_UNSIGNED_SHORT_4_4_4_4:
401 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
402 case GL_UNSIGNED_SHORT_5_5_5_1:
403 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
404 esize = 2;
405 elements = 1;
406 break;
407 case GL_INT:
408 case GL_UNSIGNED_INT:
409 case GL_FLOAT:
410 esize = 4;
411 break;
412 case GL_UNSIGNED_INT_8_8_8_8:
413 case GL_UNSIGNED_INT_8_8_8_8_REV:
414 case GL_UNSIGNED_INT_10_10_10_2:
415 case GL_UNSIGNED_INT_2_10_10_10_REV:
416 esize = 4;
417 elements = 1;
418 break;
419 default:
420 return 0;
421 }
422 return elements * esize * w * h;
423 }
424
425 GLint
426 __glTexImage3D_size(GLenum format, GLenum type, GLsizei w, GLsizei h, GLsizei d)
427 {
428 GLint elements, esize;
429
430 if (w < 0)
431 return 0;
432 if (h < 0)
433 return 0;
434 if (d < 0)
435 return 0;
436 switch (format) {
437 case GL_COLOR_INDEX:
438 elements = 1;
439 break;
440 case GL_RED:
441 case GL_GREEN:
442 case GL_BLUE:
443 case GL_ALPHA:
444 case GL_LUMINANCE:
445 elements = 1;
446 break;
447 case GL_LUMINANCE_ALPHA:
448 elements = 2;
449 break;
450 case GL_RGB:
451 elements = 3;
452 break;
453 case GL_RGBA:
454 case GL_ABGR_EXT:
455 elements = 4;
456 break;
457 default:
458 return 0;
459 }
460 switch (type) {
461 case GL_BITMAP:
462 if (format == GL_COLOR_INDEX) {
463 return (d * (h * ((w + 7) / 8)));
464 }
465 else {
466 return 0;
467 }
468 case GL_BYTE:
469 case GL_UNSIGNED_BYTE:
470 esize = 1;
471 break;
472 case GL_UNSIGNED_BYTE_3_3_2:
473 case GL_UNSIGNED_BYTE_2_3_3_REV:
474 esize = 1;
475 elements = 1;
476 break;
477 case GL_SHORT:
478 case GL_UNSIGNED_SHORT:
479 esize = 2;
480 break;
481 case GL_UNSIGNED_SHORT_5_6_5:
482 case GL_UNSIGNED_SHORT_5_6_5_REV:
483 case GL_UNSIGNED_SHORT_4_4_4_4:
484 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
485 case GL_UNSIGNED_SHORT_5_5_5_1:
486 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
487 esize = 2;
488 elements = 1;
489 break;
490 case GL_INT:
491 case GL_UNSIGNED_INT:
492 case GL_FLOAT:
493 esize = 4;
494 break;
495 case GL_UNSIGNED_INT_8_8_8_8:
496 case GL_UNSIGNED_INT_8_8_8_8_REV:
497 case GL_UNSIGNED_INT_10_10_10_2:
498 case GL_UNSIGNED_INT_2_10_10_10_REV:
499 esize = 4;
500 elements = 1;
501 break;
502 default:
503 return 0;
504 }
505 return elements * esize * w * h * d;
506 }
507
508 GLint
509 __glLightfv_size(GLenum pname)
510 {
511 switch (pname) {
512 case GL_SPOT_EXPONENT:
513 return 1;
514 case GL_SPOT_CUTOFF:
515 return 1;
516 case GL_AMBIENT:
517 return 4;
518 case GL_DIFFUSE:
519 return 4;
520 case GL_SPECULAR:
521 return 4;
522 case GL_POSITION:
523 return 4;
524 case GL_SPOT_DIRECTION:
525 return 3;
526 case GL_CONSTANT_ATTENUATION:
527 return 1;
528 case GL_LINEAR_ATTENUATION:
529 return 1;
530 case GL_QUADRATIC_ATTENUATION:
531 return 1;
532 default:
533 return 0;
534 }
535 }
536
537 GLint
538 __glLightiv_size(GLenum pname)
539 {
540 return __glLightfv_size(pname);
541 }
542
543 GLint
544 __glLightModelfv_size(GLenum pname)
545 {
546 switch (pname) {
547 case GL_LIGHT_MODEL_AMBIENT:
548 return 4;
549 case GL_LIGHT_MODEL_LOCAL_VIEWER:
550 return 1;
551 case GL_LIGHT_MODEL_TWO_SIDE:
552 return 1;
553 case GL_LIGHT_MODEL_COLOR_CONTROL:
554 return 1;
555 default:
556 return 0;
557 }
558 }
559
560 GLint
561 __glLightModeliv_size(GLenum pname)
562 {
563 return __glLightModelfv_size(pname);
564 }
565
566 GLint
567 __glMaterialfv_size(GLenum pname)
568 {
569 switch (pname) {
570 case GL_SHININESS:
571 return 1;
572 case GL_EMISSION:
573 return 4;
574 case GL_AMBIENT:
575 return 4;
576 case GL_DIFFUSE:
577 return 4;
578 case GL_SPECULAR:
579 return 4;
580 case GL_AMBIENT_AND_DIFFUSE:
581 return 4;
582 case GL_COLOR_INDEXES:
583 return 3;
584 default:
585 return 0;
586 }
587 }
588
589 GLint
590 __glMaterialiv_size(GLenum pname)
591 {
592 return __glMaterialfv_size(pname);
593 }
594
595 GLint
596 __glColorTableParameterfv_size(GLenum pname)
597 {
598 switch (pname) {
599 case GL_COLOR_TABLE_FORMAT:
600 case GL_COLOR_TABLE_WIDTH:
601 case GL_COLOR_TABLE_RED_SIZE:
602 case GL_COLOR_TABLE_GREEN_SIZE:
603 case GL_COLOR_TABLE_BLUE_SIZE:
604 case GL_COLOR_TABLE_ALPHA_SIZE:
605 case GL_COLOR_TABLE_LUMINANCE_SIZE:
606 case GL_COLOR_TABLE_INTENSITY_SIZE:
607 return 1;
608 case GL_COLOR_TABLE_SCALE:
609 case GL_COLOR_TABLE_BIAS:
610 return 4;
611 default:
612 return -1;
613 }
614 }
615
616 GLint
617 __glColorTableParameteriv_size(GLenum pname)
618 {
619 return __glColorTableParameterfv_size(pname);
620 }
621
622 GLint
623 __glConvolutionParameterfv_size(GLenum pname)
624 {
625 switch (pname) {
626 case GL_CONVOLUTION_BORDER_MODE:
627 return 1;
628 case GL_CONVOLUTION_BORDER_COLOR:
629 case GL_CONVOLUTION_FILTER_SCALE:
630 case GL_CONVOLUTION_FILTER_BIAS:
631 return 4;
632 default: /* error: bad enum value */
633 return -1;
634 }
635 }
636
637 GLint
638 __glConvolutionParameteriv_size(GLenum pname)
639 {
640 return __glConvolutionParameterfv_size(pname);
641 }