[SDK] Provide .const macro for gas
[reactos.git] / dll / opengl / mesa / main / texstate.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file texstate.c
27 *
28 * Texture state handling.
29 */
30
31 #include <precomp.h>
32
33 /**
34 * Default texture combine environment state. This is used to initialize
35 * a context's texture units and as the basis for converting "classic"
36 * texture environmnets to ARB_texture_env_combine style values.
37 */
38 static const struct gl_tex_env_combine_state default_combine_state = {
39 GL_MODULATE, GL_MODULATE,
40 { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
41 { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT, GL_CONSTANT },
42 { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_SRC_ALPHA },
43 { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA },
44 0, 0,
45 2, 2
46 };
47
48
49
50 /**
51 * Used by glXCopyContext to copy texture state from one context to another.
52 */
53 void
54 _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
55 {
56 GLuint tex;
57
58 ASSERT(src);
59 ASSERT(dst);
60
61 dst->Texture._GenFlags = src->Texture._GenFlags;
62 dst->Texture._TexGenEnabled = src->Texture._TexGenEnabled;
63 dst->Texture._TexMatEnabled = src->Texture._TexMatEnabled;
64
65 dst->Texture.Unit.Enabled = src->Texture.Unit.Enabled;
66 dst->Texture.Unit.EnvMode = src->Texture.Unit.EnvMode;
67 COPY_4V(dst->Texture.Unit.EnvColor, src->Texture.Unit.EnvColor);
68 dst->Texture.Unit.TexGenEnabled = src->Texture.Unit.TexGenEnabled;
69 dst->Texture.Unit.GenS = src->Texture.Unit.GenS;
70 dst->Texture.Unit.GenT = src->Texture.Unit.GenT;
71 dst->Texture.Unit.GenR = src->Texture.Unit.GenR;
72 dst->Texture.Unit.GenQ = src->Texture.Unit.GenQ;
73 dst->Texture.Unit.LodBias = src->Texture.Unit.LodBias;
74
75 /* GL_EXT_texture_env_combine */
76 dst->Texture.Unit.Combine = src->Texture.Unit.Combine;
77
78 /*
79 * XXX strictly speaking, we should compare texture names/ids and
80 * bind textures in the dest context according to id. For now, only
81 * copy bindings if the contexts share the same pool of textures to
82 * avoid refcounting bugs.
83 */
84 if (dst->Shared == src->Shared) {
85 /* copy texture object bindings, not contents of texture objects */
86 _mesa_lock_context_textures(dst);
87
88 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
89 _mesa_reference_texobj(&dst->Texture.Unit.CurrentTex[tex],
90 src->Texture.Unit.CurrentTex[tex]);
91 }
92 _mesa_unlock_context_textures(dst);
93 }
94 }
95
96
97 /*
98 * For debugging
99 */
100 void
101 _mesa_print_texunit_state( struct gl_context *ctx )
102 {
103 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
104 printf("Texture Unit\n");
105 printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit->EnvMode));
106 printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeRGB));
107 printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeA));
108 printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[0]));
109 printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[1]));
110 printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[2]));
111 printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[0]));
112 printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[1]));
113 printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[2]));
114 printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[0]));
115 printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[1]));
116 printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[2]));
117 printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[0]));
118 printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[1]));
119 printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[2]));
120 printf(" GL_RGB_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftRGB);
121 printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftA);
122 printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit->EnvColor[0], texUnit->EnvColor[1], texUnit->EnvColor[2], texUnit->EnvColor[3]);
123 }
124
125
126
127 /**********************************************************************/
128 /* Texture Environment */
129 /**********************************************************************/
130
131 /**
132 * Convert "classic" texture environment to ARB_texture_env_combine style
133 * environments.
134 *
135 * \param state texture_env_combine state vector to be filled-in.
136 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
137 * \c GL_BLEND, \c GL_DECAL, etc.).
138 * \param texBaseFormat Base format of the texture associated with the
139 * texture unit.
140 */
141 static void
142 calculate_derived_texenv( struct gl_tex_env_combine_state *state,
143 GLenum mode, GLenum texBaseFormat )
144 {
145 GLenum mode_rgb;
146 GLenum mode_a;
147
148 *state = default_combine_state;
149
150 switch (texBaseFormat) {
151 case GL_ALPHA:
152 state->SourceRGB[0] = GL_PREVIOUS;
153 break;
154
155 case GL_LUMINANCE_ALPHA:
156 case GL_INTENSITY:
157 case GL_RGBA:
158 break;
159
160 case GL_LUMINANCE:
161 case GL_RED:
162 case GL_RG:
163 case GL_RGB:
164 case GL_YCBCR_MESA:
165 state->SourceA[0] = GL_PREVIOUS;
166 break;
167
168 default:
169 _mesa_problem(NULL,
170 "Invalid texBaseFormat 0x%x in calculate_derived_texenv",
171 texBaseFormat);
172 return;
173 }
174
175 if (mode == GL_REPLACE_EXT)
176 mode = GL_REPLACE;
177
178 switch (mode) {
179 case GL_REPLACE:
180 case GL_MODULATE:
181 mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : mode;
182 mode_a = mode;
183 break;
184
185 case GL_DECAL:
186 mode_rgb = GL_INTERPOLATE;
187 mode_a = GL_REPLACE;
188
189 state->SourceA[0] = GL_PREVIOUS;
190
191 /* Having alpha / luminance / intensity textures replace using the
192 * incoming fragment color matches the definition in NV_texture_shader.
193 * The 1.5 spec simply marks these as "undefined".
194 */
195 switch (texBaseFormat) {
196 case GL_ALPHA:
197 case GL_LUMINANCE:
198 case GL_LUMINANCE_ALPHA:
199 case GL_INTENSITY:
200 state->SourceRGB[0] = GL_PREVIOUS;
201 break;
202 case GL_RED:
203 case GL_RG:
204 case GL_RGB:
205 case GL_YCBCR_MESA:
206 mode_rgb = GL_REPLACE;
207 break;
208 case GL_RGBA:
209 state->SourceRGB[2] = GL_TEXTURE;
210 break;
211 }
212 break;
213
214 case GL_BLEND:
215 mode_rgb = GL_INTERPOLATE;
216 mode_a = GL_MODULATE;
217
218 switch (texBaseFormat) {
219 case GL_ALPHA:
220 mode_rgb = GL_REPLACE;
221 break;
222 case GL_INTENSITY:
223 mode_a = GL_INTERPOLATE;
224 state->SourceA[0] = GL_CONSTANT;
225 state->OperandA[2] = GL_SRC_ALPHA;
226 /* FALLTHROUGH */
227 case GL_LUMINANCE:
228 case GL_RED:
229 case GL_RG:
230 case GL_RGB:
231 case GL_LUMINANCE_ALPHA:
232 case GL_RGBA:
233 case GL_YCBCR_MESA:
234 state->SourceRGB[2] = GL_TEXTURE;
235 state->SourceA[2] = GL_TEXTURE;
236 state->SourceRGB[0] = GL_CONSTANT;
237 state->OperandRGB[2] = GL_SRC_COLOR;
238 break;
239 }
240 break;
241
242 case GL_ADD:
243 mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : GL_ADD;
244 mode_a = (texBaseFormat == GL_INTENSITY) ? GL_ADD : GL_MODULATE;
245 break;
246
247 default:
248 _mesa_problem(NULL,
249 "Invalid texture env mode 0x%x in calculate_derived_texenv",
250 mode);
251 return;
252 }
253
254 state->ModeRGB = (state->SourceRGB[0] != GL_PREVIOUS)
255 ? mode_rgb : GL_REPLACE;
256 state->ModeA = (state->SourceA[0] != GL_PREVIOUS)
257 ? mode_a : GL_REPLACE;
258 }
259
260 /**********************************************************************/
261 /***** State management *****/
262 /**********************************************************************/
263
264
265 /**
266 * \note This routine refers to derived texture attribute values to
267 * compute the ENABLE_TEXMAT flags, but is only called on
268 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
269 * flags are updated by _mesa_update_textures(), below.
270 *
271 * \param ctx GL context.
272 */
273 static void
274 update_texture_matrices( struct gl_context *ctx )
275 {
276 ctx->Texture._TexMatEnabled = 0x0;
277
278 if (_math_matrix_is_dirty(ctx->TextureMatrixStack.Top)) {
279 _math_matrix_analyse( ctx->TextureMatrixStack.Top );
280
281 if (ctx->Texture.Unit._ReallyEnabled &&
282 ctx->TextureMatrixStack.Top->type != MATRIX_IDENTITY)
283 ctx->Texture._TexMatEnabled = GL_TRUE;
284 }
285 }
286
287
288 /**
289 * Examine texture unit's combine/env state to update derived state.
290 */
291 static void
292 update_tex_combine(struct gl_context *ctx, struct gl_texture_unit *texUnit)
293 {
294 struct gl_tex_env_combine_state *combine;
295
296 /* Set the texUnit->_CurrentCombine field to point to the user's combiner
297 * state, or the combiner state which is derived from traditional texenv
298 * mode.
299 */
300 if (texUnit->EnvMode == GL_COMBINE ||
301 texUnit->EnvMode == GL_COMBINE4_NV) {
302 texUnit->_CurrentCombine = & texUnit->Combine;
303 }
304 else {
305 const struct gl_texture_object *texObj = texUnit->_Current;
306 GLenum format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat;
307
308 calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
309 texUnit->_CurrentCombine = & texUnit->_EnvMode;
310 }
311
312 combine = texUnit->_CurrentCombine;
313
314 /* Determine number of source RGB terms in the combiner function */
315 switch (combine->ModeRGB) {
316 case GL_REPLACE:
317 combine->_NumArgsRGB = 1;
318 break;
319 case GL_ADD:
320 case GL_ADD_SIGNED:
321 if (texUnit->EnvMode == GL_COMBINE4_NV)
322 combine->_NumArgsRGB = 4;
323 else
324 combine->_NumArgsRGB = 2;
325 break;
326 case GL_MODULATE:
327 case GL_SUBTRACT:
328 case GL_DOT3_RGB:
329 case GL_DOT3_RGBA:
330 case GL_DOT3_RGB_EXT:
331 case GL_DOT3_RGBA_EXT:
332 combine->_NumArgsRGB = 2;
333 break;
334 case GL_INTERPOLATE:
335 case GL_MODULATE_ADD_ATI:
336 case GL_MODULATE_SIGNED_ADD_ATI:
337 case GL_MODULATE_SUBTRACT_ATI:
338 combine->_NumArgsRGB = 3;
339 break;
340 default:
341 combine->_NumArgsRGB = 0;
342 _mesa_problem(ctx, "invalid RGB combine mode in update_texture_state");
343 return;
344 }
345
346 /* Determine number of source Alpha terms in the combiner function */
347 switch (combine->ModeA) {
348 case GL_REPLACE:
349 combine->_NumArgsA = 1;
350 break;
351 case GL_ADD:
352 case GL_ADD_SIGNED:
353 if (texUnit->EnvMode == GL_COMBINE4_NV)
354 combine->_NumArgsA = 4;
355 else
356 combine->_NumArgsA = 2;
357 break;
358 case GL_MODULATE:
359 case GL_SUBTRACT:
360 combine->_NumArgsA = 2;
361 break;
362 case GL_INTERPOLATE:
363 case GL_MODULATE_ADD_ATI:
364 case GL_MODULATE_SIGNED_ADD_ATI:
365 case GL_MODULATE_SUBTRACT_ATI:
366 combine->_NumArgsA = 3;
367 break;
368 default:
369 combine->_NumArgsA = 0;
370 _mesa_problem(ctx, "invalid Alpha combine mode in update_texture_state");
371 break;
372 }
373 }
374
375
376 /**
377 * \note This routine refers to derived texture matrix values to
378 * compute the ENABLE_TEXMAT flags, but is only called on
379 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
380 * flags are updated by _mesa_update_texture_matrices, above.
381 *
382 * \param ctx GL context.
383 */
384 static void
385 update_texture_state( struct gl_context *ctx )
386 {
387 /* TODO: only set this if there are actual changes */
388 ctx->NewState |= _NEW_TEXTURE;
389
390 ctx->Texture._Enabled = GL_FALSE;
391 ctx->Texture._GenFlags = 0x0;
392 ctx->Texture._TexMatEnabled = GL_FALSE;
393 ctx->Texture._TexGenEnabled = GL_FALSE;
394
395 /*
396 * Update texture unit state.
397 */
398 {
399 struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
400 GLbitfield enabledTargets = texUnit->Enabled;
401
402 texUnit->_ReallyEnabled = 0x0;
403
404 if (enabledTargets) {
405 GLuint texIndex;
406 /* Look for the highest priority texture target that's enabled (or used
407 * by the vert/frag shaders) and "complete". That's the one we'll use
408 * for texturing. If we're using vert/frag program we're guaranteed
409 * that bitcount(enabledBits) <= 1.
410 * Note that the TEXTURE_x_INDEX values are in high to low priority.
411 */
412 for (texIndex = 0; texIndex < NUM_TEXTURE_TARGETS; texIndex++) {
413 if (enabledTargets & (1 << texIndex)) {
414 struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
415 if (!texObj->_Complete) {
416 _mesa_test_texobj_completeness(ctx, texObj);
417 }
418 if (texObj->_Complete) {
419 texUnit->_ReallyEnabled = 1 << texIndex;
420 _mesa_reference_texobj(&texUnit->_Current, texObj);
421 break;
422 }
423 }
424 }
425
426 if (texUnit->_ReallyEnabled) {
427 /* if we get here, we know this texture unit is enabled */
428 ctx->Texture._Enabled = GL_TRUE;
429 update_tex_combine(ctx, texUnit);
430 }
431 }
432 }
433
434
435 /* Determine if texture coordinates are actually needed */
436 ctx->Texture._EnabledCoord = ctx->Texture._Enabled;
437
438 /* Setup texgen for those texture coordinate sets that are in use */
439 if(ctx->Texture._EnabledCoord)
440 {
441 struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
442
443 texUnit->_GenFlags = 0x0;
444
445 if (texUnit->TexGenEnabled) {
446 if (texUnit->TexGenEnabled & S_BIT) {
447 texUnit->_GenFlags |= texUnit->GenS._ModeBit;
448 }
449 if (texUnit->TexGenEnabled & T_BIT) {
450 texUnit->_GenFlags |= texUnit->GenT._ModeBit;
451 }
452 if (texUnit->TexGenEnabled & R_BIT) {
453 texUnit->_GenFlags |= texUnit->GenR._ModeBit;
454 }
455 if (texUnit->TexGenEnabled & Q_BIT) {
456 texUnit->_GenFlags |= texUnit->GenQ._ModeBit;
457 }
458
459 ctx->Texture._TexGenEnabled = GL_TRUE;
460 ctx->Texture._GenFlags |= texUnit->_GenFlags;
461 }
462
463 if (ctx->TextureMatrixStack.Top->type != MATRIX_IDENTITY)
464 ctx->Texture._TexMatEnabled = GL_TRUE;
465 }
466 }
467
468
469 /**
470 * Update texture-related derived state.
471 */
472 void
473 _mesa_update_texture( struct gl_context *ctx, GLuint new_state )
474 {
475 if (new_state & _NEW_TEXTURE_MATRIX)
476 update_texture_matrices( ctx );
477
478 if (new_state & _NEW_TEXTURE)
479 update_texture_state( ctx );
480 }
481
482
483 /**********************************************************************/
484 /***** Initialization *****/
485 /**********************************************************************/
486
487 /**
488 * Allocate the proxy textures for the given context.
489 *
490 * \param ctx the context to allocate proxies for.
491 *
492 * \return GL_TRUE on success, or GL_FALSE on failure
493 *
494 * If run out of memory part way through the allocations, clean up and return
495 * GL_FALSE.
496 */
497 static GLboolean
498 alloc_proxy_textures( struct gl_context *ctx )
499 {
500 /* NOTE: these values must be in the same order as the TEXTURE_x_INDEX
501 * values!
502 */
503 static const GLenum targets[] = {
504 GL_TEXTURE_CUBE_MAP_ARB,
505 GL_TEXTURE_2D,
506 GL_TEXTURE_1D,
507 };
508 GLint tgt;
509
510 STATIC_ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
511 assert(targets[TEXTURE_2D_INDEX] == GL_TEXTURE_2D);
512 assert(targets[TEXTURE_CUBE_INDEX] == GL_TEXTURE_CUBE_MAP);
513
514 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
515 if (!(ctx->Texture.ProxyTex[tgt]
516 = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) {
517 /* out of memory, free what we did allocate */
518 while (--tgt >= 0) {
519 ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
520 }
521 return GL_FALSE;
522 }
523 }
524
525 assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */
526 return GL_TRUE;
527 }
528
529
530 /**
531 * Initialize a texture unit.
532 *
533 * \param ctx GL context.
534 * \param unit texture unit number to be initialized.
535 */
536 static void
537 init_texture_unit( struct gl_context *ctx)
538 {
539 struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
540 GLuint tex;
541
542 texUnit->EnvMode = GL_MODULATE;
543 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
544
545 texUnit->Combine = default_combine_state;
546 texUnit->_EnvMode = default_combine_state;
547 texUnit->_CurrentCombine = & texUnit->_EnvMode;
548
549 texUnit->TexGenEnabled = 0x0;
550 texUnit->GenS.Mode = GL_EYE_LINEAR;
551 texUnit->GenT.Mode = GL_EYE_LINEAR;
552 texUnit->GenR.Mode = GL_EYE_LINEAR;
553 texUnit->GenQ.Mode = GL_EYE_LINEAR;
554 texUnit->GenS._ModeBit = TEXGEN_EYE_LINEAR;
555 texUnit->GenT._ModeBit = TEXGEN_EYE_LINEAR;
556 texUnit->GenR._ModeBit = TEXGEN_EYE_LINEAR;
557 texUnit->GenQ._ModeBit = TEXGEN_EYE_LINEAR;
558
559 /* Yes, these plane coefficients are correct! */
560 ASSIGN_4V( texUnit->GenS.ObjectPlane, 1.0, 0.0, 0.0, 0.0 );
561 ASSIGN_4V( texUnit->GenT.ObjectPlane, 0.0, 1.0, 0.0, 0.0 );
562 ASSIGN_4V( texUnit->GenR.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
563 ASSIGN_4V( texUnit->GenQ.ObjectPlane, 0.0, 0.0, 0.0, 0.0 );
564 ASSIGN_4V( texUnit->GenS.EyePlane, 1.0, 0.0, 0.0, 0.0 );
565 ASSIGN_4V( texUnit->GenT.EyePlane, 0.0, 1.0, 0.0, 0.0 );
566 ASSIGN_4V( texUnit->GenR.EyePlane, 0.0, 0.0, 0.0, 0.0 );
567 ASSIGN_4V( texUnit->GenQ.EyePlane, 0.0, 0.0, 0.0, 0.0 );
568
569 /* initialize current texture object ptrs to the shared default objects */
570 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
571 _mesa_reference_texobj(&texUnit->CurrentTex[tex],
572 ctx->Shared->DefaultTex[tex]);
573 }
574 }
575
576
577 /**
578 * Initialize texture state for the given context.
579 */
580 GLboolean
581 _mesa_init_texture(struct gl_context *ctx)
582 {
583 /* Texture group */
584 ctx->Texture._Enabled = GL_FALSE;
585
586 init_texture_unit(ctx);
587
588 /* Allocate proxy textures */
589 if (!alloc_proxy_textures( ctx ))
590 return GL_FALSE;
591
592 return GL_TRUE;
593 }
594
595
596 /**
597 * Free dynamically-allocted texture data attached to the given context.
598 */
599 void
600 _mesa_free_texture_data(struct gl_context *ctx)
601 {
602 GLuint tgt;
603
604 /* unreference current textures */
605 /* The _Current texture could account for another reference */
606 _mesa_reference_texobj(&ctx->Texture.Unit._Current, NULL);
607
608 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
609 _mesa_reference_texobj(&ctx->Texture.Unit.CurrentTex[tgt], NULL);
610 }
611
612 /* Free proxy texture objects */
613 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
614 ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
615
616 #if FEATURE_sampler_objects
617 _mesa_reference_sampler_object(ctx, &ctx->Texture.Unit.Sampler, NULL);
618 #endif
619 }
620
621
622 /**
623 * Update the default texture objects in the given context to reference those
624 * specified in the shared state and release those referencing the old
625 * shared state.
626 */
627 void
628 _mesa_update_default_objects_texture(struct gl_context *ctx)
629 {
630 GLuint tex;
631 struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
632 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
633 _mesa_reference_texobj(&texUnit->CurrentTex[tex],
634 ctx->Shared->DefaultTex[tex]);
635 }
636 }