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
->base
.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
->base
.Level
;
78 lastLevel
= intelImage
->base
.Level
;
80 /* If this image disrespects BaseLevel, allocate from level zero.
81 * Usually BaseLevel == 0, so it's unlikely to happen.
83 if (intelImage
->base
.Level
< intelObj
->base
.BaseLevel
)
86 firstLevel
= intelObj
->base
.BaseLevel
;
88 /* Figure out image dimensions at start level. */
89 for (i
= intelImage
->base
.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
->base
.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 width
, GLint height
, const void *pixels
)
165 struct intel_buffer_object
*pbo
= intel_buffer_object(unpack
->BufferObj
);
166 GLuint src_offset
, src_stride
;
167 GLuint dst_x
, dst_y
, dst_stride
;
168 drm_intel_bo
*dst_buffer
= intel_region_buffer(intel
,
169 intelImage
->mt
->region
,
172 if (!_mesa_is_bufferobj(unpack
->BufferObj
) ||
173 intel
->ctx
._ImageTransferState
||
174 unpack
->SkipPixels
|| unpack
->SkipRows
) {
175 DBG("%s: failure 1\n", __FUNCTION__
);
179 /* note: potential 64-bit ptr to 32-bit int cast */
180 src_offset
= (GLuint
) (unsigned long) pixels
;
182 if (unpack
->RowLength
> 0)
183 src_stride
= unpack
->RowLength
;
187 intel_miptree_get_image_offset(intelImage
->mt
, intelImage
->base
.Level
,
188 intelImage
->base
.Face
, 0,
191 dst_stride
= intelImage
->mt
->region
->pitch
;
193 if (drm_intel_bo_references(intel
->batch
.bo
, dst_buffer
))
194 intel_flush(&intel
->ctx
);
198 drm_intel_bo
*src_buffer
=
199 intel_bufferobj_source(intel
, pbo
, 64, &offset
);
201 if (!intelEmitCopyBlit(intel
,
203 src_stride
, src_buffer
,
204 src_offset
+ offset
, GL_FALSE
,
205 dst_stride
, dst_buffer
, 0,
206 intelImage
->mt
->region
->tiling
,
207 0, 0, dst_x
, dst_y
, width
, height
,
218 try_pbo_zcopy(struct intel_context
*intel
,
219 struct intel_texture_image
*intelImage
,
220 const struct gl_pixelstore_attrib
*unpack
,
221 GLint width
, const void *pixels
)
223 struct intel_buffer_object
*pbo
= intel_buffer_object(unpack
->BufferObj
);
224 GLuint src_offset
, src_stride
;
225 GLuint dst_x
, dst_y
, dst_stride
;
227 if (!_mesa_is_bufferobj(unpack
->BufferObj
) ||
228 intel
->ctx
._ImageTransferState
||
229 unpack
->SkipPixels
|| unpack
->SkipRows
) {
230 DBG("%s: failure 1\n", __FUNCTION__
);
234 /* note: potential 64-bit ptr to 32-bit int cast */
235 src_offset
= (GLuint
) (unsigned long) pixels
;
237 if (unpack
->RowLength
> 0)
238 src_stride
= unpack
->RowLength
;
242 intel_miptree_get_image_offset(intelImage
->mt
, intelImage
->base
.Level
,
243 intelImage
->base
.Face
, 0,
246 dst_stride
= intelImage
->mt
->region
->pitch
;
248 if (src_stride
!= dst_stride
|| dst_x
!= 0 || dst_y
!= 0 ||
250 DBG("%s: failure 2\n", __FUNCTION__
);
254 intel_region_attach_pbo(intel
, intelImage
->mt
->region
, pbo
);
260 * \param scatter Scatter if true. Gather if false.
262 * \see intel_tex_image_x8z24_scatter
263 * \see intel_tex_image_x8z24_gather
266 intel_tex_image_s8z24_scattergather(struct intel_context
*intel
,
267 struct intel_texture_image
*intel_image
,
270 struct gl_context
*ctx
= &intel
->ctx
;
271 struct gl_renderbuffer
*depth_rb
= intel_image
->depth_rb
;
272 struct gl_renderbuffer
*stencil_rb
= intel_image
->stencil_rb
;
274 int w
= intel_image
->base
.Width
;
275 int h
= intel_image
->base
.Height
;
277 uint32_t depth_row
[w
];
278 uint8_t stencil_row
[w
];
280 intel_renderbuffer_map(intel
, depth_rb
);
281 intel_renderbuffer_map(intel
, stencil_rb
);
284 for (int y
= 0; y
< h
; ++y
) {
285 depth_rb
->GetRow(ctx
, depth_rb
, w
, 0, y
, depth_row
);
286 for (int x
= 0; x
< w
; ++x
) {
287 stencil_row
[x
] = depth_row
[x
] >> 24;
289 stencil_rb
->PutRow(ctx
, stencil_rb
, w
, 0, y
, stencil_row
, NULL
);
291 } else { /* gather */
292 for (int y
= 0; y
< h
; ++y
) {
293 depth_rb
->GetRow(ctx
, depth_rb
, w
, 0, y
, depth_row
);
294 stencil_rb
->GetRow(ctx
, stencil_rb
, w
, 0, y
, stencil_row
);
295 for (int x
= 0; x
< w
; ++x
) {
296 uint32_t s8_x24
= stencil_row
[x
] << 24;
297 uint32_t x8_z24
= depth_row
[x
] & 0x00ffffff;
298 depth_row
[x
] = s8_x24
| x8_z24
;
300 depth_rb
->PutRow(ctx
, depth_rb
, w
, 0, y
, depth_row
, NULL
);
304 intel_renderbuffer_unmap(intel
, depth_rb
);
305 intel_renderbuffer_unmap(intel
, stencil_rb
);
309 * Copy the x8 bits from intel_image->depth_rb to intel_image->stencil_rb.
312 intel_tex_image_s8z24_scatter(struct intel_context
*intel
,
313 struct intel_texture_image
*intel_image
)
315 intel_tex_image_s8z24_scattergather(intel
, intel_image
, true);
319 * Copy the data in intel_image->stencil_rb to the x8 bits in
320 * intel_image->depth_rb.
323 intel_tex_image_s8z24_gather(struct intel_context
*intel
,
324 struct intel_texture_image
*intel_image
)
326 intel_tex_image_s8z24_scattergather(intel
, intel_image
, false);
330 intel_tex_image_s8z24_create_renderbuffers(struct intel_context
*intel
,
331 struct intel_texture_image
*image
)
333 struct gl_context
*ctx
= &intel
->ctx
;
336 int width
= image
->base
.Width
;
337 int height
= image
->base
.Height
;
338 struct gl_renderbuffer
*drb
;
339 struct gl_renderbuffer
*srb
;
340 struct intel_renderbuffer
*idrb
;
341 struct intel_renderbuffer
*isrb
;
343 assert(intel
->has_separate_stencil
);
344 assert(image
->base
.TexFormat
== MESA_FORMAT_S8_Z24
);
345 assert(image
->mt
!= NULL
);
347 drb
= intel_create_wrapped_renderbuffer(ctx
, width
, height
,
349 srb
= intel_create_wrapped_renderbuffer(ctx
, width
, height
,
362 idrb
= intel_renderbuffer(drb
);
363 isrb
= intel_renderbuffer(srb
);
365 intel_region_reference(&idrb
->region
, image
->mt
->region
);
366 ok
= intel_alloc_renderbuffer_storage(ctx
, srb
, GL_STENCIL_INDEX8
,
375 intel_renderbuffer_set_draw_offset(idrb
, image
, 0);
376 intel_renderbuffer_set_draw_offset(isrb
, image
, 0);
378 _mesa_reference_renderbuffer(&image
->depth_rb
, drb
);
379 _mesa_reference_renderbuffer(&image
->stencil_rb
, srb
);
385 intelTexImage(struct gl_context
* ctx
,
387 GLenum target
, GLint level
,
388 GLint internalFormat
,
389 GLint width
, GLint height
, GLint depth
,
391 GLenum format
, GLenum type
, const void *pixels
,
392 const struct gl_pixelstore_attrib
*unpack
,
393 struct gl_texture_object
*texObj
,
394 struct gl_texture_image
*texImage
, GLsizei imageSize
,
395 GLboolean compressed
)
397 struct intel_context
*intel
= intel_context(ctx
);
398 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
399 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
400 GLint texelBytes
, sizeInBytes
;
401 GLuint dstRowStride
= 0, srcRowStride
= texImage
->RowStride
;
403 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__
,
404 _mesa_lookup_enum_by_nr(target
), level
, width
, height
, depth
, border
);
406 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
410 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
412 if (!intelImage
->mt
) {
413 assert(texImage
->RowStride
== width
);
417 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
418 assert(!intelImage
->mt
);
421 intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
422 /* Use an existing miptree when possible */
423 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
424 assert(intelImage
->mt
);
425 } else if (intelImage
->base
.Border
== 0) {
426 /* Didn't fit in the object miptree, but it's suitable for inclusion in
427 * a miptree, so create one just for our level and store it in the image.
428 * It'll get moved into the object miptree at validate time.
430 intelImage
->mt
= intel_miptree_create_for_teximage(intel
, intelObj
,
434 /* Even if the object currently has a mipmap tree associated
435 * with it, this one is a more likely candidate to represent the
436 * whole object since our level didn't fit what was there
437 * before, and any lower levels would fit into our miptree.
439 if (intelImage
->mt
) {
440 intel_miptree_release(intel
, &intelObj
->mt
);
441 intel_miptree_reference(&intelObj
->mt
, intelImage
->mt
);
449 _mesa_is_bufferobj(unpack
->BufferObj
) &&
450 check_pbo_format(internalFormat
, format
,
451 type
, intelImage
->base
.TexFormat
)) {
453 DBG("trying pbo upload\n");
455 /* Attempt to texture directly from PBO data (zero copy upload).
457 * Currently disable as it can lead to worse as well as better
458 * performance (in particular when intel_region_cow() is
461 if (intelObj
->mt
== intelImage
->mt
&&
462 intelObj
->mt
->first_level
== level
&&
463 intelObj
->mt
->last_level
== level
) {
465 if (try_pbo_zcopy(intel
, intelImage
, unpack
, width
, pixels
)) {
466 DBG("pbo zcopy upload succeeded\n");
472 /* Otherwise, attempt to use the blitter for PBO image uploads.
474 if (try_pbo_upload(intel
, intelImage
, unpack
, width
, height
, pixels
)) {
475 DBG("pbo upload succeeded\n");
479 DBG("pbo upload failed\n");
482 /* intelCopyTexImage calls this function with pixels == NULL, with
483 * the expectation that the mipmap tree will be set up but nothing
484 * more will be done. This is where those calls return:
487 pixels
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, pixels
,
489 "glCompressedTexImage");
491 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
493 pixels
, unpack
, "glTexImage");
496 if (intelImage
->mt
) {
497 if (pixels
!= NULL
) {
498 /* Flush any queued rendering with the texture before mapping. */
499 if (drm_intel_bo_references(intel
->batch
.bo
,
500 intelImage
->mt
->region
->buffer
)) {
503 texImage
->Data
= intel_miptree_image_map(intel
,
505 intelImage
->base
.Face
,
506 intelImage
->base
.Level
,
508 intelImage
->base
.ImageOffsets
);
511 texImage
->RowStride
= dstRowStride
/ intelImage
->mt
->cpp
;
514 /* Allocate regular memory and store the image there temporarily. */
515 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
516 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
521 _mesa_format_row_stride(texImage
->TexFormat
, width
);
525 dstRowStride
= width
* texelBytes
;
526 sizeInBytes
= depth
* dstRowStride
* height
;
529 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
532 DBG("Upload image %dx%dx%d row_len %d "
533 "pitch %d pixels %d compressed %d\n",
534 width
, height
, depth
, width
* texelBytes
, dstRowStride
,
535 pixels
? 1 : 0, compressed
);
537 /* Copy data. Would like to know when it's ok for us to eg. use
538 * the blitter to copy. Or, use the hardware to do the format
539 * conversion and copy:
543 if (intelImage
->mt
) {
544 struct intel_region
*dst
= intelImage
->mt
->region
;
545 _mesa_copy_rect(texImage
->Data
, dst
->cpp
, dst
->pitch
,
547 intelImage
->mt
->level
[level
].width
,
548 (intelImage
->mt
->level
[level
].height
+3)/4,
554 memcpy(texImage
->Data
, pixels
, imageSize
);
557 else if (!_mesa_texstore(ctx
, dims
,
558 texImage
->_BaseFormat
,
560 texImage
->Data
, 0, 0, 0, /* dstX/Y/Zoffset */
562 texImage
->ImageOffsets
,
563 width
, height
, depth
,
564 format
, type
, pixels
, unpack
)) {
565 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
569 _mesa_unmap_teximage_pbo(ctx
, unpack
);
571 if (intel
->must_use_separate_stencil
572 && texImage
->TexFormat
== MESA_FORMAT_S8_Z24
) {
573 intel_tex_image_s8z24_create_renderbuffers(intel
, intelImage
);
574 intel_tex_image_s8z24_scatter(intel
, intelImage
);
577 if (intelImage
->mt
) {
579 intel_miptree_image_unmap(intel
, intelImage
->mt
);
580 texImage
->Data
= NULL
;
586 intelTexImage3D(struct gl_context
* ctx
,
587 GLenum target
, GLint level
,
588 GLint internalFormat
,
589 GLint width
, GLint height
, GLint depth
,
591 GLenum format
, GLenum type
, const void *pixels
,
592 const struct gl_pixelstore_attrib
*unpack
,
593 struct gl_texture_object
*texObj
,
594 struct gl_texture_image
*texImage
)
596 intelTexImage(ctx
, 3, target
, level
,
597 internalFormat
, width
, height
, depth
, border
,
598 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
603 intelTexImage2D(struct gl_context
* ctx
,
604 GLenum target
, GLint level
,
605 GLint internalFormat
,
606 GLint width
, GLint height
, GLint border
,
607 GLenum format
, GLenum type
, const void *pixels
,
608 const struct gl_pixelstore_attrib
*unpack
,
609 struct gl_texture_object
*texObj
,
610 struct gl_texture_image
*texImage
)
612 intelTexImage(ctx
, 2, target
, level
,
613 internalFormat
, width
, height
, 1, border
,
614 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
619 intelTexImage1D(struct gl_context
* ctx
,
620 GLenum target
, GLint level
,
621 GLint internalFormat
,
622 GLint width
, GLint border
,
623 GLenum format
, GLenum type
, const void *pixels
,
624 const struct gl_pixelstore_attrib
*unpack
,
625 struct gl_texture_object
*texObj
,
626 struct gl_texture_image
*texImage
)
628 intelTexImage(ctx
, 1, target
, level
,
629 internalFormat
, width
, 1, 1, border
,
630 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
635 intelCompressedTexImage2D( struct gl_context
*ctx
, GLenum target
, GLint level
,
636 GLint internalFormat
,
637 GLint width
, GLint height
, GLint border
,
638 GLsizei imageSize
, const GLvoid
*data
,
639 struct gl_texture_object
*texObj
,
640 struct gl_texture_image
*texImage
)
642 intelTexImage(ctx
, 2, target
, level
,
643 internalFormat
, width
, height
, 1, border
,
644 0, 0, data
, &ctx
->Unpack
, texObj
, texImage
, imageSize
, GL_TRUE
);
649 * Need to map texture image into memory before copying image data,
653 intel_get_tex_image(struct gl_context
* ctx
, GLenum target
, GLint level
,
654 GLenum format
, GLenum type
, GLvoid
* pixels
,
655 struct gl_texture_object
*texObj
,
656 struct gl_texture_image
*texImage
, GLboolean compressed
)
658 struct intel_context
*intel
= intel_context(ctx
);
659 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
661 /* If we're reading from a texture that has been rendered to, need to
662 * make sure rendering is complete.
663 * We could probably predicate this on texObj->_RenderToTexture
668 if (intelImage
->mt
) {
669 /* Image is stored in hardware format in a buffer managed by the
670 * kernel. Need to explicitly map and unmap it.
672 intelImage
->base
.Data
=
673 intel_miptree_image_map(intel
,
675 intelImage
->base
.Face
,
676 intelImage
->base
.Level
,
677 &intelImage
->base
.RowStride
,
678 intelImage
->base
.ImageOffsets
);
679 intelImage
->base
.RowStride
/= intelImage
->mt
->cpp
;
682 /* Otherwise, the image should actually be stored in
683 * intelImage->base.Data. This is pretty confusing for
684 * everybody, I'd much prefer to separate the two functions of
685 * texImage->Data - storage for texture images in main memory
686 * and access (ie mappings) of images. In other words, we'd
687 * create a new texImage->Map field and leave Data simply for
690 assert(intelImage
->base
.Data
);
693 if (intelImage
->stencil_rb
) {
695 * The texture has packed depth/stencil format, but uses separate
696 * stencil. The texture's embedded stencil buffer contains the real
697 * stencil data, so copy that into the miptree.
699 intel_tex_image_s8z24_gather(intel
, intelImage
);
703 _mesa_get_compressed_teximage(ctx
, target
, level
, pixels
,
707 _mesa_get_teximage(ctx
, target
, level
, format
, type
, pixels
,
713 if (intelImage
->mt
) {
714 intel_miptree_image_unmap(intel
, intelImage
->mt
);
715 intelImage
->base
.Data
= NULL
;
721 intelGetTexImage(struct gl_context
* ctx
, GLenum target
, GLint level
,
722 GLenum format
, GLenum type
, GLvoid
* pixels
,
723 struct gl_texture_object
*texObj
,
724 struct gl_texture_image
*texImage
)
726 intel_get_tex_image(ctx
, target
, level
, format
, type
, pixels
,
727 texObj
, texImage
, GL_FALSE
);
732 intelGetCompressedTexImage(struct gl_context
*ctx
, GLenum target
, GLint level
,
734 struct gl_texture_object
*texObj
,
735 struct gl_texture_image
*texImage
)
737 intel_get_tex_image(ctx
, target
, level
, 0, 0, pixels
,
738 texObj
, texImage
, GL_TRUE
);
742 intelSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
743 GLint texture_format
,
744 __DRIdrawable
*dPriv
)
746 struct gl_framebuffer
*fb
= dPriv
->driverPrivate
;
747 struct intel_context
*intel
= pDRICtx
->driverPrivate
;
748 struct gl_context
*ctx
= &intel
->ctx
;
749 struct intel_texture_object
*intelObj
;
750 struct intel_texture_image
*intelImage
;
751 struct intel_mipmap_tree
*mt
;
752 struct intel_renderbuffer
*rb
;
753 struct gl_texture_object
*texObj
;
754 struct gl_texture_image
*texImage
;
755 int level
= 0, internalFormat
;
758 texObj
= _mesa_get_current_tex_object(ctx
, target
);
759 intelObj
= intel_texture_object(texObj
);
764 if (dPriv
->lastStamp
!= dPriv
->dri2
.stamp
||
765 !pDRICtx
->driScreenPriv
->dri2
.useInvalidate
)
766 intel_update_renderbuffers(pDRICtx
, dPriv
);
768 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
769 /* If the region isn't set, then intel_update_renderbuffers was unable
770 * to get the buffers for the drawable.
772 if (rb
->region
== NULL
)
775 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
) {
776 internalFormat
= GL_RGB
;
777 texFormat
= MESA_FORMAT_XRGB8888
;
780 internalFormat
= GL_RGBA
;
781 texFormat
= MESA_FORMAT_ARGB8888
;
784 mt
= intel_miptree_create_for_region(intel
, target
, texFormat
, rb
->region
);
788 _mesa_lock_texture(&intel
->ctx
, texObj
);
790 texImage
= _mesa_get_tex_image(&intel
->ctx
, texObj
, target
, level
);
791 intelImage
= intel_texture_image(texImage
);
793 if (intelImage
->mt
) {
794 intel_miptree_release(intel
, &intelImage
->mt
);
795 assert(!texImage
->Data
);
798 intel_miptree_release(intel
, &intelObj
->mt
);
802 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
803 rb
->region
->width
, rb
->region
->height
, 1,
804 0, internalFormat
, texFormat
);
806 texImage
->RowStride
= rb
->region
->pitch
;
807 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
809 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
810 fprintf(stderr
, "miptree doesn't match image\n");
813 _mesa_unlock_texture(&intel
->ctx
, texObj
);
817 intelSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
, __DRIdrawable
*dPriv
)
819 /* The old interface didn't have the format argument, so copy our
820 * implementation's behavior at the time.
822 intelSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
825 #if FEATURE_OES_EGL_image
827 intel_image_target_texture_2d(struct gl_context
*ctx
, GLenum target
,
828 struct gl_texture_object
*texObj
,
829 struct gl_texture_image
*texImage
,
830 GLeglImageOES image_handle
)
832 struct intel_context
*intel
= intel_context(ctx
);
833 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
834 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
835 struct intel_mipmap_tree
*mt
;
839 screen
= intel
->intelScreen
->driScrnPriv
;
840 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
841 screen
->loaderPrivate
);
845 mt
= intel_miptree_create_for_region(intel
, target
, image
->format
,
850 if (intelImage
->mt
) {
851 intel_miptree_release(intel
, &intelImage
->mt
);
852 assert(!texImage
->Data
);
855 intel_miptree_release(intel
, &intelObj
->mt
);
858 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
859 image
->region
->width
, image
->region
->height
, 1,
860 0, image
->internal_format
, image
->format
);
862 texImage
->RowStride
= image
->region
->pitch
;
863 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
865 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
))
866 fprintf(stderr
, "miptree doesn't match image\n");
871 intelInitTextureImageFuncs(struct dd_function_table
*functions
)
873 functions
->TexImage1D
= intelTexImage1D
;
874 functions
->TexImage2D
= intelTexImage2D
;
875 functions
->TexImage3D
= intelTexImage3D
;
876 functions
->GetTexImage
= intelGetTexImage
;
878 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
879 functions
->GetCompressedTexImage
= intelGetCompressedTexImage
;
881 #if FEATURE_OES_EGL_image
882 functions
->EGLImageTargetTexture2D
= intel_image_target_texture_2d
;