1706f2543Smrg/*
2706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4706f2543Smrg *
5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6706f2543Smrg * copy of this software and associated documentation files (the "Software"),
7706f2543Smrg * to deal in the Software without restriction, including without limitation
8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
10706f2543Smrg * Software is furnished to do so, subject to the following conditions:
11706f2543Smrg *
12706f2543Smrg * The above copyright notice including the dates of first publication and
13706f2543Smrg * either this permission notice or a reference to
14706f2543Smrg * http://oss.sgi.com/projects/FreeB/
15706f2543Smrg * shall be included in all copies or substantial portions of the Software.
16706f2543Smrg *
17706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23706f2543Smrg * SOFTWARE.
24706f2543Smrg *
25706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
26706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or
27706f2543Smrg * other dealings in this Software without prior written authorization from
28706f2543Smrg * Silicon Graphics, Inc.
29706f2543Smrg */
30706f2543Smrg
31706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
32706f2543Smrg#include <dix-config.h>
33706f2543Smrg#endif
34706f2543Smrg
35706f2543Smrg#include <GL/gl.h>
36706f2543Smrg#include "glxserver.h"
37706f2543Smrg#include "singlesize.h"
38706f2543Smrg#include "indirect_size_get.h"
39706f2543Smrg#include "glapitable.h"
40706f2543Smrg#include "glapi.h"
41706f2543Smrg#include "glthread.h"
42706f2543Smrg#include "dispatch.h"
43706f2543Smrg
44706f2543Smrg/*
45706f2543Smrg** These routines compute the size of variable-size returned parameters.
46706f2543Smrg** Unlike the similar routines that do the same thing for variable-size
47706f2543Smrg** incoming parameters, the samplegl library itself doesn't use these routines.
48706f2543Smrg** Hence, they are located here, in the GLX extension library.
49706f2543Smrg*/
50706f2543Smrg
51706f2543SmrgGLint __glReadPixels_size(GLenum format, GLenum type, GLint w, GLint h)
52706f2543Smrg{
53706f2543Smrg    return __glXImageSize( format, type, 0, w, h, 1, 0, 0, 0, 0, 4 );
54706f2543Smrg}
55706f2543Smrg
56706f2543SmrgGLint __glGetMap_size(GLenum target, GLenum query)
57706f2543Smrg{
58706f2543Smrg    GLint k, order=0, majorMinor[2];
59706f2543Smrg
60706f2543Smrg    /*
61706f2543Smrg    ** Assume target and query are both valid.
62706f2543Smrg    */
63706f2543Smrg    switch (target) {
64706f2543Smrg      case GL_MAP1_COLOR_4:
65706f2543Smrg      case GL_MAP1_NORMAL:
66706f2543Smrg      case GL_MAP1_INDEX:
67706f2543Smrg      case GL_MAP1_TEXTURE_COORD_1:
68706f2543Smrg      case GL_MAP1_TEXTURE_COORD_2:
69706f2543Smrg      case GL_MAP1_TEXTURE_COORD_3:
70706f2543Smrg      case GL_MAP1_TEXTURE_COORD_4:
71706f2543Smrg      case GL_MAP1_VERTEX_3:
72706f2543Smrg      case GL_MAP1_VERTEX_4:
73706f2543Smrg	switch (query) {
74706f2543Smrg	  case GL_COEFF:
75706f2543Smrg	    k = __glMap1d_size(target);
76706f2543Smrg	    CALL_GetMapiv( GET_DISPATCH(), (target, GL_ORDER, &order) );
77706f2543Smrg	    /*
78706f2543Smrg	    ** The query above might fail, but then order will be zero anyway.
79706f2543Smrg	    */
80706f2543Smrg	    return order * k;
81706f2543Smrg	  case GL_DOMAIN:
82706f2543Smrg	    return 2;
83706f2543Smrg	  case GL_ORDER:
84706f2543Smrg	    return 1;
85706f2543Smrg	}
86706f2543Smrg	break;
87706f2543Smrg      case GL_MAP2_COLOR_4:
88706f2543Smrg      case GL_MAP2_NORMAL:
89706f2543Smrg      case GL_MAP2_INDEX:
90706f2543Smrg      case GL_MAP2_TEXTURE_COORD_1:
91706f2543Smrg      case GL_MAP2_TEXTURE_COORD_2:
92706f2543Smrg      case GL_MAP2_TEXTURE_COORD_3:
93706f2543Smrg      case GL_MAP2_TEXTURE_COORD_4:
94706f2543Smrg      case GL_MAP2_VERTEX_3:
95706f2543Smrg      case GL_MAP2_VERTEX_4:
96706f2543Smrg	switch (query) {
97706f2543Smrg	  case GL_COEFF:
98706f2543Smrg	    k = __glMap2d_size(target);
99706f2543Smrg	    majorMinor[0] = majorMinor[1] = 0;
100706f2543Smrg	    CALL_GetMapiv( GET_DISPATCH(), (target, GL_ORDER, majorMinor) );
101706f2543Smrg	    /*
102706f2543Smrg	    ** The query above might fail, but then majorMinor will be zeroes
103706f2543Smrg	    */
104706f2543Smrg	    return majorMinor[0] * majorMinor[1] * k;
105706f2543Smrg	  case GL_DOMAIN:
106706f2543Smrg	    return 4;
107706f2543Smrg	  case GL_ORDER:
108706f2543Smrg	    return 2;
109706f2543Smrg	}
110706f2543Smrg	break;
111706f2543Smrg    }
112706f2543Smrg    return -1;
113706f2543Smrg}
114706f2543Smrg
115706f2543SmrgGLint __glGetMapdv_size(GLenum target, GLenum query)
116706f2543Smrg{
117706f2543Smrg    return __glGetMap_size(target, query);
118706f2543Smrg}
119706f2543Smrg
120706f2543SmrgGLint __glGetMapfv_size(GLenum target, GLenum query)
121706f2543Smrg{
122706f2543Smrg    return __glGetMap_size(target, query);
123706f2543Smrg}
124706f2543Smrg
125706f2543SmrgGLint __glGetMapiv_size(GLenum target, GLenum query)
126706f2543Smrg{
127706f2543Smrg    return __glGetMap_size(target, query);
128706f2543Smrg}
129706f2543Smrg
130706f2543SmrgGLint __glGetPixelMap_size(GLenum map)
131706f2543Smrg{
132706f2543Smrg    GLint size;
133706f2543Smrg    GLenum query;
134706f2543Smrg
135706f2543Smrg    switch (map) {
136706f2543Smrg      case GL_PIXEL_MAP_I_TO_I:
137706f2543Smrg	query = GL_PIXEL_MAP_I_TO_I_SIZE;
138706f2543Smrg	break;
139706f2543Smrg      case GL_PIXEL_MAP_S_TO_S:
140706f2543Smrg	query = GL_PIXEL_MAP_S_TO_S_SIZE;
141706f2543Smrg	break;
142706f2543Smrg      case GL_PIXEL_MAP_I_TO_R:
143706f2543Smrg	query = GL_PIXEL_MAP_I_TO_R_SIZE;
144706f2543Smrg	break;
145706f2543Smrg      case GL_PIXEL_MAP_I_TO_G:
146706f2543Smrg	query = GL_PIXEL_MAP_I_TO_G_SIZE;
147706f2543Smrg	break;
148706f2543Smrg      case GL_PIXEL_MAP_I_TO_B:
149706f2543Smrg	query = GL_PIXEL_MAP_I_TO_B_SIZE;
150706f2543Smrg	break;
151706f2543Smrg      case GL_PIXEL_MAP_I_TO_A:
152706f2543Smrg	query = GL_PIXEL_MAP_I_TO_A_SIZE;
153706f2543Smrg	break;
154706f2543Smrg      case GL_PIXEL_MAP_R_TO_R:
155706f2543Smrg	query = GL_PIXEL_MAP_R_TO_R_SIZE;
156706f2543Smrg	break;
157706f2543Smrg      case GL_PIXEL_MAP_G_TO_G:
158706f2543Smrg	query = GL_PIXEL_MAP_G_TO_G_SIZE;
159706f2543Smrg	break;
160706f2543Smrg      case GL_PIXEL_MAP_B_TO_B:
161706f2543Smrg	query = GL_PIXEL_MAP_B_TO_B_SIZE;
162706f2543Smrg	break;
163706f2543Smrg      case GL_PIXEL_MAP_A_TO_A:
164706f2543Smrg	query = GL_PIXEL_MAP_A_TO_A_SIZE;
165706f2543Smrg	break;
166706f2543Smrg      default:
167706f2543Smrg	return -1;
168706f2543Smrg    }
169706f2543Smrg    CALL_GetIntegerv( GET_DISPATCH(), (query, &size) );
170706f2543Smrg    return size;
171706f2543Smrg}
172706f2543Smrg
173706f2543SmrgGLint __glGetPixelMapfv_size(GLenum map)
174706f2543Smrg{
175706f2543Smrg    return __glGetPixelMap_size(map);
176706f2543Smrg}
177706f2543Smrg
178706f2543SmrgGLint __glGetPixelMapuiv_size(GLenum map)
179706f2543Smrg{
180706f2543Smrg    return __glGetPixelMap_size(map);
181706f2543Smrg}
182706f2543Smrg
183706f2543SmrgGLint __glGetPixelMapusv_size(GLenum map)
184706f2543Smrg{
185706f2543Smrg    return __glGetPixelMap_size(map);
186706f2543Smrg}
187706f2543Smrg
188706f2543SmrgGLint __glGetTexImage_size(GLenum target, GLint level, GLenum format,
189706f2543Smrg			   GLenum type, GLint width, GLint height, GLint depth)
190706f2543Smrg{
191706f2543Smrg    return __glXImageSize( format, type, target, width, height, depth,
192706f2543Smrg			   0, 0, 0, 0, 4 );
193706f2543Smrg}
194