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
&& ctx
->API
!= API_OPENGLES2
) {
131 /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
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
|
302 GET_CURRENT_CONTEXT(ctx
);
303 const GLuint unit
= ctx
->Array
.ActiveTexture
;
304 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
306 if (ctx
->API
== API_OPENGLES
)
307 legalTypes
|= BYTE_BIT
;
309 ASSERT(unit
< Elements(ctx
->Array
.ArrayObj
->TexCoord
));
311 update_array(ctx
, "glTexCoordPointer",
312 &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
313 _NEW_ARRAY_TEXCOORD(unit
),
315 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
321 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
323 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
324 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
325 const GLboolean integer
= GL_TRUE
;
326 GET_CURRENT_CONTEXT(ctx
);
327 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
329 update_array(ctx
, "glEdgeFlagPointer",
330 &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
332 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
337 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
339 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_BIT
);
340 GET_CURRENT_CONTEXT(ctx
);
341 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
343 if (ctx
->API
!= API_OPENGLES
) {
344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
345 "glPointSizePointer(ES 1.x only)");
349 update_array(ctx
, "glPointSizePointer",
350 &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
352 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
356 #if FEATURE_NV_vertex_program
358 * Set a vertex attribute array.
359 * Note that these arrays DO alias the conventional GL vertex arrays
360 * (position, normal, color, fog, texcoord, etc).
361 * The generic attribute slots at #16 and above are not touched.
364 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
365 GLsizei stride
, const GLvoid
*ptr
)
367 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
368 FLOAT_BIT
| DOUBLE_BIT
);
369 GLboolean normalized
= GL_FALSE
;
370 GET_CURRENT_CONTEXT(ctx
);
371 ASSERT_OUTSIDE_BEGIN_END(ctx
);
373 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
374 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
378 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
379 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
383 update_array(ctx
, "glVertexAttribPointerNV",
384 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
385 _NEW_ARRAY_ATTRIB(index
),
386 legalTypes
, 1, BGRA_OR_4
,
387 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
392 #if FEATURE_ARB_vertex_program
394 * Set a generic vertex attribute array.
395 * Note that these arrays DO NOT alias the conventional GL vertex arrays
396 * (position, normal, color, fog, texcoord, etc).
399 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
400 GLboolean normalized
,
401 GLsizei stride
, const GLvoid
*ptr
)
403 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
404 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
405 INT_BIT
| UNSIGNED_INT_BIT
|
406 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
408 GET_CURRENT_CONTEXT(ctx
);
409 ASSERT_OUTSIDE_BEGIN_END(ctx
);
411 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
412 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
416 update_array(ctx
, "glVertexAttribPointer",
417 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
418 _NEW_ARRAY_ATTRIB(index
),
419 legalTypes
, 1, BGRA_OR_4
,
420 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
426 * GL_EXT_gpu_shader4 / GL 3.0.
427 * Set an integer-valued vertex attribute array.
428 * Note that these arrays DO NOT alias the conventional GL vertex arrays
429 * (position, normal, color, fog, texcoord, etc).
432 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
433 GLsizei stride
, const GLvoid
*ptr
)
435 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
436 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
437 INT_BIT
| UNSIGNED_INT_BIT
);
438 const GLboolean normalized
= GL_FALSE
;
439 const GLboolean integer
= GL_TRUE
;
440 GET_CURRENT_CONTEXT(ctx
);
441 ASSERT_OUTSIDE_BEGIN_END(ctx
);
443 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
444 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
448 update_array(ctx
, "glVertexAttribIPointer",
449 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
450 _NEW_ARRAY_ATTRIB(index
),
452 size
, type
, stride
, normalized
, integer
, ptr
);
458 _mesa_EnableVertexAttribArrayARB(GLuint index
)
460 GET_CURRENT_CONTEXT(ctx
);
461 ASSERT_OUTSIDE_BEGIN_END(ctx
);
463 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
464 _mesa_error(ctx
, GL_INVALID_VALUE
,
465 "glEnableVertexAttribArrayARB(index)");
469 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
471 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
472 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
473 ctx
->Array
.ArrayObj
->_Enabled
|= _NEW_ARRAY_ATTRIB(index
);
474 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
479 _mesa_DisableVertexAttribArrayARB(GLuint index
)
481 GET_CURRENT_CONTEXT(ctx
);
482 ASSERT_OUTSIDE_BEGIN_END(ctx
);
484 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
485 _mesa_error(ctx
, GL_INVALID_VALUE
,
486 "glEnableVertexAttribArrayARB(index)");
490 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
492 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
493 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
494 ctx
->Array
.ArrayObj
->_Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
495 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
500 * Return info for a vertex attribute array (no alias with legacy
501 * vertex attributes (pos, normal, color, etc)). This function does
502 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
505 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
508 const struct gl_client_array
*array
;
510 if (index
>= MAX_VERTEX_GENERIC_ATTRIBS
) {
511 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
515 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
517 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[index
];
520 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
521 return array
->Enabled
;
522 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
524 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
525 return array
->Stride
;
526 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
528 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
529 return array
->Normalized
;
530 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
531 return array
->BufferObj
->Name
;
532 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
533 if (ctx
->Extensions
.EXT_gpu_shader4
) {
534 return array
->Integer
;
538 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
545 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
547 GET_CURRENT_CONTEXT(ctx
);
548 ASSERT_OUTSIDE_BEGIN_END(ctx
);
550 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
552 _mesa_error(ctx
, GL_INVALID_OPERATION
,
553 "glGetVertexAttribfv(index==0)");
556 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
557 FLUSH_CURRENT(ctx
, 0);
562 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
563 "glGetVertexAttribfv");
569 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
571 GET_CURRENT_CONTEXT(ctx
);
572 ASSERT_OUTSIDE_BEGIN_END(ctx
);
574 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
577 "glGetVertexAttribdv(index==0)");
580 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
581 FLUSH_CURRENT(ctx
, 0);
582 params
[0] = (GLdouble
) v
[0];
583 params
[1] = (GLdouble
) v
[1];
584 params
[2] = (GLdouble
) v
[2];
585 params
[3] = (GLdouble
) v
[3];
589 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
590 "glGetVertexAttribdv");
596 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
598 GET_CURRENT_CONTEXT(ctx
);
599 ASSERT_OUTSIDE_BEGIN_END(ctx
);
601 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
604 "glGetVertexAttribiv(index==0)");
607 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
608 FLUSH_CURRENT(ctx
, 0);
609 /* XXX should floats in[0,1] be scaled to full int range? */
610 params
[0] = (GLint
) v
[0];
611 params
[1] = (GLint
) v
[1];
612 params
[2] = (GLint
) v
[2];
613 params
[3] = (GLint
) v
[3];
617 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
618 "glGetVertexAttribiv");
625 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
627 GET_CURRENT_CONTEXT(ctx
);
628 ASSERT_OUTSIDE_BEGIN_END(ctx
);
630 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
633 "glGetVertexAttribIiv(index==0)");
636 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
637 FLUSH_CURRENT(ctx
, 0);
638 /* XXX we don't have true integer-valued vertex attribs yet */
639 params
[0] = (GLint
) v
[0];
640 params
[1] = (GLint
) v
[1];
641 params
[2] = (GLint
) v
[2];
642 params
[3] = (GLint
) v
[3];
646 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
647 "glGetVertexAttribIiv");
654 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
656 GET_CURRENT_CONTEXT(ctx
);
657 ASSERT_OUTSIDE_BEGIN_END(ctx
);
659 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
661 _mesa_error(ctx
, GL_INVALID_OPERATION
,
662 "glGetVertexAttribIuiv(index==0)");
665 const GLfloat
*v
= ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
666 FLUSH_CURRENT(ctx
, 0);
667 /* XXX we don't have true integer-valued vertex attribs yet */
668 params
[0] = (GLuint
) v
[0];
669 params
[1] = (GLuint
) v
[1];
670 params
[2] = (GLuint
) v
[2];
671 params
[3] = (GLuint
) v
[3];
675 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
676 "glGetVertexAttribIuiv");
682 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
684 GET_CURRENT_CONTEXT(ctx
);
685 ASSERT_OUTSIDE_BEGIN_END(ctx
);
687 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
688 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
692 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
697 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
699 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
704 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
705 GLsizei count
, const GLvoid
*ptr
)
708 _mesa_VertexPointer(size
, type
, stride
, ptr
);
713 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
717 _mesa_NormalPointer(type
, stride
, ptr
);
722 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
726 _mesa_ColorPointer(size
, type
, stride
, ptr
);
731 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
735 _mesa_IndexPointer(type
, stride
, ptr
);
740 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
741 GLsizei count
, const GLvoid
*ptr
)
744 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
749 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
752 _mesa_EdgeFlagPointer(stride
, ptr
);
757 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
759 GET_CURRENT_CONTEXT(ctx
);
760 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
761 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
762 GLenum ctype
= 0; /* color type */
763 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
764 const GLint toffset
= 0; /* always zero */
765 GLint defstride
; /* default stride */
768 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
771 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
774 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
780 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
781 tcomps
= 0; ccomps
= 0; vcomps
= 2;
786 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
787 tcomps
= 0; ccomps
= 0; vcomps
= 3;
792 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
793 tcomps
= 0; ccomps
= 4; vcomps
= 2;
794 ctype
= GL_UNSIGNED_BYTE
;
800 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
801 tcomps
= 0; ccomps
= 4; vcomps
= 3;
802 ctype
= GL_UNSIGNED_BYTE
;
808 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
809 tcomps
= 0; ccomps
= 3; vcomps
= 3;
816 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
817 tcomps
= 0; ccomps
= 0; vcomps
= 3;
823 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
824 tcomps
= 0; ccomps
= 4; vcomps
= 3;
832 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
833 tcomps
= 2; ccomps
= 0; vcomps
= 3;
838 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
839 tcomps
= 4; ccomps
= 0; vcomps
= 4;
843 case GL_T2F_C4UB_V3F
:
844 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
845 tcomps
= 2; ccomps
= 4; vcomps
= 3;
846 ctype
= GL_UNSIGNED_BYTE
;
852 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
853 tcomps
= 2; ccomps
= 3; vcomps
= 3;
860 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
861 tcomps
= 2; ccomps
= 0; vcomps
= 3;
866 case GL_T2F_C4F_N3F_V3F
:
867 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
868 tcomps
= 2; ccomps
= 4; vcomps
= 3;
875 case GL_T4F_C4F_N3F_V4F
:
876 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
877 tcomps
= 4; ccomps
= 4; vcomps
= 4;
885 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
893 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
894 _mesa_DisableClientState( GL_INDEX_ARRAY
);
895 /* XXX also disable secondary color and generic arrays? */
899 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
900 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
901 (GLubyte
*) pointer
+ toffset
);
904 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
909 _mesa_EnableClientState( GL_COLOR_ARRAY
);
910 _mesa_ColorPointer( ccomps
, ctype
, stride
,
911 (GLubyte
*) pointer
+ coffset
);
914 _mesa_DisableClientState( GL_COLOR_ARRAY
);
920 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
921 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
924 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
928 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
929 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
930 (GLubyte
*) pointer
+ voffset
);
935 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
937 GET_CURRENT_CONTEXT(ctx
);
938 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
940 if (MESA_VERBOSE
& VERBOSE_API
)
941 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
944 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
948 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
951 if (ctx
->Array
.LockCount
!= 0) {
952 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
956 ctx
->Array
.LockFirst
= first
;
957 ctx
->Array
.LockCount
= count
;
959 ctx
->NewState
|= _NEW_ARRAY
;
960 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
965 _mesa_UnlockArraysEXT( void )
967 GET_CURRENT_CONTEXT(ctx
);
968 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
970 if (MESA_VERBOSE
& VERBOSE_API
)
971 _mesa_debug(ctx
, "glUnlockArrays\n");
973 if (ctx
->Array
.LockCount
== 0) {
974 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
978 ctx
->Array
.LockFirst
= 0;
979 ctx
->Array
.LockCount
= 0;
980 ctx
->NewState
|= _NEW_ARRAY
;
981 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
985 /* GL_EXT_multi_draw_arrays */
987 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
988 const GLsizei
*count
, GLsizei primcount
)
990 GET_CURRENT_CONTEXT(ctx
);
993 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
995 for (i
= 0; i
< primcount
; i
++) {
997 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1003 /* GL_IBM_multimode_draw_arrays */
1005 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1006 const GLsizei
* count
,
1007 GLsizei primcount
, GLint modestride
)
1009 GET_CURRENT_CONTEXT(ctx
);
1012 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1014 for ( i
= 0 ; i
< primcount
; i
++ ) {
1015 if ( count
[i
] > 0 ) {
1016 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1017 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1023 /* GL_IBM_multimode_draw_arrays */
1025 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1026 GLenum type
, const GLvoid
* const * indices
,
1027 GLsizei primcount
, GLint modestride
)
1029 GET_CURRENT_CONTEXT(ctx
);
1032 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1034 /* XXX not sure about ARB_vertex_buffer_object handling here */
1036 for ( i
= 0 ; i
< primcount
; i
++ ) {
1037 if ( count
[i
] > 0 ) {
1038 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1039 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1046 * GL_NV_primitive_restart and GL 3.1
1049 _mesa_PrimitiveRestartIndex(GLuint index
)
1051 GET_CURRENT_CONTEXT(ctx
);
1053 if (!ctx
->Extensions
.NV_primitive_restart
&&
1054 ctx
->VersionMajor
* 10 + ctx
->VersionMinor
< 31) {
1055 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1059 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1061 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1063 ctx
->Array
.RestartIndex
= index
;
1068 * Copy one client vertex array to another.
1071 _mesa_copy_client_array(struct gl_context
*ctx
,
1072 struct gl_client_array
*dst
,
1073 struct gl_client_array
*src
)
1075 dst
->Size
= src
->Size
;
1076 dst
->Type
= src
->Type
;
1077 dst
->Format
= src
->Format
;
1078 dst
->Stride
= src
->Stride
;
1079 dst
->StrideB
= src
->StrideB
;
1080 dst
->Ptr
= src
->Ptr
;
1081 dst
->Enabled
= src
->Enabled
;
1082 dst
->Normalized
= src
->Normalized
;
1083 dst
->Integer
= src
->Integer
;
1084 dst
->_ElementSize
= src
->_ElementSize
;
1085 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1086 dst
->_MaxElement
= src
->_MaxElement
;
1092 * Print vertex array's fields.
1095 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1098 printf(" %s[%d]: ", name
, index
);
1100 printf(" %s: ", name
);
1101 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1102 array
->Ptr
, array
->Type
, array
->Size
,
1103 array
->_ElementSize
, array
->StrideB
,
1104 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1105 array
->_MaxElement
);
1110 * Print current vertex object/array info. For debug.
1113 _mesa_print_arrays(struct gl_context
*ctx
)
1115 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1118 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1120 printf("Array Object %u\n", arrayObj
->Name
);
1121 if (arrayObj
->Vertex
.Enabled
)
1122 print_array("Vertex", -1, &arrayObj
->Vertex
);
1123 if (arrayObj
->Normal
.Enabled
)
1124 print_array("Normal", -1, &arrayObj
->Normal
);
1125 if (arrayObj
->Color
.Enabled
)
1126 print_array("Color", -1, &arrayObj
->Color
);
1127 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1128 if (arrayObj
->TexCoord
[i
].Enabled
)
1129 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1130 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1131 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1132 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1133 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1138 * Initialize vertex array state for given context.
1141 _mesa_init_varray(struct gl_context
*ctx
)
1143 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1144 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1145 ctx
->Array
.DefaultArrayObj
);
1146 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1148 ctx
->Array
.Objects
= _mesa_NewHashTable();
1153 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1156 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1158 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1159 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1160 _mesa_delete_array_object(ctx
, arrayObj
);
1165 * Free vertex array state for given context.
1168 _mesa_free_varray_data(struct gl_context
*ctx
)
1170 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1171 _mesa_DeleteHashTable(ctx
->Array
.Objects
);