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"
11 #include "main/renderbuffer.h"
12 #include "main/texcompress.h"
13 #include "main/texstore.h"
14 #include "main/texgetimage.h"
15 #include "main/texobj.h"
16 #include "main/teximage.h"
18 #include "intel_context.h"
19 #include "intel_mipmap_tree.h"
20 #include "intel_buffer_objects.h"
21 #include "intel_batchbuffer.h"
22 #include "intel_tex.h"
23 #include "intel_blit.h"
24 #include "intel_fbo.h"
25 #include "intel_span.h"
27 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
29 /* Functions to store texture images. Where possible, mipmap_tree's
30 * will be created or further instantiated with image data, otherwise
31 * images will be stored in malloc'd memory. A validation step is
32 * required to pull those images into a mipmap tree, or otherwise
33 * decide a fallback is required.
38 /* Otherwise, store it in memory if (Border != 0) or (any dimension ==
41 * Otherwise, if max_level >= level >= min_level, create tree with
42 * space for textures from min_level down to max_level.
44 * Otherwise, create tree with space for textures from (level
45 * 0)..(1x1). Consider pruning this tree at a validation if the
48 static struct intel_mipmap_tree
*
49 intel_miptree_create_for_teximage(struct intel_context
*intel
,
50 struct intel_texture_object
*intelObj
,
51 struct intel_texture_image
*intelImage
,
52 GLboolean expect_accelerated_upload
)
56 GLuint width
= intelImage
->base
.Width
;
57 GLuint height
= intelImage
->base
.Height
;
58 GLuint depth
= intelImage
->base
.Depth
;
61 DBG("%s\n", __FUNCTION__
);
63 if (intelImage
->base
.Border
)
66 if (intelImage
->level
> intelObj
->base
.BaseLevel
&&
67 (intelImage
->base
.Width
== 1 ||
68 (intelObj
->base
.Target
!= GL_TEXTURE_1D
&&
69 intelImage
->base
.Height
== 1) ||
70 (intelObj
->base
.Target
== GL_TEXTURE_3D
&&
71 intelImage
->base
.Depth
== 1))) {
72 /* For this combination, we're at some lower mipmap level and
73 * some important dimension is 1. We can't extrapolate up to a
74 * likely base level width/height/depth for a full mipmap stack
75 * from this info, so just allocate this one level.
77 firstLevel
= intelImage
->level
;
78 lastLevel
= intelImage
->level
;
80 /* If this image disrespects BaseLevel, allocate from level zero.
81 * Usually BaseLevel == 0, so it's unlikely to happen.
83 if (intelImage
->level
< intelObj
->base
.BaseLevel
)
86 firstLevel
= intelObj
->base
.BaseLevel
;
88 /* Figure out image dimensions at start level. */
89 for (i
= intelImage
->level
; i
> firstLevel
; i
--) {
97 /* Guess a reasonable value for lastLevel. This is probably going
98 * to be wrong fairly often and might mean that we have to look at
99 * resizable buffers, or require that buffers implement lazy
100 * pagetable arrangements.
102 if ((intelObj
->base
.Sampler
.MinFilter
== GL_NEAREST
||
103 intelObj
->base
.Sampler
.MinFilter
== GL_LINEAR
) &&
104 intelImage
->level
== firstLevel
&&
105 (intel
->gen
< 4 || firstLevel
== 0)) {
106 lastLevel
= firstLevel
;
108 lastLevel
= firstLevel
+ _mesa_logbase2(MAX2(MAX2(width
, height
), depth
));
112 return intel_miptree_create(intel
,
113 intelObj
->base
.Target
,
114 intelImage
->base
.TexFormat
,
120 expect_accelerated_upload
);
123 /* There are actually quite a few combinations this will work for,
124 * more than what I've listed here.
127 check_pbo_format(GLint internalFormat
,
128 GLenum format
, GLenum type
,
129 gl_format mesa_format
)
131 switch (internalFormat
) {
135 return (format
== GL_BGRA
&&
136 (type
== GL_UNSIGNED_BYTE
||
137 type
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
138 mesa_format
== MESA_FORMAT_ARGB8888
);
141 return (format
== GL_RGB
&&
142 type
== GL_UNSIGNED_SHORT_5_6_5
&&
143 mesa_format
== MESA_FORMAT_RGB565
);
146 return (format
== GL_LUMINANCE
&&
147 type
== GL_UNSIGNED_BYTE
&&
148 mesa_format
== MESA_FORMAT_L8
);
150 return (type
== GL_UNSIGNED_SHORT_8_8_MESA
|| type
== GL_UNSIGNED_BYTE
);
157 /* XXX: Do this for TexSubImage also:
160 try_pbo_upload(struct intel_context
*intel
,
161 struct intel_texture_image
*intelImage
,
162 const struct gl_pixelstore_attrib
*unpack
,
163 GLint internalFormat
,
164 GLint width
, GLint height
,
165 GLenum format
, GLenum type
, const void *pixels
)
167 struct intel_buffer_object
*pbo
= intel_buffer_object(unpack
->BufferObj
);
168 GLuint src_offset
, src_stride
;
169 GLuint dst_x
, dst_y
, dst_stride
;
170 drm_intel_bo
*dst_buffer
= intel_region_buffer(intel
,
171 intelImage
->mt
->region
,
174 if (!_mesa_is_bufferobj(unpack
->BufferObj
) ||
175 intel
->ctx
._ImageTransferState
||
176 unpack
->SkipPixels
|| unpack
->SkipRows
) {
177 DBG("%s: failure 1\n", __FUNCTION__
);
181 /* note: potential 64-bit ptr to 32-bit int cast */
182 src_offset
= (GLuint
) (unsigned long) pixels
;
184 if (unpack
->RowLength
> 0)
185 src_stride
= unpack
->RowLength
;
189 intel_miptree_get_image_offset(intelImage
->mt
, intelImage
->level
,
193 dst_stride
= intelImage
->mt
->region
->pitch
;
195 if (drm_intel_bo_references(intel
->batch
.bo
, dst_buffer
))
196 intel_flush(&intel
->ctx
);
200 drm_intel_bo
*src_buffer
=
201 intel_bufferobj_source(intel
, pbo
, 64, &offset
);
203 if (!intelEmitCopyBlit(intel
,
205 src_stride
, src_buffer
,
206 src_offset
+ offset
, GL_FALSE
,
207 dst_stride
, dst_buffer
, 0,
208 intelImage
->mt
->region
->tiling
,
209 0, 0, dst_x
, dst_y
, width
, height
,
220 try_pbo_zcopy(struct intel_context
*intel
,
221 struct intel_texture_image
*intelImage
,
222 const struct gl_pixelstore_attrib
*unpack
,
223 GLint internalFormat
,
224 GLint width
, GLint height
,
225 GLenum format
, GLenum type
, const void *pixels
)
227 struct intel_buffer_object
*pbo
= intel_buffer_object(unpack
->BufferObj
);
228 GLuint src_offset
, src_stride
;
229 GLuint dst_x
, dst_y
, dst_stride
;
231 if (!_mesa_is_bufferobj(unpack
->BufferObj
) ||
232 intel
->ctx
._ImageTransferState
||
233 unpack
->SkipPixels
|| unpack
->SkipRows
) {
234 DBG("%s: failure 1\n", __FUNCTION__
);
238 /* note: potential 64-bit ptr to 32-bit int cast */
239 src_offset
= (GLuint
) (unsigned long) pixels
;
241 if (unpack
->RowLength
> 0)
242 src_stride
= unpack
->RowLength
;
246 intel_miptree_get_image_offset(intelImage
->mt
, intelImage
->level
,
250 dst_stride
= intelImage
->mt
->region
->pitch
;
252 if (src_stride
!= dst_stride
|| dst_x
!= 0 || dst_y
!= 0 ||
254 DBG("%s: failure 2\n", __FUNCTION__
);
258 intel_region_attach_pbo(intel
, intelImage
->mt
->region
, pbo
);
264 * \param scatter Scatter if true. Gather if false.
266 * \see intel_tex_image_x8z24_scatter
267 * \see intel_tex_image_x8z24_gather
270 intel_tex_image_s8z24_scattergather(struct intel_context
*intel
,
271 struct intel_texture_image
*intel_image
,
274 struct gl_context
*ctx
= &intel
->ctx
;
275 struct gl_renderbuffer
*depth_rb
= intel_image
->depth_rb
;
276 struct gl_renderbuffer
*stencil_rb
= intel_image
->stencil_rb
;
278 int w
= intel_image
->base
.Width
;
279 int h
= intel_image
->base
.Height
;
281 uint32_t depth_row
[w
];
282 uint8_t stencil_row
[w
];
284 intel_renderbuffer_map(intel
, depth_rb
);
285 intel_renderbuffer_map(intel
, stencil_rb
);
288 for (int y
= 0; y
< h
; ++y
) {
289 depth_rb
->GetRow(ctx
, depth_rb
, w
, 0, y
, depth_row
);
290 for (int x
= 0; x
< w
; ++x
) {
291 stencil_row
[x
] = depth_row
[x
] >> 24;
293 stencil_rb
->PutRow(ctx
, stencil_rb
, w
, 0, y
, stencil_row
, NULL
);
295 } else { /* gather */
296 for (int y
= 0; y
< h
; ++y
) {
297 depth_rb
->GetRow(ctx
, depth_rb
, w
, 0, y
, depth_row
);
298 stencil_rb
->GetRow(ctx
, stencil_rb
, w
, 0, y
, stencil_row
);
299 for (int x
= 0; x
< w
; ++x
) {
300 uint32_t s8_x24
= stencil_row
[x
] << 24;
301 uint32_t x8_z24
= depth_row
[x
] & 0x00ffffff;
302 depth_row
[x
] = s8_x24
| x8_z24
;
304 depth_rb
->PutRow(ctx
, depth_rb
, w
, 0, y
, depth_row
, NULL
);
308 intel_renderbuffer_unmap(intel
, depth_rb
);
309 intel_renderbuffer_unmap(intel
, stencil_rb
);
313 * Copy the x8 bits from intel_image->depth_rb to intel_image->stencil_rb.
316 intel_tex_image_s8z24_scatter(struct intel_context
*intel
,
317 struct intel_texture_image
*intel_image
)
319 intel_tex_image_s8z24_scattergather(intel
, intel_image
, true);
323 * Copy the data in intel_image->stencil_rb to the x8 bits in
324 * intel_image->depth_rb.
327 intel_tex_image_s8z24_gather(struct intel_context
*intel
,
328 struct intel_texture_image
*intel_image
)
330 intel_tex_image_s8z24_scattergather(intel
, intel_image
, false);
334 intel_tex_image_s8z24_create_renderbuffers(struct intel_context
*intel
,
335 struct intel_texture_image
*image
)
337 struct gl_context
*ctx
= &intel
->ctx
;
340 int width
= image
->base
.Width
;
341 int height
= image
->base
.Height
;
342 struct gl_renderbuffer
*drb
;
343 struct gl_renderbuffer
*srb
;
344 struct intel_renderbuffer
*idrb
;
345 struct intel_renderbuffer
*isrb
;
347 assert(intel
->has_separate_stencil
);
348 assert(image
->base
.TexFormat
== MESA_FORMAT_S8_Z24
);
349 assert(image
->mt
!= NULL
);
351 drb
= intel_create_wrapped_renderbuffer(ctx
, width
, height
,
353 srb
= intel_create_wrapped_renderbuffer(ctx
, width
, height
,
366 idrb
= intel_renderbuffer(drb
);
367 isrb
= intel_renderbuffer(srb
);
369 intel_region_reference(&idrb
->region
, image
->mt
->region
);
370 ok
= intel_alloc_renderbuffer_storage(ctx
, srb
, GL_STENCIL_INDEX8
,
379 intel_renderbuffer_set_draw_offset(idrb
, image
, 0);
380 intel_renderbuffer_set_draw_offset(isrb
, image
, 0);
382 _mesa_reference_renderbuffer(&image
->depth_rb
, drb
);
383 _mesa_reference_renderbuffer(&image
->stencil_rb
, srb
);
389 intelTexImage(struct gl_context
* ctx
,
391 GLenum target
, GLint level
,
392 GLint internalFormat
,
393 GLint width
, GLint height
, GLint depth
,
395 GLenum format
, GLenum type
, const void *pixels
,
396 const struct gl_pixelstore_attrib
*unpack
,
397 struct gl_texture_object
*texObj
,
398 struct gl_texture_image
*texImage
, GLsizei imageSize
,
399 GLboolean compressed
)
401 struct intel_context
*intel
= intel_context(ctx
);
402 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
403 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
404 GLint texelBytes
, sizeInBytes
;
405 GLuint dstRowStride
= 0, srcRowStride
= texImage
->RowStride
;
407 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__
,
408 _mesa_lookup_enum_by_nr(target
), level
, width
, height
, depth
, border
);
410 intelImage
->face
= _mesa_tex_target_to_face(target
);
411 intelImage
->level
= level
;
413 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
417 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
419 if (!intelImage
->mt
) {
420 assert(texImage
->RowStride
== width
);
424 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
425 assert(!intelImage
->mt
);
428 intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
429 /* Use an existing miptree when possible */
430 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
431 assert(intelImage
->mt
);
432 } else if (intelImage
->base
.Border
== 0) {
433 /* Didn't fit in the object miptree, but it's suitable for inclusion in
434 * a miptree, so create one just for our level and store it in the image.
435 * It'll get moved into the object miptree at validate time.
437 intelImage
->mt
= intel_miptree_create_for_teximage(intel
, intelObj
,
441 /* Even if the object currently has a mipmap tree associated
442 * with it, this one is a more likely candidate to represent the
443 * whole object since our level didn't fit what was there
444 * before, and any lower levels would fit into our miptree.
446 if (intelImage
->mt
) {
447 intel_miptree_release(intel
, &intelObj
->mt
);
448 intel_miptree_reference(&intelObj
->mt
, intelImage
->mt
);
456 _mesa_is_bufferobj(unpack
->BufferObj
) &&
457 check_pbo_format(internalFormat
, format
,
458 type
, intelImage
->base
.TexFormat
)) {
460 DBG("trying pbo upload\n");
462 /* Attempt to texture directly from PBO data (zero copy upload).
464 * Currently disable as it can lead to worse as well as better
465 * performance (in particular when intel_region_cow() is
468 if (intelObj
->mt
== intelImage
->mt
&&
469 intelObj
->mt
->first_level
== level
&&
470 intelObj
->mt
->last_level
== level
) {
472 if (try_pbo_zcopy(intel
, intelImage
, unpack
,
474 width
, height
, format
, type
, pixels
)) {
476 DBG("pbo zcopy upload succeeded\n");
482 /* Otherwise, attempt to use the blitter for PBO image uploads.
484 if (try_pbo_upload(intel
, intelImage
, unpack
,
486 width
, height
, format
, type
, pixels
)) {
487 DBG("pbo upload succeeded\n");
491 DBG("pbo upload failed\n");
494 /* intelCopyTexImage calls this function with pixels == NULL, with
495 * the expectation that the mipmap tree will be set up but nothing
496 * more will be done. This is where those calls return:
499 pixels
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, pixels
,
501 "glCompressedTexImage");
503 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
505 pixels
, unpack
, "glTexImage");
508 if (intelImage
->mt
) {
509 if (pixels
!= NULL
) {
510 /* Flush any queued rendering with the texture before mapping. */
511 if (drm_intel_bo_references(intel
->batch
.bo
,
512 intelImage
->mt
->region
->buffer
)) {
515 texImage
->Data
= intel_miptree_image_map(intel
,
520 intelImage
->base
.ImageOffsets
);
523 texImage
->RowStride
= dstRowStride
/ intelImage
->mt
->cpp
;
526 /* Allocate regular memory and store the image there temporarily. */
527 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
528 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
533 _mesa_format_row_stride(texImage
->TexFormat
, width
);
537 dstRowStride
= width
* texelBytes
;
538 sizeInBytes
= depth
* dstRowStride
* height
;
541 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
544 DBG("Upload image %dx%dx%d row_len %d "
545 "pitch %d pixels %d compressed %d\n",
546 width
, height
, depth
, width
* texelBytes
, dstRowStride
,
547 pixels
? 1 : 0, compressed
);
549 /* Copy data. Would like to know when it's ok for us to eg. use
550 * the blitter to copy. Or, use the hardware to do the format
551 * conversion and copy:
555 if (intelImage
->mt
) {
556 struct intel_region
*dst
= intelImage
->mt
->region
;
557 _mesa_copy_rect(texImage
->Data
, dst
->cpp
, dst
->pitch
,
559 intelImage
->mt
->level
[level
].width
,
560 (intelImage
->mt
->level
[level
].height
+3)/4,
566 memcpy(texImage
->Data
, pixels
, imageSize
);
569 else if (!_mesa_texstore(ctx
, dims
,
570 texImage
->_BaseFormat
,
572 texImage
->Data
, 0, 0, 0, /* dstX/Y/Zoffset */
574 texImage
->ImageOffsets
,
575 width
, height
, depth
,
576 format
, type
, pixels
, unpack
)) {
577 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
581 _mesa_unmap_teximage_pbo(ctx
, unpack
);
583 if (intel
->must_use_separate_stencil
584 && texImage
->TexFormat
== MESA_FORMAT_S8_Z24
) {
585 intel_tex_image_s8z24_create_renderbuffers(intel
, intelImage
);
586 intel_tex_image_s8z24_scatter(intel
, intelImage
);
589 if (intelImage
->mt
) {
591 intel_miptree_image_unmap(intel
, intelImage
->mt
);
592 texImage
->Data
= NULL
;
598 intelTexImage3D(struct gl_context
* ctx
,
599 GLenum target
, GLint level
,
600 GLint internalFormat
,
601 GLint width
, GLint height
, GLint depth
,
603 GLenum format
, GLenum type
, const void *pixels
,
604 const struct gl_pixelstore_attrib
*unpack
,
605 struct gl_texture_object
*texObj
,
606 struct gl_texture_image
*texImage
)
608 intelTexImage(ctx
, 3, target
, level
,
609 internalFormat
, width
, height
, depth
, border
,
610 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
615 intelTexImage2D(struct gl_context
* ctx
,
616 GLenum target
, GLint level
,
617 GLint internalFormat
,
618 GLint width
, GLint height
, GLint border
,
619 GLenum format
, GLenum type
, const void *pixels
,
620 const struct gl_pixelstore_attrib
*unpack
,
621 struct gl_texture_object
*texObj
,
622 struct gl_texture_image
*texImage
)
624 intelTexImage(ctx
, 2, target
, level
,
625 internalFormat
, width
, height
, 1, border
,
626 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
631 intelTexImage1D(struct gl_context
* ctx
,
632 GLenum target
, GLint level
,
633 GLint internalFormat
,
634 GLint width
, GLint border
,
635 GLenum format
, GLenum type
, const void *pixels
,
636 const struct gl_pixelstore_attrib
*unpack
,
637 struct gl_texture_object
*texObj
,
638 struct gl_texture_image
*texImage
)
640 intelTexImage(ctx
, 1, target
, level
,
641 internalFormat
, width
, 1, 1, border
,
642 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
647 intelCompressedTexImage2D( struct gl_context
*ctx
, GLenum target
, GLint level
,
648 GLint internalFormat
,
649 GLint width
, GLint height
, GLint border
,
650 GLsizei imageSize
, const GLvoid
*data
,
651 struct gl_texture_object
*texObj
,
652 struct gl_texture_image
*texImage
)
654 intelTexImage(ctx
, 2, target
, level
,
655 internalFormat
, width
, height
, 1, border
,
656 0, 0, data
, &ctx
->Unpack
, texObj
, texImage
, imageSize
, GL_TRUE
);
661 * Need to map texture image into memory before copying image data,
665 intel_get_tex_image(struct gl_context
* ctx
, GLenum target
, GLint level
,
666 GLenum format
, GLenum type
, GLvoid
* pixels
,
667 struct gl_texture_object
*texObj
,
668 struct gl_texture_image
*texImage
, GLboolean compressed
)
670 struct intel_context
*intel
= intel_context(ctx
);
671 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
673 /* If we're reading from a texture that has been rendered to, need to
674 * make sure rendering is complete.
675 * We could probably predicate this on texObj->_RenderToTexture
680 if (intelImage
->mt
) {
681 /* Image is stored in hardware format in a buffer managed by the
682 * kernel. Need to explicitly map and unmap it.
684 intelImage
->base
.Data
=
685 intel_miptree_image_map(intel
,
689 &intelImage
->base
.RowStride
,
690 intelImage
->base
.ImageOffsets
);
691 intelImage
->base
.RowStride
/= intelImage
->mt
->cpp
;
694 /* Otherwise, the image should actually be stored in
695 * intelImage->base.Data. This is pretty confusing for
696 * everybody, I'd much prefer to separate the two functions of
697 * texImage->Data - storage for texture images in main memory
698 * and access (ie mappings) of images. In other words, we'd
699 * create a new texImage->Map field and leave Data simply for
702 assert(intelImage
->base
.Data
);
705 if (intelImage
->stencil_rb
) {
707 * The texture has packed depth/stencil format, but uses separate
708 * stencil. The texture's embedded stencil buffer contains the real
709 * stencil data, so copy that into the miptree.
711 intel_tex_image_s8z24_gather(intel
, intelImage
);
715 _mesa_get_compressed_teximage(ctx
, target
, level
, pixels
,
719 _mesa_get_teximage(ctx
, target
, level
, format
, type
, pixels
,
725 if (intelImage
->mt
) {
726 intel_miptree_image_unmap(intel
, intelImage
->mt
);
727 intelImage
->base
.Data
= NULL
;
733 intelGetTexImage(struct gl_context
* ctx
, GLenum target
, GLint level
,
734 GLenum format
, GLenum type
, GLvoid
* pixels
,
735 struct gl_texture_object
*texObj
,
736 struct gl_texture_image
*texImage
)
738 intel_get_tex_image(ctx
, target
, level
, format
, type
, pixels
,
739 texObj
, texImage
, GL_FALSE
);
744 intelGetCompressedTexImage(struct gl_context
*ctx
, GLenum target
, GLint level
,
746 struct gl_texture_object
*texObj
,
747 struct gl_texture_image
*texImage
)
749 intel_get_tex_image(ctx
, target
, level
, 0, 0, pixels
,
750 texObj
, texImage
, GL_TRUE
);
754 intelSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
755 GLint texture_format
,
756 __DRIdrawable
*dPriv
)
758 struct gl_framebuffer
*fb
= dPriv
->driverPrivate
;
759 struct intel_context
*intel
= pDRICtx
->driverPrivate
;
760 struct gl_context
*ctx
= &intel
->ctx
;
761 struct intel_texture_object
*intelObj
;
762 struct intel_texture_image
*intelImage
;
763 struct intel_mipmap_tree
*mt
;
764 struct intel_renderbuffer
*rb
;
765 struct gl_texture_object
*texObj
;
766 struct gl_texture_image
*texImage
;
767 int level
= 0, internalFormat
;
770 texObj
= _mesa_get_current_tex_object(ctx
, target
);
771 intelObj
= intel_texture_object(texObj
);
776 if (dPriv
->lastStamp
!= dPriv
->dri2
.stamp
||
777 !pDRICtx
->driScreenPriv
->dri2
.useInvalidate
)
778 intel_update_renderbuffers(pDRICtx
, dPriv
);
780 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
781 /* If the region isn't set, then intel_update_renderbuffers was unable
782 * to get the buffers for the drawable.
784 if (rb
->region
== NULL
)
787 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
) {
788 internalFormat
= GL_RGB
;
789 texFormat
= MESA_FORMAT_XRGB8888
;
792 internalFormat
= GL_RGBA
;
793 texFormat
= MESA_FORMAT_ARGB8888
;
796 mt
= intel_miptree_create_for_region(intel
, target
, texFormat
,
801 _mesa_lock_texture(&intel
->ctx
, texObj
);
803 texImage
= _mesa_get_tex_image(&intel
->ctx
, texObj
, target
, level
);
804 intelImage
= intel_texture_image(texImage
);
806 if (intelImage
->mt
) {
807 intel_miptree_release(intel
, &intelImage
->mt
);
808 assert(!texImage
->Data
);
811 intel_miptree_release(intel
, &intelObj
->mt
);
815 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
816 rb
->region
->width
, rb
->region
->height
, 1,
817 0, internalFormat
, texFormat
);
819 intelImage
->face
= _mesa_tex_target_to_face(target
);
820 intelImage
->level
= level
;
821 texImage
->RowStride
= rb
->region
->pitch
;
822 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
824 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
825 fprintf(stderr
, "miptree doesn't match image\n");
828 _mesa_unlock_texture(&intel
->ctx
, texObj
);
832 intelSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
, __DRIdrawable
*dPriv
)
834 /* The old interface didn't have the format argument, so copy our
835 * implementation's behavior at the time.
837 intelSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
840 #if FEATURE_OES_EGL_image
842 intel_image_target_texture_2d(struct gl_context
*ctx
, GLenum target
,
843 struct gl_texture_object
*texObj
,
844 struct gl_texture_image
*texImage
,
845 GLeglImageOES image_handle
)
847 struct intel_context
*intel
= intel_context(ctx
);
848 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
849 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
850 struct intel_mipmap_tree
*mt
;
854 screen
= intel
->intelScreen
->driScrnPriv
;
855 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
856 screen
->loaderPrivate
);
860 mt
= intel_miptree_create_for_region(intel
, target
, image
->format
,
865 if (intelImage
->mt
) {
866 intel_miptree_release(intel
, &intelImage
->mt
);
867 assert(!texImage
->Data
);
870 intel_miptree_release(intel
, &intelObj
->mt
);
873 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
874 image
->region
->width
, image
->region
->height
, 1,
875 0, image
->internal_format
, image
->format
);
877 intelImage
->face
= _mesa_tex_target_to_face(target
);
878 intelImage
->level
= 0;
879 texImage
->RowStride
= image
->region
->pitch
;
880 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
882 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
))
883 fprintf(stderr
, "miptree doesn't match image\n");
888 intelInitTextureImageFuncs(struct dd_function_table
*functions
)
890 functions
->TexImage1D
= intelTexImage1D
;
891 functions
->TexImage2D
= intelTexImage2D
;
892 functions
->TexImage3D
= intelTexImage3D
;
893 functions
->GetTexImage
= intelGetTexImage
;
895 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
896 functions
->GetCompressedTexImage
= intelGetCompressedTexImage
;
898 #if FEATURE_OES_EGL_image
899 functions
->EGLImageTargetTexture2D
= intel_image_target_texture_2d
;