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 do error checking for GL_EXT_vertex_array_bgra */
47 /** Used to indicate which GL datatypes are accepted by each of the
48 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define UNSIGNED_BYTE_BIT 0x4
54 #define UNSIGNED_SHORT_BIT 0x10
56 #define UNSIGNED_INT_BIT 0x40
58 #define FLOAT_BIT 0x100
59 #define DOUBLE_BIT 0x200
60 #define FIXED_ES_BIT 0x400
61 #define FIXED_GL_BIT 0x800
62 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
63 #define INT_2_10_10_10_REV_BIT 0x2000
66 /** Convert GL datatype enum into a <type>_BIT value seen above */
68 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
75 case GL_UNSIGNED_BYTE
:
76 return UNSIGNED_BYTE_BIT
;
79 case GL_UNSIGNED_SHORT
:
80 return UNSIGNED_SHORT_BIT
;
84 return UNSIGNED_INT_BIT
;
86 if (ctx
->Extensions
.ARB_half_float_vertex
)
95 return ctx
->API
== API_OPENGL
? FIXED_GL_BIT
: FIXED_ES_BIT
;
96 case GL_UNSIGNED_INT_2_10_10_10_REV
:
97 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
98 case GL_INT_2_10_10_10_REV
:
99 return INT_2_10_10_10_REV_BIT
;
107 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
110 * \param func name of calling function used for error reporting
111 * \param array the array to update
112 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
113 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
114 * \param sizeMin min allowable size value
115 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
116 * \param size components per element (1, 2, 3 or 4)
117 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
118 * \param stride stride between elements, in elements
119 * \param normalized are integer types converted to floats in [-1, 1]?
120 * \param integer integer-valued values (will not be normalized to [-1,1])
121 * \param ptr the address (or offset inside VBO) of the array data
124 update_array(struct gl_context
*ctx
,
126 struct gl_client_array
*array
,
127 GLbitfield64 dirtyBit
, GLbitfield legalTypesMask
,
128 GLint sizeMin
, GLint sizeMax
,
129 GLint size
, GLenum type
, GLsizei stride
,
130 GLboolean normalized
, GLboolean integer
,
135 GLenum format
= GL_RGBA
;
137 if (ctx
->API
!= API_OPENGLES
&& ctx
->API
!= API_OPENGLES2
) {
138 /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
139 legalTypesMask
&= ~FIXED_ES_BIT
;
141 if (!ctx
->Extensions
.ARB_ES2_compatibility
) {
142 legalTypesMask
&= ~FIXED_GL_BIT
;
144 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
145 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
146 INT_2_10_10_10_REV_BIT
);
149 typeBit
= type_to_bit(ctx
, type
);
150 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
151 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
152 func
, _mesa_lookup_enum_by_nr(type
));
156 /* Do size parameter checking.
157 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
158 * must be handled specially.
160 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
161 sizeMax
== BGRA_OR_4
&&
163 GLboolean bgra_error
= GL_FALSE
;
165 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
166 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
167 type
!= GL_INT_2_10_10_10_REV
&&
168 type
!= GL_UNSIGNED_BYTE
)
169 bgra_error
= GL_TRUE
;
170 } else if (type
!= GL_UNSIGNED_BYTE
)
171 bgra_error
= GL_TRUE
;
174 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(GL_BGRA/GLubyte)", func
);
180 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
181 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
185 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
186 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
187 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
188 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
194 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
198 if (ctx
->Array
.ArrayObj
->VBOonly
&&
199 ctx
->Array
.ArrayBufferObj
->Name
== 0) {
200 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
201 * Generate GL_INVALID_OPERATION if that's not true.
203 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
207 elementSize
= _mesa_sizeof_type(type
) * size
;
211 array
->Format
= format
;
212 array
->Stride
= stride
;
213 array
->StrideB
= stride
? stride
: elementSize
;
214 array
->Normalized
= normalized
;
215 array
->Integer
= integer
;
216 array
->Ptr
= (const GLubyte
*) ptr
;
217 array
->_ElementSize
= elementSize
;
219 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
220 ctx
->Array
.ArrayBufferObj
);
222 ctx
->NewState
|= _NEW_ARRAY
;
223 ctx
->Array
.NewState
|= dirtyBit
;
228 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
230 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
231 DOUBLE_BIT
| HALF_BIT
| FIXED_ES_BIT
|
232 UNSIGNED_INT_2_10_10_10_REV_BIT
|
233 INT_2_10_10_10_REV_BIT
);
234 GET_CURRENT_CONTEXT(ctx
);
235 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
237 if (ctx
->API
== API_OPENGLES
)
238 legalTypes
|= BYTE_BIT
;
240 update_array(ctx
, "glVertexPointer",
241 &ctx
->Array
.ArrayObj
->Vertex
, VERT_BIT_POS
,
243 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
248 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
250 const GLbitfield legalTypes
= (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
251 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
253 UNSIGNED_INT_2_10_10_10_REV_BIT
|
254 INT_2_10_10_10_REV_BIT
);
255 GET_CURRENT_CONTEXT(ctx
);
256 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
258 update_array(ctx
, "glNormalPointer",
259 &ctx
->Array
.ArrayObj
->Normal
, VERT_BIT_NORMAL
,
261 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
266 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
268 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
269 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
270 INT_BIT
| UNSIGNED_INT_BIT
|
271 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
273 UNSIGNED_INT_2_10_10_10_REV_BIT
|
274 INT_2_10_10_10_REV_BIT
);
275 GET_CURRENT_CONTEXT(ctx
);
276 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
278 update_array(ctx
, "glColorPointer",
279 &ctx
->Array
.ArrayObj
->Color
, VERT_BIT_COLOR0
,
280 legalTypes
, 3, BGRA_OR_4
,
281 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
286 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
288 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
289 GET_CURRENT_CONTEXT(ctx
);
290 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
292 update_array(ctx
, "glFogCoordPointer",
293 &ctx
->Array
.ArrayObj
->FogCoord
, VERT_BIT_FOG
,
295 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
300 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
302 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
303 FLOAT_BIT
| DOUBLE_BIT
);
304 GET_CURRENT_CONTEXT(ctx
);
305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
307 update_array(ctx
, "glIndexPointer",
308 &ctx
->Array
.ArrayObj
->Index
, VERT_BIT_COLOR_INDEX
,
310 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
315 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
316 GLsizei stride
, const GLvoid
*ptr
)
318 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
319 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
320 INT_BIT
| UNSIGNED_INT_BIT
|
321 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
322 UNSIGNED_INT_2_10_10_10_REV_BIT
|
323 INT_2_10_10_10_REV_BIT
);
324 GET_CURRENT_CONTEXT(ctx
);
325 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
327 update_array(ctx
, "glSecondaryColorPointer",
328 &ctx
->Array
.ArrayObj
->SecondaryColor
, VERT_BIT_COLOR1
,
329 legalTypes
, 3, BGRA_OR_4
,
330 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
335 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
338 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
339 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
341 UNSIGNED_INT_2_10_10_10_REV_BIT
|
342 INT_2_10_10_10_REV_BIT
);
343 GET_CURRENT_CONTEXT(ctx
);
344 const GLuint unit
= ctx
->Array
.ActiveTexture
;
345 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
347 if (ctx
->API
== API_OPENGLES
)
348 legalTypes
|= BYTE_BIT
;
350 ASSERT(unit
< Elements(ctx
->Array
.ArrayObj
->TexCoord
));
352 update_array(ctx
, "glTexCoordPointer",
353 &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
356 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
362 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
364 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
365 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
366 const GLboolean integer
= GL_TRUE
;
367 GET_CURRENT_CONTEXT(ctx
);
368 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
370 update_array(ctx
, "glEdgeFlagPointer",
371 &ctx
->Array
.ArrayObj
->EdgeFlag
, VERT_BIT_EDGEFLAG
,
373 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
378 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
380 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
381 GET_CURRENT_CONTEXT(ctx
);
382 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
384 if (ctx
->API
!= API_OPENGLES
) {
385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
386 "glPointSizePointer(ES 1.x only)");
390 update_array(ctx
, "glPointSizePointer",
391 &ctx
->Array
.ArrayObj
->PointSize
, VERT_BIT_POINT_SIZE
,
393 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
397 #if FEATURE_NV_vertex_program
399 * Set a vertex attribute array.
400 * Note that these arrays DO alias the conventional GL vertex arrays
401 * (position, normal, color, fog, texcoord, etc).
402 * The generic attribute slots at #16 and above are not touched.
405 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
406 GLsizei stride
, const GLvoid
*ptr
)
408 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
409 FLOAT_BIT
| DOUBLE_BIT
);
410 GLboolean normalized
= GL_FALSE
;
411 GET_CURRENT_CONTEXT(ctx
);
412 ASSERT_OUTSIDE_BEGIN_END(ctx
);
414 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
415 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
419 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
420 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
424 update_array(ctx
, "glVertexAttribPointerNV",
425 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
426 VERT_BIT_GENERIC(index
),
427 legalTypes
, 1, BGRA_OR_4
,
428 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
433 #if FEATURE_ARB_vertex_program
435 * Set a generic vertex attribute array.
436 * Note that these arrays DO NOT alias the conventional GL vertex arrays
437 * (position, normal, color, fog, texcoord, etc).
440 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
441 GLboolean normalized
,
442 GLsizei stride
, const GLvoid
*ptr
)
444 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
445 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
446 INT_BIT
| UNSIGNED_INT_BIT
|
447 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
448 FIXED_ES_BIT
| FIXED_GL_BIT
|
449 UNSIGNED_INT_2_10_10_10_REV_BIT
|
450 INT_2_10_10_10_REV_BIT
);
451 GET_CURRENT_CONTEXT(ctx
);
452 ASSERT_OUTSIDE_BEGIN_END(ctx
);
454 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
455 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
459 update_array(ctx
, "glVertexAttribPointer",
460 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
461 VERT_BIT_GENERIC(index
),
462 legalTypes
, 1, BGRA_OR_4
,
463 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
469 * GL_EXT_gpu_shader4 / GL 3.0.
470 * Set an integer-valued vertex attribute array.
471 * Note that these arrays DO NOT alias the conventional GL vertex arrays
472 * (position, normal, color, fog, texcoord, etc).
475 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
476 GLsizei stride
, const GLvoid
*ptr
)
478 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
479 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
480 INT_BIT
| UNSIGNED_INT_BIT
);
481 const GLboolean normalized
= GL_FALSE
;
482 const GLboolean integer
= GL_TRUE
;
483 GET_CURRENT_CONTEXT(ctx
);
484 ASSERT_OUTSIDE_BEGIN_END(ctx
);
486 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
487 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
491 update_array(ctx
, "glVertexAttribIPointer",
492 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
493 VERT_BIT_GENERIC(index
),
495 size
, type
, stride
, normalized
, integer
, ptr
);
501 _mesa_EnableVertexAttribArrayARB(GLuint index
)
503 GET_CURRENT_CONTEXT(ctx
);
504 ASSERT_OUTSIDE_BEGIN_END(ctx
);
506 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
507 _mesa_error(ctx
, GL_INVALID_VALUE
,
508 "glEnableVertexAttribArrayARB(index)");
512 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
514 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
515 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
516 ctx
->Array
.ArrayObj
->_Enabled
|= VERT_BIT_GENERIC(index
);
517 ctx
->Array
.NewState
|= VERT_BIT_GENERIC(index
);
522 _mesa_DisableVertexAttribArrayARB(GLuint index
)
524 GET_CURRENT_CONTEXT(ctx
);
525 ASSERT_OUTSIDE_BEGIN_END(ctx
);
527 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
528 _mesa_error(ctx
, GL_INVALID_VALUE
,
529 "glDisableVertexAttribArrayARB(index)");
533 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
535 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
536 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
537 ctx
->Array
.ArrayObj
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
538 ctx
->Array
.NewState
|= VERT_BIT_GENERIC(index
);
543 * Return info for a vertex attribute array (no alias with legacy
544 * vertex attributes (pos, normal, color, etc)). This function does
545 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
548 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
551 const struct gl_client_array
*array
;
553 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
554 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
558 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
560 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[index
];
563 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
564 return array
->Enabled
;
565 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
567 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
568 return array
->Stride
;
569 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
571 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
572 return array
->Normalized
;
573 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
574 return array
->BufferObj
->Name
;
575 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
576 if (ctx
->Extensions
.EXT_gpu_shader4
) {
577 return array
->Integer
;
580 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
581 if (ctx
->Extensions
.ARB_instanced_arrays
) {
582 return array
->InstanceDivisor
;
590 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
595 static const GLfloat
*
596 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
599 if (ctx
->API
!= API_OPENGLES2
) {
600 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
604 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
605 _mesa_error(ctx
, GL_INVALID_VALUE
,
606 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
610 FLUSH_CURRENT(ctx
, 0);
611 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
615 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
617 GET_CURRENT_CONTEXT(ctx
);
618 ASSERT_OUTSIDE_BEGIN_END(ctx
);
620 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
621 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
627 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
628 "glGetVertexAttribfv");
634 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
636 GET_CURRENT_CONTEXT(ctx
);
637 ASSERT_OUTSIDE_BEGIN_END(ctx
);
639 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
640 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
642 params
[0] = (GLdouble
) v
[0];
643 params
[1] = (GLdouble
) v
[1];
644 params
[2] = (GLdouble
) v
[2];
645 params
[3] = (GLdouble
) v
[3];
649 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
650 "glGetVertexAttribdv");
656 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
658 GET_CURRENT_CONTEXT(ctx
);
659 ASSERT_OUTSIDE_BEGIN_END(ctx
);
661 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
662 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
664 /* XXX should floats in[0,1] be scaled to full int range? */
665 params
[0] = (GLint
) v
[0];
666 params
[1] = (GLint
) v
[1];
667 params
[2] = (GLint
) v
[2];
668 params
[3] = (GLint
) v
[3];
672 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
673 "glGetVertexAttribiv");
680 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
682 GET_CURRENT_CONTEXT(ctx
);
683 ASSERT_OUTSIDE_BEGIN_END(ctx
);
685 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
687 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
689 /* XXX we don't have true integer-valued vertex attribs yet */
690 params
[0] = (GLint
) v
[0];
691 params
[1] = (GLint
) v
[1];
692 params
[2] = (GLint
) v
[2];
693 params
[3] = (GLint
) v
[3];
697 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
698 "glGetVertexAttribIiv");
705 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
707 GET_CURRENT_CONTEXT(ctx
);
708 ASSERT_OUTSIDE_BEGIN_END(ctx
);
710 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
712 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
714 /* XXX we don't have true integer-valued vertex attribs yet */
715 params
[0] = (GLuint
) v
[0];
716 params
[1] = (GLuint
) v
[1];
717 params
[2] = (GLuint
) v
[2];
718 params
[3] = (GLuint
) v
[3];
722 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
723 "glGetVertexAttribIuiv");
729 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
731 GET_CURRENT_CONTEXT(ctx
);
732 ASSERT_OUTSIDE_BEGIN_END(ctx
);
734 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
735 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
739 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
740 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
744 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
746 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
751 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
752 GLsizei count
, const GLvoid
*ptr
)
755 _mesa_VertexPointer(size
, type
, stride
, ptr
);
760 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
764 _mesa_NormalPointer(type
, stride
, ptr
);
769 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
773 _mesa_ColorPointer(size
, type
, stride
, ptr
);
778 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
782 _mesa_IndexPointer(type
, stride
, ptr
);
787 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
788 GLsizei count
, const GLvoid
*ptr
)
791 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
796 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
799 _mesa_EdgeFlagPointer(stride
, ptr
);
804 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
806 GET_CURRENT_CONTEXT(ctx
);
807 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
808 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
809 GLenum ctype
= 0; /* color type */
810 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
811 const GLint toffset
= 0; /* always zero */
812 GLint defstride
; /* default stride */
815 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
818 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
821 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
827 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
828 tcomps
= 0; ccomps
= 0; vcomps
= 2;
833 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
834 tcomps
= 0; ccomps
= 0; vcomps
= 3;
839 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
840 tcomps
= 0; ccomps
= 4; vcomps
= 2;
841 ctype
= GL_UNSIGNED_BYTE
;
847 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
848 tcomps
= 0; ccomps
= 4; vcomps
= 3;
849 ctype
= GL_UNSIGNED_BYTE
;
855 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
856 tcomps
= 0; ccomps
= 3; vcomps
= 3;
863 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
864 tcomps
= 0; ccomps
= 0; vcomps
= 3;
870 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
871 tcomps
= 0; ccomps
= 4; vcomps
= 3;
879 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
880 tcomps
= 2; ccomps
= 0; vcomps
= 3;
885 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
886 tcomps
= 4; ccomps
= 0; vcomps
= 4;
890 case GL_T2F_C4UB_V3F
:
891 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
892 tcomps
= 2; ccomps
= 4; vcomps
= 3;
893 ctype
= GL_UNSIGNED_BYTE
;
899 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
900 tcomps
= 2; ccomps
= 3; vcomps
= 3;
907 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
908 tcomps
= 2; ccomps
= 0; vcomps
= 3;
913 case GL_T2F_C4F_N3F_V3F
:
914 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
915 tcomps
= 2; ccomps
= 4; vcomps
= 3;
922 case GL_T4F_C4F_N3F_V4F
:
923 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
924 tcomps
= 4; ccomps
= 4; vcomps
= 4;
932 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
940 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
941 _mesa_DisableClientState( GL_INDEX_ARRAY
);
942 /* XXX also disable secondary color and generic arrays? */
946 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
947 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
948 (GLubyte
*) pointer
+ toffset
);
951 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
956 _mesa_EnableClientState( GL_COLOR_ARRAY
);
957 _mesa_ColorPointer( ccomps
, ctype
, stride
,
958 (GLubyte
*) pointer
+ coffset
);
961 _mesa_DisableClientState( GL_COLOR_ARRAY
);
967 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
968 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
971 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
975 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
976 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
977 (GLubyte
*) pointer
+ voffset
);
982 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
984 GET_CURRENT_CONTEXT(ctx
);
985 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
987 if (MESA_VERBOSE
& VERBOSE_API
)
988 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
991 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
995 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
998 if (ctx
->Array
.LockCount
!= 0) {
999 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1003 ctx
->Array
.LockFirst
= first
;
1004 ctx
->Array
.LockCount
= count
;
1006 ctx
->NewState
|= _NEW_ARRAY
;
1007 ctx
->Array
.NewState
|= VERT_BIT_ALL
;
1012 _mesa_UnlockArraysEXT( void )
1014 GET_CURRENT_CONTEXT(ctx
);
1015 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1017 if (MESA_VERBOSE
& VERBOSE_API
)
1018 _mesa_debug(ctx
, "glUnlockArrays\n");
1020 if (ctx
->Array
.LockCount
== 0) {
1021 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1025 ctx
->Array
.LockFirst
= 0;
1026 ctx
->Array
.LockCount
= 0;
1027 ctx
->NewState
|= _NEW_ARRAY
;
1028 ctx
->Array
.NewState
|= VERT_BIT_ALL
;
1032 /* GL_EXT_multi_draw_arrays */
1034 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
1035 const GLsizei
*count
, GLsizei primcount
)
1037 GET_CURRENT_CONTEXT(ctx
);
1040 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1042 for (i
= 0; i
< primcount
; i
++) {
1044 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1050 /* GL_IBM_multimode_draw_arrays */
1052 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1053 const GLsizei
* count
,
1054 GLsizei primcount
, GLint modestride
)
1056 GET_CURRENT_CONTEXT(ctx
);
1059 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1061 for ( i
= 0 ; i
< primcount
; i
++ ) {
1062 if ( count
[i
] > 0 ) {
1063 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1064 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1070 /* GL_IBM_multimode_draw_arrays */
1072 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1073 GLenum type
, const GLvoid
* const * indices
,
1074 GLsizei primcount
, GLint modestride
)
1076 GET_CURRENT_CONTEXT(ctx
);
1079 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1081 /* XXX not sure about ARB_vertex_buffer_object handling here */
1083 for ( i
= 0 ; i
< primcount
; i
++ ) {
1084 if ( count
[i
] > 0 ) {
1085 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1086 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1093 * GL_NV_primitive_restart and GL 3.1
1096 _mesa_PrimitiveRestartIndex(GLuint index
)
1098 GET_CURRENT_CONTEXT(ctx
);
1100 if (!ctx
->Extensions
.NV_primitive_restart
&&
1101 ctx
->VersionMajor
* 10 + ctx
->VersionMinor
< 31) {
1102 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1106 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1108 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1110 ctx
->Array
.RestartIndex
= index
;
1115 * See GL_ARB_instanced_arrays.
1116 * Note that the instance divisor only applies to generic arrays, not
1117 * the legacy vertex arrays.
1120 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1122 GET_CURRENT_CONTEXT(ctx
);
1123 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1125 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1126 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1130 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1131 _mesa_error(ctx
, GL_INVALID_ENUM
, "glVertexAttribDivisor(index = %u)",
1136 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].InstanceDivisor
= divisor
;
1142 * Copy one client vertex array to another.
1145 _mesa_copy_client_array(struct gl_context
*ctx
,
1146 struct gl_client_array
*dst
,
1147 struct gl_client_array
*src
)
1149 dst
->Size
= src
->Size
;
1150 dst
->Type
= src
->Type
;
1151 dst
->Format
= src
->Format
;
1152 dst
->Stride
= src
->Stride
;
1153 dst
->StrideB
= src
->StrideB
;
1154 dst
->Ptr
= src
->Ptr
;
1155 dst
->Enabled
= src
->Enabled
;
1156 dst
->Normalized
= src
->Normalized
;
1157 dst
->Integer
= src
->Integer
;
1158 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1159 dst
->_ElementSize
= src
->_ElementSize
;
1160 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1161 dst
->_MaxElement
= src
->_MaxElement
;
1167 * Print vertex array's fields.
1170 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1173 printf(" %s[%d]: ", name
, index
);
1175 printf(" %s: ", name
);
1176 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1177 array
->Ptr
, array
->Type
, array
->Size
,
1178 array
->_ElementSize
, array
->StrideB
,
1179 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1180 array
->_MaxElement
);
1185 * Print current vertex object/array info. For debug.
1188 _mesa_print_arrays(struct gl_context
*ctx
)
1190 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1193 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1195 printf("Array Object %u\n", arrayObj
->Name
);
1196 if (arrayObj
->Vertex
.Enabled
)
1197 print_array("Vertex", -1, &arrayObj
->Vertex
);
1198 if (arrayObj
->Normal
.Enabled
)
1199 print_array("Normal", -1, &arrayObj
->Normal
);
1200 if (arrayObj
->Color
.Enabled
)
1201 print_array("Color", -1, &arrayObj
->Color
);
1202 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1203 if (arrayObj
->TexCoord
[i
].Enabled
)
1204 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1205 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1206 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1207 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1208 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1213 * Initialize vertex array state for given context.
1216 _mesa_init_varray(struct gl_context
*ctx
)
1218 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1219 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1220 ctx
->Array
.DefaultArrayObj
);
1221 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1223 ctx
->Array
.Objects
= _mesa_NewHashTable();
1228 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1231 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1233 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1234 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1235 _mesa_delete_array_object(ctx
, arrayObj
);
1240 * Free vertex array state for given context.
1243 _mesa_free_varray_data(struct gl_context
*ctx
)
1245 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1246 _mesa_DeleteHashTable(ctx
->Array
.Objects
);