~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/mesa/state_tracker/st_texture.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * 
26
26
 **************************************************************************/
27
27
 
 
28
#include <stdio.h>
 
29
 
28
30
#include "st_context.h"
29
31
#include "st_format.h"
30
 
#include "st_public.h"
31
32
#include "st_texture.h"
32
33
#include "st_cb_fbo.h"
33
 
#include "st_inlines.h"
34
34
#include "main/enums.h"
35
 
#include "main/texfetch.h"
36
 
#include "main/teximage.h"
37
 
#include "main/texobj.h"
38
 
 
39
 
#undef Elements  /* fix re-defined macro warning */
40
35
 
41
36
#include "pipe/p_state.h"
42
37
#include "pipe/p_context.h"
49
44
 
50
45
#define DBG if(0) printf
51
46
 
52
 
#if 0
53
 
static GLenum
54
 
target_to_target(GLenum target)
55
 
{
56
 
   switch (target) {
57
 
   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
58
 
   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
59
 
   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
60
 
   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
61
 
   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
62
 
   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
63
 
      return GL_TEXTURE_CUBE_MAP_ARB;
64
 
   default:
65
 
      return target;
66
 
   }
67
 
}
68
 
#endif
69
 
 
70
47
 
71
48
/**
72
 
 * Allocate a new pipe_texture object
 
49
 * Allocate a new pipe_resource object
73
50
 * width0, height0, depth0 are the dimensions of the level 0 image
74
51
 * (the highest resolution).  last_level indicates how many mipmap levels
75
52
 * to allocate storage for.  For non-mipmapped textures, this will be zero.
76
53
 */
77
 
struct pipe_texture *
 
54
struct pipe_resource *
78
55
st_texture_create(struct st_context *st,
79
56
                  enum pipe_texture_target target,
80
57
                  enum pipe_format format,
82
59
                  GLuint width0,
83
60
                  GLuint height0,
84
61
                  GLuint depth0,
85
 
                  GLuint usage )
 
62
                  GLuint bind )
