Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

packrender.h 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef __GLX_packrender_h__
  2. #define __GLX_packrender_h__
  3. /*
  4. * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
  5. * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice including the dates of first publication and
  15. * either this permission notice or a reference to
  16. * http://oss.sgi.com/projects/FreeB/
  17. * shall be included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of Silicon Graphics, Inc.
  28. * shall not be used in advertising or otherwise to promote the sale, use or
  29. * other dealings in this Software without prior written authorization from
  30. * Silicon Graphics, Inc.
  31. */
  32. #include "glxclient.h"
  33. /*
  34. ** The macros in this header convert the client machine's native data types to
  35. ** wire protocol data types. The header is part of the porting layer of the
  36. ** client library, and it is intended that hardware vendors will rewrite this
  37. ** header to suit their own machines.
  38. */
  39. /*
  40. ** Pad a count of bytes to the nearest multiple of 4. The X protocol
  41. ** transfers data in 4 byte quantities, so this macro is used to
  42. ** insure the right amount of data being sent.
  43. */
  44. #define __GLX_PAD(a) (((a)+3) & ~3)
  45. /*
  46. ** Network size parameters
  47. */
  48. #define sz_double 8
  49. /* Setup for all commands */
  50. #define __GLX_DECLARE_VARIABLES() \
  51. struct glx_context *gc; \
  52. GLubyte *pc, *pixelHeaderPC; \
  53. GLuint compsize, cmdlen
  54. #define __GLX_LOAD_VARIABLES() \
  55. gc = __glXGetCurrentContext(); \
  56. pc = gc->pc; \
  57. /* Muffle compilers */ \
  58. cmdlen = 0; (void)cmdlen; \
  59. compsize = 0; (void)compsize; \
  60. pixelHeaderPC = 0; (void)pixelHeaderPC
  61. /*
  62. ** Variable sized command support macro. This macro is used by calls
  63. ** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE.
  64. ** Because of their size, they may not automatically fit in the buffer.
  65. ** If the buffer can't hold the command then it is flushed so that
  66. ** the command will fit in the next buffer.
  67. */
  68. #define __GLX_BEGIN_VARIABLE(opcode,size) \
  69. if (pc + (size) > gc->bufEnd) { \
  70. pc = __glXFlushRenderBuffer(gc, pc); \
  71. } \
  72. __GLX_PUT_SHORT(0,size); \
  73. __GLX_PUT_SHORT(2,opcode)
  74. #define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \
  75. pc = __glXFlushRenderBuffer(gc, pc); \
  76. __GLX_PUT_LONG(0,size); \
  77. __GLX_PUT_LONG(4,opcode)
  78. #define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size) \
  79. if (pc + (size) > gc->bufEnd) { \
  80. pc = __glXFlushRenderBuffer(gc, pc); \
  81. } \
  82. __GLX_PUT_SHORT(0,size); \
  83. __GLX_PUT_SHORT(2,opcode); \
  84. pc += __GLX_RENDER_HDR_SIZE; \
  85. pixelHeaderPC = pc; \
  86. pc += __GLX_PIXEL_HDR_SIZE
  87. #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size) \
  88. pc = __glXFlushRenderBuffer(gc, pc); \
  89. __GLX_PUT_LONG(0,size); \
  90. __GLX_PUT_LONG(4,opcode); \
  91. pc += __GLX_RENDER_LARGE_HDR_SIZE; \
  92. pixelHeaderPC = pc; \
  93. pc += __GLX_PIXEL_HDR_SIZE
  94. #define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size) \
  95. if (pc + (size) > gc->bufEnd) { \
  96. pc = __glXFlushRenderBuffer(gc, pc); \
  97. } \
  98. __GLX_PUT_SHORT(0,size); \
  99. __GLX_PUT_SHORT(2,opcode); \
  100. pc += __GLX_RENDER_HDR_SIZE; \
  101. pixelHeaderPC = pc; \
  102. pc += __GLX_PIXEL_3D_HDR_SIZE
  103. #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size) \
  104. pc = __glXFlushRenderBuffer(gc, pc); \
  105. __GLX_PUT_LONG(0,size); \
  106. __GLX_PUT_LONG(4,opcode); \
  107. pc += __GLX_RENDER_LARGE_HDR_SIZE; \
  108. pixelHeaderPC = pc; \
  109. pc += __GLX_PIXEL_3D_HDR_SIZE
  110. /*
  111. ** Fixed size command support macro. This macro is used by calls that
  112. ** are never larger than __GLX_SMALL_RENDER_CMD_SIZE. Because they
  113. ** always fit in the buffer, and because the buffer promises to
  114. ** maintain enough room for them, we don't need to check for space
  115. ** before doing the storage work.
  116. */
  117. #define __GLX_BEGIN(opcode,size) \
  118. __GLX_PUT_SHORT(0,size); \
  119. __GLX_PUT_SHORT(2,opcode)
  120. /*
  121. ** Finish a rendering command by advancing the pc. If the pc is now past
  122. ** the limit pointer then there is no longer room for a
  123. ** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the
  124. ** assumptions present in the __GLX_BEGIN macro. In this case the
  125. ** rendering buffer is flushed out into the X protocol stream (which may
  126. ** or may not do I/O).
  127. */
  128. #define __GLX_END(size) \
  129. pc += size; \
  130. if (pc > gc->limit) { \
  131. (void) __glXFlushRenderBuffer(gc, pc); \
  132. } else { \
  133. gc->pc = pc; \
  134. }
  135. /* Array copy macros */
  136. #define __GLX_MEM_COPY(dest,src,bytes) \
  137. if (src && dest) \
  138. memcpy(dest, src, bytes)
  139. /* Single item copy macros */
  140. #define __GLX_PUT_CHAR(offset,a) \
  141. *((INT8 *) (pc + offset)) = a
  142. #ifndef _CRAY
  143. #define __GLX_PUT_SHORT(offset,a) \
  144. *((INT16 *) (pc + offset)) = a
  145. #define __GLX_PUT_LONG(offset,a) \
  146. *((INT32 *) (pc + offset)) = a
  147. #define __GLX_PUT_FLOAT(offset,a) \
  148. *((FLOAT32 *) (pc + offset)) = a
  149. #else
  150. #define __GLX_PUT_SHORT(offset,a) \
  151. { GLubyte *cp = (pc+offset); \
  152. int shift = (64-16) - ((int)(cp) >> (64-6)); \
  153. *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
  154. #define __GLX_PUT_LONG(offset,a) \
  155. { GLubyte *cp = (pc+offset); \
  156. int shift = (64-32) - ((int)(cp) >> (64-6)); \
  157. *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
  158. #define __GLX_PUT_FLOAT(offset,a) \
  159. gl_put_float((pc + offset),a)
  160. #define __GLX_PUT_DOUBLE(offset,a) \
  161. gl_put_double(pc + offset, a)
  162. extern void gl_put_float( /*GLubyte *, struct cray_single */ );
  163. extern void gl_put_double( /*GLubyte *, struct cray_double */ );
  164. #endif
  165. #ifndef _CRAY
  166. #ifdef __GLX_ALIGN64
  167. /*
  168. ** This can certainly be done better for a particular machine
  169. ** architecture!
  170. */
  171. #define __GLX_PUT_DOUBLE(offset,a) \
  172. __GLX_MEM_COPY(pc + offset, &a, 8)
  173. #else
  174. #define __GLX_PUT_DOUBLE(offset,a) \
  175. *((FLOAT64 *) (pc + offset)) = a
  176. #endif
  177. #endif
  178. #define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \
  179. __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8)
  180. #ifndef _CRAY
  181. #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
  182. __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16)
  183. #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
  184. __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32)
  185. #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
  186. __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32)
  187. #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
  188. __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64)
  189. #else
  190. #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
  191. gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16)
  192. #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
  193. gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32)
  194. #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
  195. gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32)
  196. #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
  197. gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64)
  198. extern gl_put_short_array(GLubyte *, short *, int);
  199. extern gl_put_long_array(GLubyte *, long *, int);
  200. extern gl_put_float_array(GLubyte *, float *, int);
  201. extern gl_put_double_array(GLubyte *, double *, int);
  202. #endif /* _CRAY */
  203. #endif /* !__GLX_packrender_h__ */