| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 1 | /* $Id: texobj.c,v 1.35 2000/11/22 07:32:17 joukj Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 5 | * Version: 3.5 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 6 | * |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 8 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 15 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 18 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 32 | #include "colortab.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | #include "context.h" |
| 34 | #include "enums.h" |
| 35 | #include "hash.h" |
| Brian Paul | ebb248a | 2000-10-29 18:23:16 +0000 | [diff] [blame] | 36 | #include "macros.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 37 | #include "mem.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 38 | #include "teximage.h" |
| 39 | #include "texstate.h" |
| 40 | #include "texobj.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 41 | #include "mtypes.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Allocate a new texture object and add it to the linked list of texture |
| 48 | * objects. If name>0 then also insert the new texture object into the hash |
| 49 | * table. |
| 50 | * Input: shared - the shared GL state structure to contain the texture object |
| 51 | * name - integer name for the texture object |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 52 | * dimensions - either 1, 2, 3 or 6 (cube map) |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 53 | * zero is ok for the sake of GenTextures() |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 54 | * Return: pointer to new texture object |
| 55 | */ |
| 56 | struct gl_texture_object * |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 57 | _mesa_alloc_texture_object( struct gl_shared_state *shared, GLuint name, |
| 58 | GLuint dimensions) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 59 | { |
| 60 | struct gl_texture_object *obj; |
| 61 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 62 | ASSERT(dimensions <= 3 || dimensions == 6); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 63 | |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 64 | obj = CALLOC_STRUCT(gl_texture_object); |
| 65 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 66 | if (obj) { |
| 67 | /* init the non-zero fields */ |
| Brian Paul | e4b684c | 2000-09-12 21:07:40 +0000 | [diff] [blame] | 68 | _glthread_INIT_MUTEX(obj->Mutex); |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 69 | obj->RefCount = 1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 70 | obj->Name = name; |
| 71 | obj->Dimensions = dimensions; |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 72 | obj->Priority = 1.0F; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 73 | obj->WrapS = GL_REPEAT; |
| 74 | obj->WrapT = GL_REPEAT; |
| Brian Paul | 7351049 | 2000-11-11 20:23:47 +0000 | [diff] [blame] | 75 | obj->WrapR = GL_REPEAT; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 76 | obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR; |
| 77 | obj->MagFilter = GL_LINEAR; |
| 78 | obj->MinLod = -1000.0; |
| 79 | obj->MaxLod = 1000.0; |
| 80 | obj->BaseLevel = 0; |
| 81 | obj->MaxLevel = 1000; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 82 | _mesa_init_colortable(&obj->Palette); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 83 | |
| 84 | /* insert into linked list */ |
| 85 | if (shared) { |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 86 | _glthread_LOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 87 | obj->Next = shared->TexObjectList; |
| 88 | shared->TexObjectList = obj; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 89 | _glthread_UNLOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | if (name > 0) { |
| 93 | /* insert into hash table */ |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 94 | _mesa_HashInsert(shared->TexObjects, name, obj); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | return obj; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | * Deallocate a texture object struct and remove it from the given |
| 103 | * shared GL state. |
| 104 | * Input: shared - the shared GL state to which the object belongs |
| 105 | * t - the texture object to delete |
| 106 | */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 107 | void _mesa_free_texture_object( struct gl_shared_state *shared, |
| 108 | struct gl_texture_object *t ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | { |
| 110 | struct gl_texture_object *tprev, *tcurr; |
| 111 | |
| 112 | assert(t); |
| 113 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 114 | /* unlink t from the linked list */ |
| 115 | if (shared) { |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 116 | _glthread_LOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 117 | tprev = NULL; |
| 118 | tcurr = shared->TexObjectList; |
| 119 | while (tcurr) { |
| 120 | if (tcurr==t) { |
| 121 | if (tprev) { |
| 122 | tprev->Next = t->Next; |
| 123 | } |
| 124 | else { |
| 125 | shared->TexObjectList = t->Next; |
| 126 | } |
| 127 | break; |
| 128 | } |
| 129 | tprev = tcurr; |
| 130 | tcurr = tcurr->Next; |
| 131 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 132 | _glthread_UNLOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | if (t->Name) { |
| 136 | /* remove from hash table */ |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 137 | _mesa_HashRemove(shared->TexObjects, t->Name); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 140 | _mesa_free_colortable_data(&t->Palette); |
| 141 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 142 | /* free the texture images */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 143 | { |
| 144 | GLuint i; |
| 145 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| 146 | if (t->Image[i]) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 147 | _mesa_free_texture_image( t->Image[i] ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 151 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 152 | /* free this object */ |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 153 | FREE( t ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Report why a texture object is incomplete. (for debug only) |
| 159 | */ |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 160 | #if 0 |
| 161 | static void |
| 162 | incomplete(const struct gl_texture_object *t, const char *why) |
| 163 | { |
| 164 | printf("Texture Obj %d incomplete because: %s\n", t->Name, why); |
| 165 | } |
| 166 | #else |
| 167 | #define incomplete(a, b) |
| 168 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 169 | |
| 170 | |
| 171 | /* |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 172 | * Examine a texture object to determine if it is complete. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 173 | * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly. |
| 174 | */ |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 175 | void |
| 176 | _mesa_test_texobj_completeness( const GLcontext *ctx, |
| 177 | struct gl_texture_object *t ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 178 | { |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 179 | const GLint baseLevel = t->BaseLevel; |
| 180 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 181 | t->Complete = GL_TRUE; /* be optimistic */ |
| 182 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 183 | /* Always need the base level image */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 184 | if (!t->Image[baseLevel]) { |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 185 | incomplete(t, "Image[baseLevel] == NULL"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 186 | t->Complete = GL_FALSE; |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | /* Compute number of mipmap levels */ |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 191 | if (t->Dimensions == 1) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 192 | t->_P = t->Image[baseLevel]->WidthLog2; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 193 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 194 | else if (t->Dimensions == 2 || t->Dimensions == 6) { |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 195 | t->_P = MAX2(t->Image[baseLevel]->WidthLog2, |
| 196 | t->Image[baseLevel]->HeightLog2); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 197 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 198 | else if (t->Dimensions == 3) { |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 199 | GLint max = MAX2(t->Image[baseLevel]->WidthLog2, |
| 200 | t->Image[baseLevel]->HeightLog2); |
| 201 | max = MAX2(max, (GLint)(t->Image[baseLevel]->DepthLog2)); |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 202 | t->_P = max; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* Compute M (see the 1.2 spec) used during mipmapping */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 206 | t->_M = (GLfloat) (MIN2(t->MaxLevel, t->_P) - t->BaseLevel); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 207 | |
| 208 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 209 | if (t->Dimensions == 6) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 210 | /* make sure that all six cube map level 0 images are the same size */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 211 | const GLint w = t->Image[baseLevel]->Width2; |
| 212 | const GLint h = t->Image[baseLevel]->Height2; |
| 213 | if (!t->NegX[baseLevel] || |
| 214 | t->NegX[baseLevel]->Width2 != w || |
| 215 | t->NegX[baseLevel]->Height2 != h || |
| 216 | !t->PosY[baseLevel] || |
| 217 | t->PosY[baseLevel]->Width2 != w || |
| 218 | t->PosY[baseLevel]->Height2 != h || |
| 219 | !t->NegY[baseLevel] || |
| 220 | t->NegY[baseLevel]->Width2 != w || |
| 221 | t->NegY[baseLevel]->Height2 != h || |
| 222 | !t->PosZ[baseLevel] || |
| 223 | t->PosZ[baseLevel]->Width2 != w || |
| 224 | t->PosZ[baseLevel]->Height2 != h || |
| 225 | !t->NegZ[baseLevel] || |
| 226 | t->NegZ[baseLevel]->Width2 != w || |
| 227 | t->NegZ[baseLevel]->Height2 != h) { |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 228 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 229 | incomplete(t, "Non-quare cubemap image"); |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 230 | return; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 235 | /* |
| 236 | * Mipmapping: determine if we have a complete set of mipmaps |
| 237 | */ |
| 238 | GLint i; |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 239 | GLint minLevel = baseLevel; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 240 | GLint maxLevel = MIN2(t->_P, ctx->Const.MaxTextureLevels-1); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 241 | maxLevel = MIN2(maxLevel, t->MaxLevel); |
| 242 | |
| 243 | if (minLevel > maxLevel) { |
| 244 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 245 | incomplete(t, "minLevel > maxLevel"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 246 | return; |
| 247 | } |
| 248 | |
| 249 | /* Test dimension-independent attributes */ |
| 250 | for (i = minLevel; i <= maxLevel; i++) { |
| 251 | if (t->Image[i]) { |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 252 | if (t->Image[i]->Format != t->Image[baseLevel]->Format) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 253 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 254 | incomplete(t, "Format[i] != Format[baseLevel]"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 255 | return; |
| 256 | } |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 257 | if (t->Image[i]->Border != t->Image[baseLevel]->Border) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 258 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 259 | incomplete(t, "Border[i] != Border[baseLevel]"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /* Test things which depend on number of texture image dimensions */ |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 266 | if (t->Dimensions == 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 267 | /* Test 1-D mipmaps */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 268 | GLuint width = t->Image[baseLevel]->Width2; |
| 269 | for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) { |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 270 | if (width > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 271 | width /= 2; |
| 272 | } |
| 273 | if (i >= minLevel && i <= maxLevel) { |
| 274 | if (!t->Image[i]) { |
| 275 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 276 | incomplete(t, "1D Image[i] == NULL"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 277 | return; |
| 278 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 279 | if (t->Image[i]->Width2 != width ) { |
| 280 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 281 | incomplete(t, "1D Image[i] bad width"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 285 | if (width == 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 286 | return; /* found smallest needed mipmap, all done! */ |
| 287 | } |
| 288 | } |
| 289 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 290 | else if (t->Dimensions == 2) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 291 | /* Test 2-D mipmaps */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 292 | GLuint width = t->Image[baseLevel]->Width2; |
| 293 | GLuint height = t->Image[baseLevel]->Height2; |
| 294 | for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) { |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 295 | if (width > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 296 | width /= 2; |
| 297 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 298 | if (height > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 299 | height /= 2; |
| 300 | } |
| 301 | if (i >= minLevel && i <= maxLevel) { |
| 302 | if (!t->Image[i]) { |
| 303 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 304 | incomplete(t, "2D Image[i] == NULL"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | if (t->Image[i]->Width2 != width) { |
| 308 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 309 | incomplete(t, "2D Image[i] bad width"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 310 | return; |
| 311 | } |
| 312 | if (t->Image[i]->Height2 != height) { |
| 313 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 314 | incomplete(t, "2D Image[i] bad height"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | if (width==1 && height==1) { |
| 318 | return; /* found smallest needed mipmap, all done! */ |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 323 | else if (t->Dimensions == 3) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 324 | /* Test 3-D mipmaps */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 325 | GLuint width = t->Image[baseLevel]->Width2; |
| 326 | GLuint height = t->Image[baseLevel]->Height2; |
| 327 | GLuint depth = t->Image[baseLevel]->Depth2; |
| 328 | for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) { |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 329 | if (width > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 330 | width /= 2; |
| 331 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 332 | if (height > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 333 | height /= 2; |
| 334 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 335 | if (depth > 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 336 | depth /= 2; |
| 337 | } |
| 338 | if (i >= minLevel && i <= maxLevel) { |
| 339 | if (!t->Image[i]) { |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 340 | incomplete(t, "3D Image[i] == NULL"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 341 | t->Complete = GL_FALSE; |
| 342 | return; |
| 343 | } |
| 344 | if (t->Image[i]->Width2 != width) { |
| 345 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 346 | incomplete(t, "3D Image[i] bad width"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | if (t->Image[i]->Height2 != height) { |
| 350 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 351 | incomplete(t, "3D Image[i] bad height"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 352 | return; |
| 353 | } |
| 354 | if (t->Image[i]->Depth2 != depth) { |
| 355 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 356 | incomplete(t, "3D Image[i] bad depth"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 357 | return; |
| 358 | } |
| 359 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 360 | if (width == 1 && height == 1 && depth == 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 361 | return; /* found smallest needed mipmap, all done! */ |
| 362 | } |
| 363 | } |
| 364 | } |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 365 | else if (t->Dimensions == 6) { |
| 366 | /* make sure 6 cube faces are consistant */ |
| Brian Paul | 63ec423 | 2000-06-12 16:09:49 +0000 | [diff] [blame] | 367 | GLuint width = t->Image[baseLevel]->Width2; |
| 368 | GLuint height = t->Image[baseLevel]->Height2; |
| 369 | for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) { |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 370 | if (width > 1) { |
| 371 | width /= 2; |
| 372 | } |
| 373 | if (height > 1) { |
| 374 | height /= 2; |
| 375 | } |
| 376 | if (i >= minLevel && i <= maxLevel) { |
| 377 | /* check that we have images defined */ |
| 378 | if (!t->Image[i] || !t->NegX[i] || |
| 379 | !t->PosY[i] || !t->NegY[i] || |
| 380 | !t->PosZ[i] || !t->NegZ[i]) { |
| 381 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 382 | incomplete(t, "CubeMap Image[i] == NULL"); |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | /* check that all six images have same size */ |
| 386 | if (t->NegX[i]->Width2!=width || t->NegX[i]->Height2!=height || |
| 387 | t->PosY[i]->Width2!=width || t->PosY[i]->Height2!=height || |
| 388 | t->NegY[i]->Width2!=width || t->NegY[i]->Height2!=height || |
| 389 | t->PosZ[i]->Width2!=width || t->PosZ[i]->Height2!=height || |
| 390 | t->NegZ[i]->Width2!=width || t->NegZ[i]->Height2!=height) { |
| 391 | t->Complete = GL_FALSE; |
| Brian Paul | 21d073d | 2000-10-24 02:53:18 +0000 | [diff] [blame] | 392 | incomplete(t, "CubeMap Image[i] bad size"); |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | } |
| 396 | if (width == 1 && height == 1) { |
| 397 | return; /* found smallest needed mipmap, all done! */ |
| 398 | } |
| 399 | } |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 400 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 401 | else { |
| 402 | /* Dimensions = ??? */ |
| 403 | gl_problem(NULL, "Bug in gl_test_texture_object_completeness\n"); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | |
| Brian Paul | 832179c | 2000-03-21 17:42:27 +0000 | [diff] [blame] | 409 | _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock); |
| 410 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * Execute glGenTextures |
| 414 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 415 | void |
| 416 | _mesa_GenTextures( GLsizei n, GLuint *texName ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 417 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 418 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 419 | GLuint first; |
| 420 | GLint i; |
| 421 | |
| 422 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGenTextures"); |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 423 | if (n < 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 424 | gl_error( ctx, GL_INVALID_VALUE, "glGenTextures" ); |
| 425 | return; |
| 426 | } |
| 427 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 428 | if (!texName) |
| 429 | return; |
| Brian Paul | 832179c | 2000-03-21 17:42:27 +0000 | [diff] [blame] | 430 | |
| 431 | /* |
| 432 | * This must be atomic (generation and allocation of texture IDs) |
| 433 | */ |
| 434 | _glthread_LOCK_MUTEX(GenTexturesLock); |
| 435 | |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 436 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 437 | |
| 438 | /* Return the texture names */ |
| 439 | for (i=0;i<n;i++) { |
| 440 | texName[i] = first + i; |
| 441 | } |
| 442 | |
| 443 | /* Allocate new, empty texture objects */ |
| 444 | for (i=0;i<n;i++) { |
| 445 | GLuint name = first + i; |
| 446 | GLuint dims = 0; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 447 | (void) _mesa_alloc_texture_object(ctx->Shared, name, dims); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 448 | } |
| Brian Paul | 832179c | 2000-03-21 17:42:27 +0000 | [diff] [blame] | 449 | |
| 450 | _glthread_UNLOCK_MUTEX(GenTexturesLock); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
| 454 | |
| 455 | /* |
| 456 | * Execute glDeleteTextures |
| 457 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 458 | void |
| 459 | _mesa_DeleteTextures( GLsizei n, const GLuint *texName) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 460 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 461 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 462 | GLint i; |
| 463 | |
| 464 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDeleteTextures"); |
| 465 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 466 | if (!texName) |
| 467 | return; |
| 468 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 469 | for (i=0;i<n;i++) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 470 | if (texName[i] > 0) { |
| 471 | struct gl_texture_object *delObj = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 472 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 473 | if (delObj) { |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 474 | /* First check if this texture is currently bound. |
| 475 | * If so, unbind it and decrement the reference count. |
| 476 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 477 | GLuint u; |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 478 | for (u = 0; u < MAX_TEXTURE_UNITS; u++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 479 | struct gl_texture_unit *unit = &ctx->Texture.Unit[u]; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 480 | if (delObj == unit->Current1D) { |
| 481 | unit->Current1D = ctx->Shared->Default1D; |
| 482 | ctx->Shared->Default1D->RefCount++; |
| 483 | } |
| 484 | else if (delObj == unit->Current2D) { |
| 485 | unit->Current2D = ctx->Shared->Default2D; |
| 486 | ctx->Shared->Default2D->RefCount++; |
| 487 | } |
| 488 | else if (delObj == unit->Current3D) { |
| 489 | unit->Current3D = ctx->Shared->Default3D; |
| 490 | ctx->Shared->Default3D->RefCount++; |
| 491 | } |
| 492 | else if (delObj == unit->CurrentCubeMap) { |
| 493 | unit->CurrentCubeMap = ctx->Shared->DefaultCubeMap; |
| 494 | ctx->Shared->DefaultCubeMap->RefCount++; |
| 495 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 496 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 497 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 498 | |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 499 | /* Decrement reference count and delete if zero */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 500 | delObj->RefCount--; |
| 501 | ASSERT( delObj->RefCount >= 0 ); |
| 502 | if (delObj->RefCount == 0) { |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 503 | if (ctx->Driver.DeleteTexture) |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 504 | (*ctx->Driver.DeleteTexture)( ctx, delObj ); |
| 505 | _mesa_free_texture_object(ctx->Shared, delObj); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | |
| 513 | |
| 514 | /* |
| 515 | * Execute glBindTexture |
| 516 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 517 | void |
| 518 | _mesa_BindTexture( GLenum target, GLuint texName ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 519 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 520 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 521 | GLuint unit = ctx->Texture.CurrentUnit; |
| 522 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; |
| 523 | struct gl_texture_object *oldTexObj; |
| 524 | struct gl_texture_object *newTexObj; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 525 | GLuint targetDim; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 526 | |
| 527 | if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) |
| 528 | fprintf(stderr, "glBindTexture %s %d\n", |
| 529 | gl_lookup_enum_by_nr(target), (GLint) texName); |
| 530 | |
| 531 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBindTexture"); |
| 532 | |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 533 | switch (target) { |
| 534 | case GL_TEXTURE_1D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 535 | targetDim = 1; |
| 536 | oldTexObj = texUnit->Current1D; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 537 | break; |
| 538 | case GL_TEXTURE_2D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 539 | targetDim = 2; |
| 540 | oldTexObj = texUnit->Current2D; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 541 | break; |
| 542 | case GL_TEXTURE_3D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 543 | targetDim = 3; |
| 544 | oldTexObj = texUnit->Current3D; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 545 | break; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 546 | case GL_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 547 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 548 | targetDim = 6; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 549 | oldTexObj = texUnit->CurrentCubeMap; |
| 550 | break; |
| 551 | } |
| 552 | /* fallthrough */ |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 553 | default: |
| 554 | gl_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); |
| 555 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 558 | if (oldTexObj->Name == texName) |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 559 | return; /* rebinding the same texture- no change */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 560 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 561 | /* |
| 562 | * Get pointer to new texture object (newTexObj) |
| 563 | */ |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 564 | if (texName == 0) { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 565 | /* newTexObj = a default texture object */ |
| 566 | switch (target) { |
| 567 | case GL_TEXTURE_1D: |
| 568 | newTexObj = ctx->Shared->Default1D; |
| 569 | break; |
| 570 | case GL_TEXTURE_2D: |
| 571 | newTexObj = ctx->Shared->Default2D; |
| 572 | break; |
| 573 | case GL_TEXTURE_3D: |
| 574 | newTexObj = ctx->Shared->Default3D; |
| 575 | break; |
| 576 | case GL_TEXTURE_CUBE_MAP_ARB: |
| 577 | newTexObj = ctx->Shared->DefaultCubeMap; |
| 578 | break; |
| 579 | default: |
| 580 | ; /* Bad targets are caught above */ |
| 581 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 582 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 583 | else { |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 584 | /* non-default texture object */ |
| 585 | const struct _mesa_HashTable *hash = ctx->Shared->TexObjects; |
| Brian Paul | c79fab4 | 2000-01-24 20:53:32 +0000 | [diff] [blame] | 586 | newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName); |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 587 | if (newTexObj) { |
| 588 | /* error checking */ |
| 589 | if (newTexObj->Dimensions > 0 && newTexObj->Dimensions != targetDim) { |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 590 | /* the named texture object's dimensions don't match the target */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 591 | gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" ); |
| 592 | return; |
| 593 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 594 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 595 | else { |
| 596 | /* if this is a new texture id, allocate a texture object now */ |
| 597 | newTexObj = _mesa_alloc_texture_object(ctx->Shared, texName, targetDim); |
| 598 | if (!newTexObj) { |
| 599 | gl_error(ctx, GL_OUT_OF_MEMORY, "glBindTexture"); |
| 600 | return; |
| 601 | } |
| 602 | } |
| 603 | newTexObj->Dimensions = targetDim; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 606 | newTexObj->RefCount++; |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 607 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 608 | /* do the actual binding */ |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 609 | switch (target) { |
| 610 | case GL_TEXTURE_1D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 611 | texUnit->Current1D = newTexObj; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 612 | break; |
| 613 | case GL_TEXTURE_2D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 614 | texUnit->Current2D = newTexObj; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 615 | break; |
| 616 | case GL_TEXTURE_3D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 617 | texUnit->Current3D = newTexObj; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 618 | break; |
| 619 | case GL_TEXTURE_CUBE_MAP_ARB: |
| 620 | texUnit->CurrentCubeMap = newTexObj; |
| 621 | break; |
| 622 | default: |
| 623 | gl_problem(ctx, "bad target in BindTexture"); |
| 624 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 625 | |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 626 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 627 | |
| 628 | /* Pass BindTexture call to device driver */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 629 | if (ctx->Driver.BindTexture) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 630 | (*ctx->Driver.BindTexture)( ctx, target, newTexObj ); |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 631 | |
| 632 | if (oldTexObj->Name > 0) { |
| 633 | /* never delete default (id=0) texture objects */ |
| 634 | oldTexObj->RefCount--; |
| 635 | if (oldTexObj->RefCount <= 0) { |
| 636 | if (ctx->Driver.DeleteTexture) { |
| 637 | (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); |
| 638 | } |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 639 | _mesa_free_texture_object(ctx->Shared, oldTexObj); |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
| 645 | |
| 646 | /* |
| 647 | * Execute glPrioritizeTextures |
| 648 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 649 | void |
| 650 | _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, |
| 651 | const GLclampf *priorities ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 652 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 653 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 654 | GLint i; |
| 655 | |
| 656 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPrioritizeTextures"); |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 657 | if (n < 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 658 | gl_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" ); |
| 659 | return; |
| 660 | } |
| 661 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 662 | if (!priorities) |
| 663 | return; |
| 664 | |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 665 | for (i = 0; i < n; i++) { |
| 666 | if (texName[i] > 0) { |
| 667 | struct gl_texture_object *t = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 668 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 669 | if (t) { |
| 670 | t->Priority = CLAMP( priorities[i], 0.0F, 1.0F ); |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 671 | if (ctx->Driver.PrioritizeTexture) |
| 672 | ctx->Driver.PrioritizeTexture( ctx, t, t->Priority ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 676 | |
| 677 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | |
| 682 | /* |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 683 | * Execute glAreTexturesResident |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 684 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 685 | GLboolean |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 686 | _mesa_AreTexturesResident(GLsizei n, const GLuint *texName, |
| 687 | GLboolean *residences) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 688 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 689 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 690 | GLboolean allResident = GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 691 | GLint i; |
| 692 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 693 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 694 | "glAreTexturesResident", GL_FALSE); |
| 695 | if (n < 0) { |
| 696 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 697 | return GL_FALSE; |
| 698 | } |
| 699 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 700 | if (!texName || !residences) |
| 701 | return GL_FALSE; |
| 702 | |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 703 | for (i = 0; i < n; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 704 | struct gl_texture_object *t; |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 705 | if (texName[i] == 0) { |
| 706 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 707 | return GL_FALSE; |
| 708 | } |
| 709 | t = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 710 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 711 | if (t) { |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 712 | if (ctx->Driver.IsTextureResident) { |
| 713 | residences[i] = ctx->Driver.IsTextureResident(ctx, t); |
| 714 | if (!residences[i]) |
| 715 | allResident = GL_FALSE; |
| 716 | } |
| 717 | else { |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 718 | residences[i] = GL_TRUE; |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 719 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 720 | } |
| 721 | else { |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 722 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 723 | return GL_FALSE; |
| 724 | } |
| 725 | } |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 726 | return allResident; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | |
| 731 | /* |
| 732 | * Execute glIsTexture |
| 733 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 734 | GLboolean |
| 735 | _mesa_IsTexture( GLuint texture ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 736 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 737 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 738 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures", |
| 739 | GL_FALSE); |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 740 | if (texture > 0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 741 | return GL_TRUE; |
| 742 | } |
| 743 | else { |
| 744 | return GL_FALSE; |
| 745 | } |
| 746 | } |
| 747 | |