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