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
);
29 DBG("%s\n", __FUNCTION__
);
30 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
36 intelDeleteTextureObject(struct gl_context
*ctx
,
37 struct gl_texture_object
*texObj
)
39 struct intel_context
*intel
= intel_context(ctx
);
40 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
43 intel_miptree_release(intel
, &intelObj
->mt
);
45 _mesa_delete_texture_object(ctx
, texObj
);
50 intel_free_texture_image_buffer(struct gl_context
* ctx
,
51 struct gl_texture_image
*texImage
)
53 struct intel_context
*intel
= intel_context(ctx
);
54 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
56 DBG("%s\n", __FUNCTION__
);
59 intel_miptree_release(intel
, &intelImage
->mt
);
63 _mesa_free_texmemory(texImage
->Data
);
64 texImage
->Data
= NULL
;
67 if (intelImage
->depth_rb
) {
68 _mesa_reference_renderbuffer(&intelImage
->depth_rb
, NULL
);
71 if (intelImage
->stencil_rb
) {
72 _mesa_reference_renderbuffer(&intelImage
->stencil_rb
, NULL
);
77 * Map texture memory/buffer into user space.
78 * Note: the region of interest parameters are ignored here.
79 * \param mapOut returns start of mapping of region of interest
80 * \param rowStrideOut returns row stride in bytes
83 intel_map_texture_image(struct gl_context
*ctx
,
84 struct gl_texture_image
*tex_image
,
86 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
91 struct intel_context
*intel
= intel_context(ctx
);
92 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
93 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
96 if (intel_image
->stencil_rb
) {
98 * The texture has packed depth/stencil format, but uses separate
99 * stencil. The texture's embedded stencil buffer contains the real
100 * stencil data, so copy that into the miptree.
102 intel_tex_image_s8z24_gather(intel
, intel_image
);
105 /* For compressed formats, the stride is the number of bytes per
106 * row of blocks. intel_miptree_get_image_offset() already does
109 _mesa_get_format_block_size(mt
->format
, &bw
, &bh
);
114 void *base
= intel_region_map(intel
, mt
->region
);
115 unsigned int image_x
, image_y
;
117 intel_miptree_get_image_offset(mt
, tex_image
->Level
, tex_image
->Face
,
118 slice
, &image_x
, &image_y
);
122 *stride
= mt
->region
->pitch
* mt
->cpp
;
123 *map
= base
+ y
* *stride
+ x
* mt
->cpp
;
125 /* texture data is in malloc'd memory */
126 GLuint width
= tex_image
->Width
;
127 GLuint height
= ALIGN(tex_image
->Height
, bh
) / bh
;
128 GLuint texelSize
= _mesa_get_format_bytes(tex_image
->TexFormat
);
132 *stride
= _mesa_format_row_stride(tex_image
->TexFormat
, width
);
133 *map
= tex_image
->Data
+ (slice
* height
+ y
) * *stride
+ x
* texelSize
;
140 intel_unmap_texture_image(struct gl_context
*ctx
,
141 struct gl_texture_image
*tex_image
, GLuint slice
)
143 struct intel_context
*intel
= intel_context(ctx
);
144 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
146 intel_region_unmap(intel
, intel_image
->mt
->region
);
148 if (intel_image
->stencil_rb
) {
150 * The texture has packed depth/stencil format, but uses separate
151 * stencil. The texture's embedded stencil buffer contains the real
152 * stencil data, so copy that into the miptree.
154 intel_tex_image_s8z24_scatter(intel
, intel_image
);
159 * Called via ctx->Driver.GenerateMipmap()
160 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
161 * if we'll be using software mipmap generation. In that case, we need to
162 * map/unmap the base level texture image.
165 intelGenerateMipmap(struct gl_context
*ctx
, GLenum target
,
166 struct gl_texture_object
*texObj
)
168 if (_mesa_meta_check_generate_mipmap_fallback(ctx
, target
, texObj
)) {
169 /* sw path: need to map texture images */
170 struct intel_context
*intel
= intel_context(ctx
);
171 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
172 struct gl_texture_image
*first_image
= texObj
->Image
[0][texObj
->BaseLevel
];
174 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
176 intel_tex_map_level_images(intel
, intelObj
, texObj
->BaseLevel
);
177 _mesa_generate_mipmap(ctx
, target
, texObj
);
178 intel_tex_unmap_level_images(intel
, intelObj
, texObj
->BaseLevel
);
180 if (!_mesa_is_format_compressed(first_image
->TexFormat
)) {
181 GLuint nr_faces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
183 for (face
= 0; face
< nr_faces
; face
++) {
184 for (i
= texObj
->BaseLevel
+ 1; i
< texObj
->MaxLevel
; i
++) {
185 struct intel_texture_image
*intelImage
=
186 intel_texture_image(texObj
->Image
[face
][i
]);
189 /* Unreference the miptree to signal that the new Data is a
190 * bare pointer from mesa.
192 intel_miptree_release(intel
, &intelImage
->mt
);
198 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
204 intelInitTextureFuncs(struct dd_function_table
*functions
)
206 functions
->GenerateMipmap
= intelGenerateMipmap
;
208 functions
->NewTextureObject
= intelNewTextureObject
;
209 functions
->NewTextureImage
= intelNewTextureImage
;
210 functions
->DeleteTexture
= intelDeleteTextureObject
;
211 functions
->FreeTextureImageBuffer
= intel_free_texture_image_buffer
;
212 functions
->MapTextureImage
= intel_map_texture_image
;
213 functions
->UnmapTextureImage
= intel_unmap_texture_image
;