86
63
{
87
 
   struct pipe_texture pt, *newtex;
 
64
   struct pipe_resource pt, *newtex;
88
65
   struct pipe_screen *screen = st->pipe->screen;
89
66
 
90
 
   assert(target <= PIPE_TEXTURE_CUBE);
 
67
   assert(target < PIPE_MAX_TEXTURE_TYPES);
 
68
   assert(width0 > 0);
 
69
   assert(height0 > 0);
 
70
   assert(depth0 > 0);
91
71
 
92
72
   DBG("%s target %s format %s last_level %d\n", __FUNCTION__,
93
73
       _mesa_lookup_enum_by_nr(target),
94
74
       _mesa_lookup_enum_by_nr(format), last_level);
95
75
 
96
76
   assert(format);
97
 
   assert(screen->is_format_supported(screen, format, target, 
98
 
                                      PIPE_TEXTURE_USAGE_SAMPLER, 0));
 
77
   assert(screen->is_format_supported(screen, format, target, 0,
 
78
                                      PIPE_BIND_SAMPLER_VIEW, 0));
99
79
 
100
80
   memset(&pt, 0, sizeof(pt));
101
81
   pt.target = target;
104
84
   pt.width0 = width0;
105
85
   pt.height0 = height0;
106
86
   pt.depth0 = depth0;
107
 
   pt.tex_usage = usage;
 
87
   pt.usage = PIPE_USAGE_DEFAULT;
 
88
   pt.bind = bind;
 
89
   pt.flags = 0;
108
90
 
109
 
   newtex = screen->texture_create(screen, &pt);
 
91
   newtex = screen->resource_create(screen, &pt);
110
92
 
111
93
   assert(!newtex || pipe_is_referenced(&newtex->reference));
112
94
 
118
100
 * Check if a texture image can be pulled into a unified mipmap texture.
119
101
 */
120
102
GLboolean
121
 
st_texture_match_image(const struct pipe_texture *pt,
 
103
st_texture_match_image(const struct pipe_resource *pt,
122
104
                       const struct gl_texture_image *image,
123
105
                       GLuint face, GLuint level)
124
106
{
144
126
}
145
127
 
146
128
 
147
 
#if 000
148
 
/* Although we use the image_offset[] array to store relative offsets
149
 
 * to cube faces, Mesa doesn't know anything about this and expects
150
 
 * each cube face to be treated as a separate image.
151
 
 *
152
 
 * These functions present that view to mesa:
153
 
 */
154
 
const GLuint *
155
 
st_texture_depth_offsets(struct pipe_texture *pt, GLuint level)
156
 
{
157
 
   static const GLuint zero = 0;
158
 
 
159
 
   if (pt->target != PIPE_TEXTURE_3D || pt->level[level].nr_images == 1)
160
 
      return &zero;
161
 
   else
162
 
      return pt->level[level].image_offset;
163
 
}
164
 
 
165
 
 
166
 
/**
167
 
 * Return the offset to the given mipmap texture image within the
168
 
 * texture memory buffer, in bytes.
169
 
 */
170
 
GLuint
171
 
st_texture_image_offset(const struct pipe_texture * pt,
172
 
                        GLuint face, GLuint level)
173
 
{
174
 
   if (pt->target == PIPE_TEXTURE_CUBE)
175
 
      return (pt->level[level].level_offset +
176
 
              pt->level[level].image_offset[face] * pt->cpp);
177
 
   else
178
 
      return pt->level[level].level_offset;
179
 
}
180
 
#endif
181
 
 
182
 
 
183
 
/**
184
 
 * Map a teximage in a mipmap texture.
185
 
 * \param row_stride  returns row stride in bytes
186
 
 * \param image_stride  returns image stride in bytes (for 3D textures).
187
 
 * \return address of mapping
 
129
/**
 
130
 * Map a texture image and return the address for a particular 2D face/slice/
 
131
 * layer.  The stImage indicates the cube face and mipmap level.  The slice
 
132
 * of the 3D texture is passed in 'zoffset'.
 
133
 * \param usage  one of the PIPE_TRANSFER_x values
 
134
 * \param x, y, w, h  the region of interest of the 2D image.
 
135
 * \return address of mapping or NULL if any error
188
136
 */
189
137
GLubyte *
190
138
st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
192
140
                     GLuint x, GLuint y, GLuint w, GLuint h)
193
141
{
194
142
   struct pipe_context *pipe = st->pipe;
195
 
   struct pipe_screen *screen = pipe->screen;
196
 
   struct pipe_texture *pt = stImage->pt;
 
143
   struct pipe_resource *pt = stImage->pt;
197
144
 
198
145
   DBG("%s \n", __FUNCTION__);
199
146
 
200
 
   stImage->transfer = st_no_flush_get_tex_transfer(st, pt, stImage->face,
 
147
   stImage->transfer = pipe_get_transfer(st->pipe, pt, stImage->face,
201
148
                                                    stImage->level, zoffset,
202
149
                                                    usage, x, y, w, h);
203
150
 
204
151
   if (stImage->transfer)
205
 
      return screen->transfer_map(screen, stImage->transfer);
 
152
      return pipe_transfer_map(pipe, stImage->transfer);
206
153
   else
207
154
      return NULL;
208
155
}
212
159
st_texture_image_unmap(struct st_context *st,
213
160
                       struct st_texture_image *stImage)
214
161
{
215
 
   struct pipe_screen *screen = st->pipe->screen;
 
162
   struct pipe_context *pipe = st->pipe;
216
163
 
217
164
   DBG("%s\n", __FUNCTION__);
218
165
 
219
 
   screen->transfer_unmap(screen, stImage->transfer);
 
166
   pipe_transfer_unmap(pipe, stImage->transfer);
220
167
 
221
 
   screen->tex_transfer_destroy(stImage->transfer);
 
168
   pipe->transfer_destroy(pipe, stImage->transfer);
222
169
}
223
170
 
224
171
 
238
185
                const void *src, unsigned src_stride,
239
186
                unsigned srcx, unsigned srcy, unsigned width, unsigned height)
240
187
{
241
 
   struct pipe_screen *screen = pipe->screen;
242
 
   void *map = screen->transfer_map(screen, dst);
 
188
   void *map = pipe_transfer_map(pipe, dst);
243
189
 
244
 
   assert(dst->texture);
 
190
   assert(dst->resource);
245
191
   util_copy_rect(map,
246
 
                  dst->texture->format,
 
192
                  dst->resource->format,
247
193
                  dst->stride,
248
194
                  dstx, dsty, 
249
195
                  width, height, 
250
196
                  src, src_stride, 
251
197
                  srcx, srcy);
252
198
 
253
 
   screen->transfer_unmap(screen, dst);
 
199
   pipe_transfer_unmap(pipe, dst);
254
200
}
255
201
 
256
202
 
258
204
 */
259
205
void
260
206
st_texture_image_data(struct st_context *st,
261
 
                      struct pipe_texture *dst,
 
207
                      struct pipe_resource *dst,
262
208
                      GLuint face,
263
209
                      GLuint level,
264
210
                      void *src,
265
211
                      GLuint src_row_stride, GLuint src_image_stride)
266
212
{
267
213
   struct pipe_context *pipe = st->pipe;
268
 
   struct pipe_screen *screen = pipe->screen;
269
214
   GLuint depth = u_minify(dst->depth0, level);
270
215
   GLuint i;
271
216
   const GLubyte *srcUB = src;
274
219
   DBG("%s\n", __FUNCTION__);
275
220
 
276
221
   for (i = 0; i < depth; i++) {
277
 
      dst_transfer = st_no_flush_get_tex_transfer(st, dst, face, level, i,
 
222
      dst_transfer = pipe_get_transfer(st->pipe, dst, face, level, i,
278
223
                                                  PIPE_TRANSFER_WRITE, 0, 0,
279
224
                                                  u_minify(dst->width0, level),
280
225
                                                  u_minify(dst->height0, level));
287
232
                      u_minify(dst->width0, level),
288
233
                      u_minify(dst->height0, level));      /* width, height */
289
234
 
290
 
      screen->tex_transfer_destroy(dst_transfer);
 
235
      pipe->transfer_destroy(pipe, dst_transfer);
291
236
 
292
237
      srcUB += src_image_stride;
293
238
   }
294
239
}
295
240
 
296
241
 
297
 
/* Copy mipmap image between textures
 
242
/**
 
243
 * For debug only: get/print center pixel in the src resource.
 
244
 */
 
245
static void
 
246
print_center_pixel(struct pipe_context *pipe, struct pipe_resource *src)
 
247
{
 
248
   struct pipe_subresource rect;
 
249
   struct pipe_transfer *xfer;
 
250
   struct pipe_box region;
 
251
   ubyte *map;
 
252
 
 
253
   rect.face = 0;
 
254
   rect.level = 0;
 
255
 
 
256
   region.x = src->width0 / 2;
 
257
   region.y = src->height0 / 2;
 
258
   region.z = 0;
 
259
   region.width = 1;
 
260
   region.height = 1;
 
261
   region.depth = 1;
 
262
 
 
263
   xfer = pipe->get_transfer(pipe, src, rect, PIPE_TRANSFER_READ, &region);
 
264
   map = pipe->transfer_map(pipe, xfer);
 
265
 
 
266
   printf("center pixel: %d %d %d %d\n", map[0], map[1], map[2], map[3]);
 
267
 
 
268
   pipe->transfer_unmap(pipe, xfer);
 
269
   pipe->transfer_destroy(pipe, xfer);
 
270
}
 
271
 
 
272
 
 
273
/**
 
274
 * Copy the image at level=0 in 'src' to the 'dst' resource at 'dstLevel'.
 
275
 * This is used to copy mipmap images from one texture buffer to another.
 
276
 * This typically happens when our initial guess at the total texture size
 
277
 * is incorrect (see the guess_and_alloc_texture() function).
298
278
 */
299
279
void
300
280
st_texture_image_copy(struct pipe_context *pipe,
301
 
                      struct pipe_texture *dst, GLuint dstLevel,
302
 
                      struct pipe_texture *src,
 
281
                      struct pipe_resource *dst, GLuint dstLevel,
 
282
                      struct pipe_resource *src, GLuint srcLevel,
303
283
                      GLuint face)
304
284
{
305
 
   struct pipe_screen *screen = pipe->screen;
306
285
   GLuint width = u_minify(dst->width0, dstLevel); 
307
286
   GLuint height = u_minify(dst->height0, dstLevel); 
308
287
   GLuint depth = u_minify(dst->depth0, dstLevel); 
309
 
   struct pipe_surface *src_surface;
310
 
   struct pipe_surface *dst_surface;
 
288
   struct pipe_subresource dstsub, srcsub;
311
289
   GLuint i;
312
290
 
 
291
   assert(u_minify(src->width0, srcLevel) == width);
 
292
   assert(u_minify(src->height0, srcLevel) == height);
 
293
   assert(u_minify(src->depth0, srcLevel) == depth);
 
294
 
 
295
   dstsub.face = face;
 
296
   dstsub.level = dstLevel;
 
297
   srcsub.face = face;
 
298
   srcsub.level = srcLevel;
 
299
   /* Loop over 3D image slices */
313
300
   for (i = 0; i < depth; i++) {
314
 
      GLuint srcLevel;
315
 
 
316
 
      /* find src texture level of needed size */
317
 
      for (srcLevel = 0; srcLevel <= src->last_level; srcLevel++) {
318
 
         if (u_minify(src->width0, srcLevel) == width &&
319
 
             u_minify(src->height0, srcLevel) == height) {
320
 
            break;
321
 
         }
322
 
      }
323
 
      assert(u_minify(src->width0, srcLevel) == width);
324
 
      assert(u_minify(src->height0, srcLevel) == height);
325
 
 
326
 
#if 0
327
 
      {
328
 
         src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
329
 
                                               PIPE_BUFFER_USAGE_CPU_READ);
330
 
         ubyte *map = screen->surface_map(screen, src_surface, PIPE_BUFFER_USAGE_CPU_READ);
331
 
         map += src_surface->width * src_surface->height * 4 / 2;
332
 
         printf("%s center pixel: %d %d %d %d (pt %p[%d] -> %p[%d])\n",
333
 
                __FUNCTION__,
334
 
                map[0], map[1], map[2], map[3],
335
 
                src, srcLevel, dst, dstLevel);
336
 
 
337
 
         screen->surface_unmap(screen, src_surface);
338
 
         pipe_surface_reference(&src_surface, NULL);
339
 
      }
340
 
#endif
341
 
 
342
 
      dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i,
343
 
                                            PIPE_BUFFER_USAGE_GPU_WRITE);
344
 
 
345
 
      src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
346
 
                                            PIPE_BUFFER_USAGE_GPU_READ);
