Changeset 3598 for trunk/src/opengl/mesa/texobj.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/texobj.c
r2962 r3598 1 /* $Id: texobj.c,v 1. 2 2000-03-01 18:49:36jeroen Exp $ */1 /* $Id: texobj.c,v 1.3 2000-05-23 20:40:55 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 24 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 25 */ 26 /* $XFree86: xc/lib/GL/mesa/src/texobj.c,v 1.3 1999/04/04 00:20:32 dawes Exp $ */27 28 29 30 26 31 27 #ifdef PC_HEADER 32 28 #include "all.h" 33 29 #else 34 #ifndef XFree86Server 35 #include <assert.h> 36 #include <stdio.h> 37 #include <stdlib.h> 38 #else 39 #include "GL/xf86glx.h" 40 #endif 30 #include "glheader.h" 41 31 #include "types.h" 42 32 #include "context.h" 43 33 #include "enums.h" 44 34 #include "hash.h" 45 #include "macros.h"46 35 #include "teximage.h" 47 36 #include "texstate.h" 48 37 #include "texobj.h" 38 #include "mem.h" 49 39 #endif 50 40 … … 60 50 * Return: pointer to new texture object 61 51 */ 52 62 53 struct gl_texture_object * 63 54 gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name, … … 68 59 ASSERT(dimensions <= 3); 69 60 70 obj = (struct gl_texture_object *)71 calloc(1,sizeof(struct gl_texture_object)); 61 obj = CALLOC_STRUCT(gl_texture_object); 62 72 63 if (obj) { 73 64 /* init the non-zero fields */ … … 84 75 obj->MaxLevel = 1000; 85 76 obj->MinMagThresh = 0.0F; 86 obj->Palette [0] = 255;87 obj->Palette [1] = 255;88 obj->Palette [2] = 255;89 obj->Palette [3] = 255;90 obj->Palette Size = 1;91 obj->Palette IntFormat = GL_RGBA;92 obj->Palette Format = GL_RGBA;77 obj->Palette.Table[0] = 255; 78 obj->Palette.Table[1] = 255; 79 obj->Palette.Table[2] = 255; 80 obj->Palette.Table[3] = 255; 81 obj->Palette.Size = 1; 82 obj->Palette.IntFormat = GL_RGBA; 83 obj->Palette.Format = GL_RGBA; 93 84 94 85 /* insert into linked list */ 95 86 if (shared) { 87 _glthread_LOCK_MUTEX(shared->Mutex); 96 88 obj->Next = shared->TexObjectList; 97 89 shared->TexObjectList = obj; 90 _glthread_UNLOCK_MUTEX(shared->Mutex); 98 91 } 99 92 100 93 if (name > 0) { 101 94 /* insert into hash table */ 102 HashInsert(shared->TexObjects, name, obj);95 _mesa_HashInsert(shared->TexObjects, name, obj); 103 96 } 104 97 } … … 118 111 struct gl_texture_object *tprev, *tcurr; 119 112 120 assert(t);113 ASSERT(t); 121 114 122 115 /* Remove t from dirty list so we don't touch free'd memory later. … … 128 121 /* unlink t from the linked list */ 129 122 if (shared) { 123 _glthread_LOCK_MUTEX(shared->Mutex); 130 124 tprev = NULL; 131 125 tcurr = shared->TexObjectList; … … 143 137 tcurr = tcurr->Next; 144 138 } 139 _glthread_UNLOCK_MUTEX(shared->Mutex); 145 140 } 146 141 147 142 if (t->Name) { 148 143 /* remove from hash table */ 149 HashRemove(shared->TexObjects, t->Name);144 _mesa_HashRemove(shared->TexObjects, t->Name); 150 145 } 151 146 … … 290 285 GLuint height = t->Image[0]->Height2; 291 286 GLuint depth = t->Image[0]->Depth2; 292 287 for (i=1; i<ctx->Const.MaxTextureLevels; i++) { 293 288 if (width>1) { 294 289 width /= 2; … … 331 326 332 327 328 _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock); 329 333 330 334 331 /* 335 332 * Execute glGenTextures 336 333 */ 337 void gl_GenTextures( GLcontext *ctx, GLsizei n, GLuint *texName ) 338 { 334 void 335 _mesa_GenTextures( GLsizei n, GLuint *texName ) 336 { 337 GET_CURRENT_CONTEXT(ctx); 339 338 GLuint first; 340 339 GLint i; … … 346 345 } 347 346 348 first = HashFindFreeKeyBlock(ctx->Shared->TexObjects, n); 347 348 /* 349 * This must be atomic (generation and allocation of texture IDs) 350 */ 351 _glthread_LOCK_MUTEX(GenTexturesLock); 352 353 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n); 349 354 350 355 /* Return the texture names */ … … 359 364 (void) gl_alloc_texture_object(ctx->Shared, name, dims); 360 365 } 366 367 _glthread_UNLOCK_MUTEX(GenTexturesLock); 361 368 } 362 369 … … 366 373 * Execute glDeleteTextures 367 374 */ 368 void gl_DeleteTextures( GLcontext *ctx, GLsizei n, const GLuint *texName) 369 { 375 void 376 _mesa_DeleteTextures( GLsizei n, const GLuint *texName) 377 { 378 GET_CURRENT_CONTEXT(ctx); 370 379 GLint i; 371 380 … … 376 385 if (texName[i]>0) { 377 386 t = (struct gl_texture_object *) 378 HashLookup(ctx->Shared->TexObjects, texName[i]);387 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); 379 388 if (t) { 389 /* First check if this texture is currently bound. 390 * If so, unbind it and decrement the reference count. 391 */ 380 392 GLuint u; 381 for (u =0; u<MAX_TEXTURE_UNITS; u++) {393 for (u = 0; u < MAX_TEXTURE_UNITS; u++) { 382 394 struct gl_texture_unit *unit = &ctx->Texture.Unit[u]; 383 384 385 if (unit->CurrentD[d]==t) {386 387 388 389 assert( t->RefCount >= 0 );390 391 392 } 393 394 /* tell device driver to delete texture*/395 if (ctx->Driver.DeleteTexture) {396 (*ctx->Driver.DeleteTexture)( ctx, t);397 }398 399 if (t->RefCount==0) {395 GLuint d; 396 for (d = 1 ; d <= 3 ; d++) { 397 if (unit->CurrentD[d] == t) { 398 unit->CurrentD[d] = ctx->Shared->DefaultD[d]; 399 ctx->Shared->DefaultD[d]->RefCount++; 400 t->RefCount--; 401 ASSERT( t->RefCount >= 0 ); 402 } 403 } 404 } 405 406 /* Decrement reference count and delete if zero */ 407 t->RefCount--; 408 ASSERT( t->RefCount >= 0 ); 409 if (t->RefCount == 0) { 410 if (ctx->Driver.DeleteTexture) 411 (*ctx->Driver.DeleteTexture)( ctx, t ); 400 412 gl_free_texture_object(ctx->Shared, t); 401 413 } … … 410 422 * Execute glBindTexture 411 423 */ 412 void gl_BindTexture( GLcontext *ctx, GLenum target, GLuint texName ) 413 { 424 void 425 _mesa_BindTexture( GLenum target, GLuint texName ) 426 { 427 GET_CURRENT_CONTEXT(ctx); 414 428 GLuint unit = ctx->Texture.CurrentUnit; 415 429 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; … … 420 434 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 421 435 fprintf(stderr, "glBindTexture %s %d\n", 422 436 gl_lookup_enum_by_nr(target), (GLint) texName); 423 437 424 438 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBindTexture"); … … 447 461 newTexObj = ctx->Shared->DefaultD[dim]; 448 462 else { 449 struct HashTable *hash = ctx->Shared->TexObjects;450 newTexObj = (struct gl_texture_object *) HashLookup(hash, texName);463 struct _mesa_HashTable *hash = ctx->Shared->TexObjects; 464 newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName); 451 465 452 466 if (!newTexObj) 453 467 newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim); 454 468 455 469 if (newTexObj->Dimensions != dim) { 456 470 if (newTexObj->Dimensions) { 457 471 /* the named texture object's dimensions don't match the target */ 458 459 460 461 472 gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" ); 473 return; 474 } 475 newTexObj->Dimensions = dim; 462 476 } 463 477 } … … 480 494 || oldTexObj->MagFilter != newTexObj->MagFilter 481 495 || (oldTexObj->Image[0] && newTexObj->Image[0] && 482 496 (oldTexObj->Image[0]->Format!=newTexObj->Image[0]->Format)))) 483 497 { 484 498 ctx->NewState |= (NEW_RASTER_OPS | NEW_TEXTURING); … … 498 512 if (oldTexObj->RefCount <= 0) { 499 513 if (ctx->Driver.DeleteTexture) { 500 501 514 (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); 515 } 502 516 gl_free_texture_object(ctx->Shared, oldTexObj); 503 517 } … … 510 524 * Execute glPrioritizeTextures 511 525 */ 512 void gl_PrioritizeTextures( GLcontext *ctx, 513 GLsizei n, const GLuint *texName, 514 const GLclampf *priorities ) 515 { 526 void 527 _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, 528 const GLclampf *priorities ) 529 { 530 GET_CURRENT_CONTEXT(ctx); 516 531 GLint i; 517 532 … … 526 541 if (texName[i]>0) { 527 542 t = (struct gl_texture_object *) 528 HashLookup(ctx->Shared->TexObjects, texName[i]);543 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); 529 544 if (t) { 530 545 t->Priority = CLAMP( priorities[i], 0.0F, 1.0F ); 531 546 532 533 547 if (ctx->Driver.PrioritizeTexture) 548 ctx->Driver.PrioritizeTexture( ctx, t, t->Priority ); 534 549 } 535 550 } … … 542 557 * Execute glAreTexturesResident 543 558 */ 544 GLboolean gl_AreTexturesResident( GLcontext *ctx, GLsizei n, 545 const GLuint *texName, 546 GLboolean *residences ) 547 { 559 GLboolean 560 _mesa_AreTexturesResident( GLsizei n, const GLuint *texName, 561 GLboolean *residences ) 562 { 563 GET_CURRENT_CONTEXT(ctx); 548 564 GLboolean resident = GL_TRUE; 549 565 GLint i; 550 566 551 567 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, 552 553 568 "glAreTexturesResident", 569 GL_FALSE); 554 570 if (n<0) { 555 571 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" ); … … 564 580 } 565 581 t = (struct gl_texture_object *) 566 HashLookup(ctx->Shared->TexObjects, texName[i]);582 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); 567 583 if (t) { 568 569 570 571 584 if (ctx->Driver.IsTextureResident) 585 residences[i] = ctx->Driver.IsTextureResident( ctx, t ); 586 else 587 residences[i] = GL_TRUE; 572 588 } 573 589 else { … … 584 600 * Execute glIsTexture 585 601 */ 586 GLboolean gl_IsTexture( GLcontext *ctx, GLuint texture ) 587 { 602 GLboolean 603 _mesa_IsTexture( GLuint texture ) 604 { 605 GET_CURRENT_CONTEXT(ctx); 588 606 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures", 589 590 if (texture>0 && HashLookup(ctx->Shared->TexObjects, texture)) {607 GL_FALSE); 608 if (texture>0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) { 591 609 return GL_TRUE; 592 610 }
Note:
See TracChangeset
for help on using the changeset viewer.