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