cell: implement NRM3 opcode
[mesa.git] / src / glx / x11 / packsingle.h
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 #ifndef __GLX_packsingle_h__
3 #define __GLX_packsingle_h__
4
5 /*
6 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
7 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice including the dates of first publication and
17 * either this permission notice or a reference to
18 * http://oss.sgi.com/projects/FreeB/
19 * shall be included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * Except as contained in this notice, the name of Silicon Graphics, Inc.
30 * shall not be used in advertising or otherwise to promote the sale, use or
31 * other dealings in this Software without prior written authorization from
32 * Silicon Graphics, Inc.
33 */
34
35 #include "packrender.h"
36
37 /*
38 ** The macros in this header convert wire protocol data types to the client
39 ** machine's native data types. The header is part of the porting layer of
40 ** the client library, and it is intended that hardware vendors will rewrite
41 ** this header to suit their own machines.
42 */
43
44 /*
45 ** Dummy define to make the GetReqExtra macro happy. The value is not
46 ** used, but instead the code in __GLX_SINGLE_BEGIN issues its own store
47 ** to req->reqType with the proper code (our extension code).
48 */
49 #define X_GLXSingle 0
50
51 /* Declare common variables used during a single command */
52 #define __GLX_SINGLE_DECLARE_VARIABLES() \
53 __GLXcontext *gc = __glXGetCurrentContext(); \
54 GLubyte *pc, *pixelHeaderPC; \
55 GLuint compsize, cmdlen; \
56 Display *dpy = gc->currentDpy; \
57 xGLXSingleReq *req
58
59 #define __GLX_SINGLE_LOAD_VARIABLES() \
60 pc = gc->pc; \
61 /* Muffle compilers */ \
62 pixelHeaderPC = 0; (void)pixelHeaderPC; \
63 compsize = 0; (void)compsize; \
64 cmdlen = 0; (void)cmdlen
65
66 /* Start a single command */
67 #define __GLX_SINGLE_BEGIN(opcode,bytes) \
68 if (dpy) { \
69 (void) __glXFlushRenderBuffer(gc, pc); \
70 LockDisplay(dpy); \
71 GetReqExtra(GLXSingle,bytes,req); \
72 req->reqType = gc->majorOpcode; \
73 req->glxCode = opcode; \
74 req->contextTag = gc->currentContextTag; \
75 pc = ((GLubyte *)(req) + sz_xGLXSingleReq)
76
77 /* End a single command */
78 #define __GLX_SINGLE_END() \
79 UnlockDisplay(dpy); \
80 SyncHandle(); \
81 }
82
83 /* Store data to sending for a single command */
84 #define __GLX_SINGLE_PUT_CHAR(offset,a) \
85 *((INT8 *) (pc + offset)) = a
86
87 #ifndef CRAY
88 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
89 *((INT16 *) (pc + offset)) = a
90
91 #define __GLX_SINGLE_PUT_LONG(offset,a) \
92 *((INT32 *) (pc + offset)) = a
93
94 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
95 *((FLOAT32 *) (pc + offset)) = a
96
97 #else
98 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
99 { GLubyte *cp = (pc+offset); \
100 int shift = (64-16) - ((int)(cp) >> (64-6)); \
101 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
102
103 #define __GLX_SINGLE_PUT_LONG(offset,a) \
104 { GLubyte *cp = (pc+offset); \
105 int shift = (64-32) - ((int)(cp) >> (64-6)); \
106 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
107
108 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
109 gl_put_float(pc + offset, a)
110 #endif
111
112 /* Read support macros */
113 #define __GLX_SINGLE_READ_XREPLY() \
114 (void) _XReply(dpy, (xReply*) &reply, 0, False)
115
116 #define __GLX_SINGLE_GET_RETVAL(a,cast) \
117 a = (cast) reply.retval
118
119 #define __GLX_SINGLE_GET_SIZE(a) \
120 a = (GLint) reply.size
121
122 #ifndef _CRAY
123 #define __GLX_SINGLE_GET_CHAR(p) \
124 *p = *(GLbyte *)&reply.pad3;
125
126 #define __GLX_SINGLE_GET_SHORT(p) \
127 *p = *(GLshort *)&reply.pad3;
128
129 #define __GLX_SINGLE_GET_LONG(p) \
130 *p = *(GLint *)&reply.pad3;
131
132 #define __GLX_SINGLE_GET_FLOAT(p) \
133 *p = *(GLfloat *)&reply.pad3;
134
135 #else
136 #define __GLX_SINGLE_GET_CHAR(p) \
137 *p = reply.pad3 >> 24;
138
139 #define __GLX_SINGLE_GET_SHORT(p) \
140 {int t = reply.pad3 >> 16; \
141 *p = (t & 0x8000) ? (t | ~0xffff) : (t & 0xffff);}
142
143 #define __GLX_SINGLE_GET_LONG(p) \
144 {int t = reply.pad3; \
145 *p = (t & 0x80000000) ? (t | ~0xffffffff) : (t & 0xffffffff);}
146
147 #define PAD3OFFSET 16
148 #define __GLX_SINGLE_GET_FLOAT(p) \
149 *p = gl_ntoh_float((GLubyte *)&reply + PAD3OFFSET);
150
151 #define __GLX_SINGLE_GET_DOUBLE(p) \
152 *p = gl_ntoh_double((GLubyte *)&reply + PAD3OFFSET);
153
154 extern float gl_ntoh_float(GLubyte *);
155 extern float gl_ntoh_double(GLubyte *);
156 #endif
157
158 #ifndef _CRAY
159
160 #ifdef __GLX_ALIGN64
161 #define __GLX_SINGLE_GET_DOUBLE(p) \
162 __GLX_MEM_COPY(p, &reply.pad3, 8)
163 #else
164 #define __GLX_SINGLE_GET_DOUBLE(p) \
165 *p = *(GLdouble *)&reply.pad3
166 #endif
167
168 #endif
169
170 /* Get an array of typed data */
171 #define __GLX_SINGLE_GET_VOID_ARRAY(a,alen) \
172 { \
173 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
174 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
175 if (slop) _XEatData(dpy,4-slop); \
176 }
177
178 #define __GLX_SINGLE_GET_CHAR_ARRAY(a,alen) \
179 { \
180 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
181 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
182 if (slop) _XEatData(dpy,4-slop); \
183 }
184
185
186 #define __GLX_SINGLE_GET_SHORT_ARRAY(a,alen) \
187 { \
188 GLint slop = (alen*__GLX_SIZE_INT16) & 3; \
189 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT16); \
190 if (slop) _XEatData(dpy,4-slop); \
191 }
192
193 #define __GLX_SINGLE_GET_LONG_ARRAY(a,alen) \
194 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT32);
195
196 #ifndef _CRAY
197 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
198 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT32);
199
200 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
201 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT64);
202
203 #else
204 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
205 gl_get_float_array(dpy,a,alen);
206
207 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
208 gl_get_double_array(dpy, a, alen);
209
210 extern void gl_get_float_array(Display * dpy, float *a, int alen);
211 extern void gl_get_double_array(Display * dpy, double *a, int alen);
212 #endif
213
214 #endif /* !__GLX_packsingle_h__ */