14642e01fSmrg/*
24642e01fSmrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
34642e01fSmrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
44642e01fSmrg *
54642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
64642e01fSmrg * copy of this software and associated documentation files (the "Software"),
74642e01fSmrg * to deal in the Software without restriction, including without limitation
84642e01fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
94642e01fSmrg * and/or sell copies of the Software, and to permit persons to whom the
104642e01fSmrg * Software is furnished to do so, subject to the following conditions:
114642e01fSmrg *
124642e01fSmrg * The above copyright notice including the dates of first publication and
134642e01fSmrg * either this permission notice or a reference to
144642e01fSmrg * http://oss.sgi.com/projects/FreeB/
154642e01fSmrg * shall be included in all copies or substantial portions of the Software.
164642e01fSmrg *
174642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
184642e01fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
204642e01fSmrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
214642e01fSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
224642e01fSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
234642e01fSmrg * SOFTWARE.
244642e01fSmrg *
254642e01fSmrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
264642e01fSmrg * shall not be used in advertising or otherwise to promote the sale, use or
274642e01fSmrg * other dealings in this Software without prior written authorization from
284642e01fSmrg * Silicon Graphics, Inc.
294642e01fSmrg */
304642e01fSmrg
314642e01fSmrg#ifdef HAVE_DIX_CONFIG_H
324642e01fSmrg#include <dix-config.h>
334642e01fSmrg#endif
344642e01fSmrg
354642e01fSmrg#include <GL/gl.h>
364642e01fSmrg#include "glxserver.h"
374642e01fSmrg#include "singlesize.h"
384642e01fSmrg#include "indirect_size_get.h"
394642e01fSmrg
404642e01fSmrg/*
414642e01fSmrg** These routines compute the size of variable-size returned parameters.
424642e01fSmrg** Unlike the similar routines that do the same thing for variable-size
434642e01fSmrg** incoming parameters, the samplegl library itself doesn't use these routines.
444642e01fSmrg** Hence, they are located here, in the GLX extension library.
454642e01fSmrg*/
464642e01fSmrg
4735c4bbdfSmrgGLint
4835c4bbdfSmrg__glReadPixels_size(GLenum format, GLenum type, GLint w, GLint h)
494642e01fSmrg{
5035c4bbdfSmrg    return __glXImageSize(format, type, 0, w, h, 1, 0, 0, 0, 0, 4);
514642e01fSmrg}
524642e01fSmrg
5335c4bbdfSmrgGLint
5435c4bbdfSmrg__glGetMap_size(GLenum target, GLenum query)
554642e01fSmrg{
5635c4bbdfSmrg    GLint k, order = 0, majorMinor[2];
574642e01fSmrg
584642e01fSmrg    /*
5935c4bbdfSmrg     ** Assume target and query are both valid.
6035c4bbdfSmrg     */
614642e01fSmrg    switch (target) {
6235c4bbdfSmrg    case GL_MAP1_COLOR_4:
6335c4bbdfSmrg    case GL_MAP1_NORMAL:
6435c4bbdfSmrg    case GL_MAP1_INDEX:
6535c4bbdfSmrg    case GL_MAP1_TEXTURE_COORD_1:
6635c4bbdfSmrg    case GL_MAP1_TEXTURE_COORD_2:
6735c4bbdfSmrg    case GL_MAP1_TEXTURE_COORD_3:
6835c4bbdfSmrg    case GL_MAP1_TEXTURE_COORD_4:
6935c4bbdfSmrg    case GL_MAP1_VERTEX_3:
7035c4bbdfSmrg    case GL_MAP1_VERTEX_4:
7135c4bbdfSmrg        switch (query) {
7235c4bbdfSmrg        case GL_COEFF:
7335c4bbdfSmrg            k = __glMap1d_size(target);
7435c4bbdfSmrg            glGetMapiv(target, GL_ORDER, &order);
7535c4bbdfSmrg            /*
7635c4bbdfSmrg             ** The query above might fail, but then order will be zero anyway.
7735c4bbdfSmrg             */
7835c4bbdfSmrg            return order * k;
7935c4bbdfSmrg        case GL_DOMAIN:
8035c4bbdfSmrg            return 2;
8135c4bbdfSmrg        case GL_ORDER:
8235c4bbdfSmrg            return 1;
8335c4bbdfSmrg        }
8435c4bbdfSmrg        break;
8535c4bbdfSmrg    case GL_MAP2_COLOR_4:
8635c4bbdfSmrg    case GL_MAP2_NORMAL:
8735c4bbdfSmrg    case GL_MAP2_INDEX:
8835c4bbdfSmrg    case GL_MAP2_TEXTURE_COORD_1:
8935c4bbdfSmrg    case GL_MAP2_TEXTURE_COORD_2:
9035c4bbdfSmrg    case GL_MAP2_TEXTURE_COORD_3:
9135c4bbdfSmrg    case GL_MAP2_TEXTURE_COORD_4:
9235c4bbdfSmrg    case GL_MAP2_VERTEX_3:
9335c4bbdfSmrg    case GL_MAP2_VERTEX_4:
9435c4bbdfSmrg        switch (query) {
9535c4bbdfSmrg        case GL_COEFF:
9635c4bbdfSmrg            k = __glMap2d_size(target);
9735c4bbdfSmrg            majorMinor[0] = majorMinor[1] = 0;
9835c4bbdfSmrg            glGetMapiv(target, GL_ORDER, majorMinor);
9935c4bbdfSmrg            /*
10035c4bbdfSmrg             ** The query above might fail, but then majorMinor will be zeroes
10135c4bbdfSmrg             */
10235c4bbdfSmrg            return majorMinor[0] * majorMinor[1] * k;
10335c4bbdfSmrg        case GL_DOMAIN:
10435c4bbdfSmrg            return 4;
10535c4bbdfSmrg        case GL_ORDER:
10635c4bbdfSmrg            return 2;
10735c4bbdfSmrg        }
10835c4bbdfSmrg        break;
1094642e01fSmrg    }
1104642e01fSmrg    return -1;
1114642e01fSmrg}
1124642e01fSmrg
11335c4bbdfSmrgGLint
11435c4bbdfSmrg__glGetMapdv_size(GLenum target, GLenum query)
1154642e01fSmrg{
1164642e01fSmrg    return __glGetMap_size(target, query);
1174642e01fSmrg}
1184642e01fSmrg
11935c4bbdfSmrgGLint
12035c4bbdfSmrg__glGetMapfv_size(GLenum target, GLenum query)
1214642e01fSmrg{
1224642e01fSmrg    return __glGetMap_size(target, query);
1234642e01fSmrg}
1244642e01fSmrg
12535c4bbdfSmrgGLint
12635c4bbdfSmrg__glGetMapiv_size(GLenum target, GLenum query)
1274642e01fSmrg{
1284642e01fSmrg    return __glGetMap_size(target, query);
1294642e01fSmrg}
1304642e01fSmrg
13135c4bbdfSmrgGLint
13235c4bbdfSmrg__glGetPixelMap_size(GLenum map)
1334642e01fSmrg{
1344642e01fSmrg    GLint size;
1354642e01fSmrg    GLenum query;
1364642e01fSmrg
1374642e01fSmrg    switch (map) {
13835c4bbdfSmrg    case GL_PIXEL_MAP_I_TO_I:
13935c4bbdfSmrg        query = GL_PIXEL_MAP_I_TO_I_SIZE;
14035c4bbdfSmrg        break;
14135c4bbdfSmrg    case GL_PIXEL_MAP_S_TO_S:
14235c4bbdfSmrg        query = GL_PIXEL_MAP_S_TO_S_SIZE;
14335c4bbdfSmrg        break;
14435c4bbdfSmrg    case GL_PIXEL_MAP_I_TO_R:
14535c4bbdfSmrg        query = GL_PIXEL_MAP_I_TO_R_SIZE;
14635c4bbdfSmrg        break;
14735c4bbdfSmrg    case GL_PIXEL_MAP_I_TO_G:
14835c4bbdfSmrg        query = GL_PIXEL_MAP_I_TO_G_SIZE;
14935c4bbdfSmrg        break;
15035c4bbdfSmrg    case GL_PIXEL_MAP_I_TO_B:
15135c4bbdfSmrg        query = GL_PIXEL_MAP_I_TO_B_SIZE;
15235c4bbdfSmrg        break;
15335c4bbdfSmrg    case GL_PIXEL_MAP_I_TO_A:
15435c4bbdfSmrg        query = GL_PIXEL_MAP_I_TO_A_SIZE;
15535c4bbdfSmrg        break;
15635c4bbdfSmrg    case GL_PIXEL_MAP_R_TO_R:
15735c4bbdfSmrg        query = GL_PIXEL_MAP_R_TO_R_SIZE;
15835c4bbdfSmrg        break;
15935c4bbdfSmrg    case GL_PIXEL_MAP_G_TO_G:
16035c4bbdfSmrg        query = GL_PIXEL_MAP_G_TO_G_SIZE;
16135c4bbdfSmrg        break;
16235c4bbdfSmrg    case GL_PIXEL_MAP_B_TO_B:
16335c4bbdfSmrg        query = GL_PIXEL_MAP_B_TO_B_SIZE;
16435c4bbdfSmrg        break;
16535c4bbdfSmrg    case GL_PIXEL_MAP_A_TO_A:
16635c4bbdfSmrg        query = GL_PIXEL_MAP_A_TO_A_SIZE;
16735c4bbdfSmrg        break;
16835c4bbdfSmrg    default:
16935c4bbdfSmrg        return -1;
1704642e01fSmrg    }
17135c4bbdfSmrg    glGetIntegerv(query, &size);
1724642e01fSmrg    return size;
1734642e01fSmrg}
1744642e01fSmrg
17535c4bbdfSmrgGLint
17635c4bbdfSmrg__glGetPixelMapfv_size(GLenum map)
1774642e01fSmrg{
1784642e01fSmrg    return __glGetPixelMap_size(map);
1794642e01fSmrg}
1804642e01fSmrg
18135c4bbdfSmrgGLint
18235c4bbdfSmrg__glGetPixelMapuiv_size(GLenum map)
1834642e01fSmrg{
1844642e01fSmrg    return __glGetPixelMap_size(map);
1854642e01fSmrg}
1864642e01fSmrg
18735c4bbdfSmrgGLint
18835c4bbdfSmrg__glGetPixelMapusv_size(GLenum map)
1894642e01fSmrg{
1904642e01fSmrg    return __glGetPixelMap_size(map);
1914642e01fSmrg}
1924642e01fSmrg
19335c4bbdfSmrgGLint
19435c4bbdfSmrg__glGetTexImage_size(GLenum target, GLint level, GLenum format,
19535c4bbdfSmrg                     GLenum type, GLint width, GLint height, GLint depth)
1964642e01fSmrg{
19735c4bbdfSmrg    return __glXImageSize(format, type, target, width, height, depth,
19835c4bbdfSmrg                          0, 0, 0, 0, 4);
1994642e01fSmrg}
200