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 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
->base
.Level
,
190 intelImage
->base
.Face
, 0,
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
->base
.Level
,
247 intelImage
->base
.Face
, 0,
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 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
414 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
416 if (!intelImage
->mt
) {
417 assert(texImage
->RowStride
== width
);
421 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
422 assert(!intelImage
->mt
);
425 intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
426 /* Use an existing miptree when possible */
427 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
428 assert(intelImage
->mt
);
429 } else if (intelImage
->base
.Border
== 0) {
430 /* Didn't fit in the object miptree, but it's suitable for inclusion in
431 * a miptree, so create one just for our level and store it in the image.
432 * It'll get moved into the object miptree at validate time.
434 intelImage
->mt
= intel_miptree_create_for_teximage(intel
, intelObj
,
438 /* Even if the object currently has a mipmap tree associated
439 * with it, this one is a more likely candidate to represent the
440 * whole object since our level didn't fit what was there
441 * before, and any lower levels would fit into our miptree.
443 if (intelImage
->mt
) {
444 intel_miptree_release(intel
, &intelObj
->mt
);
445 intel_miptree_reference(&intelObj
->mt
, intelImage
->mt
);
453 _mesa_is_bufferobj(unpack
->BufferObj
) &&
454 check_pbo_format(internalFormat
, format
,
455 type
, intelImage
->base
.TexFormat
)) {
457 DBG("trying pbo upload\n");
459 /* Attempt to texture directly from PBO data (zero copy upload).
461 * Currently disable as it can lead to worse as well as better
462 * performance (in particular when intel_region_cow() is
465 if (intelObj
->mt
== intelImage
->mt
&&
466 intelObj
->mt
->first_level
== level
&&
467 intelObj
->mt
->last_level
== level
) {
469 if (try_pbo_zcopy(intel
, intelImage
, unpack
,
471 width
, height
, format
, type
, pixels
)) {
473 DBG("pbo zcopy upload succeeded\n");
479 /* Otherwise, attempt to use the blitter for PBO image uploads.
481 if (try_pbo_upload(intel
, intelImage
, unpack
,
483 width
, height
, format
, type
, pixels
)) {
484 DBG("pbo upload succeeded\n");
488 DBG("pbo upload failed\n");
491 /* intelCopyTexImage calls this function with pixels == NULL, with
492 * the expectation that the mipmap tree will be set up but nothing
493 * more will be done. This is where those calls return:
496 pixels
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, pixels
,
498 "glCompressedTexImage");
500 pixels
= _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, 1,
502 pixels
, unpack
, "glTexImage");
505 if (intelImage
->mt
) {
506 if (pixels
!= NULL
) {
507 /* Flush any queued rendering with the texture before mapping. */
508 if (drm_intel_bo_references(intel
->batch
.bo
,
509 intelImage
->mt
->region
->buffer
)) {
512 texImage
->Data
= intel_miptree_image_map(intel
,
514 intelImage
->base
.Face
,
515 intelImage
->base
.Level
,
517 intelImage
->base
.ImageOffsets
);
520 texImage
->RowStride
= dstRowStride
/ intelImage
->mt
->cpp
;
523 /* Allocate regular memory and store the image there temporarily. */
524 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
525 sizeInBytes
= _mesa_format_image_size(texImage
->TexFormat
,
530 _mesa_format_row_stride(texImage
->TexFormat
, width
);
534 dstRowStride
= width
* texelBytes
;
535 sizeInBytes
= depth
* dstRowStride
* height
;
538 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
541 DBG("Upload image %dx%dx%d row_len %d "
542 "pitch %d pixels %d compressed %d\n",
543 width
, height
, depth
, width
* texelBytes
, dstRowStride
,
544 pixels
? 1 : 0, compressed
);
546 /* Copy data. Would like to know when it's ok for us to eg. use
547 * the blitter to copy. Or, use the hardware to do the format
548 * conversion and copy:
552 if (intelImage
->mt
) {
553 struct intel_region
*dst
= intelImage
->mt
->region
;
554 _mesa_copy_rect(texImage
->Data
, dst
->cpp
, dst
->pitch
,
556 intelImage
->mt
->level
[level
].width
,
557 (intelImage
->mt
->level
[level
].height
+3)/4,
563 memcpy(texImage
->Data
, pixels
, imageSize
);
566 else if (!_mesa_texstore(ctx
, dims
,
567 texImage
->_BaseFormat
,
569 texImage
->Data
, 0, 0, 0, /* dstX/Y/Zoffset */
571 texImage
->ImageOffsets
,
572 width
, height
, depth
,
573 format
, type
, pixels
, unpack
)) {
574 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage");
578 _mesa_unmap_teximage_pbo(ctx
, unpack
);
580 if (intel
->must_use_separate_stencil
581 && texImage
->TexFormat
== MESA_FORMAT_S8_Z24
) {
582 intel_tex_image_s8z24_create_renderbuffers(intel
, intelImage
);
583 intel_tex_image_s8z24_scatter(intel
, intelImage
);
586 if (intelImage
->mt
) {
588 intel_miptree_image_unmap(intel
, intelImage
->mt
);
589 texImage
->Data
= NULL
;
595 intelTexImage3D(struct gl_context
* ctx
,
596 GLenum target
, GLint level
,
597 GLint internalFormat
,
598 GLint width
, GLint height
, GLint depth
,
600 GLenum format
, GLenum type
, const void *pixels
,
601 const struct gl_pixelstore_attrib
*unpack
,
602 struct gl_texture_object
*texObj
,
603 struct gl_texture_image
*texImage
)
605 intelTexImage(ctx
, 3, target
, level
,
606 internalFormat
, width
, height
, depth
, border
,
607 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
612 intelTexImage2D(struct gl_context
* ctx
,
613 GLenum target
, GLint level
,
614 GLint internalFormat
,
615 GLint width
, GLint height
, GLint border
,
616 GLenum format
, GLenum type
, const void *pixels
,
617 const struct gl_pixelstore_attrib
*unpack
,
618 struct gl_texture_object
*texObj
,
619 struct gl_texture_image
*texImage
)
621 intelTexImage(ctx
, 2, target
, level
,
622 internalFormat
, width
, height
, 1, border
,
623 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
628 intelTexImage1D(struct gl_context
* ctx
,
629 GLenum target
, GLint level
,
630 GLint internalFormat
,
631 GLint width
, GLint border
,
632 GLenum format
, GLenum type
, const void *pixels
,
633 const struct gl_pixelstore_attrib
*unpack
,
634 struct gl_texture_object
*texObj
,
635 struct gl_texture_image
*texImage
)
637 intelTexImage(ctx
, 1, target
, level
,
638 internalFormat
, width
, 1, 1, border
,
639 format
, type
, pixels
, unpack
, texObj
, texImage
, 0, GL_FALSE
);
644 intelCompressedTexImage2D( struct gl_context
*ctx
, GLenum target
, GLint level
,
645 GLint internalFormat
,
646 GLint width
, GLint height
, GLint border
,
647 GLsizei imageSize
, const GLvoid
*data
,
648 struct gl_texture_object
*texObj
,
649 struct gl_texture_image
*texImage
)
651 intelTexImage(ctx
, 2, target
, level
,
652 internalFormat
, width
, height
, 1, border
,
653 0, 0, data
, &ctx
->Unpack
, texObj
, texImage
, imageSize
, GL_TRUE
);
658 * Need to map texture image into memory before copying image data,
662 intel_get_tex_image(struct gl_context
* ctx
, GLenum target
, GLint level
,
663 GLenum format
, GLenum type
, GLvoid
* pixels
,
664 struct gl_texture_object
*texObj
,
665 struct gl_texture_image
*texImage
, GLboolean compressed
)
667 struct intel_context
*intel
= intel_context(ctx
);
668 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
670 /* If we're reading from a texture that has been rendered to, need to
671 * make sure rendering is complete.
672 * We could probably predicate this on texObj->_RenderToTexture
677 if (intelImage
->mt
) {
678 /* Image is stored in hardware format in a buffer managed by the
679 * kernel. Need to explicitly map and unmap it.
681 intelImage
->base
.Data
=
682 intel_miptree_image_map(intel
,
684 intelImage
->base
.Face
,
685 intelImage
->base
.Level
,
686 &intelImage
->base
.RowStride
,
687 intelImage
->base
.ImageOffsets
);
688 intelImage
->base
.RowStride
/= intelImage
->mt
->cpp
;
691 /* Otherwise, the image should actually be stored in
692 * intelImage->base.Data. This is pretty confusing for
693 * everybody, I'd much prefer to separate the two functions of
694 * texImage->Data - storage for texture images in main memory
695 * and access (ie mappings) of images. In other words, we'd
696 * create a new texImage->Map field and leave Data simply for
699 assert(intelImage
->base
.Data
);
702 if (intelImage
->stencil_rb
) {
704 * The texture has packed depth/stencil format, but uses separate
705 * stencil. The texture's embedded stencil buffer contains the real
706 * stencil data, so copy that into the miptree.
708 intel_tex_image_s8z24_gather(intel
, intelImage
);
712 _mesa_get_compressed_teximage(ctx
, target
, level
, pixels
,
716 _mesa_get_teximage(ctx
, target
, level
, format
, type
, pixels
,
722 if (intelImage
->mt
) {
723 intel_miptree_image_unmap(intel
, intelImage
->mt
);
724 intelImage
->base
.Data
= NULL
;
730 intelGetTexImage(struct gl_context
* ctx
, GLenum target
, GLint level
,
731 GLenum format
, GLenum type
, GLvoid
* pixels
,
732 struct gl_texture_object
*texObj
,
733 struct gl_texture_image
*texImage
)
735 intel_get_tex_image(ctx
, target
, level
, format
, type
, pixels
,
736 texObj
, texImage
, GL_FALSE
);
741 intelGetCompressedTexImage(struct gl_context
*ctx
, GLenum target
, GLint level
,
743 struct gl_texture_object
*texObj
,
744 struct gl_texture_image
*texImage
)
746 intel_get_tex_image(ctx
, target
, level
, 0, 0, pixels
,
747 texObj
, texImage
, GL_TRUE
);
751 intelSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
752 GLint texture_format
,
753 __DRIdrawable
*dPriv
)
755 struct gl_framebuffer
*fb
= dPriv
->driverPrivate
;
756 struct intel_context
*intel
= pDRICtx
->driverPrivate
;
757 struct gl_context
*ctx
= &intel
->ctx
;
758 struct intel_texture_object
*intelObj
;
759 struct intel_texture_image
*intelImage
;
760 struct intel_mipmap_tree
*mt
;
761 struct intel_renderbuffer
*rb
;
762 struct gl_texture_object
*texObj
;
763 struct gl_texture_image
*texImage
;
764 int level
= 0, internalFormat
;
767 texObj
= _mesa_get_current_tex_object(ctx
, target
);
768 intelObj
= intel_texture_object(texObj
);
773 if (dPriv
->lastStamp
!= dPriv
->dri2
.stamp
||
774 !pDRICtx
->driScreenPriv
->dri2
.useInvalidate
)
775 intel_update_renderbuffers(pDRICtx
, dPriv
);
777 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
778 /* If the region isn't set, then intel_update_renderbuffers was unable
779 * to get the buffers for the drawable.
781 if (rb
->region
== NULL
)
784 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
) {
785 internalFormat
= GL_RGB
;
786 texFormat
= MESA_FORMAT_XRGB8888
;
789 internalFormat
= GL_RGBA
;
790 texFormat
= MESA_FORMAT_ARGB8888
;
793 mt
= intel_miptree_create_for_region(intel
, target
, texFormat
,
798 _mesa_lock_texture(&intel
->ctx
, texObj
);
800 texImage
= _mesa_get_tex_image(&intel
->ctx
, texObj
, target
, level
);
801 intelImage
= intel_texture_image(texImage
);
803 if (intelImage
->mt
) {
804 intel_miptree_release(intel
, &intelImage
->mt
);
805 assert(!texImage
->Data
);
808 intel_miptree_release(intel
, &intelObj
->mt
);
812 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
813 rb
->region
->width
, rb
->region
->height
, 1,
814 0, internalFormat
, texFormat
);
816 texImage
->RowStride
= rb
->region
->pitch
;
817 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
819 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
)) {
820 fprintf(stderr
, "miptree doesn't match image\n");
823 _mesa_unlock_texture(&intel
->ctx
, texObj
);
827 intelSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
, __DRIdrawable
*dPriv
)
829 /* The old interface didn't have the format argument, so copy our
830 * implementation's behavior at the time.
832 intelSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
835 #if FEATURE_OES_EGL_image
837 intel_image_target_texture_2d(struct gl_context
*ctx
, GLenum target
,
838 struct gl_texture_object
*texObj
,
839 struct gl_texture_image
*texImage
,
840 GLeglImageOES image_handle
)
842 struct intel_context
*intel
= intel_context(ctx
);
843 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
844 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
845 struct intel_mipmap_tree
*mt
;
849 screen
= intel
->intelScreen
->driScrnPriv
;
850 image
= screen
->dri2
.image
->lookupEGLImage(screen
, image_handle
,
851 screen
->loaderPrivate
);
855 mt
= intel_miptree_create_for_region(intel
, target
, image
->format
,
860 if (intelImage
->mt
) {
861 intel_miptree_release(intel
, &intelImage
->mt
);
862 assert(!texImage
->Data
);
865 intel_miptree_release(intel
, &intelObj
->mt
);
868 _mesa_init_teximage_fields(&intel
->ctx
, target
, texImage
,
869 image
->region
->width
, image
->region
->height
, 1,
870 0, image
->internal_format
, image
->format
);
872 texImage
->RowStride
= image
->region
->pitch
;
873 intel_miptree_reference(&intelImage
->mt
, intelObj
->mt
);
875 if (!intel_miptree_match_image(intelObj
->mt
, &intelImage
->base
))
876 fprintf(stderr
, "miptree doesn't match image\n");
881 intelInitTextureImageFuncs(struct dd_function_table
*functions
)
883 functions
->TexImage1D
= intelTexImage1D
;
884 functions
->TexImage2D
= intelTexImage2D
;
885 functions
->TexImage3D
= intelTexImage3D
;
886 functions
->GetTexImage
= intelGetTexImage
;
888 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
889 functions
->GetCompressedTexImage
= intelGetCompressedTexImage
;
891 #if FEATURE_OES_EGL_image
892 functions
->EGLImageTargetTexture2D
= intel_image_target_texture_2d
;