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 34GLint __glFogiv_size(GLenum pname) 35{ 36 switch (pname) { 37 case GL_FOG_COLOR: return 4; 38 case GL_FOG_DENSITY: return 1; 39 case GL_FOG_END: return 1; 40 case GL_FOG_MODE: return 1; 41 case GL_FOG_INDEX: return 1; 42 case GL_FOG_START: return 1; 43 default: 44 return 0; 45 } 46} 47 48GLint __glFogfv_size(GLenum pname) 49{ 50 return __glFogiv_size(pname); 51} 52 53GLint __glCallLists_size(GLsizei n, GLenum type) 54{ 55 GLint size; 56 57 if (n < 0) return 0; 58 switch (type) { 59 case GL_BYTE: size = 1; break; 60 case GL_UNSIGNED_BYTE: size = 1; break; 61 case GL_SHORT: size = 2; break; 62 case GL_UNSIGNED_SHORT: size = 2; break; 63 case GL_INT: size = 4; break; 64 case GL_UNSIGNED_INT: size = 4; break; 65 case GL_FLOAT: size = 4; break; 66 case GL_2_BYTES: size = 2; break; 67 case GL_3_BYTES: size = 3; break; 68 case GL_4_BYTES: size = 4; break; 69 default: 70 return 0; 71 } 72 return n * size; 73} 74 75GLint __glDrawPixels_size(GLenum format, GLenum type, GLsizei w, GLsizei h) 76{ 77 GLint elements, esize; 78 79 switch (format) { 80 case GL_COLOR_INDEX: 81 case GL_STENCIL_INDEX: 82 case GL_DEPTH_COMPONENT: 83 elements = 1; 84 break; 85 case GL_RED: 86 case GL_GREEN: 87 case GL_BLUE: 88 case GL_ALPHA: 89 case GL_LUMINANCE: 90 elements = 1; 91 break; 92 case GL_LUMINANCE_ALPHA: 93 elements = 2; 94 break; 95 case GL_RGB: 96 elements = 3; 97 break; 98 case GL_RGBA: 99 case GL_ABGR_EXT: 100 elements = 4; 101 break; 102 default: 103 return 0; 104 } 105 switch (type) { 106 case GL_BITMAP: 107 if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { 108 return (h * ((w+7)/8)); 109 } else { 110 return 0; 111 } 112 case GL_BYTE: 113 case GL_UNSIGNED_BYTE: 114 esize = 1; 115 break; 116 case GL_UNSIGNED_BYTE_3_3_2: 117 case GL_UNSIGNED_BYTE_2_3_3_REV: 118 esize = 1; 119 elements = 1; 120 break; 121 case GL_SHORT: 122 case GL_UNSIGNED_SHORT: 123 esize = 2; 124 break; 125 case GL_UNSIGNED_SHORT_5_6_5: 126 case GL_UNSIGNED_SHORT_5_6_5_REV: 127 case GL_UNSIGNED_SHORT_4_4_4_4: 128 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 129 case GL_UNSIGNED_SHORT_5_5_5_1: 130 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 131 esize = 2; 132 elements = 1; 133 break; 134 case GL_INT: 135 case GL_UNSIGNED_INT: 136 case GL_FLOAT: 137 esize = 4; 138 break; 139 case GL_UNSIGNED_INT_8_8_8_8: 140 case GL_UNSIGNED_INT_8_8_8_8_REV: 141 case GL_UNSIGNED_INT_10_10_10_2: 142 case GL_UNSIGNED_INT_2_10_10_10_REV: 143 esize = 4; 144 elements = 1; 145 break; 146 default: 147 return 0; 148 } 149 return elements * esize * w * h; 150} 151 152GLint __glBitmap_size(GLsizei w, GLsizei h) 153{ 154 return __glDrawPixels_size(GL_COLOR_INDEX, GL_BITMAP, w, h); 155} 156 157GLint __glTexGendv_size(GLenum e) 158{ 159 switch (e) { 160 case GL_TEXTURE_GEN_MODE: 161 return 1; 162 case GL_OBJECT_PLANE: 163 case GL_EYE_PLANE: 164 return 4; 165 default: 166 return 0; 167 } 168} 169 170GLint __glTexGenfv_size(GLenum e) 171{ 172 return __glTexGendv_size(e); 173} 174 175GLint __glTexGeniv_size(GLenum e) 176{ 177 return __glTexGendv_size(e); 178} 179 180GLint __glTexParameterfv_size(GLenum e) 181{ 182 switch (e) { 183 case GL_TEXTURE_WRAP_S: 184 case GL_TEXTURE_WRAP_T: 185 case GL_TEXTURE_WRAP_R: 186 case GL_TEXTURE_MIN_FILTER: 187 case GL_TEXTURE_MAG_FILTER: 188 return 1; 189 case GL_TEXTURE_BORDER_COLOR: 190 return 4; 191 case GL_TEXTURE_PRIORITY: 192 return 1; 193 case GL_TEXTURE_MIN_LOD: 194 case GL_TEXTURE_MAX_LOD: 195 case GL_TEXTURE_BASE_LEVEL: 196 case GL_TEXTURE_MAX_LEVEL: 197 return 1; 198 default: 199 return 0; 200 } 201} 202 203GLint __glTexParameteriv_size(GLenum e) 204{ 205 return __glTexParameterfv_size(e); 206} 207 208GLint __glTexEnvfv_size(GLenum e) 209{ 210 switch (e) { 211 case GL_TEXTURE_ENV_MODE: 212 return 1; 213 case GL_TEXTURE_ENV_COLOR: 214 return 4; 215 default: 216 return 0; 217 } 218} 219 220GLint __glTexEnviv_size(GLenum e) 221{ 222 return __glTexEnvfv_size(e); 223} 224 225GLint __glTexImage1D_size(GLenum format, GLenum type, GLsizei w) 226{ 227 GLint elements, esize; 228 229 if (w < 0) return 0; 230 switch (format) { 231 case GL_COLOR_INDEX: 232 elements = 1; 233 break; 234 case GL_RED: 235 case GL_GREEN: 236 case GL_BLUE: 237 case GL_ALPHA: 238 case GL_LUMINANCE: 239 elements = 1; 240 break; 241 case GL_LUMINANCE_ALPHA: 242 elements = 2; 243 break; 244 case GL_RGB: 245 elements = 3; 246 break; 247 case GL_RGBA: 248 case GL_ABGR_EXT: 249 elements = 4; 250 break; 251 default: 252 return 0; 253 } 254 switch (type) { 255 case GL_BITMAP: 256 if (format == GL_COLOR_INDEX) { 257 return (w+7)/8; 258 } else { 259 return 0; 260 } 261 case GL_BYTE: 262 case GL_UNSIGNED_BYTE: 263 esize = 1; 264 break; 265 case GL_UNSIGNED_BYTE_3_3_2: 266 case GL_UNSIGNED_BYTE_2_3_3_REV: 267 esize = 1; 268 elements = 1; 269 break; 270 case GL_SHORT: 271 case GL_UNSIGNED_SHORT: 272 esize = 2; 273 break; 274 case GL_UNSIGNED_SHORT_5_6_5: 275 case GL_UNSIGNED_SHORT_5_6_5_REV: 276 case GL_UNSIGNED_SHORT_4_4_4_4: 277 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 278 case GL_UNSIGNED_SHORT_5_5_5_1: 279 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 280 esize = 2; 281 elements = 1; 282 break; 283 case GL_INT: 284 case GL_UNSIGNED_INT: 285 case GL_FLOAT: 286 esize = 4; 287 break; 288 case GL_UNSIGNED_INT_8_8_8_8: 289 case GL_UNSIGNED_INT_8_8_8_8_REV: 290 case GL_UNSIGNED_INT_10_10_10_2: 291 case GL_UNSIGNED_INT_2_10_10_10_REV: 292 esize = 4; 293 elements = 1; 294 break; 295 default: 296 return 0; 297 } 298 return elements * esize * w; 299} 300 301GLint __glTexImage2D_size(GLenum format, GLenum type, GLsizei w, GLsizei h) 302{ 303 GLint elements, esize; 304 305 if (w < 0) return 0; 306 if (h < 0) return 0; 307 switch (format) { 308 case GL_COLOR_INDEX: 309 elements = 1; 310 break; 311 case GL_RED: 312 case GL_GREEN: 313 case GL_BLUE: 314 case GL_ALPHA: 315 case GL_LUMINANCE: 316 elements = 1; 317 break; 318 case GL_LUMINANCE_ALPHA: 319 elements = 2; 320 break; 321 case GL_RGB: 322 elements = 3; 323 break; 324 case GL_RGBA: 325 case GL_ABGR_EXT: 326 elements = 4; 327 break; 328 default: 329 return 0; 330 } 331 switch (type) { 332 case GL_BITMAP: 333 if (format == GL_COLOR_INDEX) { 334 return (h * ((w+7)/8)); 335 } else { 336 return 0; 337 } 338 case GL_BYTE: 339 case GL_UNSIGNED_BYTE: 340 esize = 1; 341 break; 342 case GL_UNSIGNED_BYTE_3_3_2: 343 case GL_UNSIGNED_BYTE_2_3_3_REV: 344 esize = 1; 345 elements = 1; 346 break; 347 case GL_SHORT: 348 case GL_UNSIGNED_SHORT: 349 esize = 2; 350 break; 351 case GL_UNSIGNED_SHORT_5_6_5: 352 case GL_UNSIGNED_SHORT_5_6_5_REV: 353 case GL_UNSIGNED_SHORT_4_4_4_4: 354 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 355 case GL_UNSIGNED_SHORT_5_5_5_1: 356 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 357 esize = 2; 358 elements = 1; 359 break; 360 case GL_INT: 361 case GL_UNSIGNED_INT: 362 case GL_FLOAT: 363 esize = 4; 364 break; 365 case GL_UNSIGNED_INT_8_8_8_8: 366 case GL_UNSIGNED_INT_8_8_8_8_REV: 367 case GL_UNSIGNED_INT_10_10_10_2: 368 case GL_UNSIGNED_INT_2_10_10_10_REV: 369 esize = 4; 370 elements = 1; 371 break; 372 default: 373 return 0; 374 } 375 return elements * esize * w * h; 376} 377 378GLint __glTexImage3D_size(GLenum format, GLenum type, GLsizei w, GLsizei h, 379 GLsizei d) 380{ 381 GLint elements, esize; 382 383 if (w < 0) return 0; 384 if (h < 0) return 0; 385 if (d < 0) return 0; 386 switch (format) { 387 case GL_COLOR_INDEX: 388 elements = 1; 389 break; 390 case GL_RED: 391 case GL_GREEN: 392 case GL_BLUE: 393 case GL_ALPHA: 394 case GL_LUMINANCE: 395 elements = 1; 396 break; 397 case GL_LUMINANCE_ALPHA: 398 elements = 2; 399 break; 400 case GL_RGB: 401 elements = 3; 402 break; 403 case GL_RGBA: 404 case GL_ABGR_EXT: 405 elements = 4; 406 break; 407 default: 408 return 0; 409 } 410 switch (type) { 411 case GL_BITMAP: 412 if (format == GL_COLOR_INDEX) { 413 return (d * (h * ((w+7)/8))); 414 } else { 415 return 0; 416 } 417 case GL_BYTE: 418 case GL_UNSIGNED_BYTE: 419 esize = 1; 420 break; 421 case GL_UNSIGNED_BYTE_3_3_2: 422 case GL_UNSIGNED_BYTE_2_3_3_REV: 423 esize = 1; 424 elements = 1; 425 break; 426 case GL_SHORT: 427 case GL_UNSIGNED_SHORT: 428 esize = 2; 429 break; 430 case GL_UNSIGNED_SHORT_5_6_5: 431 case GL_UNSIGNED_SHORT_5_6_5_REV: 432 case GL_UNSIGNED_SHORT_4_4_4_4: 433 case GL_UNSIGNED_SHORT_4_4_4_4_REV: 434 case GL_UNSIGNED_SHORT_5_5_5_1: 435 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 436 esize = 2; 437 elements = 1; 438 break; 439 case GL_INT: 440 case GL_UNSIGNED_INT: 441 case GL_FLOAT: 442 esize = 4; 443 break; 444 case GL_UNSIGNED_INT_8_8_8_8: 445 case GL_UNSIGNED_INT_8_8_8_8_REV: 446 case GL_UNSIGNED_INT_10_10_10_2: 447 case GL_UNSIGNED_INT_2_10_10_10_REV: 448 esize = 4; 449 elements = 1; 450 break; 451 default: 452 return 0; 453 } 454 return elements * esize * w * h * d; 455} 456 457GLint __glLightfv_size(GLenum pname) 458{ 459 switch (pname) { 460 case GL_SPOT_EXPONENT: return 1; 461 case GL_SPOT_CUTOFF: return 1; 462 case GL_AMBIENT: return 4; 463 case GL_DIFFUSE: return 4; 464 case GL_SPECULAR: return 4; 465 case GL_POSITION: return 4; 466 case GL_SPOT_DIRECTION: return 3; 467 case GL_CONSTANT_ATTENUATION: return 1; 468 case GL_LINEAR_ATTENUATION: return 1; 469 case GL_QUADRATIC_ATTENUATION: return 1; 470 default: 471 return 0; 472 } 473} 474 475GLint __glLightiv_size(GLenum pname) 476{ 477 return __glLightfv_size(pname); 478} 479 480GLint __glLightModelfv_size(GLenum pname) 481{ 482 switch (pname) { 483 case GL_LIGHT_MODEL_AMBIENT: return 4; 484 case GL_LIGHT_MODEL_LOCAL_VIEWER: return 1; 485 case GL_LIGHT_MODEL_TWO_SIDE: return 1; 486 case GL_LIGHT_MODEL_COLOR_CONTROL: return 1; 487 default: 488 return 0; 489 } 490} 491 492GLint __glLightModeliv_size(GLenum pname) 493{ 494 return __glLightModelfv_size(pname); 495} 496 497GLint __glMaterialfv_size(GLenum pname) 498{ 499 switch (pname) { 500 case GL_SHININESS: return 1; 501 case GL_EMISSION: return 4; 502 case GL_AMBIENT: return 4; 503 case GL_DIFFUSE: return 4; 504 case GL_SPECULAR: return 4; 505 case GL_AMBIENT_AND_DIFFUSE: return 4; 506 case GL_COLOR_INDEXES: return 3; 507 default: 508 return 0; 509 } 510} 511 512GLint __glMaterialiv_size(GLenum pname) 513{ 514 return __glMaterialfv_size(pname); 515} 516 517GLint __glColorTableParameterfv_size(GLenum pname) 518{ 519 switch (pname) { 520 case GL_COLOR_TABLE_FORMAT: 521 case GL_COLOR_TABLE_WIDTH: 522 case GL_COLOR_TABLE_RED_SIZE: 523 case GL_COLOR_TABLE_GREEN_SIZE: 524 case GL_COLOR_TABLE_BLUE_SIZE: 525 case GL_COLOR_TABLE_ALPHA_SIZE: 526 case GL_COLOR_TABLE_LUMINANCE_SIZE: 527 case GL_COLOR_TABLE_INTENSITY_SIZE: 528 return 1; 529 case GL_COLOR_TABLE_SCALE: 530 case GL_COLOR_TABLE_BIAS: 531 return 4; 532 default: 533 return -1; 534 } 535} 536 537GLint __glColorTableParameteriv_size(GLenum pname) 538{ 539 return __glColorTableParameterfv_size(pname); 540} 541 542GLint __glConvolutionParameterfv_size(GLenum pname) 543{ 544 switch(pname) { 545 case GL_CONVOLUTION_BORDER_MODE: 546 return 1; 547 case GL_CONVOLUTION_BORDER_COLOR: 548 case GL_CONVOLUTION_FILTER_SCALE: 549 case GL_CONVOLUTION_FILTER_BIAS: 550 return 4; 551 default: /* error: bad enum value */ 552 return -1; 553 } 554} 555 556GLint __glConvolutionParameteriv_size(GLenum pname) 557{ 558 return __glConvolutionParameterfv_size(pname); 559} 560