intel: Silence several "warning: unused parameter"
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex.c
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"
9 #include "intel_tex.h"
10
11 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
12
13 static struct gl_texture_image *
14 intelNewTextureImage(struct gl_context * ctx)
15 {
16 DBG("%s\n", __FUNCTION__);
17 (void) ctx;
18 return (struct gl_texture_image *) CALLOC_STRUCT(intel_texture_image);
19 }
20
21
22 static struct gl_texture_object *
23 intelNewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
24 {
25 struct intel_texture_object *obj = CALLOC_STRUCT(intel_texture_object);
26
27 (void) ctx;
28
29 DBG("%s\n", __FUNCTION__);
30 _mesa_initialize_texture_object(&obj->base, name, target);
31
32 return &obj->base;
33 }
34
35 static void
36 intelDeleteTextureObject(struct gl_context *ctx,
37 struct gl_texture_object *texObj)
38 {
39 struct intel_context *intel = intel_context(ctx);
40 struct intel_texture_object *intelObj = intel_texture_object(texObj);
41
42 if (intelObj->mt)
43 intel_miptree_release(intel, &intelObj->mt);
44
45 _mesa_delete_texture_object(ctx, texObj);
46 }
47
48
49 static void
50 intel_free_texture_image_buffer(struct gl_context * ctx,
51 struct gl_texture_image *texImage)
52 {
53 struct intel_context *intel = intel_context(ctx);
54 struct intel_texture_image *intelImage = intel_texture_image(texImage);
55
56 DBG("%s\n", __FUNCTION__);
57
58 if (intelImage->mt) {
59 intel_miptree_release(intel, &intelImage->mt);
60 }
61
62 if (texImage->Data) {
63 _mesa_free_texmemory(texImage->Data);
64 texImage->Data = NULL;
65 }
66
67 if (intelImage->depth_rb) {
68 _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
69 }
70
71 if (intelImage->stencil_rb) {
72 _mesa_reference_renderbuffer(&intelImage->stencil_rb, NULL);
73 }
74 }
75
76 /**
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
81 */
82 static void
83 intel_map_texture_image(struct gl_context *ctx,
84 struct gl_texture_image *tex_image,
85 GLuint slice,
86 GLuint x, GLuint y, GLuint w, GLuint h,
87 GLbitfield mode,
88 GLubyte **map,
89 GLint *stride)
90 {
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;
94 unsigned int bw, bh;
95
96 if (intel_image->stencil_rb) {
97 /*
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.
101 */
102 intel_tex_image_s8z24_gather(intel, intel_image);
103 }
104
105 /* For compressed formats, the stride is the number of bytes per
106 * row of blocks. intel_miptree_get_image_offset() already does
107 * the divide.
108 */
109 _mesa_get_format_block_size(mt->format, &bw, &bh);
110 assert(y % bh == 0);
111 y /= bh;
112
113 if (likely(mt)) {
114 void *base = intel_region_map(intel, mt->region);
115 unsigned int image_x, image_y;
116
117 intel_miptree_get_image_offset(mt, tex_image->Level, tex_image->Face,
118 slice, &image_x, &image_y);
119 x += image_x;
120 y += image_y;
121
122 *stride = mt->region->pitch * mt->cpp;
123 *map = base + y * *stride + x * mt->cpp;
124 } else {
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);
129
130 assert(map);
131
132 *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
133 *map = tex_image->Data + (slice * height + y) * *stride + x * texelSize;
134
135 return;
136 }
137 }
138
139 static void
140 intel_unmap_texture_image(struct gl_context *ctx,
141 struct gl_texture_image *tex_image, GLuint slice)
142 {
143 struct intel_context *intel = intel_context(ctx);
144 struct intel_texture_image *intel_image = intel_texture_image(tex_image);
145
146 intel_region_unmap(intel, intel_image->mt->region);
147
148 if (intel_image->stencil_rb) {
149 /*
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.
153 */
154 intel_tex_image_s8z24_scatter(intel, intel_image);
155 }
156 }
157
158 /**
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.
163 */
164 static void
165 intelGenerateMipmap(struct gl_context *ctx, GLenum target,
166 struct gl_texture_object *texObj)
167 {
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];
173
174 fallback_debug("%s - fallback to swrast\n", __FUNCTION__);
175
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);
179
180 if (!_mesa_is_format_compressed(first_image->TexFormat)) {
181 GLuint nr_faces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
182 GLuint face, i;
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]);
187 if (!intelImage)
188 break;
189 /* Unreference the miptree to signal that the new Data is a
190 * bare pointer from mesa.
191 */
192 intel_miptree_release(intel, &intelImage->mt);
193 }
194 }
195 }
196 }
197 else {
198 _mesa_meta_GenerateMipmap(ctx, target, texObj);
199 }
200 }
201
202
203 void
204 intelInitTextureFuncs(struct dd_function_table *functions)
205 {
206 functions->GenerateMipmap = intelGenerateMipmap;
207
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;
214 }