2 * (C) Copyright IBM Corporation 2004, 2005
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, sub license,
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:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * AND/OR THEIR SUPPLIERS 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
30 #include "glxclient.h"
32 #include <GL/glxproto.h>
33 #include "glxextensions.h"
34 #include "indirect_vertex_array.h"
35 #include "indirect_vertex_array_priv.h"
37 #define __GLX_PAD(n) (((n)+3) & ~3)
40 * \file indirect_vertex_array.c
41 * Implement GLX protocol for vertex arrays and vertex buffer objects.
43 * The most important function in this fill is \c fill_array_info_cache.
44 * The \c array_state_vector contains a cache of the ARRAY_INFO data sent
45 * in the DrawArrays protocol. Certain operations, such as enabling or
46 * disabling an array, can invalidate this cache. \c fill_array_info_cache
47 * fills-in this data. Additionally, it examines the enabled state and
48 * other factors to determine what "version" of DrawArrays protocoal can be
51 * Current, only two versions of DrawArrays protocol are implemented. The
52 * first version is the "none" protocol. This is the fallback when the
53 * server does not support GL 1.1 / EXT_vertex_arrays. It is implemented
54 * by sending batches of immediate mode commands that are equivalent to the
55 * DrawArrays protocol.
57 * The other protocol that is currently implemented is the "old" protocol.
58 * This is the GL 1.1 DrawArrays protocol. The only difference between GL
59 * 1.1 and EXT_vertex_arrays is the opcode used for the DrawArrays command.
60 * This protocol is called "old" because the ARB is in the process of
61 * defining a new protocol, which will probably be called wither "new" or
62 * "vbo", to support multiple texture coordinate arrays, generic attributes,
63 * and vertex buffer objects.
65 * \author Ian Romanick <idr@us.ibm.com>
68 static void emit_DrawArrays_none( GLenum mode
, GLint first
, GLsizei count
);
69 static void emit_DrawArrays_old ( GLenum mode
, GLint first
, GLsizei count
);
71 static void emit_DrawElements_none( GLenum mode
, GLsizei count
, GLenum type
,
72 const GLvoid
*indices
);
73 static void emit_DrawElements_old ( GLenum mode
, GLsizei count
, GLenum type
,
74 const GLvoid
*indices
);
77 static GLubyte
* emit_element_none( GLubyte
* dst
,
78 const struct array_state_vector
* arrays
, unsigned index
);
79 static GLubyte
* emit_element_old( GLubyte
* dst
,
80 const struct array_state_vector
* arrays
, unsigned index
);
81 static struct array_state
* get_array_entry(
82 const struct array_state_vector
* arrays
, GLenum key
, unsigned index
);
83 static void fill_array_info_cache( struct array_state_vector
* arrays
);
84 static GLboolean
validate_mode(__GLXcontext
*gc
, GLenum mode
);
85 static GLboolean
validate_count(__GLXcontext
*gc
, GLsizei count
);
86 static GLboolean
validate_type(__GLXcontext
*gc
, GLenum type
);
90 * Table of sizes, in bytes, of a GL types. All of the type enums are be in
91 * the range 0x1400 - 0x140F. That includes types added by extensions (i.e.,
92 * \c GL_HALF_FLOAT_NV). This elements of this table correspond to the
93 * type enums masked with 0x0f.
96 * \c GL_HALF_FLOAT_NV is not included. Neither are \c GL_2_BYTES,
97 * \c GL_3_BYTES, or \c GL_4_BYTES.
99 const GLuint __glXTypeSize_table
[16] = {
100 1, 1, 2, 2, 4, 4, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0
106 * Initialize vertex array state of a GLX context.
108 * \param gc GLX context whose vertex array state is to be initialized.
111 * This function may only be called after __GLXcontext::gl_extension_bits,
112 * __GLXcontext::server_minor, and __GLXcontext::server_major have been
113 * initialized. These values are used to determine what vertex arrays are
117 * Return values from malloc are not properly tested.
120 __glXInitVertexArrayState( __GLXcontext
* gc
)
122 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
123 struct array_state_vector
* arrays
;
125 unsigned array_count
;
126 int texture_units
= 1, vertex_program_attribs
= 0;
129 GLboolean got_fog
= GL_FALSE
;
130 GLboolean got_secondary_color
= GL_FALSE
;
133 arrays
= calloc( 1, sizeof( struct array_state_vector
) );
134 state
->array_state
= arrays
;
136 arrays
->old_DrawArrays_possible
= !state
->NoDrawArraysProtocol
;
137 arrays
->new_DrawArrays_possible
= GL_FALSE
;
138 arrays
->DrawArrays
= NULL
;
140 arrays
->active_texture_unit
= 0;
143 /* Determine how many arrays are actually needed. Only arrays that
144 * are supported by the server are create. For example, if the server
145 * supports only 2 texture units, then only 2 texture coordinate arrays
148 * At the very least, GL_VERTEX_ARRAY, GL_NORMAL_ARRAY,
149 * GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY, and
150 * GL_EDGE_FLAG_ARRAY are supported.
155 if ( __glExtensionBitIsEnabled( gc
, GL_EXT_fog_coord_bit
)
156 || (gc
->server_major
> 1) || (gc
->server_minor
>= 4) ) {
161 if ( __glExtensionBitIsEnabled( gc
, GL_EXT_secondary_color_bit
)
162 || (gc
->server_major
> 1) || (gc
->server_minor
>= 4) ) {
163 got_secondary_color
= GL_TRUE
;
167 if ( __glExtensionBitIsEnabled( gc
, GL_ARB_multitexture_bit
)
168 || (gc
->server_major
> 1) || (gc
->server_minor
>= 3) ) {
169 __indirect_glGetIntegerv( GL_MAX_TEXTURE_UNITS
, & texture_units
);
172 if ( __glExtensionBitIsEnabled( gc
, GL_ARB_vertex_program_bit
) ) {
173 __indirect_glGetProgramivARB( GL_VERTEX_PROGRAM_ARB
,
174 GL_MAX_PROGRAM_ATTRIBS_ARB
,
175 & vertex_program_attribs
);
178 arrays
->num_texture_units
= texture_units
;
179 arrays
->num_vertex_program_attribs
= vertex_program_attribs
;
180 array_count
+= texture_units
+ vertex_program_attribs
;
181 arrays
->num_arrays
= array_count
;
182 arrays
->arrays
= calloc( array_count
, sizeof( struct array_state
) );
184 arrays
->arrays
[0].data_type
= GL_FLOAT
;
185 arrays
->arrays
[0].count
= 3;
186 arrays
->arrays
[0].key
= GL_NORMAL_ARRAY
;
187 arrays
->arrays
[0].normalized
= GL_TRUE
;
188 arrays
->arrays
[0].old_DrawArrays_possible
= GL_TRUE
;
190 arrays
->arrays
[1].data_type
= GL_FLOAT
;
191 arrays
->arrays
[1].count
= 4;
192 arrays
->arrays
[1].key
= GL_COLOR_ARRAY
;
193 arrays
->arrays
[1].normalized
= GL_TRUE
;
194 arrays
->arrays
[1].old_DrawArrays_possible
= GL_TRUE
;
196 arrays
->arrays
[2].data_type
= GL_FLOAT
;
197 arrays
->arrays
[2].count
= 1;
198 arrays
->arrays
[2].key
= GL_INDEX_ARRAY
;
199 arrays
->arrays
[2].old_DrawArrays_possible
= GL_TRUE
;
201 arrays
->arrays
[3].data_type
= GL_UNSIGNED_BYTE
;
202 arrays
->arrays
[3].count
= 1;
203 arrays
->arrays
[3].key
= GL_EDGE_FLAG_ARRAY
;
204 arrays
->arrays
[3].old_DrawArrays_possible
= GL_TRUE
;
206 for ( i
= 0 ; i
< texture_units
; i
++ ) {
207 arrays
->arrays
[4 + i
].data_type
= GL_FLOAT
;
208 arrays
->arrays
[4 + i
].count
= 4;
209 arrays
->arrays
[4 + i
].key
= GL_TEXTURE_COORD_ARRAY
;
211 arrays
->arrays
[4 + i
].old_DrawArrays_possible
= (i
== 0);
212 arrays
->arrays
[4 + i
].index
= i
;
214 arrays
->arrays
[4 + i
].header
[1] = i
+ GL_TEXTURE0
;
217 i
= 4 + texture_units
;
220 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
221 arrays
->arrays
[i
].count
= 1;
222 arrays
->arrays
[i
].key
= GL_FOG_COORDINATE_ARRAY
;
223 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
227 if ( got_secondary_color
) {
228 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
229 arrays
->arrays
[i
].count
= 3;
230 arrays
->arrays
[i
].key
= GL_SECONDARY_COLOR_ARRAY
;
231 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
232 arrays
->arrays
[i
].normalized
= GL_TRUE
;
237 for ( j
= 0 ; j
< vertex_program_attribs
; j
++ ) {
238 const unsigned idx
= (vertex_program_attribs
- (j
+ 1));
241 arrays
->arrays
[idx
+ i
].data_type
= GL_FLOAT
;
242 arrays
->arrays
[idx
+ i
].count
= 4;
243 arrays
->arrays
[idx
+ i
].key
= GL_VERTEX_ATTRIB_ARRAY_POINTER
;
245 arrays
->arrays
[idx
+ i
].old_DrawArrays_possible
= 0;
246 arrays
->arrays
[idx
+ i
].index
= idx
;
248 arrays
->arrays
[idx
+ i
].header
[1] = idx
;
251 i
+= vertex_program_attribs
;
254 /* Vertex array *must* be last becuase of the way that
255 * emit_DrawArrays_none works.
258 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
259 arrays
->arrays
[i
].count
= 4;
260 arrays
->arrays
[i
].key
= GL_VERTEX_ARRAY
;
261 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
263 assert( (i
+ 1) == arrays
->num_arrays
);
265 arrays
->stack_index
= 0;
266 arrays
->stack
= malloc( sizeof( struct array_stack_state
)
267 * arrays
->num_arrays
);
272 * Calculate the size of a single vertex for the "none" protocol. This is
273 * essentially the size of all the immediate-mode commands required to
274 * implement the enabled vertex arrays.
277 calculate_single_vertex_size_none( const struct array_state_vector
* arrays
)
279 size_t single_vertex_size
= 0;
283 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
284 if ( arrays
->arrays
[i
].enabled
) {
285 single_vertex_size
+= ((uint16_t *)arrays
->arrays
[i
].header
)[0];
289 return single_vertex_size
;
294 * Emit a single element using non-DrawArrays protocol.
297 emit_element_none( GLubyte
* dst
,
298 const struct array_state_vector
* arrays
,
304 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
305 if ( arrays
->arrays
[i
].enabled
) {
306 const size_t offset
= index
* arrays
->arrays
[i
].true_stride
;
308 /* The generic attributes can have more data than is in the
309 * elements. This is because a vertex array can be a 2 element,
310 * normalized, unsigned short, but the "closest" immediate mode
311 * protocol is for a 4Nus. Since the sizes are small, the
312 * performance impact on modern processors should be negligible.
314 (void) memset( dst
, 0,
315 ((uint16_t *)arrays
->arrays
[i
].header
)[0] );
317 (void) memcpy( dst
, arrays
->arrays
[i
].header
,
318 arrays
->arrays
[i
].header_size
);
320 dst
+= arrays
->arrays
[i
].header_size
;
322 (void) memcpy( dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
323 arrays
->arrays
[i
].element_size
);
325 dst
+= __GLX_PAD( arrays
->arrays
[i
].element_size
);
334 * Emit a single element using "old" DrawArrays protocol from
335 * EXT_vertex_arrays / OpenGL 1.1.
338 emit_element_old( GLubyte
* dst
,
339 const struct array_state_vector
* arrays
,
345 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
346 if ( arrays
->arrays
[i
].enabled
) {
347 const size_t offset
= index
* arrays
->arrays
[i
].true_stride
;
349 (void) memcpy( dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
350 arrays
->arrays
[i
].element_size
);
352 dst
+= __GLX_PAD( arrays
->arrays
[i
].element_size
);
361 get_array_entry( const struct array_state_vector
* arrays
,
362 GLenum key
, unsigned index
)
366 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
367 if ( (arrays
->arrays
[i
].key
== key
)
368 && (arrays
->arrays
[i
].index
== index
) ) {
369 return & arrays
->arrays
[i
];
378 allocate_array_info_cache( struct array_state_vector
* arrays
,
379 size_t required_size
)
381 #define MAX_HEADER_SIZE 20
382 if ( arrays
->array_info_cache_buffer_size
< required_size
) {
383 GLubyte
* temp
= realloc( arrays
->array_info_cache_base
,
384 required_size
+ MAX_HEADER_SIZE
);
386 if ( temp
== NULL
) {
390 arrays
->array_info_cache_base
= temp
;
391 arrays
->array_info_cache
= temp
+ MAX_HEADER_SIZE
;
392 arrays
->array_info_cache_buffer_size
= required_size
;
395 arrays
->array_info_cache_size
= required_size
;
403 fill_array_info_cache( struct array_state_vector
* arrays
)
405 GLboolean old_DrawArrays_possible
;
409 /* Determine how many arrays are enabled.
412 arrays
->enabled_client_array_count
= 0;
413 old_DrawArrays_possible
= arrays
->old_DrawArrays_possible
;
414 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
415 if ( arrays
->arrays
[i
].enabled
) {
416 arrays
->enabled_client_array_count
++;
417 old_DrawArrays_possible
&= arrays
->arrays
[i
].old_DrawArrays_possible
;
421 if ( arrays
->new_DrawArrays_possible
) {
422 assert( ! arrays
->new_DrawArrays_possible
);
424 else if ( old_DrawArrays_possible
) {
425 const size_t required_size
= arrays
->enabled_client_array_count
* 12;
429 if ( ! allocate_array_info_cache( arrays
, required_size
) ) {
434 info
= (uint32_t *) arrays
->array_info_cache
;
435 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
436 if ( arrays
->arrays
[i
].enabled
) {
437 *(info
++) = arrays
->arrays
[i
].data_type
;
438 *(info
++) = arrays
->arrays
[i
].count
;
439 *(info
++) = arrays
->arrays
[i
].key
;
443 arrays
->DrawArrays
= emit_DrawArrays_old
;
444 arrays
->DrawElements
= emit_DrawElements_old
;
447 arrays
->DrawArrays
= emit_DrawArrays_none
;
448 arrays
->DrawElements
= emit_DrawElements_none
;
451 arrays
->array_info_cache_valid
= GL_TRUE
;
456 * Emit a \c glDrawArrays command using the "none" protocol. That is,
457 * emit immediate-mode commands that are equivalent to the requiested
458 * \c glDrawArrays command. This is used with servers that don't support
459 * the OpenGL 1.1 / EXT_vertex_arrays DrawArrays protocol or in cases where
460 * vertex state is enabled that is not compatible with that protocol.
463 emit_DrawArrays_none( GLenum mode
, GLint first
, GLsizei count
)
465 __GLXcontext
*gc
= __glXGetCurrentContext();
466 const __GLXattribute
* state
=
467 (const __GLXattribute
*)(gc
->client_state_private
);
468 struct array_state_vector
* arrays
= state
->array_state
;
470 size_t single_vertex_size
;
473 static const uint16_t begin_cmd
[2] = { 8, X_GLrop_Begin
};
474 static const uint16_t end_cmd
[2] = { 4, X_GLrop_End
};
477 single_vertex_size
= calculate_single_vertex_size_none( arrays
);
481 (void) memcpy( pc
, begin_cmd
, 4 );
482 *(int *)(pc
+ 4) = mode
;
486 for ( i
= 0 ; i
< count
; i
++ ) {
487 if ( (pc
+ single_vertex_size
) >= gc
->bufEnd
) {
488 pc
= __glXFlushRenderBuffer(gc
, pc
);
491 pc
= emit_element_none( pc
, arrays
, first
+ i
);
494 if ( (pc
+ 4) >= gc
->bufEnd
) {
495 pc
= __glXFlushRenderBuffer(gc
, pc
);
498 (void) memcpy( pc
, end_cmd
, 4 );
502 if ( gc
->pc
> gc
->limit
) {
503 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
509 * Emit the header data for the GL 1.1 / EXT_vertex_arrays DrawArrays
512 * \param gc GLX context.
513 * \param arrays Array state.
514 * \param elements_per_request Location to store the number of elements that
515 * can fit in a single Render / RenderLarge
517 * \param total_request Total number of requests for a RenderLarge
518 * command. If a Render command is used, this
520 * \param mode Drawing mode.
521 * \param count Number of vertices.
524 * A pointer to the buffer for array data.
527 emit_DrawArrays_header_old( __GLXcontext
* gc
,
528 struct array_state_vector
* arrays
,
529 size_t * elements_per_request
,
530 unsigned int * total_requests
,
531 GLenum mode
, GLsizei count
)
534 size_t single_vertex_size
;
535 const unsigned header_size
= 16;
540 /* Determine the size of the whole command. This includes the header,
541 * the ARRAY_INFO data and the array data. Once this size is calculated,
542 * it will be known whether a Render or RenderLarge command is needed.
545 single_vertex_size
= 0;
546 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
547 if ( arrays
->arrays
[i
].enabled
) {
548 single_vertex_size
+= __GLX_PAD( arrays
->arrays
[i
].element_size
);
552 command_size
= arrays
->array_info_cache_size
+ header_size
553 + (single_vertex_size
* count
);
556 /* Write the header for either a Render command or a RenderLarge
557 * command. After the header is written, write the ARRAY_INFO data.
560 if ( command_size
> gc
->maxSmallRenderCommandSize
) {
561 /* maxSize is the maximum amount of data can be stuffed into a single
562 * packet. sz_xGLXRenderReq is added because bufSize is the maximum
563 * packet size minus sz_xGLXRenderReq.
565 const size_t maxSize
= (gc
->bufSize
+ sz_xGLXRenderReq
)
566 - sz_xGLXRenderLargeReq
;
567 unsigned vertex_requests
;
570 /* Calculate the number of data packets that will be required to send
571 * the whole command. To do this, the number of verticies that
572 * will fit in a single buffer must be calculated.
574 * The important value here is elements_per_request. This is the
575 * number of complete array elements that will fit in a single
576 * buffer. There may be some wasted space at the end of the buffer,
577 * but splitting elements across buffer boundries would be painful.
580 elements_per_request
[0] = maxSize
/ single_vertex_size
;
582 vertex_requests
= (count
+ elements_per_request
[0] - 1)
583 / elements_per_request
[0];
585 *total_requests
= vertex_requests
+ 1;
588 __glXFlushRenderBuffer(gc
, gc
->pc
);
592 pc
= ((GLubyte
*) arrays
->array_info_cache
) - (header_size
+ 4);
593 *(uint32_t *)(pc
+ 0) = command_size
;
594 *(uint32_t *)(pc
+ 4) = X_GLrop_DrawArrays
;
595 *(uint32_t *)(pc
+ 8) = count
;
596 *(uint32_t *)(pc
+ 12) = arrays
->enabled_client_array_count
;
597 *(uint32_t *)(pc
+ 16) = mode
;
599 __glXSendLargeChunk( gc
, 1, *total_requests
, pc
,
600 header_size
+ 4 + arrays
->array_info_cache_size
);
605 if ( (gc
->pc
+ command_size
) >= gc
->bufEnd
) {
606 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
610 *(uint16_t *)(pc
+ 0) = command_size
;
611 *(uint16_t *)(pc
+ 2) = X_GLrop_DrawArrays
;
612 *(uint32_t *)(pc
+ 4) = count
;
613 *(uint32_t *)(pc
+ 8) = arrays
->enabled_client_array_count
;
614 *(uint32_t *)(pc
+ 12) = mode
;
618 (void) memcpy( pc
, arrays
->array_info_cache
,
619 arrays
->array_info_cache_size
);
620 pc
+= arrays
->array_info_cache_size
;
622 *elements_per_request
= count
;
634 emit_DrawArrays_old( GLenum mode
, GLint first
, GLsizei count
)
636 __GLXcontext
*gc
= __glXGetCurrentContext();
637 const __GLXattribute
* state
=
638 (const __GLXattribute
*)(gc
->client_state_private
);
639 struct array_state_vector
* arrays
= state
->array_state
;
642 size_t elements_per_request
;
643 unsigned total_requests
= 0;
645 size_t total_sent
= 0;
648 pc
= emit_DrawArrays_header_old( gc
, arrays
, & elements_per_request
,
649 & total_requests
, mode
, count
);
655 if ( total_requests
== 0 ) {
656 assert( elements_per_request
>= count
);
658 for ( i
= 0 ; i
< count
; i
++ ) {
659 pc
= emit_element_old( pc
, arrays
, i
+ first
);
662 assert( pc
<= gc
->bufEnd
);
665 if ( gc
->pc
> gc
->limit
) {
666 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
673 for ( req
= 2 ; req
<= total_requests
; req
++ ) {
674 if ( count
< elements_per_request
) {
675 elements_per_request
= count
;
679 for ( i
= 0 ; i
< elements_per_request
; i
++ ) {
680 pc
= emit_element_old( pc
, arrays
, i
+ first
);
683 first
+= elements_per_request
;
685 total_sent
+= (size_t) (pc
- gc
->pc
);
686 __glXSendLargeChunk( gc
, req
, total_requests
, gc
->pc
,
689 count
-= elements_per_request
;
696 emit_DrawElements_none( GLenum mode
, GLsizei count
, GLenum type
,
697 const GLvoid
*indices
)
699 __GLXcontext
*gc
= __glXGetCurrentContext();
700 const __GLXattribute
* state
=
701 (const __GLXattribute
*)(gc
->client_state_private
);
702 struct array_state_vector
* arrays
= state
->array_state
;
703 static const uint16_t begin_cmd
[2] = { 8, X_GLrop_Begin
};
704 static const uint16_t end_cmd
[2] = { 4, X_GLrop_End
};
707 size_t single_vertex_size
;
711 single_vertex_size
= calculate_single_vertex_size_none( arrays
);
714 if ( (gc
->pc
+ single_vertex_size
) >= gc
->bufEnd
) {
715 gc
->pc
= __glXFlushRenderBuffer(gc
, gc
->pc
);
720 (void) memcpy( pc
, begin_cmd
, 4 );
721 *(int *)(pc
+ 4) = mode
;
725 for ( i
= 0 ; i
< count
; i
++ ) {
728 if ( (pc
+ single_vertex_size
) >= gc
->bufEnd
) {
729 pc
= __glXFlushRenderBuffer(gc
, pc
);
733 case GL_UNSIGNED_INT
:
734 index
= (unsigned) (((GLuint
*) indices
)[i
]);
736 case GL_UNSIGNED_SHORT
:
737 index
= (unsigned) (((GLushort
*) indices
)[i
]);
739 case GL_UNSIGNED_BYTE
:
740 index
= (unsigned) (((GLubyte
*) indices
)[i
]);
743 pc
= emit_element_none( pc
, arrays
, index
);
746 if ( (pc
+ 4) >= gc
->bufEnd
) {
747 pc
= __glXFlushRenderBuffer(gc
, pc
);
750 (void) memcpy( pc
, end_cmd
, 4 );
754 if ( gc
->pc
> gc
->limit
) {
755 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
763 emit_DrawElements_old( GLenum mode
, GLsizei count
, GLenum type
,
764 const GLvoid
*indices
)
766 __GLXcontext
*gc
= __glXGetCurrentContext();
767 const __GLXattribute
* state
=
768 (const __GLXattribute
*)(gc
->client_state_private
);
769 struct array_state_vector
* arrays
= state
->array_state
;
772 size_t elements_per_request
;
773 unsigned total_requests
= 0;
776 unsigned req_element
=0;
779 pc
= emit_DrawArrays_header_old( gc
, arrays
, & elements_per_request
,
780 & total_requests
, mode
, count
);
787 while ( count
> 0 ) {
788 if ( count
< elements_per_request
) {
789 elements_per_request
= count
;
793 case GL_UNSIGNED_INT
: {
794 const GLuint
* ui_ptr
= (const GLuint
*) indices
+ req_element
;
796 for ( i
= 0 ; i
< elements_per_request
; i
++ ) {
797 const GLint index
= (GLint
) *(ui_ptr
++);
798 pc
= emit_element_old( pc
, arrays
, index
);
802 case GL_UNSIGNED_SHORT
: {
803 const GLushort
* us_ptr
= (const GLushort
*) indices
+ req_element
;
805 for ( i
= 0 ; i
< elements_per_request
; i
++ ) {
806 const GLint index
= (GLint
) *(us_ptr
++);
807 pc
= emit_element_old( pc
, arrays
, index
);
811 case GL_UNSIGNED_BYTE
: {
812 const GLubyte
* ub_ptr
= (const GLubyte
*) indices
+ req_element
;
814 for ( i
= 0 ; i
< elements_per_request
; i
++ ) {
815 const GLint index
= (GLint
) *(ub_ptr
++);
816 pc
= emit_element_old( pc
, arrays
, index
);
822 if ( total_requests
!= 0 ) {
823 __glXSendLargeChunk( gc
, req
, total_requests
, gc
->pc
,
829 count
-= elements_per_request
;
830 req_element
+= elements_per_request
;
834 assert( (total_requests
== 0) || ((req
- 1) == total_requests
) );
836 if ( total_requests
== 0 ) {
837 assert( pc
<= gc
->bufEnd
);
840 if ( gc
->pc
> gc
->limit
) {
841 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
848 * Validate that the \c mode parameter to \c glDrawArrays, et. al. is valid.
849 * If it is not valid, then an error code is set in the GLX context.
852 * \c GL_TRUE if the argument is valid, \c GL_FALSE if is not.
855 validate_mode(__GLXcontext
*gc
, GLenum mode
)
862 case GL_TRIANGLE_STRIP
:
863 case GL_TRIANGLE_FAN
:
870 __glXSetError(gc
, GL_INVALID_ENUM
);
879 * Validate that the \c count parameter to \c glDrawArrays, et. al. is valid.
880 * A value less than zero is invalid and will result in \c GL_INVALID_VALUE
881 * being set. A value of zero will not result in an error being set, but
882 * will result in \c GL_FALSE being returned.
885 * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not.
888 validate_count(__GLXcontext
*gc
, GLsizei count
)
891 __glXSetError(gc
, GL_INVALID_VALUE
);
899 * Validate that the \c type parameter to \c glDrawElements, et. al. is
900 * valid. Only \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT, and
901 * \c GL_UNSIGNED_INT are valid.
904 * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not.
906 static GLboolean
validate_type(__GLXcontext
*gc
, GLenum type
)
909 case GL_UNSIGNED_INT
:
910 case GL_UNSIGNED_SHORT
:
911 case GL_UNSIGNED_BYTE
:
914 __glXSetError(gc
, GL_INVALID_ENUM
);
920 void __indirect_glDrawArrays(GLenum mode
, GLint first
, GLsizei count
)
922 __GLXcontext
*gc
= __glXGetCurrentContext();
923 const __GLXattribute
* state
=
924 (const __GLXattribute
*)(gc
->client_state_private
);
925 struct array_state_vector
* arrays
= state
->array_state
;
928 if ( validate_mode(gc
, mode
) && validate_count(gc
, count
) ) {
929 if ( ! arrays
->array_info_cache_valid
) {
930 fill_array_info_cache( arrays
);
933 arrays
->DrawArrays(mode
, first
, count
);
938 void __indirect_glArrayElement(GLint index
)
940 __GLXcontext
*gc
= __glXGetCurrentContext();
941 const __GLXattribute
* state
=
942 (const __GLXattribute
*)(gc
->client_state_private
);
943 struct array_state_vector
* arrays
= state
->array_state
;
945 size_t single_vertex_size
;
948 single_vertex_size
= calculate_single_vertex_size_none( arrays
);
950 if ( (gc
->pc
+ single_vertex_size
) >= gc
->bufEnd
) {
951 gc
->pc
= __glXFlushRenderBuffer(gc
, gc
->pc
);
954 gc
->pc
= emit_element_none( gc
->pc
, arrays
, index
);
956 if ( gc
->pc
> gc
->limit
) {
957 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
962 void __indirect_glDrawElements(GLenum mode
, GLsizei count
, GLenum type
,
963 const GLvoid
*indices
)
965 __GLXcontext
*gc
= __glXGetCurrentContext();
966 const __GLXattribute
* state
=
967 (const __GLXattribute
*)(gc
->client_state_private
);
968 struct array_state_vector
* arrays
= state
->array_state
;
971 if ( validate_mode(gc
, mode
) && validate_count(gc
, count
)
972 && validate_type(gc
, type
) ) {
973 if ( ! arrays
->array_info_cache_valid
) {
974 fill_array_info_cache( arrays
);
977 arrays
->DrawElements(mode
, count
, type
, indices
);
982 void __indirect_glDrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
983 GLsizei count
, GLenum type
,
984 const GLvoid
*indices
)
986 __GLXcontext
*gc
= __glXGetCurrentContext();
987 const __GLXattribute
* state
=
988 (const __GLXattribute
*)(gc
->client_state_private
);
989 struct array_state_vector
* arrays
= state
->array_state
;
992 if ( validate_mode(gc
, mode
) && validate_count(gc
, count
)
993 && validate_type(gc
, type
) ) {
995 __glXSetError(gc
, GL_INVALID_VALUE
);
999 if ( ! arrays
->array_info_cache_valid
) {
1000 fill_array_info_cache( arrays
);
1003 arrays
->DrawElements(mode
, count
, type
, indices
);
1008 void __indirect_glMultiDrawArraysEXT(GLenum mode
, GLint
*first
, GLsizei
*count
,
1011 __GLXcontext
*gc
= __glXGetCurrentContext();
1012 const __GLXattribute
* state
=
1013 (const __GLXattribute
*)(gc
->client_state_private
);
1014 struct array_state_vector
* arrays
= state
->array_state
;
1018 if ( validate_mode(gc
, mode
) ) {
1019 if ( ! arrays
->array_info_cache_valid
) {
1020 fill_array_info_cache( arrays
);
1023 for ( i
= 0 ; i
< primcount
; i
++ ) {
1024 if ( validate_count( gc
, count
[i
] ) ) {
1025 arrays
->DrawArrays(mode
, first
[i
], count
[i
]);
1032 void __indirect_glMultiDrawElementsEXT(GLenum mode
, const GLsizei
*count
,
1033 GLenum type
, const GLvoid
** indices
,
1036 __GLXcontext
*gc
= __glXGetCurrentContext();
1037 const __GLXattribute
* state
=
1038 (const __GLXattribute
*)(gc
->client_state_private
);
1039 struct array_state_vector
* arrays
= state
->array_state
;
1043 if ( validate_mode(gc
, mode
) && validate_type(gc
, type
) ) {
1044 if ( ! arrays
->array_info_cache_valid
) {
1045 fill_array_info_cache( arrays
);
1048 for ( i
= 0 ; i
< primcount
; i
++ ) {
1049 if ( validate_count( gc
, count
[i
] ) ) {
1050 arrays
->DrawElements(mode
, count
[i
], type
, indices
[i
]);
1057 #define COMMON_ARRAY_DATA_INIT(a, PTR, TYPE, STRIDE, COUNT, NORMALIZED, HDR_SIZE, OPCODE) \
1060 (a)->data_type = TYPE; \
1061 (a)->user_stride = STRIDE; \
1062 (a)->count = COUNT; \
1063 (a)->normalized = NORMALIZED; \
1065 (a)->element_size = __glXTypeSize( TYPE ) * COUNT; \
1066 (a)->true_stride = (STRIDE == 0) \
1067 ? (a)->element_size : STRIDE; \
1069 (a)->header_size = HDR_SIZE; \
1070 ((uint16_t *) (a)->header)[0] = __GLX_PAD((a)->header_size + (a)->element_size); \
1071 ((uint16_t *) (a)->header)[1] = OPCODE; \
1075 void __indirect_glVertexPointer( GLint size
, GLenum type
, GLsizei stride
,
1076 const GLvoid
* pointer
)
1078 static const uint16_t short_ops
[5] = {
1079 0, 0, X_GLrop_Vertex2sv
, X_GLrop_Vertex3sv
, X_GLrop_Vertex4sv
1081 static const uint16_t int_ops
[5] = {
1082 0, 0, X_GLrop_Vertex2iv
, X_GLrop_Vertex3iv
, X_GLrop_Vertex4iv
1084 static const uint16_t float_ops
[5] = {
1085 0, 0, X_GLrop_Vertex2fv
, X_GLrop_Vertex3fv
, X_GLrop_Vertex4fv
1087 static const uint16_t double_ops
[5] = {
1088 0, 0, X_GLrop_Vertex2dv
, X_GLrop_Vertex3dv
, X_GLrop_Vertex4dv
1091 __GLXcontext
*gc
= __glXGetCurrentContext();
1092 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1093 struct array_state_vector
* arrays
= state
->array_state
;
1094 struct array_state
* a
;
1097 if (size
< 2 || size
> 4 || stride
< 0) {
1098 __glXSetError(gc
, GL_INVALID_VALUE
);
1103 case GL_SHORT
: opcode
= short_ops
[size
]; break;
1104 case GL_INT
: opcode
= int_ops
[size
]; break;
1105 case GL_FLOAT
: opcode
= float_ops
[size
]; break;
1106 case GL_DOUBLE
: opcode
= double_ops
[size
]; break;
1108 __glXSetError(gc
, GL_INVALID_ENUM
);
1112 a
= get_array_entry( arrays
, GL_VERTEX_ARRAY
, 0 );
1113 assert( a
!= NULL
);
1114 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, size
, GL_FALSE
, 4,
1118 arrays
->array_info_cache_valid
= GL_FALSE
;
1123 void __indirect_glNormalPointer( GLenum type
, GLsizei stride
,
1124 const GLvoid
* pointer
)
1127 __GLXcontext
*gc
= __glXGetCurrentContext();
1128 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1129 struct array_state_vector
* arrays
= state
->array_state
;
1130 struct array_state
* a
;
1134 __glXSetError(gc
, GL_INVALID_VALUE
);
1139 case GL_BYTE
: opcode
= X_GLrop_Normal3bv
; break;
1140 case GL_SHORT
: opcode
= X_GLrop_Normal3sv
; break;
1141 case GL_INT
: opcode
= X_GLrop_Normal3iv
; break;
1142 case GL_FLOAT
: opcode
= X_GLrop_Normal3fv
; break;
1143 case GL_DOUBLE
: opcode
= X_GLrop_Normal3dv
; break;
1145 __glXSetError(gc
, GL_INVALID_ENUM
);
1149 a
= get_array_entry( arrays
, GL_NORMAL_ARRAY
, 0 );
1150 assert( a
!= NULL
);
1151 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, 3, GL_TRUE
, 4,
1155 arrays
->array_info_cache_valid
= GL_FALSE
;
1160 void __indirect_glColorPointer( GLint size
, GLenum type
, GLsizei stride
,
1161 const GLvoid
* pointer
)
1163 static const uint16_t byte_ops
[5] = {
1164 0, 0, 0, X_GLrop_Color3bv
, X_GLrop_Color4bv
1166 static const uint16_t ubyte_ops
[5] = {
1167 0, 0, 0, X_GLrop_Color3ubv
, X_GLrop_Color4ubv
1169 static const uint16_t short_ops
[5] = {
1170 0, 0, 0, X_GLrop_Color3sv
, X_GLrop_Color4sv
1172 static const uint16_t ushort_ops
[5] = {
1173 0, 0, 0, X_GLrop_Color3usv
, X_GLrop_Color4usv
1175 static const uint16_t int_ops
[5] = {
1176 0, 0, 0, X_GLrop_Color3iv
, X_GLrop_Color4iv
1178 static const uint16_t uint_ops
[5] = {
1179 0, 0, 0, X_GLrop_Color3uiv
, X_GLrop_Color4uiv
1181 static const uint16_t float_ops
[5] = {
1182 0, 0, 0, X_GLrop_Color3fv
, X_GLrop_Color4fv
1184 static const uint16_t double_ops
[5] = {
1185 0, 0, 0, X_GLrop_Color3dv
, X_GLrop_Color4dv
1188 __GLXcontext
*gc
= __glXGetCurrentContext();
1189 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1190 struct array_state_vector
* arrays
= state
->array_state
;
1191 struct array_state
* a
;
1194 if (size
< 3 || size
> 4 || stride
< 0) {
1195 __glXSetError(gc
, GL_INVALID_VALUE
);
1200 case GL_BYTE
: opcode
= byte_ops
[size
]; break;
1201 case GL_UNSIGNED_BYTE
: opcode
= ubyte_ops
[size
]; break;
1202 case GL_SHORT
: opcode
= short_ops
[size
]; break;
1203 case GL_UNSIGNED_SHORT
: opcode
= ushort_ops
[size
]; break;
1204 case GL_INT
: opcode
= int_ops
[size
]; break;
1205 case GL_UNSIGNED_INT
: opcode
= uint_ops
[size
]; break;
1206 case GL_FLOAT
: opcode
= float_ops
[size
]; break;
1207 case GL_DOUBLE
: opcode
= double_ops
[size
]; break;
1209 __glXSetError(gc
, GL_INVALID_ENUM
);
1213 a
= get_array_entry( arrays
, GL_COLOR_ARRAY
, 0 );
1214 assert( a
!= NULL
);
1215 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, size
, GL_TRUE
, 4,
1219 arrays
->array_info_cache_valid
= GL_FALSE
;
1224 void __indirect_glIndexPointer( GLenum type
, GLsizei stride
,
1225 const GLvoid
* pointer
)
1228 __GLXcontext
*gc
= __glXGetCurrentContext();
1229 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1230 struct array_state_vector
* arrays
= state
->array_state
;
1231 struct array_state
* a
;
1235 __glXSetError(gc
, GL_INVALID_VALUE
);
1240 case GL_UNSIGNED_BYTE
: opcode
= X_GLrop_Indexubv
; break;
1241 case GL_SHORT
: opcode
= X_GLrop_Indexsv
; break;
1242 case GL_INT
: opcode
= X_GLrop_Indexiv
; break;
1243 case GL_FLOAT
: opcode
= X_GLrop_Indexfv
; break;
1244 case GL_DOUBLE
: opcode
= X_GLrop_Indexdv
; break;
1246 __glXSetError(gc
, GL_INVALID_ENUM
);
1250 a
= get_array_entry( arrays
, GL_INDEX_ARRAY
, 0 );
1251 assert( a
!= NULL
);
1252 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, 1, GL_FALSE
, 4,
1256 arrays
->array_info_cache_valid
= GL_FALSE
;
1261 void __indirect_glEdgeFlagPointer( GLsizei stride
, const GLvoid
* pointer
)
1263 __GLXcontext
*gc
= __glXGetCurrentContext();
1264 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1265 struct array_state_vector
* arrays
= state
->array_state
;
1266 struct array_state
* a
;
1270 __glXSetError(gc
, GL_INVALID_VALUE
);
1275 a
= get_array_entry( arrays
, GL_EDGE_FLAG_ARRAY
, 0 );
1276 assert( a
!= NULL
);
1277 COMMON_ARRAY_DATA_INIT( a
, pointer
, GL_UNSIGNED_BYTE
, stride
, 1, GL_FALSE
,
1278 4, X_GLrop_EdgeFlagv
);
1281 arrays
->array_info_cache_valid
= GL_FALSE
;
1286 void __indirect_glTexCoordPointer( GLint size
, GLenum type
, GLsizei stride
,
1287 const GLvoid
* pointer
)
1289 static const uint16_t short_ops
[5] = {
1290 0, X_GLrop_TexCoord1sv
, X_GLrop_TexCoord2sv
, X_GLrop_TexCoord3sv
, X_GLrop_TexCoord4sv
1292 static const uint16_t int_ops
[5] = {
1293 0, X_GLrop_TexCoord1iv
, X_GLrop_TexCoord2iv
, X_GLrop_TexCoord3iv
, X_GLrop_TexCoord4iv
1295 static const uint16_t float_ops
[5] = {
1296 0, X_GLrop_TexCoord1dv
, X_GLrop_TexCoord2fv
, X_GLrop_TexCoord3fv
, X_GLrop_TexCoord4fv
1298 static const uint16_t double_ops
[5] = {
1299 0, X_GLrop_TexCoord1dv
, X_GLrop_TexCoord2dv
, X_GLrop_TexCoord3dv
, X_GLrop_TexCoord4dv
1302 static const uint16_t mshort_ops
[5] = {
1303 0, X_GLrop_MultiTexCoord1svARB
, X_GLrop_MultiTexCoord2svARB
, X_GLrop_MultiTexCoord3svARB
, X_GLrop_MultiTexCoord4svARB
1305 static const uint16_t mint_ops
[5] = {
1306 0, X_GLrop_MultiTexCoord1ivARB
, X_GLrop_MultiTexCoord2ivARB
, X_GLrop_MultiTexCoord3ivARB
, X_GLrop_MultiTexCoord4ivARB
1308 static const uint16_t mfloat_ops
[5] = {
1309 0, X_GLrop_MultiTexCoord1dvARB
, X_GLrop_MultiTexCoord2fvARB
, X_GLrop_MultiTexCoord3fvARB
, X_GLrop_MultiTexCoord4fvARB
1311 static const uint16_t mdouble_ops
[5] = {
1312 0, X_GLrop_MultiTexCoord1dvARB
, X_GLrop_MultiTexCoord2dvARB
, X_GLrop_MultiTexCoord3dvARB
, X_GLrop_MultiTexCoord4dvARB
1316 __GLXcontext
*gc
= __glXGetCurrentContext();
1317 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1318 struct array_state_vector
* arrays
= state
->array_state
;
1319 struct array_state
* a
;
1320 unsigned header_size
;
1324 if (size
< 1 || size
> 4 || stride
< 0) {
1325 __glXSetError(gc
, GL_INVALID_VALUE
);
1329 index
= arrays
->active_texture_unit
;
1332 case GL_SHORT
: opcode
= short_ops
[size
]; break;
1333 case GL_INT
: opcode
= int_ops
[size
]; break;
1334 case GL_FLOAT
: opcode
= float_ops
[size
]; break;
1335 case GL_DOUBLE
: opcode
= double_ops
[size
]; break;
1337 __glXSetError(gc
, GL_INVALID_ENUM
);
1345 case GL_SHORT
: opcode
= mshort_ops
[size
]; break;
1346 case GL_INT
: opcode
= mint_ops
[size
]; break;
1347 case GL_FLOAT
: opcode
= mfloat_ops
[size
]; break;
1348 case GL_DOUBLE
: opcode
= mdouble_ops
[size
]; break;
1350 __glXSetError(gc
, GL_INVALID_ENUM
);
1357 a
= get_array_entry( arrays
, GL_TEXTURE_COORD_ARRAY
, index
);
1358 assert( a
!= NULL
);
1359 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, size
, GL_FALSE
,
1360 header_size
, opcode
);
1363 arrays
->array_info_cache_valid
= GL_FALSE
;
1368 void __indirect_glSecondaryColorPointerEXT( GLint size
, GLenum type
, GLsizei stride
,
1369 const GLvoid
* pointer
)
1372 __GLXcontext
*gc
= __glXGetCurrentContext();
1373 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1374 struct array_state_vector
* arrays
= state
->array_state
;
1375 struct array_state
* a
;
1378 if (size
!= 3 || stride
< 0) {
1379 __glXSetError(gc
, GL_INVALID_VALUE
);
1384 case GL_BYTE
: opcode
= 4126; break;
1385 case GL_UNSIGNED_BYTE
: opcode
= 4131; break;
1386 case GL_SHORT
: opcode
= 4127; break;
1387 case GL_UNSIGNED_SHORT
: opcode
= 4132; break;
1388 case GL_INT
: opcode
= 4128; break;
1389 case GL_UNSIGNED_INT
: opcode
= 4133; break;
1390 case GL_FLOAT
: opcode
= 4129; break;
1391 case GL_DOUBLE
: opcode
= 4130; break;
1393 __glXSetError(gc
, GL_INVALID_ENUM
);
1397 a
= get_array_entry( arrays
, GL_SECONDARY_COLOR_ARRAY
, 0 );
1399 __glXSetError(gc
, GL_INVALID_OPERATION
);
1403 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, size
, GL_TRUE
, 4,
1407 arrays
->array_info_cache_valid
= GL_FALSE
;
1412 void __indirect_glFogCoordPointerEXT( GLenum type
, GLsizei stride
,
1413 const GLvoid
* pointer
)
1416 __GLXcontext
*gc
= __glXGetCurrentContext();
1417 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1418 struct array_state_vector
* arrays
= state
->array_state
;
1419 struct array_state
* a
;
1423 __glXSetError(gc
, GL_INVALID_VALUE
);
1428 case GL_FLOAT
: opcode
= 4124; break;
1429 case GL_DOUBLE
: opcode
= 4125; break;
1431 __glXSetError(gc
, GL_INVALID_ENUM
);
1435 a
= get_array_entry( arrays
, GL_FOG_COORD_ARRAY
, 0 );
1437 __glXSetError(gc
, GL_INVALID_OPERATION
);
1441 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, 1, GL_FALSE
, 4,
1445 arrays
->array_info_cache_valid
= GL_FALSE
;
1450 void __indirect_glVertexAttribPointerARB(GLuint index
, GLint size
,
1451 GLenum type
, GLboolean normalized
,
1453 const GLvoid
* pointer
)
1455 static const uint16_t short_ops
[5] = { 0, 4189, 4190, 4191, 4192 };
1456 static const uint16_t float_ops
[5] = { 0, 4193, 4194, 4195, 4196 };
1457 static const uint16_t double_ops
[5] = { 0, 4197, 4198, 4199, 4200 };
1460 __GLXcontext
*gc
= __glXGetCurrentContext();
1461 __GLXattribute
* state
= (__GLXattribute
*)(gc
->client_state_private
);
1462 struct array_state_vector
* arrays
= state
->array_state
;
1463 struct array_state
* a
;
1464 unsigned true_immediate_count
;
1465 unsigned true_immediate_size
;
1468 if ( (size
< 1) || (size
> 4) || (stride
< 0)
1469 || (index
> arrays
->num_vertex_program_attribs
) ){
1470 __glXSetError(gc
, GL_INVALID_VALUE
);
1474 if ( normalized
&& (type
!= GL_FLOAT
) && (type
!= GL_DOUBLE
)) {
1476 case GL_BYTE
: opcode
= X_GLrop_VertexAttrib4NbvARB
; break;
1477 case GL_UNSIGNED_BYTE
: opcode
= X_GLrop_VertexAttrib4NubvARB
; break;
1478 case GL_SHORT
: opcode
= X_GLrop_VertexAttrib4NsvARB
; break;
1479 case GL_UNSIGNED_SHORT
: opcode
= X_GLrop_VertexAttrib4NusvARB
; break;
1480 case GL_INT
: opcode
= X_GLrop_VertexAttrib4NivARB
; break;
1481 case GL_UNSIGNED_INT
: opcode
= X_GLrop_VertexAttrib4NuivARB
; break;
1483 __glXSetError(gc
, GL_INVALID_ENUM
);
1487 true_immediate_count
= 4;
1490 true_immediate_count
= size
;
1494 opcode
= X_GLrop_VertexAttrib4bvARB
;
1495 true_immediate_count
= 4;
1497 case GL_UNSIGNED_BYTE
:
1498 opcode
= X_GLrop_VertexAttrib4ubvARB
;
1499 true_immediate_count
= 4;
1502 opcode
= short_ops
[size
];
1504 case GL_UNSIGNED_SHORT
:
1505 opcode
= X_GLrop_VertexAttrib4usvARB
;
1506 true_immediate_count
= 4;
1509 opcode
= X_GLrop_VertexAttrib4ivARB
;
1510 true_immediate_count
= 4;
1512 case GL_UNSIGNED_INT
:
1513 opcode
= X_GLrop_VertexAttrib4uivARB
;
1514 true_immediate_count
= 4;
1517 opcode
= float_ops
[size
];
1520 opcode
= double_ops
[size
];
1523 __glXSetError(gc
, GL_INVALID_ENUM
);
1528 a
= get_array_entry( arrays
, GL_VERTEX_ATTRIB_ARRAY_POINTER
, index
);
1530 __glXSetError(gc
, GL_INVALID_OPERATION
);
1534 COMMON_ARRAY_DATA_INIT( a
, pointer
, type
, stride
, size
, normalized
, 8,
1537 true_immediate_size
= __glXTypeSize(type
) * true_immediate_count
;
1538 ((uint16_t *) (a
)->header
)[0] = __GLX_PAD(a
->header_size
1539 + true_immediate_size
);
1542 arrays
->array_info_cache_valid
= GL_FALSE
;
1548 * I don't have 100% confidence that this is correct. The different rules
1549 * about whether or not generic vertex attributes alias "classic" vertex
1550 * attributes (i.e., attrib1 ?= primary color) between ARB_vertex_program,
1551 * ARB_vertex_shader, and NV_vertex_program are a bit confusing. My
1552 * feeling is that the client-side doesn't have to worry about it. The
1553 * client just sends all the data to the server and lets the server deal
1556 void __indirect_glVertexAttribPointerNV( GLuint index
, GLint size
,
1557 GLenum type
, GLsizei stride
,
1558 const GLvoid
* pointer
)
1560 __GLXcontext
*gc
= __glXGetCurrentContext();
1561 GLboolean normalized
= GL_FALSE
;
1565 case GL_UNSIGNED_BYTE
:
1567 __glXSetError(gc
, GL_INVALID_VALUE
);
1570 normalized
= GL_TRUE
;
1575 __indirect_glVertexAttribPointerARB(index
, size
, type
,
1580 __glXSetError(gc
, GL_INVALID_ENUM
);
1586 void __indirect_glClientActiveTextureARB(GLenum texture
)
1588 __GLXcontext
* const gc
= __glXGetCurrentContext();
1589 __GLXattribute
* const state
= (__GLXattribute
*)(gc
->client_state_private
);
1590 struct array_state_vector
* const arrays
= state
->array_state
;
1591 const GLint unit
= (GLint
) texture
- GL_TEXTURE0
;
1594 if ( (unit
< 0) || (unit
>= arrays
->num_texture_units
) ) {
1595 __glXSetError(gc
, GL_INVALID_ENUM
);
1599 arrays
->active_texture_unit
= unit
;
1606 __glXSetArrayEnable( __GLXattribute
* state
,
1607 GLenum key
, unsigned index
, GLboolean enable
)
1609 struct array_state_vector
* arrays
= state
->array_state
;
1610 struct array_state
* a
;
1613 if ( key
== GL_TEXTURE_COORD_ARRAY
) {
1614 index
= arrays
->active_texture_unit
;
1617 a
= get_array_entry( arrays
, key
, index
);
1619 if ( (a
!= NULL
) && (a
->enabled
!= enable
) ) {
1620 a
->enabled
= enable
;
1621 arrays
->array_info_cache_valid
= GL_FALSE
;
1629 __glXArrayDisableAll( __GLXattribute
* state
)
1631 struct array_state_vector
* arrays
= state
->array_state
;
1635 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
1636 arrays
->arrays
[i
].enabled
= GL_FALSE
;
1639 arrays
->array_info_cache_valid
= GL_FALSE
;
1646 __glXGetArrayEnable( const __GLXattribute
* const state
,
1647 GLenum key
, unsigned index
, GLintptr
* dest
)
1649 const struct array_state_vector
* arrays
= state
->array_state
;
1650 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1654 *dest
= (GLintptr
) a
->enabled
;
1664 __glXGetArrayType( const __GLXattribute
* const state
,
1665 GLenum key
, unsigned index
, GLintptr
* dest
)
1667 const struct array_state_vector
* arrays
= state
->array_state
;
1668 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1672 *dest
= (GLintptr
) a
->data_type
;
1682 __glXGetArraySize( const __GLXattribute
* const state
,
1683 GLenum key
, unsigned index
, GLintptr
* dest
)
1685 const struct array_state_vector
* arrays
= state
->array_state
;
1686 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1690 *dest
= (GLintptr
) a
->count
;
1700 __glXGetArrayStride( const __GLXattribute
* const state
,
1701 GLenum key
, unsigned index
, GLintptr
* dest
)
1703 const struct array_state_vector
* arrays
= state
->array_state
;
1704 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1708 *dest
= (GLintptr
) a
->user_stride
;
1718 __glXGetArrayPointer( const __GLXattribute
* const state
,
1719 GLenum key
, unsigned index
, void ** dest
)
1721 const struct array_state_vector
* arrays
= state
->array_state
;
1722 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1727 *dest
= (void *) (a
->data
);
1737 __glXGetArrayNormalized( const __GLXattribute
* const state
,
1738 GLenum key
, unsigned index
, GLintptr
* dest
)
1740 const struct array_state_vector
* arrays
= state
->array_state
;
1741 const struct array_state
* a
= get_array_entry( (struct array_state_vector
*) arrays
,
1746 *dest
= (GLintptr
) a
->normalized
;
1756 __glXGetActiveTextureUnit( const __GLXattribute
* const state
)
1758 return state
->array_state
->active_texture_unit
;
1763 __glXPushArrayState( __GLXattribute
* state
)
1765 struct array_state_vector
* arrays
= state
->array_state
;
1766 struct array_stack_state
* stack
= & arrays
->stack
[ (arrays
->stack_index
* arrays
->num_arrays
)];
1769 /* XXX are we pushing _all_ the necessary fields? */
1770 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
1771 stack
[i
].data
= arrays
->arrays
[i
].data
;
1772 stack
[i
].data_type
= arrays
->arrays
[i
].data_type
;
1773 stack
[i
].user_stride
= arrays
->arrays
[i
].user_stride
;
1774 stack
[i
].count
= arrays
->arrays
[i
].count
;
1775 stack
[i
].key
= arrays
->arrays
[i
].key
;
1776 stack
[i
].index
= arrays
->arrays
[i
].index
;
1777 stack
[i
].enabled
= arrays
->arrays
[i
].enabled
;
1780 arrays
->active_texture_unit_stack
[ arrays
->stack_index
] =
1781 arrays
->active_texture_unit
;
1783 arrays
->stack_index
++;
1788 __glXPopArrayState( __GLXattribute
* state
)
1790 struct array_state_vector
* arrays
= state
->array_state
;
1791 struct array_stack_state
* stack
;
1795 arrays
->stack_index
--;
1796 stack
= & arrays
->stack
[ (arrays
->stack_index
* arrays
->num_arrays
) ];
1798 for ( i
= 0 ; i
< arrays
->num_arrays
; i
++ ) {
1799 switch ( stack
[i
].key
) {
1800 case GL_NORMAL_ARRAY
:
1801 __indirect_glNormalPointer( stack
[i
].data_type
,
1802 stack
[i
].user_stride
,
1805 case GL_COLOR_ARRAY
:
1806 __indirect_glColorPointer( stack
[i
].count
,
1808 stack
[i
].user_stride
,
1811 case GL_INDEX_ARRAY
:
1812 __indirect_glIndexPointer( stack
[i
].data_type
,
1813 stack
[i
].user_stride
,
1816 case GL_EDGE_FLAG_ARRAY
:
1817 __indirect_glEdgeFlagPointer( stack
[i
].user_stride
,
1820 case GL_TEXTURE_COORD_ARRAY
:
1821 arrays
->active_texture_unit
= stack
[i
].index
;
1822 __indirect_glTexCoordPointer( stack
[i
].count
,
1824 stack
[i
].user_stride
,
1827 case GL_SECONDARY_COLOR_ARRAY
:
1828 __indirect_glSecondaryColorPointerEXT( stack
[i
].count
,
1830 stack
[i
].user_stride
,
1833 case GL_FOG_COORDINATE_ARRAY
:
1834 __indirect_glFogCoordPointerEXT( stack
[i
].data_type
,
1835 stack
[i
].user_stride
,
1841 __glXSetArrayEnable( state
, stack
[i
].key
, stack
[i
].index
,
1845 arrays
->active_texture_unit
=
1846 arrays
->active_texture_unit_stack
[ arrays
->stack_index
];