1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice including the dates of first publication and 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * either this permission notice or a reference to 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * http://oss.sgi.com/projects/FreeB/ 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * shall be included in all copies or substantial portions of the Software. 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE. 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Except as contained in this notice, the name of Silicon Graphics, Inc. 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * shall not be used in advertising or otherwise to promote the sale, use or 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * other dealings in this Software without prior written authorization from 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Silicon Graphics, Inc. 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <GL/gl.h> 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glxclient.h" 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org** Return the number of elements per group of a specified format 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org*/ 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLint 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__glElementsPerGroup(GLenum format, GLenum type) 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ** To make row length computation valid for image extraction, 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ** packed pixel types assume elements per group equals one. 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (type) { 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_BYTE_3_3_2: 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_BYTE_2_3_3_REV: 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_6_5: 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_6_5_REV: 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_4_4_4_4: 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_4_4_4_4_REV: 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_5_5_1: 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_1_5_5_5_REV: 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_8_8_APPLE: 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_8_8_REV_APPLE: 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_8_8_8_8: 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_8_8_8_8_REV: 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_10_10_10_2: 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_2_10_10_10_REV: 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_24_8_NV: 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (format) { 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_RGB: 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_BGR: 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 3; 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_RG: 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_422_EXT: 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_422_REV_EXT: 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_422_AVERAGE_EXT: 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_422_REV_AVERAGE_EXT: 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_DEPTH_STENCIL_NV: 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_YCBCR_422_APPLE: 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_LUMINANCE_ALPHA: 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 2; 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_RGBA: 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_BGRA: 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_ABGR_EXT: 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 4; 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_COLOR_INDEX: 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_STENCIL_INDEX: 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_DEPTH_COMPONENT: 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_RED: 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_GREEN: 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_BLUE: 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_ALPHA: 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_LUMINANCE: 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_INTENSITY: 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org** Return the number of bytes per element, based on the element type (other 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org** than GL_BITMAP). 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org*/ 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLint 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__glBytesPerElement(GLenum type) 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (type) { 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT: 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_SHORT: 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_6_5: 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_6_5_REV: 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_4_4_4_4: 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_4_4_4_4_REV: 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_5_5_5_1: 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_1_5_5_5_REV: 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_8_8_APPLE: 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_SHORT_8_8_REV_APPLE: 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 2; 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_BYTE: 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_BYTE: 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_BYTE_3_3_2: 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_BYTE_2_3_3_REV: 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 1; 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_INT: 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT: 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_FLOAT: 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_8_8_8_8: 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_8_8_8_8_REV: 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_10_10_10_2: 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_2_10_10_10_REV: 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_UNSIGNED_INT_24_8_NV: 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 4; 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org default: 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org** Compute memory required for internal packed array of data of given type 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org** and format. 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org*/ 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLint 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__glImageSize(GLsizei width, GLsizei height, GLsizei depth, 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLenum format, GLenum type, GLenum target) 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int bytes_per_row; 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int components; 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org switch (target) { 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_1D: 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_2D: 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_3D: 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_4D_SGIS: 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_CUBE_MAP: 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_RECTANGLE_ARB: 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_HISTOGRAM: 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_COLOR_TABLE: 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP: 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (width < 0 || height < 0 || depth < 0) { 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ** Zero is returned if either format or type are invalid. 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org components = __glElementsPerGroup(format, type); 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (type == GL_BITMAP) { 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bytes_per_row = (width + 7) >> 3; 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else { 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else { 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org bytes_per_row = __glBytesPerElement(type) * width; 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return bytes_per_row * height * depth * components; 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 184