singlesize.c (5632B)
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 #ifdef HAVE_DIX_CONFIG_H 32 #include <dix-config.h> 33 #endif 34 35 #include <GL/gl.h> 36 #include "glxserver.h" 37 #include "singlesize.h" 38 #include "indirect_size_get.h" 39 40 /* 41 ** These routines compute the size of variable-size returned parameters. 42 ** Unlike the similar routines that do the same thing for variable-size 43 ** incoming parameters, the samplegl library itself doesn't use these routines. 44 ** Hence, they are located here, in the GLX extension library. 45 */ 46 47 GLint 48 __glReadPixels_size(GLenum format, GLenum type, GLint w, GLint h) 49 { 50 return __glXImageSize(format, type, 0, w, h, 1, 0, 0, 0, 0, 4); 51 } 52 53 GLint 54 __glGetMap_size(GLenum target, GLenum query) 55 { 56 GLint k, order = 0, majorMinor[2]; 57 58 /* 59 ** Assume target and query are both valid. 60 */ 61 switch (target) { 62 case GL_MAP1_COLOR_4: 63 case GL_MAP1_NORMAL: 64 case GL_MAP1_INDEX: 65 case GL_MAP1_TEXTURE_COORD_1: 66 case GL_MAP1_TEXTURE_COORD_2: 67 case GL_MAP1_TEXTURE_COORD_3: 68 case GL_MAP1_TEXTURE_COORD_4: 69 case GL_MAP1_VERTEX_3: 70 case GL_MAP1_VERTEX_4: 71 switch (query) { 72 case GL_COEFF: 73 k = __glMap1d_size(target); 74 glGetMapiv(target, GL_ORDER, &order); 75 /* 76 ** The query above might fail, but then order will be zero anyway. 77 */ 78 return order * k; 79 case GL_DOMAIN: 80 return 2; 81 case GL_ORDER: 82 return 1; 83 } 84 break; 85 case GL_MAP2_COLOR_4: 86 case GL_MAP2_NORMAL: 87 case GL_MAP2_INDEX: 88 case GL_MAP2_TEXTURE_COORD_1: 89 case GL_MAP2_TEXTURE_COORD_2: 90 case GL_MAP2_TEXTURE_COORD_3: 91 case GL_MAP2_TEXTURE_COORD_4: 92 case GL_MAP2_VERTEX_3: 93 case GL_MAP2_VERTEX_4: 94 switch (query) { 95 case GL_COEFF: 96 k = __glMap2d_size(target); 97 majorMinor[0] = majorMinor[1] = 0; 98 glGetMapiv(target, GL_ORDER, majorMinor); 99 /* 100 ** The query above might fail, but then majorMinor will be zeroes 101 */ 102 return majorMinor[0] * majorMinor[1] * k; 103 case GL_DOMAIN: 104 return 4; 105 case GL_ORDER: 106 return 2; 107 } 108 break; 109 } 110 return -1; 111 } 112 113 GLint 114 __glGetMapdv_size(GLenum target, GLenum query) 115 { 116 return __glGetMap_size(target, query); 117 } 118 119 GLint 120 __glGetMapfv_size(GLenum target, GLenum query) 121 { 122 return __glGetMap_size(target, query); 123 } 124 125 GLint 126 __glGetMapiv_size(GLenum target, GLenum query) 127 { 128 return __glGetMap_size(target, query); 129 } 130 131 GLint 132 __glGetPixelMap_size(GLenum map) 133 { 134 GLint size; 135 GLenum query; 136 137 switch (map) { 138 case GL_PIXEL_MAP_I_TO_I: 139 query = GL_PIXEL_MAP_I_TO_I_SIZE; 140 break; 141 case GL_PIXEL_MAP_S_TO_S: 142 query = GL_PIXEL_MAP_S_TO_S_SIZE; 143 break; 144 case GL_PIXEL_MAP_I_TO_R: 145 query = GL_PIXEL_MAP_I_TO_R_SIZE; 146 break; 147 case GL_PIXEL_MAP_I_TO_G: 148 query = GL_PIXEL_MAP_I_TO_G_SIZE; 149 break; 150 case GL_PIXEL_MAP_I_TO_B: 151 query = GL_PIXEL_MAP_I_TO_B_SIZE; 152 break; 153 case GL_PIXEL_MAP_I_TO_A: 154 query = GL_PIXEL_MAP_I_TO_A_SIZE; 155 break; 156 case GL_PIXEL_MAP_R_TO_R: 157 query = GL_PIXEL_MAP_R_TO_R_SIZE; 158 break; 159 case GL_PIXEL_MAP_G_TO_G: 160 query = GL_PIXEL_MAP_G_TO_G_SIZE; 161 break; 162 case GL_PIXEL_MAP_B_TO_B: 163 query = GL_PIXEL_MAP_B_TO_B_SIZE; 164 break; 165 case GL_PIXEL_MAP_A_TO_A: 166 query = GL_PIXEL_MAP_A_TO_A_SIZE; 167 break; 168 default: 169 return -1; 170 } 171 glGetIntegerv(query, &size); 172 return size; 173 } 174 175 GLint 176 __glGetPixelMapfv_size(GLenum map) 177 { 178 return __glGetPixelMap_size(map); 179 } 180 181 GLint 182 __glGetPixelMapuiv_size(GLenum map) 183 { 184 return __glGetPixelMap_size(map); 185 } 186 187 GLint 188 __glGetPixelMapusv_size(GLenum map) 189 { 190 return __glGetPixelMap_size(map); 191 } 192 193 GLint 194 __glGetTexImage_size(GLenum target, GLint level, GLenum format, 195 GLenum type, GLint width, GLint height, GLint depth) 196 { 197 return __glXImageSize(format, type, target, width, height, depth, 198 0, 0, 0, 0, 4); 199 }