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