347
 
 
348
 
      if (pipe->surface_copy) {
349
 
         pipe->surface_copy(pipe,
350
 
                            dst_surface,
351
 
                            0, 0, /* destX, Y */
352
 
                            src_surface,
353
 
                            0, 0, /* srcX, Y */
354
 
                            width, height);
355
 
      } else {
356
 
         util_surface_copy(pipe, FALSE,
357
 
                           dst_surface,
358
 
                           0, 0, /* destX, Y */
359
 
                           src_surface,
360
 
                           0, 0, /* srcX, Y */
361
 
                           width, height);
362
 
      }
363
 
 
364
 
      pipe_surface_reference(&src_surface, NULL);
365
 
      pipe_surface_reference(&dst_surface, NULL);
366
 
   }
367
 
}
368
 
 
369
 
 
370
 
/**
371
 
 * Bind a pipe surface to a texture object.  After the call,
372
 
 * the texture object is marked dirty and will be (re-)validated.
373
 
 *
374
 
 * If this is the first surface bound, the texture object is said to
375
 
 * switch from normal to surface based.  It will be cleared first in
376
 
 * this case.
377
 
 *
378
 
 * \param ps      pipe surface to be unbound
379
 
 * \param target  texture target
380
 
 * \param level   image level
381
 
 * \param format  internal format of the texture
382
 
 */
