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 intel_free_texture_image_buffer(struct gl_context
* ctx
,
49 struct gl_texture_image
*texImage
)
51 struct intel_context
*intel
= intel_context(ctx
);
52 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
54 DBG("%s\n", __FUNCTION__
);
57 intel_miptree_release(intel
, &intelImage
->mt
);
61 _mesa_free_texmemory(texImage
->Data
);
62 texImage
->Data
= NULL
;
65 if (intelImage
->depth_rb
) {
66 _mesa_reference_renderbuffer(&intelImage
->depth_rb
, NULL
);
69 if (intelImage
->stencil_rb
) {
70 _mesa_reference_renderbuffer(&intelImage
->stencil_rb
, NULL
);
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.
81 intelGenerateMipmap(struct gl_context
*ctx
, GLenum target
,
82 struct gl_texture_object
*texObj
)
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
];
90 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
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
);
96 if (!_mesa_is_format_compressed(first_image
->TexFormat
)) {
97 GLuint nr_faces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
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
]);
105 /* Unreference the miptree to signal that the new Data is a
106 * bare pointer from mesa.
108 intel_miptree_release(intel
, &intelImage
->mt
);
114 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
120 intelInitTextureFuncs(struct dd_function_table
*functions
)
122 functions
->GenerateMipmap
= intelGenerateMipmap
;
124 functions
->NewTextureObject
= intelNewTextureObject
;
125 functions
->NewTextureImage
= intelNewTextureImage
;
126 functions
->DeleteTexture
= intelDeleteTextureObject
;
127 functions
->FreeTextureImageBuffer
= intel_free_texture_image_buffer
;