2004-10-25 22:09:16 +01:00
|
|
|
/*
|
Update to SGI FreeB 2.0.
Under the terms of version 1.1, "once Covered Code has been published
under a particular version of the License, Recipient may, for the
duration of the License, continue to use it under the terms of that
version, or choose to use such Covered Code under the terms of any
subsequent version published by SGI."
FreeB 2.0 license refers to "dates of first publication". They are here
taken to be 1991-2000, as noted in the original license text:
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
Official FreeB 2.0 text:
http://oss.sgi.com/projects/FreeB/SGIFreeSWLicB.2.0.pdf
As always, this code has not been tested for conformance with the OpenGL
specification. OpenGL conformance testing is available from
http://khronos.org/ and is required for use of the OpenGL logo in
product advertising and promotion.
2008-09-19 22:16:53 +01:00
|
|
|
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
|
|
|
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice including the dates of first publication and
|
|
|
|
* either this permission notice or a reference to
|
|
|
|
* http://oss.sgi.com/projects/FreeB/
|
|
|
|
* shall be included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of Silicon Graphics, Inc.
|
|
|
|
* shall not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
* other dealings in this Software without prior written authorization from
|
|
|
|
* Silicon Graphics, Inc.
|
|
|
|
*/
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
#include <GL/gl.h>
|
2006-06-12 20:56:57 +01:00
|
|
|
#include "glxclient.h"
|
2004-10-25 22:09:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the number of elements per group of a specified format
|
|
|
|
*/
|
2008-10-13 12:12:37 +01:00
|
|
|
GLint
|
|
|
|
__glElementsPerGroup(GLenum format, GLenum type)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2008-10-13 12:12:37 +01:00
|
|
|
/*
|
2004-10-25 22:09:16 +01:00
|
|
|
** To make row length computation valid for image extraction,
|
|
|
|
** packed pixel types assume elements per group equals one.
|
|
|
|
*/
|
2008-10-13 12:12:37 +01:00
|
|
|
switch (type) {
|
|
|
|
case GL_UNSIGNED_BYTE_3_3_2:
|
|
|
|
case GL_UNSIGNED_BYTE_2_3_3_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_8_8_APPLE:
|
|
|
|
case GL_UNSIGNED_SHORT_8_8_REV_APPLE:
|
|
|
|
case GL_UNSIGNED_INT_8_8_8_8:
|
|
|
|
case GL_UNSIGNED_INT_8_8_8_8_REV:
|
|
|
|
case GL_UNSIGNED_INT_10_10_10_2:
|
|
|
|
case GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
case GL_UNSIGNED_INT_24_8_NV:
|
2004-10-25 22:09:16 +01:00
|
|
|
return 1;
|
2008-10-13 12:12:37 +01:00
|
|
|
default:
|
2004-10-25 22:09:16 +01:00
|
|
|
break;
|
2008-10-13 12:12:37 +01:00
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2008-10-13 12:12:37 +01:00
|
|
|
switch (format) {
|
|
|
|
case GL_RGB:
|
|
|
|
case GL_BGR:
|
2015-07-21 16:43:42 +01:00
|
|
|
case GL_RGB_INTEGER_EXT:
|
|
|
|
case GL_BGR_INTEGER_EXT:
|
2008-10-13 12:12:37 +01:00
|
|
|
return 3;
|
2009-11-20 19:03:31 +00:00
|
|
|
case GL_RG:
|
2008-10-13 12:12:37 +01:00
|
|
|
case GL_422_EXT:
|
|
|
|
case GL_422_REV_EXT:
|
|
|
|
case GL_422_AVERAGE_EXT:
|
|
|
|
case GL_422_REV_AVERAGE_EXT:
|
2010-09-09 13:43:11 +01:00
|
|
|
case GL_DEPTH_STENCIL_NV:
|
2008-10-13 12:12:37 +01:00
|
|
|
case GL_YCBCR_422_APPLE:
|
|
|
|
case GL_LUMINANCE_ALPHA:
|
2015-07-21 16:43:42 +01:00
|
|
|
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
|
2008-10-13 12:12:37 +01:00
|
|
|
return 2;
|
|
|
|
case GL_RGBA:
|
|
|
|
case GL_BGRA:
|
|
|
|
case GL_ABGR_EXT:
|
2015-07-21 16:43:42 +01:00
|
|
|
case GL_RGBA_INTEGER_EXT:
|
|
|
|
case GL_BGRA_INTEGER_EXT:
|
2008-10-13 12:12:37 +01:00
|
|
|
return 4;
|
|
|
|
case GL_COLOR_INDEX:
|
|
|
|
case GL_STENCIL_INDEX:
|
|
|
|
case GL_DEPTH_COMPONENT:
|
|
|
|
case GL_RED:
|
|
|
|
case GL_GREEN:
|
|
|
|
case GL_BLUE:
|
|
|
|
case GL_ALPHA:
|
|
|
|
case GL_LUMINANCE:
|
|
|
|
case GL_INTENSITY:
|
2015-07-21 16:43:42 +01:00
|
|
|
case GL_RED_INTEGER_EXT:
|
|
|
|
case GL_GREEN_INTEGER_EXT:
|
|
|
|
case GL_BLUE_INTEGER_EXT:
|
|
|
|
case GL_ALPHA_INTEGER_EXT:
|
|
|
|
case GL_LUMINANCE_INTEGER_EXT:
|
2008-10-13 12:12:37 +01:00
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the number of bytes per element, based on the element type (other
|
|
|
|
** than GL_BITMAP).
|
|
|
|
*/
|
2008-10-13 12:12:37 +01:00
|
|
|
GLint
|
|
|
|
__glBytesPerElement(GLenum type)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2008-10-13 12:12:37 +01:00
|
|
|
switch (type) {
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
case GL_SHORT:
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
|
|
|
case GL_UNSIGNED_SHORT_8_8_APPLE:
|
|
|
|
case GL_UNSIGNED_SHORT_8_8_REV_APPLE:
|
|
|
|
return 2;
|
|
|
|
case GL_UNSIGNED_BYTE:
|
|
|
|
case GL_BYTE:
|
|
|
|
case GL_UNSIGNED_BYTE_3_3_2:
|
|
|
|
case GL_UNSIGNED_BYTE_2_3_3_REV:
|
|
|
|
return 1;
|
|
|
|
case GL_INT:
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
case GL_FLOAT:
|
|
|
|
case GL_UNSIGNED_INT_8_8_8_8:
|
|
|
|
case GL_UNSIGNED_INT_8_8_8_8_REV:
|
|
|
|
case GL_UNSIGNED_INT_10_10_10_2:
|
|
|
|
case GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
case GL_UNSIGNED_INT_24_8_NV:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Compute memory required for internal packed array of data of given type
|
|
|
|
** and format.
|
|
|
|
*/
|
2008-10-13 12:12:37 +01:00
|
|
|
GLint
|
|
|
|
__glImageSize(GLsizei width, GLsizei height, GLsizei depth,
|
|
|
|
GLenum format, GLenum type, GLenum target)
|
2004-10-25 22:09:16 +01:00
|
|
|
{
|
2008-10-13 12:12:37 +01:00
|
|
|
int bytes_per_row;
|
|
|
|
int components;
|
2004-10-25 22:09:16 +01:00
|
|
|
|
2008-10-13 12:12:37 +01:00
|
|
|
switch (target) {
|
|
|
|
case GL_PROXY_TEXTURE_1D:
|
|
|
|
case GL_PROXY_TEXTURE_2D:
|
|
|
|
case GL_PROXY_TEXTURE_3D:
|
|
|
|
case GL_PROXY_TEXTURE_4D_SGIS:
|
|
|
|
case GL_PROXY_TEXTURE_CUBE_MAP:
|
|
|
|
case GL_PROXY_TEXTURE_RECTANGLE_ARB:
|
|
|
|
case GL_PROXY_HISTOGRAM:
|
|
|
|
case GL_PROXY_COLOR_TABLE:
|
|
|
|
case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
|
|
|
|
case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
|
|
|
|
case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
|
|
|
|
case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-07 02:39:09 +00:00
|
|
|
|
2008-10-13 12:12:37 +01:00
|
|
|
if (width < 0 || height < 0 || depth < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-07 02:39:09 +00:00
|
|
|
|
2008-10-13 12:12:37 +01:00
|
|
|
/*
|
2004-10-25 22:09:16 +01:00
|
|
|
** Zero is returned if either format or type are invalid.
|
|
|
|
*/
|
2008-10-13 12:12:37 +01:00
|
|
|
components = __glElementsPerGroup(format, type);
|
|
|
|
if (type == GL_BITMAP) {
|
|
|
|
if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) {
|
|
|
|
bytes_per_row = (width + 7) >> 3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bytes_per_row = __glBytesPerElement(type) * width;
|
|
|
|
}
|
2005-01-07 02:39:09 +00:00
|
|
|
|
2008-10-13 12:12:37 +01:00
|
|
|
return bytes_per_row * height * depth * components;
|
2004-10-25 22:09:16 +01:00
|
|
|
}
|