383
 
int
384
 
st_bind_texture_surface(struct pipe_surface *ps, int target, int level,
385
 
                        enum pipe_format format)
386
 
{
387
 
   GET_CURRENT_CONTEXT(ctx);
388
 
   const GLuint unit = ctx->Texture.CurrentUnit;
389
 
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
390
 
   struct gl_texture_object *texObj;
391
 
   struct gl_texture_image *texImage;
392
 
   struct st_texture_object *stObj;
393
 
   struct st_texture_image *stImage;
394
 
   GLenum internalFormat;
395
 
 
396
 
   switch (target) {
397
 
   case ST_TEXTURE_2D:
398
 
      target = GL_TEXTURE_2D;
399
 
      break;
400
 
   case ST_TEXTURE_RECT:
401
 
      target = GL_TEXTURE_RECTANGLE_ARB;
402
 
      break;
403
 
   default:
404
 
      return 0;
405
 
   }
406
 
 
407
 
   /* map pipe format to base format for now */
408
 
   if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
409
 
      internalFormat = GL_RGBA;
410
 
   else
411
 
      internalFormat = GL_RGB;
412
 
 
413
 
   texObj = _mesa_select_tex_object(ctx, texUnit, target);
414
 
   _mesa_lock_texture(ctx, texObj);
415
 
 
416
 
   stObj = st_texture_object(texObj);
417
 
   /* switch to surface based */
418
 
   if (!stObj->surface_based) {
419
 
      _mesa_clear_texture_object(ctx, texObj);
420
 
      stObj->surface_based = GL_TRUE;
421
 
   }
422
 
 
423
 
   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
424
 
   stImage = st_texture_image(texImage);
425
 
 
426
 
   _mesa_init_teximage_fields(ctx, target, texImage,
427
 
                              ps->width, ps->height, 1, 0, internalFormat);
428
 
   texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
429
 
                                                GL_RGBA, GL_UNSIGNED_BYTE);
