| Brian Paul | 7351049 | 2000-11-11 20:23:47 +0000 | [diff] [blame^] | 1 | /* $Id: texobj.c,v 1.33 2000/11/11 20:23:47 brianp 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; |
| Brian Paul | 7351049 | 2000-11-11 20:23:47 +0000 | [diff] [blame^] | 74 | obj->WrapR = GL_REPEAT; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 75 | obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR; |
| 76 | obj->MagFilter = GL_LINEAR; |
| 77 | obj->MinLod = -1000.0; |
| 78 | obj->MaxLod = 1000.0; |
| 79 | obj->BaseLevel = 0; |
| 80 | obj->MaxLevel = 1000; |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 81 | _mesa_init_colortable(&obj->Palette); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 82 | |
| 83 | /* insert into linked list */ |
| 84 | if (shared) { |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 85 | _glthread_LOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 86 | obj->Next = shared->TexObjectList; |
| 87 | shared->TexObjectList = obj; |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 88 | _glthread_UNLOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | if (name > 0) { |
| 92 | /* insert into hash table */ |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 93 | _mesa_HashInsert(shared->TexObjects, name, obj); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | return obj; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | * Deallocate a texture object struct and remove it from the given |
| 102 | * shared GL state. |
| 103 | * Input: shared - the shared GL state to which the object belongs |
| 104 | * t - the texture object to delete |
| 105 | */ |
| 106 | void gl_free_texture_object( struct gl_shared_state *shared, |
| 107 | struct gl_texture_object *t ) |
| 108 | { |
| 109 | struct gl_texture_object *tprev, *tcurr; |
| 110 | |
| 111 | assert(t); |
| 112 | |
| 113 | /* Remove t from dirty list so we don't touch free'd memory later. |
| 114 | * Test for shared since Proxy texture aren't in global linked list. |
| 115 | */ |
| 116 | if (shared) |
| 117 | gl_remove_texobj_from_dirty_list( shared, t ); |
| 118 | |
| 119 | /* unlink t from the linked list */ |
| 120 | if (shared) { |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 121 | _glthread_LOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 122 | tprev = NULL; |
| 123 | tcurr = shared->TexObjectList; |
| 124 | while (tcurr) { |
| 125 | if (tcurr==t) { |
| 126 | if (tprev) { |
| 127 | tprev->Next = t->Next; |
| 128 | } |
| 129 | else { |
| 130 | shared->TexObjectList = t->Next; |
| 131 | } |
| 132 | break; |
| 133 | } |
| 134 | tprev = tcurr; |
| 135 | tcurr = tcurr->Next; |
| 136 | } |
| Brian Paul | 9560f05 | 2000-01-31 23:11:39 +0000 | [diff] [blame] | 137 | _glthread_UNLOCK_MUTEX(shared->Mutex); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | if (t->Name) { |
| 141 | /* remove from hash table */ |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 142 | _mesa_HashRemove(shared->TexObjects, t->Name); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| Brian Paul | 4bdcfe5 | 2000-04-17 17:57:04 +0000 | [diff] [blame] | 145 | _mesa_free_colortable_data(&t->Palette); |
| 146 | |
| 147 | /* free texture images */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 148 | { |
| 149 | GLuint i; |
| 150 | for (i=0;i<MAX_TEXTURE_LEVELS;i++) { |
| 151 | if (t->Image[i]) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 152 | _mesa_free_texture_image( t->Image[i] ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | /* free this object */ |
| Brian Paul | bd5cdaf | 1999-10-13 18:42:49 +0000 | [diff] [blame] | 157 | FREE( t ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 158 | } |
| 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 | /* |
| 172 | * Examine a texture object to determine if it is complete or not. |
| 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 | |
| 183 | /* Always need level zero 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) { |
| 210 | /* make sure all six level 0 images are 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; |
| 447 | (void) gl_alloc_texture_object(ctx->Shared, name, dims); |
| 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++) { |
| 470 | struct gl_texture_object *t; |
| 471 | if (texName[i]>0) { |
| 472 | t = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 473 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 474 | if (t) { |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 475 | /* First check if this texture is currently bound. |
| 476 | * If so, unbind it and decrement the reference count. |
| 477 | */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 478 | GLuint u; |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 479 | for (u = 0; u < MAX_TEXTURE_UNITS; u++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 480 | struct gl_texture_unit *unit = &ctx->Texture.Unit[u]; |
| 481 | GLuint d; |
| 482 | for (d = 1 ; d <= 3 ; d++) { |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 483 | if (unit->CurrentD[d] == t) { |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 484 | unit->CurrentD[d] = ctx->Shared->DefaultD[d]; |
| 485 | ctx->Shared->DefaultD[d]->RefCount++; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 486 | t->RefCount--; |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 487 | ASSERT( t->RefCount >= 0 ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 488 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| Brian Paul | 59d6da5 | 2000-02-12 01:59:19 +0000 | [diff] [blame] | 493 | /* Decrement reference count and delete if zero */ |
| 494 | t->RefCount--; |
| 495 | ASSERT( t->RefCount >= 0 ); |
| 496 | if (t->RefCount == 0) { |
| 497 | if (ctx->Driver.DeleteTexture) |
| 498 | (*ctx->Driver.DeleteTexture)( ctx, t ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 499 | gl_free_texture_object(ctx->Shared, t); |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | |
| 507 | |
| 508 | /* |
| 509 | * Execute glBindTexture |
| 510 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 511 | void |
| 512 | _mesa_BindTexture( GLenum target, GLuint texName ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 513 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 514 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 515 | GLuint unit = ctx->Texture.CurrentUnit; |
| 516 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; |
| 517 | struct gl_texture_object *oldTexObj; |
| 518 | struct gl_texture_object *newTexObj; |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 519 | GLuint dim; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 520 | |
| 521 | if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) |
| 522 | fprintf(stderr, "glBindTexture %s %d\n", |
| 523 | gl_lookup_enum_by_nr(target), (GLint) texName); |
| 524 | |
| 525 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBindTexture"); |
| 526 | |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 527 | switch (target) { |
| 528 | case GL_TEXTURE_1D: |
| 529 | dim = 1; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 530 | oldTexObj = texUnit->CurrentD[1]; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 531 | break; |
| 532 | case GL_TEXTURE_2D: |
| 533 | dim = 2; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 534 | oldTexObj = texUnit->CurrentD[2]; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 535 | break; |
| 536 | case GL_TEXTURE_3D: |
| 537 | dim = 3; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 538 | oldTexObj = texUnit->CurrentD[3]; |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 539 | break; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 540 | case GL_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 541 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 542 | dim = 6; |
| 543 | oldTexObj = texUnit->CurrentCubeMap; |
| 544 | break; |
| 545 | } |
| 546 | /* fallthrough */ |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 547 | default: |
| 548 | gl_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" ); |
| 549 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 552 | if (oldTexObj->Name == texName) |
| 553 | return; |
| 554 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 555 | if (texName == 0) { |
| 556 | if (target == GL_TEXTURE_CUBE_MAP_ARB) |
| 557 | newTexObj = ctx->Shared->DefaultCubeMap; |
| 558 | else |
| 559 | newTexObj = ctx->Shared->DefaultD[dim]; |
| 560 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 561 | else { |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 562 | struct _mesa_HashTable *hash = ctx->Shared->TexObjects; |
| Brian Paul | c79fab4 | 2000-01-24 20:53:32 +0000 | [diff] [blame] | 563 | newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 564 | |
| 565 | if (!newTexObj) |
| 566 | newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim); |
| 567 | |
| 568 | if (newTexObj->Dimensions != dim) { |
| 569 | if (newTexObj->Dimensions) { |
| Brian Paul | 420ef64 | 1999-12-01 21:10:08 +0000 | [diff] [blame] | 570 | /* the named texture object's dimensions don't match the target */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 571 | gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" ); |
| 572 | return; |
| 573 | } |
| 574 | newTexObj->Dimensions = dim; |
| 575 | } |
| 576 | } |
| 577 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 578 | newTexObj->RefCount++; |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 579 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 580 | switch (target) { |
| 581 | case GL_TEXTURE_1D: |
| 582 | texUnit->CurrentD[1] = newTexObj; |
| 583 | break; |
| 584 | case GL_TEXTURE_2D: |
| 585 | texUnit->CurrentD[2] = newTexObj; |
| 586 | break; |
| 587 | case GL_TEXTURE_3D: |
| 588 | texUnit->CurrentD[3] = newTexObj; |
| 589 | break; |
| 590 | case GL_TEXTURE_CUBE_MAP_ARB: |
| 591 | texUnit->CurrentCubeMap = newTexObj; |
| 592 | break; |
| 593 | default: |
| 594 | gl_problem(ctx, "bad target in BindTexture"); |
| 595 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 596 | |
| 597 | /* If we've changed the CurrentD[123] texture object then update the |
| 598 | * ctx->Texture.Current pointer to point to the new texture object. |
| 599 | */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 600 | texUnit->_Current = texUnit->CurrentD[texUnit->_CurrentDimension]; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 601 | |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 602 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 603 | |
| 604 | /* Pass BindTexture call to device driver */ |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 605 | if (ctx->Driver.BindTexture) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 606 | (*ctx->Driver.BindTexture)( ctx, target, newTexObj ); |
| Brian Paul | 6e6d4c6 | 1999-10-09 20:17:07 +0000 | [diff] [blame] | 607 | |
| 608 | if (oldTexObj->Name > 0) { |
| 609 | /* never delete default (id=0) texture objects */ |
| 610 | oldTexObj->RefCount--; |
| 611 | if (oldTexObj->RefCount <= 0) { |
| 612 | if (ctx->Driver.DeleteTexture) { |
| 613 | (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); |
| 614 | } |
| 615 | gl_free_texture_object(ctx->Shared, oldTexObj); |
| 616 | } |
| 617 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
| 621 | |
| 622 | /* |
| 623 | * Execute glPrioritizeTextures |
| 624 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 625 | void |
| 626 | _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName, |
| 627 | const GLclampf *priorities ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 628 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 629 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 630 | GLint i; |
| 631 | |
| 632 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPrioritizeTextures"); |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 633 | if (n < 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 634 | gl_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" ); |
| 635 | return; |
| 636 | } |
| 637 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 638 | if (!priorities) |
| 639 | return; |
| 640 | |
| Brian Paul | 6d04725 | 2000-08-02 00:38:25 +0000 | [diff] [blame] | 641 | for (i = 0; i < n; i++) { |
| 642 | if (texName[i] > 0) { |
| 643 | struct gl_texture_object *t = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 644 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 645 | if (t) { |
| 646 | t->Priority = CLAMP( priorities[i], 0.0F, 1.0F ); |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 647 | if (ctx->Driver.PrioritizeTexture) |
| 648 | ctx->Driver.PrioritizeTexture( ctx, t, t->Priority ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | } |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 652 | |
| 653 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | |
| 657 | |
| 658 | /* |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 659 | * Execute glAreTexturesResident |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 660 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 661 | GLboolean |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 662 | _mesa_AreTexturesResident(GLsizei n, const GLuint *texName, |
| 663 | GLboolean *residences) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 664 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 665 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 666 | GLboolean allResident = GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 667 | GLint i; |
| 668 | |
| 669 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 670 | "glAreTexturesResident", GL_FALSE); |
| 671 | if (n < 0) { |
| 672 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 673 | return GL_FALSE; |
| 674 | } |
| 675 | |
| Brian Paul | 507d83e | 2000-08-03 14:03:17 +0000 | [diff] [blame] | 676 | if (!texName || !residences) |
| 677 | return GL_FALSE; |
| 678 | |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 679 | for (i = 0; i < n; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 680 | struct gl_texture_object *t; |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 681 | if (texName[i] == 0) { |
| 682 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 683 | return GL_FALSE; |
| 684 | } |
| 685 | t = (struct gl_texture_object *) |
| Brian Paul | bb79790 | 2000-01-24 16:19:54 +0000 | [diff] [blame] | 686 | _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 687 | if (t) { |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 688 | if (ctx->Driver.IsTextureResident) { |
| 689 | residences[i] = ctx->Driver.IsTextureResident(ctx, t); |
| 690 | if (!residences[i]) |
| 691 | allResident = GL_FALSE; |
| 692 | } |
| 693 | else { |
| Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 694 | residences[i] = GL_TRUE; |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 695 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 696 | } |
| 697 | else { |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 698 | gl_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 699 | return GL_FALSE; |
| 700 | } |
| 701 | } |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 702 | return allResident; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |
| 706 | |
| 707 | /* |
| 708 | * Execute glIsTexture |
| 709 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 710 | GLboolean |
| 711 | _mesa_IsTexture( GLuint texture ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 712 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 713 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 714 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures", |
| 715 | GL_FALSE); |
| Brian Paul | bd0f7f4 | 2000-08-02 20:16:03 +0000 | [diff] [blame] | 716 | if (texture > 0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 717 | return GL_TRUE; |
| 718 | } |
| 719 | else { |
| 720 | return GL_FALSE; |
| 721 | } |
| 722 | } |
| 723 | |