Example #1
0
static void
dri_postprocessing(struct dri_context *ctx,
                   struct dri_drawable *drawable,
                   enum st_attachment_type att)
{
   struct pipe_resource *src = drawable->textures[att];
   struct pipe_resource *zsbuf = drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL];

   if (ctx->pp && src && zsbuf)
      pp_run(ctx->pp, src, src, zsbuf);
}
Example #2
0
/**
 * DRI2 flush extension.
 */
static void
dri2_flush_drawable(__DRIdrawable *dPriv)
{
   struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
   struct dri_drawable *drawable = dri_drawable(dPriv);

   struct pipe_resource *ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];

   if (ctx) {
      if (ptex && ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
         pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);

      ctx->st->flush(ctx->st, 0, NULL);
   }
}
static void
drisw_swap_buffers(__DRIdrawable *dPriv)
{
   struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
   struct dri_drawable *drawable = dri_drawable(dPriv);
   struct pipe_resource *ptex;

   if (!ctx)
      return;

   ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];

   if (ptex) {
      if (ctx->pp)
         pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);

      ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL);

      drisw_copy_to_front(dPriv, ptex);
   }
}
Example #4
0
// returns NULL if the file failed to open or is 0 length
char* LoadFile(char* pFilename, int* pnLength)
{
    char* pBuffer = 0;

    FILE* pFile = OpenFileInPath(pFilename, "rb");
    if (pFile != NULL)
    {
        if (s_bUsePreprocessor)
        {
            pp_push_file_struct(&s_preprocessor, pFile, pFilename);
            pp_run(&s_preprocessor);
            pBuffer = pp_finish(&s_preprocessor);
            *pnLength = strlen(pBuffer);
            if (*pnLength == 0)
            {
                free(pBuffer);
                pBuffer = NULL;
            }
        }
        else
        {
            // get the length of the file by seeking to the end and using ftell
            fseek(pFile, 0, SEEK_END);
            *pnLength = ftell(pFile);

            if (*pnLength > 0)
            {
                pBuffer = (char*)malloc(*pnLength+1); // allocate a buffer that is the size of the file plus one char
                pBuffer[*pnLength] = 0; // set the end of the buffer to 0 (null)

                // seek back to the beginning of the file and read it in
                fseek(pFile, 0, SEEK_SET);
                fread(pBuffer, 1, *pnLength, pFile);
            }
        }
        fclose(pFile);
    }

    return pBuffer;
}
static void
drisw_copy_sub_buffer(__DRIdrawable *dPriv, int x, int y,
                      int w, int h)
{
   struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
   struct dri_drawable *drawable = dri_drawable(dPriv);
   struct pipe_resource *ptex;
   struct pipe_box box;
   if (!ctx)
      return;

   ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];

   if (ptex) {
      if (ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
         pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);

      ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL);

      u_box_2d(x, dPriv->h - y - h, w, h, &box);
      drisw_present_texture(dPriv, ptex, &box);
   }
}
Example #6
0
/**
 * Called via glFlush/glFinish.  This is where we copy the contents
 * of the driver's color buffer into the user-specified buffer.
 */
static boolean
osmesa_st_framebuffer_flush_front(struct st_context_iface *stctx,
                                  struct st_framebuffer_iface *stfbi,
                                  enum st_attachment_type statt)
{
    OSMesaContext osmesa = OSMesaGetCurrentContext();
    struct osmesa_buffer *osbuffer = stfbi_to_osbuffer(stfbi);
    struct pipe_context *pipe = stctx->pipe;
    struct pipe_resource *res = osbuffer->textures[statt];
    struct pipe_transfer *transfer = NULL;
    struct pipe_box box;
    void *map;
    ubyte *src, *dst;
    unsigned y, bytes, bpp;
    int dst_stride;

    if (osmesa->pp) {
        struct pipe_resource *zsbuf = NULL;
        unsigned i;

        /* Find the z/stencil buffer if there is one */
        for (i = 0; i < ARRAY_SIZE(osbuffer->textures); i++) {
            struct pipe_resource *res = osbuffer->textures[i];
            if (res) {
                const struct util_format_description *desc =
                    util_format_description(res->format);

                if (util_format_has_depth(desc)) {
                    zsbuf = res;
                    break;
                }
            }
        }

        /* run the postprocess stage(s) */
        pp_run(osmesa->pp, res, res, zsbuf);
    }

    u_box_2d(0, 0, res->width0, res->height0, &box);

    map = pipe->transfer_map(pipe, res, 0, PIPE_TRANSFER_READ, &box,
                             &transfer);

    /*
     * Copy the color buffer from the resource to the user's buffer.
     */
    bpp = util_format_get_blocksize(osbuffer->visual.color_format);
    src = map;
    dst = osbuffer->map;
    if (osmesa->user_row_length)
        dst_stride = bpp * osmesa->user_row_length;
    else
        dst_stride = bpp * osbuffer->width;
    bytes = bpp * res->width0;

    if (osmesa->y_up) {
        /* need to flip image upside down */
        dst = dst + (res->height0 - 1) * dst_stride;
        dst_stride = -dst_stride;
    }

    for (y = 0; y < res->height0; y++) {
        memcpy(dst, src, bytes);
        dst += dst_stride;
        src += transfer->stride;
    }

    pipe->transfer_unmap(pipe, transfer);

    return TRUE;
}