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 GLbitfield 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
->Ptr
= (const GLubyte
*) ptr
;
216 array
->_ElementSize
= elementSize
;
218 _mesa_reference_buffer_object(ctx
, &array
->BufferObj
,
219 ctx
->Array
.ArrayBufferObj
);
221 ctx
->NewState
|= _NEW_ARRAY
;
222 ctx
->Array
.NewState
|= dirtyBit
;
227 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
229 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
230 DOUBLE_BIT
| HALF_BIT
| FIXED_ES_BIT
|
231 UNSIGNED_INT_2_10_10_10_REV_BIT
|
232 INT_2_10_10_10_REV_BIT
);
233 GET_CURRENT_CONTEXT(ctx
);
234 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
236 if (ctx
->API
== API_OPENGLES
)
237 legalTypes
|= BYTE_BIT
;
239 update_array(ctx
, "glVertexPointer",
240 &ctx
->Array
.ArrayObj
->Vertex
, _NEW_ARRAY_VERTEX
,
242 size
, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
247 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
249 const GLbitfield legalTypes
= (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
250 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
252 UNSIGNED_INT_2_10_10_10_REV_BIT
|
253 INT_2_10_10_10_REV_BIT
);
254 GET_CURRENT_CONTEXT(ctx
);
255 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
257 update_array(ctx
, "glNormalPointer",
258 &ctx
->Array
.ArrayObj
->Normal
, _NEW_ARRAY_NORMAL
,
260 3, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
265 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
267 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
268 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
269 INT_BIT
| UNSIGNED_INT_BIT
|
270 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
272 UNSIGNED_INT_2_10_10_10_REV_BIT
|
273 INT_2_10_10_10_REV_BIT
);
274 GET_CURRENT_CONTEXT(ctx
);
275 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
277 update_array(ctx
, "glColorPointer",
278 &ctx
->Array
.ArrayObj
->Color
, _NEW_ARRAY_COLOR0
,
279 legalTypes
, 3, BGRA_OR_4
,
280 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
285 _mesa_FogCoordPointerEXT(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
287 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
288 GET_CURRENT_CONTEXT(ctx
);
289 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
291 update_array(ctx
, "glFogCoordPointer",
292 &ctx
->Array
.ArrayObj
->FogCoord
, _NEW_ARRAY_FOGCOORD
,
294 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
299 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
301 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
302 FLOAT_BIT
| DOUBLE_BIT
);
303 GET_CURRENT_CONTEXT(ctx
);
304 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
306 update_array(ctx
, "glIndexPointer",
307 &ctx
->Array
.ArrayObj
->Index
, _NEW_ARRAY_INDEX
,
309 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
314 _mesa_SecondaryColorPointerEXT(GLint size
, GLenum type
,
315 GLsizei stride
, const GLvoid
*ptr
)
317 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
318 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
319 INT_BIT
| UNSIGNED_INT_BIT
|
320 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
321 UNSIGNED_INT_2_10_10_10_REV_BIT
|
322 INT_2_10_10_10_REV_BIT
);
323 GET_CURRENT_CONTEXT(ctx
);
324 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
326 update_array(ctx
, "glSecondaryColorPointer",
327 &ctx
->Array
.ArrayObj
->SecondaryColor
, _NEW_ARRAY_COLOR1
,
328 legalTypes
, 3, BGRA_OR_4
,
329 size
, type
, stride
, GL_TRUE
, GL_FALSE
, ptr
);
334 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
337 GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
338 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
340 UNSIGNED_INT_2_10_10_10_REV_BIT
|
341 INT_2_10_10_10_REV_BIT
);
342 GET_CURRENT_CONTEXT(ctx
);
343 const GLuint unit
= ctx
->Array
.ActiveTexture
;
344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
346 if (ctx
->API
== API_OPENGLES
)
347 legalTypes
|= BYTE_BIT
;
349 ASSERT(unit
< Elements(ctx
->Array
.ArrayObj
->TexCoord
));
351 update_array(ctx
, "glTexCoordPointer",
352 &ctx
->Array
.ArrayObj
->TexCoord
[unit
],
353 _NEW_ARRAY_TEXCOORD(unit
),
355 size
, type
, stride
, GL_FALSE
, GL_FALSE
,
361 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
363 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
364 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
365 const GLboolean integer
= GL_TRUE
;
366 GET_CURRENT_CONTEXT(ctx
);
367 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
369 update_array(ctx
, "glEdgeFlagPointer",
370 &ctx
->Array
.ArrayObj
->EdgeFlag
, _NEW_ARRAY_EDGEFLAG
,
372 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, ptr
);
377 _mesa_PointSizePointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
379 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
380 GET_CURRENT_CONTEXT(ctx
);
381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
383 if (ctx
->API
!= API_OPENGLES
) {
384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
385 "glPointSizePointer(ES 1.x only)");
389 update_array(ctx
, "glPointSizePointer",
390 &ctx
->Array
.ArrayObj
->PointSize
, _NEW_ARRAY_POINT_SIZE
,
392 1, type
, stride
, GL_FALSE
, GL_FALSE
, ptr
);
396 #if FEATURE_NV_vertex_program
398 * Set a vertex attribute array.
399 * Note that these arrays DO alias the conventional GL vertex arrays
400 * (position, normal, color, fog, texcoord, etc).
401 * The generic attribute slots at #16 and above are not touched.
404 _mesa_VertexAttribPointerNV(GLuint index
, GLint size
, GLenum type
,
405 GLsizei stride
, const GLvoid
*ptr
)
407 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
|
408 FLOAT_BIT
| DOUBLE_BIT
);
409 GLboolean normalized
= GL_FALSE
;
410 GET_CURRENT_CONTEXT(ctx
);
411 ASSERT_OUTSIDE_BEGIN_END(ctx
);
413 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
414 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(index)");
418 if (type
== GL_UNSIGNED_BYTE
&& size
!= 4) {
419 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerNV(size!=4)");
423 update_array(ctx
, "glVertexAttribPointerNV",
424 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
425 _NEW_ARRAY_ATTRIB(index
),
426 legalTypes
, 1, BGRA_OR_4
,
427 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
432 #if FEATURE_ARB_vertex_program
434 * Set a generic vertex attribute array.
435 * Note that these arrays DO NOT alias the conventional GL vertex arrays
436 * (position, normal, color, fog, texcoord, etc).
439 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
440 GLboolean normalized
,
441 GLsizei stride
, const GLvoid
*ptr
)
443 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
444 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
445 INT_BIT
| UNSIGNED_INT_BIT
|
446 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
447 FIXED_ES_BIT
| FIXED_GL_BIT
|
448 UNSIGNED_INT_2_10_10_10_REV_BIT
|
449 INT_2_10_10_10_REV_BIT
);
450 GET_CURRENT_CONTEXT(ctx
);
451 ASSERT_OUTSIDE_BEGIN_END(ctx
);
453 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
454 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
458 update_array(ctx
, "glVertexAttribPointer",
459 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
460 _NEW_ARRAY_ATTRIB(index
),
461 legalTypes
, 1, BGRA_OR_4
,
462 size
, type
, stride
, normalized
, GL_FALSE
, ptr
);
468 * GL_EXT_gpu_shader4 / GL 3.0.
469 * Set an integer-valued vertex attribute array.
470 * Note that these arrays DO NOT alias the conventional GL vertex arrays
471 * (position, normal, color, fog, texcoord, etc).
474 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
475 GLsizei stride
, const GLvoid
*ptr
)
477 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
478 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
479 INT_BIT
| UNSIGNED_INT_BIT
);
480 const GLboolean normalized
= GL_FALSE
;
481 const GLboolean integer
= GL_TRUE
;
482 GET_CURRENT_CONTEXT(ctx
);
483 ASSERT_OUTSIDE_BEGIN_END(ctx
);
485 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
486 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
490 update_array(ctx
, "glVertexAttribIPointer",
491 &ctx
->Array
.ArrayObj
->VertexAttrib
[index
],
492 _NEW_ARRAY_ATTRIB(index
),
494 size
, type
, stride
, normalized
, integer
, ptr
);
500 _mesa_EnableVertexAttribArrayARB(GLuint index
)
502 GET_CURRENT_CONTEXT(ctx
);
503 ASSERT_OUTSIDE_BEGIN_END(ctx
);
505 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
506 _mesa_error(ctx
, GL_INVALID_VALUE
,
507 "glEnableVertexAttribArrayARB(index)");
511 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
513 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
514 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
515 ctx
->Array
.ArrayObj
->_Enabled
|= _NEW_ARRAY_ATTRIB(index
);
516 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
521 _mesa_DisableVertexAttribArrayARB(GLuint index
)
523 GET_CURRENT_CONTEXT(ctx
);
524 ASSERT_OUTSIDE_BEGIN_END(ctx
);
526 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
527 _mesa_error(ctx
, GL_INVALID_VALUE
,
528 "glDisableVertexAttribArrayARB(index)");
532 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
534 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
535 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
536 ctx
->Array
.ArrayObj
->_Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
537 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
542 * Return info for a vertex attribute array (no alias with legacy
543 * vertex attributes (pos, normal, color, etc)). This function does
544 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
547 get_vertex_array_attrib(struct gl_context
*ctx
, GLuint index
, GLenum pname
,
550 const struct gl_client_array
*array
;
552 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
553 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
557 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
559 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[index
];
562 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
563 return array
->Enabled
;
564 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
566 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
567 return array
->Stride
;
568 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
570 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
571 return array
->Normalized
;
572 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
573 return array
->BufferObj
->Name
;
574 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
575 if (ctx
->Extensions
.EXT_gpu_shader4
) {
576 return array
->Integer
;
579 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
580 if (ctx
->Extensions
.ARB_instanced_arrays
) {
581 return array
->InstanceDivisor
;
589 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
594 static const GLfloat
*
595 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
598 if (ctx
->API
!= API_OPENGLES2
) {
599 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
603 else if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
604 _mesa_error(ctx
, GL_INVALID_VALUE
,
605 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
609 FLUSH_CURRENT(ctx
, 0);
610 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
];
614 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
616 GET_CURRENT_CONTEXT(ctx
);
617 ASSERT_OUTSIDE_BEGIN_END(ctx
);
619 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
620 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
626 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, index
, pname
,
627 "glGetVertexAttribfv");
633 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
635 GET_CURRENT_CONTEXT(ctx
);
636 ASSERT_OUTSIDE_BEGIN_END(ctx
);
638 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
639 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
641 params
[0] = (GLdouble
) v
[0];
642 params
[1] = (GLdouble
) v
[1];
643 params
[2] = (GLdouble
) v
[2];
644 params
[3] = (GLdouble
) v
[3];
648 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, index
, pname
,
649 "glGetVertexAttribdv");
655 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
657 GET_CURRENT_CONTEXT(ctx
);
658 ASSERT_OUTSIDE_BEGIN_END(ctx
);
660 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
661 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
663 /* XXX should floats in[0,1] be scaled to full int range? */
664 params
[0] = (GLint
) v
[0];
665 params
[1] = (GLint
) v
[1];
666 params
[2] = (GLint
) v
[2];
667 params
[3] = (GLint
) v
[3];
671 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
672 "glGetVertexAttribiv");
679 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
681 GET_CURRENT_CONTEXT(ctx
);
682 ASSERT_OUTSIDE_BEGIN_END(ctx
);
684 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
686 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
688 /* XXX we don't have true integer-valued vertex attribs yet */
689 params
[0] = (GLint
) v
[0];
690 params
[1] = (GLint
) v
[1];
691 params
[2] = (GLint
) v
[2];
692 params
[3] = (GLint
) v
[3];
696 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, index
, pname
,
697 "glGetVertexAttribIiv");
704 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
706 GET_CURRENT_CONTEXT(ctx
);
707 ASSERT_OUTSIDE_BEGIN_END(ctx
);
709 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
711 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
713 /* XXX we don't have true integer-valued vertex attribs yet */
714 params
[0] = (GLuint
) v
[0];
715 params
[1] = (GLuint
) v
[1];
716 params
[2] = (GLuint
) v
[2];
717 params
[3] = (GLuint
) v
[3];
721 params
[0] = get_vertex_array_attrib(ctx
, index
, pname
,
722 "glGetVertexAttribIuiv");
728 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
730 GET_CURRENT_CONTEXT(ctx
);
731 ASSERT_OUTSIDE_BEGIN_END(ctx
);
733 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
734 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
738 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
739 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
743 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
745 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
750 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
751 GLsizei count
, const GLvoid
*ptr
)
754 _mesa_VertexPointer(size
, type
, stride
, ptr
);
759 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
763 _mesa_NormalPointer(type
, stride
, ptr
);
768 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
772 _mesa_ColorPointer(size
, type
, stride
, ptr
);
777 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
781 _mesa_IndexPointer(type
, stride
, ptr
);
786 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
787 GLsizei count
, const GLvoid
*ptr
)
790 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
795 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
798 _mesa_EdgeFlagPointer(stride
, ptr
);
803 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
805 GET_CURRENT_CONTEXT(ctx
);
806 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
807 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
808 GLenum ctype
= 0; /* color type */
809 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
810 const GLint toffset
= 0; /* always zero */
811 GLint defstride
; /* default stride */
814 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
817 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
820 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
826 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
827 tcomps
= 0; ccomps
= 0; vcomps
= 2;
832 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
833 tcomps
= 0; ccomps
= 0; vcomps
= 3;
838 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
839 tcomps
= 0; ccomps
= 4; vcomps
= 2;
840 ctype
= GL_UNSIGNED_BYTE
;
846 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
847 tcomps
= 0; ccomps
= 4; vcomps
= 3;
848 ctype
= GL_UNSIGNED_BYTE
;
854 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
855 tcomps
= 0; ccomps
= 3; vcomps
= 3;
862 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
863 tcomps
= 0; ccomps
= 0; vcomps
= 3;
869 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
870 tcomps
= 0; ccomps
= 4; vcomps
= 3;
878 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
879 tcomps
= 2; ccomps
= 0; vcomps
= 3;
884 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
885 tcomps
= 4; ccomps
= 0; vcomps
= 4;
889 case GL_T2F_C4UB_V3F
:
890 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
891 tcomps
= 2; ccomps
= 4; vcomps
= 3;
892 ctype
= GL_UNSIGNED_BYTE
;
898 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
899 tcomps
= 2; ccomps
= 3; vcomps
= 3;
906 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
907 tcomps
= 2; ccomps
= 0; vcomps
= 3;
912 case GL_T2F_C4F_N3F_V3F
:
913 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
914 tcomps
= 2; ccomps
= 4; vcomps
= 3;
921 case GL_T4F_C4F_N3F_V4F
:
922 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
923 tcomps
= 4; ccomps
= 4; vcomps
= 4;
931 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
939 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
940 _mesa_DisableClientState( GL_INDEX_ARRAY
);
941 /* XXX also disable secondary color and generic arrays? */
945 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
946 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
947 (GLubyte
*) pointer
+ toffset
);
950 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
955 _mesa_EnableClientState( GL_COLOR_ARRAY
);
956 _mesa_ColorPointer( ccomps
, ctype
, stride
,
957 (GLubyte
*) pointer
+ coffset
);
960 _mesa_DisableClientState( GL_COLOR_ARRAY
);
966 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
967 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
970 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
974 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
975 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
976 (GLubyte
*) pointer
+ voffset
);
981 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
983 GET_CURRENT_CONTEXT(ctx
);
984 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
986 if (MESA_VERBOSE
& VERBOSE_API
)
987 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
990 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
994 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
997 if (ctx
->Array
.LockCount
!= 0) {
998 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1002 ctx
->Array
.LockFirst
= first
;
1003 ctx
->Array
.LockCount
= count
;
1005 ctx
->NewState
|= _NEW_ARRAY
;
1006 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
1011 _mesa_UnlockArraysEXT( void )
1013 GET_CURRENT_CONTEXT(ctx
);
1014 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1016 if (MESA_VERBOSE
& VERBOSE_API
)
1017 _mesa_debug(ctx
, "glUnlockArrays\n");
1019 if (ctx
->Array
.LockCount
== 0) {
1020 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1024 ctx
->Array
.LockFirst
= 0;
1025 ctx
->Array
.LockCount
= 0;
1026 ctx
->NewState
|= _NEW_ARRAY
;
1027 ctx
->Array
.NewState
|= _NEW_ARRAY_ALL
;
1031 /* GL_EXT_multi_draw_arrays */
1033 _mesa_MultiDrawArraysEXT( GLenum mode
, const GLint
*first
,
1034 const GLsizei
*count
, GLsizei primcount
)
1036 GET_CURRENT_CONTEXT(ctx
);
1039 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1041 for (i
= 0; i
< primcount
; i
++) {
1043 CALL_DrawArrays(ctx
->Exec
, (mode
, first
[i
], count
[i
]));
1049 /* GL_IBM_multimode_draw_arrays */
1051 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1052 const GLsizei
* count
,
1053 GLsizei primcount
, GLint modestride
)
1055 GET_CURRENT_CONTEXT(ctx
);
1058 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1060 for ( i
= 0 ; i
< primcount
; i
++ ) {
1061 if ( count
[i
] > 0 ) {
1062 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1063 CALL_DrawArrays(ctx
->Exec
, ( m
, first
[i
], count
[i
] ));
1069 /* GL_IBM_multimode_draw_arrays */
1071 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1072 GLenum type
, const GLvoid
* const * indices
,
1073 GLsizei primcount
, GLint modestride
)
1075 GET_CURRENT_CONTEXT(ctx
);
1078 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1080 /* XXX not sure about ARB_vertex_buffer_object handling here */
1082 for ( i
= 0 ; i
< primcount
; i
++ ) {
1083 if ( count
[i
] > 0 ) {
1084 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1085 CALL_DrawElements(ctx
->Exec
, ( m
, count
[i
], type
, indices
[i
] ));
1092 * GL_NV_primitive_restart and GL 3.1
1095 _mesa_PrimitiveRestartIndex(GLuint index
)
1097 GET_CURRENT_CONTEXT(ctx
);
1099 if (!ctx
->Extensions
.NV_primitive_restart
&&
1100 ctx
->VersionMajor
* 10 + ctx
->VersionMinor
< 31) {
1101 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1105 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1107 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1109 ctx
->Array
.RestartIndex
= index
;
1114 * See GL_ARB_instanced_arrays.
1115 * Note that the instance divisor only applies to generic arrays, not
1116 * the legacy vertex arrays.
1119 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1121 GET_CURRENT_CONTEXT(ctx
);
1122 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1124 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1125 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1129 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
1130 _mesa_error(ctx
, GL_INVALID_ENUM
, "glVertexAttribDivisor(index = %u)",
1135 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].InstanceDivisor
= divisor
;
1141 * Copy one client vertex array to another.
1144 _mesa_copy_client_array(struct gl_context
*ctx
,
1145 struct gl_client_array
*dst
,
1146 struct gl_client_array
*src
)
1148 dst
->Size
= src
->Size
;
1149 dst
->Type
= src
->Type
;
1150 dst
->Format
= src
->Format
;
1151 dst
->Stride
= src
->Stride
;
1152 dst
->StrideB
= src
->StrideB
;
1153 dst
->Ptr
= src
->Ptr
;
1154 dst
->Enabled
= src
->Enabled
;
1155 dst
->Normalized
= src
->Normalized
;
1156 dst
->Integer
= src
->Integer
;
1157 dst
->InstanceDivisor
= src
->InstanceDivisor
;
1158 dst
->_ElementSize
= src
->_ElementSize
;
1159 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
1160 dst
->_MaxElement
= src
->_MaxElement
;
1166 * Print vertex array's fields.
1169 print_array(const char *name
, GLint index
, const struct gl_client_array
*array
)
1172 printf(" %s[%d]: ", name
, index
);
1174 printf(" %s: ", name
);
1175 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1176 array
->Ptr
, array
->Type
, array
->Size
,
1177 array
->_ElementSize
, array
->StrideB
,
1178 array
->BufferObj
->Name
, (unsigned long) array
->BufferObj
->Size
,
1179 array
->_MaxElement
);
1184 * Print current vertex object/array info. For debug.
1187 _mesa_print_arrays(struct gl_context
*ctx
)
1189 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
1192 _mesa_update_array_object_max_element(ctx
, arrayObj
);
1194 printf("Array Object %u\n", arrayObj
->Name
);
1195 if (arrayObj
->Vertex
.Enabled
)
1196 print_array("Vertex", -1, &arrayObj
->Vertex
);
1197 if (arrayObj
->Normal
.Enabled
)
1198 print_array("Normal", -1, &arrayObj
->Normal
);
1199 if (arrayObj
->Color
.Enabled
)
1200 print_array("Color", -1, &arrayObj
->Color
);
1201 for (i
= 0; i
< Elements(arrayObj
->TexCoord
); i
++)
1202 if (arrayObj
->TexCoord
[i
].Enabled
)
1203 print_array("TexCoord", i
, &arrayObj
->TexCoord
[i
]);
1204 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++)
1205 if (arrayObj
->VertexAttrib
[i
].Enabled
)
1206 print_array("Attrib", i
, &arrayObj
->VertexAttrib
[i
]);
1207 printf(" _MaxElement = %u\n", arrayObj
->_MaxElement
);
1212 * Initialize vertex array state for given context.
1215 _mesa_init_varray(struct gl_context
*ctx
)
1217 ctx
->Array
.DefaultArrayObj
= _mesa_new_array_object(ctx
, 0);
1218 _mesa_reference_array_object(ctx
, &ctx
->Array
.ArrayObj
,
1219 ctx
->Array
.DefaultArrayObj
);
1220 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
1222 ctx
->Array
.Objects
= _mesa_NewHashTable();
1227 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1230 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
1232 struct gl_array_object
*arrayObj
= (struct gl_array_object
*) data
;
1233 struct gl_context
*ctx
= (struct gl_context
*) userData
;
1234 _mesa_delete_array_object(ctx
, arrayObj
);
1239 * Free vertex array state for given context.
1242 _mesa_free_varray_data(struct gl_context
*ctx
)
1244 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
1245 _mesa_DeleteHashTable(ctx
->Array
.Objects
);