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.

indirect_vertex_program.c 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
  2. /*
  3. * (C) Copyright IBM Corporation 2005
  4. * 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, sub license,
  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 and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  20. * IBM,
  21. * AND/OR THEIR SUPPLIERS 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. #include <inttypes.h>
  27. #include <GL/gl.h>
  28. #include "indirect.h"
  29. #include "glxclient.h"
  30. #include "indirect_vertex_array.h"
  31. #include <GL/glxproto.h>
  32. static void
  33. do_vertex_attrib_enable( GLuint index, GLboolean val )
  34. {
  35. __GLXcontext *gc = __glXGetCurrentContext();
  36. __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
  37. if ( ! __glXSetArrayEnable( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
  38. index, val ) ) {
  39. __glXSetError(gc, GL_INVALID_ENUM);
  40. }
  41. }
  42. void __indirect_glEnableVertexAttribArrayARB( GLuint index )
  43. {
  44. do_vertex_attrib_enable( index, GL_TRUE );
  45. }
  46. void __indirect_glDisableVertexAttribArrayARB( GLuint index )
  47. {
  48. do_vertex_attrib_enable( index, GL_FALSE );
  49. }
  50. static void
  51. get_parameter( unsigned opcode, unsigned size, GLenum target, GLuint index,
  52. void * params )
  53. {
  54. __GLXcontext * const gc = __glXGetCurrentContext();
  55. Display * const dpy = gc->currentDpy;
  56. const GLuint cmdlen = 12;
  57. if (__builtin_expect(dpy != NULL, 1)) {
  58. GLubyte const * pc = __glXSetupVendorRequest(gc,
  59. X_GLXVendorPrivateWithReply,
  60. opcode, cmdlen);
  61. *((GLenum *)(pc + 0)) = target;
  62. *((GLuint *)(pc + 4)) = index;
  63. *((GLuint *)(pc + 8)) = 0;
  64. (void) __glXReadReply(dpy, size, params, GL_FALSE);
  65. UnlockDisplay(dpy); SyncHandle();
  66. }
  67. return;
  68. }
  69. void __indirect_glGetProgramEnvParameterfvARB( GLenum target, GLuint index,
  70. GLfloat * params )
  71. {
  72. get_parameter( 1296, 4, target, index, params );
  73. }
  74. void __indirect_glGetProgramEnvParameterdvARB( GLenum target, GLuint index,
  75. GLdouble * params )
  76. {
  77. get_parameter( 1297, 8, target, index, params );
  78. }
  79. void __indirect_glGetProgramLocalParameterfvARB( GLenum target, GLuint index,
  80. GLfloat * params )
  81. {
  82. get_parameter( 1305, 4, target, index, params );
  83. }
  84. void __indirect_glGetProgramLocalParameterdvARB( GLenum target, GLuint index,
  85. GLdouble * params )
  86. {
  87. get_parameter( 1306, 8, target, index, params );
  88. }
  89. void __indirect_glGetVertexAttribPointervNV( GLuint index, GLenum pname,
  90. GLvoid ** pointer )
  91. {
  92. __GLXcontext * const gc = __glXGetCurrentContext();
  93. __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
  94. if ( pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB ) {
  95. __glXSetError( gc, GL_INVALID_ENUM );
  96. }
  97. if ( ! __glXGetArrayPointer( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
  98. index, pointer ) ) {
  99. __glXSetError( gc, GL_INVALID_VALUE );
  100. }
  101. }
  102. /**
  103. * Get the selected attribute from the vertex array state vector.
  104. *
  105. * \returns
  106. * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned.
  107. */
  108. static GLboolean
  109. get_attrib_array_data( __GLXattribute * state, GLuint index, GLenum cap,
  110. GLintptr * data )
  111. {
  112. GLboolean retval = GL_FALSE;
  113. const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB;
  114. switch( cap ) {
  115. case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
  116. retval = __glXGetArrayEnable( state, attrib, index, data );
  117. break;
  118. case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
  119. retval = __glXGetArraySize( state, attrib, index, data );
  120. break;
  121. case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
  122. retval = __glXGetArrayStride( state, attrib, index, data );
  123. break;
  124. case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
  125. retval = __glXGetArrayType( state, attrib, index, data );
  126. break;
  127. case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
  128. retval = __glXGetArrayNormalized( state, attrib, index, data );
  129. break;
  130. }
  131. return retval;
  132. }
  133. static void get_vertex_attrib( __GLXcontext * gc, unsigned vop,
  134. GLuint index, GLenum pname,
  135. xReply * reply )
  136. {
  137. Display * const dpy = gc->currentDpy;
  138. GLubyte * const pc = __glXSetupVendorRequest(gc,
  139. X_GLXVendorPrivateWithReply,
  140. vop, 8);
  141. *((uint32_t *)(pc + 0)) = index;
  142. *((uint32_t *)(pc + 4)) = pname;
  143. (void) _XReply( dpy, reply, 0, False );
  144. }
  145. void __indirect_glGetVertexAttribivARB( GLuint index, GLenum pname,
  146. GLint * params )
  147. {
  148. __GLXcontext * const gc = __glXGetCurrentContext();
  149. Display * const dpy = gc->currentDpy;
  150. __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
  151. xGLXSingleReply reply;
  152. get_vertex_attrib( gc, 1303, index, pname, (xReply *) & reply );
  153. if ( reply.size != 0 ) {
  154. GLintptr data;
  155. if ( get_attrib_array_data( state, index, pname, & data ) ) {
  156. *params = (GLint) data;
  157. }
  158. else {
  159. if (reply.size == 1) {
  160. *params = (GLint) reply.pad3;
  161. }
  162. else {
  163. _XRead(dpy, (void *) params, 4 * reply.size);
  164. }
  165. }
  166. }
  167. UnlockDisplay(dpy);
  168. SyncHandle();
  169. }
  170. void __indirect_glGetVertexAttribfvARB( GLuint index, GLenum pname,
  171. GLfloat * params )
  172. {
  173. __GLXcontext * const gc = __glXGetCurrentContext();
  174. Display * const dpy = gc->currentDpy;
  175. __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
  176. xGLXSingleReply reply;
  177. get_vertex_attrib( gc, 1302, index, pname, (xReply *) & reply );
  178. if ( reply.size != 0 ) {
  179. GLintptr data;
  180. if ( get_attrib_array_data( state, index, pname, & data ) ) {
  181. *params = (GLfloat) data;
  182. }
  183. else {
  184. if (reply.size == 1) {
  185. (void) memcpy( params, & reply.pad3, sizeof( GLfloat ) );
  186. }
  187. else {
  188. _XRead(dpy, (void *) params, 4 * reply.size);
  189. }
  190. }
  191. }
  192. UnlockDisplay(dpy);
  193. SyncHandle();
  194. }
  195. void __indirect_glGetVertexAttribdvARB( GLuint index, GLenum pname,
  196. GLdouble * params )
  197. {
  198. __GLXcontext * const gc = __glXGetCurrentContext();
  199. Display * const dpy = gc->currentDpy;
  200. __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
  201. xGLXSingleReply reply;
  202. get_vertex_attrib( gc, 1301, index, pname, (xReply *) & reply );
  203. if ( reply.size != 0 ) {
  204. GLintptr data;
  205. if ( get_attrib_array_data( state, index, pname, & data ) ) {
  206. *params = (GLdouble) data;
  207. }
  208. else {
  209. if (reply.size == 1) {
  210. (void) memcpy( params, & reply.pad3, sizeof( GLdouble ) );
  211. }
  212. else {
  213. _XRead(dpy, (void *) params, 8 * reply.size);
  214. }
  215. }
  216. }
  217. UnlockDisplay(dpy);
  218. SyncHandle();
  219. }