intel_tex.c revision 10e418f3815d690b2526e835bc7eb421b6be7050
1#include "swrast/swrast.h" 2#include "main/texobj.h" 3#include "main/teximage.h" 4#include "main/mipmap.h" 5#include "drivers/common/meta.h" 6#include "intel_context.h" 7#include "intel_mipmap_tree.h" 8#include "intel_tex.h" 9 10#define FILE_DEBUG_FLAG DEBUG_TEXTURE 11 12static struct gl_texture_image * 13intelNewTextureImage(struct gl_context * ctx) 14{ 15 DBG("%s\n", __FUNCTION__); 16 (void) ctx; 17 return (struct gl_texture_image *) CALLOC_STRUCT(intel_texture_image); 18} 19 20 21static struct gl_texture_object * 22intelNewTextureObject(struct gl_context * ctx, GLuint name, GLenum target) 23{ 24 struct intel_texture_object *obj = CALLOC_STRUCT(intel_texture_object); 25 26 DBG("%s\n", __FUNCTION__); 27 _mesa_initialize_texture_object(&obj->base, name, target); 28 29 return &obj->base; 30} 31 32static void 33intelDeleteTextureObject(struct gl_context *ctx, 34 struct gl_texture_object *texObj) 35{ 36 struct intel_context *intel = intel_context(ctx); 37 struct intel_texture_object *intelObj = intel_texture_object(texObj); 38 39 if (intelObj->mt) 40 intel_miptree_release(intel, &intelObj->mt); 41 42 _mesa_delete_texture_object(ctx, texObj); 43} 44 45 46static void 47intelFreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage) 48{ 49 struct intel_context *intel = intel_context(ctx); 50 struct intel_texture_image *intelImage = intel_texture_image(texImage); 51 52 DBG("%s\n", __FUNCTION__); 53 54 if (intelImage->mt) { 55 intel_miptree_release(intel, &intelImage->mt); 56 } 57 58 if (texImage->Data) { 59 _mesa_free_texmemory(texImage->Data); 60 texImage->Data = NULL; 61 } 62} 63 64/** 65 * Called via ctx->Driver.GenerateMipmap() 66 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks 67 * if we'll be using software mipmap generation. In that case, we need to 68 * map/unmap the base level texture image. 69 */ 70static void 71intelGenerateMipmap(struct gl_context *ctx, GLenum target, 72 struct gl_texture_object *texObj) 73{ 74 if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) { 75 /* sw path: need to map texture images */ 76 struct intel_context *intel = intel_context(ctx); 77 struct intel_texture_object *intelObj = intel_texture_object(texObj); 78 struct gl_texture_image *first_image = texObj->Image[0][texObj->BaseLevel]; 79 80 fallback_debug("%s - fallback to swrast\n", __FUNCTION__); 81 82 intel_tex_map_level_images(intel, intelObj, texObj->BaseLevel); 83 _mesa_generate_mipmap(ctx, target, texObj); 84 intel_tex_unmap_level_images(intel, intelObj, texObj->BaseLevel); 85 86 if (!_mesa_is_format_compressed(first_image->TexFormat)) { 87 GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; 88 GLuint face, i; 89 /* Update the level information in our private data in the new images, 90 * since it didn't get set as part of a normal TexImage path. 91 */ 92 for (face = 0; face < nr_faces; face++) { 93 for (i = texObj->BaseLevel + 1; i < texObj->MaxLevel; i++) { 94 struct intel_texture_image *intelImage = 95 intel_texture_image(texObj->Image[face][i]); 96 if (!intelImage) 97 break; 98 intelImage->level = i; 99 intelImage->face = face; 100 /* Unreference the miptree to signal that the new Data is a 101 * bare pointer from mesa. 102 */ 103 intel_miptree_release(intel, &intelImage->mt); 104 } 105 } 106 } 107 } 108 else { 109 _mesa_meta_GenerateMipmap(ctx, target, texObj); 110 } 111} 112 113 114void 115intelInitTextureFuncs(struct dd_function_table *functions) 116{ 117 functions->GenerateMipmap = intelGenerateMipmap; 118 119 functions->NewTextureObject = intelNewTextureObject; 120 functions->NewTextureImage = intelNewTextureImage; 121 functions->DeleteTexture = intelDeleteTextureObject; 122 functions->FreeTexImageData = intelFreeTextureImageData; 123} 124