430
 
   _mesa_set_fetch_functions(texImage, 2);
431
 
   pipe_texture_reference(&stImage->pt, ps->texture);
432
 
 
433
 
   _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
434
 
   _mesa_unlock_texture(ctx, texObj);
435
 
   
436
 
   return 1;
437
 
}
438
 
 
439
 
 
440
 
/**
441
 
 * Unbind a pipe surface from a texture object.  After the call,
442
 
 * the texture object is marked dirty and will be (re-)validated.
443
 
 *
444
 
 * \param ps      pipe surface to be unbound
445
 
 * \param target  texture target
446
 
 * \param level   image level
447
 
 */
448
 
int
449
 
st_unbind_texture_surface(struct pipe_surface *ps, int target, int level)
450
 
{
451
 
   GET_CURRENT_CONTEXT(ctx);
452
 
   const GLuint unit = ctx->Texture.CurrentUnit;
453
 
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
454
 
   struct gl_texture_object *texObj;
455
 
   struct gl_texture_image *texImage;
456
 
   struct st_texture_object *stObj;
457
 
   struct st_texture_image *stImage;
458
 
 
459
 
   switch (target) {
460
 
   case ST_TEXTURE_2D:
461
 
      target = GL_TEXTURE_2D;
462
 
      break;
463
 
   case ST_TEXTURE_RECT:
464
 
      target = GL_TEXTURE_RECTANGLE_ARB;
465
 
      break;
466
 
   default:
467
 
      return 0;
468
 
   }
469
 
 
470
 
   texObj = _mesa_select_tex_object(ctx, texUnit, target);
471
 
 
472
 
   _mesa_lock_texture(ctx, texObj);
473
 
 
474
 
   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
475
 
   stObj = st_texture_object(texObj);
476
 
   stImage = st_texture_image(texImage);
477
 
 
478
 
   /* Make sure the pipe surface is still bound.  The texture object is still
479
 
    * considered surface based even if this is the last bound surface. */
480
 
   if (stImage->pt == ps->texture) {
481
 
      pipe_texture_reference(&stImage->pt, NULL);
482
 
      _mesa_clear_texture_image(ctx, texImage);
483
 
 
484
 
      _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
485
 
   }
486
 
 
487
 
   _mesa_unlock_texture(ctx, texObj);
488
 
   
489
 
   return 1;
490
 
}
491
 
 
492
 
 
493
 
/** Redirect rendering into stfb's surface to a texture image */
494
 
int
495
 
st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex,
496
 
                 int target, int format, int level)
497
 
