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"
11 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
13 static struct gl_texture_image
*
14 intelNewTextureImage(struct gl_context
* ctx
)
16 DBG("%s\n", __FUNCTION__
);
18 return (struct gl_texture_image
*) CALLOC_STRUCT(intel_texture_image
);
22 static struct gl_texture_object
*
23 intelNewTextureObject(struct gl_context
* ctx
, GLuint name
, GLenum target
)
25 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
27 DBG("%s\n", __FUNCTION__
);
28 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
34 intelDeleteTextureObject(struct gl_context
*ctx
,
35 struct gl_texture_object
*texObj
)
37 struct intel_context
*intel
= intel_context(ctx
);
38 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
41 intel_miptree_release(intel
, &intelObj
->mt
);
43 _mesa_delete_texture_object(ctx
, texObj
);
48 intelFreeTextureImageData(struct gl_context
* ctx
, struct gl_texture_image
*texImage
)
50 struct intel_context
*intel
= intel_context(ctx
);
51 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
53 DBG("%s\n", __FUNCTION__
);
56 intel_miptree_release(intel
, &intelImage
->mt
);
60 _mesa_free_texmemory(texImage
->Data
);
61 texImage
->Data
= NULL
;
64 if (intelImage
->depth_rb
) {
65 _mesa_reference_renderbuffer(&intelImage
->depth_rb
, NULL
);
68 if (intelImage
->stencil_rb
) {
69 _mesa_reference_renderbuffer(&intelImage
->stencil_rb
, NULL
);
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.
80 intelGenerateMipmap(struct gl_context
*ctx
, GLenum target
,
81 struct gl_texture_object
*texObj
)
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
];
89 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
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
);
95 if (!_mesa_is_format_compressed(first_image
->TexFormat
)) {
96 GLuint nr_faces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
98 /* Update the level information in our private data in the new images,
99 * since it didn't get set as part of a normal TexImage path.
101 for (face
= 0; face
< nr_faces
; face
++) {
102 for (i
= texObj
->BaseLevel
+ 1; i
< texObj
->MaxLevel
; i
++) {
103 struct intel_texture_image
*intelImage
=
104 intel_texture_image(texObj
->Image
[face
][i
]);
107 intelImage
->level
= i
;
108 intelImage
->face
= face
;
109 /* Unreference the miptree to signal that the new Data is a
110 * bare pointer from mesa.
112 intel_miptree_release(intel
, &intelImage
->mt
);
118 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
124 intelInitTextureFuncs(struct dd_function_table
*functions
)
126 functions
->GenerateMipmap
= intelGenerateMipmap
;
128 functions
->NewTextureObject
= intelNewTextureObject
;
129 functions
->NewTextureImage
= intelNewTextureImage
;
130 functions
->DeleteTexture
= intelDeleteTextureObject
;
131 functions
->FreeTexImageData
= intelFreeTextureImageData
;