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"
36 #include "mfeatures.h"
40 #include "main/dispatch.h"
43 /** Used to indicate which GL datatypes are accepted by each of the
44 * glVertex/Color/Attrib/EtcPointer() functions.
48 #define UNSIGNED_BYTE_BIT 0x4
50 #define UNSIGNED_SHORT_BIT 0x10
52 #define UNSIGNED_INT_BIT 0x40
54 #define FLOAT_BIT 0x100
55 #define DOUBLE_BIT 0x200
56 #define FIXED_ES_BIT 0x400
57 #define FIXED_GL_BIT 0x800
60 /** Convert GL datatype enum into a <type>_BIT value seen above */
62 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
69 case GL_UNSIGNED_BYTE
:
70 return UNSIGNED_BYTE_BIT
;
73 case GL_UNSIGNED_SHORT
:
74 return UNSIGNED_SHORT_BIT
;
78 return UNSIGNED_INT_BIT
;
80 if (ctx
->Extensions
.ARB_half_float_vertex
)
89 return ctx
->API
== API_OPENGL
? FIXED_GL_BIT
: FIXED_ES_BIT
;
97 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
100 * \param func name of calling function used for error reporting
101 * \param attrib the attribute array index to update
102 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
103 * \param sizeMin min allowable size value
104 * \param sizeMax max allowable size value
105 * \param size components per element (1, 2, 3 or 4)
106 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
107 * \param stride stride between elements, in elements
108 * \param normalized are integer types converted to floats in [-1, 1]?
109 * \param integer integer-valued values (will not be normalized to [-1,1])
110 * \param ptr the address (or offset inside VBO) of the array data
113 update_array(struct gl_context
*ctx
,
115 GLuint attrib
, GLbitfield legalTypesMask
,
116 GLint sizeMin
, GLint sizeMax
,
117 GLint size
, GLenum type
, GLsizei stride
,
118 GLboolean normalized
, GLboolean integer
,
121 struct gl_client_array
*array
;
125 if (ctx
->API
!= API_OPENGLES
&& ctx
->API
!= API_OPENGLES2
) {
126 /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
127 legalTypesMask
&= ~FIXED_ES_BIT
;
129 if (!ctx
->Extensions
.ARB_ES2_compatibility
) {
130 legalTypesMask
&= ~FIXED_GL_BIT
;
133 typeBit
= type_to_bit(ctx
, type
);
134 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
135 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
136 func
, _mesa_lookup_enum_by_nr(type
));
140 /* Do size parameter checking. */
141 if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
142 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
149 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
153 if (ctx
->Array
.ArrayObj
->ARBsemantics
&&
154 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
155 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
156 * Generate GL_INVALID_OPERATION if that's not true.
158 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
162 elementSize
= _mesa_sizeof_type(type
) * size
;
164 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[attrib
];
167 array
->Stride
= stride
;
168 array
->StrideB
= stride
? stride
: elementSize
;
169 array
->Normalized
= normalized
;
170 array
->Integer
= integer
;
171 array
->Ptr
= (const GLubyte
*) ptr
;
172 array
->_ElementSize
= elementSize
;
174 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
175 ctx
->Array
.ArrayBufferObj
);
177 ctx
->NewState
|= _NEW_ARRAY
;
178 ctx
->Array
.NewState
|= VERT_BIT(attrib
);
183 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
185 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
186 DOUBLE_BIT
| HALF_BIT
| FIXED_ES_BIT
);
187 GET_CURRENT_CONTEXT(ctx
);
188 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
190 if (ctx
->API
== API_OPENGLES
)
191 legalTypes
|= BYTE_BIT
;
193 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
195 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
200 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
202 const GLbitfield legalTypes
= (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
203 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
205 GET_CURRENT_CONTEXT(ctx
);
206 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
208 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
210 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
215 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
217 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
218 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
219 INT_BIT
| UNSIGNED_INT_BIT
|
220 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
222 GET_CURRENT_CONTEXT(ctx
);
223 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
225 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
227 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
232 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
234 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
235 GET_CURRENT_CONTEXT(ctx
);
236 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
238 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
240 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
245 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
247 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
248 FLOAT_BIT
| DOUBLE_BIT
);
249 GET_CURRENT_CONTEXT(ctx
);
250 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
252 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
254 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
259 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
260 GLsizei stride
, const GLvoid
*ptr
)
262 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
263 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
264 INT_BIT
| UNSIGNED_INT_BIT
|
265 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
266 GET_CURRENT_CONTEXT(ctx
);
267 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
269 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
271 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
276 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
279 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
280 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
282 GET_CURRENT_CONTEXT(ctx
);
283 const GLuint unit
= ctx
->Array
.ActiveTexture
;
284 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
286 if (ctx
->API
== API_OPENGLES
)
287 legalTypes
|= BYTE_BIT
;
289 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
291 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
297 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
299 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
300 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
301 const GLboolean integer
= GL_TRUE
;
302 GET_CURRENT_CONTEXT(ctx
);
303 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
305 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
307 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
312 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
314 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
315 GET_CURRENT_CONTEXT(ctx
);
316 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
318 if (ctx
->API
!= API_OPENGLES
) {
319 _mesa_error(ctx
, GL_INVALID_OPERATION
,
320 "glPointSizePointer(ES 1.x only)");
324 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
326 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
330 #if FEATURE_NV_vertex_program
332 * Set a vertex attribute array.
333 * Note that these arrays DO alias the conventional GL vertex arrays
334 * (position, normal, color, fog, texcoord, etc).
335 * The generic attribute slots at #16 and above are not touched.
338 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
339 GLsizei stride
, const GLvoid
*ptr
)
341 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
342 FLOAT_BIT
| DOUBLE_BIT
);
343 GLboolean normalized
= GL_FALSE
;
344 GET_CURRENT_CONTEXT(ctx
);
345 ASSERT_OUTSIDE_BEGIN_END(ctx
);
347 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
348 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
352 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
353 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
357 update_array(ctx
, "glVertexAttribPointerNV", VERT_ATTRIB_GENERIC(index
),
359 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
364 #if FEATURE_ARB_vertex_program
366 * Set a generic vertex attribute array.
367 * Note that these arrays DO NOT alias the conventional GL vertex arrays
368 * (position, normal, color, fog, texcoord, etc).
371 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
372 GLboolean normalized
,
373 GLsizei stride
, const GLvoid
*ptr
)
375 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
376 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
377 INT_BIT
| UNSIGNED_INT_BIT
|
378 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
379 FIXED_ES_BIT
| FIXED_GL_BIT
);
380 GET_CURRENT_CONTEXT(ctx
);
381 ASSERT_OUTSIDE_BEGIN_END(ctx
);
383 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
384 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
388 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
390 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
396 * GL_EXT_gpu_shader4 / GL 3.0.
397 * Set an integer-valued vertex attribute array.
398 * Note that these arrays DO NOT alias the conventional GL vertex arrays
399 * (position, normal, color, fog, texcoord, etc).
402 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
403 GLsizei stride
, const GLvoid
*ptr
)
405 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
406 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
407 INT_BIT
| UNSIGNED_INT_BIT
);
408 const GLboolean normalized
= GL_FALSE
;
409 const GLboolean integer
= GL_TRUE
;
410 GET_CURRENT_CONTEXT(ctx
);
411 ASSERT_OUTSIDE_BEGIN_END(ctx
);
413 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
414 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
418 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
420 size
, type
, stride
, normalized
, integer
, ptr
);
426 _mesa_EnableVertexAttribArrayARB(GLuint index
)
428 GET_CURRENT_CONTEXT(ctx
);
429 ASSERT_OUTSIDE_BEGIN_END(ctx
);
431 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
432 _mesa_error(ctx
, GL_INVALID_VALUE
,
433 "glEnableVertexAttribArrayARB(index)");
437 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
439 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
440 ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_TRUE
;
441 ctx
->Array
.ArrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
442 ctx
->Array
.NewState
|= VERT_BIT_GENERIC(index
);
447 _mesa_DisableVertexAttribArrayARB(GLuint index
)
449 GET_CURRENT_CONTEXT(ctx
);
450 ASSERT_OUTSIDE_BEGIN_END(ctx
);
452 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
453 _mesa_error(ctx
, GL_INVALID_VALUE
,
454 "glDisableVertexAttribArrayARB(index)");
458 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
460 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
461 ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
462 ctx
->Array
.ArrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
463 ctx
->Array
.NewState
|= VERT_BIT_GENERIC(index
);
468 * Return info for a vertex attribute array (no alias with legacy
469 * vertex attributes (pos, normal, color, etc)). This function does
470 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
473 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
476 const struct gl_client_array
*array
;
478 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
479 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
483 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
485 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
488 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
489 return array
->Enabled
;
490 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
492 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
493 return array
->Stride
;
494 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
496 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
497 return array
->Normalized
;
498 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
499 return array
->BufferObj
->Name
;
500 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
501 if (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
) {
502 return array
->Integer
;
510 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
515 static const GLfloat
*
516 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
519 if (ctx
->API
!= API_OPENGLES2
) {
520 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
524 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
525 _mesa_error(ctx
, GL_INVALID_VALUE
,
526 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
530 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
532 FLUSH_CURRENT(ctx
, 0);
533 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
537 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
539 GET_CURRENT_CONTEXT(ctx
);
540 ASSERT_OUTSIDE_BEGIN_END(ctx
);
542 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
543 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
549 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
550 "glGetVertexAttribfv");
556 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
558 GET_CURRENT_CONTEXT(ctx
);
559 ASSERT_OUTSIDE_BEGIN_END(ctx
);
561 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
562 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
564 params
[0] = (GLdouble
) v
[0];
565 params
[1] = (GLdouble
) v
[1];
566 params
[2] = (GLdouble
) v
[2];
567 params
[3] = (GLdouble
) v
[3];
571 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
572 "glGetVertexAttribdv");
578 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
580 GET_CURRENT_CONTEXT(ctx
);
581 ASSERT_OUTSIDE_BEGIN_END(ctx
);
583 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
584 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
586 /* XXX should floats in[0,1] be scaled to full int range? */
587 params
[0] = (GLint
) v
[0];
588 params
[1] = (GLint
) v
[1];
589 params
[2] = (GLint
) v
[2];
590 params
[3] = (GLint
) v
[3];
594 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
595 "glGetVertexAttribiv");
602 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
604 GET_CURRENT_CONTEXT(ctx
);
605 ASSERT_OUTSIDE_BEGIN_END(ctx
);
607 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
609 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
611 /* XXX we don't have true integer-valued vertex attribs yet */
612 params
[0] = (GLint
) v
[0];
613 params
[1] = (GLint
) v
[1];
614 params
[2] = (GLint
) v
[2];
615 params
[3] = (GLint
) v
[3];
619 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
620 "glGetVertexAttribIiv");
627 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
629 GET_CURRENT_CONTEXT(ctx
);
630 ASSERT_OUTSIDE_BEGIN_END(ctx
);
632 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
634 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
636 /* XXX we don't have true integer-valued vertex attribs yet */
637 params
[0] = (GLuint
) v
[0];
638 params
[1] = (GLuint
) v
[1];
639 params
[2] = (GLuint
) v
[2];
640 params
[3] = (GLuint
) v
[3];
644 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
645 "glGetVertexAttribIuiv");
651 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
653 GET_CURRENT_CONTEXT(ctx
);
654 ASSERT_OUTSIDE_BEGIN_END(ctx
);
656 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
657 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
661 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
662 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
666 ASSERT(VERT_ATTRIB_GENERIC(index
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
668 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
673 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
674 GLsizei count
, const GLvoid
*ptr
)
677 _mesa_VertexPointer(size
, type
, stride
, ptr
);
682 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
686 _mesa_NormalPointer(type
, stride
, ptr
);
691 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
695 _mesa_ColorPointer(size
, type
, stride
, ptr
);
700 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
704 _mesa_IndexPointer(type
, stride
, ptr
);
709 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
710 GLsizei count
, const GLvoid
*ptr
)
713 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
718 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
721 _mesa_EdgeFlagPointer(stride
, ptr
);
726 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
728 GET_CURRENT_CONTEXT(ctx
);
729 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
730 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
731 GLenum ctype
= 0; /* color type */
732 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
733 const GLint toffset
= 0; /* always zero */
734 GLint defstride
; /* default stride */
737 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
740 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
743 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
749 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
750 tcomps
= 0; ccomps
= 0; vcomps
= 2;
755 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
756 tcomps
= 0; ccomps
= 0; vcomps
= 3;
761 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
762 tcomps
= 0; ccomps
= 4; vcomps
= 2;
763 ctype
= GL_UNSIGNED_BYTE
;
769 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
770 tcomps
= 0; ccomps
= 4; vcomps
= 3;
771 ctype
= GL_UNSIGNED_BYTE
;
777 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
778 tcomps
= 0; ccomps
= 3; vcomps
= 3;
785 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
786 tcomps
= 0; ccomps
= 0; vcomps
= 3;
792 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
793 tcomps
= 0; ccomps
= 4; vcomps
= 3;
801 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
802 tcomps
= 2; ccomps
= 0; vcomps
= 3;
807 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
808 tcomps
= 4; ccomps
= 0; vcomps
= 4;
812 case GL_T2F_C4UB_V3F
:
813 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
814 tcomps
= 2; ccomps
= 4; vcomps
= 3;
815 ctype
= GL_UNSIGNED_BYTE
;
821 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
822 tcomps
= 2; ccomps
= 3; vcomps
= 3;
829 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
830 tcomps
= 2; ccomps
= 0; vcomps
= 3;
835 case GL_T2F_C4F_N3F_V3F
:
836 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
837 tcomps
= 2; ccomps
= 4; vcomps
= 3;
844 case GL_T4F_C4F_N3F_V4F
:
845 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
846 tcomps
= 4; ccomps
= 4; vcomps
= 4;
854 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
862 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
863 _mesa_DisableClientState( GL_INDEX_ARRAY
);
864 /* XXX also disable secondary color and generic arrays? */
868 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
869 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
870 (GLubyte
*) pointer
+ toffset
);
873 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
878 _mesa_EnableClientState( GL_COLOR_ARRAY
);
879 _mesa_ColorPointer( ccomps
, ctype
, stride
,
880 (GLubyte
*) pointer
+ coffset
);
883 _mesa_DisableClientState( GL_COLOR_ARRAY
);
889 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
890 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
893 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
897 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
898 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
899 (GLubyte
*) pointer
+ voffset
);
904 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
906 GET_CURRENT_CONTEXT(ctx
);
907 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
909 if (MESA_VERBOSE
& VERBOSE_API
)
910 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
913 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
917 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
920 if (ctx
->Array
.LockCount
!= 0) {
921 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
925 ctx
->Array
.LockFirst
= first
;
926 ctx
->Array
.LockCount
= count
;
928 ctx
->NewState
|= _NEW_ARRAY
;
929 ctx
->Array
.NewState
|= VERT_BIT_ALL
;
934 _mesa_UnlockArraysEXT( void )
936 GET_CURRENT_CONTEXT(ctx
);
937 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
939 if (MESA_VERBOSE
& VERBOSE_API
)
940 _mesa_debug(ctx
, "glUnlockArrays\n");
942 if (ctx
->Array
.LockCount
== 0) {
943 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
947 ctx
->Array
.LockFirst
= 0;
948 ctx
->Array
.LockCount
= 0;
949 ctx
->NewState
|= _NEW_ARRAY
;
950 ctx
->Array
.NewState
|= VERT_BIT_ALL
;
954 /* GL_EXT_multi_draw_arrays */
956 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
957 const GLsizei
*count
, GLsizei primcount
)
959 GET_CURRENT_CONTEXT(ctx
);
962 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
964 for (i
= 0; i
< primcount
; i
++) {
966 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
972 /* GL_IBM_multimode_draw_arrays */
974 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
975 const GLsizei
* count
,
976 GLsizei primcount
, GLint modestride
)
978 GET_CURRENT_CONTEXT(ctx
);
981 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
983 for ( i
= 0 ; i
< primcount
; i
++ ) {
984 if ( count
[i
] > 0 ) {
985 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
986 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
992 /* GL_IBM_multimode_draw_arrays */
994 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
995 GLenum type
, const GLvoid
* const * indices
,
996 GLsizei primcount
, GLint modestride
)
998 GET_CURRENT_CONTEXT(ctx
);
1001 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1003 /* XXX not sure about ARB_vertex_buffer_object handling here */
1005 for ( i
= 0 ; i
< primcount
; i
++ ) {
1006 if ( count
[i
] > 0 ) {
1007 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1008 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1015 * GL_NV_primitive_restart and GL 3.1
1018 _mesa_PrimitiveRestartIndex(GLuint index
)
1020 GET_CURRENT_CONTEXT(ctx
);
1022 if (!ctx
->Extensions
.NV_primitive_restart
&&
1023 ctx
->VersionMajor
* 10 + ctx
->VersionMinor
< 31) {
1024 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1028 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1030 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1032 ctx
->Array
.RestartIndex
= index
;
1038 * Copy one client vertex array to another.
1041 _mesa_copy_client_array(struct gl_context
*ctx
,
1042 struct gl_client_array
*dst
,
1043 struct gl_client_array
*src
)
1045 dst
->Size
= src
->Size
;
1046 dst
->Type
= src
->Type
;
1047 dst
->Stride
= src
->Stride
;
1048 dst
->StrideB
= src
->StrideB
;
1049 dst
->Ptr
= src
->Ptr
;
1050 dst
->Enabled
= src
->Enabled
;
1051 dst
->Normalized
= src
->Normalized
;
1052 dst
->Integer
= src
->Integer
;
1053 dst
->_ElementSize
= src
->_ElementSize
;
1054 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1055 dst
->_MaxElement
= src
->_MaxElement
;
1061 * Print vertex array's fields.
1064 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1067 printf(" %s[%d]: ", name
, index
);
1069 printf(" %s: ", name
);
1070 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1071 array
->Ptr
, array
->Type
, array
->Size
,
1072 array
->_ElementSize
, array
->StrideB
,
1073 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1074 array
->_MaxElement
);
1079 * Print current vertex object/array info. For debug.
1082 _mesa_print_arrays(struct gl_context
*ctx
)
1084 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1087 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1089 printf("Array Object %u\n", arrayObj
->Name
);
1090 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
1091 print_array("Vertex", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
1092 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
)
1093 print_array("Normal", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
1094 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
)
1095 print_array("Color", -1, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
1096 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
1097 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
)
1098 print_array("TexCoord", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
1099 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++)
1100 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
)
1101 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
1102 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1107 * Initialize vertex array state for given context.
1110 _mesa_init_varray(struct gl_context
*ctx
)
1112 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1113 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1114 ctx
->Array
.DefaultArrayObj
);
1115 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1117 ctx
->Array
.Objects
= _mesa_NewHashTable();
1122 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1125 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1127 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1128 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1129 _mesa_delete_array_object(ctx
, arrayObj
);
1134 * Free vertex array state for given context.
1137 _mesa_free_varray_data(struct gl_context
*ctx
)
1139 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1140 _mesa_DeleteHashTable(ctx
->Array
.Objects
);