{
498
 
   GET_CURRENT_CONTEXT(ctx);
499
 
   struct st_context *st = ctx->st;
500
 
   struct pipe_context *pipe = st->pipe;
501
 
   struct pipe_screen *screen = pipe->screen;
502
 
   const GLuint unit = ctx->Texture.CurrentUnit;
503
 
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
504
 
   struct gl_texture_object *texObj;
505
 
   struct gl_texture_image *texImage;
506
 
   struct st_texture_image *stImage;
507
 
   struct st_renderbuffer *strb;
508
 
   GLint face = 0, slice = 0;
509
 
 
510
 
   assert(surfIndex <= ST_SURFACE_DEPTH);
511
 
 
512
 
   strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
513
 
 
514
 
   if (strb->texture_save || strb->surface_save) {
515
 
      /* Error! */
516
 
      return 0;
517
 
   }
518
 
 
519
 
   if (target == ST_TEXTURE_2D) {
520
 
      texObj = texUnit->CurrentTex[TEXTURE_2D_INDEX];
521
 
      texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, level);
522
 
      stImage = st_texture_image(texImage);
523
 
   }
524
 
   else {
525
 
      /* unsupported target */
526
 
      return 0;
527
 
   }
528
 
 
529
 
   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
530
 
 
531
 
   /* save the renderbuffer's surface/texture info */
532
 
   pipe_texture_reference(&strb->texture_save, strb->texture);
533
 
   pipe_surface_reference(&strb->surface_save, strb->surface);
534
 
 
535
 
   /* plug in new surface/texture info */
536
 
   pipe_texture_reference(&strb->texture, stImage->pt);
537
 
   strb->surface = screen->get_tex_surface(screen, strb->texture,
538
 
                                           face, level, slice,
539
 
                                           (PIPE_BUFFER_USAGE_GPU_READ |
540
 
                                            PIPE_BUFFER_USAGE_GPU_WRITE));
541
 
 
542
 
   st->dirty.st |= ST_NEW_FRAMEBUFFER;
543
 
 
544
 
   return 1;
545
 
}
546
 
 
547
 
 
548
 
/** Undo surface-to-texture binding */
549
 
int
550
 
st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
551
 
                    int target, int format, int level)
552
 
{
553
 
   GET_CURRENT_CONTEXT(ctx);
554
 
   struct st_context *st = ctx->st;
555
 
   struct st_renderbuffer *strb;
556
 
 
557
 
   assert(surfIndex <= ST_SURFACE_DEPTH);
558
 
 
559
 
   strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer);
560
 
 
561
 
   if (!strb->texture_save || !strb->surface_save) {
562
 
      /* Error! */
563
 
      return 0;
564
 
   }
565
 
 
566
 
   st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
567
 
 
568
 
   /* free tex surface, restore original */
569
 
   pipe_surface_reference(&strb->surface, strb->surface_save);
570
 
   pipe_texture_reference(&strb->texture, strb->texture_save);
571
 
 
572
 
   pipe_surface_reference(&strb->surface_save, NULL);
573
 
   pipe_texture_reference(&strb->texture_save, NULL);
574
 
 
575
 
   st->dirty.st |= ST_NEW_FRAMEBUFFER;
576
 
 
577
 
   return 1;
578
 
}
579
 
 
580
 
void
581
 
st_teximage_flush_before_map(struct st_context *st,
582
 
                             struct pipe_texture *pt,
583
 
                             unsigned int face,
584
 
                             unsigned int level,
585
 
                             enum pipe_transfer_usage usage)
586
 
{
587
 
   struct pipe_context *pipe = st->pipe;
588
 
   unsigned referenced =
589
 
      pipe->is_texture_referenced(pipe, pt, face, level);
590
 
 
591
 
   if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
592
 
                      (usage & PIPE_TRANSFER_WRITE)))
593
 
      st->pipe->flush(st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
594
 
}
 
301
 
 
302
      if (0)  {
 
303
         print_center_pixel(pipe, src);
 
304
      }
 
305
 
 
306
      pipe->resource_copy_region(pipe,
 
307
                                 dst,
 
308
                                 dstsub,
 
309
                                 0, 0, i,/* destX, Y, Z */
 
310
                                 src,
 
311
                                 srcsub,
 
312
                                 0, 0, i,/* srcX, Y, Z */
 
313
                                 width, height);
 
314
   }
 
315
}
 
316