intel: It is needed to allocating texture memory to accommodate
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
1
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "glheader.h"
6 #include "macros.h"
7 #include "mtypes.h"
8 #include "enums.h"
9 #include "colortab.h"
10 #include "convolve.h"
11 #include "context.h"
12 #include "simple_list.h"
13 #include "texcompress.h"
14 #include "texformat.h"
15 #include "texobj.h"
16 #include "texstore.h"
17 #include "teximage.h"
18
19 #include "intel_context.h"
20 #include "intel_mipmap_tree.h"
21 #include "intel_buffer_objects.h"
22 #include "intel_batchbuffer.h"
23 #include "intel_tex.h"
24 #include "intel_ioctl.h"
25 #include "intel_blit.h"
26 #include "intel_fbo.h"
27
28 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
29
30 /* Functions to store texture images. Where possible, mipmap_tree's
31 * will be created or further instantiated with image data, otherwise
32 * images will be stored in malloc'd memory. A validation step is
33 * required to pull those images into a mipmap tree, or otherwise
34 * decide a fallback is required.
35 */
36
37
38 static int
39 logbase2(int n)
40 {
41 GLint i = 1;
42 GLint log2 = 0;
43
44 while (n > i) {
45 i *= 2;
46 log2++;
47 }
48
49 return log2;
50 }
51
52
53 /* Otherwise, store it in memory if (Border != 0) or (any dimension ==
54 * 1).
55 *
56 * Otherwise, if max_level >= level >= min_level, create tree with
57 * space for textures from min_level down to max_level.
58 *
59 * Otherwise, create tree with space for textures from (level
60 * 0)..(1x1). Consider pruning this tree at a validation if the
61 * saving is worth it.
62 */
63 static void
64 guess_and_alloc_mipmap_tree(struct intel_context *intel,
65 struct intel_texture_object *intelObj,
66 struct intel_texture_image *intelImage)
67 {
68 GLuint firstLevel;
69 GLuint lastLevel;
70 GLuint width = intelImage->base.Width;
71 GLuint height = intelImage->base.Height;
72 GLuint depth = intelImage->base.Depth;
73 GLuint l2width, l2height, l2depth;
74 GLuint i, comp_byte = 0;
75
76 DBG("%s\n", __FUNCTION__);
77
78 if (intelImage->base.Border)
79 return;
80
81 if (intelImage->level > intelObj->base.BaseLevel &&
82 (intelImage->base.Width == 1 ||
83 (intelObj->base.Target != GL_TEXTURE_1D &&
84 intelImage->base.Height == 1) ||
85 (intelObj->base.Target == GL_TEXTURE_3D &&
86 intelImage->base.Depth == 1)))
87 return;
88
89 /* If this image disrespects BaseLevel, allocate from level zero.
90 * Usually BaseLevel == 0, so it's unlikely to happen.
91 */
92 if (intelImage->level < intelObj->base.BaseLevel)
93 firstLevel = 0;
94 else
95 firstLevel = intelObj->base.BaseLevel;
96
97
98 /* Figure out image dimensions at start level.
99 */
100 for (i = intelImage->level; i > firstLevel; i--) {
101 width <<= 1;
102 if (height != 1)
103 height <<= 1;
104 if (depth != 1)
105 depth <<= 1;
106 }
107
108 /* Guess a reasonable value for lastLevel. This is probably going
109 * to be wrong fairly often and might mean that we have to look at
110 * resizable buffers, or require that buffers implement lazy
111 * pagetable arrangements.
112 */
113 if ((intelObj->base.MinFilter == GL_NEAREST ||
114 intelObj->base.MinFilter == GL_LINEAR) &&
115 intelImage->level == firstLevel) {
116 lastLevel = firstLevel;
117 }
118 else {
119 l2width = logbase2(width);
120 l2height = logbase2(height);
121 l2depth = logbase2(depth);
122 lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
123 }
124
125 assert(!intelObj->mt);
126 if (intelImage->base.IsCompressed)
127 comp_byte = intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
128 intelObj->mt = intel_miptree_create(intel,
129 intelObj->base.Target,
130 intelImage->base.InternalFormat,
131 firstLevel,
132 lastLevel,
133 width,
134 height,
135 depth,
136 intelImage->base.TexFormat->TexelBytes,
137 comp_byte);
138
139 DBG("%s - success\n", __FUNCTION__);
140 }
141
142
143
144
145 static GLuint
146 target_to_face(GLenum target)
147 {
148 switch (target) {
149 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
150 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
151 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
152 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
153 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
154 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
155 return ((GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X);
156 default:
157 return 0;
158 }
159 }
160
161 /* There are actually quite a few combinations this will work for,
162 * more than what I've listed here.
163 */
164 static GLboolean
165 check_pbo_format(GLint internalFormat,
166 GLenum format, GLenum type,
167 const struct gl_texture_format *mesa_format)
168 {
169 switch (internalFormat) {
170 case 4:
171 case GL_RGBA:
172 return (format == GL_BGRA &&
173 (type == GL_UNSIGNED_BYTE ||
174 type == GL_UNSIGNED_INT_8_8_8_8_REV) &&
175 mesa_format == &_mesa_texformat_argb8888);
176 case 3:
177 case GL_RGB:
178 return (format == GL_RGB &&
179 type == GL_UNSIGNED_SHORT_5_6_5 &&
180 mesa_format == &_mesa_texformat_rgb565);
181 case GL_YCBCR_MESA:
182 return (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE);
183 default:
184 return GL_FALSE;
185 }
186 }
187
188
189 /* XXX: Do this for TexSubImage also:
190 */
191 static GLboolean
192 try_pbo_upload(struct intel_context *intel,
193 struct intel_texture_image *intelImage,
194 const struct gl_pixelstore_attrib *unpack,
195 GLint internalFormat,
196 GLint width, GLint height,
197 GLenum format, GLenum type, const void *pixels)
198 {
199 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
200 GLuint src_offset, src_stride;
201 GLuint dst_offset, dst_stride;
202
203 if (!pbo ||
204 intel->ctx._ImageTransferState ||
205 unpack->SkipPixels || unpack->SkipRows) {
206 _mesa_printf("%s: failure 1\n", __FUNCTION__);
207 return GL_FALSE;
208 }
209
210 src_offset = (GLuint) pixels;
211
212 if (unpack->RowLength > 0)
213 src_stride = unpack->RowLength;
214 else
215 src_stride = width;
216
217 dst_offset = intel_miptree_image_offset(intelImage->mt,
218 intelImage->face,
219 intelImage->level);
220
221 dst_stride = intelImage->mt->pitch;
222
223 intelFlush(&intel->ctx);
224 LOCK_HARDWARE(intel);
225 {
226 dri_bo *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ);
227 dri_bo *dst_buffer = intel_region_buffer(intel,
228 intelImage->mt->region,
229 INTEL_WRITE_FULL);
230
231
232 intelEmitCopyBlit(intel,
233 intelImage->mt->cpp,
234 src_stride, src_buffer, src_offset, GL_FALSE,
235 dst_stride, dst_buffer, dst_offset, GL_FALSE,
236 0, 0, 0, 0, width, height,
237 GL_COPY);
238
239 intel_batchbuffer_flush(intel->batch);
240 }
241 UNLOCK_HARDWARE(intel);
242
243 return GL_TRUE;
244 }
245
246
247
248 static GLboolean
249 try_pbo_zcopy(struct intel_context *intel,
250 struct intel_texture_image *intelImage,
251 const struct gl_pixelstore_attrib *unpack,
252 GLint internalFormat,
253 GLint width, GLint height,
254 GLenum format, GLenum type, const void *pixels)
255 {
256 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
257 GLuint src_offset, src_stride;
258 GLuint dst_offset, dst_stride;
259
260 if (!pbo ||
261 intel->ctx._ImageTransferState ||
262 unpack->SkipPixels || unpack->SkipRows) {
263 _mesa_printf("%s: failure 1\n", __FUNCTION__);
264 return GL_FALSE;
265 }
266
267 src_offset = (GLuint) pixels;
268
269 if (unpack->RowLength > 0)
270 src_stride = unpack->RowLength;
271 else
272 src_stride = width;
273
274 dst_offset = intel_miptree_image_offset(intelImage->mt,
275 intelImage->face,
276 intelImage->level);
277
278 dst_stride = intelImage->mt->pitch;
279
280 if (src_stride != dst_stride || dst_offset != 0 || src_offset != 0) {
281 _mesa_printf("%s: failure 2\n", __FUNCTION__);
282 return GL_FALSE;
283 }
284
285 intel_region_attach_pbo(intel, intelImage->mt->region, pbo);
286
287 return GL_TRUE;
288 }
289
290
291
292
293
294
295 static void
296 intelTexImage(GLcontext * ctx,
297 GLint dims,
298 GLenum target, GLint level,
299 GLint internalFormat,
300 GLint width, GLint height, GLint depth,
301 GLint border,
302 GLenum format, GLenum type, const void *pixels,
303 const struct gl_pixelstore_attrib *unpack,
304 struct gl_texture_object *texObj,
305 struct gl_texture_image *texImage, GLsizei imageSize, int compressed)
306 {
307 struct intel_context *intel = intel_context(ctx);
308 struct intel_texture_object *intelObj = intel_texture_object(texObj);
309 struct intel_texture_image *intelImage = intel_texture_image(texImage);
310 GLint postConvWidth = width;
311 GLint postConvHeight = height;
312 GLint texelBytes, sizeInBytes;
313 GLuint dstRowStride, srcRowStride = texImage->RowStride;
314
315
316 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
317 _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
318
319 intelFlush(ctx);
320
321 intelImage->face = target_to_face(target);
322 intelImage->level = level;
323
324 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
325 _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth,
326 &postConvHeight);
327 }
328
329 /* choose the texture format */
330 texImage->TexFormat = intelChooseTextureFormat(ctx, internalFormat,
331 format, type);
332
333 _mesa_set_fetch_functions(texImage, dims);
334
335 if (texImage->TexFormat->TexelBytes == 0) {
336 /* must be a compressed format */
337 texelBytes = 0;
338 texImage->IsCompressed = GL_TRUE;
339 texImage->CompressedSize =
340 ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
341 texImage->Height, texImage->Depth,
342 texImage->TexFormat->MesaFormat);
343 } else {
344 texelBytes = texImage->TexFormat->TexelBytes;
345
346 /* Minimum pitch of 32 bytes */
347 if (postConvWidth * texelBytes < 32) {
348 postConvWidth = 32 / texelBytes;
349 texImage->RowStride = postConvWidth;
350 }
351
352 assert(texImage->RowStride == postConvWidth);
353 }
354
355 /* Release the reference to a potentially orphaned buffer.
356 * Release any old malloced memory.
357 */
358 if (intelImage->mt) {
359 intel_miptree_release(intel, &intelImage->mt);
360 assert(!texImage->Data);
361 }
362 else if (texImage->Data) {
363 _mesa_align_free(texImage->Data);
364 }
365
366 /* If this is the only texture image in the tree, could call
367 * bmBufferData with NULL data to free the old block and avoid
368 * waiting on any outstanding fences.
369 */
370 if (intelObj->mt &&
371 intelObj->mt->first_level == level &&
372 intelObj->mt->last_level == level &&
373 intelObj->mt->target != GL_TEXTURE_CUBE_MAP_ARB &&
374 !intel_miptree_match_image(intelObj->mt, &intelImage->base,
375 intelImage->face, intelImage->level)) {
376
377 DBG("release it\n");
378 intel_miptree_release(intel, &intelObj->mt);
379 assert(!intelObj->mt);
380 }
381
382 if (!intelObj->mt) {
383 guess_and_alloc_mipmap_tree(intel, intelObj, intelImage);
384 if (!intelObj->mt) {
385 DBG("guess_and_alloc_mipmap_tree: failed\n");
386 }
387 }
388
389 assert(!intelImage->mt);
390
391 if (intelObj->mt &&
392 intel_miptree_match_image(intelObj->mt, &intelImage->base,
393 intelImage->face, intelImage->level)) {
394
395 intel_miptree_reference(&intelImage->mt, intelObj->mt);
396 assert(intelImage->mt);
397 }
398
399 if (!intelImage->mt)
400 DBG("XXX: Image did not fit into tree - storing in local memory!\n");
401
402 /* PBO fastpaths:
403 */
404 if (dims <= 2 &&
405 intelImage->mt &&
406 intel_buffer_object(unpack->BufferObj) &&
407 check_pbo_format(internalFormat, format,
408 type, intelImage->base.TexFormat)) {
409
410 DBG("trying pbo upload\n");
411
412 /* Attempt to texture directly from PBO data (zero copy upload).
413 *
414 * Currently disable as it can lead to worse as well as better
415 * performance (in particular when intel_region_cow() is
416 * required).
417 */
418 if (intelObj->mt == intelImage->mt &&
419 intelObj->mt->first_level == level &&
420 intelObj->mt->last_level == level) {
421
422 if (try_pbo_zcopy(intel, intelImage, unpack,
423 internalFormat,
424 width, height, format, type, pixels)) {
425
426 DBG("pbo zcopy upload succeeded\n");
427 return;
428 }
429 }
430
431
432 /* Otherwise, attempt to use the blitter for PBO image uploads.
433 */
434 if (try_pbo_upload(intel, intelImage, unpack,
435 internalFormat,
436 width, height, format, type, pixels)) {
437 DBG("pbo upload succeeded\n");
438 return;
439 }
440
441 DBG("pbo upload failed\n");
442 }
443
444
445
446 /* intelCopyTexImage calls this function with pixels == NULL, with
447 * the expectation that the mipmap tree will be set up but nothing
448 * more will be done. This is where those calls return:
449 */
450 if (compressed) {
451 pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
452 unpack,
453 "glCompressedTexImage");
454 } else {
455 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
456 format, type,
457 pixels, unpack, "glTexImage");
458 }
459
460 LOCK_HARDWARE(intel);
461
462 if (intelImage->mt) {
463 texImage->Data = intel_miptree_image_map(intel,
464 intelImage->mt,
465 intelImage->face,
466 intelImage->level,
467 &dstRowStride,
468 intelImage->base.ImageOffsets);
469 texImage->RowStride = dstRowStride / intelImage->mt->cpp;
470 }
471 else {
472 /* Allocate regular memory and store the image there temporarily. */
473 if (texImage->IsCompressed) {
474 sizeInBytes = texImage->CompressedSize;
475 dstRowStride =
476 _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
477 assert(dims != 3);
478 }
479 else {
480 dstRowStride = postConvWidth * texelBytes;
481 sizeInBytes = depth * dstRowStride * postConvHeight;
482 }
483
484 texImage->Data = malloc(sizeInBytes);
485 }
486
487 DBG("Upload image %dx%dx%d row_len %d "
488 "pitch %d\n",
489 width, height, depth, width * texelBytes, dstRowStride);
490
491 /* Copy data. Would like to know when it's ok for us to eg. use
492 * the blitter to copy. Or, use the hardware to do the format
493 * conversion and copy:
494 */
495 if (pixels) {
496 if (compressed) {
497 if (intelImage->mt) {
498 struct intel_region *dst = intelImage->mt->region;
499 _mesa_copy_rect(texImage->Data, dst->cpp, dst->pitch,
500 0, 0,
501 intelImage->mt->level[level].width,
502 intelImage->mt->level[level].height/4,
503 pixels,
504 srcRowStride,
505 0, 0);
506 } else
507 memcpy(texImage->Data, pixels, imageSize);
508 } else if (!texImage->TexFormat->StoreImage(ctx, dims,
509 texImage->_BaseFormat,
510 texImage->TexFormat,
511 texImage->Data, 0, 0, 0, /* dstX/Y/Zoffset */
512 dstRowStride,
513 texImage->ImageOffsets,
514 width, height, depth,
515 format, type, pixels, unpack)) {
516 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
517 }
518 }
519
520 /* GL_SGIS_generate_mipmap */
521 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
522 intel_generate_mipmap(ctx, target,
523 &ctx->Texture.Unit[ctx->Texture.CurrentUnit],
524 texObj);
525 }
526
527 _mesa_unmap_teximage_pbo(ctx, unpack);
528
529 if (intelImage->mt) {
530 intel_miptree_image_unmap(intel, intelImage->mt);
531 texImage->Data = NULL;
532 }
533
534 UNLOCK_HARDWARE(intel);
535 }
536
537 void
538 intelTexImage3D(GLcontext * ctx,
539 GLenum target, GLint level,
540 GLint internalFormat,
541 GLint width, GLint height, GLint depth,
542 GLint border,
543 GLenum format, GLenum type, const void *pixels,
544 const struct gl_pixelstore_attrib *unpack,
545 struct gl_texture_object *texObj,
546 struct gl_texture_image *texImage)
547 {
548 intelTexImage(ctx, 3, target, level,
549 internalFormat, width, height, depth, border,
550 format, type, pixels, unpack, texObj, texImage, 0, 0);
551 }
552
553
554 void
555 intelTexImage2D(GLcontext * ctx,
556 GLenum target, GLint level,
557 GLint internalFormat,
558 GLint width, GLint height, GLint border,
559 GLenum format, GLenum type, const void *pixels,
560 const struct gl_pixelstore_attrib *unpack,
561 struct gl_texture_object *texObj,
562 struct gl_texture_image *texImage)
563 {
564 intelTexImage(ctx, 2, target, level,
565 internalFormat, width, height, 1, border,
566 format, type, pixels, unpack, texObj, texImage, 0, 0);
567 }
568
569 void
570 intelTexImage1D(GLcontext * ctx,
571 GLenum target, GLint level,
572 GLint internalFormat,
573 GLint width, GLint border,
574 GLenum format, GLenum type, const void *pixels,
575 const struct gl_pixelstore_attrib *unpack,
576 struct gl_texture_object *texObj,
577 struct gl_texture_image *texImage)
578 {
579 intelTexImage(ctx, 1, target, level,
580 internalFormat, width, 1, 1, border,
581 format, type, pixels, unpack, texObj, texImage, 0, 0);
582 }
583
584 void intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
585 GLint internalFormat,
586 GLint width, GLint height, GLint border,
587 GLsizei imageSize, const GLvoid *data,
588 struct gl_texture_object *texObj,
589 struct gl_texture_image *texImage )
590 {
591 intelTexImage(ctx, 2, target, level,
592 internalFormat, width, height, 1, border,
593 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, 1);
594 }
595
596 /**
597 * Need to map texture image into memory before copying image data,
598 * then unmap it.
599 */
600 static void
601 intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
602 GLenum format, GLenum type, GLvoid * pixels,
603 struct gl_texture_object *texObj,
604 struct gl_texture_image *texImage, int compressed)
605 {
606 struct intel_context *intel = intel_context(ctx);
607 struct intel_texture_image *intelImage = intel_texture_image(texImage);
608
609 /* Map */
610 if (intelImage->mt) {
611 /* Image is stored in hardware format in a buffer managed by the
612 * kernel. Need to explicitly map and unmap it.
613 */
614 intelImage->base.Data =
615 intel_miptree_image_map(intel,
616 intelImage->mt,
617 intelImage->face,
618 intelImage->level,
619 &intelImage->base.RowStride,
620 intelImage->base.ImageOffsets);
621 intelImage->base.RowStride /= intelImage->mt->cpp;
622 }
623 else {
624 /* Otherwise, the image should actually be stored in
625 * intelImage->base.Data. This is pretty confusing for
626 * everybody, I'd much prefer to separate the two functions of
627 * texImage->Data - storage for texture images in main memory
628 * and access (ie mappings) of images. In other words, we'd
629 * create a new texImage->Map field and leave Data simply for
630 * storage.
631 */
632 assert(intelImage->base.Data);
633 }
634
635
636 if (compressed) {
637 _mesa_get_compressed_teximage(ctx, target, level, pixels,
638 texObj, texImage);
639 } else {
640 _mesa_get_teximage(ctx, target, level, format, type, pixels,
641 texObj, texImage);
642 }
643
644
645 /* Unmap */
646 if (intelImage->mt) {
647 intel_miptree_image_unmap(intel, intelImage->mt);
648 intelImage->base.Data = NULL;
649 }
650 }
651
652 void
653 intelGetTexImage(GLcontext * ctx, GLenum target, GLint level,
654 GLenum format, GLenum type, GLvoid * pixels,
655 struct gl_texture_object *texObj,
656 struct gl_texture_image *texImage)
657 {
658 intel_get_tex_image(ctx, target, level, format, type, pixels,
659 texObj, texImage, 0);
660
661
662 }
663
664 void
665 intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
666 GLvoid *pixels,
667 struct gl_texture_object *texObj,
668 struct gl_texture_image *texImage)
669 {
670 intel_get_tex_image(ctx, target, level, 0, 0, pixels,
671 texObj, texImage, 1);
672 }
673
674 void
675 intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname,
676 unsigned long long offset, GLint depth, GLuint pitch)
677 {
678 struct intel_context *intel = (struct intel_context*)
679 ((__DRIcontextPrivate*)pDRICtx->private)->driverPrivate;
680 struct gl_texture_object *tObj = _mesa_lookup_texture(&intel->ctx, texname);
681 struct intel_texture_object *intelObj = intel_texture_object(tObj);
682
683 if (!intelObj)
684 return;
685
686 if (intelObj->mt)
687 intel_miptree_release(intel, &intelObj->mt);
688
689 intelObj->imageOverride = GL_TRUE;
690 intelObj->depthOverride = depth;
691 intelObj->pitchOverride = pitch;
692
693 if (offset)
694 intelObj->textureOffset = offset;
695 }
696
697 void
698 intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *pDraw)
699 {
700 __DRIcontextPrivate *driContext = pDRICtx->private;
701 __DRIdrawablePrivate *dPriv = pDraw->private;
702 struct intel_framebuffer *intel_fb = dPriv->driverPrivate;
703 struct intel_context *intel = driContext->driverPrivate;
704 struct intel_texture_object *intelObj;
705 struct intel_texture_image *intelImage;
706 struct intel_mipmap_tree *mt;
707 struct intel_renderbuffer *rb;
708 struct gl_texture_unit *texUnit;
709 struct gl_texture_object *texObj;
710 struct gl_texture_image *texImage;
711 int level = 0, type, format, internalFormat;
712
713 texUnit = &intel->ctx.Texture.Unit[intel->ctx.Texture.CurrentUnit];
714 texObj = _mesa_select_tex_object(&intel->ctx, texUnit, target);
715 intelObj = intel_texture_object(texObj);
716
717 if (!intelObj)
718 return;
719
720 __driParseEvents(driContext, dPriv);
721
722 rb = intel_fb->color_rb[0];
723 type = GL_BGRA;
724 format = GL_UNSIGNED_BYTE;
725 internalFormat = (rb->region->cpp == 3 ? 3 : 4);
726
727 mt = intel_miptree_create_for_region(intel, target,
728 internalFormat,
729 0, 0, rb->region, 1, 0);
730 if (mt == NULL)
731 return;
732
733 _mesa_lock_texture(&intel->ctx, texObj);
734
735 if (intelObj->mt)
736 intel_miptree_release(intel, &intelObj->mt);
737
738 intelObj->mt = mt;
739 texImage = _mesa_get_tex_image(&intel->ctx, texObj, target, level);
740 _mesa_init_teximage_fields(&intel->ctx, target, texImage,
741 rb->region->pitch, rb->region->height, 1,
742 0, internalFormat);
743
744 intelImage = intel_texture_image(texImage);
745 intelImage->face = target_to_face(target);
746 intelImage->level = level;
747 texImage->TexFormat = intelChooseTextureFormat(&intel->ctx, internalFormat,
748 type, format);
749 _mesa_set_fetch_functions(texImage, 2);
750 texImage->RowStride = rb->region->pitch;
751 intel_miptree_reference(&intelImage->mt, intelObj->mt);
752
753 if (!intel_miptree_match_image(intelObj->mt, &intelImage->base,
754 intelImage->face, intelImage->level)) {
755 fprintf(stderr, "miptree doesn't match image\n");
756 }
757
758 _mesa_unlock_texture(&intel->ctx, texObj);
759 }