glx: indent -br -i3 -npcs --no-tabs dri2_glx.c
[mesa.git] / src / glx / x11 / render2.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
30 */
31
32 #include "packrender.h"
33 #include "indirect.h"
34 #include "indirect_size.h"
35
36 /*
37 ** This file contains routines that might need to be transported as
38 ** GLXRender or GLXRenderLarge commands, and these commands don't
39 ** use the pixel header. See renderpix.c for those routines.
40 */
41
42 void __indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
43 GLint order, const GLdouble *pnts)
44 {
45 __GLX_DECLARE_VARIABLES();
46 GLint k;
47
48 __GLX_LOAD_VARIABLES();
49 k = __glMap1d_size(target);
50 if (k == 0) {
51 __glXSetError(gc, GL_INVALID_ENUM);
52 return;
53 } else if (stride < k || order <= 0) {
54 __glXSetError(gc, GL_INVALID_VALUE);
55 return;
56 }
57 compsize = k * order * __GLX_SIZE_FLOAT64;
58 cmdlen = 28+compsize;
59 if (!gc->currentDpy) return;
60
61 if (cmdlen <= gc->maxSmallRenderCommandSize) {
62 /* Use GLXRender protocol to send small command */
63 __GLX_BEGIN_VARIABLE(X_GLrop_Map1d,cmdlen);
64 __GLX_PUT_DOUBLE(4,u1);
65 __GLX_PUT_DOUBLE(12,u2);
66 __GLX_PUT_LONG(20,target);
67 __GLX_PUT_LONG(24,order);
68 /*
69 ** NOTE: the doubles that follow are not aligned because of 3
70 ** longs preceeding
71 */
72 __glFillMap1d(k, order, stride, pnts, (pc+28));
73 __GLX_END(cmdlen);
74 } else {
75 /* Use GLXRenderLarge protocol to send command */
76 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d,cmdlen+4);
77 __GLX_PUT_DOUBLE(8,u1);
78 __GLX_PUT_DOUBLE(16,u2);
79 __GLX_PUT_LONG(24,target);
80 __GLX_PUT_LONG(28,order);
81
82 /*
83 ** NOTE: the doubles that follow are not aligned because of 3
84 ** longs preceeding
85 */
86 if (stride != k) {
87 GLubyte *buf;
88
89 buf = (GLubyte *) Xmalloc(compsize);
90 if (!buf) {
91 __glXSetError(gc, GL_OUT_OF_MEMORY);
92 return;
93 }
94 __glFillMap1d(k, order, stride, pnts, buf);
95 __glXSendLargeCommand(gc, pc, 32, buf, compsize);
96 Xfree((char*) buf);
97 } else {
98 /* Data is already packed. Just send it out */
99 __glXSendLargeCommand(gc, pc, 32, pnts, compsize);
100 }
101 }
102 }
103
104 void __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
105 GLint order, const GLfloat *pnts)
106 {
107 __GLX_DECLARE_VARIABLES();
108 GLint k;
109
110 __GLX_LOAD_VARIABLES();
111 k = __glMap1f_size(target);
112 if (k == 0) {
113 __glXSetError(gc, GL_INVALID_ENUM);
114 return;
115 } else if (stride < k || order <= 0) {
116 __glXSetError(gc, GL_INVALID_VALUE);
117 return;
118 }
119 compsize = k * order * __GLX_SIZE_FLOAT32;
120 cmdlen = 20+compsize;
121 if (!gc->currentDpy) return;
122
123 /*
124 ** The order that arguments are packed is different from the order
125 ** for glMap1d.
126 */
127 if (cmdlen <= gc->maxSmallRenderCommandSize) {
128 /* Use GLXRender protocol to send small command */
129 __GLX_BEGIN_VARIABLE(X_GLrop_Map1f,cmdlen);
130 __GLX_PUT_LONG(4,target);
131 __GLX_PUT_FLOAT(8,u1);
132 __GLX_PUT_FLOAT(12,u2);
133 __GLX_PUT_LONG(16,order);
134 __glFillMap1f(k, order, stride, pnts, (GLubyte*) (pc+20));
135 __GLX_END(cmdlen);
136 } else {
137 /* Use GLXRenderLarge protocol to send command */
138 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f,cmdlen+4);
139 __GLX_PUT_LONG(8,target);
140 __GLX_PUT_FLOAT(12,u1);
141 __GLX_PUT_FLOAT(16,u2);
142 __GLX_PUT_LONG(20,order);
143
144 if (stride != k) {
145 GLubyte *buf;
146
147 buf = (GLubyte *) Xmalloc(compsize);
148 if (!buf) {
149 __glXSetError(gc, GL_OUT_OF_MEMORY);
150 return;
151 }
152 __glFillMap1f(k, order, stride, pnts, buf);
153 __glXSendLargeCommand(gc, pc, 24, buf, compsize);
154 Xfree((char*) buf);
155 } else {
156 /* Data is already packed. Just send it out */
157 __glXSendLargeCommand(gc, pc, 24, pnts, compsize);
158 }
159 }
160 }
161
162 void __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, GLint uord,
163 GLdouble v1, GLdouble v2, GLint vstr, GLint vord,
164 const GLdouble *pnts)
165 {
166 __GLX_DECLARE_VARIABLES();
167 GLint k;
168
169 __GLX_LOAD_VARIABLES();
170 k = __glMap2d_size(target);
171 if (k == 0) {
172 __glXSetError(gc, GL_INVALID_ENUM);
173 return;
174 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
175 __glXSetError(gc, GL_INVALID_VALUE);
176 return;
177 }
178 compsize = k * uord * vord * __GLX_SIZE_FLOAT64;
179 cmdlen = 48+compsize;
180 if (!gc->currentDpy) return;
181
182 if (cmdlen <= gc->maxSmallRenderCommandSize) {
183 /* Use GLXRender protocol to send small command */
184 __GLX_BEGIN_VARIABLE(X_GLrop_Map2d,cmdlen);
185 __GLX_PUT_DOUBLE(4,u1);
186 __GLX_PUT_DOUBLE(12,u2);
187 __GLX_PUT_DOUBLE(20,v1);
188 __GLX_PUT_DOUBLE(28,v2);
189 __GLX_PUT_LONG(36,target);
190 __GLX_PUT_LONG(40,uord);
191 __GLX_PUT_LONG(44,vord);
192 /*
193 ** Pack into a u-major ordering.
194 ** NOTE: the doubles that follow are not aligned because of 5
195 ** longs preceeding
196 */
197 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble*) (pc+48));
198 __GLX_END(cmdlen);
199 } else {
200 /* Use GLXRenderLarge protocol to send command */
201 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d,cmdlen+4);
202 __GLX_PUT_DOUBLE(8,u1);
203 __GLX_PUT_DOUBLE(16,u2);
204 __GLX_PUT_DOUBLE(24,v1);
205 __GLX_PUT_DOUBLE(32,v2);
206 __GLX_PUT_LONG(40,target);
207 __GLX_PUT_LONG(44,uord);
208 __GLX_PUT_LONG(48,vord);
209
210 /*
211 ** NOTE: the doubles that follow are not aligned because of 5
212 ** longs preceeding
213 */
214 if ((vstr != k) || (ustr != k*vord)) {
215 GLdouble *buf;
216
217 buf = (GLdouble *) Xmalloc(compsize);
218 if (!buf) {
219 __glXSetError(gc, GL_OUT_OF_MEMORY);
220 return;
221 }
222 /*
223 ** Pack into a u-major ordering.
224 */
225 __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf);
226 __glXSendLargeCommand(gc, pc, 52, buf, compsize);
227 Xfree((char*) buf);
228 } else {
229 /* Data is already packed. Just send it out */
230 __glXSendLargeCommand(gc, pc, 52, pnts, compsize);
231 }
232 }
233 }
234
235 void __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, GLint uord,
236 GLfloat v1, GLfloat v2, GLint vstr, GLint vord,
237 const GLfloat *pnts)
238 {
239 __GLX_DECLARE_VARIABLES();
240 GLint k;
241
242 __GLX_LOAD_VARIABLES();
243 k = __glMap2f_size(target);
244 if (k == 0) {
245 __glXSetError(gc, GL_INVALID_ENUM);
246 return;
247 } else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) {
248 __glXSetError(gc, GL_INVALID_VALUE);
249 return;
250 }
251 compsize = k * uord * vord * __GLX_SIZE_FLOAT32;
252 cmdlen = 32+compsize;
253 if (!gc->currentDpy) return;
254
255 /*
256 ** The order that arguments are packed is different from the order
257 ** for glMap2d.
258 */
259 if (cmdlen <= gc->maxSmallRenderCommandSize) {
260 /* Use GLXRender protocol to send small command */
261 __GLX_BEGIN_VARIABLE(X_GLrop_Map2f,cmdlen);
262 __GLX_PUT_LONG(4,target);
263 __GLX_PUT_FLOAT(8,u1);
264 __GLX_PUT_FLOAT(12,u2);
265 __GLX_PUT_LONG(16,uord);
266 __GLX_PUT_FLOAT(20,v1);
267 __GLX_PUT_FLOAT(24,v2);
268 __GLX_PUT_LONG(28,vord);
269 /*
270 ** Pack into a u-major ordering.
271 */
272 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat*) (pc+32));
273 __GLX_END(cmdlen);
274 } else {
275 /* Use GLXRenderLarge protocol to send command */
276 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f,cmdlen+4);
277 __GLX_PUT_LONG(8,target);
278 __GLX_PUT_FLOAT(12,u1);
279 __GLX_PUT_FLOAT(16,u2);
280 __GLX_PUT_LONG(20,uord);
281 __GLX_PUT_FLOAT(24,v1);
282 __GLX_PUT_FLOAT(28,v2);
283 __GLX_PUT_LONG(32,vord);
284
285 if ((vstr != k) || (ustr != k*vord)) {
286 GLfloat *buf;
287
288 buf = (GLfloat *) Xmalloc(compsize);
289 if (!buf) {
290 __glXSetError(gc, GL_OUT_OF_MEMORY);
291 return;
292 }
293 /*
294 ** Pack into a u-major ordering.
295 */
296 __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf);
297 __glXSendLargeCommand(gc, pc, 36, buf, compsize);
298 Xfree((char*) buf);
299 } else {
300 /* Data is already packed. Just send it out */
301 __glXSendLargeCommand(gc, pc, 36, pnts, compsize);
302 }
303 }
304 }
305
306 void __indirect_glEnable(GLenum cap)
307 {
308 __GLX_DECLARE_VARIABLES();
309
310 __GLX_LOAD_VARIABLES();
311 if (!gc->currentDpy) return;
312
313 switch(cap) {
314 case GL_COLOR_ARRAY:
315 case GL_EDGE_FLAG_ARRAY:
316 case GL_INDEX_ARRAY:
317 case GL_NORMAL_ARRAY:
318 case GL_TEXTURE_COORD_ARRAY:
319 case GL_VERTEX_ARRAY:
320 case GL_SECONDARY_COLOR_ARRAY:
321 case GL_FOG_COORD_ARRAY:
322 __indirect_glEnableClientState(cap);
323 return;
324 default:
325 break;
326 }
327
328 __GLX_BEGIN(X_GLrop_Enable,8);
329 __GLX_PUT_LONG(4,cap);
330 __GLX_END(8);
331 }
332
333 void __indirect_glDisable(GLenum cap)
334 {
335 __GLX_DECLARE_VARIABLES();
336
337 __GLX_LOAD_VARIABLES();
338 if (!gc->currentDpy) return;
339
340 switch(cap) {
341 case GL_COLOR_ARRAY:
342 case GL_EDGE_FLAG_ARRAY:
343 case GL_INDEX_ARRAY:
344 case GL_NORMAL_ARRAY:
345 case GL_TEXTURE_COORD_ARRAY:
346 case GL_VERTEX_ARRAY:
347 case GL_SECONDARY_COLOR_ARRAY:
348 case GL_FOG_COORD_ARRAY:
349 __indirect_glDisableClientState(cap);
350 return;
351 default:
352 break;
353 }
354
355 __GLX_BEGIN(X_GLrop_Disable,8);
356 __GLX_PUT_LONG(4,cap);
357 __GLX_END(8);
358 }