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 * Map texture memory/buffer into user space.
76 * Note: the region of interest parameters are ignored here.
77 * \param mapOut returns start of mapping of region of interest
78 * \param rowStrideOut returns row stride in bytes
81 intel_map_texture_image(struct gl_context
*ctx
,
82 struct gl_texture_image
*tex_image
,
84 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
89 struct intel_context
*intel
= intel_context(ctx
);
90 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
91 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
94 if (intel_image
->stencil_rb
) {
96 * The texture has packed depth/stencil format, but uses separate
97 * stencil. The texture's embedded stencil buffer contains the real
98 * stencil data, so copy that into the miptree.
100 intel_tex_image_s8z24_gather(intel
, intel_image
);
103 /* For compressed formats, the stride is the number of bytes per
104 * row of blocks. intel_miptree_get_image_offset() already does
107 _mesa_get_format_block_size(mt
->format
, &bw
, &bh
);
112 void *base
= intel_region_map(intel
, mt
->region
);
113 unsigned int image_x
, image_y
;
115 intel_miptree_get_image_offset(mt
, tex_image
->Level
, tex_image
->Face
,
116 slice
, &image_x
, &image_y
);
120 *stride
= mt
->region
->pitch
* mt
->cpp
;
121 *map
= base
+ y
* *stride
+ x
* mt
->cpp
;
123 /* texture data is in malloc'd memory */
124 GLuint width
= tex_image
->Width
;
125 GLuint height
= ALIGN(tex_image
->Height
, bh
) / bh
;
126 GLuint texelSize
= _mesa_get_format_bytes(tex_image
->TexFormat
);
130 *stride
= _mesa_format_row_stride(tex_image
->TexFormat
, width
);
131 *map
= tex_image
->Data
+ (slice
* height
+ y
) * *stride
+ x
* texelSize
;
138 intel_unmap_texture_image(struct gl_context
*ctx
,
139 struct gl_texture_image
*tex_image
, GLuint slice
)
141 struct intel_context
*intel
= intel_context(ctx
);
142 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
144 intel_region_unmap(intel
, intel_image
->mt
->region
);
146 if (intel_image
->stencil_rb
) {
148 * The texture has packed depth/stencil format, but uses separate
149 * stencil. The texture's embedded stencil buffer contains the real
150 * stencil data, so copy that into the miptree.
152 intel_tex_image_s8z24_scatter(intel
, intel_image
);
157 * Called via ctx->Driver.GenerateMipmap()
158 * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
159 * if we'll be using software mipmap generation. In that case, we need to
160 * map/unmap the base level texture image.
163 intelGenerateMipmap(struct gl_context
*ctx
, GLenum target
,
164 struct gl_texture_object
*texObj
)
166 if (_mesa_meta_check_generate_mipmap_fallback(ctx
, target
, texObj
)) {
167 /* sw path: need to map texture images */
168 struct intel_context
*intel
= intel_context(ctx
);
169 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
170 struct gl_texture_image
*first_image
= texObj
->Image
[0][texObj
->BaseLevel
];
172 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
174 intel_tex_map_level_images(intel
, intelObj
, texObj
->BaseLevel
);
175 _mesa_generate_mipmap(ctx
, target
, texObj
);
176 intel_tex_unmap_level_images(intel
, intelObj
, texObj
->BaseLevel
);
178 if (!_mesa_is_format_compressed(first_image
->TexFormat
)) {
179 GLuint nr_faces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
181 for (face
= 0; face
< nr_faces
; face
++) {
182 for (i
= texObj
->BaseLevel
+ 1; i
< texObj
->MaxLevel
; i
++) {
183 struct intel_texture_image
*intelImage
=
184 intel_texture_image(texObj
->Image
[face
][i
]);
187 /* Unreference the miptree to signal that the new Data is a
188 * bare pointer from mesa.
190 intel_miptree_release(intel
, &intelImage
->mt
);
196 _mesa_meta_GenerateMipmap(ctx
, target
, texObj
);
202 intelInitTextureFuncs(struct dd_function_table
*functions
)
204 functions
->GenerateMipmap
= intelGenerateMipmap
;
206 functions
->NewTextureObject
= intelNewTextureObject
;
207 functions
->NewTextureImage
= intelNewTextureImage
;
208 functions
->DeleteTexture
= intelDeleteTextureObject
;
209 functions
->FreeTextureImageBuffer
= intel_free_texture_image_buffer
;
210 functions
->MapTextureImage
= intel_map_texture_image
;
211 functions
->UnmapTextureImage
= intel_unmap_texture_image
;