Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenarrayobj.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.2 00004 * 00005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 00006 * (C) Copyright IBM Corporation 2006 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a 00009 * copy of this software and associated documentation files (the "Software"), 00010 * to deal in the Software without restriction, including without limitation 00011 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00012 * and/or sell copies of the Software, and to permit persons to whom the 00013 * Software is furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included 00016 * in all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00021 * BRIAN PAUL OR IBM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00022 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 00023 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00024 * SOFTWARE. 00025 */ 00026 00027 00041 #include "glheader.h" 00042 #include "hash.h" 00043 #include "imports.h" 00044 #include "context.h" 00045 #if FEATURE_ARB_vertex_buffer_object 00046 #include "bufferobj.h" 00047 #endif 00048 #include "arrayobj.h" 00049 #include "glapi/dispatch.h" 00050 00051 00061 static INLINE struct gl_array_object * 00062 lookup_arrayobj(GLcontext *ctx, GLuint id) 00063 { 00064 return (id == 0) 00065 ? NULL 00066 : (struct gl_array_object *) _mesa_HashLookup(ctx->Shared->ArrayObjects, 00067 id); 00068 } 00069 00070 00077 struct gl_array_object * 00078 _mesa_new_array_object( GLcontext *ctx, GLuint name ) 00079 { 00080 struct gl_array_object *obj = CALLOC_STRUCT(gl_array_object); 00081 if (obj) 00082 _mesa_initialize_array_object(ctx, obj, name); 00083 return obj; 00084 } 00085 00086 00093 void 00094 _mesa_delete_array_object( GLcontext *ctx, struct gl_array_object *obj ) 00095 { 00096 (void) ctx; 00097 _mesa_free(obj); 00098 } 00099 00100 00101 void 00102 _mesa_initialize_array_object( GLcontext *ctx, 00103 struct gl_array_object *obj, 00104 GLuint name ) 00105 { 00106 GLuint i; 00107 00108 obj->Name = name; 00109 00110 /* Vertex arrays */ 00111 obj->Vertex.Size = 4; 00112 obj->Vertex.Type = GL_FLOAT; 00113 obj->Vertex.Stride = 0; 00114 obj->Vertex.StrideB = 0; 00115 obj->Vertex.Ptr = NULL; 00116 obj->Vertex.Enabled = GL_FALSE; 00117 obj->Normal.Type = GL_FLOAT; 00118 obj->Normal.Stride = 0; 00119 obj->Normal.StrideB = 0; 00120 obj->Normal.Ptr = NULL; 00121 obj->Normal.Enabled = GL_FALSE; 00122 obj->Color.Size = 4; 00123 obj->Color.Type = GL_FLOAT; 00124 obj->Color.Stride = 0; 00125 obj->Color.StrideB = 0; 00126 obj->Color.Ptr = NULL; 00127 obj->Color.Enabled = GL_FALSE; 00128 obj->SecondaryColor.Size = 4; 00129 obj->SecondaryColor.Type = GL_FLOAT; 00130 obj->SecondaryColor.Stride = 0; 00131 obj->SecondaryColor.StrideB = 0; 00132 obj->SecondaryColor.Ptr = NULL; 00133 obj->SecondaryColor.Enabled = GL_FALSE; 00134 obj->FogCoord.Size = 1; 00135 obj->FogCoord.Type = GL_FLOAT; 00136 obj->FogCoord.Stride = 0; 00137 obj->FogCoord.StrideB = 0; 00138 obj->FogCoord.Ptr = NULL; 00139 obj->FogCoord.Enabled = GL_FALSE; 00140 obj->Index.Type = GL_FLOAT; 00141 obj->Index.Stride = 0; 00142 obj->Index.StrideB = 0; 00143 obj->Index.Ptr = NULL; 00144 obj->Index.Enabled = GL_FALSE; 00145 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { 00146 obj->TexCoord[i].Size = 4; 00147 obj->TexCoord[i].Type = GL_FLOAT; 00148 obj->TexCoord[i].Stride = 0; 00149 obj->TexCoord[i].StrideB = 0; 00150 obj->TexCoord[i].Ptr = NULL; 00151 obj->TexCoord[i].Enabled = GL_FALSE; 00152 } 00153 obj->EdgeFlag.Stride = 0; 00154 obj->EdgeFlag.StrideB = 0; 00155 obj->EdgeFlag.Ptr = NULL; 00156 obj->EdgeFlag.Enabled = GL_FALSE; 00157 for (i = 0; i < VERT_ATTRIB_MAX; i++) { 00158 obj->VertexAttrib[i].Size = 4; 00159 obj->VertexAttrib[i].Type = GL_FLOAT; 00160 obj->VertexAttrib[i].Stride = 0; 00161 obj->VertexAttrib[i].StrideB = 0; 00162 obj->VertexAttrib[i].Ptr = NULL; 00163 obj->VertexAttrib[i].Enabled = GL_FALSE; 00164 obj->VertexAttrib[i].Normalized = GL_FALSE; 00165 } 00166 00167 #if FEATURE_point_size_array 00168 obj->PointSize.Type = GL_FLOAT; 00169 obj->PointSize.Stride = 0; 00170 obj->PointSize.StrideB = 0; 00171 obj->PointSize.Ptr = NULL; 00172 obj->PointSize.Enabled = GL_FALSE; 00173 obj->PointSize.BufferObj = ctx->Array.NullBufferObj; 00174 #endif 00175 00176 #if FEATURE_ARB_vertex_buffer_object 00177 /* Vertex array buffers */ 00178 obj->Vertex.BufferObj = ctx->Array.NullBufferObj; 00179 obj->Normal.BufferObj = ctx->Array.NullBufferObj; 00180 obj->Color.BufferObj = ctx->Array.NullBufferObj; 00181 obj->SecondaryColor.BufferObj = ctx->Array.NullBufferObj; 00182 obj->FogCoord.BufferObj = ctx->Array.NullBufferObj; 00183 obj->Index.BufferObj = ctx->Array.NullBufferObj; 00184 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { 00185 obj->TexCoord[i].BufferObj = ctx->Array.NullBufferObj; 00186 } 00187 obj->EdgeFlag.BufferObj = ctx->Array.NullBufferObj; 00188 for (i = 0; i < VERT_ATTRIB_MAX; i++) { 00189 obj->VertexAttrib[i].BufferObj = ctx->Array.NullBufferObj; 00190 } 00191 #endif 00192 } 00193 00194 00198 void 00199 _mesa_save_array_object( GLcontext *ctx, struct gl_array_object *obj ) 00200 { 00201 if (obj->Name > 0) { 00202 /* insert into hash table */ 00203 _mesa_HashInsert(ctx->Shared->ArrayObjects, obj->Name, obj); 00204 } 00205 } 00206 00207 00212 void 00213 _mesa_remove_array_object( GLcontext *ctx, struct gl_array_object *obj ) 00214 { 00215 if (obj->Name > 0) { 00216 /* remove from hash table */ 00217 _mesa_HashRemove(ctx->Shared->ArrayObjects, obj->Name); 00218 } 00219 } 00220 00221 00222 static void 00223 unbind_buffer_object( GLcontext *ctx, struct gl_buffer_object *bufObj ) 00224 { 00225 if (bufObj != ctx->Array.NullBufferObj) { 00226 _mesa_reference_buffer_object(ctx, &bufObj, NULL); 00227 } 00228 } 00229 00230 00231 /**********************************************************************/ 00232 /* API Functions */ 00233 /**********************************************************************/ 00234 00243 void GLAPIENTRY 00244 _mesa_BindVertexArrayAPPLE( GLuint id ) 00245 { 00246 GET_CURRENT_CONTEXT(ctx); 00247 struct gl_array_object * const oldObj = ctx->Array.ArrayObj; 00248 struct gl_array_object *newObj = NULL; 00249 ASSERT_OUTSIDE_BEGIN_END(ctx); 00250 00251 ASSERT(oldObj != NULL); 00252 00253 if ( oldObj->Name == id ) 00254 return; /* rebinding the same array object- no change */ 00255 00256 /* 00257 * Get pointer to new array object (newBufObj) 00258 */ 00259 if (id == 0) { 00260 /* The spec says there is no array object named 0, but we use 00261 * one internally because it simplifies things. 00262 */ 00263 newObj = ctx->Array.DefaultArrayObj; 00264 } 00265 else { 00266 /* non-default array object */ 00267 newObj = lookup_arrayobj(ctx, id); 00268 if (!newObj) { 00269 /* If this is a new array object id, allocate an array object now. 00270 */ 00271 00272 newObj = (*ctx->Driver.NewArrayObject)(ctx, id); 00273 if (!newObj) { 00274 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE"); 00275 return; 00276 } 00277 _mesa_save_array_object(ctx, newObj); 00278 } 00279 } 00280 00281 00282 ctx->NewState |= _NEW_ARRAY; 00283 ctx->Array.NewState |= _NEW_ARRAY_ALL; 00284 ctx->Array.ArrayObj = newObj; 00285 00286 00287 /* Pass BindVertexArray call to device driver */ 00288 if (ctx->Driver.BindArrayObject && newObj) 00289 (*ctx->Driver.BindArrayObject)( ctx, newObj ); 00290 } 00291 00292 00299 void GLAPIENTRY 00300 _mesa_DeleteVertexArraysAPPLE(GLsizei n, const GLuint *ids) 00301 { 00302 GET_CURRENT_CONTEXT(ctx); 00303 GLsizei i; 00304 ASSERT_OUTSIDE_BEGIN_END(ctx); 00305 00306 if (n < 0) { 00307 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArrayAPPLE(n)"); 00308 return; 00309 } 00310 00311 _glthread_LOCK_MUTEX(ctx->Shared->Mutex); 00312 00313 for (i = 0; i < n; i++) { 00314 struct gl_array_object *obj = lookup_arrayobj(ctx, ids[i]); 00315 00316 if ( obj != NULL ) { 00317 ASSERT( obj->Name == ids[i] ); 00318 00319 00320 /* If the array object is currently bound, the spec says "the binding 00321 * for that object reverts to zero and the default vertex array 00322 * becomes current." 00323 */ 00324 if ( obj == ctx->Array.ArrayObj ) { 00325 CALL_BindVertexArrayAPPLE( ctx->Exec, (0) ); 00326 } 00327 00328 #if FEATURE_ARB_vertex_buffer_object 00329 /* Unbind any buffer objects that might be bound to arrays in 00330 * this array object. 00331 */ 00332 unbind_buffer_object( ctx, obj->Vertex.BufferObj ); 00333 unbind_buffer_object( ctx, obj->Normal.BufferObj ); 00334 unbind_buffer_object( ctx, obj->Color.BufferObj ); 00335 unbind_buffer_object( ctx, obj->SecondaryColor.BufferObj ); 00336 unbind_buffer_object( ctx, obj->FogCoord.BufferObj ); 00337 unbind_buffer_object( ctx, obj->Index.BufferObj ); 00338 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { 00339 unbind_buffer_object( ctx, obj->TexCoord[i].BufferObj ); 00340 } 00341 unbind_buffer_object( ctx, obj->EdgeFlag.BufferObj ); 00342 for (i = 0; i < VERT_ATTRIB_MAX; i++) { 00343 unbind_buffer_object( ctx, obj->VertexAttrib[i].BufferObj ); 00344 } 00345 #endif 00346 00347 /* The ID is immediately freed for re-use */ 00348 _mesa_remove_array_object(ctx, obj); 00349 ctx->Driver.DeleteArrayObject(ctx, obj); 00350 } 00351 } 00352 00353 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); 00354 } 00355 00356 00363 void GLAPIENTRY 00364 _mesa_GenVertexArraysAPPLE(GLsizei n, GLuint *arrays) 00365 { 00366 GET_CURRENT_CONTEXT(ctx); 00367 GLuint first; 00368 GLint i; 00369 ASSERT_OUTSIDE_BEGIN_END(ctx); 00370 00371 if (n < 0) { 00372 _mesa_error(ctx, GL_INVALID_VALUE, "glGenVertexArraysAPPLE"); 00373 return; 00374 } 00375 00376 if (!arrays) { 00377 return; 00378 } 00379 00380 /* 00381 * This must be atomic (generation and allocation of array object IDs) 00382 */ 00383 _glthread_LOCK_MUTEX(ctx->Shared->Mutex); 00384 00385 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->ArrayObjects, n); 00386 00387 /* Allocate new, empty array objects and return identifiers */ 00388 for (i = 0; i < n; i++) { 00389 struct gl_array_object *obj; 00390 GLuint name = first + i; 00391 00392 obj = (*ctx->Driver.NewArrayObject)( ctx, name ); 00393 if (!obj) { 00394 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); 00395 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenVertexArraysAPPLE"); 00396 return; 00397 } 00398 _mesa_save_array_object(ctx, obj); 00399 arrays[i] = first + i; 00400 } 00401 00402 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); 00403 } 00404 00405 00413 GLboolean GLAPIENTRY 00414 _mesa_IsVertexArrayAPPLE( GLuint id ) 00415 { 00416 struct gl_array_object * obj; 00417 GET_CURRENT_CONTEXT(ctx); 00418 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE); 00419 00420 if (id == 0) 00421 return GL_FALSE; 00422 00423 _glthread_LOCK_MUTEX(ctx->Shared->Mutex); 00424 obj = lookup_arrayobj(ctx, id); 00425 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); 00426 00427 return (obj != NULL) ? GL_TRUE : GL_FALSE; 00428 } Generated on Mon May 28 2012 04:19:56 for ReactOS by
1.7.6.1
|