Example #1
0
/**
 * Bind an OSMesaContext to an image buffer.  The image buffer is just a
 * block of memory which the client provides.  Its size must be at least
 * as large as width*height*pixelSize.  Its address should be a multiple
 * of 4 if using RGBA mode.
 *
 * By default, image data is stored in the order of glDrawPixels: row-major
 * order with the lower-left image pixel stored in the first array position
 * (ie. bottom-to-top).
 *
 * If the context's viewport hasn't been initialized yet, it will now be
 * initialized to (0,0,width,height).
 *
 * Input:  osmesa - the rendering context
 *         buffer - the image buffer memory
 *         type - data type for pixel components
 *                GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT
 *                or GL_FLOAT.
 *         width, height - size of image buffer in pixels, at least 1
 * Return:  GL_TRUE if success, GL_FALSE if error because of invalid osmesa,
 *          invalid type, invalid size, etc.
 */
GLAPI GLboolean GLAPIENTRY
OSMesaMakeCurrent(OSMesaContext osmesa, void *buffer, GLenum type,
                  GLsizei width, GLsizei height)
{
   struct st_api *stapi = get_st_api();
   struct osmesa_buffer *osbuffer;
   enum pipe_format color_format;

   if (osmesa->format == OSMESA_RGB_565 && type != GL_UNSIGNED_SHORT_5_6_5) {
      return GL_FALSE;
   }
   if (width < 1 || height < 1) {
      return GL_FALSE;
   }

   color_format = osmesa_choose_format(osmesa->format, type);
   if (color_format == PIPE_FORMAT_NONE) {
      fprintf(stderr, "OSMesaMakeCurrent(unsupported format/type)\n");
      return GL_FALSE;
   }

   /* See if we already have a buffer that uses these pixel formats */
   osbuffer = osmesa_find_buffer(color_format,
                                 osmesa->depth_stencil_format,
                                 osmesa->accum_format);
   if (!osbuffer) {
      /* Existing buffer found, create new buffer */
      osbuffer = osmesa_create_buffer(color_format,
                                      osmesa->depth_stencil_format,
                                      osmesa->accum_format);
   }

   osbuffer->width = width;
   osbuffer->height = height;
   osbuffer->map = buffer;

   /* XXX unused for now */
   (void) osmesa_destroy_buffer;

   osmesa->current_buffer = osbuffer;
   osmesa->type = type;

   stapi->make_current(stapi, osmesa->stctx, osbuffer->stfb, osbuffer->stfb);

   return GL_TRUE;
}
Example #2
0
/**
 * Bind an OSMesaContext to an image buffer.  The image buffer is just a
 * block of memory which the client provides.  Its size must be at least
 * as large as width*height*pixelSize.  Its address should be a multiple
 * of 4 if using RGBA mode.
 *
 * By default, image data is stored in the order of glDrawPixels: row-major
 * order with the lower-left image pixel stored in the first array position
 * (ie. bottom-to-top).
 *
 * If the context's viewport hasn't been initialized yet, it will now be
 * initialized to (0,0,width,height).
 *
 * Input:  osmesa - the rendering context
 *         buffer - the image buffer memory
 *         type - data type for pixel components
 *                GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT
 *                or GL_FLOAT.
 *         width, height - size of image buffer in pixels, at least 1
 * Return:  GL_TRUE if success, GL_FALSE if error because of invalid osmesa,
 *          invalid type, invalid size, etc.
 */
GLAPI GLboolean GLAPIENTRY
OSMesaMakeCurrent(OSMesaContext osmesa, void *buffer, GLenum type,
                  GLsizei width, GLsizei height)
{
    struct st_api *stapi = get_st_api();
    struct osmesa_buffer *osbuffer;
    enum pipe_format color_format;

    if (!osmesa || !buffer || width < 1 || height < 1) {
        return GL_FALSE;
    }

    if (osmesa->format == OSMESA_RGB_565 && type != GL_UNSIGNED_SHORT_5_6_5) {
        return GL_FALSE;
    }

    color_format = osmesa_choose_format(osmesa->format, type);
    if (color_format == PIPE_FORMAT_NONE) {
        fprintf(stderr, "OSMesaMakeCurrent(unsupported format/type)\n");
        return GL_FALSE;
    }

    /* See if we already have a buffer that uses these pixel formats */
    osbuffer = osmesa_find_buffer(color_format,
                                  osmesa->depth_stencil_format,
                                  osmesa->accum_format, width, height);
    if (!osbuffer) {
        /* Existing buffer found, create new buffer */
        osbuffer = osmesa_create_buffer(color_format,
                                        osmesa->depth_stencil_format,
                                        osmesa->accum_format);
    }

    osbuffer->width = width;
    osbuffer->height = height;
    osbuffer->map = buffer;

    /* XXX unused for now */
    (void) osmesa_destroy_buffer;

    osmesa->current_buffer = osbuffer;
    osmesa->type = type;

    stapi->make_current(stapi, osmesa->stctx, osbuffer->stfb, osbuffer->stfb);

    if (!osmesa->ever_used) {
        /* one-time init, just postprocessing for now */
        boolean any_pp_enabled = FALSE;
        unsigned i;

        for (i = 0; i < ARRAY_SIZE(osmesa->pp_enabled); i++) {
            if (osmesa->pp_enabled[i]) {
                any_pp_enabled = TRUE;
                break;
            }
        }

        if (any_pp_enabled) {
            osmesa->pp = pp_init(osmesa->stctx->pipe,
                                 osmesa->pp_enabled,
                                 osmesa->stctx->cso_context);

            pp_init_fbos(osmesa->pp, width, height);
        }

        osmesa->ever_used = TRUE;
    }

    return GL_TRUE;
}