Rename some driver FreeTextureImageData functions to FreeTextureImageBuffer.
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex.c
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
13 static struct gl_texture_image *
14 intelNewTextureImage(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
22 static struct gl_texture_object *
23 intelNewTextureObject(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
33 static void
34 intelDeleteTextureObject(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
47 static void
48 intel_free_texture_image_buffer(struct gl_context * ctx,
49 struct gl_texture_image *texImage)
50 {
51 struct intel_context *intel = intel_context(ctx);
52 struct intel_texture_image *intelImage = intel_texture_image(texImage);
53
54 DBG("%s\n", __FUNCTION__);
55
56 if (intelImage->mt) {
57 intel_miptree_release(intel, &intelImage->mt);
58 }
59
60 if (texImage->Data) {
61 _mesa_free_texmemory(texImage->Data);
62 texImage->Data = NULL;
63 }
64
65 if (intelImage->depth_rb) {
66 _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
67 }
68
69 if (intelImage->stencil_rb) {
70 _mesa_reference_renderbuffer(&intelImage->stencil_rb, NULL);
71 }
72 }
73
74 /**
75 * Called via ctx->Driver.GenerateMipmap()
76 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
77 * if we'll be using software mipmap generation. In that case, we need to
78 * map/unmap the base level texture image.
79 */
80 static void
81 intelGenerateMipmap(struct gl_context *ctx, GLenum target,
82 struct gl_texture_object *texObj)
83 {
84 if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) {
85 /* sw path: need to map texture images */
86 struct intel_context *intel = intel_context(ctx);
87 struct intel_texture_object *intelObj = intel_texture_object(texObj);
88 struct gl_texture_image *first_image = texObj->Image[0][texObj->BaseLevel];
89
90 fallback_debug("%s - fallback to swrast\n", __FUNCTION__);
91
92 intel_tex_map_level_images(intel, intelObj, texObj->BaseLevel);
93 _mesa_generate_mipmap(ctx, target, texObj);
94 intel_tex_unmap_level_images(intel, intelObj, texObj->BaseLevel);
95
96 if (!_mesa_is_format_compressed(first_image->TexFormat)) {
97 GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
98 GLuint face, i;
99 for (face = 0; face < nr_faces; face++) {
100 for (i = texObj->BaseLevel + 1; i < texObj->MaxLevel; i++) {
101 struct intel_texture_image *intelImage =
102 intel_texture_image(texObj->Image[face][i]);
103 if (!intelImage)
104 break;
105 /* Unreference the miptree to signal that the new Data is a
106 * bare pointer from mesa.
107 */
108 intel_miptree_release(intel, &intelImage->mt);
109 }
110 }
111 }
112 }
113 else {
114 _mesa_meta_GenerateMipmap(ctx, target, texObj);
115 }
116 }
117
118
119 void
120 intelInitTextureFuncs(struct dd_function_table *functions)
121 {
122 functions->GenerateMipmap = intelGenerateMipmap;
123
124 functions->NewTextureObject = intelNewTextureObject;
125 functions->NewTextureImage = intelNewTextureImage;
126 functions->DeleteTexture = intelDeleteTextureObject;
127 functions->FreeTextureImageBuffer = intel_free_texture_image_buffer;
128 }