varray.c revision 3464ebd5
17117f1b4Smrg/*
27117f1b4Smrg * Mesa 3-D graphics library
34a49301eSmrg * Version:  7.6
47117f1b4Smrg *
5c1f859d4Smrg * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
64a49301eSmrg * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
77117f1b4Smrg *
87117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
97117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
107117f1b4Smrg * to deal in the Software without restriction, including without limitation
117117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
127117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
137117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
147117f1b4Smrg *
157117f1b4Smrg * The above copyright notice and this permission notice shall be included
167117f1b4Smrg * in all copies or substantial portions of the Software.
177117f1b4Smrg *
187117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
217117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
227117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
237117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
247117f1b4Smrg */
257117f1b4Smrg
267117f1b4Smrg
277117f1b4Smrg#include "glheader.h"
287117f1b4Smrg#include "imports.h"
297117f1b4Smrg#include "bufferobj.h"
307117f1b4Smrg#include "context.h"
317117f1b4Smrg#include "enable.h"
327117f1b4Smrg#include "enums.h"
334a49301eSmrg#include "hash.h"
343464ebd5Sriastradh#include "image.h"
353464ebd5Sriastradh#include "macros.h"
363464ebd5Sriastradh#include "mfeatures.h"
377117f1b4Smrg#include "mtypes.h"
387117f1b4Smrg#include "varray.h"
397117f1b4Smrg#include "arrayobj.h"
40cdc920a0Smrg#include "main/dispatch.h"
417117f1b4Smrg
427117f1b4Smrg
433464ebd5Sriastradh/** Used to do error checking for GL_EXT_vertex_array_bgra */
443464ebd5Sriastradh#define BGRA_OR_4  5
453464ebd5Sriastradh
463464ebd5Sriastradh
473464ebd5Sriastradh/** Used to indicate which GL datatypes are accepted by each of the
483464ebd5Sriastradh * glVertex/Color/Attrib/EtcPointer() functions.
493464ebd5Sriastradh */
503464ebd5Sriastradh#define BOOL_BIT             0x1
513464ebd5Sriastradh#define BYTE_BIT             0x2
523464ebd5Sriastradh#define UNSIGNED_BYTE_BIT    0x4
533464ebd5Sriastradh#define SHORT_BIT            0x8
543464ebd5Sriastradh#define UNSIGNED_SHORT_BIT   0x10
553464ebd5Sriastradh#define INT_BIT              0x20
563464ebd5Sriastradh#define UNSIGNED_INT_BIT     0x40
573464ebd5Sriastradh#define HALF_BIT             0x80
583464ebd5Sriastradh#define FLOAT_BIT            0x100
593464ebd5Sriastradh#define DOUBLE_BIT           0x200
603464ebd5Sriastradh#define FIXED_ES_BIT         0x400
613464ebd5Sriastradh#define FIXED_GL_BIT         0x800
623464ebd5Sriastradh
633464ebd5Sriastradh
643464ebd5Sriastradh/** Convert GL datatype enum into a <type>_BIT value seen above */
653464ebd5Sriastradhstatic GLbitfield
663464ebd5Sriastradhtype_to_bit(const struct gl_context *ctx, GLenum type)
673464ebd5Sriastradh{
683464ebd5Sriastradh   switch (type) {
693464ebd5Sriastradh   case GL_BOOL:
703464ebd5Sriastradh      return BOOL_BIT;
713464ebd5Sriastradh   case GL_BYTE:
723464ebd5Sriastradh      return BYTE_BIT;
733464ebd5Sriastradh   case GL_UNSIGNED_BYTE:
743464ebd5Sriastradh      return UNSIGNED_BYTE_BIT;
753464ebd5Sriastradh   case GL_SHORT:
763464ebd5Sriastradh      return SHORT_BIT;
773464ebd5Sriastradh   case GL_UNSIGNED_SHORT:
783464ebd5Sriastradh      return UNSIGNED_SHORT_BIT;
793464ebd5Sriastradh   case GL_INT:
803464ebd5Sriastradh      return INT_BIT;
813464ebd5Sriastradh   case GL_UNSIGNED_INT:
823464ebd5Sriastradh      return UNSIGNED_INT_BIT;
833464ebd5Sriastradh   case GL_HALF_FLOAT:
843464ebd5Sriastradh      if (ctx->Extensions.ARB_half_float_vertex)
853464ebd5Sriastradh         return HALF_BIT;
863464ebd5Sriastradh      else
873464ebd5Sriastradh         return 0x0;
883464ebd5Sriastradh   case GL_FLOAT:
893464ebd5Sriastradh      return FLOAT_BIT;
903464ebd5Sriastradh   case GL_DOUBLE:
913464ebd5Sriastradh      return DOUBLE_BIT;
923464ebd5Sriastradh   case GL_FIXED:
933464ebd5Sriastradh      return ctx->API == API_OPENGL ? FIXED_GL_BIT : FIXED_ES_BIT;
943464ebd5Sriastradh   default:
953464ebd5Sriastradh      return 0;
963464ebd5Sriastradh   }
973464ebd5Sriastradh}
983464ebd5Sriastradh
993464ebd5Sriastradh
1007117f1b4Smrg/**
1013464ebd5Sriastradh * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
1023464ebd5Sriastradh * functions.
1037117f1b4Smrg *
1043464ebd5Sriastradh * \param func  name of calling function used for error reporting
1057117f1b4Smrg * \param array  the array to update
1067117f1b4Smrg * \param dirtyBit  which bit to set in ctx->Array.NewState for this array
1073464ebd5Sriastradh * \param legalTypes  bitmask of *_BIT above indicating legal datatypes
1083464ebd5Sriastradh * \param sizeMin  min allowable size value
1093464ebd5Sriastradh * \param sizeMax  max allowable size value (may also be BGRA_OR_4)
1107117f1b4Smrg * \param size  components per element (1, 2, 3 or 4)
1117117f1b4Smrg * \param type  datatype of each component (GL_FLOAT, GL_INT, etc)
1127117f1b4Smrg * \param stride  stride between elements, in elements
1137117f1b4Smrg * \param normalized  are integer types converted to floats in [-1, 1]?
1143464ebd5Sriastradh * \param integer  integer-valued values (will not be normalized to [-1,1])
1157117f1b4Smrg * \param ptr  the address (or offset inside VBO) of the array data
1167117f1b4Smrg */
1177117f1b4Smrgstatic void
1183464ebd5Sriastradhupdate_array(struct gl_context *ctx,
1193464ebd5Sriastradh             const char *func,
1203464ebd5Sriastradh             struct gl_client_array *array,
1213464ebd5Sriastradh             GLbitfield dirtyBit, GLbitfield legalTypesMask,
1223464ebd5Sriastradh             GLint sizeMin, GLint sizeMax,
1233464ebd5Sriastradh             GLint size, GLenum type, GLsizei stride,
1243464ebd5Sriastradh             GLboolean normalized, GLboolean integer,
1253464ebd5Sriastradh             const GLvoid *ptr)
1267117f1b4Smrg{
1273464ebd5Sriastradh   GLbitfield typeBit;
1283464ebd5Sriastradh   GLsizei elementSize;
1293464ebd5Sriastradh   GLenum format = GL_RGBA;
1303464ebd5Sriastradh
1313464ebd5Sriastradh   if (ctx->API != API_OPENGLES && ctx->API != API_OPENGLES2) {
1323464ebd5Sriastradh      /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
1333464ebd5Sriastradh      legalTypesMask &= ~FIXED_ES_BIT;
1343464ebd5Sriastradh   }
1353464ebd5Sriastradh   if (!ctx->Extensions.ARB_ES2_compatibility) {
1363464ebd5Sriastradh      legalTypesMask &= ~FIXED_GL_BIT;
1373464ebd5Sriastradh   }
1383464ebd5Sriastradh
1393464ebd5Sriastradh   typeBit = type_to_bit(ctx, type);
1403464ebd5Sriastradh   if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
1413464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
1423464ebd5Sriastradh                  func, _mesa_lookup_enum_by_nr(type));
1433464ebd5Sriastradh      return;
1443464ebd5Sriastradh   }
1453464ebd5Sriastradh
1463464ebd5Sriastradh   /* Do size parameter checking.
1473464ebd5Sriastradh    * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
1483464ebd5Sriastradh    * must be handled specially.
1493464ebd5Sriastradh    */
1503464ebd5Sriastradh   if (ctx->Extensions.EXT_vertex_array_bgra &&
1513464ebd5Sriastradh       sizeMax == BGRA_OR_4 &&
1523464ebd5Sriastradh       size == GL_BGRA) {
1533464ebd5Sriastradh      if (type != GL_UNSIGNED_BYTE) {
1543464ebd5Sriastradh         _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func);
1553464ebd5Sriastradh         return;
1563464ebd5Sriastradh      }
1573464ebd5Sriastradh      format = GL_BGRA;
1583464ebd5Sriastradh      size = 4;
1593464ebd5Sriastradh   }
1603464ebd5Sriastradh   else if (size < sizeMin || size > sizeMax || size > 4) {
1613464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
1623464ebd5Sriastradh      return;
1633464ebd5Sriastradh   }
1643464ebd5Sriastradh
1653464ebd5Sriastradh   ASSERT(size <= 4);
1663464ebd5Sriastradh
1673464ebd5Sriastradh   if (stride < 0) {
1683464ebd5Sriastradh      _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
1693464ebd5Sriastradh      return;
1703464ebd5Sriastradh   }
1714a49301eSmrg
1724a49301eSmrg   if (ctx->Array.ArrayObj->VBOonly &&
1734a49301eSmrg       ctx->Array.ArrayBufferObj->Name == 0) {
1744a49301eSmrg      /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
1754a49301eSmrg       * Generate GL_INVALID_OPERATION if that's not true.
1764a49301eSmrg       */
1773464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
1784a49301eSmrg      return;
1794a49301eSmrg   }
1804a49301eSmrg
1813464ebd5Sriastradh   elementSize = _mesa_sizeof_type(type) * size;
1823464ebd5Sriastradh
1837117f1b4Smrg   array->Size = size;
1847117f1b4Smrg   array->Type = type;
1854a49301eSmrg   array->Format = format;
1867117f1b4Smrg   array->Stride = stride;
1877117f1b4Smrg   array->StrideB = stride ? stride : elementSize;
1887117f1b4Smrg   array->Normalized = normalized;
1897117f1b4Smrg   array->Ptr = (const GLubyte *) ptr;
1904a49301eSmrg   array->_ElementSize = elementSize;
1914a49301eSmrg
192c1f859d4Smrg   _mesa_reference_buffer_object(ctx, &array->BufferObj,
193c1f859d4Smrg                                 ctx->Array.ArrayBufferObj);
194c1f859d4Smrg
1957117f1b4Smrg   ctx->NewState |= _NEW_ARRAY;
1967117f1b4Smrg   ctx->Array.NewState |= dirtyBit;
1977117f1b4Smrg}
1987117f1b4Smrg
1997117f1b4Smrg
2007117f1b4Smrgvoid GLAPIENTRY
2017117f1b4Smrg_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
2027117f1b4Smrg{
2033464ebd5Sriastradh   GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
2043464ebd5Sriastradh                            DOUBLE_BIT | HALF_BIT | FIXED_ES_BIT);
2057117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2067117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2077117f1b4Smrg
2083464ebd5Sriastradh   if (ctx->API == API_OPENGLES)
2093464ebd5Sriastradh      legalTypes |= BYTE_BIT;
2107117f1b4Smrg
2113464ebd5Sriastradh   update_array(ctx, "glVertexPointer",
2123464ebd5Sriastradh                &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX,
2133464ebd5Sriastradh                legalTypes, 2, 4,
2143464ebd5Sriastradh                size, type, stride, GL_FALSE, GL_FALSE, ptr);
2157117f1b4Smrg}
2167117f1b4Smrg
2177117f1b4Smrg
2187117f1b4Smrgvoid GLAPIENTRY
2197117f1b4Smrg_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
2207117f1b4Smrg{
2213464ebd5Sriastradh   const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
2223464ebd5Sriastradh                                  HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
2233464ebd5Sriastradh                                  FIXED_ES_BIT);
2247117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2257117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2267117f1b4Smrg
2273464ebd5Sriastradh   update_array(ctx, "glNormalPointer",
2283464ebd5Sriastradh                &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL,
2293464ebd5Sriastradh                legalTypes, 3, 3,
2303464ebd5Sriastradh                3, type, stride, GL_TRUE, GL_FALSE, ptr);
2317117f1b4Smrg}
2327117f1b4Smrg
2337117f1b4Smrg
2347117f1b4Smrgvoid GLAPIENTRY
2357117f1b4Smrg_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
2367117f1b4Smrg{
2373464ebd5Sriastradh   const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
2383464ebd5Sriastradh                                  SHORT_BIT | UNSIGNED_SHORT_BIT |
2393464ebd5Sriastradh                                  INT_BIT | UNSIGNED_INT_BIT |
2403464ebd5Sriastradh                                  HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
2413464ebd5Sriastradh                                  FIXED_ES_BIT);
2427117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2437117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2447117f1b4Smrg
2453464ebd5Sriastradh   update_array(ctx, "glColorPointer",
2463464ebd5Sriastradh                &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0,
2473464ebd5Sriastradh                legalTypes, 3, BGRA_OR_4,
2483464ebd5Sriastradh                size, type, stride, GL_TRUE, GL_FALSE, ptr);
2497117f1b4Smrg}
2507117f1b4Smrg
2517117f1b4Smrg
2527117f1b4Smrgvoid GLAPIENTRY
2537117f1b4Smrg_mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
2547117f1b4Smrg{
2553464ebd5Sriastradh   const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
2567117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2577117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2587117f1b4Smrg
2593464ebd5Sriastradh   update_array(ctx, "glFogCoordPointer",
2603464ebd5Sriastradh                &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD,
2613464ebd5Sriastradh                legalTypes, 1, 1,
2623464ebd5Sriastradh                1, type, stride, GL_FALSE, GL_FALSE, ptr);
2637117f1b4Smrg}
2647117f1b4Smrg
2657117f1b4Smrg
2667117f1b4Smrgvoid GLAPIENTRY
2677117f1b4Smrg_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
2687117f1b4Smrg{
2693464ebd5Sriastradh   const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
2703464ebd5Sriastradh                                  FLOAT_BIT | DOUBLE_BIT);
2717117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2727117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2737117f1b4Smrg
2743464ebd5Sriastradh   update_array(ctx, "glIndexPointer",
2753464ebd5Sriastradh                &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX,
2763464ebd5Sriastradh                legalTypes, 1, 1,
2773464ebd5Sriastradh                1, type, stride, GL_FALSE, GL_FALSE, ptr);
2787117f1b4Smrg}
2797117f1b4Smrg
2807117f1b4Smrg
2817117f1b4Smrgvoid GLAPIENTRY
2827117f1b4Smrg_mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
2837117f1b4Smrg			       GLsizei stride, const GLvoid *ptr)
2847117f1b4Smrg{
2853464ebd5Sriastradh   const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
2863464ebd5Sriastradh                                  SHORT_BIT | UNSIGNED_SHORT_BIT |
2873464ebd5Sriastradh                                  INT_BIT | UNSIGNED_INT_BIT |
2883464ebd5Sriastradh                                  HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
2897117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
2907117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2917117f1b4Smrg
2923464ebd5Sriastradh   update_array(ctx, "glSecondaryColorPointer",
2933464ebd5Sriastradh                &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1,
2943464ebd5Sriastradh                legalTypes, 3, BGRA_OR_4,
2953464ebd5Sriastradh                size, type, stride, GL_TRUE, GL_FALSE, ptr);
2967117f1b4Smrg}
2977117f1b4Smrg
2987117f1b4Smrg
2997117f1b4Smrgvoid GLAPIENTRY
3007117f1b4Smrg_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
3017117f1b4Smrg                      const GLvoid *ptr)
3027117f1b4Smrg{
3033464ebd5Sriastradh   GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
3043464ebd5Sriastradh                            HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
3053464ebd5Sriastradh                            FIXED_ES_BIT);
3067117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3077117f1b4Smrg   const GLuint unit = ctx->Array.ActiveTexture;
3087117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3097117f1b4Smrg
3103464ebd5Sriastradh   if (ctx->API == API_OPENGLES)
3113464ebd5Sriastradh      legalTypes |= BYTE_BIT;
3127117f1b4Smrg
313cdc920a0Smrg   ASSERT(unit < Elements(ctx->Array.ArrayObj->TexCoord));
314cdc920a0Smrg
3153464ebd5Sriastradh   update_array(ctx, "glTexCoordPointer",
3163464ebd5Sriastradh                &ctx->Array.ArrayObj->TexCoord[unit],
3177117f1b4Smrg                _NEW_ARRAY_TEXCOORD(unit),
3183464ebd5Sriastradh                legalTypes, 1, 4,
3193464ebd5Sriastradh                size, type, stride, GL_FALSE, GL_FALSE,
3203464ebd5Sriastradh                ptr);
3217117f1b4Smrg}
3227117f1b4Smrg
3237117f1b4Smrg
3247117f1b4Smrgvoid GLAPIENTRY
3257117f1b4Smrg_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
3267117f1b4Smrg{
3273464ebd5Sriastradh   const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
3283464ebd5Sriastradh   /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
3293464ebd5Sriastradh   const GLboolean integer = GL_TRUE;
3307117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3317117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3327117f1b4Smrg
3333464ebd5Sriastradh   update_array(ctx, "glEdgeFlagPointer",
3343464ebd5Sriastradh                &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG,
3353464ebd5Sriastradh                legalTypes, 1, 1,
3363464ebd5Sriastradh                1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
3377117f1b4Smrg}
3387117f1b4Smrg
3397117f1b4Smrg
340c1f859d4Smrgvoid GLAPIENTRY
341c1f859d4Smrg_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
342c1f859d4Smrg{
3433464ebd5Sriastradh   const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
344c1f859d4Smrg   GET_CURRENT_CONTEXT(ctx);
345c1f859d4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
346c1f859d4Smrg
3473464ebd5Sriastradh   if (ctx->API != API_OPENGLES) {
3483464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_OPERATION,
3493464ebd5Sriastradh                  "glPointSizePointer(ES 1.x only)");
350c1f859d4Smrg      return;
351c1f859d4Smrg   }
3523464ebd5Sriastradh
3533464ebd5Sriastradh   update_array(ctx, "glPointSizePointer",
3543464ebd5Sriastradh                &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE,
3553464ebd5Sriastradh                legalTypes, 1, 1,
3563464ebd5Sriastradh                1, type, stride, GL_FALSE, GL_FALSE, ptr);
357c1f859d4Smrg}
358c1f859d4Smrg
359c1f859d4Smrg
3607117f1b4Smrg#if FEATURE_NV_vertex_program
3614a49301eSmrg/**
3624a49301eSmrg * Set a vertex attribute array.
3634a49301eSmrg * Note that these arrays DO alias the conventional GL vertex arrays
3644a49301eSmrg * (position, normal, color, fog, texcoord, etc).
3654a49301eSmrg * The generic attribute slots at #16 and above are not touched.
3664a49301eSmrg */
3677117f1b4Smrgvoid GLAPIENTRY
3687117f1b4Smrg_mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
3697117f1b4Smrg                            GLsizei stride, const GLvoid *ptr)
3707117f1b4Smrg{
3713464ebd5Sriastradh   const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT |
3723464ebd5Sriastradh                                  FLOAT_BIT | DOUBLE_BIT);
3737117f1b4Smrg   GLboolean normalized = GL_FALSE;
3747117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3757117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
3767117f1b4Smrg
3774a49301eSmrg   if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
3787117f1b4Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
3797117f1b4Smrg      return;
3807117f1b4Smrg   }
3817117f1b4Smrg
3827117f1b4Smrg   if (type == GL_UNSIGNED_BYTE && size != 4) {
3837117f1b4Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
3847117f1b4Smrg      return;
3857117f1b4Smrg   }
3867117f1b4Smrg
3873464ebd5Sriastradh   update_array(ctx, "glVertexAttribPointerNV",
3883464ebd5Sriastradh                &ctx->Array.ArrayObj->VertexAttrib[index],
3897117f1b4Smrg                _NEW_ARRAY_ATTRIB(index),
3903464ebd5Sriastradh                legalTypes, 1, BGRA_OR_4,
3913464ebd5Sriastradh                size, type, stride, normalized, GL_FALSE, ptr);
3927117f1b4Smrg}
3937117f1b4Smrg#endif
3947117f1b4Smrg
3957117f1b4Smrg
3967117f1b4Smrg#if FEATURE_ARB_vertex_program
3974a49301eSmrg/**
3984a49301eSmrg * Set a generic vertex attribute array.
3994a49301eSmrg * Note that these arrays DO NOT alias the conventional GL vertex arrays
4004a49301eSmrg * (position, normal, color, fog, texcoord, etc).
4014a49301eSmrg */
4027117f1b4Smrgvoid GLAPIENTRY
4037117f1b4Smrg_mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
4047117f1b4Smrg                             GLboolean normalized,
4057117f1b4Smrg                             GLsizei stride, const GLvoid *ptr)
4067117f1b4Smrg{
4073464ebd5Sriastradh   const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
4083464ebd5Sriastradh                                  SHORT_BIT | UNSIGNED_SHORT_BIT |
4093464ebd5Sriastradh                                  INT_BIT | UNSIGNED_INT_BIT |
4103464ebd5Sriastradh                                  HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
4113464ebd5Sriastradh                                  FIXED_ES_BIT | FIXED_GL_BIT);
4127117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
4137117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END(ctx);
4147117f1b4Smrg
4157117f1b4Smrg   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
4167117f1b4Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
4177117f1b4Smrg      return;
4187117f1b4Smrg   }
4197117f1b4Smrg
4203464ebd5Sriastradh   update_array(ctx, "glVertexAttribPointer",
4213464ebd5Sriastradh                &ctx->Array.ArrayObj->VertexAttrib[index],
4223464ebd5Sriastradh                _NEW_ARRAY_ATTRIB(index),
4233464ebd5Sriastradh                legalTypes, 1, BGRA_OR_4,
4243464ebd5Sriastradh                size, type, stride, normalized, GL_FALSE, ptr);
4253464ebd5Sriastradh}
4263464ebd5Sriastradh#endif
4273464ebd5Sriastradh
4283464ebd5Sriastradh
4293464ebd5Sriastradh/**
4303464ebd5Sriastradh * GL_EXT_gpu_shader4 / GL 3.0.
4313464ebd5Sriastradh * Set an integer-valued vertex attribute array.
4323464ebd5Sriastradh * Note that these arrays DO NOT alias the conventional GL vertex arrays
4333464ebd5Sriastradh * (position, normal, color, fog, texcoord, etc).
4343464ebd5Sriastradh */
4353464ebd5Sriastradhvoid GLAPIENTRY
4363464ebd5Sriastradh_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
4373464ebd5Sriastradh                           GLsizei stride, const GLvoid *ptr)
4383464ebd5Sriastradh{
4393464ebd5Sriastradh   const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
4403464ebd5Sriastradh                                  SHORT_BIT | UNSIGNED_SHORT_BIT |
4413464ebd5Sriastradh                                  INT_BIT | UNSIGNED_INT_BIT);
4423464ebd5Sriastradh   const GLboolean normalized = GL_FALSE;
4433464ebd5Sriastradh   const GLboolean integer = GL_TRUE;
4443464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
4453464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
4463464ebd5Sriastradh
4473464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
4483464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
4493464ebd5Sriastradh      return;
4507117f1b4Smrg   }
4517117f1b4Smrg
4523464ebd5Sriastradh   update_array(ctx, "glVertexAttribIPointer",
4533464ebd5Sriastradh                &ctx->Array.ArrayObj->VertexAttrib[index],
4543464ebd5Sriastradh                _NEW_ARRAY_ATTRIB(index),
4553464ebd5Sriastradh                legalTypes, 1, 4,
4563464ebd5Sriastradh                size, type, stride, normalized, integer, ptr);
4573464ebd5Sriastradh}
4583464ebd5Sriastradh
4593464ebd5Sriastradh
4603464ebd5Sriastradh
4613464ebd5Sriastradhvoid GLAPIENTRY
4623464ebd5Sriastradh_mesa_EnableVertexAttribArrayARB(GLuint index)
4633464ebd5Sriastradh{
4643464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
4653464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
4663464ebd5Sriastradh
4673464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
4683464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE,
4693464ebd5Sriastradh                  "glEnableVertexAttribArrayARB(index)");
4707117f1b4Smrg      return;
4717117f1b4Smrg   }
4727117f1b4Smrg
4733464ebd5Sriastradh   ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
4743464ebd5Sriastradh
4753464ebd5Sriastradh   FLUSH_VERTICES(ctx, _NEW_ARRAY);
4763464ebd5Sriastradh   ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
4773464ebd5Sriastradh   ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
4783464ebd5Sriastradh   ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
4793464ebd5Sriastradh}
4803464ebd5Sriastradh
4813464ebd5Sriastradh
4823464ebd5Sriastradhvoid GLAPIENTRY
4833464ebd5Sriastradh_mesa_DisableVertexAttribArrayARB(GLuint index)
4843464ebd5Sriastradh{
4853464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
4863464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
4873464ebd5Sriastradh
4883464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
4893464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE,
4903464ebd5Sriastradh                  "glDisableVertexAttribArrayARB(index)");
4913464ebd5Sriastradh      return;
4923464ebd5Sriastradh   }
4933464ebd5Sriastradh
4943464ebd5Sriastradh   ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
4953464ebd5Sriastradh
4963464ebd5Sriastradh   FLUSH_VERTICES(ctx, _NEW_ARRAY);
4973464ebd5Sriastradh   ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
4983464ebd5Sriastradh   ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
4993464ebd5Sriastradh   ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
5003464ebd5Sriastradh}
5013464ebd5Sriastradh
5023464ebd5Sriastradh
5033464ebd5Sriastradh/**
5043464ebd5Sriastradh * Return info for a vertex attribute array (no alias with legacy
5053464ebd5Sriastradh * vertex attributes (pos, normal, color, etc)).  This function does
5063464ebd5Sriastradh * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
5073464ebd5Sriastradh */
5083464ebd5Sriastradhstatic GLuint
5093464ebd5Sriastradhget_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
5103464ebd5Sriastradh                  const char *caller)
5113464ebd5Sriastradh{
5123464ebd5Sriastradh   const struct gl_client_array *array;
5133464ebd5Sriastradh
5143464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
5153464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
5163464ebd5Sriastradh      return 0;
5173464ebd5Sriastradh   }
5183464ebd5Sriastradh
5193464ebd5Sriastradh   ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
5203464ebd5Sriastradh
5213464ebd5Sriastradh   array = &ctx->Array.ArrayObj->VertexAttrib[index];
5223464ebd5Sriastradh
5233464ebd5Sriastradh   switch (pname) {
5243464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
5253464ebd5Sriastradh      return array->Enabled;
5263464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
5273464ebd5Sriastradh      return array->Size;
5283464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
5293464ebd5Sriastradh      return array->Stride;
5303464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
5313464ebd5Sriastradh      return array->Type;
5323464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
5333464ebd5Sriastradh      return array->Normalized;
5343464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
5353464ebd5Sriastradh      return array->BufferObj->Name;
5363464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
5373464ebd5Sriastradh      if (ctx->Extensions.EXT_gpu_shader4) {
5383464ebd5Sriastradh         return array->Integer;
5394a49301eSmrg      }
5403464ebd5Sriastradh      goto error;
5413464ebd5Sriastradh   case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
5423464ebd5Sriastradh      if (ctx->Extensions.ARB_instanced_arrays) {
5433464ebd5Sriastradh         return array->InstanceDivisor;
5444a49301eSmrg      }
5453464ebd5Sriastradh      goto error;
5463464ebd5Sriastradh   default:
5473464ebd5Sriastradh      ; /* fall-through */
5483464ebd5Sriastradh   }
5494a49301eSmrg
5503464ebd5Sriastradherror:
5513464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
5523464ebd5Sriastradh   return 0;
5533464ebd5Sriastradh}
5543464ebd5Sriastradh
5553464ebd5Sriastradh
5563464ebd5Sriastradhstatic const GLfloat *
5573464ebd5Sriastradhget_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
5583464ebd5Sriastradh{
5593464ebd5Sriastradh   if (index == 0) {
5603464ebd5Sriastradh      if (ctx->API != API_OPENGLES2) {
5613464ebd5Sriastradh	 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
5623464ebd5Sriastradh	 return NULL;
5633464ebd5Sriastradh      }
5643464ebd5Sriastradh   }
5653464ebd5Sriastradh   else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
5663464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE,
5673464ebd5Sriastradh		  "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
5683464ebd5Sriastradh      return NULL;
5693464ebd5Sriastradh   }
5703464ebd5Sriastradh
5713464ebd5Sriastradh   FLUSH_CURRENT(ctx, 0);
5723464ebd5Sriastradh   return ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index];
5733464ebd5Sriastradh}
5743464ebd5Sriastradh
5753464ebd5Sriastradhvoid GLAPIENTRY
5763464ebd5Sriastradh_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
5773464ebd5Sriastradh{
5783464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
5793464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
5803464ebd5Sriastradh
5813464ebd5Sriastradh   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
5823464ebd5Sriastradh      const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
5833464ebd5Sriastradh      if (v != NULL) {
5843464ebd5Sriastradh         COPY_4V(params, v);
5853464ebd5Sriastradh      }
5864a49301eSmrg   }
5874a49301eSmrg   else {
5883464ebd5Sriastradh      params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
5893464ebd5Sriastradh                                                    "glGetVertexAttribfv");
5904a49301eSmrg   }
5913464ebd5Sriastradh}
5924a49301eSmrg
5933464ebd5Sriastradh
5943464ebd5Sriastradhvoid GLAPIENTRY
5953464ebd5Sriastradh_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
5963464ebd5Sriastradh{
5973464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
5983464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
5993464ebd5Sriastradh
6003464ebd5Sriastradh   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
6013464ebd5Sriastradh      const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
6023464ebd5Sriastradh      if (v != NULL) {
6033464ebd5Sriastradh         params[0] = (GLdouble) v[0];
6043464ebd5Sriastradh         params[1] = (GLdouble) v[1];
6053464ebd5Sriastradh         params[2] = (GLdouble) v[2];
6063464ebd5Sriastradh         params[3] = (GLdouble) v[3];
6073464ebd5Sriastradh      }
6083464ebd5Sriastradh   }
6093464ebd5Sriastradh   else {
6103464ebd5Sriastradh      params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
6113464ebd5Sriastradh                                                     "glGetVertexAttribdv");
6127117f1b4Smrg   }
6133464ebd5Sriastradh}
6147117f1b4Smrg
6153464ebd5Sriastradh
6163464ebd5Sriastradhvoid GLAPIENTRY
6173464ebd5Sriastradh_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
6183464ebd5Sriastradh{
6193464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
6203464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
6213464ebd5Sriastradh
6223464ebd5Sriastradh   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
6233464ebd5Sriastradh      const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
6243464ebd5Sriastradh      if (v != NULL) {
6253464ebd5Sriastradh         /* XXX should floats in[0,1] be scaled to full int range? */
6263464ebd5Sriastradh         params[0] = (GLint) v[0];
6273464ebd5Sriastradh         params[1] = (GLint) v[1];
6283464ebd5Sriastradh         params[2] = (GLint) v[2];
6293464ebd5Sriastradh         params[3] = (GLint) v[3];
6303464ebd5Sriastradh      }
6313464ebd5Sriastradh   }
6323464ebd5Sriastradh   else {
6333464ebd5Sriastradh      params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
6343464ebd5Sriastradh                                                  "glGetVertexAttribiv");
6353464ebd5Sriastradh   }
6363464ebd5Sriastradh}
6373464ebd5Sriastradh
6383464ebd5Sriastradh
6393464ebd5Sriastradh/** GL 3.0 */
6403464ebd5Sriastradhvoid GLAPIENTRY
6413464ebd5Sriastradh_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
6423464ebd5Sriastradh{
6433464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
6443464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
6453464ebd5Sriastradh
6463464ebd5Sriastradh   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
6473464ebd5Sriastradh      const GLfloat *v =
6483464ebd5Sriastradh	 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
6493464ebd5Sriastradh      if (v != NULL) {
6503464ebd5Sriastradh         /* XXX we don't have true integer-valued vertex attribs yet */
6513464ebd5Sriastradh         params[0] = (GLint) v[0];
6523464ebd5Sriastradh         params[1] = (GLint) v[1];
6533464ebd5Sriastradh         params[2] = (GLint) v[2];
6543464ebd5Sriastradh         params[3] = (GLint) v[3];
6553464ebd5Sriastradh      }
6563464ebd5Sriastradh   }
6573464ebd5Sriastradh   else {
6583464ebd5Sriastradh      params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
6593464ebd5Sriastradh                                                  "glGetVertexAttribIiv");
6603464ebd5Sriastradh   }
6613464ebd5Sriastradh}
6623464ebd5Sriastradh
6633464ebd5Sriastradh
6643464ebd5Sriastradh/** GL 3.0 */
6653464ebd5Sriastradhvoid GLAPIENTRY
6663464ebd5Sriastradh_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
6673464ebd5Sriastradh{
6683464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
6693464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
6703464ebd5Sriastradh
6713464ebd5Sriastradh   if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
6723464ebd5Sriastradh      const GLfloat *v =
6733464ebd5Sriastradh	 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
6743464ebd5Sriastradh      if (v != NULL) {
6753464ebd5Sriastradh         /* XXX we don't have true integer-valued vertex attribs yet */
6763464ebd5Sriastradh         params[0] = (GLuint) v[0];
6773464ebd5Sriastradh         params[1] = (GLuint) v[1];
6783464ebd5Sriastradh         params[2] = (GLuint) v[2];
6793464ebd5Sriastradh         params[3] = (GLuint) v[3];
6803464ebd5Sriastradh      }
6813464ebd5Sriastradh   }
6823464ebd5Sriastradh   else {
6833464ebd5Sriastradh      params[0] = get_vertex_array_attrib(ctx, index, pname,
6843464ebd5Sriastradh                                          "glGetVertexAttribIuiv");
6853464ebd5Sriastradh   }
6863464ebd5Sriastradh}
6873464ebd5Sriastradh
6883464ebd5Sriastradh
6893464ebd5Sriastradhvoid GLAPIENTRY
6903464ebd5Sriastradh_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
6913464ebd5Sriastradh{
6923464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
6933464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END(ctx);
6943464ebd5Sriastradh
6953464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
6963464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
6973464ebd5Sriastradh      return;
6983464ebd5Sriastradh   }
6993464ebd5Sriastradh
7003464ebd5Sriastradh   if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
7013464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
7023464ebd5Sriastradh      return;
7033464ebd5Sriastradh   }
7043464ebd5Sriastradh
7053464ebd5Sriastradh   ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
7063464ebd5Sriastradh
7073464ebd5Sriastradh   *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
7087117f1b4Smrg}
7097117f1b4Smrg
7107117f1b4Smrg
7117117f1b4Smrgvoid GLAPIENTRY
7127117f1b4Smrg_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
7137117f1b4Smrg                       GLsizei count, const GLvoid *ptr)
7147117f1b4Smrg{
7157117f1b4Smrg   (void) count;
7167117f1b4Smrg   _mesa_VertexPointer(size, type, stride, ptr);
7177117f1b4Smrg}
7187117f1b4Smrg
7197117f1b4Smrg
7207117f1b4Smrgvoid GLAPIENTRY
7217117f1b4Smrg_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
7227117f1b4Smrg                       const GLvoid *ptr)
7237117f1b4Smrg{
7247117f1b4Smrg   (void) count;
7257117f1b4Smrg   _mesa_NormalPointer(type, stride, ptr);
7267117f1b4Smrg}
7277117f1b4Smrg
7287117f1b4Smrg
7297117f1b4Smrgvoid GLAPIENTRY
7307117f1b4Smrg_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
7317117f1b4Smrg                      const GLvoid *ptr)
7327117f1b4Smrg{
7337117f1b4Smrg   (void) count;
7347117f1b4Smrg   _mesa_ColorPointer(size, type, stride, ptr);
7357117f1b4Smrg}
7367117f1b4Smrg
7377117f1b4Smrg
7387117f1b4Smrgvoid GLAPIENTRY
7397117f1b4Smrg_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
7407117f1b4Smrg                      const GLvoid *ptr)
7417117f1b4Smrg{
7427117f1b4Smrg   (void) count;
7437117f1b4Smrg   _mesa_IndexPointer(type, stride, ptr);
7447117f1b4Smrg}
7457117f1b4Smrg
7467117f1b4Smrg
7477117f1b4Smrgvoid GLAPIENTRY
7487117f1b4Smrg_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
7497117f1b4Smrg                         GLsizei count, const GLvoid *ptr)
7507117f1b4Smrg{
7517117f1b4Smrg   (void) count;
7527117f1b4Smrg   _mesa_TexCoordPointer(size, type, stride, ptr);
7537117f1b4Smrg}
7547117f1b4Smrg
7557117f1b4Smrg
7567117f1b4Smrgvoid GLAPIENTRY
7577117f1b4Smrg_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
7587117f1b4Smrg{
7597117f1b4Smrg   (void) count;
7607117f1b4Smrg   _mesa_EdgeFlagPointer(stride, ptr);
7617117f1b4Smrg}
7627117f1b4Smrg
7637117f1b4Smrg
7647117f1b4Smrgvoid GLAPIENTRY
7657117f1b4Smrg_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
7667117f1b4Smrg{
7677117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7687117f1b4Smrg   GLboolean tflag, cflag, nflag;  /* enable/disable flags */
7697117f1b4Smrg   GLint tcomps, ccomps, vcomps;   /* components per texcoord, color, vertex */
7707117f1b4Smrg   GLenum ctype = 0;               /* color type */
7717117f1b4Smrg   GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
7727117f1b4Smrg   const GLint toffset = 0;        /* always zero */
7737117f1b4Smrg   GLint defstride;                /* default stride */
7747117f1b4Smrg   GLint c, f;
7757117f1b4Smrg
7767117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
7777117f1b4Smrg
7787117f1b4Smrg   f = sizeof(GLfloat);
7797117f1b4Smrg   c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
7807117f1b4Smrg
7817117f1b4Smrg   if (stride < 0) {
7827117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
7837117f1b4Smrg      return;
7847117f1b4Smrg   }
7857117f1b4Smrg
7867117f1b4Smrg   switch (format) {
7877117f1b4Smrg      case GL_V2F:
7887117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_FALSE;  nflag = GL_FALSE;
7897117f1b4Smrg         tcomps = 0;  ccomps = 0;  vcomps = 2;
7907117f1b4Smrg         voffset = 0;
7917117f1b4Smrg         defstride = 2*f;
7927117f1b4Smrg         break;
7937117f1b4Smrg      case GL_V3F:
7947117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_FALSE;  nflag = GL_FALSE;
7957117f1b4Smrg         tcomps = 0;  ccomps = 0;  vcomps = 3;
7967117f1b4Smrg         voffset = 0;
7977117f1b4Smrg         defstride = 3*f;
7987117f1b4Smrg         break;
7997117f1b4Smrg      case GL_C4UB_V2F:
8007117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_TRUE;  nflag = GL_FALSE;
8017117f1b4Smrg         tcomps = 0;  ccomps = 4;  vcomps = 2;
8027117f1b4Smrg         ctype = GL_UNSIGNED_BYTE;
8037117f1b4Smrg         coffset = 0;
8047117f1b4Smrg         voffset = c;
8057117f1b4Smrg         defstride = c + 2*f;
8067117f1b4Smrg         break;
8077117f1b4Smrg      case GL_C4UB_V3F:
8087117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_TRUE;  nflag = GL_FALSE;
8097117f1b4Smrg         tcomps = 0;  ccomps = 4;  vcomps = 3;
8107117f1b4Smrg         ctype = GL_UNSIGNED_BYTE;
8117117f1b4Smrg         coffset = 0;
8127117f1b4Smrg         voffset = c;
8137117f1b4Smrg         defstride = c + 3*f;
8147117f1b4Smrg         break;
8157117f1b4Smrg      case GL_C3F_V3F:
8167117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_TRUE;  nflag = GL_FALSE;
8177117f1b4Smrg         tcomps = 0;  ccomps = 3;  vcomps = 3;
8187117f1b4Smrg         ctype = GL_FLOAT;
8197117f1b4Smrg         coffset = 0;
8207117f1b4Smrg         voffset = 3*f;
8217117f1b4Smrg         defstride = 6*f;
8227117f1b4Smrg         break;
8237117f1b4Smrg      case GL_N3F_V3F:
8247117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_FALSE;  nflag = GL_TRUE;
8257117f1b4Smrg         tcomps = 0;  ccomps = 0;  vcomps = 3;
8267117f1b4Smrg         noffset = 0;
8277117f1b4Smrg         voffset = 3*f;
8287117f1b4Smrg         defstride = 6*f;
8297117f1b4Smrg         break;
8307117f1b4Smrg      case GL_C4F_N3F_V3F:
8317117f1b4Smrg         tflag = GL_FALSE;  cflag = GL_TRUE;  nflag = GL_TRUE;
8327117f1b4Smrg         tcomps = 0;  ccomps = 4;  vcomps = 3;
8337117f1b4Smrg         ctype = GL_FLOAT;
8347117f1b4Smrg         coffset = 0;
8357117f1b4Smrg         noffset = 4*f;
8367117f1b4Smrg         voffset = 7*f;
8377117f1b4Smrg         defstride = 10*f;
8387117f1b4Smrg         break;
8397117f1b4Smrg      case GL_T2F_V3F:
8407117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_FALSE;  nflag = GL_FALSE;
8417117f1b4Smrg         tcomps = 2;  ccomps = 0;  vcomps = 3;
8427117f1b4Smrg         voffset = 2*f;
8437117f1b4Smrg         defstride = 5*f;
8447117f1b4Smrg         break;
8457117f1b4Smrg      case GL_T4F_V4F:
8467117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_FALSE;  nflag = GL_FALSE;
8477117f1b4Smrg         tcomps = 4;  ccomps = 0;  vcomps = 4;
8487117f1b4Smrg         voffset = 4*f;
8497117f1b4Smrg         defstride = 8*f;
8507117f1b4Smrg         break;
8517117f1b4Smrg      case GL_T2F_C4UB_V3F:
8527117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_TRUE;  nflag = GL_FALSE;
8537117f1b4Smrg         tcomps = 2;  ccomps = 4;  vcomps = 3;
8547117f1b4Smrg         ctype = GL_UNSIGNED_BYTE;
8557117f1b4Smrg         coffset = 2*f;
8567117f1b4Smrg         voffset = c+2*f;
8577117f1b4Smrg         defstride = c+5*f;
8587117f1b4Smrg         break;
8597117f1b4Smrg      case GL_T2F_C3F_V3F:
8607117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_TRUE;  nflag = GL_FALSE;
8617117f1b4Smrg         tcomps = 2;  ccomps = 3;  vcomps = 3;
8627117f1b4Smrg         ctype = GL_FLOAT;
8637117f1b4Smrg         coffset = 2*f;
8647117f1b4Smrg         voffset = 5*f;
8657117f1b4Smrg         defstride = 8*f;
8667117f1b4Smrg         break;
8677117f1b4Smrg      case GL_T2F_N3F_V3F:
8687117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_FALSE;  nflag = GL_TRUE;
8697117f1b4Smrg         tcomps = 2;  ccomps = 0;  vcomps = 3;
8707117f1b4Smrg         noffset = 2*f;
8717117f1b4Smrg         voffset = 5*f;
8727117f1b4Smrg         defstride = 8*f;
8737117f1b4Smrg         break;
8747117f1b4Smrg      case GL_T2F_C4F_N3F_V3F:
8757117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_TRUE;  nflag = GL_TRUE;
8767117f1b4Smrg         tcomps = 2;  ccomps = 4;  vcomps = 3;
8777117f1b4Smrg         ctype = GL_FLOAT;
8787117f1b4Smrg         coffset = 2*f;
8797117f1b4Smrg         noffset = 6*f;
8807117f1b4Smrg         voffset = 9*f;
8817117f1b4Smrg         defstride = 12*f;
8827117f1b4Smrg         break;
8837117f1b4Smrg      case GL_T4F_C4F_N3F_V4F:
8847117f1b4Smrg         tflag = GL_TRUE;  cflag = GL_TRUE;  nflag = GL_TRUE;
8857117f1b4Smrg         tcomps = 4;  ccomps = 4;  vcomps = 4;
8867117f1b4Smrg         ctype = GL_FLOAT;
8877117f1b4Smrg         coffset = 4*f;
8887117f1b4Smrg         noffset = 8*f;
8897117f1b4Smrg         voffset = 11*f;
8907117f1b4Smrg         defstride = 15*f;
8917117f1b4Smrg         break;
8927117f1b4Smrg      default:
8937117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
8947117f1b4Smrg         return;
8957117f1b4Smrg   }
8967117f1b4Smrg
8977117f1b4Smrg   if (stride==0) {
8987117f1b4Smrg      stride = defstride;
8997117f1b4Smrg   }
9007117f1b4Smrg
9017117f1b4Smrg   _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
9027117f1b4Smrg   _mesa_DisableClientState( GL_INDEX_ARRAY );
9037117f1b4Smrg   /* XXX also disable secondary color and generic arrays? */
9047117f1b4Smrg
9057117f1b4Smrg   /* Texcoords */
9067117f1b4Smrg   if (tflag) {
9077117f1b4Smrg      _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
9087117f1b4Smrg      _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
9097117f1b4Smrg                             (GLubyte *) pointer + toffset );
9107117f1b4Smrg   }
9117117f1b4Smrg   else {
9127117f1b4Smrg      _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
9137117f1b4Smrg   }
9147117f1b4Smrg
9157117f1b4Smrg   /* Color */
9167117f1b4Smrg   if (cflag) {
9177117f1b4Smrg      _mesa_EnableClientState( GL_COLOR_ARRAY );
9187117f1b4Smrg      _mesa_ColorPointer( ccomps, ctype, stride,
9197117f1b4Smrg			  (GLubyte *) pointer + coffset );
9207117f1b4Smrg   }
9217117f1b4Smrg   else {
9227117f1b4Smrg      _mesa_DisableClientState( GL_COLOR_ARRAY );
9237117f1b4Smrg   }
9247117f1b4Smrg
9257117f1b4Smrg
9267117f1b4Smrg   /* Normals */
9277117f1b4Smrg   if (nflag) {
9287117f1b4Smrg      _mesa_EnableClientState( GL_NORMAL_ARRAY );
9297117f1b4Smrg      _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
9307117f1b4Smrg   }
9317117f1b4Smrg   else {
9327117f1b4Smrg      _mesa_DisableClientState( GL_NORMAL_ARRAY );
9337117f1b4Smrg   }
9347117f1b4Smrg
9357117f1b4Smrg   /* Vertices */
9367117f1b4Smrg   _mesa_EnableClientState( GL_VERTEX_ARRAY );
9377117f1b4Smrg   _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
9387117f1b4Smrg			(GLubyte *) pointer + voffset );
9397117f1b4Smrg}
9407117f1b4Smrg
9417117f1b4Smrg
9427117f1b4Smrgvoid GLAPIENTRY
9437117f1b4Smrg_mesa_LockArraysEXT(GLint first, GLsizei count)
9447117f1b4Smrg{
9457117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
9467117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
9477117f1b4Smrg
9487117f1b4Smrg   if (MESA_VERBOSE & VERBOSE_API)
9497117f1b4Smrg      _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
9507117f1b4Smrg
951c1f859d4Smrg   if (first < 0) {
952c1f859d4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
953c1f859d4Smrg      return;
9547117f1b4Smrg   }
955c1f859d4Smrg   if (count <= 0) {
956c1f859d4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
957c1f859d4Smrg      return;
958c1f859d4Smrg   }
959c1f859d4Smrg   if (ctx->Array.LockCount != 0) {
960c1f859d4Smrg      _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
961c1f859d4Smrg      return;
9627117f1b4Smrg   }
9637117f1b4Smrg
964c1f859d4Smrg   ctx->Array.LockFirst = first;
965c1f859d4Smrg   ctx->Array.LockCount = count;
966c1f859d4Smrg
9677117f1b4Smrg   ctx->NewState |= _NEW_ARRAY;
9687117f1b4Smrg   ctx->Array.NewState |= _NEW_ARRAY_ALL;
9697117f1b4Smrg}
9707117f1b4Smrg
9717117f1b4Smrg
9727117f1b4Smrgvoid GLAPIENTRY
9737117f1b4Smrg_mesa_UnlockArraysEXT( void )
9747117f1b4Smrg{
9757117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
9767117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
9777117f1b4Smrg
9787117f1b4Smrg   if (MESA_VERBOSE & VERBOSE_API)
9797117f1b4Smrg      _mesa_debug(ctx, "glUnlockArrays\n");
9807117f1b4Smrg
981c1f859d4Smrg   if (ctx->Array.LockCount == 0) {
982c1f859d4Smrg      _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
983c1f859d4Smrg      return;
984c1f859d4Smrg   }
985c1f859d4Smrg
9867117f1b4Smrg   ctx->Array.LockFirst = 0;
9877117f1b4Smrg   ctx->Array.LockCount = 0;
9887117f1b4Smrg   ctx->NewState |= _NEW_ARRAY;
9897117f1b4Smrg   ctx->Array.NewState |= _NEW_ARRAY_ALL;
9907117f1b4Smrg}
9917117f1b4Smrg
9927117f1b4Smrg
9937117f1b4Smrg/* GL_EXT_multi_draw_arrays */
9947117f1b4Smrgvoid GLAPIENTRY
9953464ebd5Sriastradh_mesa_MultiDrawArraysEXT( GLenum mode, const GLint *first,
9963464ebd5Sriastradh                          const GLsizei *count, GLsizei primcount )
9977117f1b4Smrg{
9987117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
9997117f1b4Smrg   GLint i;
10007117f1b4Smrg
10017117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
10027117f1b4Smrg
10037117f1b4Smrg   for (i = 0; i < primcount; i++) {
10047117f1b4Smrg      if (count[i] > 0) {
10057117f1b4Smrg         CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
10067117f1b4Smrg      }
10077117f1b4Smrg   }
10087117f1b4Smrg}
10097117f1b4Smrg
10107117f1b4Smrg
10117117f1b4Smrg/* GL_IBM_multimode_draw_arrays */
10127117f1b4Smrgvoid GLAPIENTRY
10137117f1b4Smrg_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
10147117f1b4Smrg			      const GLsizei * count,
10157117f1b4Smrg			      GLsizei primcount, GLint modestride )
10167117f1b4Smrg{
10177117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
10187117f1b4Smrg   GLint i;
10197117f1b4Smrg
10207117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
10217117f1b4Smrg
10227117f1b4Smrg   for ( i = 0 ; i < primcount ; i++ ) {
10237117f1b4Smrg      if ( count[i] > 0 ) {
10247117f1b4Smrg         GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
10257117f1b4Smrg	 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
10267117f1b4Smrg      }
10277117f1b4Smrg   }
10287117f1b4Smrg}
10297117f1b4Smrg
10307117f1b4Smrg
10317117f1b4Smrg/* GL_IBM_multimode_draw_arrays */
10327117f1b4Smrgvoid GLAPIENTRY
10337117f1b4Smrg_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
10347117f1b4Smrg				GLenum type, const GLvoid * const * indices,
10357117f1b4Smrg				GLsizei primcount, GLint modestride )
10367117f1b4Smrg{
10377117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
10387117f1b4Smrg   GLint i;
10397117f1b4Smrg
10407117f1b4Smrg   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
10417117f1b4Smrg
10427117f1b4Smrg   /* XXX not sure about ARB_vertex_buffer_object handling here */
10437117f1b4Smrg
10447117f1b4Smrg   for ( i = 0 ; i < primcount ; i++ ) {
10457117f1b4Smrg      if ( count[i] > 0 ) {
10467117f1b4Smrg         GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
10477117f1b4Smrg	 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
10487117f1b4Smrg      }
10497117f1b4Smrg   }
10507117f1b4Smrg}
10517117f1b4Smrg
10527117f1b4Smrg
10533464ebd5Sriastradh/**
10543464ebd5Sriastradh * GL_NV_primitive_restart and GL 3.1
10553464ebd5Sriastradh */
10563464ebd5Sriastradhvoid GLAPIENTRY
10573464ebd5Sriastradh_mesa_PrimitiveRestartIndex(GLuint index)
10583464ebd5Sriastradh{
10593464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
10603464ebd5Sriastradh
10613464ebd5Sriastradh   if (!ctx->Extensions.NV_primitive_restart &&
10623464ebd5Sriastradh       ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
10633464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
10643464ebd5Sriastradh      return;
10653464ebd5Sriastradh   }
10663464ebd5Sriastradh
10673464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
10683464ebd5Sriastradh
10693464ebd5Sriastradh   FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
10703464ebd5Sriastradh
10713464ebd5Sriastradh   ctx->Array.RestartIndex = index;
10723464ebd5Sriastradh}
10733464ebd5Sriastradh
10743464ebd5Sriastradh
10753464ebd5Sriastradh/**
10763464ebd5Sriastradh * See GL_ARB_instanced_arrays.
10773464ebd5Sriastradh * Note that the instance divisor only applies to generic arrays, not
10783464ebd5Sriastradh * the legacy vertex arrays.
10793464ebd5Sriastradh */
10803464ebd5Sriastradhvoid GLAPIENTRY
10813464ebd5Sriastradh_mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
10823464ebd5Sriastradh{
10833464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
10843464ebd5Sriastradh   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
10853464ebd5Sriastradh
10863464ebd5Sriastradh   if (!ctx->Extensions.ARB_instanced_arrays) {
10873464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
10883464ebd5Sriastradh      return;
10893464ebd5Sriastradh   }
10903464ebd5Sriastradh
10913464ebd5Sriastradh   if (index >= ctx->Const.VertexProgram.MaxAttribs) {
10923464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_ENUM, "glVertexAttribDivisor(index = %u)",
10933464ebd5Sriastradh                  index);
10943464ebd5Sriastradh      return;
10953464ebd5Sriastradh   }
10963464ebd5Sriastradh
10973464ebd5Sriastradh   ctx->Array.ArrayObj->VertexAttrib[index].InstanceDivisor = divisor;
10983464ebd5Sriastradh}
10993464ebd5Sriastradh
11003464ebd5Sriastradh
11013464ebd5Sriastradh
11024a49301eSmrg/**
11034a49301eSmrg * Copy one client vertex array to another.
11044a49301eSmrg */
11054a49301eSmrgvoid
11063464ebd5Sriastradh_mesa_copy_client_array(struct gl_context *ctx,
11074a49301eSmrg                        struct gl_client_array *dst,
11084a49301eSmrg                        struct gl_client_array *src)
11094a49301eSmrg{
11104a49301eSmrg   dst->Size = src->Size;
11114a49301eSmrg   dst->Type = src->Type;
11124a49301eSmrg   dst->Format = src->Format;
11134a49301eSmrg   dst->Stride = src->Stride;
11144a49301eSmrg   dst->StrideB = src->StrideB;
11154a49301eSmrg   dst->Ptr = src->Ptr;
11164a49301eSmrg   dst->Enabled = src->Enabled;
11174a49301eSmrg   dst->Normalized = src->Normalized;
11183464ebd5Sriastradh   dst->Integer = src->Integer;
11193464ebd5Sriastradh   dst->InstanceDivisor = src->InstanceDivisor;
11204a49301eSmrg   dst->_ElementSize = src->_ElementSize;
11214a49301eSmrg   _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
11224a49301eSmrg   dst->_MaxElement = src->_MaxElement;
11234a49301eSmrg}
11244a49301eSmrg
11254a49301eSmrg
11264a49301eSmrg
11274a49301eSmrg/**
11284a49301eSmrg * Print vertex array's fields.
11294a49301eSmrg */
11304a49301eSmrgstatic void
11314a49301eSmrgprint_array(const char *name, GLint index, const struct gl_client_array *array)
11324a49301eSmrg{
11334a49301eSmrg   if (index >= 0)
1134cdc920a0Smrg      printf("  %s[%d]: ", name, index);
11354a49301eSmrg   else
1136cdc920a0Smrg      printf("  %s: ", name);
11373464ebd5Sriastradh   printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1138cdc920a0Smrg	  array->Ptr, array->Type, array->Size,
1139cdc920a0Smrg	  array->_ElementSize, array->StrideB,
11403464ebd5Sriastradh	  array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
1141cdc920a0Smrg	  array->_MaxElement);
11424a49301eSmrg}
11434a49301eSmrg
11444a49301eSmrg
11454a49301eSmrg/**
11464a49301eSmrg * Print current vertex object/array info.  For debug.
11474a49301eSmrg */
11484a49301eSmrgvoid
11493464ebd5Sriastradh_mesa_print_arrays(struct gl_context *ctx)
11504a49301eSmrg{
11514a49301eSmrg   struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
11524a49301eSmrg   GLuint i;
11534a49301eSmrg
11544a49301eSmrg   _mesa_update_array_object_max_element(ctx, arrayObj);
11554a49301eSmrg
1156cdc920a0Smrg   printf("Array Object %u\n", arrayObj->Name);
11574a49301eSmrg   if (arrayObj->Vertex.Enabled)
11584a49301eSmrg      print_array("Vertex", -1, &arrayObj->Vertex);
11594a49301eSmrg   if (arrayObj->Normal.Enabled)
11604a49301eSmrg      print_array("Normal", -1, &arrayObj->Normal);
11614a49301eSmrg   if (arrayObj->Color.Enabled)
11624a49301eSmrg      print_array("Color", -1, &arrayObj->Color);
11634a49301eSmrg   for (i = 0; i < Elements(arrayObj->TexCoord); i++)
11644a49301eSmrg      if (arrayObj->TexCoord[i].Enabled)
11654a49301eSmrg         print_array("TexCoord", i, &arrayObj->TexCoord[i]);
11664a49301eSmrg   for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
11674a49301eSmrg      if (arrayObj->VertexAttrib[i].Enabled)
11684a49301eSmrg         print_array("Attrib", i, &arrayObj->VertexAttrib[i]);
1169cdc920a0Smrg   printf("  _MaxElement = %u\n", arrayObj->_MaxElement);
11704a49301eSmrg}
11714a49301eSmrg
11724a49301eSmrg
11737117f1b4Smrg/**
11747117f1b4Smrg * Initialize vertex array state for given context.
11757117f1b4Smrg */
11767117f1b4Smrgvoid
11773464ebd5Sriastradh_mesa_init_varray(struct gl_context *ctx)
11787117f1b4Smrg{
11797117f1b4Smrg   ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
11804a49301eSmrg   _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
11814a49301eSmrg                                ctx->Array.DefaultArrayObj);
11827117f1b4Smrg   ctx->Array.ActiveTexture = 0;   /* GL_ARB_multitexture */
11834a49301eSmrg
11844a49301eSmrg   ctx->Array.Objects = _mesa_NewHashTable();
11854a49301eSmrg}
11864a49301eSmrg
11874a49301eSmrg
11884a49301eSmrg/**
11894a49301eSmrg * Callback for deleting an array object.  Called by _mesa_HashDeleteAll().
11904a49301eSmrg */
11914a49301eSmrgstatic void
11924a49301eSmrgdelete_arrayobj_cb(GLuint id, void *data, void *userData)
11934a49301eSmrg{
11944a49301eSmrg   struct gl_array_object *arrayObj = (struct gl_array_object *) data;
11953464ebd5Sriastradh   struct gl_context *ctx = (struct gl_context *) userData;
11964a49301eSmrg   _mesa_delete_array_object(ctx, arrayObj);
11974a49301eSmrg}
11984a49301eSmrg
11994a49301eSmrg
12004a49301eSmrg/**
12014a49301eSmrg * Free vertex array state for given context.
12024a49301eSmrg */
12034a49301eSmrgvoid
12043464ebd5Sriastradh_mesa_free_varray_data(struct gl_context *ctx)
12054a49301eSmrg{
12064a49301eSmrg   _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
12074a49301eSmrg   _mesa_DeleteHashTable(ctx->Array.Objects);
12087117f1b4Smrg}
1209