Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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:36 jeroen Exp $ */
     1/* $Id: texobj.c,v 1.3 2000-05-23 20:40:55 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    2424 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    2525 */
    26 /* $XFree86: xc/lib/GL/mesa/src/texobj.c,v 1.3 1999/04/04 00:20:32 dawes Exp $ */
    27 
    28 
    29 
    3026
    3127#ifdef PC_HEADER
    3228#include "all.h"
    3329#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"
    4131#include "types.h"
    4232#include "context.h"
    4333#include "enums.h"
    4434#include "hash.h"
    45 #include "macros.h"
    4635#include "teximage.h"
    4736#include "texstate.h"
    4837#include "texobj.h"
     38#include "mem.h"
    4939#endif
    5040
     
    6050 * Return:  pointer to new texture object
    6151 */
     52
    6253struct gl_texture_object *
    6354gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name,
     
    6859   ASSERT(dimensions <= 3);
    6960
    70    obj = (struct gl_texture_object *)
    71                      calloc(1,sizeof(struct gl_texture_object));
     61   obj = CALLOC_STRUCT(gl_texture_object);
     62
    7263   if (obj) {
    7364      /* init the non-zero fields */
     
    8475      obj->MaxLevel = 1000;
    8576      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->PaletteSize = 1;
    91       obj->PaletteIntFormat = GL_RGBA;
    92       obj->PaletteFormat = 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;
    9384
    9485      /* insert into linked list */
    9586      if (shared) {
     87         _glthread_LOCK_MUTEX(shared->Mutex);
    9688         obj->Next = shared->TexObjectList;
    9789         shared->TexObjectList = obj;
     90         _glthread_UNLOCK_MUTEX(shared->Mutex);
    9891      }
    9992
    10093      if (name > 0) {
    10194         /* insert into hash table */
    102          HashInsert(shared->TexObjects, name, obj);
     95         _mesa_HashInsert(shared->TexObjects, name, obj);
    10396      }
    10497   }
     
    118111   struct gl_texture_object *tprev, *tcurr;
    119112
    120    assert(t);
     113   ASSERT(t);
    121114
    122115   /* Remove t from dirty list so we don't touch free'd memory later.
     
    128121   /* unlink t from the linked list */
    129122   if (shared) {
     123      _glthread_LOCK_MUTEX(shared->Mutex);
    130124      tprev = NULL;
    131125      tcurr = shared->TexObjectList;
     
    143137         tcurr = tcurr->Next;
    144138      }
     139      _glthread_UNLOCK_MUTEX(shared->Mutex);
    145140   }
    146141
    147142   if (t->Name) {
    148143      /* remove from hash table */
    149       HashRemove(shared->TexObjects, t->Name);
     144      _mesa_HashRemove(shared->TexObjects, t->Name);
    150145   }
    151146
     
    290285         GLuint height = t->Image[0]->Height2;
    291286         GLuint depth = t->Image[0]->Depth2;
    292         for (i=1; i<ctx->Const.MaxTextureLevels; i++) {
     287        for (i=1; i<ctx->Const.MaxTextureLevels; i++) {
    293288            if (width>1) {
    294289               width /= 2;
     
    331326
    332327
     328_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
     329
    333330
    334331/*
    335332 * Execute glGenTextures
    336333 */
    337 void gl_GenTextures( GLcontext *ctx, GLsizei n, GLuint *texName )
    338 {
     334void
     335_mesa_GenTextures( GLsizei n, GLuint *texName )
     336{
     337   GET_CURRENT_CONTEXT(ctx);
    339338   GLuint first;
    340339   GLint i;
     
    346345   }
    347346
    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);
    349354
    350355   /* Return the texture names */
     
    359364      (void) gl_alloc_texture_object(ctx->Shared, name, dims);
    360365   }
     366
     367   _glthread_UNLOCK_MUTEX(GenTexturesLock);
    361368}
    362369
     
    366373 * Execute glDeleteTextures
    367374 */
    368 void gl_DeleteTextures( GLcontext *ctx, GLsizei n, const GLuint *texName)
    369 {
     375void
     376_mesa_DeleteTextures( GLsizei n, const GLuint *texName)
     377{
     378   GET_CURRENT_CONTEXT(ctx);
    370379   GLint i;
    371380
     
    376385      if (texName[i]>0) {
    377386         t = (struct gl_texture_object *)
    378             HashLookup(ctx->Shared->TexObjects, texName[i]);
     387            _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
    379388         if (t) {
     389            /* First check if this texture is currently bound.
     390             * If so, unbind it and decrement the reference count.
     391             */
    380392            GLuint u;
    381             for (u=0; u<MAX_TEXTURE_UNITS; u++) {
     393            for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
    382394               struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
    383                GLuint d;
    384                for (d = 1 ; d <= 3 ; d++) {
    385                   if (unit->CurrentD[d]==t) {
    386                      unit->CurrentD[d] = ctx->Shared->DefaultD[d];
    387                      ctx->Shared->DefaultD[d]->RefCount++;
    388                      t->RefCount--;
    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 );
    400412               gl_free_texture_object(ctx->Shared, t);
    401413            }
     
    410422 * Execute glBindTexture
    411423 */
    412 void gl_BindTexture( GLcontext *ctx, GLenum target, GLuint texName )
    413 {
     424void
     425_mesa_BindTexture( GLenum target, GLuint texName )
     426{
     427   GET_CURRENT_CONTEXT(ctx);
    414428   GLuint unit = ctx->Texture.CurrentUnit;
    415429   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
     
    420434   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
    421435      fprintf(stderr, "glBindTexture %s %d\n",
    422               gl_lookup_enum_by_nr(target), (GLint) texName);
     436              gl_lookup_enum_by_nr(target), (GLint) texName);
    423437
    424438   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBindTexture");
     
    447461      newTexObj = ctx->Shared->DefaultD[dim];
    448462   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);
    451465
    452466      if (!newTexObj)
    453         newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim);
     467        newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim);
    454468
    455469      if (newTexObj->Dimensions != dim) {
    456         if (newTexObj->Dimensions) {
     470        if (newTexObj->Dimensions) {
    457471            /* the named texture object's dimensions don't match the target */
    458             gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" );
    459             return;
    460         }
    461         newTexObj->Dimensions = dim;
     472            gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" );
     473            return;
     474        }
     475        newTexObj->Dimensions = dim;
    462476      }
    463477   }
     
    480494        || oldTexObj->MagFilter != newTexObj->MagFilter
    481495        || (oldTexObj->Image[0] && newTexObj->Image[0] &&
    482            (oldTexObj->Image[0]->Format!=newTexObj->Image[0]->Format))))
     496           (oldTexObj->Image[0]->Format!=newTexObj->Image[0]->Format))))
    483497   {
    484498      ctx->NewState |= (NEW_RASTER_OPS | NEW_TEXTURING);
     
    498512      if (oldTexObj->RefCount <= 0) {
    499513         if (ctx->Driver.DeleteTexture) {
    500             (*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
    501         }
     514            (*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
     515        }
    502516         gl_free_texture_object(ctx->Shared, oldTexObj);
    503517      }
     
    510524 * Execute glPrioritizeTextures
    511525 */
    512 void gl_PrioritizeTextures( GLcontext *ctx,
    513                             GLsizei n, const GLuint *texName,
    514                             const GLclampf *priorities )
    515 {
     526void
     527_mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
     528                          const GLclampf *priorities )
     529{
     530   GET_CURRENT_CONTEXT(ctx);
    516531   GLint i;
    517532
     
    526541      if (texName[i]>0) {
    527542         t = (struct gl_texture_object *)
    528             HashLookup(ctx->Shared->TexObjects, texName[i]);
     543            _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
    529544         if (t) {
    530545            t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
    531546
    532             if (ctx->Driver.PrioritizeTexture)
    533                ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
     547            if (ctx->Driver.PrioritizeTexture)
     548               ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
    534549         }
    535550      }
     
    542557 * Execute glAreTexturesResident
    543558 */
    544 GLboolean gl_AreTexturesResident( GLcontext *ctx, GLsizei n,
    545                                   const GLuint *texName,
    546                                   GLboolean *residences )
    547 {
     559GLboolean
     560_mesa_AreTexturesResident( GLsizei n, const GLuint *texName,
     561                           GLboolean *residences )
     562{
     563   GET_CURRENT_CONTEXT(ctx);
    548564   GLboolean resident = GL_TRUE;
    549565   GLint i;
    550566
    551567   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx,
    552                                                   "glAreTexturesResident",
    553                                                   GL_FALSE);
     568                                                  "glAreTexturesResident",
     569                                                  GL_FALSE);
    554570   if (n<0) {
    555571      gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" );
     
    564580      }
    565581      t = (struct gl_texture_object *)
    566          HashLookup(ctx->Shared->TexObjects, texName[i]);
     582         _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
    567583      if (t) {
    568         if (ctx->Driver.IsTextureResident)
    569             residences[i] = ctx->Driver.IsTextureResident( ctx, t );
    570         else
    571             residences[i] = GL_TRUE;
     584        if (ctx->Driver.IsTextureResident)
     585            residences[i] = ctx->Driver.IsTextureResident( ctx, t );
     586        else
     587            residences[i] = GL_TRUE;
    572588      }
    573589      else {
     
    584600 * Execute glIsTexture
    585601 */
    586 GLboolean gl_IsTexture( GLcontext *ctx, GLuint texture )
    587 {
     602GLboolean
     603_mesa_IsTexture( GLuint texture )
     604{
     605   GET_CURRENT_CONTEXT(ctx);
    588606   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures",
    589                                                   GL_FALSE);
    590    if (texture>0 && HashLookup(ctx->Shared->TexObjects, texture)) {
     607                                                  GL_FALSE);
     608   if (texture>0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) {
    591609      return GL_TRUE;
    592610   }
Note: See TracChangeset for help on using the changeset viewer.