Esempio n. 1
0
static void
sw_MapRenderbuffer(struct gl_context *ctx,
                   struct gl_renderbuffer *rb,
                   GLuint x, GLuint y, GLuint w, GLuint h,
                   GLbitfield mode,
                   GLubyte **mapOut, GLint *rowStrideOut)
{
    if(rb->ClassID == SW_FRONT_RENDERBUFFER_CLASS)
    {
        /* This is our front buffer */
        struct sw_front_renderbuffer* srb = (struct sw_front_renderbuffer*)rb;
        struct sw_framebuffer* fb = CONTAINING_RECORD(srb, struct sw_framebuffer, frontbuffer);
        /* Set the stride */
        *rowStrideOut = WIDTH_BYTES_ALIGN32(rb->Width, pixel_formats[fb->format_index].color_bits);
        /* Remember where we "mapped" */
        srb->x = x; srb->y = y; srb->w = w; srb->h = h;
        /* Remember if we should write it later */
        srb->write = !!(mode & GL_MAP_WRITE_BIT);
        /* Get the bits, if needed */
        if(mode & GL_MAP_READ_BIT)
        {
            BitBlt(srb->hdcmem, srb->x, srb->y, srb->w, srb->h,
                IntGetCurrentDC(), srb->x, srb->y, SRCCOPY);
        }
        /* And return it */
        *mapOut = (BYTE*)srb->swrast.Buffer + *rowStrideOut*y + x*pixel_formats[fb->format_index].color_bits/8;
        return;
    }
    
    if(rb->ClassID == SW_BACK_RENDERBUFFER_CLASS)
    {
        /* This is our front buffer */
        struct swrast_renderbuffer* srb = (struct swrast_renderbuffer*)rb;
        const GLuint bpp = _mesa_get_format_bytes(rb->Format);
        /* Set the stride */
        *rowStrideOut = srb->RowStride;
        *mapOut = (BYTE*)srb->Buffer + srb->RowStride*y + x*bpp;
        return;
    }
    
    /* Let mesa rasterizer take care of this */
    _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
                                  mapOut, rowStrideOut);
}
Esempio n. 2
0
static void
osmesa_MapRenderbuffer(struct gl_context *ctx,
                       struct gl_renderbuffer *rb,
                       GLuint x, GLuint y, GLuint w, GLuint h,
                       GLbitfield mode,
                       GLubyte **mapOut, GLint *rowStrideOut)
{
   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);

   if (rb->ClassID == OSMESA_RENDERBUFFER_CLASS) {
      /* this is an OSMesa renderbuffer which wraps user memory */
      struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
      const GLuint bpp = _mesa_get_format_bytes(rb->Format);
      GLint rowStride; /* in bytes */

      if (osmesa->userRowLength)
         rowStride = osmesa->userRowLength * bpp;
      else
         rowStride = rb->Width * bpp;

      if (!osmesa->yup) {
         /* Y=0 is top line of window */
         y = rb->Height - y - 1;
         *rowStrideOut = -rowStride;
      }
      else {
         *rowStrideOut = rowStride;
      }

      *mapOut = (GLubyte *) srb->Buffer + y * rowStride + x * bpp;
   }
   else {
      _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
                                    mapOut, rowStrideOut);
   }
}
Esempio n. 3
0
/**
 * Called via ctx->Driver.MapRenderbuffer()
 */
