89f10284ce610b3f1e2e9d6cdfd2b9c01774df8c
[mesa.git] / src / mesa / state_tracker / st_cb_texture.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/mfeatures.h"
29 #include "main/bufferobj.h"
30 #if FEATURE_convolve
31 #include "main/convolve.h"
32 #endif
33 #include "main/enums.h"
34 #include "main/fbobject.h"
35 #include "main/formats.h"
36 #include "main/image.h"
37 #include "main/imports.h"
38 #include "main/macros.h"
39 #include "main/mipmap.h"
40 #include "main/texcompress.h"
41 #include "main/texfetch.h"
42 #include "main/texgetimage.h"
43 #include "main/teximage.h"
44 #include "main/texobj.h"
45 #include "main/texstore.h"
46
47 #include "state_tracker/st_debug.h"
48 #include "state_tracker/st_context.h"
49 #include "state_tracker/st_cb_fbo.h"
50 #include "state_tracker/st_cb_texture.h"
51 #include "state_tracker/st_format.h"
52 #include "state_tracker/st_texture.h"
53 #include "state_tracker/st_gen_mipmap.h"
54 #include "state_tracker/st_inlines.h"
55 #include "state_tracker/st_atom.h"
56
57 #include "pipe/p_context.h"
58 #include "pipe/p_defines.h"
59 #include "util/u_inlines.h"
60 #include "pipe/p_shader_tokens.h"
61 #include "util/u_tile.h"
62 #include "util/u_blit.h"
63 #include "util/u_format.h"
64 #include "util/u_surface.h"
65 #include "util/u_sampler.h"
66 #include "util/u_math.h"
67
68
69 #define DBG if (0) printf
70
71
72 static enum pipe_texture_target
73 gl_target_to_pipe(GLenum target)
74 {
75 switch (target) {
76 case GL_TEXTURE_1D:
77 return PIPE_TEXTURE_1D;
78
79 case GL_TEXTURE_2D:
80 case GL_TEXTURE_RECTANGLE_NV:
81 return PIPE_TEXTURE_2D;
82
83 case GL_TEXTURE_3D:
84 return PIPE_TEXTURE_3D;
85
86 case GL_TEXTURE_CUBE_MAP_ARB:
87 return PIPE_TEXTURE_CUBE;
88
89 default:
90 assert(0);
91 return 0;
92 }
93 }
94
95
96 /** called via ctx->Driver.NewTextureImage() */
97 static struct gl_texture_image *
98 st_NewTextureImage(GLcontext * ctx)
99 {
100 DBG("%s\n", __FUNCTION__);
101 (void) ctx;
102 return (struct gl_texture_image *) ST_CALLOC_STRUCT(st_texture_image);
103 }
104
105
106 /** called via ctx->Driver.NewTextureObject() */
107 static struct gl_texture_object *
108 st_NewTextureObject(GLcontext * ctx, GLuint name, GLenum target)
109 {
110 struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
111
112 DBG("%s\n", __FUNCTION__);
113 _mesa_initialize_texture_object(&obj->base, name, target);
114
115 return &obj->base;
116 }
117
118 /** called via ctx->Driver.DeleteTextureImage() */
119 static void
120 st_DeleteTextureObject(GLcontext *ctx,
121 struct gl_texture_object *texObj)
122 {
123 struct st_texture_object *stObj = st_texture_object(texObj);
124 if (stObj->pt)
125 pipe_resource_reference(&stObj->pt, NULL);
126 if (stObj->sampler_view) {
127 if (stObj->sampler_view->context != ctx->st->pipe) {
128 /* Take "ownership" of this texture sampler view by setting
129 * its context pointer to this context. This avoids potential
130 * crashes when the texture object is shared among contexts
131 * and the original/owner context has already been destroyed.
132 */
133 stObj->sampler_view->context = ctx->st->pipe;
134 }
135 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
136 }
137 _mesa_delete_texture_object(ctx, texObj);
138 }
139
140
141 /** called via ctx->Driver.FreeTexImageData() */
142 static void
143 st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
144 {
145 struct st_texture_image *stImage = st_texture_image(texImage);
146
147 DBG("%s\n", __FUNCTION__);
148
149 if (stImage->pt) {
150 pipe_resource_reference(&stImage->pt, NULL);
151 }
152
153 if (texImage->Data) {
154 _mesa_align_free(texImage->Data);
155 texImage->Data = NULL;
156 }
157 }
158
159
160 /**
161 * From linux kernel i386 header files, copes with odd sizes better
162 * than COPY_DWORDS would:
163 * XXX Put this in src/mesa/main/imports.h ???
164 */
165 #if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
166 static INLINE void *
167 __memcpy(void *to, const void *from, size_t n)
168 {
169 int d0, d1, d2;
170 __asm__ __volatile__("rep ; movsl\n\t"
171 "testb $2,%b4\n\t"
172 "je 1f\n\t"
173 "movsw\n"
174 "1:\ttestb $1,%b4\n\t"
175 "je 2f\n\t"
176 "movsb\n" "2:":"=&c"(d0), "=&D"(d1), "=&S"(d2)
177 :"0"(n / 4), "q"(n), "1"((long) to), "2"((long) from)
178 :"memory");
179 return (to);
180 }
181 #else
182 #define __memcpy(a,b,c) memcpy(a,b,c)
183 #endif
184
185
186 /**
187 * The system memcpy (at least on ubuntu 5.10) has problems copying
188 * to agp (writecombined) memory from a source which isn't 64-byte
189 * aligned - there is a 4x performance falloff.
190 *
191 * The x86 __memcpy is immune to this but is slightly slower
192 * (10%-ish) than the system memcpy.
193 *
194 * The sse_memcpy seems to have a slight cliff at 64/32 bytes, but
195 * isn't much faster than x86_memcpy for agp copies.
196 *
197 * TODO: switch dynamically.
198 */
199 static void *
200 do_memcpy(void *dest, const void *src, size_t n)
201 {
202 if ((((unsigned long) src) & 63) || (((unsigned long) dest) & 63)) {
203 return __memcpy(dest, src, n);
204 }
205 else
206 return memcpy(dest, src, n);
207 }
208
209
210 /**
211 * Return default texture usage bitmask for the given texture format.
212 */
213 static GLuint
214 default_usage(enum pipe_format fmt)
215 {
216 GLuint usage = PIPE_BIND_SAMPLER_VIEW;
217 if (util_format_is_depth_or_stencil(fmt))
218 usage |= PIPE_BIND_DEPTH_STENCIL;
219 else
220 usage |= PIPE_BIND_RENDER_TARGET;
221 return usage;
222 }
223
224
225 /**
226 * Allocate a pipe_resource object for the given st_texture_object using
227 * the given st_texture_image to guess the mipmap size/levels.
228 *
229 * [comments...]
230 * Otherwise, store it in memory if (Border != 0) or (any dimension ==
231 * 1).
232 *
233 * Otherwise, if max_level >= level >= min_level, create texture with
234 * space for images from min_level down to max_level.
235 *
236 * Otherwise, create texture with space for images from (level 0)..(1x1).
237 * Consider pruning this texture at a validation if the saving is worth it.
238 */
239 static void
240 guess_and_alloc_texture(struct st_context *st,
241 struct st_texture_object *stObj,
242 const struct st_texture_image *stImage)
243 {
244 GLuint firstLevel;
245 GLuint lastLevel;
246 GLuint width = stImage->base.Width2; /* size w/out border */
247 GLuint height = stImage->base.Height2;
248 GLuint depth = stImage->base.Depth2;
249 GLuint i, usage;
250 enum pipe_format fmt;
251
252 DBG("%s\n", __FUNCTION__);
253
254 assert(!stObj->pt);
255
256 if (stObj->pt &&
257 (GLint) stImage->level > stObj->base.BaseLevel &&
258 (stImage->base.Width == 1 ||
259 (stObj->base.Target != GL_TEXTURE_1D &&
260 stImage->base.Height == 1) ||
261 (stObj->base.Target == GL_TEXTURE_3D &&
262 stImage->base.Depth == 1)))
263 return;
264
265 /* If this image disrespects BaseLevel, allocate from level zero.
266 * Usually BaseLevel == 0, so it's unlikely to happen.
267 */
268 if ((GLint) stImage->level < stObj->base.BaseLevel)
269 firstLevel = 0;
270 else
271 firstLevel = stObj->base.BaseLevel;
272
273
274 /* Figure out image dimensions at start level.
275 */
276 for (i = stImage->level; i > firstLevel; i--) {
277 if (width != 1)
278 width <<= 1;
279 if (height != 1)
280 height <<= 1;
281 if (depth != 1)
282 depth <<= 1;
283 }
284
285 if (width == 0 || height == 0 || depth == 0) {
286 /* no texture needed */
287 return;
288 }
289
290 /* Guess a reasonable value for lastLevel. This is probably going
291 * to be wrong fairly often and might mean that we have to look at
292 * resizable buffers, or require that buffers implement lazy
293 * pagetable arrangements.
294 */
295 if ((stObj->base.MinFilter == GL_NEAREST ||
296 stObj->base.MinFilter == GL_LINEAR ||
297 stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
298 stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
299 !stObj->base.GenerateMipmap &&
300 stImage->level == firstLevel) {
301 /* only alloc space for a single mipmap level */
302 lastLevel = firstLevel;
303 }
304 else {
305 /* alloc space for a full mipmap */
306 GLuint l2width = util_logbase2(width);
307 GLuint l2height = util_logbase2(height);
308 GLuint l2depth = util_logbase2(depth);
309 lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth);
310 }
311
312 fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat);
313
314 usage = default_usage(fmt);
315
316 stObj->pt = st_texture_create(st,
317 gl_target_to_pipe(stObj->base.Target),
318 fmt,
319 lastLevel,
320 width,
321 height,
322 depth,
323 usage);
324
325 DBG("%s - success\n", __FUNCTION__);
326 }
327
328
329 /**
330 * Adjust pixel unpack params and image dimensions to strip off the
331 * texture border.
332 * Gallium doesn't support texture borders. They've seldem been used
333 * and seldom been implemented correctly anyway.
334 * \param unpackNew returns the new pixel unpack parameters
335 */
336 static void
337 strip_texture_border(GLint border,
338 GLint *width, GLint *height, GLint *depth,
339 const struct gl_pixelstore_attrib *unpack,
340 struct gl_pixelstore_attrib *unpackNew)
341 {
342 assert(border > 0); /* sanity check */
343
344 *unpackNew = *unpack;
345
346 if (unpackNew->RowLength == 0)
347 unpackNew->RowLength = *width;
348
349 if (depth && unpackNew->ImageHeight == 0)
350 unpackNew->ImageHeight = *height;
351
352 unpackNew->SkipPixels += border;
353 if (height)
354 unpackNew->SkipRows += border;
355 if (depth)
356 unpackNew->SkipImages += border;
357
358 assert(*width >= 3);
359 *width = *width - 2 * border;
360 if (height && *height >= 3)
361 *height = *height - 2 * border;
362 if (depth && *depth >= 3)
363 *depth = *depth - 2 * border;
364 }
365
366
367 /**
368 * Try to do texture compression via rendering. If the Gallium driver
369 * can render into a compressed surface this will allow us to do texture
370 * compression.
371 * \return GL_TRUE for success, GL_FALSE for failure
372 */
373 static GLboolean
374 compress_with_blit(GLcontext * ctx,
375 GLenum target, GLint level,
376 GLint xoffset, GLint yoffset, GLint zoffset,
377 GLint width, GLint height, GLint depth,
378 GLenum format, GLenum type, const void *pixels,
379 const struct gl_pixelstore_attrib *unpack,
380 struct gl_texture_image *texImage)
381 {
382 const GLuint dstImageOffsets[1] = {0};
383 struct st_texture_image *stImage = st_texture_image(texImage);
384 struct pipe_context *pipe = ctx->st->pipe;
385 struct pipe_screen *screen = pipe->screen;
386 gl_format mesa_format;
387 struct pipe_resource templ;
388 struct pipe_resource *src_tex;
389 struct pipe_sampler_view view_templ;
390 struct pipe_sampler_view *src_view;
391 struct pipe_surface *dst_surface;
392 struct pipe_transfer *tex_xfer;
393 void *map;
394
395 if (!stImage->pt) {
396 /* XXX: Can this happen? Should we assert? */
397 return GL_FALSE;
398 }
399
400 /* get destination surface (in the compressed texture) */
401 dst_surface = screen->get_tex_surface(screen, stImage->pt,
402 stImage->face, stImage->level, 0,
403 PIPE_BIND_BLIT_DESTINATION);
404 if (!dst_surface) {
405 /* can't render into this format (or other problem) */
406 return GL_FALSE;
407 }
408
409 /* Choose format for the temporary RGBA texture image.
410 */
411 mesa_format = st_ChooseTextureFormat(ctx, GL_RGBA, format, type);
412 assert(mesa_format);
413 if (!mesa_format)
414 return GL_FALSE;
415
416 /* Create the temporary source texture
417 */
418 memset(&templ, 0, sizeof(templ));
419 templ.target = PIPE_TEXTURE_2D;
420 templ.format = st_mesa_format_to_pipe_format(mesa_format);
421 templ.width0 = width;
422 templ.height0 = height;
423 templ.depth0 = 1;
424 templ.last_level = 0;
425 templ._usage = PIPE_USAGE_DEFAULT;
426 templ.bind = PIPE_BIND_SAMPLER_VIEW;
427 src_tex = screen->resource_create(screen, &templ);
428
429 if (!src_tex)
430 return GL_FALSE;
431
432 /* Put user's tex data into the temporary texture
433 */
434 tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx), src_tex,
435 0, 0, 0, /* face, level are zero */
436 PIPE_TRANSFER_WRITE,
437 0, 0, width, height); /* x, y, w, h */
438 map = pipe_transfer_map(pipe, tex_xfer);
439
440 _mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
441 map, /* dest ptr */
442 0, 0, 0, /* dest x/y/z offset */
443 tex_xfer->stride, /* dest row stride (bytes) */
444 dstImageOffsets, /* image offsets (for 3D only) */
445 width, height, 1, /* size */
446 format, type, /* source format/type */
447 pixels, /* source data */
448 unpack); /* source data packing */
449
450 pipe_transfer_unmap(pipe, tex_xfer);
451 pipe->transfer_destroy(pipe, tex_xfer);
452
453 /* Create temporary sampler view */
454 u_sampler_view_default_template(&view_templ,
455 src_tex,
456 src_tex->format);
457 src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ);
458
459
460 /* copy / compress image */
461 util_blit_pixels_tex(ctx->st->blit,
462 src_view, /* sampler view (src) */
463 0, 0, /* src x0, y0 */
464 width, height, /* src x1, y1 */
465 dst_surface, /* pipe_surface (dst) */
466 xoffset, yoffset, /* dst x0, y0 */
467 xoffset + width, /* dst x1 */
468 yoffset + height, /* dst y1 */
469 0.0, /* z */
470 PIPE_TEX_MIPFILTER_NEAREST);
471
472 pipe_surface_reference(&dst_surface, NULL);
473 pipe_resource_reference(&src_tex, NULL);
474 pipe_sampler_view_reference(&src_view, NULL);
475
476 return GL_TRUE;
477 }
478
479
480 /**
481 * Do glTexImage1/2/3D().
482 */
483 static void
484 st_TexImage(GLcontext * ctx,
485 GLint dims,
486 GLenum target, GLint level,
487 GLint internalFormat,
488 GLint width, GLint height, GLint depth,
489 GLint border,
490 GLenum format, GLenum type, const void *pixels,
491 const struct gl_pixelstore_attrib *unpack,
492 struct gl_texture_object *texObj,
493 struct gl_texture_image *texImage,
494 GLsizei imageSize, GLboolean compressed_src)
495 {
496 struct pipe_screen *screen = ctx->st->pipe->screen;
497 struct st_texture_object *stObj = st_texture_object(texObj);
498 struct st_texture_image *stImage = st_texture_image(texImage);
499 GLint postConvWidth, postConvHeight;
500 GLint texelBytes, sizeInBytes;
501 GLuint dstRowStride = 0;
502 struct gl_pixelstore_attrib unpackNB;
503 enum pipe_transfer_usage transfer_usage = 0;
504
505 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
506 _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
507
508 /* switch to "normal" */
509 if (stObj->surface_based) {
510 _mesa_clear_texture_object(ctx, texObj);
511 stObj->surface_based = GL_FALSE;
512 }
513
514 /* gallium does not support texture borders, strip it off */
515 if (border) {
516 strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
517 unpack = &unpackNB;
518 texImage->Width = width;
519 texImage->Height = height;
520 texImage->Depth = depth;
521 texImage->Border = 0;
522 border = 0;
523 }
524
525 postConvWidth = width;
526 postConvHeight = height;
527
528 stImage->face = _mesa_tex_target_to_face(target);
529 stImage->level = level;
530
531 #if FEATURE_convolve
532 if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) {
533 _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth,
534 &postConvHeight);
535 }
536 #endif
537
538 _mesa_set_fetch_functions(texImage, dims);
539
540 if (_mesa_is_format_compressed(texImage->TexFormat)) {
541 /* must be a compressed format */
542 texelBytes = 0;
543 }
544 else {
545 texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
546
547 /* Minimum pitch of 32 bytes */
548 if (postConvWidth * texelBytes < 32) {
549 postConvWidth = 32 / texelBytes;
550 texImage->RowStride = postConvWidth;
551 }
552
553 /* we'll set RowStride elsewhere when the texture is a "mapped" state */
554 /*assert(texImage->RowStride == postConvWidth);*/
555 }
556
557 /* Release the reference to a potentially orphaned buffer.
558 * Release any old malloced memory.
559 */
560 if (stImage->pt) {
561 pipe_resource_reference(&stImage->pt, NULL);
562 assert(!texImage->Data);
563 }
564 else if (texImage->Data) {
565 _mesa_align_free(texImage->Data);
566 }
567
568 /*
569 * See if the new image is somehow incompatible with the existing
570 * mipmap. If so, free the old mipmap.
571 */
572 if (stObj->pt) {
573 if (stObj->teximage_realloc ||
574 level > (GLint) stObj->pt->last_level ||
575 !st_texture_match_image(stObj->pt, &stImage->base,
576 stImage->face, stImage->level)) {
577 DBG("release it\n");
578 pipe_resource_reference(&stObj->pt, NULL);
579 assert(!stObj->pt);
580 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
581 stObj->teximage_realloc = FALSE;
582 }
583 }
584
585 if (width == 0 || height == 0 || depth == 0) {
586 /* stop after freeing old image */
587 return;
588 }
589
590 if (!stObj->pt) {
591 guess_and_alloc_texture(ctx->st, stObj, stImage);
592 if (!stObj->pt) {
593 /* Probably out of memory.
594 * Try flushing any pending rendering, then retry.
595 */
596 st_finish(ctx->st);
597 guess_and_alloc_texture(ctx->st, stObj, stImage);
598 if (!stObj->pt) {
599 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
600 return;
601 }
602 }
603 }
604
605 assert(!stImage->pt);
606
607 if (stObj->pt &&
608 st_texture_match_image(stObj->pt, &stImage->base,
609 stImage->face, stImage->level)) {
610
611 pipe_resource_reference(&stImage->pt, stObj->pt);
612 assert(stImage->pt);
613 }
614
615 if (!stImage->pt)
616 DBG("XXX: Image did not fit into texture - storing in local memory!\n");
617
618 /* st_CopyTexImage calls this function with pixels == NULL, with
619 * the expectation that the texture will be set up but nothing
620 * more will be done. This is where those calls return:
621 */
622 if (compressed_src) {
623 pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
624 unpack,
625 "glCompressedTexImage");
626 }
627 else {
628 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
629 format, type,
630 pixels, unpack, "glTexImage");
631 }
632
633 /* Note: we can't check for pixels==NULL until after we've allocated
634 * memory for the texture.
635 */
636
637 /* See if we can do texture compression with a blit/render.
638 */
639 if (!compressed_src &&
640 !ctx->Mesa_DXTn &&
641 _mesa_is_format_compressed(texImage->TexFormat) &&
642 screen->is_format_supported(screen,
643 stImage->pt->format,
644 stImage->pt->target,
645 PIPE_BIND_RENDER_TARGET, 0)) {
646 if (!pixels)
647 goto done;
648
649 if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth,
650 format, type, pixels, unpack, texImage)) {
651 goto done;
652 }
653 }
654
655 if (stImage->pt) {
656 if (format == GL_DEPTH_COMPONENT &&
657 util_format_is_depth_and_stencil(stImage->pt->format))
658 transfer_usage = PIPE_TRANSFER_READ_WRITE;
659 else
660 transfer_usage = PIPE_TRANSFER_WRITE;
661
662 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
663 transfer_usage, 0, 0,
664 stImage->base.Width,
665 stImage->base.Height);
666 if(stImage->transfer)
667 dstRowStride = stImage->transfer->stride;
668 }
669 else {
670 /* Allocate regular memory and store the image there temporarily. */
671 if (_mesa_is_format_compressed(texImage->TexFormat)) {
672 sizeInBytes = _mesa_format_image_size(texImage->TexFormat,
673 texImage->Width,
674 texImage->Height,
675 texImage->Depth);
676 dstRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
677 assert(dims != 3);
678 }
679 else {
680 dstRowStride = postConvWidth * texelBytes;
681 sizeInBytes = depth * dstRowStride * postConvHeight;
682 }
683
684 texImage->Data = _mesa_align_malloc(sizeInBytes, 16);
685 }
686
687 if (!texImage->Data) {
688 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
689 return;
690 }
691
692 if (!pixels)
693 goto done;
694
695 DBG("Upload image %dx%dx%d row_len %x pitch %x\n",
696 width, height, depth, width * texelBytes, dstRowStride);
697
698 /* Copy data. Would like to know when it's ok for us to eg. use
699 * the blitter to copy. Or, use the hardware to do the format
700 * conversion and copy:
701 */
702 if (compressed_src) {
703 const GLuint srcImageStride = _mesa_format_row_stride(texImage->TexFormat, width);
704 if(dstRowStride == srcImageStride)
705 memcpy(texImage->Data, pixels, imageSize);
706 else
707 {
708 char *dst = texImage->Data;
709 const char *src = pixels;
710 GLuint i, bw, bh, lines;
711 _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
712 lines = (height + bh - 1) / bh;
713
714 for(i = 0; i < lines; ++i)
715 {
716 memcpy(dst, src, srcImageStride);
717 dst += dstRowStride;
718 src += srcImageStride;
719 }
720 }
721 }
722 else {
723 const GLuint srcImageStride =
724 _mesa_image_image_stride(unpack, width, height, format, type);
725 GLint i;
726 const GLubyte *src = (const GLubyte *) pixels;
727
728 for (i = 0; i < depth; i++) {
729 if (!_mesa_texstore(ctx, dims,
730 texImage->_BaseFormat,
731 texImage->TexFormat,
732 texImage->Data,
733 0, 0, 0, /* dstX/Y/Zoffset */
734 dstRowStride,
735 texImage->ImageOffsets,
736 width, height, 1,
737 format, type, src, unpack)) {
738 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
739 }
740
741 if (stImage->pt && i + 1 < depth) {
742 /* unmap this slice */
743 st_texture_image_unmap(ctx->st, stImage);
744 /* map next slice of 3D texture */
745 texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
746 transfer_usage, 0, 0,
747 stImage->base.Width,
748 stImage->base.Height);
749 src += srcImageStride;
750 }
751 }
752 }
753
754 done:
755 _mesa_unmap_teximage_pbo(ctx, unpack);
756
757 if (stImage->pt && texImage->Data) {
758 st_texture_image_unmap(ctx->st, stImage);
759 texImage->Data = NULL;
760 }
761 }
762
763
764 static void
765 st_TexImage3D(GLcontext * ctx,
766 GLenum target, GLint level,
767 GLint internalFormat,
768 GLint width, GLint height, GLint depth,
769 GLint border,
770 GLenum format, GLenum type, const void *pixels,
771 const struct gl_pixelstore_attrib *unpack,
772 struct gl_texture_object *texObj,
773 struct gl_texture_image *texImage)
774 {
775 st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth,
776 border, format, type, pixels, unpack, texObj, texImage,
777 0, GL_FALSE);
778 }
779
780
781 static void
782 st_TexImage2D(GLcontext * ctx,
783 GLenum target, GLint level,
784 GLint internalFormat,
785 GLint width, GLint height, GLint border,
786 GLenum format, GLenum type, const void *pixels,
787 const struct gl_pixelstore_attrib *unpack,
788 struct gl_texture_object *texObj,
789 struct gl_texture_image *texImage)
790 {
791 st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
792 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
793 }
794
795
796 static void
797 st_TexImage1D(GLcontext * ctx,
798 GLenum target, GLint level,
799 GLint internalFormat,
800 GLint width, GLint border,
801 GLenum format, GLenum type, const void *pixels,
802 const struct gl_pixelstore_attrib *unpack,
803 struct gl_texture_object *texObj,
804 struct gl_texture_image *texImage)
805 {
806 st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border,
807 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
808 }
809
810
811 static void
812 st_CompressedTexImage2D(GLcontext *ctx, GLenum target, GLint level,
813 GLint internalFormat,
814 GLint width, GLint height, GLint border,
815 GLsizei imageSize, const GLvoid *data,
816 struct gl_texture_object *texObj,
817 struct gl_texture_image *texImage)
818 {
819 st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border,
820 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
821 }
822
823
824
825 /**
826 * glGetTexImage() helper: decompress a compressed texture by rendering
827 * a textured quad. Store the results in the user's buffer.
828 */
829 static void
830 decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
831 GLenum format, GLenum type, GLvoid *pixels,
832 struct gl_texture_object *texObj,
833 struct gl_texture_image *texImage)
834 {
835 struct pipe_context *pipe = ctx->st->pipe;
836 struct pipe_screen *screen = pipe->screen;
837 struct st_texture_image *stImage = st_texture_image(texImage);
838 struct st_texture_object *stObj = st_texture_object(texObj);
839 struct pipe_sampler_view *src_view =
840 st_get_texture_sampler_view(stObj, pipe);
841 const GLuint width = texImage->Width;
842 const GLuint height = texImage->Height;
843 struct pipe_surface *dst_surface;
844 struct pipe_resource *dst_texture;
845 struct pipe_transfer *tex_xfer;
846 unsigned bind = (PIPE_BIND_BLIT_DESTINATION |
847 PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
848 PIPE_BIND_TRANSFER_READ);
849
850 /* create temp / dest surface */
851 if (!util_create_rgba_surface(screen, width, height, bind,
852 &dst_texture, &dst_surface)) {
853 _mesa_problem(ctx, "util_create_rgba_surface() failed "
854 "in decompress_with_blit()");
855 return;
856 }
857
858 /* blit/render/decompress */
859 util_blit_pixels_tex(ctx->st->blit,
860 src_view, /* pipe_resource (src) */
861 0, 0, /* src x0, y0 */
862 width, height, /* src x1, y1 */
863 dst_surface, /* pipe_surface (dst) */
864 0, 0, /* dst x0, y0 */
865 width, height, /* dst x1, y1 */
866 0.0, /* z */
867 PIPE_TEX_MIPFILTER_NEAREST);
868
869 /* map the dst_surface so we can read from it */
870 tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx),
871 dst_texture, 0, 0, 0,
872 PIPE_TRANSFER_READ,
873 0, 0, width, height);
874
875 pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels);
876
877 /* copy/pack data into user buffer */
878 if (st_equal_formats(stImage->pt->format, format, type)) {
879 /* memcpy */
880 const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
881 ubyte *map = pipe_transfer_map(pipe, tex_xfer);
882 GLuint row;
883 for (row = 0; row < height; row++) {
884 GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
885 height, format, type, row, 0);
886 memcpy(dest, map, bytesPerRow);
887 map += tex_xfer->stride;
888 }
889 pipe_transfer_unmap(pipe, tex_xfer);
890 }
891 else {
892 /* format translation via floats */
893 GLuint row;
894 for (row = 0; row < height; row++) {
895 const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
896 GLfloat rgba[4 * MAX_WIDTH];
897 GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
898 height, format, type, row, 0);
899
900 if (ST_DEBUG & DEBUG_FALLBACK)
901 debug_printf("%s: fallback format translation\n", __FUNCTION__);
902
903 /* get float[4] rgba row from surface */
904 pipe_get_tile_rgba(pipe, tex_xfer, 0, row, width, 1, rgba);
905
906 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
907 type, dest, &ctx->Pack, transferOps);
908 }
909 }
910
911 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
912
913 pipe->transfer_destroy(pipe, tex_xfer);
914
915 /* destroy the temp / dest surface */
916 util_destroy_rgba_surface(dst_texture, dst_surface);
917 }
918
919
920
921 /**
922 * Need to map texture image into memory before copying image data,
923 * then unmap it.
924 */
925 static void
926 st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
927 GLenum format, GLenum type, GLvoid * pixels,
928 struct gl_texture_object *texObj,
929 struct gl_texture_image *texImage, GLboolean compressed_dst)
930 {
931 struct st_texture_image *stImage = st_texture_image(texImage);
932 const GLuint dstImageStride =
933 _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height,
934 format, type);
935 GLuint depth, i;
936 GLubyte *dest;
937
938 if (stImage->pt &&
939 util_format_is_s3tc(stImage->pt->format) &&
940 !compressed_dst) {
941 /* Need to decompress the texture.
942 * We'll do this by rendering a textured quad.
943 * Note that we only expect RGBA formats (no Z/depth formats).
944 */
945 decompress_with_blit(ctx, target, level, format, type, pixels,
946 texObj, texImage);
947 return;
948 }
949
950 /* Map */
951 if (stImage->pt) {
952 /* Image is stored in hardware format in a buffer managed by the
953 * kernel. Need to explicitly map and unmap it.
954 */
955 unsigned face = _mesa_tex_target_to_face(target);
956
957 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
958 PIPE_TRANSFER_READ);
959
960 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
961 PIPE_TRANSFER_READ, 0, 0,
962 stImage->base.Width,
963 stImage->base.Height);
964 texImage->RowStride = stImage->transfer->stride / util_format_get_blocksize(stImage->pt->format);
965 }
966 else {
967 /* Otherwise, the image should actually be stored in
968 * texImage->Data. This is pretty confusing for
969 * everybody, I'd much prefer to separate the two functions of
970 * texImage->Data - storage for texture images in main memory
971 * and access (ie mappings) of images. In other words, we'd
972 * create a new texImage->Map field and leave Data simply for
973 * storage.
974 */
975 assert(texImage->Data);
976 }
977
978 depth = texImage->Depth;
979 texImage->Depth = 1;
980
981 dest = (GLubyte *) pixels;
982
983 for (i = 0; i < depth; i++) {
984 if (compressed_dst) {
985 _mesa_get_compressed_teximage(ctx, target, level, dest,
986 texObj, texImage);
987 }
988 else {
989 _mesa_get_teximage(ctx, target, level, format, type, dest,
990 texObj, texImage);
991 }
992
993 if (stImage->pt && i + 1 < depth) {
994 /* unmap this slice */
995 st_texture_image_unmap(ctx->st, stImage);
996 /* map next slice of 3D texture */
997 texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
998 PIPE_TRANSFER_READ, 0, 0,
999 stImage->base.Width,
1000 stImage->base.Height);
1001 dest += dstImageStride;
1002 }
1003 }
1004
1005 texImage->Depth = depth;
1006
1007 /* Unmap */
1008 if (stImage->pt) {
1009 st_texture_image_unmap(ctx->st, stImage);
1010 texImage->Data = NULL;
1011 }
1012 }
1013
1014
1015 static void
1016 st_GetTexImage(GLcontext * ctx, GLenum target, GLint level,
1017 GLenum format, GLenum type, GLvoid * pixels,
1018 struct gl_texture_object *texObj,
1019 struct gl_texture_image *texImage)
1020 {
1021 st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage,
1022 GL_FALSE);
1023 }
1024
1025
1026 static void
1027 st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
1028 GLvoid *pixels,
1029 struct gl_texture_object *texObj,
1030 struct gl_texture_image *texImage)
1031 {
1032 st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage,
1033 GL_TRUE);
1034 }
1035
1036
1037
1038 static void
1039 st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
1040 GLint xoffset, GLint yoffset, GLint zoffset,
1041 GLint width, GLint height, GLint depth,
1042 GLenum format, GLenum type, const void *pixels,
1043 const struct gl_pixelstore_attrib *packing,
1044 struct gl_texture_object *texObj,
1045 struct gl_texture_image *texImage)
1046 {
1047 struct pipe_screen *screen = ctx->st->pipe->screen;
1048 struct st_texture_image *stImage = st_texture_image(texImage);
1049 GLuint dstRowStride;
1050 const GLuint srcImageStride =
1051 _mesa_image_image_stride(packing, width, height, format, type);
1052 GLint i;
1053 const GLubyte *src;
1054 /* init to silence warning only: */
1055 enum pipe_transfer_usage transfer_usage = PIPE_TRANSFER_WRITE;
1056
1057 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
1058 _mesa_lookup_enum_by_nr(target),
1059 level, xoffset, yoffset, width, height);
1060
1061 pixels =
1062 _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
1063 type, pixels, packing, "glTexSubImage2D");
1064 if (!pixels)
1065 return;
1066
1067 /* See if we can do texture compression with a blit/render.
1068 */
1069 if (!ctx->Mesa_DXTn &&
1070 _mesa_is_format_compressed(texImage->TexFormat) &&
1071 screen->is_format_supported(screen,
1072 stImage->pt->format,
1073 stImage->pt->target,
1074 PIPE_BIND_RENDER_TARGET, 0)) {
1075 if (compress_with_blit(ctx, target, level,
1076 xoffset, yoffset, zoffset,
1077 width, height, depth,
1078 format, type, pixels, packing, texImage)) {
1079 goto done;
1080 }
1081 }
1082
1083 /* Map buffer if necessary. Need to lock to prevent other contexts
1084 * from uploading the buffer under us.
1085 */
1086 if (stImage->pt) {
1087 unsigned face = _mesa_tex_target_to_face(target);
1088
1089 if (format == GL_DEPTH_COMPONENT &&
1090 util_format_is_depth_and_stencil(stImage->pt->format))
1091 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1092 else
1093 transfer_usage = PIPE_TRANSFER_WRITE;
1094
1095 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
1096 transfer_usage);
1097 texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset,
1098 transfer_usage,
1099 xoffset, yoffset,
1100 width, height);
1101 }
1102
1103 if (!texImage->Data) {
1104 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1105 goto done;
1106 }
1107
1108 src = (const GLubyte *) pixels;
1109 dstRowStride = stImage->transfer->stride;
1110
1111 for (i = 0; i < depth; i++) {
1112 if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
1113 texImage->TexFormat,
1114 texImage->Data,
1115 0, 0, 0,
1116 dstRowStride,
1117 texImage->ImageOffsets,
1118 width, height, 1,
1119 format, type, src, packing)) {
1120 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1121 }
1122
1123 if (stImage->pt && i + 1 < depth) {
1124 /* unmap this slice */
1125 st_texture_image_unmap(ctx->st, stImage);
1126 /* map next slice of 3D texture */
1127 texImage->Data = st_texture_image_map(ctx->st, stImage,
1128 zoffset + i + 1,
1129 transfer_usage,
1130 xoffset, yoffset,
1131 width, height);
1132 src += srcImageStride;
1133 }
1134 }
1135
1136 done:
1137 _mesa_unmap_teximage_pbo(ctx, packing);
1138
1139 if (stImage->pt && texImage->Data) {
1140 st_texture_image_unmap(ctx->st, stImage);
1141 texImage->Data = NULL;
1142 }
1143 }
1144
1145
1146
1147 static void
1148 st_TexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1149 GLint xoffset, GLint yoffset, GLint zoffset,
1150 GLsizei width, GLsizei height, GLsizei depth,
1151 GLenum format, GLenum type, const GLvoid *pixels,
1152 const struct gl_pixelstore_attrib *packing,
1153 struct gl_texture_object *texObj,
1154 struct gl_texture_image *texImage)
1155 {
1156 st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset,
1157 width, height, depth, format, type,
1158 pixels, packing, texObj, texImage);
1159 }
1160
1161
1162 static void
1163 st_TexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1164 GLint xoffset, GLint yoffset,
1165 GLsizei width, GLsizei height,
1166 GLenum format, GLenum type, const GLvoid * pixels,
1167 const struct gl_pixelstore_attrib *packing,
1168 struct gl_texture_object *texObj,
1169 struct gl_texture_image *texImage)
1170 {
1171 st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0,
1172 width, height, 1, format, type,
1173 pixels, packing, texObj, texImage);
1174 }
1175
1176
1177 static void
1178 st_TexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1179 GLint xoffset, GLsizei width, GLenum format, GLenum type,
1180 const GLvoid * pixels,
1181 const struct gl_pixelstore_attrib *packing,
1182 struct gl_texture_object *texObj,
1183 struct gl_texture_image *texImage)
1184 {
1185 st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1,
1186 format, type, pixels, packing, texObj, texImage);
1187 }
1188
1189
1190 static void
1191 st_CompressedTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1192 GLint xoffset, GLsizei width,
1193 GLenum format,
1194 GLsizei imageSize, const GLvoid *data,
1195 struct gl_texture_object *texObj,
1196 struct gl_texture_image *texImage)
1197 {
1198 assert(0);
1199 }
1200
1201
1202 static void
1203 st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1204 GLint xoffset, GLint yoffset,
1205 GLsizei width, GLint height,
1206 GLenum format,
1207 GLsizei imageSize, const GLvoid *data,
1208 struct gl_texture_object *texObj,
1209 struct gl_texture_image *texImage)
1210 {
1211 struct st_texture_image *stImage = st_texture_image(texImage);
1212 int srcBlockStride;
1213 int dstBlockStride;
1214 int y;
1215 enum pipe_format pformat;
1216
1217 if (stImage->pt) {
1218 unsigned face = _mesa_tex_target_to_face(target);
1219 pformat = stImage->pt->format;
1220
1221 st_teximage_flush_before_map(ctx->st, stImage->pt, face, level,
1222 PIPE_TRANSFER_WRITE);
1223 texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
1224 PIPE_TRANSFER_WRITE,
1225 xoffset, yoffset,
1226 width, height);
1227
1228 srcBlockStride = util_format_get_stride(pformat, width);
1229 dstBlockStride = stImage->transfer->stride;
1230 } else {
1231 assert(stImage->pt);
1232 /* TODO find good values for block and strides */
1233 /* TODO also adjust texImage->data for yoffset/xoffset */
1234 return;
1235 }
1236
1237 if (!texImage->Data) {
1238 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage");
1239 return;
1240 }
1241
1242 assert(xoffset % util_format_get_blockwidth(pformat) == 0);
1243 assert(yoffset % util_format_get_blockheight(pformat) == 0);
1244 assert(width % util_format_get_blockwidth(pformat) == 0);
1245 assert(height % util_format_get_blockheight(pformat) == 0);
1246
1247 for (y = 0; y < height; y += util_format_get_blockheight(pformat)) {
1248 /* don't need to adjust for xoffset and yoffset as st_texture_image_map does that */
1249 const char *src = (const char*)data + srcBlockStride * util_format_get_nblocksy(pformat, y);
1250 char *dst = (char*)texImage->Data + dstBlockStride * util_format_get_nblocksy(pformat, y);
1251 memcpy(dst, src, util_format_get_stride(pformat, width));
1252 }
1253
1254 if (stImage->pt) {
1255 st_texture_image_unmap(ctx->st, stImage);
1256 texImage->Data = NULL;
1257 }
1258 }
1259
1260
1261 static void
1262 st_CompressedTexSubImage3D(GLcontext *ctx, GLenum target, GLint level,
1263 GLint xoffset, GLint yoffset, GLint zoffset,
1264 GLsizei width, GLint height, GLint depth,
1265 GLenum format,
1266 GLsizei imageSize, const GLvoid *data,
1267 struct gl_texture_object *texObj,
1268 struct gl_texture_image *texImage)
1269 {
1270 assert(0);
1271 }
1272
1273
1274
1275 /**
1276 * Do a CopyTexSubImage operation using a read transfer from the source,
1277 * a write transfer to the destination and get_tile()/put_tile() to access
1278 * the pixels/texels.
1279 *
1280 * Note: srcY=0=TOP of renderbuffer
1281 */
1282 static void
1283 fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
1284 struct st_renderbuffer *strb,
1285 struct st_texture_image *stImage,
1286 GLenum baseFormat,
1287 GLint destX, GLint destY, GLint destZ,
1288 GLint srcX, GLint srcY,
1289 GLsizei width, GLsizei height)
1290 {
1291 struct pipe_context *pipe = ctx->st->pipe;
1292 struct pipe_transfer *src_trans;
1293 GLvoid *texDest;
1294 enum pipe_transfer_usage transfer_usage;
1295
1296 if (ST_DEBUG & DEBUG_FALLBACK)
1297 debug_printf("%s: fallback processing\n", __FUNCTION__);
1298
1299 assert(width <= MAX_WIDTH);
1300
1301 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1302 srcY = strb->Base.Height - srcY - height;
1303 }
1304
1305 src_trans = st_cond_flush_get_tex_transfer( st_context(ctx),
1306 strb->texture,
1307 0, 0, 0,
1308 PIPE_TRANSFER_READ,
1309 srcX, srcY,
1310 width, height);
1311
1312 if ((baseFormat == GL_DEPTH_COMPONENT ||
1313 baseFormat == GL_DEPTH_STENCIL) &&
1314 util_format_is_depth_and_stencil(stImage->pt->format))
1315 transfer_usage = PIPE_TRANSFER_READ_WRITE;
1316 else
1317 transfer_usage = PIPE_TRANSFER_WRITE;
1318
1319 st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0,
1320 transfer_usage);
1321
1322 texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage,
1323 destX, destY, width, height);
1324
1325 if (baseFormat == GL_DEPTH_COMPONENT ||
1326 baseFormat == GL_DEPTH_STENCIL) {
1327 const GLboolean scaleOrBias = (ctx->Pixel.DepthScale != 1.0F ||
1328 ctx->Pixel.DepthBias != 0.0F);
1329 GLint row, yStep;
1330
1331 /* determine bottom-to-top vs. top-to-bottom order for src buffer */
1332 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1333 srcY = height - 1;
1334 yStep = -1;
1335 }
1336 else {
1337 srcY = 0;
1338 yStep = 1;
1339 }
1340
1341 /* To avoid a large temp memory allocation, do copy row by row */
1342 for (row = 0; row < height; row++, srcY += yStep) {
1343 uint data[MAX_WIDTH];
1344 pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data);
1345 if (scaleOrBias) {
1346 _mesa_scale_and_bias_depth_uint(ctx, width, data);
1347 }
1348 pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data);
1349 }
1350 }
1351 else {
1352 /* RGBA format */
1353 GLfloat *tempSrc =
1354 (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
1355
1356 if (tempSrc && texDest) {
1357 const GLint dims = 2;
1358 const GLint dstRowStride = stImage->transfer->stride;
1359 struct gl_texture_image *texImage = &stImage->base;
1360 struct gl_pixelstore_attrib unpack = ctx->DefaultPacking;
1361
1362 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
1363 unpack.Invert = GL_TRUE;
1364 }
1365
1366 /* get float/RGBA image from framebuffer */
1367 /* XXX this usually involves a lot of int/float conversion.
1368 * try to avoid that someday.
1369 */
1370 pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc);
1371
1372 /* Store into texture memory.
1373 * Note that this does some special things such as pixel transfer
1374 * ops and format conversion. In particular, if the dest tex format
1375 * is actually RGBA but the user created the texture as GL_RGB we
1376 * need to fill-in/override the alpha channel with 1.0.
1377 */
1378 _mesa_texstore(ctx, dims,
1379 texImage->_BaseFormat,
1380 texImage->TexFormat,
1381 texDest,
1382 0, 0, 0,
1383 dstRowStride,
1384 texImage->ImageOffsets,
1385 width, height, 1,
1386 GL_RGBA, GL_FLOAT, tempSrc, /* src */
1387 &unpack);
1388 }
1389 else {
1390 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
1391 }
1392
1393 if (tempSrc)
1394 free(tempSrc);
1395 }
1396
1397 st_texture_image_unmap(ctx->st, stImage);
1398 pipe->transfer_destroy(pipe, src_trans);
1399 }
1400
1401
1402
1403 /**
1404 * If the format of the src renderbuffer and the format of the dest
1405 * texture are compatible (in terms of blitting), return a TGSI writemask
1406 * to be used during the blit.
1407 * If the src/dest are incompatible, return 0.
1408 */
1409 static unsigned
1410 compatible_src_dst_formats(GLcontext *ctx,
1411 const struct gl_renderbuffer *src,
1412 const struct gl_texture_image *dst)
1413 {
1414 /* Get logical base formats for the src and dest.
1415 * That is, use the user-requested formats and not the actual, device-
1416 * chosen formats.
1417 * For example, the user may have requested an A8 texture but the
1418 * driver may actually be using an RGBA texture format. When we
1419 * copy/blit to that texture, we only want to copy the Alpha channel
1420 * and not the RGB channels.
1421 *
1422 * Similarly, when the src FBO was created an RGB format may have been
1423 * requested but the driver actually chose an RGBA format. In that case,
1424 * we don't want to copy the undefined Alpha channel to the dest texture
1425 * (it should be 1.0).
1426 */
1427 const GLenum srcFormat = _mesa_base_fbo_format(ctx, src->InternalFormat);
1428 const GLenum dstFormat = _mesa_base_tex_format(ctx, dst->InternalFormat);
1429
1430 /**
1431 * XXX when we have red-only and red/green renderbuffers we'll need
1432 * to add more cases here (or implement a general-purpose routine that
1433 * queries the existance of the R,G,B,A channels in the src and dest).
1434 */
1435 if (srcFormat == dstFormat) {
1436 /* This is the same as matching_base_formats, which should
1437 * always pass, as it did previously.
1438 */
1439 return TGSI_WRITEMASK_XYZW;
1440 }
1441 else if (srcFormat == GL_RGB && dstFormat == GL_RGBA) {
1442 /* Make sure that A in the dest is 1. The actual src format
1443 * may be RGBA and have undefined A values.
1444 */
1445 return TGSI_WRITEMASK_XYZ;
1446 }
1447 else if (srcFormat == GL_RGBA && dstFormat == GL_RGB) {
1448 /* Make sure that A in the dest is 1. The actual dst format
1449 * may be RGBA and will need A=1 to provide proper alpha values
1450 * when sampled later.
1451 */
1452 return TGSI_WRITEMASK_XYZ;
1453 }
1454 else {
1455 if (ST_DEBUG & DEBUG_FALLBACK)
1456 debug_printf("%s failed for src %s, dst %s\n",
1457 __FUNCTION__,
1458 _mesa_lookup_enum_by_nr(srcFormat),
1459 _mesa_lookup_enum_by_nr(dstFormat));
1460
1461 /* Otherwise fail.
1462 */
1463 return 0;
1464 }
1465 }
1466
1467
1468
1469 /**
1470 * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
1471 * Note that the region to copy has already been clipped so we know we
1472 * won't read from outside the source renderbuffer's bounds.
1473 *
1474 * Note: srcY=0=Bottom of renderbuffer (GL convention)
1475 */
1476 static void
1477 st_copy_texsubimage(GLcontext *ctx,
1478 GLenum target, GLint level,
1479 GLint destX, GLint destY, GLint destZ,
1480 GLint srcX, GLint srcY,
1481 GLsizei width, GLsizei height)
1482 {
1483 struct gl_texture_unit *texUnit =
1484 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1485 struct gl_texture_object *texObj =
1486 _mesa_select_tex_object(ctx, texUnit, target);
1487 struct gl_texture_image *texImage =
1488 _mesa_select_tex_image(ctx, texObj, target, level);
1489 struct st_texture_image *stImage = st_texture_image(texImage);
1490 const GLenum texBaseFormat = texImage->_BaseFormat;
1491 struct gl_framebuffer *fb = ctx->ReadBuffer;
1492 struct st_renderbuffer *strb;
1493 struct pipe_context *pipe = ctx->st->pipe;
1494 struct pipe_screen *screen = pipe->screen;
1495 enum pipe_format dest_format, src_format;
1496 GLboolean use_fallback = GL_TRUE;
1497 GLboolean matching_base_formats;
1498 GLuint format_writemask;
1499 struct pipe_surface *dest_surface = NULL;
1500 GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
1501
1502 /* any rendering in progress must flushed before we grab the fb image */
1503 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
1504
1505 /* make sure finalize_textures has been called?
1506 */
1507 if (0) st_validate_state(ctx->st);
1508
1509 /* determine if copying depth or color data */
1510 if (texBaseFormat == GL_DEPTH_COMPONENT ||
1511 texBaseFormat == GL_DEPTH_STENCIL) {
1512 strb = st_renderbuffer(fb->_DepthBuffer);
1513 }
1514 else {
1515 /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
1516 strb = st_renderbuffer(fb->_ColorReadBuffer);
1517 }
1518
1519 if (!strb || !strb->surface || !stImage->pt) {
1520 debug_printf("%s: null strb or stImage\n", __FUNCTION__);
1521 return;
1522 }
1523
1524 if (srcX < 0) {
1525 width -= -srcX;
1526 destX += -srcX;
1527 srcX = 0;
1528 }
1529
1530 if (srcY < 0) {
1531 height -= -srcY;
1532 destY += -srcY;
1533 srcY = 0;
1534 }
1535
1536 if (destX < 0) {
1537 width -= -destX;
1538 srcX += -destX;
1539 destX = 0;
1540 }
1541
1542 if (destY < 0) {
1543 height -= -destY;
1544 srcY += -destY;
1545 destY = 0;
1546 }
1547
1548 if (width < 0 || height < 0)
1549 return;
1550
1551
1552 assert(strb);
1553 assert(strb->surface);
1554 assert(stImage->pt);
1555
1556 src_format = strb->surface->format;
1557 dest_format = stImage->pt->format;
1558
1559 /*
1560 * Determine if the src framebuffer and dest texture have the same
1561 * base format. We need this to detect a case such as the framebuffer
1562 * being GL_RGBA but the texture being GL_RGB. If the actual hardware
1563 * texture format stores RGBA we need to set A=1 (overriding the
1564 * framebuffer's alpha values). We can't do that with the blit or
1565 * textured-quad paths.
1566 */
1567 matching_base_formats =
1568 (_mesa_get_format_base_format(strb->Base.Format) ==
1569 _mesa_get_format_base_format(texImage->TexFormat));
1570 format_writemask = compatible_src_dst_formats(ctx, &strb->Base, texImage);
1571
1572 if (ctx->_ImageTransferState == 0x0) {
1573
1574 if (matching_base_formats &&
1575 src_format == dest_format &&
1576 !do_flip)
1577 {
1578 /* use surface_copy() / blit */
1579
1580 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1581 stImage->face, stImage->level,
1582 destZ,
1583 PIPE_BIND_BLIT_DESTINATION);
1584
1585 /* for surface_copy(), y=0=top, always */
1586 pipe->surface_copy(pipe,
1587 /* dest */
1588 dest_surface,
1589 destX, destY,
1590 /* src */
1591 strb->surface,
1592 srcX, srcY,
1593 /* size */
1594 width, height);
1595 use_fallback = GL_FALSE;
1596 }
1597 else if (format_writemask &&
1598 texBaseFormat != GL_DEPTH_COMPONENT &&
1599 texBaseFormat != GL_DEPTH_STENCIL &&
1600 screen->is_format_supported(screen, src_format,
1601 PIPE_TEXTURE_2D,
1602 PIPE_BIND_SAMPLER_VIEW,
1603 0) &&
1604 screen->is_format_supported(screen, dest_format,
1605 PIPE_TEXTURE_2D,
1606 PIPE_BIND_RENDER_TARGET,
1607 0)) {
1608 /* draw textured quad to do the copy */
1609 GLint srcY0, srcY1;
1610
1611 dest_surface = screen->get_tex_surface(screen, stImage->pt,
1612 stImage->face, stImage->level,
1613 destZ,
1614 PIPE_BIND_BLIT_DESTINATION);
1615
1616 if (do_flip) {
1617 srcY1 = strb->Base.Height - srcY - height;
1618 srcY0 = srcY1 + height;
1619 }
1620 else {
1621 srcY0 = srcY;
1622 srcY1 = srcY0 + height;
1623 }
1624 util_blit_pixels_writemask(ctx->st->blit,
1625 strb->surface,
1626 st_get_renderbuffer_sampler_view(strb, pipe),
1627 srcX, srcY0,
1628 srcX + width, srcY1,
1629 dest_surface,
1630 destX, destY,
1631 destX + width, destY + height,
1632 0.0, PIPE_TEX_MIPFILTER_NEAREST,
1633 format_writemask);
1634 use_fallback = GL_FALSE;
1635 }
1636
1637 if (dest_surface)
1638 pipe_surface_reference(&dest_surface, NULL);
1639 }
1640
1641 if (use_fallback) {
1642 /* software fallback */
1643 fallback_copy_texsubimage(ctx, target, level,
1644 strb, stImage, texBaseFormat,
1645 destX, destY, destZ,
1646 srcX, srcY, width, height);
1647 }
1648 }
1649
1650
1651
1652 static void
1653 st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level,
1654 GLenum internalFormat,
1655 GLint x, GLint y, GLsizei width, GLint border)
1656 {
1657 struct gl_texture_unit *texUnit =
1658 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1659 struct gl_texture_object *texObj =
1660 _mesa_select_tex_object(ctx, texUnit, target);
1661 struct gl_texture_image *texImage =
1662 _mesa_select_tex_image(ctx, texObj, target, level);
1663
1664 /* Setup or redefine the texture object, texture and texture
1665 * image. Don't populate yet.
1666 */
1667 ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
1668 width, border,
1669 GL_RGBA, CHAN_TYPE, NULL,
1670 &ctx->DefaultPacking, texObj, texImage);
1671
1672 st_copy_texsubimage(ctx, target, level,
1673 0, 0, 0, /* destX,Y,Z */
1674 x, y, width, 1); /* src X, Y, size */
1675 }
1676
1677
1678 static void
1679 st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
1680 GLenum internalFormat,
1681 GLint x, GLint y, GLsizei width, GLsizei height,
1682 GLint border)
1683 {
1684 struct gl_texture_unit *texUnit =
1685 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1686 struct gl_texture_object *texObj =
1687 _mesa_select_tex_object(ctx, texUnit, target);
1688 struct gl_texture_image *texImage =
1689 _mesa_select_tex_image(ctx, texObj, target, level);
1690
1691 /* Setup or redefine the texture object, texture and texture
1692 * image. Don't populate yet.
1693 */
1694 ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
1695 width, height, border,
1696 GL_RGBA, CHAN_TYPE, NULL,
1697 &ctx->DefaultPacking, texObj, texImage);
1698
1699 st_copy_texsubimage(ctx, target, level,
1700 0, 0, 0, /* destX,Y,Z */
1701 x, y, width, height); /* src X, Y, size */
1702 }
1703
1704
1705 static void
1706 st_CopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
1707 GLint xoffset, GLint x, GLint y, GLsizei width)
1708 {
1709 const GLint yoffset = 0, zoffset = 0;
1710 const GLsizei height = 1;
1711 st_copy_texsubimage(ctx, target, level,
1712 xoffset, yoffset, zoffset, /* destX,Y,Z */
1713 x, y, width, height); /* src X, Y, size */
1714 }
1715
1716
1717 static void
1718 st_CopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
1719 GLint xoffset, GLint yoffset,
1720 GLint x, GLint y, GLsizei width, GLsizei height)
1721 {
1722 const GLint zoffset = 0;
1723 st_copy_texsubimage(ctx, target, level,
1724 xoffset, yoffset, zoffset, /* destX,Y,Z */
1725 x, y, width, height); /* src X, Y, size */
1726 }
1727
1728
1729 static void
1730 st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
1731 GLint xoffset, GLint yoffset, GLint zoffset,
1732 GLint x, GLint y, GLsizei width, GLsizei height)
1733 {
1734 st_copy_texsubimage(ctx, target, level,
1735 xoffset, yoffset, zoffset, /* destX,Y,Z */
1736 x, y, width, height); /* src X, Y, size */
1737 }
1738
1739
1740 static void
1741 copy_image_data_to_texture(struct st_context *st,
1742 struct st_texture_object *stObj,
1743 GLuint dstLevel,
1744 struct st_texture_image *stImage)
1745 {
1746 if (stImage->pt) {
1747 /* Copy potentially with the blitter:
1748 */
1749 st_texture_image_copy(st->pipe,
1750 stObj->pt, dstLevel, /* dest texture, level */
1751 stImage->pt, /* src texture */
1752 stImage->face);
1753
1754 pipe_resource_reference(&stImage->pt, NULL);
1755 }
1756 else if (stImage->base.Data) {
1757 /* More straightforward upload.
1758 */
1759 st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel,
1760 PIPE_TRANSFER_WRITE);
1761
1762 st_texture_image_data(st,
1763 stObj->pt,
1764 stImage->face,
1765 dstLevel,
1766 stImage->base.Data,
1767 stImage->base.RowStride *
1768 util_format_get_blocksize(stObj->pt->format),
1769 stImage->base.RowStride *
1770 stImage->base.Height *
1771 util_format_get_blocksize(stObj->pt->format));
1772 _mesa_align_free(stImage->base.Data);
1773 stImage->base.Data = NULL;
1774 }
1775
1776 pipe_resource_reference(&stImage->pt, stObj->pt);
1777 }
1778
1779
1780 /**
1781 * Called during state validation. When this function is finished,
1782 * the texture object should be ready for rendering.
1783 * \return GL_TRUE for success, GL_FALSE for failure (out of mem)
1784 */
1785 GLboolean
1786 st_finalize_texture(GLcontext *ctx,
1787 struct pipe_context *pipe,
1788 struct gl_texture_object *tObj,
1789 GLboolean *needFlush)
1790 {
1791 struct st_texture_object *stObj = st_texture_object(tObj);
1792 const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
1793 GLuint blockSize, face;
1794 struct st_texture_image *firstImage;
1795
1796 *needFlush = GL_FALSE;
1797
1798 if (stObj->base._Complete) {
1799 /* The texture is complete and we know exactly how many mipmap levels
1800 * are present/needed. This is conditional because we may be called
1801 * from the st_generate_mipmap() function when the texture object is
1802 * incomplete. In that case, we'll have set stObj->lastLevel before
1803 * we get here.
1804 */
1805 if (stObj->base.MinFilter == GL_LINEAR ||
1806 stObj->base.MinFilter == GL_NEAREST)
1807 stObj->lastLevel = stObj->base.BaseLevel;
1808 else
1809 stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel;
1810 }
1811
1812 firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]);
1813
1814 /* If both firstImage and stObj point to a texture which can contain
1815 * all active images, favour firstImage. Note that because of the
1816 * completeness requirement, we know that the image dimensions
1817 * will match.
1818 */
1819 if (firstImage->pt &&
1820 firstImage->pt != stObj->pt &&
1821 firstImage->pt->last_level >= stObj->lastLevel) {
1822 pipe_resource_reference(&stObj->pt, firstImage->pt);
1823 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
1824 }
1825
1826 /* bytes per pixel block (blocks are usually 1x1) */
1827 blockSize = _mesa_get_format_bytes(firstImage->base.TexFormat);
1828
1829 /* If we already have a gallium texture, check that it matches the texture
1830 * object's format, target, size, num_levels, etc.
1831 */
1832 if (stObj->pt) {
1833 const enum pipe_format fmt =
1834 st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
1835 if (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) ||
1836 stObj->pt->format != fmt ||
1837 stObj->pt->last_level < stObj->lastLevel ||
1838 stObj->pt->width0 != firstImage->base.Width2 ||
1839 stObj->pt->height0 != firstImage->base.Height2 ||
1840 stObj->pt->depth0 != firstImage->base.Depth2)
1841 {
1842 pipe_resource_reference(&stObj->pt, NULL);
1843 pipe_sampler_view_reference(&stObj->sampler_view, NULL);
1844 ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
1845 }
1846 }
1847
1848 /* May need to create a new gallium texture:
1849 */
1850 if (!stObj->pt) {
1851 const enum pipe_format fmt =
1852 st_mesa_format_to_pipe_format(firstImage->base.TexFormat);
1853 GLuint usage = default_usage(fmt);
1854
1855 stObj->pt = st_texture_create(ctx->st,
1856 gl_target_to_pipe(stObj->base.Target),
1857 fmt,
1858 stObj->lastLevel,
1859 firstImage->base.Width2,
1860 firstImage->base.Height2,
1861 firstImage->base.Depth2,
1862 usage);
1863
1864 if (!stObj->pt) {
1865 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
1866 return GL_FALSE;
1867 }
1868 }
1869
1870 /* Pull in any images not in the object's texture:
1871 */
1872 for (face = 0; face < nr_faces; face++) {
1873 GLuint level;
1874 for (level = 0; level <= stObj->lastLevel; level++) {
1875 struct st_texture_image *stImage =
1876 st_texture_image(stObj->base.Image[face][stObj->base.BaseLevel + level]);
1877
1878 /* Need to import images in main memory or held in other textures.
1879 */
1880 if (stImage && stObj->pt != stImage->pt) {
1881 copy_image_data_to_texture(ctx->st, stObj, level, stImage);
1882 *needFlush = GL_TRUE;
1883 }
1884 }
1885 }
1886
1887 return GL_TRUE;
1888 }
1889
1890
1891 /**
1892 * Returns pointer to a default/dummy texture.
1893 * This is typically used when the current shader has tex/sample instructions
1894 * but the user has not provided a (any) texture(s).
1895 */
1896 struct gl_texture_object *
1897 st_get_default_texture(struct st_context *st)
1898 {
1899 if (!st->default_texture) {
1900 static const GLenum target = GL_TEXTURE_2D;
1901 GLubyte pixels[16][16][4];
1902 struct gl_texture_object *texObj;
1903 struct gl_texture_image *texImg;
1904 GLuint i, j;
1905
1906 /* The ARB_fragment_program spec says (0,0,0,1) should be returned
1907 * when attempting to sample incomplete textures.
1908 */
1909 for (i = 0; i < 16; i++) {
1910 for (j = 0; j < 16; j++) {
1911 pixels[i][j][0] = 0;
1912 pixels[i][j][1] = 0;
1913 pixels[i][j][2] = 0;
1914 pixels[i][j][3] = 255;
1915 }
1916 }
1917
1918 texObj = st->ctx->Driver.NewTextureObject(st->ctx, 0, target);
1919
1920 texImg = _mesa_get_tex_image(st->ctx, texObj, target, 0);
1921
1922 _mesa_init_teximage_fields(st->ctx, target, texImg,
1923 16, 16, 1, 0, /* w, h, d, border */
1924 GL_RGBA);
1925
1926 st_TexImage(st->ctx, 2, target,
1927 0, GL_RGBA, /* level, intformat */
1928 16, 16, 1, 0, /* w, h, d, border */
1929 GL_RGBA, GL_UNSIGNED_BYTE, pixels,
1930 &st->ctx->DefaultPacking,
1931 texObj, texImg,
1932 0, 0);
1933
1934 texObj->MinFilter = GL_NEAREST;
1935 texObj->MagFilter = GL_NEAREST;
1936 texObj->_Complete = GL_TRUE;
1937
1938 st->default_texture = texObj;
1939 }
1940 return st->default_texture;
1941 }
1942
1943
1944 void
1945 st_init_texture_functions(struct dd_function_table *functions)
1946 {
1947 functions->ChooseTextureFormat = st_ChooseTextureFormat;
1948 functions->TexImage1D = st_TexImage1D;
1949 functions->TexImage2D = st_TexImage2D;
1950 functions->TexImage3D = st_TexImage3D;
1951 functions->TexSubImage1D = st_TexSubImage1D;
1952 functions->TexSubImage2D = st_TexSubImage2D;
1953 functions->TexSubImage3D = st_TexSubImage3D;
1954 functions->CompressedTexSubImage1D = st_CompressedTexSubImage1D;
1955 functions->CompressedTexSubImage2D = st_CompressedTexSubImage2D;
1956 functions->CompressedTexSubImage3D = st_CompressedTexSubImage3D;
1957 functions->CopyTexImage1D = st_CopyTexImage1D;
1958 functions->CopyTexImage2D = st_CopyTexImage2D;
1959 functions->CopyTexSubImage1D = st_CopyTexSubImage1D;
1960 functions->CopyTexSubImage2D = st_CopyTexSubImage2D;
1961 functions->CopyTexSubImage3D = st_CopyTexSubImage3D;
1962 functions->GenerateMipmap = st_generate_mipmap;
1963
1964 functions->GetTexImage = st_GetTexImage;
1965
1966 /* compressed texture functions */
1967 functions->CompressedTexImage2D = st_CompressedTexImage2D;
1968 functions->GetCompressedTexImage = st_GetCompressedTexImage;
1969
1970 functions->NewTextureObject = st_NewTextureObject;
1971 functions->NewTextureImage = st_NewTextureImage;
1972 functions->DeleteTexture = st_DeleteTextureObject;
1973 functions->FreeTexImageData = st_FreeTextureImageData;
1974 functions->UpdateTexturePalette = 0;
1975
1976 functions->TextureMemCpy = do_memcpy;
1977
1978 /* XXX Temporary until we can query pipe's texture sizes */
1979 functions->TestProxyTexImage = _mesa_test_proxy_teximage;
1980 }