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 intelDeleteTextureImage(struct gl_context
* ctx
, struct gl_texture_image
*img
)
24 /* nothing special (yet) for intel_texture_image */
25 _mesa_delete_texture_image(ctx
, img
);
29 static struct gl_texture_object
*
30 intelNewTextureObject(struct gl_context
* ctx
, GLuint name
, GLenum target
)
32 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
36 DBG("%s\n", __FUNCTION__
);
37 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
43 intelDeleteTextureObject(struct gl_context
*ctx
,
44 struct gl_texture_object
*texObj
)
46 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
48 intel_miptree_release(&intelObj
->mt
);
49 _mesa_delete_texture_object(ctx
, texObj
);
54 intel_free_texture_image_buffer(struct gl_context
* ctx
,
55 struct gl_texture_image
*texImage
)
57 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
59 DBG("%s\n", __FUNCTION__
);
61 intel_miptree_release(&intelImage
->mt
);
64 _mesa_free_texmemory(texImage
->Data
);
65 texImage
->Data
= NULL
;
68 _mesa_reference_renderbuffer(&intelImage
->depth_rb
, NULL
);
69 _mesa_reference_renderbuffer(&intelImage
->stencil_rb
, NULL
);
73 * Map texture memory/buffer into user space.
74 * Note: the region of interest parameters are ignored here.
75 * \param mapOut returns start of mapping of region of interest
76 * \param rowStrideOut returns row stride in bytes
79 intel_map_texture_image(struct gl_context
*ctx
,
80 struct gl_texture_image
*tex_image
,
82 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
87 struct intel_context
*intel
= intel_context(ctx
);
88 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
89 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
92 if (intel_image
->stencil_rb
) {
94 * The texture has packed depth/stencil format, but uses separate
95 * stencil. The texture's embedded stencil buffer contains the real
96 * stencil data, so copy that into the miptree.
98 intel_tex_image_s8z24_gather(intel
, intel_image
);
101 /* For compressed formats, the stride is the number of bytes per
102 * row of blocks. intel_miptree_get_image_offset() already does
105 _mesa_get_format_block_size(tex_image
->TexFormat
, &bw
, &bh
);
110 void *base
= intel_region_map(intel
, mt
->region
);
111 unsigned int image_x
, image_y
;
113 intel_miptree_get_image_offset(mt
, tex_image
->Level
, tex_image
->Face
,
114 slice
, &image_x
, &image_y
);
118 *stride
= mt
->region
->pitch
* mt
->cpp
;
119 *map
= base
+ y
* *stride
+ x
* mt
->cpp
;
121 /* texture data is in malloc'd memory */
122 GLuint width
= tex_image
->Width
;
123 GLuint height
= ALIGN(tex_image
->Height
, bh
) / bh
;
124 GLuint texelSize
= _mesa_get_format_bytes(tex_image
->TexFormat
);
128 *stride
= _mesa_format_row_stride(tex_image
->TexFormat
, width
);
129 *map
= tex_image
->Data
+ (slice
* height
+ y
) * *stride
+ x
* texelSize
;
136 intel_unmap_texture_image(struct gl_context
*ctx
,
137 struct gl_texture_image
*tex_image
, GLuint slice
)
139 struct intel_context
*intel
= intel_context(ctx
);
140 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
143 intel_region_unmap(intel
, intel_image
->mt
->region
);
145 if (intel_image
->stencil_rb
) {
147 * The texture has packed depth/stencil format, but uses separate
148 * stencil. The texture's embedded stencil buffer contains the real
149 * stencil data, so copy that into the miptree.
151 intel_tex_image_s8z24_scatter(intel
, intel_image
);
156 * Called via ctx->Driver.GenerateMipmap()
157 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
158 * if we'll be using software mipmap generation. In that case, we need to
159 * map/unmap the base level texture image.
162 intelGenerateMipmap(struct gl_context
*ctx
, GLenum target
,
163 struct gl_texture_object
*texObj
)
165 if (_mesa_meta_check_generate_mipmap_fallback(ctx
, target
, texObj
)) {
166 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
168 _mesa_generate_mipmap(ctx
, target
, texObj
);
171 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
177 intelInitTextureFuncs(struct dd_function_table
*functions
)
179 functions
->GenerateMipmap
= intelGenerateMipmap
;
181 functions
->NewTextureObject
= intelNewTextureObject
;
182 functions
->NewTextureImage
= intelNewTextureImage
;
183 functions
->DeleteTextureImage
= intelDeleteTextureImage
;
184 functions
->DeleteTexture
= intelDeleteTextureObject
;
185 functions
->FreeTextureImageBuffer
= intel_free_texture_image_buffer
;
186 functions
->MapTextureImage
= intel_map_texture_image
;
187 functions
->UnmapTextureImage
= intel_unmap_texture_image
;