void
xmesa_MapRenderbuffer(struct gl_context *ctx,
                      struct gl_renderbuffer *rb,
                      GLuint x, GLuint y, GLuint w, GLuint h,
                      GLbitfield mode,
                      GLubyte **mapOut, GLint *rowStrideOut)
{
    struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);

    if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
        XImage *ximage = xrb->ximage;

        assert(!xrb->map_mode); /* only a single mapping allowed */

        xrb->map_mode = mode;
        xrb->map_x = x;
        xrb->map_y = y;
        xrb->map_w = w;
        xrb->map_h = h;

        if (ximage) {
            int y2 = rb->Height - y - 1;

            *mapOut = (GLubyte *) ximage->data
                      + y2 * ximage->bytes_per_line
                      + x * ximage->bits_per_pixel / 8;
        }
        else {
            /* this must be a pixmap/window renderbuffer */
            int (*old_handler)(XMesaDisplay *, XErrorEvent *);
            int y2 = rb->Height - y - h;

            assert(xrb->pixmap);

            /* Install error handler for XGetImage() in case the the window
             * isn't mapped.  If we fail we'll create a temporary XImage.
             */
            mesaXErrorFlag = 0;
            old_handler = XSetErrorHandler(mesaHandleXError);

            /* read pixel data out of the pixmap/window into an XImage */
            ximage = XGetImage(xrb->Parent->display,
                               xrb->pixmap, x, y2, w, h,
                               AllPlanes, ZPixmap);

            XSetErrorHandler(old_handler);

            if (mesaXErrorFlag) {
                /* create new, temporary XImage */
                int bytes_per_line =
                    _mesa_format_row_stride(xrb->Base.Base.Format,
                                            xrb->Base.Base.Width);
                char *image = (char *) malloc(bytes_per_line *
                                              xrb->Base.Base.Height);
                ximage = XCreateImage(xrb->Parent->display,
                                      xrb->Parent->xm_visual->visinfo->visual,
                                      xrb->Parent->xm_visual->visinfo->depth,
                                      ZPixmap, /* format */
                                      0, /* offset */
                                      image, /* data */
                                      xrb->Base.Base.Width,
                                      xrb->Base.Base.Height,
                                      8, /* pad */
                                      bytes_per_line);
            }

            if (!ximage) {
                *mapOut = NULL;
                *rowStrideOut = 0;
                return;
            }

            xrb->map_ximage = ximage;

            /* the first row of the OpenGL image is last row of the XImage */
            *mapOut = (GLubyte *) ximage->data
                      + (h - 1) * ximage->bytes_per_line;
        }

        /* We return a negative stride here since XImage data is upside down
         * with respect to OpenGL images.
         */
        *rowStrideOut = -ximage->bytes_per_line;
        return;
    }

    /* otherwise, this is an ordinary malloc-based renderbuffer */
    _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
                                  mapOut, rowStrideOut);
}
Esempio n. 4
0
/**
 * Called via ctx->Driver.MapRenderbuffer()
 */
void
xmesa_MapRenderbuffer(struct gl_context *ctx,
                      struct gl_renderbuffer *rb,
                      GLuint x, GLuint y, GLuint w, GLuint h,
                      GLbitfield mode,
                      GLubyte **mapOut, GLint *rowStrideOut)
{
   struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);

   if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
      XImage *ximage = xrb->ximage;

      assert(!xrb->map_mode); /* only a single mapping allowed */

      xrb->map_mode = mode;
      xrb->map_x = x;
      xrb->map_y = y;
      xrb->map_w = w;
      xrb->map_h = h;

      if (ximage) {
         int y2 = rb->Height - y - 1;

         *mapOut = (GLubyte *) ximage->data
            + y2 * ximage->bytes_per_line
            + x * ximage->bits_per_pixel / 8;
      }
      else {
         /* this must be a pixmap/window renderbuffer */
         int y2 = rb->Height - y - h;

         assert(xrb->pixmap);

         /* read pixel data out of the pixmap/window into an XImage */
         ximage = XGetImage(xrb->Parent->display,
                            xrb->pixmap, x, y2, w, h,
                            AllPlanes, ZPixmap);
         if (!ximage) {
            *mapOut = NULL;
            *rowStrideOut = 0;
            return;
         }

         xrb->map_ximage = ximage;

         /* the first row of the OpenGL image is last row of the XImage */
         *mapOut = (GLubyte *) ximage->data
            + (h - 1) * ximage->bytes_per_line;
      }

      /* We return a negative stride here since XImage data is upside down
       * with respect to OpenGL images.
       */
      *rowStrideOut = -ximage->bytes_per_line;
      return;
   }

   /* otherwise, this is an ordinary malloc-based renderbuffer */
   _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
                                 mapOut, rowStrideOut);
}