render2.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. __glXDisp_Map1f(GLbyte * pc)
  39. {
  40. GLint order, k;
  41. GLfloat u1, u2, *points;
  42. GLenum target;
  43. target = *(GLenum *) (pc + 0);
  44. order = *(GLint *) (pc + 12);
  45. u1 = *(GLfloat *) (pc + 4);
  46. u2 = *(GLfloat *) (pc + 8);
  47. points = (GLfloat *) (pc + 16);
  48. k = __glMap1f_size(target);
  49. glMap1f(target, u1, u2, k, order, points);
  50. }
  51. void
  52. __glXDisp_Map2f(GLbyte * pc)
  53. {
  54. GLint uorder, vorder, ustride, vstride, k;
  55. GLfloat u1, u2, v1, v2, *points;
  56. GLenum target;
  57. target = *(GLenum *) (pc + 0);
  58. uorder = *(GLint *) (pc + 12);
  59. vorder = *(GLint *) (pc + 24);
  60. u1 = *(GLfloat *) (pc + 4);
  61. u2 = *(GLfloat *) (pc + 8);
  62. v1 = *(GLfloat *) (pc + 16);
  63. v2 = *(GLfloat *) (pc + 20);
  64. points = (GLfloat *) (pc + 28);
  65. k = __glMap2f_size(target);
  66. ustride = vorder * k;
  67. vstride = k;
  68. glMap2f(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
  69. }
  70. void
  71. __glXDisp_Map1d(GLbyte * pc)
  72. {
  73. GLint order, k;
  74. #ifdef __GLX_ALIGN64
  75. GLint compsize;
  76. #endif
  77. GLenum target;
  78. GLdouble u1, u2, *points;
  79. target = *(GLenum *) (pc + 16);
  80. order = *(GLint *) (pc + 20);
  81. k = __glMap1d_size(target);
  82. #ifdef __GLX_ALIGN64
  83. if (order < 0 || k < 0) {
  84. compsize = 0;
  85. }
  86. else {
  87. compsize = order * k;
  88. }
  89. #endif
  90. __GLX_GET_DOUBLE(u1, pc);
  91. __GLX_GET_DOUBLE(u2, pc + 8);
  92. pc += 24;
  93. #ifdef __GLX_ALIGN64
  94. if (((unsigned long) pc) & 7) {
  95. /*
  96. ** Copy the doubles up 4 bytes, trashing the command but aligning
  97. ** the data in the process
  98. */
  99. __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
  100. points = (GLdouble *) (pc - 4);
  101. }
  102. else {
  103. points = (GLdouble *) pc;
  104. }
  105. #else
  106. points = (GLdouble *) pc;
  107. #endif
  108. glMap1d(target, u1, u2, k, order, points);
  109. }
  110. void
  111. __glXDisp_Map2d(GLbyte * pc)
  112. {
  113. GLdouble u1, u2, v1, v2, *points;
  114. GLint uorder, vorder, ustride, vstride, k;
  115. #ifdef __GLX_ALIGN64
  116. GLint compsize;
  117. #endif
  118. GLenum target;
  119. target = *(GLenum *) (pc + 32);
  120. uorder = *(GLint *) (pc + 36);
  121. vorder = *(GLint *) (pc + 40);
  122. k = __glMap2d_size(target);
  123. #ifdef __GLX_ALIGN64
  124. if (vorder < 0 || uorder < 0 || k < 0) {
  125. compsize = 0;
  126. }
  127. else {
  128. compsize = uorder * vorder * k;
  129. }
  130. #endif
  131. __GLX_GET_DOUBLE(u1, pc);
  132. __GLX_GET_DOUBLE(u2, pc + 8);
  133. __GLX_GET_DOUBLE(v1, pc + 16);
  134. __GLX_GET_DOUBLE(v2, pc + 24);
  135. pc += 44;
  136. ustride = vorder * k;
  137. vstride = k;
  138. #ifdef __GLX_ALIGN64
  139. if (((unsigned long) pc) & 7) {
  140. /*
  141. ** Copy the doubles up 4 bytes, trashing the command but aligning
  142. ** the data in the process
  143. */
  144. __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
  145. points = (GLdouble *) (pc - 4);
  146. }
  147. else {
  148. points = (GLdouble *) pc;
  149. }
  150. #else
  151. points = (GLdouble *) pc;
  152. #endif
  153. glMap2d(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points);
  154. }
  155. void
  156. __glXDisp_DrawArrays(GLbyte * pc)
  157. {
  158. __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *) pc;
  159. __GLXdispatchDrawArraysComponentHeader *compHeader;
  160. GLint numVertexes = hdr->numVertexes;
  161. GLint numComponents = hdr->numComponents;
  162. GLenum primType = hdr->primType;
  163. GLint stride = 0;
  164. int i;
  165. pc += sizeof(__GLXdispatchDrawArraysHeader);
  166. compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
  167. /* compute stride (same for all component arrays) */
  168. for (i = 0; i < numComponents; i++) {
  169. GLenum datatype = compHeader[i].datatype;
  170. GLint numVals = compHeader[i].numVals;
  171. stride += __GLX_PAD(numVals * __glXTypeSize(datatype));
  172. }
  173. pc += numComponents * sizeof(__GLXdispatchDrawArraysComponentHeader);
  174. /* set up component arrays */
  175. for (i = 0; i < numComponents; i++) {
  176. GLenum datatype = compHeader[i].datatype;
  177. GLint numVals = compHeader[i].numVals;
  178. GLenum component = compHeader[i].component;
  179. switch (component) {
  180. case GL_VERTEX_ARRAY:
  181. glEnableClientState(GL_VERTEX_ARRAY);
  182. glVertexPointer(numVals, datatype, stride, pc);
  183. break;
  184. case GL_NORMAL_ARRAY:
  185. glEnableClientState(GL_NORMAL_ARRAY);
  186. glNormalPointer(datatype, stride, pc);
  187. break;
  188. case GL_COLOR_ARRAY:
  189. glEnableClientState(GL_COLOR_ARRAY);
  190. glColorPointer(numVals, datatype, stride, pc);
  191. break;
  192. case GL_INDEX_ARRAY:
  193. glEnableClientState(GL_INDEX_ARRAY);
  194. glIndexPointer(datatype, stride, pc);
  195. break;
  196. case GL_TEXTURE_COORD_ARRAY:
  197. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  198. glTexCoordPointer(numVals, datatype, stride, pc);
  199. break;
  200. case GL_EDGE_FLAG_ARRAY:
  201. glEnableClientState(GL_EDGE_FLAG_ARRAY);
  202. glEdgeFlagPointer(stride, (const GLboolean *) pc);
  203. break;
  204. case GL_SECONDARY_COLOR_ARRAY:
  205. {
  206. PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointerEXT =
  207. __glGetProcAddress("glSecondaryColorPointerEXT");
  208. glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
  209. SecondaryColorPointerEXT(numVals, datatype, stride, pc);
  210. break;
  211. }
  212. case GL_FOG_COORD_ARRAY:
  213. {
  214. PFNGLFOGCOORDPOINTERPROC FogCoordPointerEXT =
  215. __glGetProcAddress("glFogCoordPointerEXT");
  216. glEnableClientState(GL_FOG_COORD_ARRAY);
  217. FogCoordPointerEXT(datatype, stride, pc);
  218. break;
  219. }
  220. default:
  221. break;
  222. }
  223. pc += __GLX_PAD(numVals * __glXTypeSize(datatype));
  224. }
  225. glDrawArrays(primType, 0, numVertexes);
  226. /* turn off anything we might have turned on */
  227. glDisableClientState(GL_VERTEX_ARRAY);
  228. glDisableClientState(GL_NORMAL_ARRAY);
  229. glDisableClientState(GL_COLOR_ARRAY);
  230. glDisableClientState(GL_INDEX_ARRAY);
  231. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  232. glDisableClientState(GL_EDGE_FLAG_ARRAY);
  233. glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
  234. glDisableClientState(GL_FOG_COORD_ARRAY);
  235. }