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