Пример #1
0
/*
 * TODO: Optimize!!!!
 */
static void
copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
                   GLint width, GLint height,
                   GLint destx, GLint desty )
{
   SWcontext *swrast = SWRAST_CONTEXT(ctx);
   struct gl_framebuffer *fb = ctx->ReadBuffer;
   struct gl_renderbuffer *readRb = fb->_DepthBuffer;
   GLfloat *p, *tmpImage;
   GLint sy, dy, stepy;
   GLint j;
   const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
   GLint overlapping;
   SWspan span;

   if (!readRb) {
      /* no readbuffer - OK */
      return;
   }

   INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_Z);

   if (ctx->DrawBuffer == ctx->ReadBuffer) {
      overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
                                    ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
   }
   else {
      overlapping = GL_FALSE;
   }

   /* Determine if copy should be bottom-to-top or top-to-bottom */
   if (!overlapping && srcy < desty) {
      /* top-down  max-to-min */
      sy = srcy + height - 1;
      dy = desty + height - 1;
      stepy = -1;
   }
   else {
      /* bottom-up  min-to-max */
      sy = srcy;
      dy = desty;
      stepy = 1;
   }

   _swrast_span_default_color(ctx, &span);
   _swrast_span_default_secondary_color(ctx, &span);
   if (swrast->_FogEnabled)
      _swrast_span_default_fog(ctx, &span);

   if (overlapping) {
      GLint ssy = sy;
      tmpImage = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat));
      if (!tmpImage) {
         _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
         return;
      }
      p = tmpImage;
      for (j = 0; j < height; j++, ssy += stepy) {
         _swrast_read_depth_span_float(ctx, readRb, width, srcx, ssy, p);
         p += width;
      }
      p = tmpImage;
   }
   else {
      tmpImage = NULL;  /* silence compiler warning */
      p = NULL;
   }

   for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
      GLfloat depth[MAX_WIDTH];
      /* get depth values */
      if (overlapping) {
         _mesa_memcpy(depth, p, width * sizeof(GLfloat));
         p += width;
      }
      else {
         _swrast_read_depth_span_float(ctx, readRb, width, srcx, sy, depth);
      }

      /* apply scale and bias */
      scale_and_bias_z(ctx, width, depth, span.array->z);

      /* write depth values */
      span.x = destx;
      span.y = dy;
      span.end = width;
      if (fb->Visual.rgbMode) {
         if (zoom)
            _swrast_write_zoomed_depth_span(ctx, destx, desty, &span);
         else
            _swrast_write_rgba_span(ctx, &span);
      }
      else {
         if (zoom)
            _swrast_write_zoomed_depth_span(ctx, destx, desty, &span);
         else
            _swrast_write_index_span(ctx, &span);
      }
   }

   if (overlapping)
      _mesa_free(tmpImage);
}
Пример #2
0
/*
 * TODO: Optimize!!!!
 */
static void
copy_depth_pixels( struct gl_context *ctx, GLint srcx, GLint srcy,
                   GLint width, GLint height,
                   GLint destx, GLint desty )
{
    struct gl_framebuffer *fb = ctx->ReadBuffer;
    struct gl_renderbuffer *readRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
    GLfloat *p, *tmpImage, *depth;
    GLint sy, dy, stepy;
    GLint j;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
    GLint overlapping;
    SWspan span;

    if (!readRb) {
        /* no readbuffer - OK */
        return;
    }

    INIT_SPAN(span, GL_BITMAP);
    _swrast_span_default_attribs(ctx, &span);
    span.arrayMask = SPAN_Z;

    if (ctx->DrawBuffer == ctx->ReadBuffer) {
        overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
                                      ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
    }
    else {
        overlapping = GL_FALSE;
    }

    /* Determine if copy should be bottom-to-top or top-to-bottom */
    if (!overlapping && srcy < desty) {
        /* top-down  max-to-min */
        sy = srcy + height - 1;
        dy = desty + height - 1;
        stepy = -1;
    }
    else {
        /* bottom-up  min-to-max */
        sy = srcy;
        dy = desty;
        stepy = 1;
    }

    if (overlapping) {
        GLint ssy = sy;
        tmpImage = malloc(width * height * sizeof(GLfloat));
        if (!tmpImage) {
            _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
            return;
        }
        p = tmpImage;
        for (j = 0; j < height; j++, ssy += stepy) {
            _swrast_read_depth_span_float(ctx, readRb, width, srcx, ssy, p);
            p += width;
        }
        p = tmpImage;
    }
    else {
        tmpImage = NULL;  /* silence compiler warning */
        p = NULL;
    }

    depth = malloc(width * sizeof(GLfloat));
    if (!depth) {
        _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels()");
        goto end;
    }

    for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
        /* get depth values */
        if (overlapping) {
            memcpy(depth, p, width * sizeof(GLfloat));
            p += width;
        }
        else {
            _swrast_read_depth_span_float(ctx, readRb, width, srcx, sy, depth);
        }

        /* apply scale and bias */
        scale_and_bias_z(ctx, width, depth, span.array->z);

        /* write depth values */
        span.x = destx;
        span.y = dy;
        span.end = width;
        if (zoom)
            _swrast_write_zoomed_depth_span(ctx, destx, desty, &span);
        else
            _swrast_write_rgba_span(ctx, &span);
    }

    free(depth);

end:
    if (overlapping)
        free(tmpImage);
}