/**
* \file bufferobj.c
* \brief Functions for the GL_ARB_vertex_buffer_object extension.
- * \author Brian Paul
+ * \author Brian Paul, Ian Romanick
*/
_mesa_new_buffer_object( GLcontext *ctx, GLuint name, GLenum target )
{
struct gl_buffer_object *obj;
- obj = CALLOC_STRUCT(gl_buffer_object);
+ obj = MALLOC_STRUCT(gl_buffer_object);
_mesa_initialize_buffer_object(obj, name, target);
return obj;
}
_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
GLuint name, GLenum target )
{
+ _mesa_bzero(obj, sizeof(struct gl_buffer_object));
obj->RefCount = 1;
obj->Name = name;
}
bufObj->usage = usage;
if ( data != NULL ) {
- memcpy( bufObj->data, data, size );
+ _mesa_memcpy( bufObj->data, data, size );
}
}
}
{
if ( (bufObj->data != NULL)
&& ((size + offset) <= bufObj->size) ) {
- memcpy( (GLubyte *) bufObj->data + offset, data, size );
+ _mesa_memcpy( (GLubyte *) bufObj->data + offset, data, size );
}
}
{
if ( (bufObj->data != NULL)
&& ((size + offset) <= bufObj->size) ) {
- memcpy( data, (GLubyte *) bufObj->data + offset, size );
+ _mesa_memcpy( data, (GLubyte *) bufObj->data + offset, size );
}
}
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
- /* Return the buffer names */
- for (i=0;i<n;i++) {
- buffer[i] = first + i;
- }
-
- /* Allocate new, empty buffer objects */
+ /* Allocate new, empty buffer objects and return identifiers */
for (i = 0; i < n; i++) {
struct gl_buffer_object *bufObj;
GLuint name = first + i;
return;
}
_mesa_save_buffer_object(ctx, bufObj);
+ buffer[i] = first + i;
}
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
bufObj = buffer_object_get_target( ctx, target, "BufferDataARB" );
if ( bufObj == NULL ) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferDataARB" );
return;
}
ASSERT_OUTSIDE_BEGIN_END(ctx);
bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
- "BufferSubDataARB" );
- if ( bufObj != NULL ) {
- ASSERT(ctx->Driver.BufferSubData);
- (*ctx->Driver.BufferSubData)( ctx, target, offset, size, data, bufObj );
+ "glBufferSubDataARB" );
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferSubDataARB" );
+ return;
}
+
+ ASSERT(ctx->Driver.BufferSubData);
+ (*ctx->Driver.BufferSubData)( ctx, target, offset, size, data, bufObj );
}
ASSERT_OUTSIDE_BEGIN_END(ctx);
bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
- "GetBufferSubDataARB" );
- if ( bufObj != NULL ) {
- ASSERT(ctx->Driver.GetBufferSubData);
- (*ctx->Driver.GetBufferSubData)( ctx, target, offset, size, data, bufObj );
+ "glGetBufferSubDataARB" );
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferSubDataARB" );
+ return;
}
+ ASSERT(ctx->Driver.GetBufferSubData);
+ (*ctx->Driver.GetBufferSubData)( ctx, target, offset, size, data, bufObj );
}
bufObj = buffer_object_get_target( ctx, target, "MapBufferARB" );
if ( bufObj == NULL ) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB" );
return NULL;
}
bufObj = buffer_object_get_target( ctx, target, "UnmapBufferARB" );
if ( bufObj == NULL ) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferSubDataARB" );
return GL_FALSE;
}
ASSERT_OUTSIDE_BEGIN_END(ctx);
bufObj = buffer_object_get_target( ctx, target, "GetBufferParameterivARB" );
- if ( bufObj == NULL ) {
+ if (!bufObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "GetBufferParameterivARB" );
return;
}
bufObj = buffer_object_get_target( ctx, target, "GetBufferPointervARB" );
if ( bufObj == NULL ) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferPointervARB" );
return;
}
{
GET_CURRENT_CONTEXT(ctx);
GLuint i;
- GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint clientUnit = ctx->Array.ActiveTexture;
+ const GLuint texUnit = ctx->Texture.CurrentUnit;
const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit];
ASSERT_OUTSIDE_BEGIN_END(ctx);
*params = INT_TO_BOOL(0);
break;
case GL_TEXTURE_COORD_ARRAY:
- *params = ctx->Array.TexCoord[texUnit].Enabled;
+ *params = ctx->Array.TexCoord[clientUnit].Enabled;
break;
case GL_TEXTURE_COORD_ARRAY_SIZE:
- *params = INT_TO_BOOL(ctx->Array.TexCoord[texUnit].Size);
+ *params = INT_TO_BOOL(ctx->Array.TexCoord[clientUnit].Size);
break;
case GL_TEXTURE_COORD_ARRAY_TYPE:
- *params = ENUM_TO_BOOL(ctx->Array.TexCoord[texUnit].Type);
+ *params = ENUM_TO_BOOL(ctx->Array.TexCoord[clientUnit].Type);
break;
case GL_TEXTURE_COORD_ARRAY_STRIDE:
- *params = INT_TO_BOOL(ctx->Array.TexCoord[texUnit].Stride);
+ *params = INT_TO_BOOL(ctx->Array.TexCoord[clientUnit].Stride);
break;
case GL_TEXTURE_COORD_ARRAY_COUNT_EXT:
*params = INT_TO_BOOL(0);
break;
case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.VertexArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.Vertex.BufferBinding);
break;
case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.NormalArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.Normal.BufferBinding);
break;
case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.ColorArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.Color.BufferBinding);
break;
case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.IndexArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.Index.BufferBinding);
break;
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.TextureArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.TexCoord[clientUnit].BufferBinding);
break;
case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.EdgeFlagArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.EdgeFlag.BufferBinding);
break;
case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.SecondaryColorArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.SecondaryColor.BufferBinding);
break;
case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.FogCoordArrayBufferBinding);
- break;
- case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB:
- CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
- *params = INT_TO_BOOL(ctx->Array.WeightArrayBufferBinding);
+ *params = INT_TO_BOOL(ctx->Array.FogCoord.BufferBinding);
break;
+ /*case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB: - not supported */
case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_B(ARB_vertex_buffer_object, pname);
*params = INT_TO_BOOL(ctx->Array.ElementArrayBufferBinding);
{
GET_CURRENT_CONTEXT(ctx);
GLuint i;
- GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint clientUnit = ctx->Array.ActiveTexture;
+ const GLuint texUnit = ctx->Texture.CurrentUnit;
const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit];
ASSERT_OUTSIDE_BEGIN_END(ctx);
*params = 0.0;
break;
case GL_TEXTURE_COORD_ARRAY:
- *params = (GLdouble) ctx->Array.TexCoord[texUnit].Enabled;
+ *params = (GLdouble) ctx->Array.TexCoord[clientUnit].Enabled;
break;
case GL_TEXTURE_COORD_ARRAY_SIZE:
- *params = (GLdouble) ctx->Array.TexCoord[texUnit].Size;
+ *params = (GLdouble) ctx->Array.TexCoord[clientUnit].Size;
break;
case GL_TEXTURE_COORD_ARRAY_TYPE:
- *params = ENUM_TO_DOUBLE(ctx->Array.TexCoord[texUnit].Type);
+ *params = ENUM_TO_DOUBLE(ctx->Array.TexCoord[clientUnit].Type);
break;
case GL_TEXTURE_COORD_ARRAY_STRIDE:
- *params = (GLdouble) ctx->Array.TexCoord[texUnit].Stride;
+ *params = (GLdouble) ctx->Array.TexCoord[clientUnit].Stride;
break;
case GL_TEXTURE_COORD_ARRAY_COUNT_EXT:
*params = 0.0;
break;
case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.VertexArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.Vertex.BufferBinding;
break;
case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.NormalArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.Normal.BufferBinding;
break;
case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.ColorArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.Color.BufferBinding;
break;
case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.IndexArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.Index.BufferBinding;
break;
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.TextureArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.TexCoord[clientUnit].BufferBinding;
break;
case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.EdgeFlagArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.EdgeFlag.BufferBinding;
break;
case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.SecondaryColorArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.SecondaryColor.BufferBinding;
break;
case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.FogCoordArrayBufferBinding;
- break;
- case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB:
- CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
- *params = (GLdouble) ctx->Array.WeightArrayBufferBinding;
+ *params = (GLdouble) ctx->Array.FogCoord.BufferBinding;
break;
+ /*case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB: - not supported */
case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_D(ARB_vertex_buffer_object, pname);
*params = (GLdouble) ctx->Array.ElementArrayBufferBinding;
{
GET_CURRENT_CONTEXT(ctx);
GLuint i;
- GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint clientUnit = ctx->Array.ActiveTexture;
+ const GLuint texUnit = ctx->Texture.CurrentUnit;
const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit];
ASSERT_OUTSIDE_BEGIN_END(ctx);
*params = 0.0;
break;
case GL_TEXTURE_COORD_ARRAY:
- *params = (GLfloat) ctx->Array.TexCoord[texUnit].Enabled;
+ *params = (GLfloat) ctx->Array.TexCoord[clientUnit].Enabled;
break;
case GL_TEXTURE_COORD_ARRAY_SIZE:
- *params = (GLfloat) ctx->Array.TexCoord[texUnit].Size;
+ *params = (GLfloat) ctx->Array.TexCoord[clientUnit].Size;
break;
case GL_TEXTURE_COORD_ARRAY_TYPE:
- *params = ENUM_TO_FLOAT(ctx->Array.TexCoord[texUnit].Type);
+ *params = ENUM_TO_FLOAT(ctx->Array.TexCoord[clientUnit].Type);
break;
case GL_TEXTURE_COORD_ARRAY_STRIDE:
- *params = (GLfloat) ctx->Array.TexCoord[texUnit].Stride;
+ *params = (GLfloat) ctx->Array.TexCoord[clientUnit].Stride;
break;
case GL_TEXTURE_COORD_ARRAY_COUNT_EXT:
*params = 0.0;
break;
case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.VertexArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.Vertex.BufferBinding;
break;
case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.NormalArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.Normal.BufferBinding;
break;
case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.ColorArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.Color.BufferBinding;
break;
case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.IndexArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.Index.BufferBinding;
break;
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.TextureArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.TexCoord[clientUnit].BufferBinding;
break;
case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.EdgeFlagArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.EdgeFlag.BufferBinding;
break;
case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.SecondaryColorArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.SecondaryColor.BufferBinding;
break;
case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.FogCoordArrayBufferBinding;
- break;
- case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB:
- CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
- *params = (GLfloat) ctx->Array.WeightArrayBufferBinding;
+ *params = (GLfloat) ctx->Array.FogCoord.BufferBinding;
break;
+ /*case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB: - not supported */
case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_F(ARB_vertex_buffer_object, pname);
*params = (GLfloat) ctx->Array.ElementArrayBufferBinding;
{
GET_CURRENT_CONTEXT(ctx);
GLuint i;
- GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint clientUnit = ctx->Array.ActiveTexture;
+ const GLuint texUnit = ctx->Texture.CurrentUnit;
const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit];
ASSERT_OUTSIDE_BEGIN_END(ctx);
*params = 0;
break;
case GL_TEXTURE_COORD_ARRAY:
- *params = (GLint) ctx->Array.TexCoord[texUnit].Enabled;
+ *params = (GLint) ctx->Array.TexCoord[clientUnit].Enabled;
break;
case GL_TEXTURE_COORD_ARRAY_SIZE:
- *params = ctx->Array.TexCoord[texUnit].Size;
+ *params = ctx->Array.TexCoord[clientUnit].Size;
break;
case GL_TEXTURE_COORD_ARRAY_TYPE:
- *params = ctx->Array.TexCoord[texUnit].Type;
+ *params = ctx->Array.TexCoord[clientUnit].Type;
break;
case GL_TEXTURE_COORD_ARRAY_STRIDE:
- *params = ctx->Array.TexCoord[texUnit].Stride;
+ *params = ctx->Array.TexCoord[clientUnit].Stride;
break;
case GL_TEXTURE_COORD_ARRAY_COUNT_EXT:
*params = 0;
break;
case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.VertexArrayBufferBinding;
+ *params = (GLint) ctx->Array.Vertex.BufferBinding;
break;
case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.NormalArrayBufferBinding;
+ *params = (GLint) ctx->Array.Normal.BufferBinding;
break;
case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.ColorArrayBufferBinding;
+ *params = (GLint) ctx->Array.Color.BufferBinding;
break;
case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.IndexArrayBufferBinding;
+ *params = (GLint) ctx->Array.Index.BufferBinding;
break;
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.TextureArrayBufferBinding;
+ *params = (GLint) ctx->Array.TexCoord[clientUnit].BufferBinding;
break;
case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.EdgeFlagArrayBufferBinding;
+ *params = (GLint) ctx->Array.EdgeFlag.BufferBinding;
break;
case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.SecondaryColorArrayBufferBinding;
+ *params = (GLint) ctx->Array.SecondaryColor.BufferBinding;
break;
case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.FogCoordArrayBufferBinding;
- break;
- case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB:
- CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
- *params = (GLint) ctx->Array.WeightArrayBufferBinding;
+ *params = (GLint) ctx->Array.FogCoord.BufferBinding;
break;
+ /*case GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB: - not supported */
case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
CHECK_EXTENSION_I(ARB_vertex_buffer_object, pname);
*params = (GLint) ctx->Array.ElementArrayBufferBinding;
_mesa_GetPointerv( GLenum pname, GLvoid **params )
{
GET_CURRENT_CONTEXT(ctx);
- GLuint texUnit = ctx->Texture.CurrentUnit;
+ const GLuint clientUnit = ctx->Array.ActiveTexture;
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (!params)
*params = ctx->Array.Index.Ptr;
break;
case GL_TEXTURE_COORD_ARRAY_POINTER:
- *params = ctx->Array.TexCoord[texUnit].Ptr;
+ *params = ctx->Array.TexCoord[clientUnit].Ptr;
break;
case GL_EDGE_FLAG_ARRAY_POINTER:
*params = ctx->Array.EdgeFlag.Ptr;