📄 varray.c
字号:
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (index >= ctx->Const.MaxVertexProgramAttribs) {
_mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
return;
}
if (size < 1 || size > 4) {
_mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size)");
return;
}
if (stride < 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(stride)");
return;
}
if (type == GL_UNSIGNED_BYTE && size != 4) {
_mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(size!=4)");
return;
}
/* 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;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glVertexAttribPointerARB(type)" );
return;
}
update_array(ctx, &ctx->Array.VertexAttrib[index], _NEW_ARRAY_ATTRIB(index),
elementSize, size, type, stride, normalized, ptr);
/* XXX fix
if (ctx->Driver.VertexAttribPointer)
ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr );
*/
}
#endif
void GLAPIENTRY
_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
GLsizei count, const GLvoid *ptr)
{
(void) count;
_mesa_VertexPointer(size, type, stride, ptr);
}
void GLAPIENTRY
_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
const GLvoid *ptr)
{
(void) count;
_mesa_NormalPointer(type, stride, ptr);
}
void GLAPIENTRY
_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
const GLvoid *ptr)
{
(void) count;
_mesa_ColorPointer(size, type, stride, ptr);
}
void GLAPIENTRY
_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
const GLvoid *ptr)
{
(void) count;
_mesa_IndexPointer(type, stride, ptr);
}
void GLAPIENTRY
_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
GLsizei count, const GLvoid *ptr)
{
(void) count;
_mesa_TexCoordPointer(size, type, stride, ptr);
}
void GLAPIENTRY
_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
{
(void) count;
_mesa_EdgeFlagPointer(stride, ptr);
}
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;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
f = sizeof(GLfloat);
c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
if (stride < 0) {
_mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
return;
}
switch (format) {
case GL_V2F:
tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
tcomps = 0; ccomps = 0; vcomps = 2;
voffset = 0;
defstride = 2*f;
break;
case GL_V3F:
tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
tcomps = 0; ccomps = 0; vcomps = 3;
voffset = 0;
defstride = 3*f;
break;
case GL_C4UB_V2F:
tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
tcomps = 0; ccomps = 4; vcomps = 2;
ctype = GL_UNSIGNED_BYTE;
coffset = 0;
voffset = c;
defstride = c + 2*f;
break;
case GL_C4UB_V3F:
tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
tcomps = 0; ccomps = 4; vcomps = 3;
ctype = GL_UNSIGNED_BYTE;
coffset = 0;
voffset = c;
defstride = c + 3*f;
break;
case GL_C3F_V3F:
tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
tcomps = 0; ccomps = 3; vcomps = 3;
ctype = GL_FLOAT;
coffset = 0;
voffset = 3*f;
defstride = 6*f;
break;
case GL_N3F_V3F:
tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
tcomps = 0; ccomps = 0; vcomps = 3;
noffset = 0;
voffset = 3*f;
defstride = 6*f;
break;
case GL_C4F_N3F_V3F:
tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
tcomps = 0; ccomps = 4; vcomps = 3;
ctype = GL_FLOAT;
coffset = 0;
noffset = 4*f;
voffset = 7*f;
defstride = 10*f;
break;
case GL_T2F_V3F:
tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
tcomps = 2; ccomps = 0; vcomps = 3;
voffset = 2*f;
defstride = 5*f;
break;
case GL_T4F_V4F:
tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
tcomps = 4; ccomps = 0; vcomps = 4;
voffset = 4*f;
defstride = 8*f;
break;
case GL_T2F_C4UB_V3F:
tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
tcomps = 2; ccomps = 4; vcomps = 3;
ctype = GL_UNSIGNED_BYTE;
coffset = 2*f;
voffset = c+2*f;
defstride = c+5*f;
break;
case GL_T2F_C3F_V3F:
tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
tcomps = 2; ccomps = 3; vcomps = 3;
ctype = GL_FLOAT;
coffset = 2*f;
voffset = 5*f;
defstride = 8*f;
break;
case GL_T2F_N3F_V3F:
tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
tcomps = 2; ccomps = 0; vcomps = 3;
noffset = 2*f;
voffset = 5*f;
defstride = 8*f;
break;
case GL_T2F_C4F_N3F_V3F:
tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
tcomps = 2; ccomps = 4; vcomps = 3;
ctype = GL_FLOAT;
coffset = 2*f;
noffset = 6*f;
voffset = 9*f;
defstride = 12*f;
break;
case GL_T4F_C4F_N3F_V4F:
tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
tcomps = 4; ccomps = 4; vcomps = 4;
ctype = GL_FLOAT;
coffset = 4*f;
noffset = 8*f;
voffset = 11*f;
defstride = 15*f;
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
return;
}
if (stride==0) {
stride = defstride;
}
_mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
_mesa_DisableClientState( GL_INDEX_ARRAY );
/* Texcoords */
if (tflag) {
_mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
_mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
(GLubyte *) pointer + toffset );
}
else {
_mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
}
/* Color */
if (cflag) {
_mesa_EnableClientState( GL_COLOR_ARRAY );
_mesa_ColorPointer( ccomps, ctype, stride,
(GLubyte *) pointer + coffset );
}
else {
_mesa_DisableClientState( GL_COLOR_ARRAY );
}
/* Normals */
if (nflag) {
_mesa_EnableClientState( GL_NORMAL_ARRAY );
_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 GLAPIENTRY
_mesa_LockArraysEXT(GLint first, GLsizei count)
{
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
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;
}
else {
ctx->Array.LockFirst = 0;
ctx->Array.LockCount = 0;
}
ctx->NewState |= _NEW_ARRAY;
ctx->Array.NewState |= _NEW_ARRAY_ALL;
if (ctx->Driver.LockArraysEXT)
ctx->Driver.LockArraysEXT( ctx, first, count );
}
void GLAPIENTRY
_mesa_UnlockArraysEXT( void )
{
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glUnlockArrays\n");
ctx->Array.LockFirst = 0;
ctx->Array.LockCount = 0;
ctx->NewState |= _NEW_ARRAY;
ctx->Array.NewState |= _NEW_ARRAY_ALL;
if (ctx->Driver.UnlockArraysEXT)
ctx->Driver.UnlockArraysEXT( ctx );
}
/* GL_EXT_multi_draw_arrays */
/* Somebody forgot to spec the first and count parameters as const! <sigh> */
void GLAPIENTRY
_mesa_MultiDrawArraysEXT( GLenum mode, GLint *first,
GLsizei *count, GLsizei primcount )
{
GET_CURRENT_CONTEXT(ctx);
GLint i;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
for (i = 0; i < primcount; i++) {
if (count[i] > 0) {
CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
}
}
}
/* GL_EXT_multi_draw_arrays */
void GLAPIENTRY
_mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
const GLvoid **indices, GLsizei primcount )
{
GET_CURRENT_CONTEXT(ctx);
GLint i;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
for (i = 0; i < primcount; i++) {
if (count[i] > 0) {
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] ));
}
}
}
/**********************************************************************/
/***** Initialization *****/
/**********************************************************************/
void
_mesa_init_varray( GLcontext * ctx )
{
GLuint i;
/* Vertex arrays */
ctx->Array.Vertex.Size = 4;
ctx->Array.Vertex.Type = GL_FLOAT;
ctx->Array.Vertex.Stride = 0;
ctx->Array.Vertex.StrideB = 0;
ctx->Array.Vertex.Ptr = NULL;
ctx->Array.Vertex.Enabled = GL_FALSE;
ctx->Array.Vertex.Flags = CA_CLIENT_DATA;
ctx->Array.Normal.Type = GL_FLOAT;
ctx->Array.Normal.Stride = 0;
ctx->Array.Normal.StrideB = 0;
ctx->Array.Normal.Ptr = NULL;
ctx->Array.Normal.Enabled = GL_FALSE;
ctx->Array.Normal.Flags = CA_CLIENT_DATA;
ctx->Array.Color.Size = 4;
ctx->Array.Color.Type = GL_FLOAT;
ctx->Array.Color.Stride = 0;
ctx->Array.Color.StrideB = 0;
ctx->Array.Color.Ptr = NULL;
ctx->Array.Color.Enabled = GL_FALSE;
ctx->Array.Color.Flags = CA_CLIENT_DATA;
ctx->Array.SecondaryColor.Size = 4;
ctx->Array.SecondaryColor.Type = GL_FLOAT;
ctx->Array.SecondaryColor.Stride = 0;
ctx->Array.SecondaryColor.StrideB = 0;
ctx->Array.SecondaryColor.Ptr = NULL;
ctx->Array.SecondaryColor.Enabled = GL_FALSE;
ctx->Array.SecondaryColor.Flags = CA_CLIENT_DATA;
ctx->Array.FogCoord.Size = 1;
ctx->Array.FogCoord.Type = GL_FLOAT;
ctx->Array.FogCoord.Stride = 0;
ctx->Array.FogCoord.StrideB = 0;
ctx->Array.FogCoord.Ptr = NULL;
ctx->Array.FogCoord.Enabled = GL_FALSE;
ctx->Array.FogCoord.Flags = CA_CLIENT_DATA;
ctx->Array.Index.Type = GL_FLOAT;
ctx->Array.Index.Stride = 0;
ctx->Array.Index.StrideB = 0;
ctx->Array.Index.Ptr = NULL;
ctx->Array.Index.Enabled = GL_FALSE;
ctx->Array.Index.Flags = CA_CLIENT_DATA;
for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
ctx->Array.TexCoord[i].Size = 4;
ctx->Array.TexCoord[i].Type = GL_FLOAT;
ctx->Array.TexCoord[i].Stride = 0;
ctx->Array.TexCoord[i].StrideB = 0;
ctx->Array.TexCoord[i].Ptr = NULL;
ctx->Array.TexCoord[i].Enabled = GL_FALSE;
ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
}
ctx->Array.EdgeFlag.Stride = 0;
ctx->Array.EdgeFlag.StrideB = 0;
ctx->Array.EdgeFlag.Ptr = NULL;
ctx->Array.EdgeFlag.Enabled = GL_FALSE;
ctx->Array.EdgeFlag.Flags = CA_CLIENT_DATA;
ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
for (i = 0; i < VERT_ATTRIB_MAX; i++) {
ctx->Array.VertexAttrib[i].Size = 4;
ctx->Array.VertexAttrib[i].Type = GL_FLOAT;
ctx->Array.VertexAttrib[i].Stride = 0;
ctx->Array.VertexAttrib[i].StrideB = 0;
ctx->Array.VertexAttrib[i].Ptr = NULL;
ctx->Array.VertexAttrib[i].Enabled = GL_FALSE;
ctx->Array.VertexAttrib[i].Flags = CA_CLIENT_DATA;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -