2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "bufferobj.h"
39 #include "main/dispatch.h"
42 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 /** Used to indicate which GL datatypes are accepted by each of the
47 * glVertex/Color/Attrib/EtcPointer() functions.
51 #define UNSIGNED_BYTE_BIT 0x4
53 #define UNSIGNED_SHORT_BIT 0x10
55 #define UNSIGNED_INT_BIT 0x40
57 #define FLOAT_BIT 0x100
58 #define DOUBLE_BIT 0x200
59 #define FIXED_BIT 0x400
63 /** Convert GL datatype enum into a <type>_BIT value seen above */
65 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
72 case GL_UNSIGNED_BYTE
:
73 return UNSIGNED_BYTE_BIT
;
76 case GL_UNSIGNED_SHORT
:
77 return UNSIGNED_SHORT_BIT
;
81 return UNSIGNED_INT_BIT
;
83 if (ctx
->Extensions
.ARB_half_float_vertex
)
100 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
103 * \param func name of calling function used for error reporting
104 * \param array the array to update
105 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
106 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
107 * \param sizeMin min allowable size value
108 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
109 * \param size components per element (1, 2, 3 or 4)
110 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
111 * \param stride stride between elements, in elements
112 * \param normalized are integer types converted to floats in [-1, 1]?
113 * \param integer integer-valued values (will not be normalized to [-1,1])
114 * \param ptr the address (or offset inside VBO) of the array data
117 update_array(struct gl_context
*ctx
,
119 struct gl_client_array
*array
,
120 GLbitfield dirtyBit
, GLbitfield legalTypesMask
,
121 GLint sizeMin
, GLint sizeMax
,
122 GLint size
, GLenum type
, GLsizei stride
,
123 GLboolean normalized
, GLboolean integer
,
128 GLenum format
= GL_RGBA
;
130 if (ctx
->API
!= API_OPENGLES
) {
131 /* fixed point arrays / data is only allowed with OpenGL ES 1.x */
132 legalTypesMask
&= ~FIXED_BIT
;
135 typeBit
= type_to_bit(ctx
, type
);
136 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
137 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
138 func
, _mesa_lookup_enum_by_nr(type
));
142 /* Do size parameter checking.
143 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
144 * must be handled specially.
146 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
147 sizeMax
== BGRA_OR_4
&&
149 if (type
!= GL_UNSIGNED_BYTE
) {
150 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(GL_BGRA/GLubyte)", func
);
156 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
157 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
164 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
168 if (ctx
->Array
.ArrayObj
->VBOonly
&&
169 ctx
->Array
.ArrayBufferObj
->Name
== 0) {
170 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
171 * Generate GL_INVALID_OPERATION if that's not true.
173 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
177 elementSize
= _mesa_sizeof_type(type
) * size
;
181 array
->Format
= format
;
182 array
->Stride
= stride
;
183 array
->StrideB
= stride
? stride
: elementSize
;
184 array
->Normalized
= normalized
;
185 array
->Ptr
= (const GLubyte
*) ptr
;
186 array
->_ElementSize
= elementSize
;
188 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
189 ctx
->Array
.ArrayBufferObj
);
191 ctx
->NewState
|= _NEW_ARRAY
;
192 ctx
->Array
.NewState
|= dirtyBit
;
197 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
199 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
200 DOUBLE_BIT
| HALF_BIT
| FIXED_BIT
);
201 GET_CURRENT_CONTEXT(ctx
);
202 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
204 if (ctx
->API
== API_OPENGLES
)
205 legalTypes
|= BYTE_BIT
;
207 update_array(ctx
, "glVertexPointer",
208 &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
210 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
215 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
217 const GLbitfield legalTypes
= (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
218 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
220 GET_CURRENT_CONTEXT(ctx
);
221 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
223 update_array(ctx
, "glNormalPointer",
224 &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
226 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
231 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
233 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
234 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
235 INT_BIT
| UNSIGNED_INT_BIT
|
236 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
238 GET_CURRENT_CONTEXT(ctx
);
239 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
241 update_array(ctx
, "glColorPointer",
242 &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
243 legalTypes
, 3, BGRA_OR_4
,
244 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
249 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
251 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
252 GET_CURRENT_CONTEXT(ctx
);
253 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
255 update_array(ctx
, "glFogCoordPointer",
256 &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
258 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
263 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
265 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
266 FLOAT_BIT
| DOUBLE_BIT
);
267 GET_CURRENT_CONTEXT(ctx
);
268 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
270 update_array(ctx
, "glIndexPointer",
271 &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
273 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
278 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
279 GLsizei stride
, const GLvoid
*ptr
)
281 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
282 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
283 INT_BIT
| UNSIGNED_INT_BIT
|
284 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
285 GET_CURRENT_CONTEXT(ctx
);
286 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
288 update_array(ctx
, "glSecondaryColorPointer",
289 &ctx
->Array
.ArrayObj
->SecondaryColor
, _NEW_ARRAY_COLOR1
,
290 legalTypes
, 3, BGRA_OR_4
,
291 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
296 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
299 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
300 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
301 GET_CURRENT_CONTEXT(ctx
);
302 const GLuint unit
= ctx
->Array
.ActiveTexture
;
303 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
305 if (ctx
->API
== API_OPENGLES
)
306 legalTypes
|= BYTE_BIT
;
308 ASSERT(unit
< Elements(ctx
->Array
.ArrayObj
->TexCoord
));
310 update_array(ctx
, "glTexCoordPointer",
311 &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
312 _NEW_ARRAY_TEXCOORD(unit
),
314 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
320 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
322 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
323 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
324 const GLboolean integer
= GL_TRUE
;
325 GET_CURRENT_CONTEXT(ctx
);
326 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
328 update_array(ctx
, "glEdgeFlagPointer",
329 &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
331 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
336 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
338 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_BIT
);
339 GET_CURRENT_CONTEXT(ctx
);
340 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
342 if (ctx
->API
!= API_OPENGLES
) {
343 _mesa_error(ctx
, GL_INVALID_OPERATION
,
344 "glPointSizePointer(ES 1.x only)");
348 update_array(ctx
, "glPointSizePointer",
349 &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
351 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
355 #if FEATURE_NV_vertex_program
357 * Set a vertex attribute array.
358 * Note that these arrays DO alias the conventional GL vertex arrays
359 * (position, normal, color, fog, texcoord, etc).
360 * The generic attribute slots at #16 and above are not touched.
363 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
364 GLsizei stride
, const GLvoid
*ptr
)
366 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
367 FLOAT_BIT
| DOUBLE_BIT
);
368 GLboolean normalized
= GL_FALSE
;
369 GET_CURRENT_CONTEXT(ctx
);
370 ASSERT_OUTSIDE_BEGIN_END(ctx
);
372 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
373 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
377 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
382 update_array(ctx
, "glVertexAttribPointerNV",
383 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
384 _NEW_ARRAY_ATTRIB(index
),
385 legalTypes
, 1, BGRA_OR_4
,
386 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
391 #if FEATURE_ARB_vertex_program
393 * Set a generic vertex attribute array.
394 * Note that these arrays DO NOT alias the conventional GL vertex arrays
395 * (position, normal, color, fog, texcoord, etc).
398 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
399 GLboolean normalized
,
400 GLsizei stride
, const GLvoid
*ptr
)
402 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
403 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
404 INT_BIT
| UNSIGNED_INT_BIT
|
405 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
407 GET_CURRENT_CONTEXT(ctx
);
408 ASSERT_OUTSIDE_BEGIN_END(ctx
);
410 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
411 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
415 update_array(ctx
, "glVertexAttribPointer",
416 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
417 _NEW_ARRAY_ATTRIB(index
),
418 legalTypes
, 1, BGRA_OR_4
,
419 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
425 * GL_EXT_gpu_shader4 / GL 3.0.
426 * Set an integer-valued vertex attribute array.
427 * Note that these arrays DO NOT alias the conventional GL vertex arrays
428 * (position, normal, color, fog, texcoord, etc).
431 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
432 GLsizei stride
, const GLvoid
*ptr
)
434 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
435 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
436 INT_BIT
| UNSIGNED_INT_BIT
);
437 const GLboolean normalized
= GL_FALSE
;
438 const GLboolean integer
= GL_TRUE
;
439 GET_CURRENT_CONTEXT(ctx
);
440 ASSERT_OUTSIDE_BEGIN_END(ctx
);
442 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
443 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
447 update_array(ctx
, "glVertexAttribIPointer",
448 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
449 _NEW_ARRAY_ATTRIB(index
),
451 size
, type
, stride
, normalized
, integer
, ptr
);
457 _mesa_EnableVertexAttribArrayARB(GLuint index
)
459 GET_CURRENT_CONTEXT(ctx
);
460 ASSERT_OUTSIDE_BEGIN_END(ctx
);
462 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
463 _mesa_error(ctx
, GL_INVALID_VALUE
,
464 "glEnableVertexAttribArrayARB(index)");
468 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
470 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
471 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
472 ctx
->Array
.ArrayObj
->_Enabled
|= _NEW_ARRAY_ATTRIB(index
);
473 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
478 _mesa_DisableVertexAttribArrayARB(GLuint index
)
480 GET_CURRENT_CONTEXT(ctx
);
481 ASSERT_OUTSIDE_BEGIN_END(ctx
);
483 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
484 _mesa_error(ctx
, GL_INVALID_VALUE
,
485 "glEnableVertexAttribArrayARB(index)");
489 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
491 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
492 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
493 ctx
->Array
.ArrayObj
->_Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
494 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
499 * Return info for a vertex attribute array (no alias with legacy
500 * vertex attributes (pos, normal, color, etc)). This function does
501 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
504 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
507 const struct gl_client_array
*array
;
509 if (index
>= MAX_VERTEX_GENERIC_ATTRIBS
) {
510 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
514 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
516 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[index
];
519 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
520 return array
->Enabled
;
521 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
523 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
524 return array
->Stride
;
525 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
527 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
528 return array
->Normalized
;
529 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
530 return array
->BufferObj
->Name
;
531 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
532 if (ctx
->Extensions
.EXT_gpu_shader4
) {
533 return array
->Integer
;
537 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
544 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
546 GET_CURRENT_CONTEXT(ctx
);
547 ASSERT_OUTSIDE_BEGIN_END(ctx
);
549 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
551 _mesa_error(ctx
, GL_INVALID_OPERATION
,
552 "glGetVertexAttribfv(index==0)");
555 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
556 FLUSH_CURRENT(ctx
, 0);
561 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
562 "glGetVertexAttribfv");
568 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
570 GET_CURRENT_CONTEXT(ctx
);
571 ASSERT_OUTSIDE_BEGIN_END(ctx
);
573 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
576 "glGetVertexAttribdv(index==0)");
579 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
580 FLUSH_CURRENT(ctx
, 0);
581 params
[0] = (GLdouble
) v
[0];
582 params
[1] = (GLdouble
) v
[1];
583 params
[2] = (GLdouble
) v
[2];
584 params
[3] = (GLdouble
) v
[3];
588 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
589 "glGetVertexAttribdv");
595 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
597 GET_CURRENT_CONTEXT(ctx
);
598 ASSERT_OUTSIDE_BEGIN_END(ctx
);
600 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
603 "glGetVertexAttribiv(index==0)");
606 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
607 FLUSH_CURRENT(ctx
, 0);
608 /* XXX should floats in[0,1] be scaled to full int range? */
609 params
[0] = (GLint
) v
[0];
610 params
[1] = (GLint
) v
[1];
611 params
[2] = (GLint
) v
[2];
612 params
[3] = (GLint
) v
[3];
616 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
617 "glGetVertexAttribiv");
624 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
626 GET_CURRENT_CONTEXT(ctx
);
627 ASSERT_OUTSIDE_BEGIN_END(ctx
);
629 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
631 _mesa_error(ctx
, GL_INVALID_OPERATION
,
632 "glGetVertexAttribIiv(index==0)");
635 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
636 FLUSH_CURRENT(ctx
, 0);
637 /* XXX we don't have true integer-valued vertex attribs yet */
638 params
[0] = (GLint
) v
[0];
639 params
[1] = (GLint
) v
[1];
640 params
[2] = (GLint
) v
[2];
641 params
[3] = (GLint
) v
[3];
645 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
646 "glGetVertexAttribIiv");
653 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
655 GET_CURRENT_CONTEXT(ctx
);
656 ASSERT_OUTSIDE_BEGIN_END(ctx
);
658 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
661 "glGetVertexAttribIuiv(index==0)");
664 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
665 FLUSH_CURRENT(ctx
, 0);
666 /* XXX we don't have true integer-valued vertex attribs yet */
667 params
[0] = (GLuint
) v
[0];
668 params
[1] = (GLuint
) v
[1];
669 params
[2] = (GLuint
) v
[2];
670 params
[3] = (GLuint
) v
[3];
674 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
675 "glGetVertexAttribIuiv");
681 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
683 GET_CURRENT_CONTEXT(ctx
);
684 ASSERT_OUTSIDE_BEGIN_END(ctx
);
686 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
687 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
691 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
692 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
696 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
698 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
703 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
704 GLsizei count
, const GLvoid
*ptr
)
707 _mesa_VertexPointer(size
, type
, stride
, ptr
);
712 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
716 _mesa_NormalPointer(type
, stride
, ptr
);
721 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
725 _mesa_ColorPointer(size
, type
, stride
, ptr
);
730 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
734 _mesa_IndexPointer(type
, stride
, ptr
);
739 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
740 GLsizei count
, const GLvoid
*ptr
)
743 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
748 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
751 _mesa_EdgeFlagPointer(stride
, ptr
);
756 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
758 GET_CURRENT_CONTEXT(ctx
);
759 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
760 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
761 GLenum ctype
= 0; /* color type */
762 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
763 const GLint toffset
= 0; /* always zero */
764 GLint defstride
; /* default stride */
767 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
770 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
773 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
779 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
780 tcomps
= 0; ccomps
= 0; vcomps
= 2;
785 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
786 tcomps
= 0; ccomps
= 0; vcomps
= 3;
791 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
792 tcomps
= 0; ccomps
= 4; vcomps
= 2;
793 ctype
= GL_UNSIGNED_BYTE
;
799 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
800 tcomps
= 0; ccomps
= 4; vcomps
= 3;
801 ctype
= GL_UNSIGNED_BYTE
;
807 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
808 tcomps
= 0; ccomps
= 3; vcomps
= 3;
815 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
816 tcomps
= 0; ccomps
= 0; vcomps
= 3;
822 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
823 tcomps
= 0; ccomps
= 4; vcomps
= 3;
831 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
832 tcomps
= 2; ccomps
= 0; vcomps
= 3;
837 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
838 tcomps
= 4; ccomps
= 0; vcomps
= 4;
842 case GL_T2F_C4UB_V3F
:
843 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
844 tcomps
= 2; ccomps
= 4; vcomps
= 3;
845 ctype
= GL_UNSIGNED_BYTE
;
851 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
852 tcomps
= 2; ccomps
= 3; vcomps
= 3;
859 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
860 tcomps
= 2; ccomps
= 0; vcomps
= 3;
865 case GL_T2F_C4F_N3F_V3F
:
866 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
867 tcomps
= 2; ccomps
= 4; vcomps
= 3;
874 case GL_T4F_C4F_N3F_V4F
:
875 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
876 tcomps
= 4; ccomps
= 4; vcomps
= 4;
884 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
892 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
893 _mesa_DisableClientState( GL_INDEX_ARRAY
);
894 /* XXX also disable secondary color and generic arrays? */
898 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
899 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
900 (GLubyte
*) pointer
+ toffset
);
903 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
908 _mesa_EnableClientState( GL_COLOR_ARRAY
);
909 _mesa_ColorPointer( ccomps
, ctype
, stride
,
910 (GLubyte
*) pointer
+ coffset
);
913 _mesa_DisableClientState( GL_COLOR_ARRAY
);
919 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
920 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
923 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
927 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
928 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
929 (GLubyte
*) pointer
+ voffset
);
934 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
936 GET_CURRENT_CONTEXT(ctx
);
937 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
939 if (MESA_VERBOSE
& VERBOSE_API
)
940 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
943 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
947 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
950 if (ctx
->Array
.LockCount
!= 0) {
951 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
955 ctx
->Array
.LockFirst
= first
;
956 ctx
->Array
.LockCount
= count
;
958 ctx
->NewState
|= _NEW_ARRAY
;
959 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
964 _mesa_UnlockArraysEXT( void )
966 GET_CURRENT_CONTEXT(ctx
);
967 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
969 if (MESA_VERBOSE
& VERBOSE_API
)
970 _mesa_debug(ctx
, "glUnlockArrays\n");
972 if (ctx
->Array
.LockCount
== 0) {
973 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
977 ctx
->Array
.LockFirst
= 0;
978 ctx
->Array
.LockCount
= 0;
979 ctx
->NewState
|= _NEW_ARRAY
;
980 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
984 /* GL_EXT_multi_draw_arrays */
986 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
987 const GLsizei
*count
, GLsizei primcount
)
989 GET_CURRENT_CONTEXT(ctx
);
992 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
994 for (i
= 0; i
< primcount
; i
++) {
996 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1002 /* GL_IBM_multimode_draw_arrays */
1004 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1005 const GLsizei
* count
,
1006 GLsizei primcount
, GLint modestride
)
1008 GET_CURRENT_CONTEXT(ctx
);
1011 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1013 for ( i
= 0 ; i
< primcount
; i
++ ) {
1014 if ( count
[i
] > 0 ) {
1015 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1016 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1022 /* GL_IBM_multimode_draw_arrays */
1024 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1025 GLenum type
, const GLvoid
* const * indices
,
1026 GLsizei primcount
, GLint modestride
)
1028 GET_CURRENT_CONTEXT(ctx
);
1031 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1033 /* XXX not sure about ARB_vertex_buffer_object handling here */
1035 for ( i
= 0 ; i
< primcount
; i
++ ) {
1036 if ( count
[i
] > 0 ) {
1037 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1038 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1045 * GL_NV_primitive_restart and GL 3.1
1048 _mesa_PrimitiveRestartIndex(GLuint index
)
1050 GET_CURRENT_CONTEXT(ctx
);
1052 if (!ctx
->Extensions
.NV_primitive_restart
&&
1053 ctx
->VersionMajor
* 10 + ctx
->VersionMinor
< 31) {
1054 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1058 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1060 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1062 ctx
->Array
.RestartIndex
= index
;
1067 * Copy one client vertex array to another.
1070 _mesa_copy_client_array(struct gl_context
*ctx
,
1071 struct gl_client_array
*dst
,
1072 struct gl_client_array
*src
)
1074 dst
->Size
= src
->Size
;
1075 dst
->Type
= src
->Type
;
1076 dst
->Format
= src
->Format
;
1077 dst
->Stride
= src
->Stride
;
1078 dst
->StrideB
= src
->StrideB
;
1079 dst
->Ptr
= src
->Ptr
;
1080 dst
->Enabled
= src
->Enabled
;
1081 dst
->Normalized
= src
->Normalized
;
1082 dst
->Integer
= src
->Integer
;
1083 dst
->_ElementSize
= src
->_ElementSize
;
1084 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1085 dst
->_MaxElement
= src
->_MaxElement
;
1091 * Print vertex array's fields.
1094 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1097 printf(" %s[%d]: ", name
, index
);
1099 printf(" %s: ", name
);
1100 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1101 array
->Ptr
, array
->Type
, array
->Size
,
1102 array
->_ElementSize
, array
->StrideB
,
1103 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1104 array
->_MaxElement
);
1109 * Print current vertex object/array info. For debug.
1112 _mesa_print_arrays(struct gl_context
*ctx
)
1114 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1117 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1119 printf("Array Object %u\n", arrayObj
->Name
);
1120 if (arrayObj
->Vertex
.Enabled
)
1121 print_array("Vertex", -1, &arrayObj
->Vertex
);
1122 if (arrayObj
->Normal
.Enabled
)
1123 print_array("Normal", -1, &arrayObj
->Normal
);
1124 if (arrayObj
->Color
.Enabled
)
1125 print_array("Color", -1, &arrayObj
->Color
);
1126 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1127 if (arrayObj
->TexCoord
[i
].Enabled
)
1128 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1129 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1130 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1131 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1132 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1137 * Initialize vertex array state for given context.
1140 _mesa_init_varray(struct gl_context
*ctx
)
1142 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1143 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1144 ctx
->Array
.DefaultArrayObj
);
1145 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1147 ctx
->Array
.Objects
= _mesa_NewHashTable();
1152 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1155 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1157 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1158 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1159 _mesa_delete_array_object(ctx
, arrayObj
);
1164 * Free vertex array state for given context.
1167 _mesa_free_varray_data(struct gl_context
*ctx
)
1169 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1170 _mesa_DeleteHashTable(ctx
->Array
.Objects
);