X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fvarray.c;h=106252e46098c12455b014da6a43661e928ef564;hb=b6e8256899a9a93c665c34e10efcc918f2fcc095;hp=1b540eff44749c5b404047a2efb71b6bf2bb847d;hpb=3c63452e64df7e10aa073c6c3b9492b1d7dabbb8;p=mesa.git diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 1b540eff447..106252e4609 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -1,10 +1,8 @@ -/* $Id: varray.c,v 1.47 2002/10/24 23:57:21 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 4.1 + * Version: 7.2 * - * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,25 +22,72 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + #include "glheader.h" +#include "imports.h" +#include "bufferobj.h" #include "context.h" #include "enable.h" #include "enums.h" -#include "dlist.h" -#include "light.h" -#include "macros.h" -#include "mmath.h" -#include "state.h" -#include "texstate.h" #include "mtypes.h" #include "varray.h" -#include "math/m_translate.h" +#include "arrayobj.h" +#include "glapi/dispatch.h" +/** + * Update the fields of a vertex array object. + * We need to do a few special things for arrays that live in + * vertex buffer objects. + * + * \param array the array to update + * \param dirtyBit which bit to set in ctx->Array.NewState for this array + * \param elementSize size of each array element, in bytes + * \param size components per element (1, 2, 3 or 4) + * \param type datatype of each component (GL_FLOAT, GL_INT, etc) + * \param stride stride between elements, in elements + * \param normalized are integer types converted to floats in [-1, 1]? + * \param ptr the address (or offset inside VBO) of the array data + */ +static void +update_array(GLcontext *ctx, struct gl_client_array *array, + GLbitfield dirtyBit, GLsizei elementSize, + GLint size, GLenum type, GLenum format, + GLsizei stride, GLboolean normalized, const GLvoid *ptr) +{ + ASSERT(format == GL_RGBA || format == GL_BGRA); + array->Size = size; + array->Type = type; + array->Format = format; + array->Stride = stride; + array->StrideB = stride ? stride : elementSize; + array->Normalized = normalized; + array->Ptr = (const GLubyte *) ptr; +#if FEATURE_ARB_vertex_buffer_object + _mesa_reference_buffer_object(ctx, &array->BufferObj, + ctx->Array.ArrayBufferObj); + + /* Compute the index of the last array element that's inside the buffer. + * Later in glDrawArrays we'll check if start + count > _MaxElement to + * be sure we won't go out of bounds. + */ + if (ctx->Array.ArrayBufferObj->Name) + array->_MaxElement = ((GLsizeiptrARB) ctx->Array.ArrayBufferObj->Size + - (GLsizeiptrARB) array->Ptr + array->StrideB + - elementSize) / array->StrideB; + else +#endif + array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */ -void + ctx->NewState |= _NEW_ARRAY; + ctx->Array.NewState |= dirtyBit; +} + + +void GLAPIENTRY _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { + GLsizei elementSize; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); @@ -62,42 +107,44 @@ _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) /* always need to check that is legal */ switch (type) { case GL_SHORT: - ctx->Array.Vertex.StrideB = size * sizeof(GLshort); + elementSize = size * sizeof(GLshort); break; case GL_INT: - ctx->Array.Vertex.StrideB = size * sizeof(GLint); + elementSize = size * sizeof(GLint); break; case GL_FLOAT: - ctx->Array.Vertex.StrideB = size * sizeof(GLfloat); + elementSize = size * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.Vertex.StrideB = size * sizeof(GLdouble); + elementSize = size * sizeof(GLdouble); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = size * sizeof(GLfixed); + break; +#endif +#if FEATURE_vertex_array_byte + case GL_BYTE: + elementSize = size * sizeof(GLbyte); break; +#endif default: _mesa_error( ctx, GL_INVALID_ENUM, "glVertexPointer(type)" ); return; } - if (stride) - ctx->Array.Vertex.StrideB = stride; - - ctx->Array.Vertex.Size = size; - ctx->Array.Vertex.Type = type; - ctx->Array.Vertex.Stride = stride; - ctx->Array.Vertex.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_VERTEX; + update_array(ctx, &ctx->Array.ArrayObj->Vertex, _NEW_ARRAY_VERTEX, + elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.VertexPointer) ctx->Driver.VertexPointer( ctx, size, type, stride, ptr ); } - - -void +void GLAPIENTRY _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) { + GLsizei elementSize; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); @@ -112,51 +159,53 @@ _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) switch (type) { case GL_BYTE: - ctx->Array.Normal.StrideB = 3 * sizeof(GLbyte); + elementSize = 3 * sizeof(GLbyte); break; case GL_SHORT: - ctx->Array.Normal.StrideB = 3 * sizeof(GLshort); + elementSize = 3 * sizeof(GLshort); break; case GL_INT: - ctx->Array.Normal.StrideB = 3 * sizeof(GLint); + elementSize = 3 * sizeof(GLint); break; case GL_FLOAT: - ctx->Array.Normal.StrideB = 3 * sizeof(GLfloat); + elementSize = 3 * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.Normal.StrideB = 3 * sizeof(GLdouble); + elementSize = 3 * sizeof(GLdouble); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = 3 * sizeof(GLfixed); break; +#endif default: _mesa_error( ctx, GL_INVALID_ENUM, "glNormalPointer(type)" ); return; } - if (stride) - ctx->Array.Normal.StrideB = stride; - ctx->Array.Normal.Size = 3; - ctx->Array.Normal.Type = type; - ctx->Array.Normal.Stride = stride; - ctx->Array.Normal.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_NORMAL; + update_array(ctx, &ctx->Array.ArrayObj->Normal, _NEW_ARRAY_NORMAL, + elementSize, 3, type, GL_RGBA, stride, GL_TRUE, ptr); if (ctx->Driver.NormalPointer) ctx->Driver.NormalPointer( ctx, type, stride, ptr ); } - -void +void GLAPIENTRY _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { + GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (size < 3 || size > 4) { - _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(size)" ); - return; + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(size)"); + return; + } } - if (stride<0) { + if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glColorPointer(stride)" ); return; } @@ -165,55 +214,65 @@ _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) _mesa_debug(ctx, "glColorPointer( sz %d type %s stride %d )\n", size, _mesa_lookup_enum_by_nr( type ), stride); + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)"); + return; + } + format = GL_BGRA; + size = 4; + } + else { + format = GL_RGBA; + } + switch (type) { case GL_BYTE: - ctx->Array.Color.StrideB = size * sizeof(GLbyte); + elementSize = size * sizeof(GLbyte); break; case GL_UNSIGNED_BYTE: - ctx->Array.Color.StrideB = size * sizeof(GLubyte); + elementSize = size * sizeof(GLubyte); break; case GL_SHORT: - ctx->Array.Color.StrideB = size * sizeof(GLshort); + elementSize = size * sizeof(GLshort); break; case GL_UNSIGNED_SHORT: - ctx->Array.Color.StrideB = size * sizeof(GLushort); + elementSize = size * sizeof(GLushort); break; case GL_INT: - ctx->Array.Color.StrideB = size * sizeof(GLint); + elementSize = size * sizeof(GLint); break; case GL_UNSIGNED_INT: - ctx->Array.Color.StrideB = size * sizeof(GLuint); + elementSize = size * sizeof(GLuint); break; case GL_FLOAT: - ctx->Array.Color.StrideB = size * sizeof(GLfloat); + elementSize = size * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.Color.StrideB = size * sizeof(GLdouble); + elementSize = size * sizeof(GLdouble); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = size * sizeof(GLfixed); break; +#endif default: _mesa_error( ctx, GL_INVALID_ENUM, "glColorPointer(type)" ); return; } - if (stride) - ctx->Array.Color.StrideB = stride; - - ctx->Array.Color.Size = size; - ctx->Array.Color.Type = type; - ctx->Array.Color.Stride = stride; - ctx->Array.Color.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_COLOR0; + update_array(ctx, &ctx->Array.ArrayObj->Color, _NEW_ARRAY_COLOR0, + elementSize, size, type, format, stride, GL_TRUE, ptr); if (ctx->Driver.ColorPointer) ctx->Driver.ColorPointer( ctx, size, type, stride, ptr ); } - -void +void GLAPIENTRY _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr) { + GLint elementSize; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); @@ -224,34 +283,28 @@ _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr) switch (type) { case GL_FLOAT: - ctx->Array.FogCoord.StrideB = sizeof(GLfloat); + elementSize = sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.FogCoord.StrideB = sizeof(GLdouble); + elementSize = sizeof(GLdouble); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glFogCoordPointer(type)" ); return; } - if (stride) - ctx->Array.FogCoord.StrideB = stride; - - ctx->Array.FogCoord.Size = 1; - ctx->Array.FogCoord.Type = type; - ctx->Array.FogCoord.Stride = stride; - ctx->Array.FogCoord.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_FOGCOORD; + update_array(ctx, &ctx->Array.ArrayObj->FogCoord, _NEW_ARRAY_FOGCOORD, + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.FogCoordPointer) ctx->Driver.FogCoordPointer( ctx, type, stride, ptr ); } -void +void GLAPIENTRY _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) { + GLsizei elementSize; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); @@ -262,50 +315,47 @@ _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) switch (type) { case GL_UNSIGNED_BYTE: - ctx->Array.Index.StrideB = sizeof(GLubyte); + elementSize = sizeof(GLubyte); break; case GL_SHORT: - ctx->Array.Index.StrideB = sizeof(GLshort); + elementSize = sizeof(GLshort); break; case GL_INT: - ctx->Array.Index.StrideB = sizeof(GLint); + elementSize = sizeof(GLint); break; case GL_FLOAT: - ctx->Array.Index.StrideB = sizeof(GLfloat); + elementSize = sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.Index.StrideB = sizeof(GLdouble); + elementSize = sizeof(GLdouble); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glIndexPointer(type)" ); return; } - if (stride) - ctx->Array.Index.StrideB = stride; - - ctx->Array.Index.Size = 1; - ctx->Array.Index.Type = type; - ctx->Array.Index.Stride = stride; - ctx->Array.Index.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_INDEX; + update_array(ctx, &ctx->Array.ArrayObj->Index, _NEW_ARRAY_INDEX, + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.IndexPointer) ctx->Driver.IndexPointer( ctx, type, stride, ptr ); } -void +void GLAPIENTRY _mesa_SecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { + GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (size != 3 && size != 4) { - _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)" ); - return; + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(size)"); + return; + } } if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glSecondaryColorPointer(stride)" ); @@ -316,58 +366,63 @@ _mesa_SecondaryColorPointerEXT(GLint size, GLenum type, _mesa_debug(ctx, "glSecondaryColorPointer( sz %d type %s stride %d )\n", size, _mesa_lookup_enum_by_nr( type ), stride); + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, "glColorPointer(GL_BGRA/GLubyte)"); + return; + } + format = GL_BGRA; + size = 4; + } + else { + format = GL_RGBA; + } + switch (type) { case GL_BYTE: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLbyte); + elementSize = size * sizeof(GLbyte); break; case GL_UNSIGNED_BYTE: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLubyte); + elementSize = size * sizeof(GLubyte); break; case GL_SHORT: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLshort); + elementSize = size * sizeof(GLshort); break; case GL_UNSIGNED_SHORT: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLushort); + elementSize = size * sizeof(GLushort); break; case GL_INT: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLint); + elementSize = size * sizeof(GLint); break; case GL_UNSIGNED_INT: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLuint); + elementSize = size * sizeof(GLuint); break; case GL_FLOAT: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLfloat); + elementSize = size * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.SecondaryColor.StrideB = size * sizeof(GLdouble); + elementSize = size * sizeof(GLdouble); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glSecondaryColorPointer(type)" ); return; } - if (stride) - ctx->Array.SecondaryColor.StrideB = stride; - - ctx->Array.SecondaryColor.Size = 3; /* hardwire */ - ctx->Array.SecondaryColor.Type = type; - ctx->Array.SecondaryColor.Stride = stride; - ctx->Array.SecondaryColor.Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_COLOR1; + update_array(ctx, &ctx->Array.ArrayObj->SecondaryColor, _NEW_ARRAY_COLOR1, + elementSize, size, type, format, stride, GL_TRUE, ptr); if (ctx->Driver.SecondaryColorPointer) ctx->Driver.SecondaryColorPointer( ctx, size, type, stride, ptr ); } - -void +void GLAPIENTRY _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) { + GLint elementSize; GET_CURRENT_CONTEXT(ctx); - GLuint texUnit = ctx->Array.ActiveTexture; + const GLuint unit = ctx->Array.ActiveTexture; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); if (size < 1 || size > 4) { @@ -381,71 +436,108 @@ _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, if (MESA_VERBOSE&(VERBOSE_VARRAY|VERBOSE_API)) _mesa_debug(ctx, "glTexCoordPointer(unit %u sz %d type %s stride %d)\n", - texUnit, size, _mesa_lookup_enum_by_nr( type ), stride); + unit, size, _mesa_lookup_enum_by_nr( type ), stride); /* always need to check that is legal */ switch (type) { case GL_SHORT: - ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLshort); + elementSize = size * sizeof(GLshort); break; case GL_INT: - ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLint); + elementSize = size * sizeof(GLint); break; case GL_FLOAT: - ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLfloat); + elementSize = size * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.TexCoord[texUnit].StrideB = size * sizeof(GLdouble); + elementSize = size * sizeof(GLdouble); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = size * sizeof(GLfixed); break; +#endif +#if FEATURE_vertex_array_byte + case GL_BYTE: + elementSize = size * sizeof(GLbyte); + break; +#endif default: _mesa_error( ctx, GL_INVALID_ENUM, "glTexCoordPointer(type)" ); return; } - if (stride) - ctx->Array.TexCoord[texUnit].StrideB = stride; - - ctx->Array.TexCoord[texUnit].Size = size; - ctx->Array.TexCoord[texUnit].Type = type; - ctx->Array.TexCoord[texUnit].Stride = stride; - ctx->Array.TexCoord[texUnit].Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_TEXCOORD(texUnit); + update_array(ctx, &ctx->Array.ArrayObj->TexCoord[unit], + _NEW_ARRAY_TEXCOORD(unit), + elementSize, size, type, GL_RGBA, stride, GL_FALSE, ptr); if (ctx->Driver.TexCoordPointer) ctx->Driver.TexCoordPointer( ctx, size, type, stride, ptr ); } -void -_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *vptr) +void GLAPIENTRY +_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr) { GET_CURRENT_CONTEXT(ctx); - const GLboolean *ptr = (GLboolean *)vptr; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); - if (stride<0) { + if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glEdgeFlagPointer(stride)" ); return; } - ctx->Array.EdgeFlag.Stride = stride; - ctx->Array.EdgeFlag.StrideB = stride ? stride : sizeof(GLboolean); - ctx->Array.EdgeFlag.Ptr = (GLboolean *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_EDGEFLAG; + + update_array(ctx, &ctx->Array.ArrayObj->EdgeFlag, _NEW_ARRAY_EDGEFLAG, + sizeof(GLboolean), 1, GL_UNSIGNED_BYTE, GL_RGBA, + stride, GL_FALSE, ptr); if (ctx->Driver.EdgeFlagPointer) ctx->Driver.EdgeFlagPointer( ctx, stride, ptr ); } -void _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr) +void GLAPIENTRY +_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr) +{ + GLsizei elementSize; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + if (stride < 0) { + _mesa_error( ctx, GL_INVALID_VALUE, "glPointSizePointer(stride)" ); + return; + } + + switch (type) { + case GL_FLOAT: + elementSize = sizeof(GLfloat); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = sizeof(GLfixed); + break; +#endif + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glPointSizePointer(type)" ); + return; + } + + update_array(ctx, &ctx->Array.ArrayObj->PointSize, _NEW_ARRAY_POINT_SIZE, + elementSize, 1, type, GL_RGBA, stride, GL_FALSE, ptr); +} + + +#if FEATURE_NV_vertex_program +void GLAPIENTRY +_mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr) { + GLboolean normalized = GL_FALSE; + GLsizei elementSize; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); - if (index >= VERT_ATTRIB_MAX) { + if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) { _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)"); return; } @@ -468,39 +560,123 @@ void _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, /* check for valid 'type' and compute StrideB right away */ switch (type) { case GL_UNSIGNED_BYTE: - ctx->Array.VertexAttrib[index].StrideB = size * sizeof(GLubyte); + normalized = GL_TRUE; + elementSize = size * sizeof(GLubyte); break; case GL_SHORT: - ctx->Array.VertexAttrib[index].StrideB = size * sizeof(GLshort); + elementSize = size * sizeof(GLshort); break; case GL_FLOAT: - ctx->Array.VertexAttrib[index].StrideB = size * sizeof(GLfloat); + elementSize = size * sizeof(GLfloat); break; case GL_DOUBLE: - ctx->Array.VertexAttrib[index].StrideB = size * sizeof(GLdouble); + elementSize = size * sizeof(GLdouble); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerNV(type)" ); return; } - if (stride) - ctx->Array.VertexAttrib[index].StrideB = stride; + update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], + _NEW_ARRAY_ATTRIB(index), + elementSize, size, type, GL_RGBA, stride, normalized, ptr); + + if (ctx->Driver.VertexAttribPointer) + ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr ); +} +#endif - ctx->Array.VertexAttrib[index].Stride = stride; - ctx->Array.VertexAttrib[index].Size = size; - ctx->Array.VertexAttrib[index].Type = type; - ctx->Array.VertexAttrib[index].Ptr = (void *) ptr; - ctx->NewState |= _NEW_ARRAY; - ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index); +#if FEATURE_ARB_vertex_program +void GLAPIENTRY +_mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, + GLboolean normalized, + GLsizei stride, const GLvoid *ptr) +{ + GLsizei elementSize; + GLenum format; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (index >= ctx->Const.VertexProgram.MaxAttribs) { + _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)"); + return; + } + + if (size < 1 || size > 4) { + if (!ctx->Extensions.EXT_vertex_array_bgra || size != GL_BGRA) { + _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)"); + return; + } + } + + if (stride < 0) { + _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(stride)"); + return; + } + + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glVertexAttribPointerARB(GL_BGRA/type)"); + return; + } + format = GL_BGRA; + size = 4; + normalized = GL_TRUE; + } + else { + format = GL_RGBA; + } + + /* check for valid 'type' and compute StrideB right away */ + /* NOTE: more types are supported here than in the NV extension */ + switch (type) { + case GL_BYTE: + elementSize = size * sizeof(GLbyte); + break; + case GL_UNSIGNED_BYTE: + elementSize = size * sizeof(GLubyte); + break; + case GL_SHORT: + elementSize = size * sizeof(GLshort); + break; + case GL_UNSIGNED_SHORT: + elementSize = size * sizeof(GLushort); + break; + case GL_INT: + elementSize = size * sizeof(GLint); + break; + case GL_UNSIGNED_INT: + elementSize = size * sizeof(GLuint); + break; + case GL_FLOAT: + elementSize = size * sizeof(GLfloat); + break; + case GL_DOUBLE: + elementSize = size * sizeof(GLdouble); + break; +#if FEATURE_fixedpt + case GL_FIXED: + elementSize = size * sizeof(GLfixed); + break; +#endif + default: + _mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerARB(type)" ); + return; + } + + update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], + _NEW_ARRAY_ATTRIB(index), + elementSize, size, type, GL_RGBA, stride, normalized, ptr); if (ctx->Driver.VertexAttribPointer) - ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr ); + ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr); } +#endif -void +void GLAPIENTRY _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { @@ -509,7 +685,7 @@ _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, } -void +void GLAPIENTRY _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { @@ -518,7 +694,7 @@ _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, } -void +void GLAPIENTRY _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { @@ -527,7 +703,7 @@ _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, } -void +void GLAPIENTRY _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { @@ -536,7 +712,7 @@ _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, } -void +void GLAPIENTRY _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *ptr) { @@ -545,7 +721,7 @@ _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, } -void +void GLAPIENTRY _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) { (void) count; @@ -553,27 +729,24 @@ _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) } - - -void +void GLAPIENTRY _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) { GET_CURRENT_CONTEXT(ctx); GLboolean tflag, cflag, nflag; /* enable/disable flags */ GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ - GLenum ctype = 0; /* color type */ GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */ + const GLint toffset = 0; /* always zero */ GLint defstride; /* default stride */ GLint c, f; - GLint coordUnitSave; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); f = sizeof(GLfloat); - c = f * ((4*sizeof(GLubyte) + (f-1)) / f); + c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f); - if (stride<0) { + if (stride < 0) { _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" ); return; } @@ -695,39 +868,23 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY ); _mesa_DisableClientState( GL_INDEX_ARRAY ); + /* XXX also disable secondary color and generic arrays? */ /* Texcoords */ - coordUnitSave = ctx->Array.ActiveTexture; if (tflag) { - GLint i; - GLint factor = ctx->Array.TexCoordInterleaveFactor; - for (i = 0; i < factor; i++) { - _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); - _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); - _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride, - (GLubyte *) pointer + i * coffset ); - } - for (i = factor; i < (GLint) ctx->Const.MaxTextureUnits; i++) { - _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); - _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); - } + _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); + _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride, + (GLubyte *) pointer + toffset ); } else { - GLint i; - for (i = 0; i < (GLint) ctx->Const.MaxTextureUnits; i++) { - _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) ); - _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); - } + _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); } - /* Restore texture coordinate unit index */ - _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) ); - /* Color */ if (cflag) { _mesa_EnableClientState( GL_COLOR_ARRAY ); _mesa_ColorPointer( ccomps, ctype, stride, - (GLubyte*) pointer + coffset ); + (GLubyte *) pointer + coffset ); } else { _mesa_DisableClientState( GL_COLOR_ARRAY ); @@ -737,21 +894,20 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) /* Normals */ if (nflag) { _mesa_EnableClientState( GL_NORMAL_ARRAY ); - _mesa_NormalPointer( GL_FLOAT, stride, - (GLubyte*) pointer + noffset ); + _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset ); } else { _mesa_DisableClientState( GL_NORMAL_ARRAY ); } + /* Vertices */ _mesa_EnableClientState( GL_VERTEX_ARRAY ); _mesa_VertexPointer( vcomps, GL_FLOAT, stride, (GLubyte *) pointer + voffset ); } - -void +void GLAPIENTRY _mesa_LockArraysEXT(GLint first, GLsizei count) { GET_CURRENT_CONTEXT(ctx); @@ -760,16 +916,22 @@ _mesa_LockArraysEXT(GLint first, GLsizei count) if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glLockArrays %d %d\n", first, count); - if (first == 0 && count > 0 && - count <= (GLint) ctx->Const.MaxArrayLockSize) { - ctx->Array.LockFirst = first; - ctx->Array.LockCount = count; + if (first < 0) { + _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" ); + return; } - else { - ctx->Array.LockFirst = 0; - ctx->Array.LockCount = 0; + if (count <= 0) { + _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" ); + return; + } + if (ctx->Array.LockCount != 0) { + _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" ); + return; } + ctx->Array.LockFirst = first; + ctx->Array.LockCount = count; + ctx->NewState |= _NEW_ARRAY; ctx->Array.NewState |= _NEW_ARRAY_ALL; @@ -778,7 +940,7 @@ _mesa_LockArraysEXT(GLint first, GLsizei count) } -void +void GLAPIENTRY _mesa_UnlockArraysEXT( void ) { GET_CURRENT_CONTEXT(ctx); @@ -787,6 +949,11 @@ _mesa_UnlockArraysEXT( void ) if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glUnlockArrays\n"); + if (ctx->Array.LockCount == 0) { + _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" ); + return; + } + ctx->Array.LockFirst = 0; ctx->Array.LockCount = 0; ctx->NewState |= _NEW_ARRAY; @@ -797,10 +964,9 @@ _mesa_UnlockArraysEXT( void ) } - /* GL_EXT_multi_draw_arrays */ /* Somebody forgot to spec the first and count parameters as const! */ -void +void GLAPIENTRY _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount ) { @@ -811,14 +977,14 @@ _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first, for (i = 0; i < primcount; i++) { if (count[i] > 0) { - (ctx->Exec->DrawArrays)(mode, first[i], count[i]); + CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i])); } } } /* GL_EXT_multi_draw_arrays */ -void +void GLAPIENTRY _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount ) { @@ -829,7 +995,62 @@ _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, for (i = 0; i < primcount; i++) { if (count[i] > 0) { - (ctx->Exec->DrawElements)(mode, count[i], type, indices[i]); + CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i])); } } } + + +/* GL_IBM_multimode_draw_arrays */ +void GLAPIENTRY +_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, + const GLsizei * count, + GLsizei primcount, GLint modestride ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + for ( i = 0 ; i < primcount ; i++ ) { + if ( count[i] > 0 ) { + GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); + CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] )); + } + } +} + + +/* GL_IBM_multimode_draw_arrays */ +void GLAPIENTRY +_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, + GLenum type, const GLvoid * const * indices, + GLsizei primcount, GLint modestride ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint i; + + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + /* XXX not sure about ARB_vertex_buffer_object handling here */ + + for ( i = 0 ; i < primcount ; i++ ) { + if ( count[i] > 0 ) { + GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); + CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] )); + } + } +} + + +/** + * Initialize vertex array state for given context. + */ +void +_mesa_init_varray(GLcontext *ctx) +{ + ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0); + ctx->Array.ArrayObj = ctx->Array.DefaultArrayObj; + + ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ +}