render2swap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. #ifdef HAVE_DIX_CONFIG_H
  31. #include <dix-config.h>
  32. #endif
  33. #include "glxserver.h"
  34. #include "unpack.h"
  35. #include "indirect_size.h"
  36. #include "indirect_dispatch.h"
  37. void
  38. __glXDispSwap_Map1f(GLbyte * pc)
  39. {
  40. GLint order, k;
  41. GLfloat u1, u2, *points;
  42. GLenum target;
  43. GLint compsize;
  44. __GLX_DECLARE_SWAP_VARIABLES;
  45. __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
  46. __GLX_SWAP_INT(pc + 0);
  47. __GLX_SWAP_INT(pc + 12);
  48. __GLX_SWAP_FLOAT(pc + 4);
  49. __GLX_SWAP_FLOAT(pc + 8);
  50. target = *(GLenum *) (pc + 0);
  51. order = *(GLint *) (pc + 12);
  52. u1 = *(GLfloat *) (pc + 4);
  53. u2 = *(GLfloat *) (pc + 8);
  54. points = (GLfloat *) (pc + 16);
  55. k = __glMap1f_size(target);
  56. if (order <= 0 || k < 0) {
  57. /* Erroneous command. */
  58. compsize = 0;
  59. }
  60. else {
  61. compsize = order * k;
  62. }
  63. __GLX_SWAP_FLOAT_ARRAY(points, compsize);
  64. glMap1f(target, u1, u2, k, order, points);
  65. }
  66. void
  67. __glXDispSwap_Map2f(GLbyte * pc)
  68. {
  69. GLint uorder, vorder, ustride, vstride, k;
  70. GLfloat u1, u2, v1, v2, *points;
  71. GLenum target;
  72. GLint compsize;
  73. __GLX_DECLARE_SWAP_VARIABLES;
  74. __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
  75. __GLX_SWAP_INT(pc + 0);
  76. __GLX_SWAP_INT(pc + 12);
  77. __GLX_SWAP_INT(pc + 24);
  78. __GLX_SWAP_FLOAT(pc + 4);
  79. __GLX_SWAP_FLOAT(pc + 8);
  80. __GLX_SWAP_FLOAT(pc + 16);
  81. __GLX_SWAP_FLOAT(pc + 20);
  82. target = *(GLenum *) (pc + 0);
  83. uorder = *(GLint *) (pc + 12);
  84. vorder = *(GLint *) (pc + 24);
  85. u1 = *(GLfloat *) (pc + 4);
  86. u2 = *(GLfloat *) (pc + 8);
  87. v1 = *(GLfloat *) (pc + 16);
  88. v2 = *(GLfloat *) (pc + 20);
  89. points = (GLfloat *) (pc + 28);
  90. k = __glMap2f_size(target);
  91. ustride = vorder * k;
  92. vstride = k;
  93. if (vorder <= 0 || uorder <= 0 || k < 0) {
  94. /* Erroneous command. */
  95. compsize = 0;
  96. }
  97. else {
  98. compsize = uorder * vorder * k;
  99. }
  100. __GLX_SWAP_FLOAT_ARRAY(points, compsize);
  101. glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
  102. }
  103. void
  104. __glXDispSwap_Map1d(GLbyte * pc)
  105. {
  106. GLint order, k, compsize;
  107. GLenum target;
  108. GLdouble u1, u2, *points;
  109. __GLX_DECLARE_SWAP_VARIABLES;
  110. __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
  111. __GLX_SWAP_DOUBLE(pc + 0);
  112. __GLX_SWAP_DOUBLE(pc + 8);
  113. __GLX_SWAP_INT(pc + 16);
  114. __GLX_SWAP_INT(pc + 20);
  115. target = *(GLenum *) (pc + 16);
  116. order = *(GLint *) (pc + 20);
  117. k = __glMap1d_size(target);
  118. if (order <= 0 || k < 0) {
  119. /* Erroneous command. */
  120. compsize = 0;
  121. }
  122. else {
  123. compsize = order * k;
  124. }
  125. __GLX_GET_DOUBLE(u1, pc);
  126. __GLX_GET_DOUBLE(u2, pc + 8);
  127. __GLX_SWAP_DOUBLE_ARRAY(pc + 24, compsize);
  128. pc += 24;
  129. #ifdef __GLX_ALIGN64
  130. if (((unsigned long) pc) & 7) {
  131. /*
  132. ** Copy the doubles up 4 bytes, trashing the command but aligning
  133. ** the data in the process
  134. */
  135. __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
  136. points = (GLdouble *) (pc - 4);
  137. }
  138. else {
  139. points = (GLdouble *) pc;
  140. }
  141. #else
  142. points = (GLdouble *) pc;
  143. #endif
  144. glMap1d(target, u1, u2, k, order, points);
  145. }
  146. void
  147. __glXDispSwap_Map2d(GLbyte * pc)
  148. {
  149. GLdouble u1, u2, v1, v2, *points;
  150. GLint uorder, vorder, ustride, vstride, k, compsize;
  151. GLenum target;
  152. __GLX_DECLARE_SWAP_VARIABLES;
  153. __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
  154. __GLX_SWAP_DOUBLE(pc + 0);
  155. __GLX_SWAP_DOUBLE(pc + 8);
  156. __GLX_SWAP_DOUBLE(pc + 16);
  157. __GLX_SWAP_DOUBLE(pc + 24);
  158. __GLX_SWAP_INT(pc + 32);
  159. __GLX_SWAP_INT(pc + 36);
  160. __GLX_SWAP_INT(pc + 40);
  161. target = *(GLenum *) (pc + 32);
  162. uorder = *(GLint *) (pc + 36);
  163. vorder = *(GLint *) (pc + 40);
  164. k = __glMap2d_size(target);
  165. if (vorder <= 0 || uorder <= 0 || k < 0) {
  166. /* Erroneous command. */
  167. compsize = 0;
  168. }
  169. else {
  170. compsize = uorder * vorder * k;
  171. }
  172. __GLX_GET_DOUBLE(u1, pc);
  173. __GLX_GET_DOUBLE(u2, pc + 8);
  174. __GLX_GET_DOUBLE(v1, pc + 16);
  175. __GLX_GET_DOUBLE(v2, pc + 24);
  176. __GLX_SWAP_DOUBLE_ARRAY(pc + 44, compsize);
  177. pc += 44;
  178. ustride = vorder * k;
  179. vstride = k;
  180. #ifdef __GLX_ALIGN64
  181. if (((unsigned long) pc) & 7) {
  182. /*
  183. ** Copy the doubles up 4 bytes, trashing the command but aligning
  184. ** the data in the process
  185. */
  186. __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
  187. points = (GLdouble *) (pc - 4);
  188. }
  189. else {
  190. points = (GLdouble *) pc;
  191. }
  192. #else
  193. points = (GLdouble *) pc;
  194. #endif
  195. glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
  196. }
  197. static void
  198. swapArray(GLint numVals, GLenum datatype,
  199. GLint stride, GLint numVertexes, GLbyte * pc)
  200. {
  201. int i, j;
  202. __GLX_DECLARE_SWAP_VARIABLES;
  203. switch (datatype) {
  204. case GL_BYTE:
  205. case GL_UNSIGNED_BYTE:
  206. /* don't need to swap */
  207. return;
  208. case GL_SHORT:
  209. case GL_UNSIGNED_SHORT:
  210. for (i = 0; i < numVertexes; i++) {
  211. GLshort *pVal = (GLshort *) pc;
  212. for (j = 0; j < numVals; j++) {
  213. __GLX_SWAP_SHORT(&pVal[j]);
  214. }
  215. pc += stride;
  216. }
  217. break;
  218. case GL_INT:
  219. case GL_UNSIGNED_INT:
  220. for (i = 0; i < numVertexes; i++) {
  221. GLint *pVal = (GLint *) pc;
  222. for (j = 0; j < numVals; j++) {
  223. __GLX_SWAP_INT(&pVal[j]);
  224. }
  225. pc += stride;
  226. }
  227. break;
  228. case GL_FLOAT:
  229. for (i = 0; i < numVertexes; i++) {
  230. GLfloat *pVal = (GLfloat *) pc;
  231. for (j = 0; j < numVals; j++) {
  232. __GLX_SWAP_FLOAT(&pVal[j]);
  233. }
  234. pc += stride;
  235. }
  236. break;
  237. case GL_DOUBLE:
  238. for (i = 0; i < numVertexes; i++) {
  239. GLdouble *pVal = (GLdouble *) pc;
  240. for (j = 0; j < numVals; j++) {
  241. __GLX_SWAP_DOUBLE(&pVal[j]);
  242. }
  243. pc += stride;
  244. }
  245. break;
  246. default:
  247. return;
  248. }
  249. }
  250. void
  251. __glXDispSwap_DrawArrays(GLbyte * pc)
  252. {
  253. __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *) pc;
  254. __GLXdispatchDrawArraysComponentHeader *compHeader;
  255. GLint numVertexes = hdr->numVertexes;
  256. GLint numComponents = hdr->numComponents;
  257. GLenum primType = hdr->primType;
  258. GLint stride = 0;
  259. int i;
  260. __GLX_DECLARE_SWAP_VARIABLES;
  261. __GLX_SWAP_INT(&numVertexes);
  262. __GLX_SWAP_INT(&numComponents);
  263. __GLX_SWAP_INT(&primType);
  264. pc += sizeof(__GLXdispatchDrawArraysHeader);
  265. compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
  266. /* compute stride (same for all component arrays) */
  267. for (i = 0; i < numComponents; i++) {
  268. GLenum datatype = compHeader[i].datatype;
  269. GLint numVals = compHeader[i].numVals;
  270. GLenum component = compHeader[i].component;
  271. __GLX_SWAP_INT(&datatype);
  272. __GLX_SWAP_INT(&numVals);
  273. __GLX_SWAP_INT(&component);
  274. stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
  275. }
  276. pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
  277. /* set up component arrays */
  278. for (i = 0; i < numComponents; i++) {
  279. GLenum datatype = compHeader[i].datatype;
  280. GLint numVals = compHeader[i].numVals;
  281. GLenum component = compHeader[i].component;
  282. __GLX_SWAP_INT(&datatype);
  283. __GLX_SWAP_INT(&numVals);
  284. __GLX_SWAP_INT(&component);
  285. swapArray(numVals, datatype, stride, numVertexes, pc);
  286. switch (component) {
  287. case GL_VERTEX_ARRAY:
  288. glEnableClientState(GL_VERTEX_ARRAY);
  289. glVertexPointer(numVals, datatype, stride, pc);
  290. break;
  291. case GL_NORMAL_ARRAY:
  292. glEnableClientState(GL_NORMAL_ARRAY);
  293. glNormalPointer(datatype, stride, pc);
  294. break;
  295. case GL_COLOR_ARRAY:
  296. glEnableClientState(GL_COLOR_ARRAY);
  297. glColorPointer(numVals, datatype, stride, pc);
  298. break;
  299. case GL_INDEX_ARRAY:
  300. glEnableClientState(GL_INDEX_ARRAY);
  301. glIndexPointer(datatype, stride, pc);
  302. break;
  303. case GL_TEXTURE_COORD_ARRAY:
  304. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  305. glTexCoordPointer(numVals, datatype, stride, pc);
  306. break;
  307. case GL_EDGE_FLAG_ARRAY:
  308. glEnableClientState(GL_EDGE_FLAG_ARRAY);
  309. glEdgeFlagPointer(stride, (const GLboolean *) pc);
  310. break;
  311. case GL_SECONDARY_COLOR_ARRAY:
  312. {
  313. PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointerEXT =
  314. __glGetProcAddress("glSecondaryColorPointerEXT");
  315. glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
  316. SecondaryColorPointerEXT(numVals, datatype, stride, pc);
  317. break;
  318. }
  319. case GL_FOG_COORD_ARRAY:
  320. {
  321. PFNGLFOGCOORDPOINTERPROC FogCoordPointerEXT =
  322. __glGetProcAddress("glFogCoordPointerEXT");
  323. glEnableClientState(GL_FOG_COORD_ARRAY);
  324. FogCoordPointerEXT(datatype, stride, pc);
  325. break;
  326. }
  327. default:
  328. break;
  329. }
  330. pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
  331. }
  332. glDrawArrays(primType, 0, numVertexes);
  333. /* turn off anything we might have turned on */
  334. glDisableClientState(GL_VERTEX_ARRAY);
  335. glDisableClientState(GL_NORMAL_ARRAY);
  336. glDisableClientState(GL_COLOR_ARRAY);
  337. glDisableClientState(GL_INDEX_ARRAY);
  338. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  339. glDisableClientState(GL_EDGE_FLAG_ARRAY);
  340. glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
  341. glDisableClientState(GL_FOG_COORD_ARRAY);
  342. }