indirect_vertex_array.c

来自「Mesa is an open-source implementation of」· C语言 代码 · 共 1,877 行 · 第 1/4 页

C
1,877
字号
    case GL_SHORT:		opcode = 4127; break;    case GL_UNSIGNED_SHORT:	opcode = 4132; break;    case GL_INT:		opcode = 4128; break;    case GL_UNSIGNED_INT:	opcode = 4133; break;    case GL_FLOAT:		opcode = 4129; break;    case GL_DOUBLE:		opcode = 4130; break;    default:        __glXSetError(gc, GL_INVALID_ENUM);        return;    }    a = get_array_entry( arrays, GL_SECONDARY_COLOR_ARRAY, 0 );    if ( a == NULL ) {        __glXSetError(gc, GL_INVALID_OPERATION);        return;    }    COMMON_ARRAY_DATA_INIT( a, pointer, type, stride, size, GL_TRUE, 4,			    opcode );    if ( a->enabled ) {	arrays->array_info_cache_valid = GL_FALSE;    }}void __indirect_glFogCoordPointerEXT( GLenum type, GLsizei stride,				const GLvoid * pointer ){    uint16_t opcode;    __GLXcontext *gc = __glXGetCurrentContext();    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);    struct array_state_vector * arrays = state->array_state;    struct array_state * a;    if (stride < 0) {        __glXSetError(gc, GL_INVALID_VALUE);        return;    }    switch ( type ) {    case GL_FLOAT:		opcode = 4124; break;    case GL_DOUBLE:		opcode = 4125; break;    default:        __glXSetError(gc, GL_INVALID_ENUM);        return;    }    a = get_array_entry( arrays, GL_FOG_COORD_ARRAY, 0 );    if ( a == NULL ) {        __glXSetError(gc, GL_INVALID_OPERATION);        return;    }    COMMON_ARRAY_DATA_INIT( a, pointer, type, stride, 1, GL_FALSE, 4,			    opcode );    if ( a->enabled ) {	arrays->array_info_cache_valid = GL_FALSE;    }}void __indirect_glVertexAttribPointerARB(GLuint index, GLint size,					 GLenum type, GLboolean normalized,					 GLsizei stride,					 const GLvoid * pointer){    static const uint16_t short_ops[5]  = { 0, 4189, 4190, 4191, 4192 };    static const uint16_t float_ops[5]  = { 0, 4193, 4194, 4195, 4196 };    static const uint16_t double_ops[5] = { 0, 4197, 4198, 4199, 4200 };    uint16_t opcode;    __GLXcontext *gc = __glXGetCurrentContext();    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);    struct array_state_vector * arrays = state->array_state;    struct array_state * a;    unsigned true_immediate_count;    unsigned true_immediate_size;    if ( (size < 1) || (size > 4) || (stride < 0) 	 || (index > arrays->num_vertex_program_attribs) ){        __glXSetError(gc, GL_INVALID_VALUE);        return;    }    if ( normalized && (type != GL_FLOAT) && (type != GL_DOUBLE)) {	switch( type ) {	case GL_BYTE:           opcode = X_GLrop_VertexAttrib4NbvARB;  break;	case GL_UNSIGNED_BYTE:  opcode = X_GLrop_VertexAttrib4NubvARB; break;	case GL_SHORT:          opcode = X_GLrop_VertexAttrib4NsvARB;  break;	case GL_UNSIGNED_SHORT: opcode = X_GLrop_VertexAttrib4NusvARB; break;	case GL_INT:            opcode = X_GLrop_VertexAttrib4NivARB;  break;	case GL_UNSIGNED_INT:   opcode = X_GLrop_VertexAttrib4NuivARB; break;	default:	    __glXSetError(gc, GL_INVALID_ENUM);	    return;	}		true_immediate_count = 4;    }    else {	true_immediate_count = size;	switch( type ) {	case GL_BYTE:	    opcode = X_GLrop_VertexAttrib4bvARB;	    true_immediate_count = 4;	    break;	case GL_UNSIGNED_BYTE:	    opcode = X_GLrop_VertexAttrib4ubvARB;	    true_immediate_count = 4;	    break;	case GL_SHORT:	    opcode = short_ops[size];	    break;	case GL_UNSIGNED_SHORT:	    opcode = X_GLrop_VertexAttrib4usvARB;	    true_immediate_count = 4;	    break;	case GL_INT:            opcode = X_GLrop_VertexAttrib4ivARB;	    true_immediate_count = 4;	    break;	case GL_UNSIGNED_INT:	    opcode = X_GLrop_VertexAttrib4uivARB;	    true_immediate_count = 4;	    break;	case GL_FLOAT:	    opcode = float_ops[size];	    break;	case GL_DOUBLE:	    opcode = double_ops[size];	    break;	default:	    __glXSetError(gc, GL_INVALID_ENUM);	    return;	}    }    a = get_array_entry( arrays, GL_VERTEX_ATTRIB_ARRAY_POINTER, index );    if ( a == NULL ) {        __glXSetError(gc, GL_INVALID_OPERATION);        return;    }    COMMON_ARRAY_DATA_INIT( a, pointer, type, stride, size, normalized, 8,			    opcode );    true_immediate_size = __glXTypeSize(type) * true_immediate_count;    ((uint16_t *) (a)->header)[0] = __GLX_PAD(a->header_size 					      + true_immediate_size);    if ( a->enabled ) {	arrays->array_info_cache_valid = GL_FALSE;    }}/** * I don't have 100% confidence that this is correct.  The different rules * about whether or not generic vertex attributes alias "classic" vertex * attributes (i.e., attrib1 ?= primary color) between ARB_vertex_program, * ARB_vertex_shader, and NV_vertex_program are a bit confusing.  My * feeling is that the client-side doesn't have to worry about it.  The * client just sends all the data to the server and lets the server deal * with it. */void __indirect_glVertexAttribPointerNV( GLuint index, GLint size,					 GLenum type, GLsizei stride,					 const GLvoid * pointer){    __GLXcontext *gc = __glXGetCurrentContext();    GLboolean normalized = GL_FALSE;    switch( type ) {    case GL_UNSIGNED_BYTE:	if ( size != 4 ) {	    __glXSetError(gc, GL_INVALID_VALUE);	    return;	}	normalized = GL_TRUE;    case GL_SHORT:    case GL_FLOAT:    case GL_DOUBLE:	__indirect_glVertexAttribPointerARB(index, size, type,					    normalized,					    stride, pointer);	return;    default:	__glXSetError(gc, GL_INVALID_ENUM);	return;    }}void __indirect_glClientActiveTextureARB(GLenum texture){    __GLXcontext * const gc = __glXGetCurrentContext();    __GLXattribute * const state = (__GLXattribute *)(gc->client_state_private);    struct array_state_vector * const arrays = state->array_state;    const GLint unit = (GLint) texture - GL_TEXTURE0;    if ( (unit < 0) || (unit >= arrays->num_texture_units) ) {	__glXSetError(gc, GL_INVALID_ENUM);	return;    }    arrays->active_texture_unit = unit;}/** * Modify the enable state for the selected array */GLboolean__glXSetArrayEnable(__GLXattribute *state, GLenum key, unsigned index,                    GLboolean enable){    struct array_state_vector * arrays = state->array_state;    struct array_state * a;        /* Texture coordinate arrays have an implict index set when the     * application calls glClientActiveTexture.     */    if (key == GL_TEXTURE_COORD_ARRAY) {        index = arrays->active_texture_unit;    }    a = get_array_entry( arrays, key, index );    if ( (a != NULL) && (a->enabled != enable) ) {	a->enabled = enable;	arrays->array_info_cache_valid = GL_FALSE;    }    return (a != NULL);}void__glXArrayDisableAll( __GLXattribute * state ){    struct array_state_vector * arrays = state->array_state;    unsigned  i;    for ( i = 0 ; i < arrays->num_arrays ; i++ ) {	arrays->arrays[i].enabled = GL_FALSE;    }    arrays->array_info_cache_valid = GL_FALSE;}/** */GLboolean__glXGetArrayEnable( const __GLXattribute * const state,		     GLenum key, unsigned index, GLintptr * dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (GLintptr) a->enabled;    }    return (a != NULL);}/** */GLboolean__glXGetArrayType( const __GLXattribute * const state,		     GLenum key, unsigned index, GLintptr * dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (GLintptr) a->data_type;    }    return (a != NULL);}/** */GLboolean__glXGetArraySize( const __GLXattribute * const state,		     GLenum key, unsigned index, GLintptr * dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (GLintptr) a->count;    }    return (a != NULL);}/** */GLboolean__glXGetArrayStride( const __GLXattribute * const state,		     GLenum key, unsigned index, GLintptr * dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (GLintptr) a->user_stride;    }    return (a != NULL);}/** */GLboolean__glXGetArrayPointer( const __GLXattribute * const state,		      GLenum key, unsigned index, void ** dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (void *) (a->data);    }    return (a != NULL);}/** */GLboolean__glXGetArrayNormalized( const __GLXattribute * const state,			 GLenum key, unsigned index, GLintptr * dest ){    const struct array_state_vector * arrays = state->array_state;    const struct array_state * a = get_array_entry( (struct array_state_vector *) arrays,						    key, index );    if ( a != NULL ) {	*dest = (GLintptr) a->normalized;    }    return (a != NULL);}/** */GLuint__glXGetActiveTextureUnit( const __GLXattribute * const state ){    return state->array_state->active_texture_unit;}void__glXPushArrayState( __GLXattribute * state ){    struct array_state_vector * arrays = state->array_state;    struct array_stack_state * stack = & arrays->stack[ (arrays->stack_index * arrays->num_arrays)];    unsigned  i;    /* XXX are we pushing _all_ the necessary fields? */    for ( i = 0 ; i < arrays->num_arrays ; i++ ) {	stack[i].data = arrays->arrays[i].data;	stack[i].data_type = arrays->arrays[i].data_type;	stack[i].user_stride = arrays->arrays[i].user_stride;	stack[i].count = arrays->arrays[i].count;	stack[i].key = arrays->arrays[i].key;        stack[i].index = arrays->arrays[i].index;	stack[i].enabled = arrays->arrays[i].enabled;    }    arrays->active_texture_unit_stack[ arrays->stack_index ] =      arrays->active_texture_unit;    arrays->stack_index++;}void__glXPopArrayState( __GLXattribute * state ){    struct array_state_vector * arrays = state->array_state;    struct array_stack_state * stack;    unsigned  i;    arrays->stack_index--;    stack = & arrays->stack[ (arrays->stack_index * arrays->num_arrays) ];    for ( i = 0 ; i < arrays->num_arrays ; i++ ) {	switch ( stack[i].key ) {	case GL_NORMAL_ARRAY:	    __indirect_glNormalPointer( stack[i].data_type,					stack[i].user_stride,					stack[i].data );	    break;	case GL_COLOR_ARRAY:	    __indirect_glColorPointer( stack[i].count,				       stack[i].data_type,				       stack[i].user_stride,				       stack[i].data );	    break;	case GL_INDEX_ARRAY:	    __indirect_glIndexPointer( stack[i].data_type,				       stack[i].user_stride,				       stack[i].data );	    break;	case GL_EDGE_FLAG_ARRAY:	    __indirect_glEdgeFlagPointer( stack[i].user_stride,					  stack[i].data );	    break;	case GL_TEXTURE_COORD_ARRAY:	    arrays->active_texture_unit = stack[i].index;	    __indirect_glTexCoordPointer( stack[i].count,					  stack[i].data_type,					  stack[i].user_stride,					  stack[i].data );	    break;	case GL_SECONDARY_COLOR_ARRAY:	    __indirect_glSecondaryColorPointerEXT( stack[i].count,						   stack[i].data_type,						   stack[i].user_stride,						   stack[i].data );	    break;	case GL_FOG_COORDINATE_ARRAY:	    __indirect_glFogCoordPointerEXT( stack[i].data_type,					     stack[i].user_stride,					     stack[i].data );	    break;	}		__glXSetArrayEnable( state, stack[i].key, stack[i].index,			     stack[i].enabled );    }    arrays->active_texture_unit =       arrays->active_texture_unit_stack[ arrays->stack_index ];}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?