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