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 <ian.d.romanick@intel.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
,
80 static GLubyte
*emit_element_old(GLubyte
* dst
,
81 const struct array_state_vector
*arrays
,
83 static struct array_state
*get_array_entry(const struct array_state_vector
86 static void fill_array_info_cache(struct array_state_vector
*arrays
);
87 static GLboolean
validate_mode(struct glx_context
* gc
, GLenum mode
);
88 static GLboolean
validate_count(struct glx_context
* gc
, GLsizei count
);
89 static GLboolean
validate_type(struct glx_context
* gc
, GLenum type
);
93 * Table of sizes, in bytes, of a GL types. All of the type enums are be in
94 * the range 0x1400 - 0x140F. That includes types added by extensions (i.e.,
95 * \c GL_HALF_FLOAT_NV). This elements of this table correspond to the
96 * type enums masked with 0x0f.
99 * \c GL_HALF_FLOAT_NV is not included. Neither are \c GL_2_BYTES,
100 * \c GL_3_BYTES, or \c GL_4_BYTES.
102 const GLuint __glXTypeSize_table
[16] = {
103 1, 1, 2, 2, 4, 4, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0
108 * Free the per-context array state that was allocated with
109 * __glXInitVertexArrayState().
112 __glXFreeVertexArrayState(struct glx_context
* gc
)
114 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
115 struct array_state_vector
*arrays
= state
->array_state
;
119 arrays
->stack
= NULL
;
120 free(arrays
->arrays
);
121 arrays
->arrays
= NULL
;
123 state
->array_state
= NULL
;
129 * Initialize vertex array state of a GLX context.
131 * \param gc GLX context whose vertex array state is to be initialized.
134 * This function may only be called after struct glx_context::gl_extension_bits,
135 * struct glx_context::server_minor, and __GLXcontext::server_major have been
136 * initialized. These values are used to determine what vertex arrays are
140 __glXInitVertexArrayState(struct glx_context
* gc
)
142 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
143 struct array_state_vector
*arrays
;
145 unsigned array_count
;
146 int texture_units
= 1, vertex_program_attribs
= 0;
149 GLboolean got_fog
= GL_FALSE
;
150 GLboolean got_secondary_color
= GL_FALSE
;
153 arrays
= calloc(1, sizeof(struct array_state_vector
));
154 state
->array_state
= arrays
;
156 if (arrays
== NULL
) {
157 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
161 arrays
->old_DrawArrays_possible
= !state
->NoDrawArraysProtocol
;
162 arrays
->new_DrawArrays_possible
= GL_FALSE
;
163 arrays
->DrawArrays
= NULL
;
165 arrays
->active_texture_unit
= 0;
168 /* Determine how many arrays are actually needed. Only arrays that
169 * are supported by the server are create. For example, if the server
170 * supports only 2 texture units, then only 2 texture coordinate arrays
173 * At the very least, GL_VERTEX_ARRAY, GL_NORMAL_ARRAY,
174 * GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY, and
175 * GL_EDGE_FLAG_ARRAY are supported.
180 if (__glExtensionBitIsEnabled(gc
, GL_EXT_fog_coord_bit
)
181 || (gc
->server_major
> 1) || (gc
->server_minor
>= 4)) {
186 if (__glExtensionBitIsEnabled(gc
, GL_EXT_secondary_color_bit
)
187 || (gc
->server_major
> 1) || (gc
->server_minor
>= 4)) {
188 got_secondary_color
= GL_TRUE
;
192 if (__glExtensionBitIsEnabled(gc
, GL_ARB_multitexture_bit
)
193 || (gc
->server_major
> 1) || (gc
->server_minor
>= 3)) {
194 __indirect_glGetIntegerv(GL_MAX_TEXTURE_UNITS
, &texture_units
);
197 if (__glExtensionBitIsEnabled(gc
, GL_ARB_vertex_program_bit
)) {
198 __indirect_glGetProgramivARB(GL_VERTEX_PROGRAM_ARB
,
199 GL_MAX_PROGRAM_ATTRIBS_ARB
,
200 &vertex_program_attribs
);
203 arrays
->num_texture_units
= texture_units
;
204 arrays
->num_vertex_program_attribs
= vertex_program_attribs
;
205 array_count
+= texture_units
+ vertex_program_attribs
;
206 arrays
->num_arrays
= array_count
;
207 arrays
->arrays
= calloc(array_count
, sizeof(struct array_state
));
209 if (arrays
->arrays
== NULL
) {
210 state
->array_state
= NULL
;
212 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
216 arrays
->arrays
[0].data_type
= GL_FLOAT
;
217 arrays
->arrays
[0].count
= 3;
218 arrays
->arrays
[0].key
= GL_NORMAL_ARRAY
;
219 arrays
->arrays
[0].normalized
= GL_TRUE
;
220 arrays
->arrays
[0].old_DrawArrays_possible
= GL_TRUE
;
222 arrays
->arrays
[1].data_type
= GL_FLOAT
;
223 arrays
->arrays
[1].count
= 4;
224 arrays
->arrays
[1].key
= GL_COLOR_ARRAY
;
225 arrays
->arrays
[1].normalized
= GL_TRUE
;
226 arrays
->arrays
[1].old_DrawArrays_possible
= GL_TRUE
;
228 arrays
->arrays
[2].data_type
= GL_FLOAT
;
229 arrays
->arrays
[2].count
= 1;
230 arrays
->arrays
[2].key
= GL_INDEX_ARRAY
;
231 arrays
->arrays
[2].old_DrawArrays_possible
= GL_TRUE
;
233 arrays
->arrays
[3].data_type
= GL_UNSIGNED_BYTE
;
234 arrays
->arrays
[3].count
= 1;
235 arrays
->arrays
[3].key
= GL_EDGE_FLAG_ARRAY
;
236 arrays
->arrays
[3].old_DrawArrays_possible
= GL_TRUE
;
238 for (i
= 0; i
< texture_units
; i
++) {
239 arrays
->arrays
[4 + i
].data_type
= GL_FLOAT
;
240 arrays
->arrays
[4 + i
].count
= 4;
241 arrays
->arrays
[4 + i
].key
= GL_TEXTURE_COORD_ARRAY
;
243 arrays
->arrays
[4 + i
].old_DrawArrays_possible
= (i
== 0);
244 arrays
->arrays
[4 + i
].index
= i
;
247 i
= 4 + texture_units
;
250 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
251 arrays
->arrays
[i
].count
= 1;
252 arrays
->arrays
[i
].key
= GL_FOG_COORDINATE_ARRAY
;
253 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
257 if (got_secondary_color
) {
258 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
259 arrays
->arrays
[i
].count
= 3;
260 arrays
->arrays
[i
].key
= GL_SECONDARY_COLOR_ARRAY
;
261 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
262 arrays
->arrays
[i
].normalized
= GL_TRUE
;
267 for (j
= 0; j
< vertex_program_attribs
; j
++) {
268 const unsigned idx
= (vertex_program_attribs
- (j
+ 1));
271 arrays
->arrays
[idx
+ i
].data_type
= GL_FLOAT
;
272 arrays
->arrays
[idx
+ i
].count
= 4;
273 arrays
->arrays
[idx
+ i
].key
= GL_VERTEX_ATTRIB_ARRAY_POINTER
;
275 arrays
->arrays
[idx
+ i
].old_DrawArrays_possible
= 0;
276 arrays
->arrays
[idx
+ i
].index
= idx
;
279 i
+= vertex_program_attribs
;
282 /* Vertex array *must* be last because of the way that
283 * emit_DrawArrays_none works.
286 arrays
->arrays
[i
].data_type
= GL_FLOAT
;
287 arrays
->arrays
[i
].count
= 4;
288 arrays
->arrays
[i
].key
= GL_VERTEX_ARRAY
;
289 arrays
->arrays
[i
].old_DrawArrays_possible
= GL_TRUE
;
291 assert((i
+ 1) == arrays
->num_arrays
);
293 arrays
->stack_index
= 0;
294 arrays
->stack
= malloc(sizeof(struct array_stack_state
)
296 * __GL_CLIENT_ATTRIB_STACK_DEPTH
);
298 if (arrays
->stack
== NULL
) {
299 state
->array_state
= NULL
;
300 free(arrays
->arrays
);
302 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
309 * Calculate the size of a single vertex for the "none" protocol. This is
310 * essentially the size of all the immediate-mode commands required to
311 * implement the enabled vertex arrays.
314 calculate_single_vertex_size_none(const struct array_state_vector
*arrays
)
316 size_t single_vertex_size
= 0;
320 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
321 if (arrays
->arrays
[i
].enabled
) {
322 single_vertex_size
+= arrays
->arrays
[i
].header
[0];
326 return single_vertex_size
;
331 * Emit a single element using non-DrawArrays protocol.
334 emit_element_none(GLubyte
* dst
,
335 const struct array_state_vector
* arrays
, unsigned index
)
340 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
341 if (arrays
->arrays
[i
].enabled
) {
342 const size_t offset
= index
* arrays
->arrays
[i
].true_stride
;
344 /* The generic attributes can have more data than is in the
345 * elements. This is because a vertex array can be a 2 element,
346 * normalized, unsigned short, but the "closest" immediate mode
347 * protocol is for a 4Nus. Since the sizes are small, the
348 * performance impact on modern processors should be negligible.
350 (void) memset(dst
, 0, arrays
->arrays
[i
].header
[0]);
352 (void) memcpy(dst
, arrays
->arrays
[i
].header
, 4);
356 if (arrays
->arrays
[i
].key
== GL_TEXTURE_COORD_ARRAY
&&
357 arrays
->arrays
[i
].index
> 0) {
358 /* Multi-texture coordinate arrays require the texture target
359 * to be sent. For doubles it is after the data, for everything
362 GLenum texture
= arrays
->arrays
[i
].index
+ GL_TEXTURE0
;
363 if (arrays
->arrays
[i
].data_type
== GL_DOUBLE
) {
364 (void) memcpy(dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
365 arrays
->arrays
[i
].element_size
);
366 dst
+= arrays
->arrays
[i
].element_size
;
367 (void) memcpy(dst
, &texture
, 4);
370 (void) memcpy(dst
, &texture
, 4);
372 (void) memcpy(dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
373 arrays
->arrays
[i
].element_size
);
374 dst
+= __GLX_PAD(arrays
->arrays
[i
].element_size
);
376 } else if (arrays
->arrays
[i
].key
== GL_VERTEX_ATTRIB_ARRAY_POINTER
) {
377 /* Vertex attribute data requires the index sent first.
379 (void) memcpy(dst
, &arrays
->arrays
[i
].index
, 4);
381 (void) memcpy(dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
382 arrays
->arrays
[i
].element_size
);
383 dst
+= __GLX_PAD(arrays
->arrays
[i
].element_size
);
385 (void) memcpy(dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
386 arrays
->arrays
[i
].element_size
);
387 dst
+= __GLX_PAD(arrays
->arrays
[i
].element_size
);
397 * Emit a single element using "old" DrawArrays protocol from
398 * EXT_vertex_arrays / OpenGL 1.1.
401 emit_element_old(GLubyte
* dst
,
402 const struct array_state_vector
* arrays
, unsigned index
)
407 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
408 if (arrays
->arrays
[i
].enabled
) {
409 const size_t offset
= index
* arrays
->arrays
[i
].true_stride
;
411 (void) memcpy(dst
, ((GLubyte
*) arrays
->arrays
[i
].data
) + offset
,
412 arrays
->arrays
[i
].element_size
);
414 dst
+= __GLX_PAD(arrays
->arrays
[i
].element_size
);
423 get_array_entry(const struct array_state_vector
*arrays
,
424 GLenum key
, unsigned index
)
428 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
429 if ((arrays
->arrays
[i
].key
== key
)
430 && (arrays
->arrays
[i
].index
== index
)) {
431 return &arrays
->arrays
[i
];
440 allocate_array_info_cache(struct array_state_vector
*arrays
,
441 size_t required_size
)
443 #define MAX_HEADER_SIZE 20
444 if (arrays
->array_info_cache_buffer_size
< required_size
) {
445 GLubyte
*temp
= realloc(arrays
->array_info_cache_base
,
446 required_size
+ MAX_HEADER_SIZE
);
452 arrays
->array_info_cache_base
= temp
;
453 arrays
->array_info_cache
= temp
+ MAX_HEADER_SIZE
;
454 arrays
->array_info_cache_buffer_size
= required_size
;
457 arrays
->array_info_cache_size
= required_size
;
465 fill_array_info_cache(struct array_state_vector
*arrays
)
467 GLboolean old_DrawArrays_possible
;
471 /* Determine how many arrays are enabled.
474 arrays
->enabled_client_array_count
= 0;
475 old_DrawArrays_possible
= arrays
->old_DrawArrays_possible
;
476 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
477 if (arrays
->arrays
[i
].enabled
) {
478 arrays
->enabled_client_array_count
++;
479 old_DrawArrays_possible
&= arrays
->arrays
[i
].old_DrawArrays_possible
;
483 if (arrays
->new_DrawArrays_possible
) {
484 assert(!arrays
->new_DrawArrays_possible
);
486 else if (old_DrawArrays_possible
) {
487 const size_t required_size
= arrays
->enabled_client_array_count
* 12;
491 if (!allocate_array_info_cache(arrays
, required_size
)) {
496 info
= (uint32_t *) arrays
->array_info_cache
;
497 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
498 if (arrays
->arrays
[i
].enabled
) {
499 *(info
++) = arrays
->arrays
[i
].data_type
;
500 *(info
++) = arrays
->arrays
[i
].count
;
501 *(info
++) = arrays
->arrays
[i
].key
;
505 arrays
->DrawArrays
= emit_DrawArrays_old
;
506 arrays
->DrawElements
= emit_DrawElements_old
;
509 arrays
->DrawArrays
= emit_DrawArrays_none
;
510 arrays
->DrawElements
= emit_DrawElements_none
;
513 arrays
->array_info_cache_valid
= GL_TRUE
;
518 * Emit a \c glDrawArrays command using the "none" protocol. That is,
519 * emit immediate-mode commands that are equivalent to the requiested
520 * \c glDrawArrays command. This is used with servers that don't support
521 * the OpenGL 1.1 / EXT_vertex_arrays DrawArrays protocol or in cases where
522 * vertex state is enabled that is not compatible with that protocol.
525 emit_DrawArrays_none(GLenum mode
, GLint first
, GLsizei count
)
527 struct glx_context
*gc
= __glXGetCurrentContext();
528 const __GLXattribute
*state
=
529 (const __GLXattribute
*) (gc
->client_state_private
);
530 struct array_state_vector
*arrays
= state
->array_state
;
532 size_t single_vertex_size
;
535 static const uint16_t begin_cmd
[2] = { 8, X_GLrop_Begin
};
536 static const uint16_t end_cmd
[2] = { 4, X_GLrop_End
};
539 single_vertex_size
= calculate_single_vertex_size_none(arrays
);
543 (void) memcpy(pc
, begin_cmd
, 4);
544 *(int *) (pc
+ 4) = mode
;
548 for (i
= 0; i
< count
; i
++) {
549 if ((pc
+ single_vertex_size
) >= gc
->bufEnd
) {
550 pc
= __glXFlushRenderBuffer(gc
, pc
);
553 pc
= emit_element_none(pc
, arrays
, first
+ i
);
556 if ((pc
+ 4) >= gc
->bufEnd
) {
557 pc
= __glXFlushRenderBuffer(gc
, pc
);
560 (void) memcpy(pc
, end_cmd
, 4);
564 if (gc
->pc
> gc
->limit
) {
565 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
571 * Emit the header data for the GL 1.1 / EXT_vertex_arrays DrawArrays
574 * \param gc GLX context.
575 * \param arrays Array state.
576 * \param elements_per_request Location to store the number of elements that
577 * can fit in a single Render / RenderLarge
579 * \param total_request Total number of requests for a RenderLarge
580 * command. If a Render command is used, this
582 * \param mode Drawing mode.
583 * \param count Number of vertices.
586 * A pointer to the buffer for array data.
589 emit_DrawArrays_header_old(struct glx_context
* gc
,
590 struct array_state_vector
*arrays
,
591 size_t * elements_per_request
,
592 unsigned int *total_requests
,
593 GLenum mode
, GLsizei count
)
596 size_t single_vertex_size
;
597 const unsigned header_size
= 16;
602 /* Determine the size of the whole command. This includes the header,
603 * the ARRAY_INFO data and the array data. Once this size is calculated,
604 * it will be known whether a Render or RenderLarge command is needed.
607 single_vertex_size
= 0;
608 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
609 if (arrays
->arrays
[i
].enabled
) {
610 single_vertex_size
+= __GLX_PAD(arrays
->arrays
[i
].element_size
);
614 command_size
= arrays
->array_info_cache_size
+ header_size
615 + (single_vertex_size
* count
);
618 /* Write the header for either a Render command or a RenderLarge
619 * command. After the header is written, write the ARRAY_INFO data.
622 if (command_size
> gc
->maxSmallRenderCommandSize
) {
623 /* maxSize is the maximum amount of data can be stuffed into a single
624 * packet. sz_xGLXRenderReq is added because bufSize is the maximum
625 * packet size minus sz_xGLXRenderReq.
627 const size_t maxSize
= (gc
->bufSize
+ sz_xGLXRenderReq
)
628 - sz_xGLXRenderLargeReq
;
629 unsigned vertex_requests
;
632 /* Calculate the number of data packets that will be required to send
633 * the whole command. To do this, the number of verticies that
634 * will fit in a single buffer must be calculated.
636 * The important value here is elements_per_request. This is the
637 * number of complete array elements that will fit in a single
638 * buffer. There may be some wasted space at the end of the buffer,
639 * but splitting elements across buffer boundries would be painful.
642 elements_per_request
[0] = maxSize
/ single_vertex_size
;
644 vertex_requests
= (count
+ elements_per_request
[0] - 1)
645 / elements_per_request
[0];
647 *total_requests
= vertex_requests
+ 1;
650 __glXFlushRenderBuffer(gc
, gc
->pc
);
654 pc
= ((GLubyte
*) arrays
->array_info_cache
) - (header_size
+ 4);
655 *(uint32_t *) (pc
+ 0) = command_size
;
656 *(uint32_t *) (pc
+ 4) = X_GLrop_DrawArrays
;
657 *(uint32_t *) (pc
+ 8) = count
;
658 *(uint32_t *) (pc
+ 12) = arrays
->enabled_client_array_count
;
659 *(uint32_t *) (pc
+ 16) = mode
;
661 __glXSendLargeChunk(gc
, 1, *total_requests
, pc
,
662 header_size
+ 4 + arrays
->array_info_cache_size
);
667 if ((gc
->pc
+ command_size
) >= gc
->bufEnd
) {
668 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
672 *(uint16_t *) (pc
+ 0) = command_size
;
673 *(uint16_t *) (pc
+ 2) = X_GLrop_DrawArrays
;
674 *(uint32_t *) (pc
+ 4) = count
;
675 *(uint32_t *) (pc
+ 8) = arrays
->enabled_client_array_count
;
676 *(uint32_t *) (pc
+ 12) = mode
;
680 (void) memcpy(pc
, arrays
->array_info_cache
,
681 arrays
->array_info_cache_size
);
682 pc
+= arrays
->array_info_cache_size
;
684 *elements_per_request
= count
;
696 emit_DrawArrays_old(GLenum mode
, GLint first
, GLsizei count
)
698 struct glx_context
*gc
= __glXGetCurrentContext();
699 const __GLXattribute
*state
=
700 (const __GLXattribute
*) (gc
->client_state_private
);
701 struct array_state_vector
*arrays
= state
->array_state
;
704 size_t elements_per_request
;
705 unsigned total_requests
= 0;
707 size_t total_sent
= 0;
710 pc
= emit_DrawArrays_header_old(gc
, arrays
, &elements_per_request
,
711 &total_requests
, mode
, count
);
717 if (total_requests
== 0) {
718 assert(elements_per_request
>= count
);
720 for (i
= 0; i
< count
; i
++) {
721 pc
= emit_element_old(pc
, arrays
, i
+ first
);
724 assert(pc
<= gc
->bufEnd
);
727 if (gc
->pc
> gc
->limit
) {
728 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
735 for (req
= 2; req
<= total_requests
; req
++) {
736 if (count
< elements_per_request
) {
737 elements_per_request
= count
;
741 for (i
= 0; i
< elements_per_request
; i
++) {
742 pc
= emit_element_old(pc
, arrays
, i
+ first
);
745 first
+= elements_per_request
;
747 total_sent
+= (size_t) (pc
- gc
->pc
);
748 __glXSendLargeChunk(gc
, req
, total_requests
, gc
->pc
, pc
- gc
->pc
);
750 count
-= elements_per_request
;
757 emit_DrawElements_none(GLenum mode
, GLsizei count
, GLenum type
,
758 const GLvoid
* indices
)
760 struct glx_context
*gc
= __glXGetCurrentContext();
761 const __GLXattribute
*state
=
762 (const __GLXattribute
*) (gc
->client_state_private
);
763 struct array_state_vector
*arrays
= state
->array_state
;
764 static const uint16_t begin_cmd
[2] = { 8, X_GLrop_Begin
};
765 static const uint16_t end_cmd
[2] = { 4, X_GLrop_End
};
768 size_t single_vertex_size
;
772 single_vertex_size
= calculate_single_vertex_size_none(arrays
);
775 if ((gc
->pc
+ single_vertex_size
) >= gc
->bufEnd
) {
776 gc
->pc
= __glXFlushRenderBuffer(gc
, gc
->pc
);
781 (void) memcpy(pc
, begin_cmd
, 4);
782 *(int *) (pc
+ 4) = mode
;
786 for (i
= 0; i
< count
; i
++) {
789 if ((pc
+ single_vertex_size
) >= gc
->bufEnd
) {
790 pc
= __glXFlushRenderBuffer(gc
, pc
);
794 case GL_UNSIGNED_INT
:
795 index
= (unsigned) (((GLuint
*) indices
)[i
]);
797 case GL_UNSIGNED_SHORT
:
798 index
= (unsigned) (((GLushort
*) indices
)[i
]);
800 case GL_UNSIGNED_BYTE
:
801 index
= (unsigned) (((GLubyte
*) indices
)[i
]);
804 pc
= emit_element_none(pc
, arrays
, index
);
807 if ((pc
+ 4) >= gc
->bufEnd
) {
808 pc
= __glXFlushRenderBuffer(gc
, pc
);
811 (void) memcpy(pc
, end_cmd
, 4);
815 if (gc
->pc
> gc
->limit
) {
816 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
824 emit_DrawElements_old(GLenum mode
, GLsizei count
, GLenum type
,
825 const GLvoid
* indices
)
827 struct glx_context
*gc
= __glXGetCurrentContext();
828 const __GLXattribute
*state
=
829 (const __GLXattribute
*) (gc
->client_state_private
);
830 struct array_state_vector
*arrays
= state
->array_state
;
833 size_t elements_per_request
;
834 unsigned total_requests
= 0;
837 unsigned req_element
= 0;
840 pc
= emit_DrawArrays_header_old(gc
, arrays
, &elements_per_request
,
841 &total_requests
, mode
, count
);
849 if (count
< elements_per_request
) {
850 elements_per_request
= count
;
854 case GL_UNSIGNED_INT
:{
855 const GLuint
*ui_ptr
= (const GLuint
*) indices
+ req_element
;
857 for (i
= 0; i
< elements_per_request
; i
++) {
858 const GLint index
= (GLint
) * (ui_ptr
++);
859 pc
= emit_element_old(pc
, arrays
, index
);
863 case GL_UNSIGNED_SHORT
:{
864 const GLushort
*us_ptr
= (const GLushort
*) indices
+ req_element
;
866 for (i
= 0; i
< elements_per_request
; i
++) {
867 const GLint index
= (GLint
) * (us_ptr
++);
868 pc
= emit_element_old(pc
, arrays
, index
);
872 case GL_UNSIGNED_BYTE
:{
873 const GLubyte
*ub_ptr
= (const GLubyte
*) indices
+ req_element
;
875 for (i
= 0; i
< elements_per_request
; i
++) {
876 const GLint index
= (GLint
) * (ub_ptr
++);
877 pc
= emit_element_old(pc
, arrays
, index
);
883 if (total_requests
!= 0) {
884 __glXSendLargeChunk(gc
, req
, total_requests
, gc
->pc
, pc
- gc
->pc
);
889 count
-= elements_per_request
;
890 req_element
+= elements_per_request
;
894 assert((total_requests
== 0) || ((req
- 1) == total_requests
));
896 if (total_requests
== 0) {
897 assert(pc
<= gc
->bufEnd
);
900 if (gc
->pc
> gc
->limit
) {
901 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
908 * Validate that the \c mode parameter to \c glDrawArrays, et. al. is valid.
909 * If it is not valid, then an error code is set in the GLX context.
912 * \c GL_TRUE if the argument is valid, \c GL_FALSE if is not.
915 validate_mode(struct glx_context
* gc
, GLenum mode
)
922 case GL_TRIANGLE_STRIP
:
923 case GL_TRIANGLE_FAN
:
930 __glXSetError(gc
, GL_INVALID_ENUM
);
939 * Validate that the \c count parameter to \c glDrawArrays, et. al. is valid.
940 * A value less than zero is invalid and will result in \c GL_INVALID_VALUE
941 * being set. A value of zero will not result in an error being set, but
942 * will result in \c GL_FALSE being returned.
945 * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not.
948 validate_count(struct glx_context
* gc
, GLsizei count
)
951 __glXSetError(gc
, GL_INVALID_VALUE
);
959 * Validate that the \c type parameter to \c glDrawElements, et. al. is
960 * valid. Only \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT, and
961 * \c GL_UNSIGNED_INT are valid.
964 * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not.
967 validate_type(struct glx_context
* gc
, GLenum type
)
970 case GL_UNSIGNED_INT
:
971 case GL_UNSIGNED_SHORT
:
972 case GL_UNSIGNED_BYTE
:
975 __glXSetError(gc
, GL_INVALID_ENUM
);
982 __indirect_glDrawArrays(GLenum mode
, GLint first
, GLsizei count
)
984 struct glx_context
*gc
= __glXGetCurrentContext();
985 const __GLXattribute
*state
=
986 (const __GLXattribute
*) (gc
->client_state_private
);
987 struct array_state_vector
*arrays
= state
->array_state
;
990 if (validate_mode(gc
, mode
) && validate_count(gc
, count
)) {
991 if (!arrays
->array_info_cache_valid
) {
992 fill_array_info_cache(arrays
);
995 arrays
->DrawArrays(mode
, first
, count
);
1001 __indirect_glArrayElement(GLint index
)
1003 struct glx_context
*gc
= __glXGetCurrentContext();
1004 const __GLXattribute
*state
=
1005 (const __GLXattribute
*) (gc
->client_state_private
);
1006 struct array_state_vector
*arrays
= state
->array_state
;
1008 size_t single_vertex_size
;
1011 single_vertex_size
= calculate_single_vertex_size_none(arrays
);
1013 if ((gc
->pc
+ single_vertex_size
) >= gc
->bufEnd
) {
1014 gc
->pc
= __glXFlushRenderBuffer(gc
, gc
->pc
);
1017 gc
->pc
= emit_element_none(gc
->pc
, arrays
, index
);
1019 if (gc
->pc
> gc
->limit
) {
1020 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
1026 __indirect_glDrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1027 const GLvoid
* indices
)
1029 struct glx_context
*gc
= __glXGetCurrentContext();
1030 const __GLXattribute
*state
=
1031 (const __GLXattribute
*) (gc
->client_state_private
);
1032 struct array_state_vector
*arrays
= state
->array_state
;
1035 if (validate_mode(gc
, mode
) && validate_count(gc
, count
)
1036 && validate_type(gc
, type
)) {
1037 if (!arrays
->array_info_cache_valid
) {
1038 fill_array_info_cache(arrays
);
1041 arrays
->DrawElements(mode
, count
, type
, indices
);
1047 __indirect_glDrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1048 GLsizei count
, GLenum type
,
1049 const GLvoid
* indices
)
1051 struct glx_context
*gc
= __glXGetCurrentContext();
1052 const __GLXattribute
*state
=
1053 (const __GLXattribute
*) (gc
->client_state_private
);
1054 struct array_state_vector
*arrays
= state
->array_state
;
1057 if (validate_mode(gc
, mode
) && validate_count(gc
, count
)
1058 && validate_type(gc
, type
)) {
1060 __glXSetError(gc
, GL_INVALID_VALUE
);
1064 if (!arrays
->array_info_cache_valid
) {
1065 fill_array_info_cache(arrays
);
1068 arrays
->DrawElements(mode
, count
, type
, indices
);
1074 __indirect_glMultiDrawArrays(GLenum mode
, const GLint
*first
,
1075 const GLsizei
*count
, GLsizei primcount
)
1077 struct glx_context
*gc
= __glXGetCurrentContext();
1078 const __GLXattribute
*state
=
1079 (const __GLXattribute
*) (gc
->client_state_private
);
1080 struct array_state_vector
*arrays
= state
->array_state
;
1084 if (validate_mode(gc
, mode
)) {
1085 if (!arrays
->array_info_cache_valid
) {
1086 fill_array_info_cache(arrays
);
1089 for (i
= 0; i
< primcount
; i
++) {
1090 if (validate_count(gc
, count
[i
])) {
1091 arrays
->DrawArrays(mode
, first
[i
], count
[i
]);
1099 __indirect_glMultiDrawElementsEXT(GLenum mode
, const GLsizei
* count
,
1100 GLenum type
, const GLvoid
* const * indices
,
1103 struct glx_context
*gc
= __glXGetCurrentContext();
1104 const __GLXattribute
*state
=
1105 (const __GLXattribute
*) (gc
->client_state_private
);
1106 struct array_state_vector
*arrays
= state
->array_state
;
1110 if (validate_mode(gc
, mode
) && validate_type(gc
, type
)) {
1111 if (!arrays
->array_info_cache_valid
) {
1112 fill_array_info_cache(arrays
);
1115 for (i
= 0; i
< primcount
; i
++) {
1116 if (validate_count(gc
, count
[i
])) {
1117 arrays
->DrawElements(mode
, count
[i
], type
, indices
[i
]);
1124 /* The HDR_SIZE macro argument is the command header size (4 bytes)
1125 * plus any additional index word e.g. for texture units or vertex
1128 #define COMMON_ARRAY_DATA_INIT(a, PTR, TYPE, STRIDE, COUNT, NORMALIZED, HDR_SIZE, OPCODE) \
1131 (a)->data_type = TYPE; \
1132 (a)->user_stride = STRIDE; \
1133 (a)->count = COUNT; \
1134 (a)->normalized = NORMALIZED; \
1136 (a)->element_size = __glXTypeSize( TYPE ) * COUNT; \
1137 (a)->true_stride = (STRIDE == 0) \
1138 ? (a)->element_size : STRIDE; \
1140 (a)->header[0] = __GLX_PAD(HDR_SIZE + (a)->element_size); \
1141 (a)->header[1] = OPCODE; \
1146 __indirect_glVertexPointer(GLint size
, GLenum type
, GLsizei stride
,
1147 const GLvoid
* pointer
)
1149 static const uint16_t short_ops
[5] = {
1150 0, 0, X_GLrop_Vertex2sv
, X_GLrop_Vertex3sv
, X_GLrop_Vertex4sv
1152 static const uint16_t int_ops
[5] = {
1153 0, 0, X_GLrop_Vertex2iv
, X_GLrop_Vertex3iv
, X_GLrop_Vertex4iv
1155 static const uint16_t float_ops
[5] = {
1156 0, 0, X_GLrop_Vertex2fv
, X_GLrop_Vertex3fv
, X_GLrop_Vertex4fv
1158 static const uint16_t double_ops
[5] = {
1159 0, 0, X_GLrop_Vertex2dv
, X_GLrop_Vertex3dv
, X_GLrop_Vertex4dv
1162 struct glx_context
*gc
= __glXGetCurrentContext();
1163 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1164 struct array_state_vector
*arrays
= state
->array_state
;
1165 struct array_state
*a
;
1168 if (size
< 2 || size
> 4 || stride
< 0) {
1169 __glXSetError(gc
, GL_INVALID_VALUE
);
1175 opcode
= short_ops
[size
];
1178 opcode
= int_ops
[size
];
1181 opcode
= float_ops
[size
];
1184 opcode
= double_ops
[size
];
1187 __glXSetError(gc
, GL_INVALID_ENUM
);
1191 a
= get_array_entry(arrays
, GL_VERTEX_ARRAY
, 0);
1193 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, size
, GL_FALSE
, 4,
1197 arrays
->array_info_cache_valid
= GL_FALSE
;
1203 __indirect_glNormalPointer(GLenum type
, GLsizei stride
,
1204 const GLvoid
* pointer
)
1207 struct glx_context
*gc
= __glXGetCurrentContext();
1208 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1209 struct array_state_vector
*arrays
= state
->array_state
;
1210 struct array_state
*a
;
1214 __glXSetError(gc
, GL_INVALID_VALUE
);
1220 opcode
= X_GLrop_Normal3bv
;
1223 opcode
= X_GLrop_Normal3sv
;
1226 opcode
= X_GLrop_Normal3iv
;
1229 opcode
= X_GLrop_Normal3fv
;
1232 opcode
= X_GLrop_Normal3dv
;
1235 __glXSetError(gc
, GL_INVALID_ENUM
);
1239 a
= get_array_entry(arrays
, GL_NORMAL_ARRAY
, 0);
1241 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, 3, GL_TRUE
, 4, opcode
);
1244 arrays
->array_info_cache_valid
= GL_FALSE
;
1250 __indirect_glColorPointer(GLint size
, GLenum type
, GLsizei stride
,
1251 const GLvoid
* pointer
)
1253 static const uint16_t byte_ops
[5] = {
1254 0, 0, 0, X_GLrop_Color3bv
, X_GLrop_Color4bv
1256 static const uint16_t ubyte_ops
[5] = {
1257 0, 0, 0, X_GLrop_Color3ubv
, X_GLrop_Color4ubv
1259 static const uint16_t short_ops
[5] = {
1260 0, 0, 0, X_GLrop_Color3sv
, X_GLrop_Color4sv
1262 static const uint16_t ushort_ops
[5] = {
1263 0, 0, 0, X_GLrop_Color3usv
, X_GLrop_Color4usv
1265 static const uint16_t int_ops
[5] = {
1266 0, 0, 0, X_GLrop_Color3iv
, X_GLrop_Color4iv
1268 static const uint16_t uint_ops
[5] = {
1269 0, 0, 0, X_GLrop_Color3uiv
, X_GLrop_Color4uiv
1271 static const uint16_t float_ops
[5] = {
1272 0, 0, 0, X_GLrop_Color3fv
, X_GLrop_Color4fv
1274 static const uint16_t double_ops
[5] = {
1275 0, 0, 0, X_GLrop_Color3dv
, X_GLrop_Color4dv
1278 struct glx_context
*gc
= __glXGetCurrentContext();
1279 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1280 struct array_state_vector
*arrays
= state
->array_state
;
1281 struct array_state
*a
;
1284 if (size
< 3 || size
> 4 || stride
< 0) {
1285 __glXSetError(gc
, GL_INVALID_VALUE
);
1291 opcode
= byte_ops
[size
];
1293 case GL_UNSIGNED_BYTE
:
1294 opcode
= ubyte_ops
[size
];
1297 opcode
= short_ops
[size
];
1299 case GL_UNSIGNED_SHORT
:
1300 opcode
= ushort_ops
[size
];
1303 opcode
= int_ops
[size
];
1305 case GL_UNSIGNED_INT
:
1306 opcode
= uint_ops
[size
];
1309 opcode
= float_ops
[size
];
1312 opcode
= double_ops
[size
];
1315 __glXSetError(gc
, GL_INVALID_ENUM
);
1319 a
= get_array_entry(arrays
, GL_COLOR_ARRAY
, 0);
1321 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, size
, GL_TRUE
, 4, opcode
);
1324 arrays
->array_info_cache_valid
= GL_FALSE
;
1330 __indirect_glIndexPointer(GLenum type
, GLsizei stride
, const GLvoid
* pointer
)
1333 struct glx_context
*gc
= __glXGetCurrentContext();
1334 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1335 struct array_state_vector
*arrays
= state
->array_state
;
1336 struct array_state
*a
;
1340 __glXSetError(gc
, GL_INVALID_VALUE
);
1345 case GL_UNSIGNED_BYTE
:
1346 opcode
= X_GLrop_Indexubv
;
1349 opcode
= X_GLrop_Indexsv
;
1352 opcode
= X_GLrop_Indexiv
;
1355 opcode
= X_GLrop_Indexfv
;
1358 opcode
= X_GLrop_Indexdv
;
1361 __glXSetError(gc
, GL_INVALID_ENUM
);
1365 a
= get_array_entry(arrays
, GL_INDEX_ARRAY
, 0);
1367 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, 1, GL_FALSE
, 4, opcode
);
1370 arrays
->array_info_cache_valid
= GL_FALSE
;
1376 __indirect_glEdgeFlagPointer(GLsizei stride
, const GLvoid
* pointer
)
1378 struct glx_context
*gc
= __glXGetCurrentContext();
1379 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1380 struct array_state_vector
*arrays
= state
->array_state
;
1381 struct array_state
*a
;
1385 __glXSetError(gc
, GL_INVALID_VALUE
);
1390 a
= get_array_entry(arrays
, GL_EDGE_FLAG_ARRAY
, 0);
1392 COMMON_ARRAY_DATA_INIT(a
, pointer
, GL_UNSIGNED_BYTE
, stride
, 1, GL_FALSE
,
1393 4, X_GLrop_EdgeFlagv
);
1396 arrays
->array_info_cache_valid
= GL_FALSE
;
1402 __indirect_glTexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1403 const GLvoid
* pointer
)
1405 static const uint16_t short_ops
[5] = {
1406 0, X_GLrop_TexCoord1sv
, X_GLrop_TexCoord2sv
, X_GLrop_TexCoord3sv
,
1409 static const uint16_t int_ops
[5] = {
1410 0, X_GLrop_TexCoord1iv
, X_GLrop_TexCoord2iv
, X_GLrop_TexCoord3iv
,
1413 static const uint16_t float_ops
[5] = {
1414 0, X_GLrop_TexCoord1fv
, X_GLrop_TexCoord2fv
, X_GLrop_TexCoord3fv
,
1417 static const uint16_t double_ops
[5] = {
1418 0, X_GLrop_TexCoord1dv
, X_GLrop_TexCoord2dv
, X_GLrop_TexCoord3dv
,
1422 static const uint16_t mshort_ops
[5] = {
1423 0, X_GLrop_MultiTexCoord1svARB
, X_GLrop_MultiTexCoord2svARB
,
1424 X_GLrop_MultiTexCoord3svARB
, X_GLrop_MultiTexCoord4svARB
1426 static const uint16_t mint_ops
[5] = {
1427 0, X_GLrop_MultiTexCoord1ivARB
, X_GLrop_MultiTexCoord2ivARB
,
1428 X_GLrop_MultiTexCoord3ivARB
, X_GLrop_MultiTexCoord4ivARB
1430 static const uint16_t mfloat_ops
[5] = {
1431 0, X_GLrop_MultiTexCoord1fvARB
, X_GLrop_MultiTexCoord2fvARB
,
1432 X_GLrop_MultiTexCoord3fvARB
, X_GLrop_MultiTexCoord4fvARB
1434 static const uint16_t mdouble_ops
[5] = {
1435 0, X_GLrop_MultiTexCoord1dvARB
, X_GLrop_MultiTexCoord2dvARB
,
1436 X_GLrop_MultiTexCoord3dvARB
, X_GLrop_MultiTexCoord4dvARB
1440 struct glx_context
*gc
= __glXGetCurrentContext();
1441 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1442 struct array_state_vector
*arrays
= state
->array_state
;
1443 struct array_state
*a
;
1444 unsigned header_size
;
1448 if (size
< 1 || size
> 4 || stride
< 0) {
1449 __glXSetError(gc
, GL_INVALID_VALUE
);
1453 index
= arrays
->active_texture_unit
;
1457 opcode
= short_ops
[size
];
1460 opcode
= int_ops
[size
];
1463 opcode
= float_ops
[size
];
1466 opcode
= double_ops
[size
];
1469 __glXSetError(gc
, GL_INVALID_ENUM
);
1478 opcode
= mshort_ops
[size
];
1481 opcode
= mint_ops
[size
];
1484 opcode
= mfloat_ops
[size
];
1487 opcode
= mdouble_ops
[size
];
1490 __glXSetError(gc
, GL_INVALID_ENUM
);
1497 a
= get_array_entry(arrays
, GL_TEXTURE_COORD_ARRAY
, index
);
1499 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, size
, GL_FALSE
,
1500 header_size
, opcode
);
1503 arrays
->array_info_cache_valid
= GL_FALSE
;
1509 __indirect_glSecondaryColorPointer(GLint size
, GLenum type
, GLsizei stride
,
1510 const GLvoid
* pointer
)
1513 struct glx_context
*gc
= __glXGetCurrentContext();
1514 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1515 struct array_state_vector
*arrays
= state
->array_state
;
1516 struct array_state
*a
;
1519 if (size
!= 3 || stride
< 0) {
1520 __glXSetError(gc
, GL_INVALID_VALUE
);
1528 case GL_UNSIGNED_BYTE
:
1534 case GL_UNSIGNED_SHORT
:
1540 case GL_UNSIGNED_INT
:
1550 __glXSetError(gc
, GL_INVALID_ENUM
);
1554 a
= get_array_entry(arrays
, GL_SECONDARY_COLOR_ARRAY
, 0);
1556 __glXSetError(gc
, GL_INVALID_OPERATION
);
1560 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, size
, GL_TRUE
, 4, opcode
);
1563 arrays
->array_info_cache_valid
= GL_FALSE
;
1569 __indirect_glFogCoordPointer(GLenum type
, GLsizei stride
,
1570 const GLvoid
* pointer
)
1573 struct glx_context
*gc
= __glXGetCurrentContext();
1574 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1575 struct array_state_vector
*arrays
= state
->array_state
;
1576 struct array_state
*a
;
1580 __glXSetError(gc
, GL_INVALID_VALUE
);
1592 __glXSetError(gc
, GL_INVALID_ENUM
);
1596 a
= get_array_entry(arrays
, GL_FOG_COORD_ARRAY
, 0);
1598 __glXSetError(gc
, GL_INVALID_OPERATION
);
1602 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, 1, GL_FALSE
, 4, opcode
);
1605 arrays
->array_info_cache_valid
= GL_FALSE
;
1611 __indirect_glVertexAttribPointer(GLuint index
, GLint size
,
1612 GLenum type
, GLboolean normalized
,
1613 GLsizei stride
, const GLvoid
* pointer
)
1615 static const uint16_t short_ops
[5] = {
1616 0, X_GLrop_VertexAttrib1svARB
, X_GLrop_VertexAttrib2svARB
,
1617 X_GLrop_VertexAttrib3svARB
, X_GLrop_VertexAttrib4svARB
1619 static const uint16_t float_ops
[5] = {
1620 0, X_GLrop_VertexAttrib1fvARB
, X_GLrop_VertexAttrib2fvARB
,
1621 X_GLrop_VertexAttrib3fvARB
, X_GLrop_VertexAttrib4fvARB
1623 static const uint16_t double_ops
[5] = {
1624 0, X_GLrop_VertexAttrib1dvARB
, X_GLrop_VertexAttrib2dvARB
,
1625 X_GLrop_VertexAttrib3dvARB
, X_GLrop_VertexAttrib4dvARB
1629 struct glx_context
*gc
= __glXGetCurrentContext();
1630 __GLXattribute
*state
= (__GLXattribute
*) (gc
->client_state_private
);
1631 struct array_state_vector
*arrays
= state
->array_state
;
1632 struct array_state
*a
;
1633 unsigned true_immediate_count
;
1634 unsigned true_immediate_size
;
1637 if ((size
< 1) || (size
> 4) || (stride
< 0)
1638 || (index
> arrays
->num_vertex_program_attribs
)) {
1639 __glXSetError(gc
, GL_INVALID_VALUE
);
1643 if (normalized
&& (type
!= GL_FLOAT
) && (type
!= GL_DOUBLE
)) {
1646 opcode
= X_GLrop_VertexAttrib4NbvARB
;
1648 case GL_UNSIGNED_BYTE
:
1649 opcode
= X_GLrop_VertexAttrib4NubvARB
;
1652 opcode
= X_GLrop_VertexAttrib4NsvARB
;
1654 case GL_UNSIGNED_SHORT
:
1655 opcode
= X_GLrop_VertexAttrib4NusvARB
;
1658 opcode
= X_GLrop_VertexAttrib4NivARB
;
1660 case GL_UNSIGNED_INT
:
1661 opcode
= X_GLrop_VertexAttrib4NuivARB
;
1664 __glXSetError(gc
, GL_INVALID_ENUM
);
1668 true_immediate_count
= 4;
1671 true_immediate_count
= size
;
1675 opcode
= X_GLrop_VertexAttrib4bvARB
;
1676 true_immediate_count
= 4;
1678 case GL_UNSIGNED_BYTE
:
1679 opcode
= X_GLrop_VertexAttrib4ubvARB
;
1680 true_immediate_count
= 4;
1683 opcode
= short_ops
[size
];
1685 case GL_UNSIGNED_SHORT
:
1686 opcode
= X_GLrop_VertexAttrib4usvARB
;
1687 true_immediate_count
= 4;
1690 opcode
= X_GLrop_VertexAttrib4ivARB
;
1691 true_immediate_count
= 4;
1693 case GL_UNSIGNED_INT
:
1694 opcode
= X_GLrop_VertexAttrib4uivARB
;
1695 true_immediate_count
= 4;
1698 opcode
= float_ops
[size
];
1701 opcode
= double_ops
[size
];
1704 __glXSetError(gc
, GL_INVALID_ENUM
);
1709 a
= get_array_entry(arrays
, GL_VERTEX_ATTRIB_ARRAY_POINTER
, index
);
1711 __glXSetError(gc
, GL_INVALID_OPERATION
);
1715 COMMON_ARRAY_DATA_INIT(a
, pointer
, type
, stride
, size
, normalized
, 8,
1718 true_immediate_size
= __glXTypeSize(type
) * true_immediate_count
;
1719 a
->header
[0] = __GLX_PAD(8 + true_immediate_size
);
1722 arrays
->array_info_cache_valid
= GL_FALSE
;
1728 * I don't have 100% confidence that this is correct. The different rules
1729 * about whether or not generic vertex attributes alias "classic" vertex
1730 * attributes (i.e., attrib1 ?= primary color) between ARB_vertex_program,
1731 * ARB_vertex_shader, and NV_vertex_program are a bit confusing. My
1732 * feeling is that the client-side doesn't have to worry about it. The
1733 * client just sends all the data to the server and lets the server deal
1737 __indirect_glVertexAttribPointerNV(GLuint index
, GLint size
,
1738 GLenum type
, GLsizei stride
,
1739 const GLvoid
* pointer
)
1741 struct glx_context
*gc
= __glXGetCurrentContext();
1742 GLboolean normalized
= GL_FALSE
;
1746 case GL_UNSIGNED_BYTE
:
1748 __glXSetError(gc
, GL_INVALID_VALUE
);
1751 normalized
= GL_TRUE
;
1756 __indirect_glVertexAttribPointer(index
, size
, type
,
1757 normalized
, stride
, pointer
);
1760 __glXSetError(gc
, GL_INVALID_ENUM
);
1767 __indirect_glClientActiveTexture(GLenum texture
)
1769 struct glx_context
*const gc
= __glXGetCurrentContext();
1770 __GLXattribute
*const state
=
1771 (__GLXattribute
*) (gc
->client_state_private
);
1772 struct array_state_vector
*const arrays
= state
->array_state
;
1773 const GLint unit
= (GLint
) texture
- GL_TEXTURE0
;
1776 if ((unit
< 0) || (unit
>= arrays
->num_texture_units
)) {
1777 __glXSetError(gc
, GL_INVALID_ENUM
);
1781 arrays
->active_texture_unit
= unit
;
1786 * Modify the enable state for the selected array
1789 __glXSetArrayEnable(__GLXattribute
* state
, GLenum key
, unsigned index
,
1792 struct array_state_vector
*arrays
= state
->array_state
;
1793 struct array_state
*a
;
1796 /* Texture coordinate arrays have an implict index set when the
1797 * application calls glClientActiveTexture.
1799 if (key
== GL_TEXTURE_COORD_ARRAY
) {
1800 index
= arrays
->active_texture_unit
;
1803 a
= get_array_entry(arrays
, key
, index
);
1805 if ((a
!= NULL
) && (a
->enabled
!= enable
)) {
1806 a
->enabled
= enable
;
1807 arrays
->array_info_cache_valid
= GL_FALSE
;
1815 __glXArrayDisableAll(__GLXattribute
* state
)
1817 struct array_state_vector
*arrays
= state
->array_state
;
1821 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
1822 arrays
->arrays
[i
].enabled
= GL_FALSE
;
1825 arrays
->array_info_cache_valid
= GL_FALSE
;
1832 __glXGetArrayEnable(const __GLXattribute
* const state
,
1833 GLenum key
, unsigned index
, GLintptr
* dest
)
1835 const struct array_state_vector
*arrays
= state
->array_state
;
1836 const struct array_state
*a
=
1837 get_array_entry((struct array_state_vector
*) arrays
,
1841 *dest
= (GLintptr
) a
->enabled
;
1851 __glXGetArrayType(const __GLXattribute
* const state
,
1852 GLenum key
, unsigned index
, GLintptr
* dest
)
1854 const struct array_state_vector
*arrays
= state
->array_state
;
1855 const struct array_state
*a
=
1856 get_array_entry((struct array_state_vector
*) arrays
,
1860 *dest
= (GLintptr
) a
->data_type
;
1870 __glXGetArraySize(const __GLXattribute
* const state
,
1871 GLenum key
, unsigned index
, GLintptr
* dest
)
1873 const struct array_state_vector
*arrays
= state
->array_state
;
1874 const struct array_state
*a
=
1875 get_array_entry((struct array_state_vector
*) arrays
,
1879 *dest
= (GLintptr
) a
->count
;
1889 __glXGetArrayStride(const __GLXattribute
* const state
,
1890 GLenum key
, unsigned index
, GLintptr
* dest
)
1892 const struct array_state_vector
*arrays
= state
->array_state
;
1893 const struct array_state
*a
=
1894 get_array_entry((struct array_state_vector
*) arrays
,
1898 *dest
= (GLintptr
) a
->user_stride
;
1908 __glXGetArrayPointer(const __GLXattribute
* const state
,
1909 GLenum key
, unsigned index
, void **dest
)
1911 const struct array_state_vector
*arrays
= state
->array_state
;
1912 const struct array_state
*a
=
1913 get_array_entry((struct array_state_vector
*) arrays
,
1918 *dest
= (void *) (a
->data
);
1928 __glXGetArrayNormalized(const __GLXattribute
* const state
,
1929 GLenum key
, unsigned index
, GLintptr
* dest
)
1931 const struct array_state_vector
*arrays
= state
->array_state
;
1932 const struct array_state
*a
=
1933 get_array_entry((struct array_state_vector
*) arrays
,
1938 *dest
= (GLintptr
) a
->normalized
;
1948 __glXGetActiveTextureUnit(const __GLXattribute
* const state
)
1950 return state
->array_state
->active_texture_unit
;
1955 __glXPushArrayState(__GLXattribute
* state
)
1957 struct array_state_vector
*arrays
= state
->array_state
;
1958 struct array_stack_state
*stack
=
1959 &arrays
->stack
[(arrays
->stack_index
* arrays
->num_arrays
)];
1962 /* XXX are we pushing _all_ the necessary fields? */
1963 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
1964 stack
[i
].data
= arrays
->arrays
[i
].data
;
1965 stack
[i
].data_type
= arrays
->arrays
[i
].data_type
;
1966 stack
[i
].user_stride
= arrays
->arrays
[i
].user_stride
;
1967 stack
[i
].count
= arrays
->arrays
[i
].count
;
1968 stack
[i
].key
= arrays
->arrays
[i
].key
;
1969 stack
[i
].index
= arrays
->arrays
[i
].index
;
1970 stack
[i
].enabled
= arrays
->arrays
[i
].enabled
;
1973 arrays
->active_texture_unit_stack
[arrays
->stack_index
] =
1974 arrays
->active_texture_unit
;
1976 arrays
->stack_index
++;
1981 __glXPopArrayState(__GLXattribute
* state
)
1983 struct array_state_vector
*arrays
= state
->array_state
;
1984 struct array_stack_state
*stack
;
1988 arrays
->stack_index
--;
1989 stack
= &arrays
->stack
[(arrays
->stack_index
* arrays
->num_arrays
)];
1991 for (i
= 0; i
< arrays
->num_arrays
; i
++) {
1992 switch (stack
[i
].key
) {
1993 case GL_NORMAL_ARRAY
:
1994 __indirect_glNormalPointer(stack
[i
].data_type
,
1995 stack
[i
].user_stride
, stack
[i
].data
);
1997 case GL_COLOR_ARRAY
:
1998 __indirect_glColorPointer(stack
[i
].count
,
2000 stack
[i
].user_stride
, stack
[i
].data
);
2002 case GL_INDEX_ARRAY
:
2003 __indirect_glIndexPointer(stack
[i
].data_type
,
2004 stack
[i
].user_stride
, stack
[i
].data
);
2006 case GL_EDGE_FLAG_ARRAY
:
2007 __indirect_glEdgeFlagPointer(stack
[i
].user_stride
, stack
[i
].data
);
2009 case GL_TEXTURE_COORD_ARRAY
:
2010 arrays
->active_texture_unit
= stack
[i
].index
;
2011 __indirect_glTexCoordPointer(stack
[i
].count
,
2013 stack
[i
].user_stride
, stack
[i
].data
);
2015 case GL_SECONDARY_COLOR_ARRAY
:
2016 __indirect_glSecondaryColorPointer(stack
[i
].count
,
2018 stack
[i
].user_stride
,
2021 case GL_FOG_COORDINATE_ARRAY
:
2022 __indirect_glFogCoordPointer(stack
[i
].data_type
,
2023 stack
[i
].user_stride
, stack
[i
].data
);
2028 __glXSetArrayEnable(state
, stack
[i
].key
, stack
[i
].index
,
2032 arrays
->active_texture_unit
=
2033 arrays
->active_texture_unit_stack
[arrays
->stack_index
];