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"
10 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
12 static struct gl_texture_image *
13 intelNewTextureImage(struct gl_context * ctx)
15 DBG("%s\n", __FUNCTION__);
17 return (struct gl_texture_image *) CALLOC_STRUCT(intel_texture_image);
21 static struct gl_texture_object *
22 intelNewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
24 struct intel_texture_object *obj = CALLOC_STRUCT(intel_texture_object);
26 DBG("%s\n", __FUNCTION__);
27 _mesa_initialize_texture_object(&obj->base, name, target);
33 intelDeleteTextureObject(struct gl_context *ctx,
34 struct gl_texture_object *texObj)
36 struct intel_context *intel = intel_context(ctx);
37 struct intel_texture_object *intelObj = intel_texture_object(texObj);
40 intel_miptree_release(intel, &intelObj->mt);
42 _mesa_delete_texture_object(ctx, texObj);
47 intelFreeTextureImageData(struct gl_context * ctx, struct gl_texture_image *texImage)
49 struct intel_context *intel = intel_context(ctx);
50 struct intel_texture_image *intelImage = intel_texture_image(texImage);
52 DBG("%s\n", __FUNCTION__);
55 intel_miptree_release(intel, &intelImage->mt);
59 _mesa_free_texmemory(texImage->Data);
60 texImage->Data = NULL;
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.
71 intelGenerateMipmap(struct gl_context *ctx, GLenum target,
72 struct gl_texture_object *texObj)
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);
79 fallback_debug("%s - fallback to swrast\n", __FUNCTION__);
81 intel_tex_map_level_images(intel, intelObj, texObj->BaseLevel);
82 _mesa_generate_mipmap(ctx, target, texObj);
83 intel_tex_unmap_level_images(intel, intelObj, texObj->BaseLevel);
86 GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
88 /* Update the level information in our private data in the new images,
89 * since it didn't get set as part of a normal TexImage path.
91 for (face = 0; face < nr_faces; face++) {
92 for (i = texObj->BaseLevel + 1; i < texObj->MaxLevel; i++) {
93 struct intel_texture_image *intelImage =
94 intel_texture_image(texObj->Image[face][i]);
97 intelImage->level = i;
98 intelImage->face = face;
99 /* Unreference the miptree to signal that the new Data is a
100 * bare pointer from mesa.
102 intel_miptree_release(intel, &intelImage->mt);
108 _mesa_meta_GenerateMipmap(ctx, target, texObj);
114 intelInitTextureFuncs(struct dd_function_table *functions)
116 functions->ChooseTextureFormat = intelChooseTextureFormat;
117 functions->GenerateMipmap = intelGenerateMipmap;
119 functions->NewTextureObject = intelNewTextureObject;
120 functions->NewTextureImage = intelNewTextureImage;
121 functions->DeleteTexture = intelDeleteTextureObject;
122 functions->FreeTexImageData = intelFreeTextureImageData;