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